fix: hide button edit and delete if status done
This commit is contained in:
parent
cfc47a00a8
commit
6fa5a05624
|
|
@ -23,7 +23,7 @@ import Swal from "sweetalert2";
|
|||
import { useTranslations } from "next-intl";
|
||||
|
||||
const useTableColumns = () => {
|
||||
const t = useTranslations("Table"); // Panggil di dalam hook
|
||||
const t = useTranslations("Table");
|
||||
const columns: ColumnDef<any>[] = [
|
||||
{
|
||||
accessorKey: "no",
|
||||
|
|
@ -124,6 +124,85 @@ const useTableColumns = () => {
|
|||
accessorKey: "action",
|
||||
header: t("action", { defaultValue: "Action" }),
|
||||
enableHiding: false,
|
||||
// cell: ({ row }) => {
|
||||
// const router = useRouter();
|
||||
// const MySwal = withReactContent(Swal);
|
||||
|
||||
// async function deleteProcess(id: any) {
|
||||
// loading();
|
||||
// const resDelete = await deleteTask(id);
|
||||
|
||||
// if (resDelete?.error) {
|
||||
// error(resDelete.message);
|
||||
// return false;
|
||||
// }
|
||||
// success();
|
||||
// }
|
||||
|
||||
// function success() {
|
||||
// MySwal.fire({
|
||||
// title: "Sukses",
|
||||
// icon: "success",
|
||||
// confirmButtonColor: "#3085d6",
|
||||
// confirmButtonText: "OK",
|
||||
// }).then((result) => {
|
||||
// if (result.isConfirmed) {
|
||||
// window.location.reload();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// const TaskDelete = (id: any) => {
|
||||
// MySwal.fire({
|
||||
// title: "Hapus Data",
|
||||
// text: "",
|
||||
// icon: "warning",
|
||||
// showCancelButton: true,
|
||||
// cancelButtonColor: "#3085d6",
|
||||
// confirmButtonColor: "#d33",
|
||||
// confirmButtonText: "Hapus",
|
||||
// }).then((result) => {
|
||||
// if (result.isConfirmed) {
|
||||
// deleteProcess(id);
|
||||
// }
|
||||
// });
|
||||
// };
|
||||
|
||||
// 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/task/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/task/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
|
||||
// onClick={() => TaskDelete(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" />
|
||||
// Delete
|
||||
// </DropdownMenuItem>
|
||||
// </DropdownMenuContent>
|
||||
// </DropdownMenu>
|
||||
// );
|
||||
// },
|
||||
cell: ({ row }) => {
|
||||
const router = useRouter();
|
||||
const MySwal = withReactContent(Swal);
|
||||
|
|
@ -168,6 +247,8 @@ const useTableColumns = () => {
|
|||
});
|
||||
};
|
||||
|
||||
const isDone = row.original.isDone;
|
||||
|
||||
return (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
|
|
@ -186,19 +267,24 @@ const useTableColumns = () => {
|
|||
View
|
||||
</DropdownMenuItem>
|
||||
</Link>
|
||||
<Link href={`/contributor/task/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
|
||||
onClick={() => TaskDelete(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" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
|
||||
{!isDone && (
|
||||
<>
|
||||
<Link href={`/contributor/task/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
|
||||
onClick={() => TaskDelete(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" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ const TaskPage = () => {
|
|||
const t = useTranslations("AnalyticsDashboard");
|
||||
useEffect(() => {
|
||||
function initState() {
|
||||
checkAuthorization("admin"); // Specify the page, e.g., "admin" or another value
|
||||
checkAuthorization("admin");
|
||||
checkLoginSession();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue