Merge pull request #9966 from demarches-simplifiees/etq-admin-je-peux-coller-une-liste-d-emails-d-experts

ETQ admin ou instructeur je peux copier une liste d'emails pour inviter des experts
This commit is contained in:
Eric Leroy-Terquem 2024-02-28 14:49:04 +00:00 committed by GitHub
commit efa19926e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 107 additions and 6 deletions

View file

@ -87,6 +87,7 @@ export default function ComboMultiple({
: options.filter((o) => o).map((o) => [o, o]),
[options]
);
const extraOptions = useMemo(
() =>
acceptNewValues &&
@ -97,6 +98,15 @@ export default function ComboMultiple({
: [],
[acceptNewValues, term, optionsWithLabels, newValues]
);
const extraListOptions = useMemo(
() =>
acceptNewValues && term && term.length > 2 && term.includes(';')
? term.split(';').map((val) => [val.trim(), val.trim()])
: [],
[acceptNewValues, term]
);
const results = useMemo(
() =>
[
@ -129,12 +139,22 @@ export default function ComboMultiple({
const maybeValue = [...extraOptions, ...optionsWithLabels].find(
([, val]) => val == value
);
const selectedValue = maybeValue && maybeValue[1];
const maybeValueFromListOptions = extraListOptions.find(
([, val]) => val == value
);
const selectedValue =
term.includes(';') && acceptNewValues
? maybeValueFromListOptions && maybeValueFromListOptions[1]
: maybeValue && maybeValue[1];
if (selectedValue) {
if (
acceptNewValues &&
extraOptions[0] &&
extraOptions[0][0] == selectedValue
(acceptNewValues &&
extraOptions[0] &&
extraOptions[0][0] == selectedValue) ||
(acceptNewValues && extraListOptions[0])
) {
setNewValues((newValues) => {
const set = new Set(newValues);
@ -172,7 +192,12 @@ export default function ComboMultiple({
isHotkey(',', event) ||
isHotkey(';', event)
) {
if (
if (term.includes(';')) {
for (const val of term.split(';')) {
event.preventDefault();
onSelect(val.trim());
}
} else if (
term &&
[...extraOptions, ...optionsWithLabels]
.map(([label]) => label)
@ -204,7 +229,11 @@ export default function ComboMultiple({
.includes(term);
awaitFormSubmit(() => {
if (shouldSelect) {
if (term.includes(';')) {
for (const val of term.split(';')) {
onSelect(val.trim());
}
} else if (shouldSelect) {
onSelect(term);
} else {
hidePopover();