From 7ab83a4f66bc139069b09867ba83ad4690d4d82d Mon Sep 17 00:00:00 2001 From: Ardeman Date: Wed, 12 Mar 2025 21:19:41 +0800 Subject: [PATCH] feat: implement toast notifications for delete actions in dashboard pages --- app/components/ui/button.tsx | 4 +- app/pages/dashboard-advertisements/index.tsx | 111 +++++++++++++++++-- app/pages/dashboard-categories/index.tsx | 4 +- app/pages/dashboard-contents/index.tsx | 4 +- app/pages/dashboard-plan-subscribe/index.tsx | 4 +- app/pages/dashboard-tags/index.tsx | 4 +- app/pages/form-tag/index.tsx | 2 + 7 files changed, 114 insertions(+), 19 deletions(-) diff --git a/app/components/ui/button.tsx b/app/components/ui/button.tsx index 798fa4f..c4fc7e5 100644 --- a/app/components/ui/button.tsx +++ b/app/components/ui/button.tsx @@ -11,6 +11,8 @@ const buttonVariants = cva( variant: { newsPrimary: 'bg-[#2E2F7C] text-white text-lg hover:bg-[#4C5CA0] hover:shadow transition active:bg-[#6970B4]', + newsDanger: + 'bg-red-500 text-white text-lg hover:bg-red-600 hover:shadow transition active:bg-red-700', newsPrimaryOutline: 'border-[3px] bg-[#2E2F7C] border-white text-white text-lg hover:bg-[#4C5CA0] hover:shadow-lg active:shadow-2xl transition active:bg-[#6970B4]', newsSecondary: @@ -21,7 +23,7 @@ const buttonVariants = cva( size: { default: 'h-[50px] w-[150px]', block: 'h-[50px] w-full', - icon: 'h-9 w-9', + icon: 'h-9 w-9 rounded-full', sm: 'h-8 rounded-md px-3 text-xs', lg: 'h-10 rounded-md px-8', fit: 'w-fit', diff --git a/app/pages/dashboard-advertisements/index.tsx b/app/pages/dashboard-advertisements/index.tsx index 6bad15e..c7ebf92 100644 --- a/app/pages/dashboard-advertisements/index.tsx +++ b/app/pages/dashboard-advertisements/index.tsx @@ -1,7 +1,18 @@ +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' -import { Link, useRouteLoaderData } from 'react-router' +import { useEffect, useState } from 'react' +import toast from 'react-hot-toast' +import { Link, useFetcher, useRouteLoaderData } from 'react-router' +import type { TAdResponse } from '~/apis/common/get-ads' import { Button } from '~/components/ui/button' import { UiTable } from '~/components/ui/table' import { TitleDashboard } from '~/components/ui/title-dashboard' @@ -12,6 +23,22 @@ export const AdvertisementsPage = () => { 'routes/_admin.lg-admin._dashboard.advertisements._index', ) const { adsData: dataTable } = loaderData || {} + const [selectedId, setSelectedId] = useState() + const fetcher = useFetcher() + + useEffect(() => { + if (fetcher.data?.success === false) { + toast.error(fetcher.data?.message) + return + } + + if (fetcher.data?.success === true) { + setSelectedId(undefined) + toast.success('Banner iklan berhasil dihapus!') + return + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [fetcher.data]) const dataColumns: ConfigColumns[] = [ { @@ -42,15 +69,25 @@ export const AdvertisementsPage = () => { /> ) }, - 3: (value: string) => ( - + 3: (value: string, _type: unknown, data: TAdResponse) => ( +
+ + +
), } @@ -76,6 +113,60 @@ export const AdvertisementsPage = () => { slots={dataSlot} title="Daftar Banner Iklan" /> + + 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 e1114b3..46e8c97 100644 --- a/app/pages/dashboard-categories/index.tsx +++ b/app/pages/dashboard-categories/index.tsx @@ -56,8 +56,8 @@ export const CategoriesPage = () => { ), 3: (value: string) => (