Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Inviting Users to Course by Email #7655

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bivanalhar
Copy link
Contributor

Feature

Inside Manage Users > Invite Users, we have an additional feature in which user can copy-paste list of names and emails, and then the invitation lists will be updated automatically to include all the users enlisted within the list.

Screenshot 2024-11-21 at 4 40 41 PM

Should the format has an error in some of the users, then we updated the list to include those correctly-formatted users and inform user about the errors, so that the inviter can modify the name / email accordingly

Screenshot 2024-11-21 at 4 43 56 PM

@bivanalhar bivanalhar force-pushed the bivan/course-invitation-email-copy branch from 5d70495 to eff71f6 Compare November 21, 2024 08:45
@bivanalhar bivanalhar force-pushed the bivan/course-invitation-email-copy branch from eff71f6 to 494dc57 Compare November 21, 2024 08:46
Comment on lines +134 to +156
export const splitEntries = (input: string): string[] => {
const entries: string[] = [];
let currentEntry = '';
let inQuotes = false;
for (let i = 0; i < input.length; i++) {
const char = input[i];
if (char === '"') {
inQuotes = !inQuotes;
currentEntry += char;
} else if ((char === ',' || char === ';') && !inQuotes) {
if (currentEntry.trim()) {
entries.push(currentEntry.trim());
}
currentEntry = '';
} else {
currentEntry += char;
}
}
if (currentEntry.trim()) {
entries.push(currentEntry.trim());
}
return entries;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Split using regex instead of implementing an algorithm here instead.
difference is 2 lines vs 22 lines.

export const parseEmails = (
input: string,
): { results: InvitationEntry[]; errors: string[] } => {
const regex = /^(?:"([^"]+)"|([^"<]+))?\s*<([^>]+)>$|^([^"<\s]+@[^\s,;<>]+)$/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update variable name to formattedEmailRegex? regex is not meaningful

const match = regex.exec(entry);
if (match) {
if (match[3]) {
const name = (match[1] || match[2] || '').trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your regex should be written to exclude the surrounding whitespaces, so you won't need to use .trim() here.

Comment on lines +171 to +172
if (match[3]) {
const name = (match[1] || match[2] || '').trim();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify the regex? Why so many cases?

});
};

const parsedEmail = parseEmails(nameEmailInput);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parsedEmails plural?

Comment on lines +90 to +95
name: entry.name,
email: entry.email,
role: lastRow.role,
phantom: lastRow.phantom,
...(permissions.canManagePersonalTimes && {
timelineAlgorithm: lastRow.timelineAlgorithm,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code duplication here. You should make use of appendNewRow and extend it by allowing name and email arguments (default '').

variant="filled"
/>
<Button
className="w-1/8 h-[3.5rem]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: avoid hardcoding [3.5rem] if possible, can we use a default value?

Comment on lines +123 to +125
parsedEmail.errors.length > 0
? parsedEmail.errors.join('; ')
: '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the length is 0 then parsedEmail.errors.join('; ') will still be an empty string, what's the point of this ternary if-else then?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants