2024-11-29 12:41:23 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import * as React from "react";
|
|
|
|
|
import {
|
|
|
|
|
ColumnDef,
|
|
|
|
|
ColumnFiltersState,
|
|
|
|
|
PaginationState,
|
|
|
|
|
SortingState,
|
|
|
|
|
VisibilityState,
|
|
|
|
|
flexRender,
|
|
|
|
|
getCoreRowModel,
|
|
|
|
|
getFilteredRowModel,
|
|
|
|
|
getPaginationRowModel,
|
|
|
|
|
getSortedRowModel,
|
|
|
|
|
useReactTable,
|
|
|
|
|
} from "@tanstack/react-table";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
} from "@/components/ui/table";
|
|
|
|
|
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
|
|
|
|
|
import {
|
|
|
|
|
Badge,
|
|
|
|
|
ChevronLeft,
|
|
|
|
|
ChevronRight,
|
|
|
|
|
Eye,
|
|
|
|
|
MoreVertical,
|
|
|
|
|
Search,
|
|
|
|
|
SquarePen,
|
|
|
|
|
Trash2,
|
|
|
|
|
TrendingDown,
|
|
|
|
|
TrendingUp,
|
|
|
|
|
} from "lucide-react";
|
|
|
|
|
import {
|
|
|
|
|
DropdownMenu,
|
|
|
|
|
DropdownMenuContent,
|
|
|
|
|
DropdownMenuItem,
|
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
|
} from "@/components/ui/dropdown-menu";
|
|
|
|
|
|
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
import { InputGroup, InputGroupText } from "@/components/ui/input-group";
|
2024-12-03 17:49:25 +00:00
|
|
|
import { Link } from "@/components/navigation";
|
2024-12-04 17:28:40 +00:00
|
|
|
import { title } from "process";
|
|
|
|
|
import search from "../../app/chat/components/search";
|
|
|
|
|
import { format } from "date-fns";
|
2024-12-05 17:02:06 +00:00
|
|
|
import { listTask } from "@/service/task";
|
2024-12-04 17:28:40 +00:00
|
|
|
|
|
|
|
|
export type CompanyData = {
|
|
|
|
|
no: number;
|
|
|
|
|
title: string;
|
|
|
|
|
uniqueCode: string;
|
|
|
|
|
assignmentMainType: string;
|
|
|
|
|
assignmentType: string;
|
|
|
|
|
createdAt: string;
|
|
|
|
|
isDone: string;
|
|
|
|
|
};
|
2024-11-29 12:41:23 +00:00
|
|
|
|
|
|
|
|
export const columns: ColumnDef<CompanyData>[] = [
|
2024-12-04 17:28:40 +00:00
|
|
|
{
|
|
|
|
|
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>
|
|
|
|
|
),
|
|
|
|
|
},
|
2024-11-29 12:41:23 +00:00
|
|
|
{
|
|
|
|
|
accessorKey: "title",
|
|
|
|
|
header: "Judul",
|
|
|
|
|
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("title")}
|
|
|
|
|
</h4>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-12-04 17:28:40 +00:00
|
|
|
accessorKey: "uniqueCode",
|
2024-11-29 12:41:23 +00:00
|
|
|
header: "Kode ",
|
|
|
|
|
cell: ({ row }) => (
|
2024-12-04 17:28:40 +00:00
|
|
|
<span className="whitespace-nowrap">{row.getValue("uniqueCode")}</span>
|
2024-11-29 12:41:23 +00:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-12-04 17:28:40 +00:00
|
|
|
accessorKey: "assignmentMainType",
|
|
|
|
|
header: "Tipe Tugas ",
|
2024-11-29 12:41:23 +00:00
|
|
|
cell: ({ row }) => (
|
2024-12-04 17:28:40 +00:00
|
|
|
<span className="whitespace-nowrap">
|
|
|
|
|
{row.getValue("assignmentMainType")}
|
|
|
|
|
</span>
|
2024-11-29 12:41:23 +00:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-12-04 17:28:40 +00:00
|
|
|
accessorKey: "assignmentType",
|
2024-11-29 12:41:23 +00:00
|
|
|
header: "Jenis Tugas ",
|
|
|
|
|
cell: ({ row }) => (
|
2024-12-04 17:28:40 +00:00
|
|
|
<span className="whitespace-nowrap">
|
|
|
|
|
{row.getValue("assignmentType")}
|
|
|
|
|
</span>
|
2024-11-29 12:41:23 +00:00
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
{
|
2024-12-04 17:28:40 +00:00
|
|
|
accessorKey: "createdAt",
|
|
|
|
|
header: "Tanggal Unggah",
|
|
|
|
|
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>;
|
|
|
|
|
},
|
2024-11-29 12:41:23 +00:00
|
|
|
},
|
2024-12-04 17:28:40 +00:00
|
|
|
|
2024-11-29 12:41:23 +00:00
|
|
|
{
|
2024-12-04 17:28:40 +00:00
|
|
|
accessorKey: "isDone",
|
2024-11-29 12:41:23 +00:00
|
|
|
header: "Status",
|
|
|
|
|
cell: ({ row }) => {
|
2024-12-04 17:28:40 +00:00
|
|
|
const isDone = row.getValue<boolean>("isDone");
|
2024-11-29 12:41:23 +00:00
|
|
|
return (
|
2024-12-04 17:28:40 +00:00
|
|
|
<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>
|
2024-11-29 12:41:23 +00:00
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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">
|
2024-12-03 17:49:25 +00:00
|
|
|
<a href="/en/task/detail/[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>
|
|
|
|
|
</a>
|
2024-11-29 12:41:23 +00:00
|
|
|
<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>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const TaskTable = () => {
|
|
|
|
|
const [sorting, setSorting] = React.useState<SortingState>([]);
|
2024-12-04 17:28:40 +00:00
|
|
|
const [taskTable, setTaskTable] = React.useState<CompanyData[]>([]);
|
2024-11-29 12:41:23 +00:00
|
|
|
const [columnFilters, setColumnFilters] = React.useState<ColumnFiltersState>(
|
|
|
|
|
[]
|
|
|
|
|
);
|
|
|
|
|
const [columnVisibility, setColumnVisibility] =
|
|
|
|
|
React.useState<VisibilityState>({});
|
|
|
|
|
const [rowSelection, setRowSelection] = React.useState({});
|
|
|
|
|
const [pagination, setPagination] = React.useState<PaginationState>({
|
|
|
|
|
pageIndex: 0,
|
2024-12-04 17:31:26 +00:00
|
|
|
pageSize: 10,
|
2024-11-29 12:41:23 +00:00
|
|
|
});
|
2024-12-04 17:31:26 +00:00
|
|
|
const [page, setPage] = React.useState(1);
|
|
|
|
|
const [totalPage, setTotalPage] = React.useState(1);
|
2024-12-05 17:02:06 +00:00
|
|
|
const [limit, setLimit] = React.useState(100);
|
2024-12-04 17:28:40 +00:00
|
|
|
const [search, setSearch] = React.useState(title);
|
2024-11-29 12:41:23 +00:00
|
|
|
|
|
|
|
|
const table = useReactTable({
|
2024-12-04 17:28:40 +00:00
|
|
|
data: taskTable,
|
2024-11-29 12:41:23 +00:00
|
|
|
columns,
|
|
|
|
|
onSortingChange: setSorting,
|
|
|
|
|
onColumnFiltersChange: setColumnFilters,
|
2024-12-04 17:28:40 +00:00
|
|
|
onPaginationChange: setPagination,
|
2024-11-29 12:41:23 +00:00
|
|
|
getCoreRowModel: getCoreRowModel(),
|
|
|
|
|
getPaginationRowModel: getPaginationRowModel(),
|
|
|
|
|
getSortedRowModel: getSortedRowModel(),
|
|
|
|
|
getFilteredRowModel: getFilteredRowModel(),
|
|
|
|
|
state: {
|
|
|
|
|
sorting,
|
|
|
|
|
columnFilters,
|
|
|
|
|
pagination,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2024-12-04 17:28:40 +00:00
|
|
|
React.useEffect(() => {
|
|
|
|
|
initState();
|
|
|
|
|
}, [page, limit]);
|
|
|
|
|
|
|
|
|
|
async function initState() {
|
|
|
|
|
try {
|
|
|
|
|
const res = await listTask(limit, page);
|
|
|
|
|
const data = res.data.data.content.map((item: any, index: number) => ({
|
2024-12-04 17:31:26 +00:00
|
|
|
no: (page - 1) * limit + index + 1,
|
2024-12-04 17:28:40 +00:00
|
|
|
title: item.title,
|
|
|
|
|
uniqueCode: item.uniqueCode || "-",
|
|
|
|
|
assignmentMainType: item.assignmentMainType?.name || "-",
|
|
|
|
|
assignmentType: item.assignmentType?.name || "-",
|
|
|
|
|
createdAt: item.createdAt,
|
|
|
|
|
isDone: item.isDone,
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
setTaskTable(data);
|
2024-12-04 17:31:26 +00:00
|
|
|
setTotalPage(res.data.totalPages);
|
2024-12-04 17:28:40 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error fetching tasks:", error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-29 12:41:23 +00:00
|
|
|
return (
|
|
|
|
|
<div className="w-full overflow-x-auto">
|
|
|
|
|
<div className="flex justify-between items-center py-4 px-5">
|
|
|
|
|
<div>
|
|
|
|
|
<InputGroup merged>
|
|
|
|
|
<InputGroupText className="bg-transparent dark:border-secondary dark:group-focus-within:border-secondary">
|
|
|
|
|
<Search className=" h-4 w-4 dark:text-white" />
|
|
|
|
|
</InputGroupText>
|
|
|
|
|
<Input
|
|
|
|
|
type="text"
|
|
|
|
|
placeholder="Search Judul..."
|
|
|
|
|
className="bg-transparent dark:border-secondary dark:placeholder-white/80 dark:focus:border-secondary dark:text-white"
|
|
|
|
|
/>
|
|
|
|
|
</InputGroup>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-none">
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="Filter Status..."
|
|
|
|
|
value={
|
|
|
|
|
(table.getColumn("status")?.getFilterValue() as string) ?? ""
|
|
|
|
|
}
|
|
|
|
|
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
|
|
|
|
|
table.getColumn("status")?.setFilterValue(event.target.value)
|
|
|
|
|
}
|
|
|
|
|
className="max-w-sm "
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<Table className="overflow-hidden">
|
|
|
|
|
<TableHeader>
|
|
|
|
|
{table.getHeaderGroups().map((headerGroup) => (
|
|
|
|
|
<TableRow key={headerGroup.id} className="bg-default-200">
|
|
|
|
|
{headerGroup.headers.map((header) => (
|
|
|
|
|
<TableHead key={header.id}>
|
|
|
|
|
{header.isPlaceholder
|
|
|
|
|
? null
|
|
|
|
|
: flexRender(
|
|
|
|
|
header.column.columnDef.header,
|
|
|
|
|
header.getContext()
|
|
|
|
|
)}
|
|
|
|
|
</TableHead>
|
|
|
|
|
))}
|
|
|
|
|
</TableRow>
|
|
|
|
|
))}
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{table.getRowModel().rows?.length ? (
|
|
|
|
|
table.getRowModel().rows.map((row) => (
|
|
|
|
|
<TableRow
|
|
|
|
|
key={row.id}
|
|
|
|
|
data-state={row.getIsSelected() && "selected"}
|
|
|
|
|
className="h-[75px]"
|
|
|
|
|
>
|
|
|
|
|
{row.getVisibleCells().map((cell) => (
|
|
|
|
|
<TableCell key={cell.id}>
|
|
|
|
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
|
|
|
</TableCell>
|
|
|
|
|
))}
|
|
|
|
|
</TableRow>
|
|
|
|
|
))
|
|
|
|
|
) : (
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableCell colSpan={columns.length} className="h-24 text-center">
|
|
|
|
|
No results.
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
)}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
<div className="flex items-center justify-center py-4 gap-2 flex-none">
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
onClick={() => table.previousPage()}
|
|
|
|
|
disabled={!table.getCanPreviousPage()}
|
|
|
|
|
className="w-8 h-8"
|
|
|
|
|
>
|
|
|
|
|
<ChevronLeft className="w-4 h-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
{table.getPageOptions().map((page, pageIndex) => (
|
|
|
|
|
<Button
|
|
|
|
|
key={`basic-data-table-${pageIndex}`}
|
|
|
|
|
onClick={() => table.setPageIndex(pageIndex)}
|
|
|
|
|
size="icon"
|
|
|
|
|
className="w-8 h-8"
|
|
|
|
|
variant={
|
|
|
|
|
table.getState().pagination.pageIndex === pageIndex
|
|
|
|
|
? "default"
|
|
|
|
|
: "outline"
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{page + 1}
|
|
|
|
|
</Button>
|
|
|
|
|
))}
|
|
|
|
|
<Button
|
|
|
|
|
variant="outline"
|
|
|
|
|
size="icon"
|
|
|
|
|
onClick={() => table.nextPage()}
|
|
|
|
|
disabled={!table.getCanNextPage()}
|
|
|
|
|
className="w-8 h-8"
|
|
|
|
|
>
|
|
|
|
|
<ChevronRight className="w-4 h-4" />
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TaskTable;
|