Removed the need for it to alway use Passport ID

This commit is contained in:
Tiago Ribeiro
2024-01-25 10:28:45 +00:00
parent bcacbbdd15
commit c38c1d9ff6
2 changed files with 27 additions and 20 deletions

View File

@@ -58,6 +58,7 @@ export default function BatchCodeGenerator({user}: {user: User}) {
if (filesContent.length > 0) { if (filesContent.length > 0) {
const file = filesContent[0]; const file = filesContent[0];
readXlsxFile(file.content).then((rows) => { readXlsxFile(file.content).then((rows) => {
try {
const information = uniqBy( const information = uniqBy(
rows rows
.map((row) => { .map((row) => {
@@ -66,7 +67,7 @@ export default function BatchCodeGenerator({user}: {user: User}) {
? { ? {
email: email.toString(), email: email.toString(),
name: `${firstName ?? ""} ${lastName ?? ""}`.trim(), name: `${firstName ?? ""} ${lastName ?? ""}`.trim(),
passport_id: passport_id.toString(), passport_id: passport_id?.toString() || undefined,
} }
: undefined; : undefined;
}) })
@@ -82,6 +83,12 @@ export default function BatchCodeGenerator({user}: {user: User}) {
} }
setInfos(information); setInfos(information);
} catch {
toast.error(
"Please upload an Excel file containing user information, one per line! All already registered e-mails have also been ignored!",
);
return clear();
}
}); });
} }
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps

View File

@@ -42,7 +42,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
const {type, codes, infos, expiryDate} = req.body as { const {type, codes, infos, expiryDate} = req.body as {
type: Type; type: Type;
codes: string[]; codes: string[];
infos?: {email: string; name: string; passport_id: string}[]; infos?: {email: string; name: string; passport_id?: string}[];
expiryDate: null | Date; expiryDate: null | Date;
}; };
const permission = PERMISSIONS.generateCode[type]; const permission = PERMISSIONS.generateCode[type];
@@ -74,7 +74,7 @@ async function post(req: NextApiRequest, res: NextApiResponse) {
if (infos && infos.length > index) { if (infos && infos.length > index) {
const {email, name, passport_id} = infos[index]; const {email, name, passport_id} = infos[index];
await setDoc(codeRef, {email: email.trim(), name: name.trim(), passport_id: passport_id.trim()}, {merge: true}); await setDoc(codeRef, {email: email.trim(), name: name.trim(), ...(passport_id ? {passport_id: passport_id.trim()} : {})}, {merge: true});
const transport = prepareMailer(); const transport = prepareMailer();
const mailOptions = prepareMailOptions( const mailOptions = prepareMailOptions(