Skip to content

Commit f042ad4

Browse files
authored
Tweak IP pool edit onSuccess logic (#2409)
tweak IP pool edit onSuccess logic
1 parent c648c44 commit f042ad4

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

app/forms/ip-pool-edit.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,21 @@ export function EditIpPoolSideModalForm() {
3535
const { data: pool } = usePrefetchedApiQuery('ipPoolView', { path: poolSelector })
3636

3737
const form = useForm({ defaultValues: pool })
38-
const onDismiss = () => navigate(pb.ipPool({ pool: poolSelector.pool }))
3938

4039
const editPool = useApiMutation('ipPoolUpdate', {
41-
onSuccess(_pool) {
40+
onSuccess(updatedPool) {
4241
queryClient.invalidateQueries('ipPoolList')
43-
if (pool.name !== _pool.name) {
44-
// as the pool's name has changed, we need to navigate to an updated URL
45-
navigate(pb.ipPool({ pool: _pool.name }))
46-
} else {
42+
navigate(pb.ipPool({ pool: updatedPool.name }))
43+
addToast({ content: 'Your IP pool has been updated' })
44+
45+
// Only invalidate if we're staying on the same page. If the name
46+
// _has_ changed, invalidating ipPoolView causes an error page to flash
47+
// while the loader for the target page is running because the current
48+
// page's pool gets cleared out while we're still on the page. If we're
49+
// navigating to a different page, its query will fetch anew regardless.
50+
if (pool.name === updatedPool.name) {
4751
queryClient.invalidateQueries('ipPoolView')
48-
onDismiss()
4952
}
50-
addToast({ content: 'Your IP pool has been updated' })
5153
},
5254
})
5355

@@ -56,7 +58,7 @@ export function EditIpPoolSideModalForm() {
5658
form={form}
5759
formType="edit"
5860
resourceName="IP pool"
59-
onDismiss={onDismiss}
61+
onDismiss={() => navigate(pb.ipPool({ pool: poolSelector.pool }))}
6062
onSubmit={({ name, description }) => {
6163
editPool.mutate({ path: poolSelector, body: { name, description } })
6264
}}

0 commit comments

Comments
 (0)