Skip to content

Commit

Permalink
Refactor email input handling to format comma-separated addresses
Browse files Browse the repository at this point in the history
- Introduced `getFormattedEmailOptions` to split and trim comma-separated email values
- Updated EuiComboBox to handle email entry for `to`, `cc`, and `bcc` fields

Signed-off-by: Oyelola Victoria <[email protected]>
  • Loading branch information
VriaA committed Sep 29, 2024
1 parent fb79799 commit 877c51d
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export const EmailParamsFields = ({
const isBCCInvalid: boolean =
errors.bcc !== undefined && Number(errors.bcc.length) > 0 && bcc !== undefined;

const getFormattedEmailOptions = (
searchValue: string,
previousOptions: Array<{ label: string }>
): Array<{ label: string }> => {
const formattedOptions: Array<{ label: string }> = searchValue
.split(',')
.map((value) => ({ label: value.trim() }));
return [...previousOptions, ...formattedOptions];
};

return (
<>
<EuiFormRow
Expand Down Expand Up @@ -105,7 +115,7 @@ export const EmailParamsFields = ({
data-test-subj="toEmailAddressInput"
selectedOptions={toOptions}
onCreateOption={(searchValue: string) => {
const newOptions = [...toOptions, { label: searchValue }];
const newOptions = getFormattedEmailOptions(searchValue, toOptions);
editAction(
'to',
newOptions.map((newOption) => newOption.label),
Expand Down Expand Up @@ -148,7 +158,7 @@ export const EmailParamsFields = ({
data-test-subj="ccEmailAddressInput"
selectedOptions={ccOptions}
onCreateOption={(searchValue: string) => {
const newOptions = [...ccOptions, { label: searchValue }];
const newOptions = getFormattedEmailOptions(searchValue, ccOptions);
editAction(
'cc',
newOptions.map((newOption) => newOption.label),
Expand Down Expand Up @@ -192,7 +202,7 @@ export const EmailParamsFields = ({
data-test-subj="bccEmailAddressInput"
selectedOptions={bccOptions}
onCreateOption={(searchValue: string) => {
const newOptions = [...bccOptions, { label: searchValue }];
const newOptions = getFormattedEmailOptions(searchValue, bccOptions);
editAction(
'bcc',
newOptions.map((newOption) => newOption.label),
Expand Down

0 comments on commit 877c51d

Please sign in to comment.