From 850f42e99d55c30b6fa127761af6f8e368912f52 Mon Sep 17 00:00:00 2001 From: Ardeman Date: Wed, 12 Mar 2025 21:30:30 +0800 Subject: [PATCH] feat: add delete confirmation dialog for advertisements --- .../dialog-delete.tsx | 82 +++++++++++++++++++ app/pages/dashboard-advertisements/index.tsx | 76 ++--------------- app/pages/dashboard-categories/index.tsx | 1 + 3 files changed, 92 insertions(+), 67 deletions(-) create mode 100644 app/pages/dashboard-advertisements/dialog-delete.tsx diff --git a/app/pages/dashboard-advertisements/dialog-delete.tsx b/app/pages/dashboard-advertisements/dialog-delete.tsx new file mode 100644 index 0000000..38cb4fa --- /dev/null +++ b/app/pages/dashboard-advertisements/dialog-delete.tsx @@ -0,0 +1,82 @@ +import { + Description, + Dialog, + DialogBackdrop, + DialogPanel, + DialogTitle, +} from '@headlessui/react' +import type { Dispatch, SetStateAction } from 'react' +import { Link, useFetcher } from 'react-router' + +import type { TAdResponse } from '~/apis/common/get-ads' +import { Button } from '~/components/ui/button' + +type TProperties = { + selectedAds?: TAdResponse + setSelectedAds: Dispatch> +} + +export const DialogDelete = (properties: TProperties) => { + const { selectedAds, setSelectedAds } = properties || {} + const fetcher = useFetcher() + + return ( + { + if (fetcher.state === 'idle') { + setSelectedAds(undefined) + } + }} + className="relative z-50" + transition + > + +
+ + + Anda akan menghapus banner berikut? + + + {selectedAds?.image_url} + + +
+ + + +
+
+
+
+ ) +} diff --git a/app/pages/dashboard-advertisements/index.tsx b/app/pages/dashboard-advertisements/index.tsx index 3aa0d28..09ec703 100644 --- a/app/pages/dashboard-advertisements/index.tsx +++ b/app/pages/dashboard-advertisements/index.tsx @@ -1,10 +1,3 @@ -import { - Description, - Dialog, - DialogBackdrop, - DialogPanel, - DialogTitle, -} from '@headlessui/react' import { PencilSquareIcon, TrashIcon } from '@heroicons/react/20/solid' import type { ConfigColumns } from 'datatables.net-dt' import type { DataTableSlots } from 'datatables.net-react' @@ -18,12 +11,14 @@ import { UiTable } from '~/components/ui/table' import { TitleDashboard } from '~/components/ui/title-dashboard' import type { loader } from '~/routes/_admin.lg-admin._dashboard.advertisements._index' +import { DialogDelete } from './dialog-delete' + export const AdvertisementsPage = () => { const loaderData = useRouteLoaderData( 'routes/_admin.lg-admin._dashboard.advertisements._index', ) const { adsData: dataTable } = loaderData || {} - const [selectedId, setSelectedId] = useState() + const [selectedAds, setSelectedAds] = useState() const fetcher = useFetcher() useEffect(() => { @@ -33,7 +28,7 @@ export const AdvertisementsPage = () => { } if (fetcher.data?.success === true) { - setSelectedId(undefined) + setSelectedAds(undefined) toast.success('Banner iklan berhasil dihapus!') return } @@ -83,7 +78,7 @@ export const AdvertisementsPage = () => { type="button" size="icon" variant="newsDanger" - onClick={() => setSelectedId(data)} + onClick={() => setSelectedAds(data)} > @@ -114,63 +109,10 @@ export const AdvertisementsPage = () => { title="Daftar Banner Iklan" /> - { - if (fetcher.state === 'idle') { - setSelectedId(undefined) - } - }} - className="relative z-50" - transition - > - -
- - - Anda akan menghapus banner berikut? - - - {selectedId?.image_url} - - -
- - - -
-
-
-
+ ) } diff --git a/app/pages/dashboard-categories/index.tsx b/app/pages/dashboard-categories/index.tsx index 46e8c97..653d3f8 100644 --- a/app/pages/dashboard-categories/index.tsx +++ b/app/pages/dashboard-categories/index.tsx @@ -7,6 +7,7 @@ import { Button } from '~/components/ui/button' import { UiTable } from '~/components/ui/table' import { TitleDashboard } from '~/components/ui/title-dashboard' import type { loader } from '~/routes/_admin.lg-admin._dashboard' + export const CategoriesPage = () => { const loaderData = useRouteLoaderData( 'routes/_admin.lg-admin._dashboard',