Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
fix: [CAL-2593] Uploading a CSV File does not comma separate the valu…
Browse files Browse the repository at this point in the history
…es (calcom#11756)

* csv email validation added

* most common csv delimeters added
  • Loading branch information
Chiranjeev-droid authored Oct 16, 2023
1 parent bab72a5 commit 461120a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions packages/features/ee/teams/components/MemberInvitationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,24 @@ export default function MemberInvitationModal(props: MemberInvitationModalProps)

if (file) {
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) => {
const contents = e?.target?.result as string;
const values = contents?.split(",").map((email) => email.trim().toLocaleLowerCase());
newMemberFormMethods.setValue("emailOrUsername", values);
const lines = contents.split("\n");
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);
Expand Down

0 comments on commit 461120a

Please sign in to comment.