From 3a992505087b43dd0cb795c32f3bdf33648f35e7 Mon Sep 17 00:00:00 2001 From: Trial Date: Mon, 31 Mar 2025 23:45:09 +0300 Subject: [PATCH] added lowercase text onchange --- src/Components/TabPanels/Account/TeamPanel.jsx | 7 ++++--- src/Features/Auth/authSlice.js | 6 ++---- src/Pages/Auth/Login/Login.jsx | 5 +++-- src/Pages/Auth/Register/Register.jsx | 5 +++-- src/Validation/validation.js | 7 +++++++ 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Components/TabPanels/Account/TeamPanel.jsx b/src/Components/TabPanels/Account/TeamPanel.jsx index 93fcb6d23..72ff55eee 100644 --- a/src/Components/TabPanels/Account/TeamPanel.jsx +++ b/src/Components/TabPanels/Account/TeamPanel.jsx @@ -107,12 +107,13 @@ const TeamPanel = () => { const handleChange = (event) => { const { value } = event.target; + const newEmail = value?.toLowerCase() || value setToInvite((prev) => ({ ...prev, - email: value, + email: newEmail, })); - const validation = credentials.validate({ email: value }, { abortEarly: false }); + const validation = credentials.validate({ email: newEmail }, { abortEarly: false }); setErrors((prev) => { const updatedErrors = { ...prev }; @@ -153,7 +154,7 @@ const TeamPanel = () => { try { await networkService.sendInvitationToken({ - email: toInvite.email.toLowerCase(), + email: toInvite.email, role: toInvite.role, }); closeInviteModal(); diff --git a/src/Features/Auth/authSlice.js b/src/Features/Auth/authSlice.js index 2fe089971..2fde49202 100644 --- a/src/Features/Auth/authSlice.js +++ b/src/Features/Auth/authSlice.js @@ -12,8 +12,7 @@ const initialState = { export const register = createAsyncThunk("auth/register", async (form, thunkApi) => { try { - const newForm = {...form, email: form.email.toLowerCase()} - const res = await networkService.registerUser(newForm); + const res = await networkService.registerUser(form); return res.data; } catch (error) { if (error.response.data) { @@ -29,8 +28,7 @@ export const register = createAsyncThunk("auth/register", async (form, thunkApi) export const login = createAsyncThunk("auth/login", async (form, thunkApi) => { try { - const newForm = {...form, email: form.email.toLowerCase()} - const res = await networkService.loginUser(newForm); + const res = await networkService.loginUser(form); return res.data; } catch (error) { if (error.response && error.response.data) { diff --git a/src/Pages/Auth/Login/Login.jsx b/src/Pages/Auth/Login/Login.jsx index c13218018..9db56ae49 100644 --- a/src/Pages/Auth/Login/Login.jsx +++ b/src/Pages/Auth/Login/Login.jsx @@ -63,12 +63,13 @@ const Login = () => { const handleChange = (event) => { const { value, id } = event.target; const name = idMap[id]; + const lowerCasedValue = name === idMap["login-email-input"]? value?.toLowerCase()||value : value setForm((prev) => ({ ...prev, - [name]: value, + [name]: lowerCasedValue, })); - const { error } = credentials.validate({ [name]: value }, { abortEarly: false }); + const { error } = credentials.validate({ [name]: lowerCasedValue }, { abortEarly: false }); setErrors((prev) => { const prevErrors = { ...prev }; diff --git a/src/Pages/Auth/Register/Register.jsx b/src/Pages/Auth/Register/Register.jsx index afb05435c..118357432 100644 --- a/src/Pages/Auth/Register/Register.jsx +++ b/src/Pages/Auth/Register/Register.jsx @@ -259,13 +259,14 @@ const Register = ({ isSuperAdmin }) => { const handleChange = (event) => { const { value, id } = event.target; const name = idMap[id]; + const lowerCasedValue = name === idMap["register-email-input"]? value?.toLowerCase() || value : value setForm((prev) => ({ ...prev, - [name]: value, + [name]: lowerCasedValue, })); const { error } = credentials.validate( - { [name]: value }, + { [name]: lowerCasedValue }, { abortEarly: false, context: { password: form.password } } ); diff --git a/src/Validation/validation.js b/src/Validation/validation.js index 48b57d046..6e8ff76cb 100644 --- a/src/Validation/validation.js +++ b/src/Validation/validation.js @@ -65,6 +65,13 @@ const credentials = joi.object({ .string() .trim() .email({ tlds: { allow: false } }) + .custom((value, helpers) => { + const lowercasedValue = value.toLowerCase(); + if (value !== lowercasedValue) { + return helpers.message("Email must be in lowercase"); + } + return lowercasedValue; + }) .messages({ "string.empty": "Email is required", "string.email": "Must be a valid email address",