From 267dbfc9c16bdb25892d1f80d5e972a912e95664 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 2 Apr 2022 11:53:52 -0300 Subject: [PATCH] Improve email parsing on sharing. --- .../action-dispatcher/share-dialog/index.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx b/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx index 77d5efbc..8b903f1f 100644 --- a/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx +++ b/packages/webapp/src/components/maps-page/action-dispatcher/share-dialog/index.tsx @@ -56,11 +56,18 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement } ); + const splitEmail = (emails: string): string[] => { + return emails.split(/,|;/) + .map(e => e.trim().replace(/\s/g, '')) + .filter(e => e.trim().length > 0); + } + + const addMutation = useMutation( (model: ShareModel) => { - const emails = model.emails.split(','); + const emails = splitEmail(model.emails); const permissions = emails.map((email: string) => { - return { email: email.replace(/\s/g, ''), role: model.role }; + return { email: email, role: model.role }; }); return client.addMapPermissions(mapId, model.message, permissions); }, @@ -114,9 +121,7 @@ const ShareDialog = ({ mapId, onClose }: SimpleDialogProps): React.ReactElement }; // very basic email validation, just make sure the basic syntax is fine - const isValid = model.emails - .split(/,|;/) - .filter(e => e.trim().length > 0) + const isValid = splitEmail(model.emails) .every(str => /\S+@\S+\.\S+/.test((str || '') .trim()));