Skip to content

Commit 9fd2a8a

Browse files
committed
2024-11-08 - non-recipient search
1 parent 6aa1bda commit 9fd2a8a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

web-ui/src/components/feedback_external_recipient_selector/NewExternalRecipientModal.jsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,23 @@ const NewExternalRecipientModal = ({ open, onClose, onSubmit }) => {
88
const [firstName, setFirstName] = useState('');
99
const [lastName, setLastName] = useState('');
1010
const [companyName, setCompanyName] = useState('');
11+
const [emailError, setEmailError] = useState('');
1112

1213
useEffect(() => {
1314
if (open) {
1415
setEmail('');
1516
setFirstName('');
1617
setLastName('');
1718
setCompanyName('');
19+
setEmailError('');
1820
}
1921
}, [open]);
2022

2123
const handleSubmit = () => {
24+
if (!validateEmail(email)) {
25+
setEmailError('Please enter a valid email address');
26+
return;
27+
}
2228
const newRecipient = {
2329
email,
2430
firstName,
@@ -28,6 +34,11 @@ const NewExternalRecipientModal = ({ open, onClose, onSubmit }) => {
2834
onSubmit(newRecipient);
2935
};
3036

37+
const validateEmail = (email) => {
38+
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
39+
return re.test(String(email).toLowerCase());
40+
};
41+
3142
return (
3243
<Modal open={open} onClose={onClose}>
3344
<Box sx={{ ...modalStyle }}>
@@ -44,7 +55,12 @@ const NewExternalRecipientModal = ({ open, onClose, onSubmit }) => {
4455
<TextField
4556
label="Email"
4657
value={email}
47-
onChange={(e) => setEmail(e.target.value)}
58+
onChange={(e) => {
59+
setEmail(e.target.value);
60+
if (emailError) setEmailError('');
61+
}}
62+
error={!!emailError}
63+
helperText={emailError}
4864
fullWidth
4965
margin="normal"
5066
/>
@@ -69,7 +85,12 @@ const NewExternalRecipientModal = ({ open, onClose, onSubmit }) => {
6985
fullWidth
7086
margin="normal"
7187
/>
72-
<Button variant="contained" color="primary" onClick={handleSubmit}>
88+
<Button
89+
variant="contained"
90+
color="primary"
91+
onClick={handleSubmit}
92+
disabled={!email || !!emailError}
93+
>
7394
Submit
7495
</Button>
7596
</Box>

0 commit comments

Comments
 (0)