From 44411454b246a9d60dd8a96fc7f766661a7b65f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chlo=C3=A9=20CHAUVIN?= Date: Tue, 10 Jan 2023 10:31:03 +0100 Subject: [PATCH] [WIP] finished the aesthetic but not functionnal --- front/components/forms/changeEmailForm.tsx | 119 ++++++++++++++------- 1 file changed, 82 insertions(+), 37 deletions(-) diff --git a/front/components/forms/changeEmailForm.tsx b/front/components/forms/changeEmailForm.tsx index b27ce55..fa6a0c6 100644 --- a/front/components/forms/changeEmailForm.tsx +++ b/front/components/forms/changeEmailForm.tsx @@ -12,12 +12,22 @@ import { } from "native-base"; interface ChangeEmailFormProps { - onSubmit: (newEmail: string) => Promise; + onSubmit: ( + oldEmail: string, + newEmail: string + ) => Promise; } +const validationSchemas = { + email: string().email("Invalid email").required("Email is required"), +}; const ChangeEmailForm = ({ onSubmit }: ChangeEmailFormProps) => { const [formData, setFormData] = React.useState({ + oldEmail: { + value: "", + error: null as string | null, + }, newEmail: { value: "", error: null as string | null, @@ -30,44 +40,79 @@ const ChangeEmailForm = ({ onSubmit }: ChangeEmailFormProps) => { return ( - - Test - { - // let error: null | string = null; - // setFormData({ ...formData, newEmail: { value: t, error } }); - // } - // } - /> - - + + {translate("oldEmail")} + { + let error: null | string = null; + validationSchemas.email + .validate(t) + .catch((e) => (error = e.message)) + .finally(() => { + setFormData({ ...formData, oldEmail: { value: t, error } }); + }); + }} + /> + } > + {formData.oldEmail.error} + + + {translate("newEmail")} + { + let error: null | string = null; + validationSchemas.email + .validate(t) + .catch((e) => (error = e.message)) + .finally(() => { + setFormData({ ...formData, newEmail: { value: t, error } }); + }); + }} + /> + } > + {formData.oldEmail.error} + + + + ); } -export default ChangeEmailForm +export default ChangeEmailForm;