From d074edbbf12896c726279e3c832b9e8729e598f5 Mon Sep 17 00:00:00 2001 From: jq1836 <95712150+jq1836@users.noreply.github.com> Date: Mon, 23 Sep 2024 16:52:07 +0800 Subject: [PATCH 1/5] Add switch component to edit modal --- .../admin-edit-user-modal.tsx | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/frontend/components/admin-user-management/admin-edit-user-modal.tsx b/frontend/components/admin-user-management/admin-edit-user-modal.tsx index 19f1f1774b..f752b9e630 100644 --- a/frontend/components/admin-user-management/admin-edit-user-modal.tsx +++ b/frontend/components/admin-user-management/admin-edit-user-modal.tsx @@ -14,11 +14,12 @@ import { Label } from "../ui/label"; import { updateUser } from "@/lib/update-user"; import { useAuth } from "@/app/auth/auth-context"; import { useToast } from "@/components/hooks/use-toast"; +import { Switch } from "../ui/switch"; interface AdminEditUserModalProps extends React.HTMLProps { showModal?: boolean; setShowModal: (show: boolean) => void; - user: { id: string; username: string; email: string } | undefined; + user: { id: string; username: string; email: string, isAdmin: boolean } | undefined; onUserUpdate: () => void; } @@ -32,6 +33,7 @@ const AdminEditUserModal: React.FC = ({ id?: string; username?: string; email?: string; + isAdmin?: boolean; } | undefined >(); @@ -43,6 +45,15 @@ const AdminEditUserModal: React.FC = ({ const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); + updateUserInfo().then(() => updateUserPrivilege()); + + // Remove old states, update UI and close modal + setEditingUser(undefined); + props.onUserUpdate(); + props.setShowModal(false); + }; + + const updateUserInfo = async () => { if (!auth?.token) { // Will not reach this point as button is disabled // when token is missing @@ -127,11 +138,10 @@ const AdminEditUserModal: React.FC = ({ }); return; } + }; + + const updateUserPrivilege = async () => { - // Remove old states, update UI and close modal - setEditingUser(undefined); - props.onUserUpdate(); - props.setShowModal(false); }; return ( @@ -172,6 +182,16 @@ const AdminEditUserModal: React.FC = ({ required /> +
+
+ +
+ setEditingUser({ ...editingUser, isAdmin: e })} + required + /> +