Skip to content

Commit 166e764

Browse files
committed
fix(access-control): don't leave the detail view when an unsaved-changes save fails
The unsaved-changes dialog's Save action navigated back unconditionally after handleSaveConfig, but that helper swallows mutation errors — so a failed save still exited the view and silently dropped the edits. handleSaveConfig now returns success, and the dialog only closes + navigates back when the save actually succeeded.
1 parent 33ee7da commit 166e764

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

apps/sim/ee/access-control/components/group-detail.tsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,19 +1065,22 @@ export function GroupDetail({
10651065
})
10661066
}, [])
10671067

1068-
const handleSaveConfig = useCallback(async () => {
1068+
/** Persists the editing buffer. Returns whether the save succeeded so callers can decide whether to navigate away. */
1069+
const handleSaveConfig = useCallback(async (): Promise<boolean> => {
10691070
try {
10701071
await updatePermissionGroup.mutateAsync({
10711072
id: viewingGroup.id,
10721073
organizationId,
10731074
config: editingConfig,
10741075
})
10751076
setViewingGroup((prev) => ({ ...prev, config: editingConfig }))
1077+
return true
10761078
} catch (error) {
10771079
logger.error('Failed to update config', error)
10781080
toast.error("Couldn't save changes", {
10791081
description: getErrorMessage(error, 'Please try again in a moment.'),
10801082
})
1083+
return false
10811084
}
10821085
}, [viewingGroup.id, editingConfig, organizationId, updatePermissionGroup])
10831086

@@ -1725,9 +1728,13 @@ export function GroupDetail({
17251728
primaryAction={{
17261729
label: updatePermissionGroup.isPending ? 'Saving...' : 'Save Changes',
17271730
onClick: async () => {
1728-
await handleSaveConfig()
1729-
setShowUnsavedChanges(false)
1730-
onBack()
1731+
// Only leave once the save actually succeeds; a failed save keeps
1732+
// the dialog open with the edits intact (error surfaced via toast).
1733+
const saved = await handleSaveConfig()
1734+
if (saved) {
1735+
setShowUnsavedChanges(false)
1736+
onBack()
1737+
}
17311738
},
17321739
disabled: updatePermissionGroup.isPending,
17331740
}}

0 commit comments

Comments
 (0)