feat: add toast notifications for delete actions and update button titles in advertisements page

This commit is contained in:
Ardeman
2025-03-12 21:38:44 +08:00
parent 850f42e99d
commit d63884dde1
2 changed files with 26 additions and 22 deletions
@@ -5,7 +5,8 @@ import {
DialogPanel,
DialogTitle,
} from '@headlessui/react'
import type { Dispatch, SetStateAction } from 'react'
import { useEffect, type Dispatch, type SetStateAction } from 'react'
import toast from 'react-hot-toast'
import { Link, useFetcher } from 'react-router'
import type { TAdResponse } from '~/apis/common/get-ads'
@@ -20,6 +21,20 @@ export const DialogDelete = (properties: TProperties) => {
const { selectedAds, setSelectedAds } = properties || {}
const fetcher = useFetcher()
useEffect(() => {
if (fetcher.data?.success === false) {
toast.error(fetcher.data?.message)
return
}
if (fetcher.data?.success === true) {
setSelectedAds(undefined)
toast.success('Banner iklan berhasil dihapus!')
return
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [fetcher.data])
return (
<Dialog
open={!!selectedAds}