Skip to content

Commit

Permalink
Tweak IP pool edit onSuccess logic (#2409)
Browse files Browse the repository at this point in the history
tweak IP pool edit onSuccess logic
  • Loading branch information
david-crespo authored Sep 3, 2024
1 parent c648c44 commit f042ad4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions app/forms/ip-pool-edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ export function EditIpPoolSideModalForm() {
const { data: pool } = usePrefetchedApiQuery('ipPoolView', { path: poolSelector })

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

const editPool = useApiMutation('ipPoolUpdate', {
onSuccess(_pool) {
onSuccess(updatedPool) {
queryClient.invalidateQueries('ipPoolList')
if (pool.name !== _pool.name) {
// as the pool's name has changed, we need to navigate to an updated URL
navigate(pb.ipPool({ pool: _pool.name }))
} else {
navigate(pb.ipPool({ pool: updatedPool.name }))
addToast({ content: 'Your IP pool has been updated' })

// Only invalidate if we're staying on the same page. If the name
// _has_ changed, invalidating ipPoolView causes an error page to flash
// while the loader for the target page is running because the current
// page's pool gets cleared out while we're still on the page. If we're
// navigating to a different page, its query will fetch anew regardless.
if (pool.name === updatedPool.name) {
queryClient.invalidateQueries('ipPoolView')
onDismiss()
}
addToast({ content: 'Your IP pool has been updated' })
},
})

Expand All @@ -56,7 +58,7 @@ export function EditIpPoolSideModalForm() {
form={form}
formType="edit"
resourceName="IP pool"
onDismiss={onDismiss}
onDismiss={() => navigate(pb.ipPool({ pool: poolSelector.pool }))}
onSubmit={({ name, description }) => {
editPool.mutate({ path: poolSelector, body: { name, description } })
}}
Expand Down

0 comments on commit f042ad4

Please sign in to comment.