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,30 +58,37 @@ export default function BatchCodeGenerator({user}: {user: User}) {
if (filesContent.length > 0) {
const file = filesContent[0];
readXlsxFile(file.content).then((rows) => {
const information = uniqBy(
rows
.map((row) => {
const [firstName, lastName, country, passport_id, email, ...phone] = row as string[];
return EMAIL_REGEX.test(email) && !users.map((u) => u.email).includes(email)
? {
email: email.toString(),
name: `${firstName ?? ""} ${lastName ?? ""}`.trim(),
passport_id: passport_id.toString(),
}
: undefined;
})
.filter((x) => !!x) as typeof infos,
(x) => x.email,
);
try {
const information = uniqBy(
rows
.map((row) => {
const [firstName, lastName, country, passport_id, email, ...phone] = row as string[];
return EMAIL_REGEX.test(email) && !users.map((u) => u.email).includes(email)
? {
email: email.toString(),
name: `${firstName ?? ""} ${lastName ?? ""}`.trim(),
passport_id: passport_id?.toString() || undefined,
}
: undefined;
})
.filter((x) => !!x) as typeof infos,
(x) => x.email,
);
if (information.length === 0) {
if (information.length === 0) {
toast.error(
"Please upload an Excel file containing user information, one per line! All already registered e-mails have also been ignored!",
);
return clear();
}
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();
}
setInfos(information);
});
}
// eslint-disable-next-line react-hooks/exhaustive-deps