ENCOA-97: Now it allows the user to write the name of the country in english

This commit is contained in:
Tiago Ribeiro
2024-08-22 16:15:25 +01:00
parent cfcff3cf3b
commit 326d305a69
3 changed files with 8 additions and 3 deletions

View File

@@ -16,6 +16,8 @@ import Checkbox from "@/components/Low/Checkbox";
import ReactDatePicker from "react-datepicker";
import clsx from "clsx";
import usePermissions from "@/hooks/usePermissions";
import countryCodes from "country-codes-list";
const EMAIL_REGEX = new RegExp(/^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)*$/);
type Type = Exclude<UserType, "admin" | "developer" | "agent" | "mastercorporate">;
@@ -103,6 +105,10 @@ export default function BatchCreateUser({user}: {user: User}) {
rows
.map((row) => {
const [firstName, lastName, country, passport_id, email, phone, group] = row as string[];
const countryItem =
countryCodes.findOne("countryCode" as any, country.toUpperCase()) ||
countryCodes.all().find((x) => x.countryNameEn.toLowerCase() === country.toLowerCase());
return EMAIL_REGEX.test(email.toString().trim())
? {
email: email.toString().trim().toLowerCase(),
@@ -111,7 +117,7 @@ export default function BatchCreateUser({user}: {user: User}) {
passport_id: passport_id?.toString().trim() || undefined,
groupName: group,
demographicInformation: {
country: country,
country: countryItem?.countryCode,
passport_id: passport_id?.toString().trim() || undefined,
phone,
},