feat(blog): clear form changes with confirm alert popup
This commit is contained in:
parent
5877912cea
commit
b71e503c8f
@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react'
|
import { useRef, useState } from 'react'
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
useActionData,
|
useActionData,
|
||||||
@ -24,6 +24,7 @@ import { EditorContent, useEditor } from '@tiptap/react'
|
|||||||
import StarterKit from '@tiptap/starter-kit'
|
import StarterKit from '@tiptap/starter-kit'
|
||||||
import Link from '@tiptap/extension-link'
|
import Link from '@tiptap/extension-link'
|
||||||
import Image from '@tiptap/extension-image'
|
import Image from '@tiptap/extension-image'
|
||||||
|
import { AlertPopup } from 'components/AlertPopup'
|
||||||
|
|
||||||
export const WritePage = () => {
|
export const WritePage = () => {
|
||||||
const userState = useAppSelector((state) => state.user)
|
const userState = useAppSelector((state) => state.user)
|
||||||
@ -53,6 +54,20 @@ export const WritePage = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const formRef = useRef<HTMLFormElement>(null)
|
||||||
|
const [showConfirmPopup, setShowConfirmPopup] = useState<boolean>(false)
|
||||||
|
const handleReset = () => {
|
||||||
|
setShowConfirmPopup(true)
|
||||||
|
}
|
||||||
|
const handleResetConfirm = (confirm: boolean) => {
|
||||||
|
setShowConfirmPopup(false)
|
||||||
|
|
||||||
|
// Cancel if not confirmed
|
||||||
|
if (!confirm) return
|
||||||
|
|
||||||
|
formRef.current?.reset()
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='InnerBodyMain'>
|
<div className='InnerBodyMain'>
|
||||||
<div className='ContainerMain'>
|
<div className='ContainerMain'>
|
||||||
@ -68,7 +83,11 @@ export const WritePage = () => {
|
|||||||
{navigation.state === 'submitting' && (
|
{navigation.state === 'submitting' && (
|
||||||
<LoadingSpinner desc='Publishing blog to relays' />
|
<LoadingSpinner desc='Publishing blog to relays' />
|
||||||
)}
|
)}
|
||||||
<Form className='IBMSMSMBS_Write' method={blog ? 'put' : 'post'}>
|
<Form
|
||||||
|
ref={formRef}
|
||||||
|
className='IBMSMSMBS_Write'
|
||||||
|
method={blog ? 'put' : 'post'}
|
||||||
|
>
|
||||||
<InputFieldUncontrolled
|
<InputFieldUncontrolled
|
||||||
label='Title'
|
label='Title'
|
||||||
name='title'
|
name='title'
|
||||||
@ -130,6 +149,17 @@ export const WritePage = () => {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<div className='IBMSMSMBS_WriteAction'>
|
<div className='IBMSMSMBS_WriteAction'>
|
||||||
|
<button
|
||||||
|
className='btn btnMain'
|
||||||
|
type='button'
|
||||||
|
onClick={handleReset}
|
||||||
|
disabled={
|
||||||
|
navigation.state === 'loading' ||
|
||||||
|
navigation.state === 'submitting'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{blog ? 'Reset' : 'Clear fields'}
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
className='btn btnMain'
|
className='btn btnMain'
|
||||||
type='submit'
|
type='submit'
|
||||||
@ -143,6 +173,18 @@ export const WritePage = () => {
|
|||||||
: 'Publish'}
|
: 'Publish'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{showConfirmPopup && (
|
||||||
|
<AlertPopup
|
||||||
|
handleConfirm={handleResetConfirm}
|
||||||
|
handleClose={() => 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?`
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
{userState.auth && userState.user?.pubkey && (
|
{userState.auth && userState.user?.pubkey && (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user