diff --git a/components/form/login.tsx b/components/form/login.tsx index d117ff5..d4d792f 100644 --- a/components/form/login.tsx +++ b/components/form/login.tsx @@ -69,98 +69,98 @@ export default function Login() { error("Username & Password Wajib Diisi !"); } else { // login dengan otp - // loading(); - // const response: any = await emailValidation(data); - // if (response?.error) { - // console.log("error", response); - // if (response?.message?.messages[0]?.includes("failed to send mail")) { - // error("Gagal Mengirim OTP"); - // return false; - // } + loading(); + const response: any = await emailValidation(data); + if (response?.error) { + console.log("error", response); + if (response?.message?.messages[0]?.includes("failed to send mail")) { + error("Gagal Mengirim OTP"); + return false; + } - // if (response?.message?.messages[0]?.includes("username")) { - // error("Username / Password Tidak Sesuai"); - // return false; - // } - // error("Unknown Error"); - // return false; - // } - // close(); - // if (response?.data?.messages[0] === "Continue to setup email") { - // setFirstLogin(true); - // } else { - // setNeedOtp(true); - // } + if (response?.message?.messages[0]?.includes("username")) { + error("Username / Password Tidak Sesuai"); + return false; + } + error("Unknown Error"); + return false; + } + close(); + if (response?.data?.messages[0] === "Continue to setup email") { + setFirstLogin(true); + } else { + setNeedOtp(true); + } // login tanpa otp - loading(); - const response = await postSignIn(data); - if (response?.error) { - error("Username / Password Tidak Sesuai"); - } else { - const profile = await getProfile(response?.data?.data?.access_token); - const dateTime: any = new Date(); + // loading(); + // const response = await postSignIn(data); + // if (response?.error) { + // error("Username / Password Tidak Sesuai"); + // } else { + // const profile = await getProfile(response?.data?.data?.access_token); + // const dateTime: any = new Date(); - const newTime: any = dateTime.getTime() + 10 * 60 * 1000; + // const newTime: any = dateTime.getTime() + 10 * 60 * 1000; - Cookies.set("access_token", response?.data?.data?.access_token, { - expires: 1, - }); - Cookies.set("refresh_token", response?.data?.data?.refresh_token, { - expires: 1, - }); - Cookies.set("time_refresh", newTime, { - expires: 1, - }); - Cookies.set("is_first_login", "true", { - secure: true, - sameSite: "strict", - }); - const resActivity = await saveActivity( - { - activityTypeId: 1, - url: "https://kontenhumas.com/auth", - userId: profile?.data?.data?.id, - }, - accessData?.id_token - ); - Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { - expires: 1, - }); - Cookies.set("uie", profile?.data?.data?.id, { - expires: 1, - }); - Cookies.set("ufne", profile?.data?.data?.fullname, { - expires: 1, - }); - Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { - expires: 1, - }); - Cookies.set("username", profile?.data?.data?.username, { - expires: 1, - }); - Cookies.set("urie", profile?.data?.data?.userRoleId, { - expires: 1, - }); - Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { - expires: 1, - }); - Cookies.set("ulne", profile?.data?.data?.userLevelId, { - expires: 1, - }); - // Cookies.set("urce", profile?.data?.data?.roleCode, { - // expires: 1, - // }); - Cookies.set("email", profile?.data?.data?.email, { - expires: 1, - }); - router.push("/admin/dashboard"); - Cookies.set("status", "login", { - expires: 1, - }); + // Cookies.set("access_token", response?.data?.data?.access_token, { + // expires: 1, + // }); + // Cookies.set("refresh_token", response?.data?.data?.refresh_token, { + // expires: 1, + // }); + // Cookies.set("time_refresh", newTime, { + // expires: 1, + // }); + // Cookies.set("is_first_login", "true", { + // secure: true, + // sameSite: "strict", + // }); + // const resActivity = await saveActivity( + // { + // activityTypeId: 1, + // url: "https://kontenhumas.com/auth", + // userId: profile?.data?.data?.id, + // }, + // accessData?.id_token + // ); + // Cookies.set("profile_picture", profile?.data?.data?.profilePictureUrl, { + // expires: 1, + // }); + // Cookies.set("uie", profile?.data?.data?.id, { + // expires: 1, + // }); + // Cookies.set("ufne", profile?.data?.data?.fullname, { + // expires: 1, + // }); + // Cookies.set("ulie", profile?.data?.data?.userLevelGroup, { + // expires: 1, + // }); + // Cookies.set("username", profile?.data?.data?.username, { + // expires: 1, + // }); + // Cookies.set("urie", profile?.data?.data?.userRoleId, { + // expires: 1, + // }); + // Cookies.set("masterPoldaId", profile?.data?.data?.masterPoldaId, { + // expires: 1, + // }); + // Cookies.set("ulne", profile?.data?.data?.userLevelId, { + // expires: 1, + // }); + // // Cookies.set("urce", profile?.data?.data?.roleCode, { + // // expires: 1, + // // }); + // Cookies.set("email", profile?.data?.data?.email, { + // expires: 1, + // }); + // router.push("/admin/dashboard"); + // Cookies.set("status", "login", { + // expires: 1, + // }); - close(); - } + // close(); + // } } }; diff --git a/components/table/article-table.tsx b/components/table/article-table.tsx index 62500b9..4b44ca7 100644 --- a/components/table/article-table.tsx +++ b/components/table/article-table.tsx @@ -28,6 +28,7 @@ import { Autocomplete, AutocompleteItem, Calendar, + Checkbox, Chip, ChipProps, Dropdown, @@ -50,7 +51,7 @@ import { TableRow, } from "@heroui/react"; import Link from "next/link"; -import { Key, useCallback, useEffect, useState } from "react"; +import { Key, useCallback, useEffect, useRef, useState } from "react"; import Datepicker from "react-tailwindcss-datepicker"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; @@ -112,6 +113,8 @@ export default function ArticleTable() { endDate: null, }); + const [selectedArticles, setSelectedArticles] = useState(new Set([])); + const [articleDate, setArticleDate] = useState<{ startDate: any; endDate: any; @@ -283,27 +286,66 @@ export default function ArticleTable() { } }; + const selectedArticlesRef = useRef(selectedArticles); + const articlesRef = useRef(article); + + useEffect(() => { + selectedArticlesRef.current = selectedArticles; + articlesRef.current = article; + }, [selectedArticles, article]); + + const doBulkDelete = useCallback(() => { + console.log("issame", Array.from(selectedArticlesRef.current)); + const now = Array.from(selectedArticlesRef.current); + if (now.length < 1) { + error("Pilih Article"); + return false; + } + const isAll = now.join("") === "all"; + + MySwal.fire({ + title: "Hapus Artikel yang Dipilih?", + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#3085d6", + confirmButtonColor: "#d33", + confirmButtonText: "Hapus", + }).then((result) => { + if (result.isConfirmed) { + if (isAll) { + const temp = []; + for (const element of articlesRef.current) { + temp.push(String(element.id)); + } + deleteBulkProcess(temp); + } else { + deleteBulkProcess(now as string[]); + } + } + }); + }, []); + + const deleteBulkProcess = async (data: string[]) => { + loading(); + for (const element of data) { + const resDelete = await deleteArticle(element); + } + close(); + success("Berhasil Hapus"); + setPage(1); + initState(); + }; + const renderCell = useCallback( (article: any, columnKey: Key) => { const cellValue = article[columnKey as keyof any]; switch (columnKey) { case "isPublish": - return ( - // - //
- // {article.status} - //
- //
-

{article.isPublish ? "Publish" : "Draft"}

- ); + return

{article.isPublish ? "Publish" : "Draft"}

; case "isBanner": return

{article.isBanner ? "Ya" : "Tidak"}

; + case "createdAt": return

{convertDateFormat(article.createdAt)}

; case "category": @@ -393,6 +435,23 @@ export default function ArticleTable() { )} + + {roleId && Number(roleId) < 3 && ( + <> + {" "} + + Bulk Delete + + )} + @@ -402,7 +461,7 @@ export default function ArticleTable() { return cellValue; } }, - [article, page] + [article, page, selectedArticles] ); let typingTimer: NodeJS.Timeout; @@ -492,30 +551,6 @@ export default function ArticleTable() { placeholder="Kategori..." name="sub-module" options={categories} - // styles={{ - // control: (base) => ({ - // ...base, - // width: "100%", - // overflowX: "auto", - // }), - // valueContainer: (base) => ({ - // ...base, - // display: "flex", - // flexWrap: "nowrap", - // overflowX: "auto", - // whiteSpace: "nowrap", - // gap: "4px", - // }), - // multiValue: (base) => ({ - // ...base, - // whiteSpace: "nowrap", - // flexShrink: 0, - // }), - // multiValueLabel: (base) => ({ - // ...base, - // whiteSpace: "nowrap", - // }), - // }} /> {roleId && Number(roleId) < 3 && ( @@ -635,6 +670,9 @@ export default function ArticleTable() { wrapper: "min-h-[50px] bg-transpararent text-black dark:text-white ", }} + selectionMode={roleId && Number(roleId) < 3 ? "multiple" : "none"} + selectedKeys={selectedArticles} + onSelectionChange={setSelectedArticles} >