diff --git a/src/components/ModForm.tsx b/src/components/ModForm.tsx index 22e750d..1db8b96 100644 --- a/src/components/ModForm.tsx +++ b/src/components/ModForm.tsx @@ -31,6 +31,7 @@ import { LoadingSpinner } from './LoadingSpinner' import { NDKEvent } from '@nostr-dev-kit/ndk' import { OriginalAuthor } from './OriginalAuthor' import { CategoryAutocomplete } from './CategoryAutocomplete' +import { AlertPopup } from './AlertPopup' interface FormErrors { game?: string @@ -176,6 +177,27 @@ export const ModForm = ({ existingModData }: ModFormProps) => { [] ) + const [showConfirmPopup, setShowConfirmPopup] = useState(false) + const handleReset = () => { + setShowConfirmPopup(true) + } + const handleResetConfirm = (confirm: boolean) => { + setShowConfirmPopup(false) + + // Cancel if not confirmed + if (!confirm) return + + // Editing + if (existingModData) { + // Reset fields to the original existing data + setFormState(initializeFormState(existingModData)) + return + } + + // New - set form state to the initial (clear form state) + setFormState(initializeFormState()) + } + const handlePublish = async () => { setIsPublishing(true) @@ -563,6 +585,14 @@ export const ModForm = ({ existingModData }: ModFormProps) => { )}
+
+ {showConfirmPopup && ( + setShowConfirmPopup(false)} + header={'Are you sure?'} + label={ + existingModData + ? `Are you sure you want to clear all changes?` + : `Are you sure you want to clear all field data?` + } + /> + )} ) } diff --git a/src/styles/write.css b/src/styles/write.css index 7ac363d..412bcec 100644 --- a/src/styles/write.css +++ b/src/styles/write.css @@ -11,5 +11,5 @@ flex-direction: row; justify-content: end; align-items: center; + gap: 25px; } -