@@ -46,9 +46,8 @@ export default function AdviceEditPage() {
4646 const [ error , setError ] = useState < string | null > ( null ) ;
4747 const [ saving , setSaving ] = useState ( false ) ;
4848 const [ validationErrors , setValidationErrors ] = useState < ValidationError [ ] > ( [ ] ) ;
49- const [ showCancelModal , setShowCancelModal ] = useState ( false ) ;
49+ const [ showConfirmModal , setshowConfirmModal ] = useState ( false ) ;
5050 const [ locations , setLocations ] = useState < Array < { Key : string ; Name : string } > > ( [ ] ) ;
51- const [ editorResetKey , setEditorResetKey ] = useState ( 0 ) ;
5251 const { setAdviceTitle } = useBreadcrumb ( ) ;
5352
5453 // Form state
@@ -174,24 +173,17 @@ export default function AdviceEditPage() {
174173
175174 const handleCancel = ( ) => {
176175 if ( JSON . stringify ( formData ) !== JSON . stringify ( originalData ) ) {
177- setShowCancelModal ( true ) ;
176+ setshowConfirmModal ( true ) ;
178177 } else {
179- router . push ( `/advice/ ${ id } ` ) ;
178+ router . push ( `/advice` ) ;
180179 }
181180 } ;
182181
183182 const confirmCancel = ( ) => {
184- // Revert to original data
185- if ( originalData ) {
186- setFormData ( JSON . parse ( JSON . stringify ( originalData ) ) ) ;
187- setValidationErrors ( [ ] ) ;
188- setEditorResetKey ( prev => prev + 1 ) ; // Force editor remount
189- }
190- setShowCancelModal ( false ) ;
183+ setshowConfirmModal ( false ) ;
184+ router . push ( '/advice' ) ;
191185 } ;
192186
193- const hasChanges = JSON . stringify ( formData ) !== JSON . stringify ( originalData ) ;
194-
195187 // Show loading while checking authorization or fetching data
196188 if ( isChecking || loading ) {
197189 return < LoadingSpinner /> ;
@@ -268,7 +260,6 @@ export default function AdviceEditPage() {
268260 placeholder = "Enter the advice content..."
269261 minHeight = "400px"
270262 required
271- resetKey = { editorResetKey }
272263 />
273264 </ div >
274265
@@ -293,7 +284,7 @@ export default function AdviceEditPage() {
293284 < Button
294285 type = "submit"
295286 variant = "primary"
296- disabled = { saving || ! hasChanges }
287+ disabled = { saving }
297288 >
298289 { saving ? 'Saving...' : 'Save Changes' }
299290 </ Button >
@@ -304,13 +295,13 @@ export default function AdviceEditPage() {
304295
305296 { /* Cancel Confirmation Modal */ }
306297 < ConfirmModal
307- isOpen = { showCancelModal }
308- onClose = { ( ) => setShowCancelModal ( false ) }
298+ isOpen = { showConfirmModal }
299+ onClose = { ( ) => setshowConfirmModal ( false ) }
309300 onConfirm = { confirmCancel }
310301 title = "Close without saving?"
311302 message = "You may lose unsaved changes."
312303 variant = "warning"
313- confirmLabel = "Discard changes "
304+ confirmLabel = "Close Without Saving "
314305 cancelLabel = "Continue Editing"
315306 />
316307 </ div >
0 commit comments