feat(mod): clear form changes with confirm alert popup
This commit is contained in:
parent
96fe99669b
commit
5877912cea
@ -31,6 +31,7 @@ import { LoadingSpinner } from './LoadingSpinner'
|
|||||||
import { NDKEvent } from '@nostr-dev-kit/ndk'
|
import { NDKEvent } from '@nostr-dev-kit/ndk'
|
||||||
import { OriginalAuthor } from './OriginalAuthor'
|
import { OriginalAuthor } from './OriginalAuthor'
|
||||||
import { CategoryAutocomplete } from './CategoryAutocomplete'
|
import { CategoryAutocomplete } from './CategoryAutocomplete'
|
||||||
|
import { AlertPopup } from './AlertPopup'
|
||||||
|
|
||||||
interface FormErrors {
|
interface FormErrors {
|
||||||
game?: string
|
game?: string
|
||||||
@ -176,6 +177,27 @@ export const ModForm = ({ existingModData }: ModFormProps) => {
|
|||||||
[]
|
[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const [showConfirmPopup, setShowConfirmPopup] = useState<boolean>(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 () => {
|
const handlePublish = async () => {
|
||||||
setIsPublishing(true)
|
setIsPublishing(true)
|
||||||
|
|
||||||
@ -563,6 +585,14 @@ export const ModForm = ({ existingModData }: ModFormProps) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div className='IBMSMSMBS_WriteAction'>
|
<div className='IBMSMSMBS_WriteAction'>
|
||||||
|
<button
|
||||||
|
className='btn btnMain'
|
||||||
|
type='button'
|
||||||
|
onClick={handleReset}
|
||||||
|
disabled={isPublishing}
|
||||||
|
>
|
||||||
|
{existingModData ? 'Reset' : 'Clear fields'}
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
className='btn btnMain'
|
className='btn btnMain'
|
||||||
type='button'
|
type='button'
|
||||||
@ -572,6 +602,18 @@ export const ModForm = ({ existingModData }: ModFormProps) => {
|
|||||||
Publish
|
Publish
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{showConfirmPopup && (
|
||||||
|
<AlertPopup
|
||||||
|
handleConfirm={handleResetConfirm}
|
||||||
|
handleClose={() => 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?`
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -11,5 +11,5 @@
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: end;
|
justify-content: end;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
gap: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user