feat: add react-hot-toast in admin and news layouts, and update ads form handling

This commit is contained in:
Ardeman
2025-03-12 19:20:59 +08:00
parent 4a21b7d331
commit f026277a88
5 changed files with 36 additions and 7 deletions
+4 -7
View File
@@ -1,5 +1,6 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { useEffect, useState } from 'react'
import { useEffect } from 'react'
import toast from 'react-hot-toast'
import { useFetcher, useNavigate } from 'react-router'
import { RemixFormProvider, useRemixForm } from 'remix-hook-form'
import { z } from 'zod'
@@ -38,17 +39,16 @@ export const FormAdvertisementsPage = (properties: TProperties) => {
url: adData?.url || '',
},
})
const [error, setError] = useState<string>()
const { handleSubmit } = formMethods
useEffect(() => {
if (!fetcher.data?.success) {
setError(fetcher.data?.message)
toast.error(fetcher.data?.message)
return
}
toast.success(`Banner iklan berhasil ${adData ? 'diupdate' : 'dibuat'}!`)
navigate('/lg-admin/advertisements')
setError(undefined)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetcher])
@@ -63,9 +63,6 @@ export const FormAdvertisementsPage = (properties: TProperties) => {
action={`/actions/admin/advertisements/${adData ? 'update' : 'create'}`}
className="space-y-4"
>
{error && (
<div className="text-sm text-red-500 capitalize">{error}</div>
)}
<div className="flex items-end justify-between gap-4">
<InputFile
id="image"