From b71e503c8f817047d2d83d3e2c36da39bfe3b4b8 Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 12 Dec 2024 16:48:18 +0100 Subject: [PATCH] feat(blog): clear form changes with confirm alert popup --- src/pages/write/index.tsx | 46 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/src/pages/write/index.tsx b/src/pages/write/index.tsx index 870bb2b..26544e0 100644 --- a/src/pages/write/index.tsx +++ b/src/pages/write/index.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useRef, useState } from 'react' import { Form, useActionData, @@ -24,6 +24,7 @@ import { EditorContent, useEditor } from '@tiptap/react' import StarterKit from '@tiptap/starter-kit' import Link from '@tiptap/extension-link' import Image from '@tiptap/extension-image' +import { AlertPopup } from 'components/AlertPopup' export const WritePage = () => { const userState = useAppSelector((state) => state.user) @@ -53,6 +54,20 @@ export const WritePage = () => { } }) + const formRef = useRef(null) + const [showConfirmPopup, setShowConfirmPopup] = useState(false) + const handleReset = () => { + setShowConfirmPopup(true) + } + const handleResetConfirm = (confirm: boolean) => { + setShowConfirmPopup(false) + + // Cancel if not confirmed + if (!confirm) return + + formRef.current?.reset() + } + return (
@@ -68,7 +83,11 @@ export const WritePage = () => { {navigation.state === 'submitting' && ( )} -
+ { /> )}
+
+ {showConfirmPopup && ( + setShowConfirmPopup(false)} + header={'Are you sure?'} + label={ + blog + ? `Are you sure you want to clear all changes?` + : `Are you sure you want to clear all field data?` + } + /> + )}
{userState.auth && userState.user?.pubkey && (