mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-25 15:47:55 +01:00
Improve email parsing on sharing.
This commit is contained in:
parent
819428651e
commit
267dbfc9c1
@ -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(
|
const addMutation = useMutation(
|
||||||
(model: ShareModel) => {
|
(model: ShareModel) => {
|
||||||
const emails = model.emails.split(',');
|
const emails = splitEmail(model.emails);
|
||||||
const permissions = emails.map((email: string) => {
|
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);
|
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
|
// very basic email validation, just make sure the basic syntax is fine
|
||||||
const isValid = model.emails
|
const isValid = splitEmail(model.emails)
|
||||||
.split(/,|;/)
|
|
||||||
.filter(e => e.trim().length > 0)
|
|
||||||
.every(str => /\S+@\S+\.\S+/.test((str || '')
|
.every(str => /\S+@\S+\.\S+/.test((str || '')
|
||||||
.trim()));
|
.trim()));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user