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) => {