diff --git a/components/form/login.tsx b/components/form/login.tsx index 788b02f..9c4f79b 100644 --- a/components/form/login.tsx +++ b/components/form/login.tsx @@ -72,8 +72,16 @@ export default function Login() { // login dengan otp loading(); const response: any = await emailValidation(data); + if (response?.data?.messages[0]?.includes("Suspended")) { + close(); + error( + "Untuk sementara akun Polda/Polres Anda di tangguhkan, silahkan hubungi Admin Mabes untuk konfirmasi, Terima Kasih" + ); + return false; + } if (response?.error) { console.log("error", response); + if (response?.message?.messages[0]?.includes("failed to send mail")) { error("Gagal Mengirim OTP"); return false; diff --git a/components/icons.tsx b/components/icons.tsx index 7f3a70a..756204d 100644 --- a/components/icons.tsx +++ b/components/icons.tsx @@ -1421,14 +1421,16 @@ export const Checklist = ({ size = 24, width, height, + fill = "currentColor", + ...props }: IconSvgProps) => ( ); +export const SuspendIcon = ({ + size, + height = 37, + width = 32, + fill = "currentColor", + ...props +}: IconSvgProps) => ( + + + +); diff --git a/components/table/master-user-table.tsx b/components/table/master-user-table.tsx index 238a698..df4be22 100644 --- a/components/table/master-user-table.tsx +++ b/components/table/master-user-table.tsx @@ -1,14 +1,20 @@ "use client"; import { + Checklist, CreateIconIon, DeleteIcon, DotsYIcon, EyeIconMdi, SearchIcon, + SuspendIcon, } from "@/components/icons"; -import { error, success } from "@/config/swal"; +import { error, loading, success } from "@/config/swal"; import { deleteArticle, getListArticle } from "@/services/article"; -import { deleteMasterUser, listMasterUsers } from "@/services/master-user"; +import { + changeSuspendStatus, + deleteMasterUser, + listMasterUsers, +} from "@/services/master-user"; import { Article, MasterUser } from "@/types/globals"; import { getUnixTimestamp } from "@/utils/global"; import { Button } from "@heroui/button"; @@ -41,8 +47,10 @@ const columns = [ { name: "Username", uid: "username" }, { name: "Fullname", uid: "fullname" }, { name: "Email", uid: "email" }, - { name: "Identity Type", uid: "identityType" }, - { name: "Identity Number", uid: "identityNumber" }, + { name: "Status", uid: "status" }, + // { name: "Identity Type", uid: "identityType" }, + // { name: "Identity Number", uid: "identityNumber" }, + // { name: "Users", uid: "users" }, // { name: "Status", uid: "status" }, { name: "Aksi", uid: "actions" }, @@ -126,6 +134,38 @@ export default function MasterUserTable() { }); } + const handleSuspend = (id: number, status: boolean) => { + MySwal.fire({ + title: `${!status ? "Lepas " : ""}Suspend User?`, + icon: "warning", + showCancelButton: true, + cancelButtonColor: "#3085d6", + confirmButtonColor: "#d33", + confirmButtonText: "Yes", + }).then((result) => { + if (result.isConfirmed) { + doSuspend(id, status); + } + }); + }; + + async function doSuspend(id: number, status: boolean) { + loading(); + + console.log("do suspend", id, status); + const res = await changeSuspendStatus({ + user_id: id, + is_suspended: status, + }); + + if (res?.error) { + error(res.message); + return false; + } + close(); + successSubmit(); + } + const renderCell = useCallback((user: MasterUser, columnKey: Key) => { const cellValue = user[columnKey as keyof MasterUser]; const statusColorMap: Record = { @@ -142,12 +182,12 @@ export default function MasterUserTable() { return ( - {cellValue} + {user?.isSuspended ? "Suspend" : "Active"} ); @@ -168,6 +208,28 @@ export default function MasterUserTable() { Edit + handleSuspend(user.id, !user?.isSuspended)} + > + {user?.isSuspended ? ( + + ) : ( + + )} + + {user?.isSuspended ? "Unsuspend" : "Suspend"} + handleDelete(user.id)} diff --git a/services/master-user.ts b/services/master-user.ts index 21c506b..2b30910 100644 --- a/services/master-user.ts +++ b/services/master-user.ts @@ -140,6 +140,14 @@ export async function otpValidationLogin(data: any) { return await httpPost(`/users/otp-validation`, headers, data); } +export async function changeSuspendStatus(data: any) { + const headers = { + "content-type": "application/json", + Authorization: `Bearer ${token}`, + }; + return await httpPost(`/users/suspend`, headers, data); +} + export async function postArticleComment(data: any) { const headers = token ? { diff --git a/types/globals.tsx b/types/globals.tsx index 39fb826..d98b70f 100644 --- a/types/globals.tsx +++ b/types/globals.tsx @@ -40,6 +40,7 @@ export type MasterUser = { userRoleId: number; username: string; workType: string; + isSuspended?: boolean; }; export type MasterUserRole = {