From fbd5586ae6a5632361003cf29df84ab4851b7b41 Mon Sep 17 00:00:00 2001 From: Sabda Yagra Date: Wed, 25 Jun 2025 21:05:02 +0700 Subject: [PATCH] fixing --- .../content/image/components/table-image.tsx | 20 +-- .../routine-task/components/columns.tsx | 142 +++++++++++------- .../routine-task/components/content-table.tsx | 8 +- 3 files changed, 104 insertions(+), 66 deletions(-) diff --git a/app/[locale]/(protected)/contributor/content/image/components/table-image.tsx b/app/[locale]/(protected)/contributor/content/image/components/table-image.tsx index 1399f44c..c81407c0 100644 --- a/app/[locale]/(protected)/contributor/content/image/components/table-image.tsx +++ b/app/[locale]/(protected)/contributor/content/image/components/table-image.tsx @@ -164,8 +164,8 @@ const TableImage = () => { setSelectedCategories( (prev: any) => prev.includes(categoryId) - ? prev.filter((id: any) => id !== categoryId) // Hapus jika sudah dipilih - : [...prev, categoryId] // Tambahkan jika belum dipilih + ? prev.filter((id: any) => id !== categoryId) + : [...prev, categoryId] ); // Perbarui filter kategori @@ -199,8 +199,8 @@ const TableImage = () => { statusFilter?.sort().join(",").includes("1") ? userLevelId : "", filterByCreator, filterBySource, - formattedStartDate, // Pastikan format sesuai - formattedEndDate, // Pastikan format sesuai + formattedStartDate, + formattedEndDate, search, filterByCreatorGroup, locale == "en" @@ -221,16 +221,16 @@ const TableImage = () => { } const handleSearch = (e: React.ChangeEvent) => { - setSearch(e.target.value); // Perbarui state search - table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel + setSearch(e.target.value); + table.getColumn("judul")?.setFilterValue(e.target.value); }; const handleSearchFilterBySource = ( e: React.ChangeEvent ) => { const value = e.target.value; - setFilterBySource(value); // Perbarui state filter - fetchData(); // Panggil ulang data dengan filter baru + setFilterBySource(value); + fetchData(); }; function handleStatusCheckboxChange(value: any) { @@ -245,8 +245,8 @@ const TableImage = () => { e: React.ChangeEvent ) => { const value = e.target.value; - setFilterByCreator(value); // Perbarui state filter - fetchData(); // Panggil ulang data dengan filter baru + setFilterByCreator(value); + fetchData(); }; return ( diff --git a/app/[locale]/(protected)/dashboard/routine-task/components/columns.tsx b/app/[locale]/(protected)/dashboard/routine-task/components/columns.tsx index 1089a6ba..0a6c4caf 100644 --- a/app/[locale]/(protected)/dashboard/routine-task/components/columns.tsx +++ b/app/[locale]/(protected)/dashboard/routine-task/components/columns.tsx @@ -12,6 +12,9 @@ import { import { Button } from "@/components/ui/button"; import { format } from "date-fns"; import { Link } from "@/i18n/routing"; +import Swal from "sweetalert2"; +import { deleteMedia } from "@/service/content/content"; +import { error, success } from "@/config/swal"; const userLevelId = getCookiesDecrypt("ulie"); @@ -168,61 +171,96 @@ const columns: ColumnDef[] = [ ); }, }, - { - id: "actions", - accessorKey: "action", - header: "Actions", - enableHiding: false, - cell: ({ row }) => { - // Menentukan segmen path berdasarkan fileTypeId - let fileTypeSegment; - switch (row.original.fileTypeId) { - case 1: - fileTypeSegment = "image"; - break; - case 2: - fileTypeSegment = "video"; - break; - case 3: - fileTypeSegment = "teks"; // Asumsi 'teks' untuk fileTypeId 3 - break; - case 4: - fileTypeSegment = "audio"; // Asumsi 'audio' untuk fileTypeId 4 - break; - default: - fileTypeSegment = row.original.fileTypeId; // Fallback jika tidak ada yang cocok - } + { + id: "actions", + accessorKey: "action", + header: "Actions", + enableHiding: false, + cell: ({ row }) => { + // Menentukan segmen path berdasarkan fileTypeId + let fileTypeSegment; + switch (row.original.fileTypeId) { + case 1: + fileTypeSegment = "image"; + break; + case 2: + fileTypeSegment = "video"; + break; + case 3: + fileTypeSegment = "teks"; // Asumsi 'teks' untuk fileTypeId 3 + break; + case 4: + fileTypeSegment = "audio"; // Asumsi 'audio' untuk fileTypeId 4 + break; + default: + fileTypeSegment = row.original.fileTypeId; // Fallback jika tidak ada yang cocok + } - return ( - - - - - - {/* Link "View" yang diperbarui dengan logika kondisional untuk fileTypeSegment */} - - - - Lihat + async function doDelete(id: any) { + // loading(); + const data = { + id, + }; + + const response = await deleteMedia(data); + + if (response?.error) { + error(response.message); + return false; + } + Swal.fire("Berhasil", "Konten telah dihapus.", "success"); + window.location.reload(); + } + + const handleDeleteMedia = (id: any) => { + Swal.fire({ + title: "Hapus Data", + text: "", + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#3085d6", + confirmButtonColor: "#d33", + confirmButtonText: "Hapus", + }).then((result) => { + if (result.isConfirmed) { + doDelete(id); + } + }); + }; + + return ( + + + + + + {/* Link "View" yang diperbarui dengan logika kondisional untuk fileTypeSegment */} + + + + Lihat + + + handleDeleteMedia(row.original.id)} + className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none" + > + + Hapus - - - - Hapus - - - - ); + + + ); + }, }, -}, ]; export default columns; diff --git a/app/[locale]/(protected)/dashboard/routine-task/components/content-table.tsx b/app/[locale]/(protected)/dashboard/routine-task/components/content-table.tsx index befee683..6bfc7860 100644 --- a/app/[locale]/(protected)/dashboard/routine-task/components/content-table.tsx +++ b/app/[locale]/(protected)/dashboard/routine-task/components/content-table.tsx @@ -165,8 +165,8 @@ const ContentTable = () => { } const handleSearch = (e: React.ChangeEvent) => { - setSearch(e.target.value); // Perbarui state search - table.getColumn("judul")?.setFilterValue(e.target.value); // Set filter tabel + setSearch(e.target.value); + table.getColumn("judul")?.setFilterValue(e.target.value); }; return ( @@ -216,8 +216,8 @@ const ContentTable = () => { Filter - Image - Video + Foto + Audio Visual Teks Audio