fix(profile-form): optional email

This commit is contained in:
devthejo 2025-04-23 15:06:25 +02:00
parent ccd8373edb
commit 426054bc0e

View file

@ -35,19 +35,11 @@ const schema = {
properties: {
login: { type: "string" },
email: {
oneOf: [
{
type: "string",
format: "email",
errorMessage: {
format: "adresse email invalide",
},
},
{
type: "string",
maxLength: 0,
},
],
type: "string",
pattern: "^$|^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$", // format: "email" doesn't seem to allow optional (tried many approaches)
errorMessage: {
pattern: "adresse email invalide",
},
},
},
};
@ -101,7 +93,7 @@ export default function Form({
const onSubmit = useCallback(
async (data) => {
if (!(email && email === data.email)) {
if (data.email && !(email && email === data.email)) {
const isRegistered = await checkEmailIsRegistered(data.email);
if (isRegistered) {
setError("email", {