Skip to content

Commit ecdbf8e

Browse files
committed
WIP for #540
1 parent 7aa42b7 commit ecdbf8e

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

client/src/components/EmailField.jsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ export default function EmailField({
1515
pinnedEmails = [],
1616
error = false,
1717
grabFocus = true,
18-
required = false
18+
required = false,
19+
maxEmails = null,
20+
maxEmailsMessage = null
1921
}) {
2022

2123
const [emailErrors, setEmailErrors] = useState([]);
24+
const [displayMaxEmailMessage, setDisplayMaxEmailMessage] = useState(false);
2225
const [value, setValue] = useState("");
2326

2427
const refContainer = useRef(null);
@@ -62,9 +65,9 @@ export default function EmailField({
6265
const email = e.target.value;
6366
const invalidEmails = [];
6467
const delimiters = [",", " ", ";", "\n", "\t"];
65-
let emails;
68+
let localEmails;
6669
if (!isEmpty(email) && email.indexOf("<") > -1) {
67-
emails = email.split(/[,\n\t;]/)
70+
localEmails = email.split(/[,\n\t;]/)
6871
.map(e => e.trim())
6972
.filter(part => {
7073
const indexOf = part.indexOf("<");
@@ -74,21 +77,27 @@ export default function EmailField({
7477
} else if (!isEmpty(email) && delimiters.some(delimiter => email.indexOf(delimiter) > -1)) {
7578
const replacedEmails = email.replace(/[;\s]/g, ",");
7679
const splitEmails = replacedEmails.split(",");
77-
emails = splitEmails
80+
localEmails = splitEmails
7881
.filter(part => validateEmail(part, invalidEmails));
7982
} else if (!isEmpty(email)) {
8083
const valid = validEmailRegExp.test(email.trim());
8184
if (valid) {
82-
emails = [email];
85+
localEmails = [email];
8386
} else {
8487
invalidEmails.push(email.trim());
8588
}
8689
}
8790
setEmailErrors((!isEmpty(e.target.value) && !isEmpty(invalidEmails)) ? invalidEmails : []);
88-
const uniqueEmails = [...new Set(emails)];
89-
if (!isEmpty(uniqueEmails)) {
91+
const uniqueEmails = [...new Set(localEmails)];
92+
const nbrOfEmails = (emails || []).length + uniqueEmails.length;
93+
if (!isEmpty(uniqueEmails) && (isEmpty(maxEmails) || nbrOfEmails <= maxEmails)) {
9094
addEmails(uniqueEmails);
9195
}
96+
if (!isEmpty(maxEmails) && nbrOfEmails > maxEmails) {
97+
setDisplayMaxEmailMessage(true);
98+
} else {
99+
setDisplayMaxEmailMessage(false);
100+
}
92101
setValue("");
93102
};
94103

@@ -137,6 +146,10 @@ export default function EmailField({
137146
{(!isEmpty(emailErrors) && value === "") && <p className="error">
138147
{I18n.t("invitations.invalidEmails", {emails: Array.from(new Set(emailErrors)).join(", ")})}
139148
</p>}
149+
{(displayMaxEmailMessage && !isEmpty(maxEmailsMessage)) && <p className="error">
150+
{maxEmailsMessage}
151+
</p>}
152+
140153
</div>
141154
);
142155
}

client/src/pages/InvitationForm.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ export const InvitationForm = () => {
246246
pinnedEmails={[]}
247247
removeMail={removeMail}
248248
required={true}
249+
maxEmails={null} //TODO is there a internal placeholder identifier? then one
250+
maxEmailsMessage={"TODO : localize Not allowed to add more then one email"}
249251
error={!initial && isEmpty(invitation.invites)}/>
250252

251253
{(!initial && isEmpty(invitation.invites)) &&

0 commit comments

Comments
 (0)