167 lines
4.9 KiB
TypeScript
167 lines
4.9 KiB
TypeScript
import * as React from "react";
|
|
import { ColumnDef } from "@tanstack/react-table";
|
|
|
|
import { Eye, MoreVertical, SquarePen, Trash2 } from "lucide-react";
|
|
import { cn } from "@/lib/utils";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuTrigger,
|
|
DropdownMenuItem,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { format } from "date-fns";
|
|
import { Link } from "@/components/navigation";
|
|
|
|
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="whitespace-nowrap">
|
|
{title.length > 50 ? `${title.slice(0, 30)}...` : title}
|
|
</span>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "categoryName",
|
|
header: "Category Name",
|
|
cell: ({ row }) => (
|
|
<span className="whitespace-nowrap">{row.getValue("categoryName")}</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: "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: "isDone",
|
|
header: "Status",
|
|
cell: ({ row }) => {
|
|
const isDone = row.getValue<boolean>("isDone");
|
|
return (
|
|
<div>
|
|
<Button
|
|
size="sm"
|
|
color="success"
|
|
variant="outline"
|
|
className={` btn btn-sm ${
|
|
isDone ? "btn-outline-success" : "btn-outline-primary"
|
|
} pill-btn ml-1`}
|
|
>
|
|
{isDone ? "Selesai" : "Aktif"}
|
|
</Button>
|
|
</div>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
id: "actions",
|
|
accessorKey: "action",
|
|
header: "Actions",
|
|
enableHiding: false,
|
|
cell: ({ row }) => {
|
|
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">Open menu</span>
|
|
<MoreVertical className="h-4 w-4 text-default-800" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent className="p-0" align="end">
|
|
<Link href={`/contributor/content/teks/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" />
|
|
View
|
|
</DropdownMenuItem>
|
|
</Link>
|
|
<Link href={`/contributor/content/teks/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>
|
|
<DropdownMenuItem 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" />
|
|
Delete
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
);
|
|
},
|
|
},
|
|
];
|
|
|
|
export default columns;
|