184 lines
5.7 KiB
TypeScript
184 lines
5.7 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 { Link } from "@/components/navigation";
|
|
import { useTranslations } from "next-intl";
|
|
|
|
const useTableColumns = () => {
|
|
const t = useTranslations("Table"); // Panggil di dalam hook
|
|
|
|
const columns: ColumnDef<any>[] = [
|
|
{
|
|
accessorKey: "no",
|
|
header: t("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: t("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: "startDate",
|
|
header: t("start-date"),
|
|
cell: ({ row }) => (
|
|
<span className="whitespace-nowrap">{row.getValue("startDate")}</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "endDate",
|
|
header: t("end-date"),
|
|
cell: ({ row }) => (
|
|
<span className="whitespace-nowrap">{row.getValue("endDate")}</span>
|
|
),
|
|
},
|
|
{
|
|
accessorKey: "time",
|
|
header: t("time"),
|
|
cell: ({ row }: { row: { original: any } }) => {
|
|
console.log("Row Original Data:", row.original);
|
|
const { startTime, endTime } = row.original;
|
|
return (
|
|
<span className="whitespace-nowrap">
|
|
{startTime || "N/A"} - {endTime || "N/A"}
|
|
</span>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "address",
|
|
header: t("address"),
|
|
cell: ({ row }: { row: { getValue: (key: string) => string } }) => {
|
|
const address: string = row.getValue("address");
|
|
return (
|
|
<span className="whitespace-nowrap">
|
|
{address.length > 50 ? `${address.slice(0, 40)}...` : address}
|
|
</span>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "statusName",
|
|
header: "Status",
|
|
cell: ({ row }) => {
|
|
const statusColors: Record<string, string> = {
|
|
diterima: "bg-green-100 text-green-600",
|
|
"menunggu review": "bg-orange-100 text-orange-600",
|
|
};
|
|
|
|
// Mengambil `statusName` dari data API
|
|
const status = row.getValue("statusName") as string;
|
|
const statusName = status?.toLocaleLowerCase(); // Ubah ke huruf kecil
|
|
|
|
// Gunakan `statusName` untuk pencocokan
|
|
const statusStyles =
|
|
statusColors[statusName] || "bg-gray-100 text-gray-600";
|
|
|
|
return (
|
|
<Badge
|
|
className={cn("rounded-full px-5 whitespace-nowrap", statusStyles)}
|
|
>
|
|
{status} {/* Tetap tampilkan nilai asli */}
|
|
</Badge>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "speaker",
|
|
header: t("speaker"),
|
|
cell: ({ row }: { row: { original: any } }) => {
|
|
console.log("Row Original Data:", row.original);
|
|
const { speakerTitle, speakerName } = row.original;
|
|
return (
|
|
<span className="whitespace-nowrap">
|
|
{speakerTitle || ""} {speakerName || ""}
|
|
</span>
|
|
);
|
|
},
|
|
},
|
|
{
|
|
accessorKey: "uploaderName",
|
|
header: t("source"),
|
|
cell: ({ row }) => (
|
|
<span className="whitespace-nowrap">
|
|
{row.getValue("uploaderName")}
|
|
</span>
|
|
),
|
|
},
|
|
|
|
{
|
|
id: "actions",
|
|
accessorKey: "action",
|
|
header: t("action"),
|
|
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/schedule/press-release/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/schedule/press-release/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>
|
|
);
|
|
},
|
|
},
|
|
];
|
|
|
|
return columns;
|
|
};
|
|
|
|
export default useTableColumns;
|