Skip to content

Commit

Permalink
fix(email): add email check
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihoub2 committed Nov 6, 2023
1 parent 86de8da commit 98b5e64
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/forms/emails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import FormFooter from '../form-footer';
import useFetch from '../../../hooks/useFetch';
import useForm from '../../../hooks/useForm';
import PaysageBlame from '../../paysage-blame';
import validateEmail from '../../../utils/mail-validation';

function validate(body) {
const validationErrors = {};
if (!body.emailTypeId) { validationErrors.emailTypeId = 'Le type est obligatoire'; }
if (!body.email) { validationErrors.email = 'Un email est obligatoire.'; }
if (!validateEmail(body.email) && body.email) { validationErrors.email = "L'adresse mail n'est pas valide."; }

return validationErrors;
}

Expand Down Expand Up @@ -68,8 +71,8 @@ export default function EmailForm({ id, data, onDelete, onSave }) {
label="Email"
value={form.email || ''}
onChange={(e) => updateForm({ email: e.target.value })}
message={(showErrors && errors.documentTypeId) ? errors.documentTypeId : null}
messageType={(showErrors && errors.documentTypeId) ? 'error' : ''}
message={(showErrors && errors.email) ? errors.email : null}
messageType={(showErrors && errors.email) ? 'error' : ''}
/>
</Col>
</Row>
Expand Down

0 comments on commit 98b5e64

Please sign in to comment.