2024-12-16 01:25:47 +00:00
|
|
|
import * as React from "react";
|
|
|
|
|
import { ColumnDef } from "@tanstack/react-table";
|
|
|
|
|
|
|
|
|
|
import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react";
|
2025-06-07 10:27:37 +00:00
|
|
|
import { cn, getCookiesDecrypt } from "@/lib/utils";
|
2024-12-16 01:25:47 +00:00
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { format } from "date-fns";
|
2025-01-02 04:53:30 +00:00
|
|
|
import { Link } from "@/i18n/routing";
|
2025-06-25 14:05:02 +00:00
|
|
|
import Swal from "sweetalert2";
|
|
|
|
|
import { deleteMedia } from "@/service/content/content";
|
|
|
|
|
import { error, success } from "@/config/swal";
|
2024-12-16 01:25:47 +00:00
|
|
|
|
2025-06-07 10:27:37 +00:00
|
|
|
const userLevelId = getCookiesDecrypt("ulie");
|
|
|
|
|
|
2024-12-16 01:25:47 +00:00
|
|
|
const columns: ColumnDef<any>[] = [
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "no",
|
|
|
|
|
header: "No",
|
|
|
|
|
cell: ({ row }) => (
|
|
|
|
|
<div className="flex items-center gap-5">
|
|
|
|
|
<div className="flex-1 text-start">
|
|
|
|
|
<h4 className="text-sm font-medium text-default-600 whitespace-nowrap mb-1">
|
|
|
|
|
{row.getValue("no")}
|
|
|
|
|
</h4>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "title",
|
|
|
|
|
header: "Title",
|
|
|
|
|
cell: ({ row }: { row: { getValue: (key: string) => string } }) => {
|
|
|
|
|
const title: string = row.getValue("title");
|
|
|
|
|
return (
|
|
|
|
|
<span className="">
|
|
|
|
|
{title.length > 50 ? `${title.slice(0, 10)}...` : title}
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "createdAt",
|
|
|
|
|
header: "Upload Date",
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
const createdAt = row.getValue("createdAt") as
|
|
|
|
|
| string
|
|
|
|
|
| number
|
|
|
|
|
| undefined;
|
|
|
|
|
|
|
|
|
|
const formattedDate =
|
|
|
|
|
createdAt && !isNaN(new Date(createdAt).getTime())
|
|
|
|
|
? format(new Date(createdAt), "dd-MM-yyyy HH:mm:ss")
|
|
|
|
|
: "-";
|
|
|
|
|
return <span className="whitespace-nowrap">{formattedDate}</span>;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "fileTypeName",
|
|
|
|
|
header: "Type Content",
|
|
|
|
|
cell: ({ row }: { row: { getValue: (key: string) => string } }) => {
|
|
|
|
|
const title: string = row.getValue("fileTypeName");
|
|
|
|
|
return (
|
|
|
|
|
<span className="whitespace-nowrap">
|
|
|
|
|
{title.length > 50 ? `${title.slice(0, 30)}...` : title}
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
// {
|
|
|
|
|
// accessorKey: "creatorGroup",
|
|
|
|
|
// header: "Creator Group",
|
|
|
|
|
// cell: ({ row }) => (
|
|
|
|
|
// <span className="whitespace-nowrap">{row.getValue("creatorGroup")}</span>
|
|
|
|
|
// ),
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// accessorKey: "creatorName",
|
|
|
|
|
// header: "Sumber",
|
|
|
|
|
// cell: ({ row }) => (
|
|
|
|
|
// <span className="whitespace-nowrap">{row.getValue("creatorName")}</span>
|
|
|
|
|
// ),
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// accessorKey: "publishedOn",
|
|
|
|
|
// header: "Published",
|
|
|
|
|
// cell: ({ row }) => {
|
|
|
|
|
// const isPublish = row.original.isPublish;
|
|
|
|
|
// const isPublishOnPolda = row.original.isPublishOnPolda;
|
|
|
|
|
|
|
|
|
|
// let displayText = "-";
|
|
|
|
|
// if (isPublish && !isPublishOnPolda) {
|
|
|
|
|
// displayText = "Mabes";
|
|
|
|
|
// } else if (isPublish && isPublishOnPolda) {
|
|
|
|
|
// displayText = "Mabes & Polda";
|
|
|
|
|
// } else if (!isPublish && isPublishOnPolda) {
|
|
|
|
|
// displayText = "Polda";
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// return (
|
|
|
|
|
// <div className="text-center whitespace-nowrap" title={displayText}>
|
|
|
|
|
// {displayText}
|
|
|
|
|
// </div>
|
|
|
|
|
// );
|
|
|
|
|
// },
|
|
|
|
|
// },
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
accessorKey: "statusName",
|
|
|
|
|
header: "Status",
|
|
|
|
|
cell: ({ row }) => {
|
|
|
|
|
// Mendapatkan nilai statusName
|
|
|
|
|
const statusName = row.getValue<string>("statusName");
|
|
|
|
|
|
|
|
|
|
// Mapping warna berdasarkan statusName
|
|
|
|
|
const colorMapping: Record<string, string> = {
|
|
|
|
|
"Menunggu Review": "text-orange-500 border-orange-500",
|
|
|
|
|
Diterima: "text-green-500 border-green-500",
|
|
|
|
|
"Minta Update": "text-blue-500 border-blue-500",
|
|
|
|
|
Ditolak: "text-red-500 border-red-500",
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-07 10:27:37 +00:00
|
|
|
const colors = [
|
|
|
|
|
"text-orange-500 border-orange-500",
|
|
|
|
|
"text-orange-500 border-orange-500",
|
|
|
|
|
"text-green-500 border-green-500",
|
|
|
|
|
"text-blue-500 border-blue-500",
|
|
|
|
|
"text-red-500 border-red-500",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const status =
|
|
|
|
|
Number(row.original?.statusId) == 2 &&
|
|
|
|
|
row.original?.reviewedAtLevel !== null &&
|
|
|
|
|
!row.original?.reviewedAtLevel?.includes(`:${userLevelId}:`) &&
|
|
|
|
|
Number(row.original?.creatorGroupLevelId) != Number(userLevelId)
|
|
|
|
|
? "1"
|
|
|
|
|
: row.original?.statusId;
|
|
|
|
|
|
2024-12-16 01:25:47 +00:00
|
|
|
// Mendapatkan kelas warna dari mapping, default ke abu-abu jika tidak ditemukan
|
|
|
|
|
const buttonClass =
|
2025-06-07 10:27:37 +00:00
|
|
|
colors[Number(status)] || "text-gray-500 border-gray-500";
|
|
|
|
|
// const buttonClass =
|
|
|
|
|
// colorMapping[statusName] || "text-gray-500 border-gray-500";
|
2024-12-16 01:25:47 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<Button
|
|
|
|
|
size="sm"
|
|
|
|
|
variant="outline"
|
|
|
|
|
className={`btn btn-sm pill-btn ml-1 ${buttonClass}`}
|
|
|
|
|
>
|
2025-06-07 10:27:37 +00:00
|
|
|
{(Number(row.original?.statusId) == 2 &&
|
|
|
|
|
!row.original?.reviewedAtLevel !== null &&
|
|
|
|
|
!row.original?.reviewedAtLevel?.includes(
|
|
|
|
|
`:${Number(userLevelId)}:`
|
|
|
|
|
) &&
|
|
|
|
|
Number(row.original?.creatorGroupLevelId) !=
|
|
|
|
|
Number(userLevelId)) ||
|
|
|
|
|
(Number(row.original?.statusId) == 1 &&
|
|
|
|
|
Number(row.original?.needApprovalFromLevel) ==
|
|
|
|
|
Number(userLevelId))
|
|
|
|
|
? "Menunggu Review"
|
|
|
|
|
: row.original?.statusName}{" "}
|
2024-12-16 01:25:47 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-06-25 14:05:02 +00:00
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-21 09:19:02 +00:00
|
|
|
const [isMabesApprover, setIsMabesApprover] = React.useState(false);
|
|
|
|
|
const userId = getCookiesDecrypt("uie");
|
|
|
|
|
const userLevelId = getCookiesDecrypt("ulie");
|
|
|
|
|
const roleId = getCookiesDecrypt("urie");
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (userLevelId !== undefined && roleId !== undefined) {
|
|
|
|
|
setIsMabesApprover(Number(userLevelId) == 216 && Number(roleId) == 3);
|
|
|
|
|
}
|
|
|
|
|
}, [userLevelId, roleId]);
|
|
|
|
|
|
2025-06-25 14:05:02 +00:00
|
|
|
return (
|
|
|
|
|
<DropdownMenu>
|
|
|
|
|
<DropdownMenuTrigger asChild>
|
|
|
|
|
<Button
|
|
|
|
|
size="icon"
|
|
|
|
|
className="bg-transparent ring-offset-transparent hover:bg-transparent hover:ring-0 hover:ring-transparent"
|
|
|
|
|
>
|
|
|
|
|
<span className="sr-only">Buka menu</span>
|
|
|
|
|
<MoreVertical className="h-4 w-4 text-default-800" />
|
|
|
|
|
</Button>
|
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
|
<DropdownMenuContent className="p-0" align="end">
|
|
|
|
|
<Link
|
|
|
|
|
href={`/contributor/content/${fileTypeSegment}/detail/${row.original.id}`}
|
|
|
|
|
>
|
|
|
|
|
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
|
|
|
|
<Eye className="w-4 h-4 me-1.5" />
|
|
|
|
|
Lihat
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</Link>
|
2025-07-21 09:19:02 +00:00
|
|
|
|
|
|
|
|
{(Number(row.original.uploadedById) === Number(userId) ||
|
|
|
|
|
isMabesApprover) && (
|
|
|
|
|
<Link
|
|
|
|
|
href={`/contributor/content/${fileTypeSegment}/update/${row.original.id}`}
|
|
|
|
|
>
|
|
|
|
|
<DropdownMenuItem className="p-2 border-b text-default-700 group focus:bg-default focus:text-primary-foreground rounded-none">
|
|
|
|
|
<SquarePen className="w-4 h-4 me-1.5" />
|
|
|
|
|
Edit
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{(row.original.uploadedById === userId || isMabesApprover) && (
|
|
|
|
|
<DropdownMenuItem
|
|
|
|
|
onClick={() => handleDeleteMedia(row.original.id)}
|
|
|
|
|
className="p-2 border-b text-destructive bg-destructive/30 focus:bg-destructive focus:text-destructive-foreground rounded-none"
|
|
|
|
|
>
|
|
|
|
|
<Trash2 className="w-4 h-4 me-1.5" />
|
|
|
|
|
Hapus
|
|
|
|
|
</DropdownMenuItem>
|
|
|
|
|
)}
|
2025-06-25 14:05:02 +00:00
|
|
|
</DropdownMenuContent>
|
|
|
|
|
</DropdownMenu>
|
|
|
|
|
);
|
|
|
|
|
},
|
2024-12-16 01:25:47 +00:00
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export default columns;
|