added lowercase text onchange
This commit is contained in:
1 parent
dacf729bca
commit
3a99250508
5 files changed
+19
-11
No files matched your search
@@ -107,12 +107,13 @@ const TeamPanel = () => {
|
|||||||
|
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { value } = event.target;
|
const { value } = event.target;
|
||||||
|
const newEmail = value?.toLowerCase() || value
|
||||||
setToInvite((prev) => ({
|
setToInvite((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
email: value,
|
email: newEmail,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const validation = credentials.validate({ email: value }, { abortEarly: false });
|
const validation = credentials.validate({ email: newEmail }, { abortEarly: false });
|
||||||
|
|
||||||
setErrors((prev) => {
|
setErrors((prev) => {
|
||||||
const updatedErrors = { ...prev };
|
const updatedErrors = { ...prev };
|
||||||
@@ -153,7 +154,7 @@ const TeamPanel = () => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await networkService.sendInvitationToken({
|
await networkService.sendInvitationToken({
|
||||||
email: toInvite.email.toLowerCase(),
|
email: toInvite.email,
|
||||||
role: toInvite.role,
|
role: toInvite.role,
|
||||||
});
|
});
|
||||||
closeInviteModal();
|
closeInviteModal();
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ const initialState = {
|
|||||||
|
|
||||||
export const register = createAsyncThunk("auth/register", async (form, thunkApi) => {
|
export const register = createAsyncThunk("auth/register", async (form, thunkApi) => {
|
||||||
try {
|
try {
|
||||||
const newForm = {...form, email: form.email.toLowerCase()}
|
const res = await networkService.registerUser(form);
|
||||||
const res = await networkService.registerUser(newForm);
|
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response.data) {
|
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) => {
|
export const login = createAsyncThunk("auth/login", async (form, thunkApi) => {
|
||||||
try {
|
try {
|
||||||
const newForm = {...form, email: form.email.toLowerCase()}
|
const res = await networkService.loginUser(form);
|
||||||
const res = await networkService.loginUser(newForm);
|
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.data) {
|
if (error.response && error.response.data) {
|
||||||
|
|||||||
@@ -63,12 +63,13 @@ const Login = () => {
|
|||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
const name = idMap[id];
|
const name = idMap[id];
|
||||||
|
const lowerCasedValue = name === idMap["login-email-input"]? value?.toLowerCase()||value : value
|
||||||
setForm((prev) => ({
|
setForm((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[name]: value,
|
[name]: lowerCasedValue,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { error } = credentials.validate({ [name]: value }, { abortEarly: false });
|
const { error } = credentials.validate({ [name]: lowerCasedValue }, { abortEarly: false });
|
||||||
|
|
||||||
setErrors((prev) => {
|
setErrors((prev) => {
|
||||||
const prevErrors = { ...prev };
|
const prevErrors = { ...prev };
|
||||||
|
|||||||
@@ -259,13 +259,14 @@ const Register = ({ isSuperAdmin }) => {
|
|||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
const name = idMap[id];
|
const name = idMap[id];
|
||||||
|
const lowerCasedValue = name === idMap["register-email-input"]? value?.toLowerCase() || value : value
|
||||||
setForm((prev) => ({
|
setForm((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
[name]: value,
|
[name]: lowerCasedValue,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { error } = credentials.validate(
|
const { error } = credentials.validate(
|
||||||
{ [name]: value },
|
{ [name]: lowerCasedValue },
|
||||||
{ abortEarly: false, context: { password: form.password } }
|
{ abortEarly: false, context: { password: form.password } }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,13 @@ const credentials = joi.object({
|
|||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
.email({ tlds: { allow: false } })
|
.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({
|
.messages({
|
||||||
"string.empty": "Email is required",
|
"string.empty": "Email is required",
|
||||||
"string.email": "Must be a valid email address",
|
"string.email": "Must be a valid email address",
|
||||||
|
|||||||
Reference in new issue
Block a user