fix: [CAL-2593] Uploading a CSV File does not comma separate the values (#11756)
* csv email validation added * most common csv delimeters addedpull/11907/head
parent
bab72a5d2e
commit
461120ad84
|
@ -143,11 +143,24 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)
|
||||||
|
|
||||||
if (file) {
|
if (file) {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
|
const emailRegex = /^([A-Z0-9_+-]+\.?)*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i;
|
||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
const contents = e?.target?.result as string;
|
const contents = e?.target?.result as string;
|
||||||
const values = contents?.split(",").map((email) => email.trim().toLocaleLowerCase());
|
const lines = contents.split("\n");
|
||||||
newMemberFormMethods.setValue("emailOrUsername", values);
|
const validEmails = [];
|
||||||
|
for (const line of lines) {
|
||||||
|
const columns = line.split(/,|;|\|| /);
|
||||||
|
for (const column of columns) {
|
||||||
|
const email = column.trim().toLowerCase();
|
||||||
|
|
||||||
|
if (emailRegex.test(email)) {
|
||||||
|
validEmails.push(email);
|
||||||
|
break; // Stop checking columns if a valid email is found in this line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newMemberFormMethods.setValue("emailOrUsername", validEmails);
|
||||||
};
|
};
|
||||||
|
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
|
|
Loading…
Reference in New Issue