-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemberEmailInput.tsx
More file actions
37 lines (32 loc) · 1021 Bytes
/
MemberEmailInput.tsx
File metadata and controls
37 lines (32 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { useState, KeyboardEvent } from 'react';
import EmailInputBase from '../../../shared/ui/EmailInputBase';
interface MemberEmailInputProps {
emails: string[];
setEmails: React.Dispatch<React.SetStateAction<string[]>>;
}
const MemberEmailInput = ({ emails, setEmails }: MemberEmailInputProps) => {
const [inputValue, setInputValue] = useState('');
const handleKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
if (e.key === 'Enter' && inputValue.trim()) {
e.preventDefault();
if (inputValue.includes('@')) {
setEmails([...emails, inputValue.trim()]);
setInputValue('');
}
}
};
const removeEmail = (indexToRemove: number) => {
setEmails(emails.filter((_, index) => index !== indexToRemove));
};
return (
<EmailInputBase
emails={emails}
inputValue={inputValue}
setInputValue={setInputValue}
onRemove={removeEmail}
onKeyDown={handleKeyDown}
showAllEmails={true}
/>
);
};
export default MemberEmailInput;