Skip to content

Commit 92ac45a

Browse files
committed
Restore old value if clear-guideline fails
1 parent 004f11b commit 92ac45a

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

‎routes/content-guidelines/components/guideline-accordion-form.tsx‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,27 @@ export default function GuidelineAccordionForm( {
9898
const handleClearClick = () => setShowClearConfirmation( true );
9999

100100
const handleClearConfirm = () => {
101+
const oldValue = draft;
102+
101103
// We need to pass an empty string to remove the guideline.
102104
// This is because the API will only remove the guideline if the value is an empty string.
103105
setGuideline( slug, '' );
104-
setDraft( '' );
105106
setLoading( true );
106107
saveContentGuidelines()
107108
.then( () => {
108109
setError( null );
109-
setShowClearConfirmation( false );
110110
createSuccessNotice( __( 'Guidelines cleared.' ), {
111111
type: 'snackbar',
112112
} );
113113
} )
114-
.catch( ( e: Error ) => setError( e.message ) )
115-
.finally( () => setLoading( false ) );
114+
.catch( ( e: Error ) => {
115+
setError( e.message );
116+
setGuideline( slug, oldValue );
117+
} )
118+
.finally( () => {
119+
setLoading( false );
120+
setShowClearConfirmation( false );
121+
} );
116122
};
117123

118124
return (

0 commit comments

Comments
 (0)