unsaveChangeWarning hooks
This commit is contained in:
@@ -16,11 +16,13 @@ import { toast } from 'react-toastify'
|
||||
import { ErrorType } from '../../helpers/types'
|
||||
import { Pages } from '../../config/Pages'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useUnsavedChangesWarning } from '../../hooks/useUnsavedChangesWarning'
|
||||
const CreateBlog: FC = () => {
|
||||
|
||||
const { t } = useTranslation('global')
|
||||
const [file, setFile] = useState<File>()
|
||||
const [audioFile, setAudioFile] = useState<File>()
|
||||
const [isSaved, setIsSaved] = useState(false)
|
||||
const singleSlug = useSingleUpload()
|
||||
const audioUpload = useSingleUpload()
|
||||
|
||||
@@ -85,6 +87,7 @@ const CreateBlog: FC = () => {
|
||||
|
||||
createBlog.mutate(values, {
|
||||
onSuccess() {
|
||||
setIsSaved(true)
|
||||
toast.success(t('success'))
|
||||
navigate(Pages.blog.list)
|
||||
},
|
||||
@@ -95,6 +98,8 @@ const CreateBlog: FC = () => {
|
||||
},
|
||||
})
|
||||
|
||||
// استفاده از hook برای هشدار تغییرات ذخیره نشده
|
||||
useUnsavedChangesWarning(formik.dirty && !isSaved)
|
||||
|
||||
return (
|
||||
<div className='mt-4'>
|
||||
|
||||
@@ -16,12 +16,14 @@ import { toast } from 'react-toastify'
|
||||
import { ErrorType } from '../../helpers/types'
|
||||
import { Pages } from '../../config/Pages'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useUnsavedChangesWarning } from '../../hooks/useUnsavedChangesWarning'
|
||||
const UpdateBlog: FC = () => {
|
||||
|
||||
const { id } = useParams()
|
||||
const { t } = useTranslation('global')
|
||||
const [file, setFile] = useState<File>()
|
||||
const [audioFile, setAudioFile] = useState<File>()
|
||||
const [isSaved, setIsSaved] = useState(false)
|
||||
const singleSlug = useSingleUpload()
|
||||
const audioUpload = useSingleUpload()
|
||||
const getBlogDetail = useGetBlogDetail(id || '')
|
||||
@@ -84,6 +86,7 @@ const UpdateBlog: FC = () => {
|
||||
|
||||
updateBlog.mutate({ id: id || '', params: values }, {
|
||||
onSuccess() {
|
||||
setIsSaved(true)
|
||||
toast.success(t('success'))
|
||||
navigate(Pages.blog.list)
|
||||
},
|
||||
@@ -102,6 +105,9 @@ const UpdateBlog: FC = () => {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [getBlogDetail.data])
|
||||
|
||||
// استفاده از hook برای هشدار تغییرات ذخیره نشده
|
||||
useUnsavedChangesWarning(formik.dirty && !isSaved)
|
||||
|
||||
|
||||
return (
|
||||
<div className='mt-4'>
|
||||
|
||||
Reference in New Issue
Block a user