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

[FIX] Feedback on bulk invite #20339

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/lib/server/methods/sendInvitationEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Meteor.methods({
}
const validEmails = emails.filter(Mailer.checkAddressFormat);

if (!validEmails || validEmails.length === 0) {
throw new Meteor.Error('error-email-send-failed', 'No valid email addresses', {
method: 'sendInvitationEmail',
});
}

const subject = settings.get('Invitation_Subject');

return validEmails.filter((email) => {
Expand Down
16 changes: 7 additions & 9 deletions client/views/admin/users/InviteUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ export function InviteUsers({ data, ...props }) {
const [text, setText] = useState('');
const sendInvites = useMethod('sendInvitationEmail');
const getEmails = useCallback((text) => text.split(/[\ ,;]+/i).filter((val) => isEmail(val)), []);
const handleClick = () => {
sendInvites(getEmails(text), (error, result) => {
if (result) {
return dispatchToastMessage({ type: 'success', message: t('Emails_sent_successfully!') });
}
if (error) {
return dispatchToastMessage({ type: 'error', message: error });
}
});
const handleClick = async () => {
try {
await sendInvites(getEmails(text));
dispatchToastMessage({ type: 'success', message: t('Emails_sent_successfully!') });
} catch (error) {
dispatchToastMessage({ type: 'error', message: error.message });
}
};
return <VerticalBar.ScrollableContent {...props}>
<Box is='h2' fontScale='h1' mb='x8'>{t('Send_invitation_email')}</Box>
Expand Down