feat:merge dev - suspend user

This commit is contained in:
Rama Priyanto 2025-11-10 13:43:32 +07:00
commit d303496552
5 changed files with 111 additions and 10 deletions

View File

@ -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;

View File

@ -1421,14 +1421,16 @@ export const Checklist = ({
size = 24,
width,
height,
fill = "currentColor",
...props
}: IconSvgProps) => (
<svg
width="25"
height="24"
viewBox="0 0 25 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
width={size || width}
height={size || height}
{...props}
viewBox="0 0 25 24"
>
<g clipPath="url(#clip0_681_10672)">
<path
@ -2732,3 +2734,23 @@ export const VideoIcon = ({
</g>
</svg>
);
export const SuspendIcon = ({
size,
height = 37,
width = 32,
fill = "currentColor",
...props
}: IconSvgProps) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={size || width}
height={size || height}
{...props}
viewBox="0 0 24 24"
>
<path
fill="currentColor"
d="M12 2c5.5 0 10 4.5 10 10s-4.5 10-10 10S2 17.5 2 12S6.5 2 12 2m0 2c-1.9 0-3.6.6-4.9 1.7l11.2 11.2c1-1.4 1.7-3.1 1.7-4.9c0-4.4-3.6-8-8-8m4.9 14.3L5.7 7.1C4.6 8.4 4 10.1 4 12c0 4.4 3.6 8 8 8c1.9 0 3.6-.6 4.9-1.7"
/>
</svg>
);

View File

@ -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<string, ChipProps["color"]> = {
@ -142,12 +182,12 @@ export default function MasterUserTable() {
return (
<Chip
className="capitalize "
// color={statusColorMap[user.status]}
color={user?.isSuspended ? "danger" : "success"}
size="lg"
variant="flat"
>
<div className="flex flex-row items-center gap-2 justify-center">
{cellValue}
{user?.isSuspended ? "Suspend" : "Active"}
</div>
</Chip>
);
@ -168,6 +208,28 @@ export default function MasterUserTable() {
Edit
</Link>
</DropdownItem>
<DropdownItem
key="Suspend"
onClick={() => handleSuspend(user.id, !user?.isSuspended)}
>
{user?.isSuspended ? (
<Checklist
color="green"
width={20}
height={16}
className="inline mr-2 mb-1"
/>
) : (
<SuspendIcon
color="red"
width={20}
height={16}
className="inline mr-2 mb-1"
/>
)}
{user?.isSuspended ? "Unsuspend" : "Suspend"}
</DropdownItem>
<DropdownItem
key="Delete"
onClick={() => handleDelete(user.id)}

View File

@ -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
? {

View File

@ -40,6 +40,7 @@ export type MasterUser = {
userRoleId: number;
username: string;
workType: string;
isSuspended?: boolean;
};
export type MasterUserRole = {