Made it so, when using the batch code generator, it sends e-mails to everyone
This commit is contained in:
@@ -10,6 +10,7 @@ import {useFilePicker} from "use-file-picker";
|
||||
|
||||
export default function BatchCodeGenerator() {
|
||||
const [emails, setEmails] = useState<string[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const {openFilePicker, filesContent} = useFilePicker({
|
||||
accept: ".txt",
|
||||
multiple: false,
|
||||
@@ -35,11 +36,12 @@ export default function BatchCodeGenerator() {
|
||||
const uid = new ShortUniqueId();
|
||||
const codes = emails.map(() => uid.randomUUID(6));
|
||||
|
||||
setIsLoading(true);
|
||||
axios
|
||||
.post("/api/code", {type, codes})
|
||||
.post("/api/code", {type, codes, emails})
|
||||
.then(({data, status}) => {
|
||||
if (data.ok) {
|
||||
toast.success(`Successfully generated ${capitalize(type)} codes!`, {toastId: "success"});
|
||||
toast.success(`Successfully generated ${capitalize(type)} codes and they have been notified by e-mail!`, {toastId: "success"});
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -54,25 +56,28 @@ export default function BatchCodeGenerator() {
|
||||
}
|
||||
|
||||
toast.error(`Something went wrong, please try again later!`, {toastId: "error"});
|
||||
});
|
||||
})
|
||||
.finally(() => setIsLoading(false));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4 border p-4 border-mti-gray-platinum rounded-xl">
|
||||
<label className="font-normal text-base text-mti-gray-dim">Choose a .txt file containing e-mails</label>
|
||||
<Button onClick={openFilePicker}>{filesContent.length > 0 ? filesContent[0].name : "Choose a file"}</Button>
|
||||
<Button onClick={openFilePicker} isLoading={isLoading} disabled={isLoading}>
|
||||
{filesContent.length > 0 ? filesContent[0].name : "Choose a file"}
|
||||
</Button>
|
||||
<label className="font-normal text-base text-mti-gray-dim">Select the type of user they should be</label>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<Button className="w-48" variant="outline" onClick={() => generateCode("student")} disabled={emails.length === 0}>
|
||||
<Button className="w-48" variant="outline" onClick={() => generateCode("student")} disabled={emails.length === 0 || isLoading}>
|
||||
Student
|
||||
</Button>
|
||||
<Button className="w-48" variant="outline" onClick={() => generateCode("teacher")} disabled={emails.length === 0}>
|
||||
<Button className="w-48" variant="outline" onClick={() => generateCode("teacher")} disabled={emails.length === 0 || isLoading}>
|
||||
Teacher
|
||||
</Button>
|
||||
<Button className="w-48" variant="outline" onClick={() => generateCode("admin")} disabled={emails.length === 0}>
|
||||
<Button className="w-48" variant="outline" onClick={() => generateCode("admin")} disabled={emails.length === 0 || isLoading}>
|
||||
Admin
|
||||
</Button>
|
||||
<Button className="w-48" variant="outline" onClick={() => generateCode("owner")} disabled={emails.length === 0}>
|
||||
<Button className="w-48" variant="outline" onClick={() => generateCode("owner")} disabled={emails.length === 0 || isLoading}>
|
||||
Owner
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user