From a35c85545e7332031d39efab2d2ad37ddd0033f5 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Mon, 29 Jan 2024 21:02:52 +0000 Subject: [PATCH] Updated the code to set the participant's expiration date to use the corporate's one if it is better --- src/pages/(admin)/Lists/GroupList.tsx | 17 +++- src/pages/api/groups/[id].ts | 126 ++++++++++++++++---------- src/pages/api/groups/index.ts | 82 +++++++++++------ src/utils/groups.be.ts | 53 +++++++++++ src/utils/groups.ts | 24 +++-- 5 files changed, 216 insertions(+), 86 deletions(-) create mode 100644 src/utils/groups.be.ts diff --git a/src/pages/(admin)/Lists/GroupList.tsx b/src/pages/(admin)/Lists/GroupList.tsx index f3a02401..35e9f106 100644 --- a/src/pages/(admin)/Lists/GroupList.tsx +++ b/src/pages/(admin)/Lists/GroupList.tsx @@ -39,6 +39,8 @@ const CreatePanel = ({ user, users, group, onClose }: CreateDialogProps) => { const [participants, setParticipants] = useState( group?.participants || [], ); + const [isLoading, setIsLoading] = useState(false); + const { openFilePicker, filesContent, clear } = useFilePicker({ accept: ".xlsx", multiple: false, @@ -47,6 +49,8 @@ const CreatePanel = ({ user, users, group, onClose }: CreateDialogProps) => { useEffect(() => { if (filesContent.length > 0) { + setIsLoading(true); + const file = filesContent[0]; readXlsxFile(file.content).then((rows) => { const emails = uniq( @@ -64,6 +68,7 @@ const CreatePanel = ({ user, users, group, onClose }: CreateDialogProps) => { if (emails.length === 0) { toast.error("Please upload an Excel file containing e-mails!"); clear(); + setIsLoading(false); return; } @@ -86,16 +91,20 @@ const CreatePanel = ({ user, users, group, onClose }: CreateDialogProps) => { : "Added all students found in the file you've provided!", { toastId: "upload-success" }, ); + setIsLoading(false); }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [filesContent, user.type, users]); const submit = () => { + setIsLoading(true); + if (name !== group?.name && (name === "Students" || name === "Teachers")) { toast.error( "That group name is reserved and cannot be used, please enter another one.", ); + setIsLoading(false); return; } @@ -113,7 +122,10 @@ const CreatePanel = ({ user, users, group, onClose }: CreateDialogProps) => { toast.error("Something went wrong, please try again later!"); return false; }) - .finally(onClose); + .finally(() => { + setIsLoading(false); + onClose(); + }); }; return ( @@ -178,6 +190,7 @@ const CreatePanel = ({ user, users, group, onClose }: CreateDialogProps) => {