@@ -588,8 +588,12 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
588588 reportFailure : false ,
589589 } ) ;
590590 const { environments } = useEnvironments ( ) ;
591- const persistServerSettings = async ( request : Parameters < typeof persist > [ 0 ] ) => {
591+ const persistServerSettings = async (
592+ request : Parameters < typeof persist > [ 0 ] ,
593+ onFailed ?: ( ) => void ,
594+ ) => {
592595 const result = await persist ( request ) ;
596+ if ( result . _tag === "Failure" ) onFailed ?.( ) ;
593597 if ( result . _tag === "Failure" && ! isAtomCommandInterrupted ( result ) ) {
594598 const label =
595599 environments . find ( ( environment ) => environment . environmentId === request . environmentId )
@@ -604,7 +608,10 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
604608 return result ;
605609 } ;
606610 const sharedSettingsSyncTargetIds = useSharedSettingsSyncTargetIds ( true ) ;
607- const updateSettings = ( patch : UnifiedSettingsPatch ) => {
611+ const updateSettings = (
612+ patch : UnifiedSettingsPatch ,
613+ options ?: { readonly onFailed ?: ( ) => void } ,
614+ ) => {
608615 const { serverPatch, clientPatch } = splitPatch ( patch ) ;
609616
610617 const canWriteServerPatch =
@@ -613,6 +620,7 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
613620 readEnvironmentScope ( environmentId , scope ) ,
614621 ) ;
615622 if ( Object . keys ( serverPatch ) . length > 0 && ! canWriteServerPatch ) {
623+ options ?. onFailed ?.( ) ;
616624 toastManager . add ( {
617625 type : "warning" ,
618626 title : "Setting not saved" ,
@@ -622,18 +630,20 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
622630 if ( Object . keys ( serverPatch ) . length > 0 && canWriteServerPatch ) {
623631 const { sharedPatch, localPatch } = splitSharedServerPatch ( serverPatch ) ;
624632 // Dropping the write silently leaves the control looking saved.
625- const warnUnsaved = ( description = PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE ) =>
626- toastManager . add ( {
633+ const warnUnsaved = ( description = PRIMARY_SETTINGS_UNAVAILABLE_MESSAGE ) => {
634+ options ?. onFailed ?.( ) ;
635+ return toastManager . add ( {
627636 type : "warning" ,
628637 title : "Setting not saved" ,
629638 description,
630639 } ) ;
640+ } ;
631641 if ( Object . keys ( localPatch ) . length > 0 ) {
632642 if ( environmentId ) {
633- void persistServerSettings ( {
634- environmentId,
635- input : { patch : localPatch } ,
636- } ) ;
643+ void persistServerSettings (
644+ { environmentId, input : { patch : localPatch } } ,
645+ options ?. onFailed ,
646+ ) ;
637647 } else {
638648 warnUnsaved ( ) ;
639649 }
@@ -688,6 +698,12 @@ function useUpdateSettingsTarget(environmentId: EnvironmentId | null) {
688698 result : await persist ( request ) ,
689699 } ) ) ,
690700 ) . then ( ( outcomes ) => {
701+ if (
702+ deniedLabels . length > 0 ||
703+ outcomes . some ( ( { result } ) => result . _tag === "Failure" )
704+ ) {
705+ options ?. onFailed ?.( ) ;
706+ }
691707 const failures = outcomes . flatMap ( ( { label, result } ) => {
692708 if ( result . _tag !== "Failure" || isAtomCommandInterrupted ( result ) ) return [ ] ;
693709 const error = squashAtomCommandFailure ( result ) ;
0 commit comments