fix: validation on profile page (#398)
* fix validation of username and fullname * fix * fix message * Update validator.js * Update Profile.svelte * remove unused functions --------- Co-authored-by: Rotimi Best <best@classroomio.com>
This commit is contained in:
co-authored by
Rotimi Best
parent
1f91299544
commit
7a2954faba
@@ -13,21 +13,18 @@
|
|||||||
import { t } from '$lib/utils/functions/translations';
|
import { t } from '$lib/utils/functions/translations';
|
||||||
import LanguagePicker from './LanguagePicker.svelte';
|
import LanguagePicker from './LanguagePicker.svelte';
|
||||||
import { handleLocaleChange } from '$lib/utils/functions/translations';
|
import { handleLocaleChange } from '$lib/utils/functions/translations';
|
||||||
import { updateProfileEmailValidation } from '$lib/utils/functions/validator';
|
import { updateProfileValidation } from '$lib/utils/functions/validator';
|
||||||
|
|
||||||
let avatar = '';
|
let avatar = '';
|
||||||
let loading = false;
|
let loading = false;
|
||||||
let hasLangChanged = false;
|
let hasLangChanged = false;
|
||||||
let locale = '';
|
let locale = '';
|
||||||
|
|
||||||
let errors = {
|
let errors = {};
|
||||||
email: ''
|
|
||||||
}
|
|
||||||
|
|
||||||
async function handleUpdate() {
|
async function handleUpdate() {
|
||||||
errors = updateProfileEmailValidation($profile.email)
|
errors = updateProfileValidation($profile);
|
||||||
|
if (Object.values(errors).some((error) => error)) {
|
||||||
if (Object.values(errors).length) {
|
|
||||||
loading = false;
|
loading = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -105,17 +102,19 @@
|
|||||||
label={$t('settings.profile.personal_information.full_name')}
|
label={$t('settings.profile.personal_information.full_name')}
|
||||||
bind:value={$profile.fullname}
|
bind:value={$profile.fullname}
|
||||||
className="w-full lg:w-60 mb-4"
|
className="w-full lg:w-60 mb-4"
|
||||||
|
errorMessage={$t(errors.fullname)}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
label={$t('settings.profile.personal_information.username')}
|
label={$t('settings.profile.personal_information.username')}
|
||||||
bind:value={$profile.username}
|
bind:value={$profile.username}
|
||||||
className="w-full lg:w-60 mb-4"
|
className="w-full lg:w-60 mb-4"
|
||||||
|
errorMessage={$t(errors.username)}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
label={$t('settings.profile.personal_information.email')}
|
label={$t('settings.profile.personal_information.email')}
|
||||||
bind:value={$profile.email}
|
bind:value={$profile.email}
|
||||||
className="w-full lg:w-60 mb-4"
|
className="w-full lg:w-60 mb-4"
|
||||||
errorMessage={errors.email}
|
errorMessage={$t(errors.email)}
|
||||||
/>
|
/>
|
||||||
<LanguagePicker bind:hasLangChanged bind:value={locale} className="w-full lg:w-60 mb-4" />
|
<LanguagePicker bind:hasLangChanged bind:value={locale} className="w-full lg:w-60 mb-4" />
|
||||||
</Column>
|
</Column>
|
||||||
|
|||||||
@@ -125,6 +125,12 @@ const onboardingValidationSchema = {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const updateProfileValidationSchema = z.object({
|
||||||
|
email: z.string().email({ message: 'validations.user_profile.email' }),
|
||||||
|
username: z.string().nonempty({ message: 'validations.user_profile.username' }),
|
||||||
|
fullname: z.string().min(5, { message: 'validations.user_profile.fullname' })
|
||||||
|
});
|
||||||
|
|
||||||
export const getConfirmPasswordError = ({ password, confirmPassword }) => {
|
export const getConfirmPasswordError = ({ password, confirmPassword }) => {
|
||||||
return password > 6 && confirmPassword > 6 && password !== confirmPassword
|
return password > 6 && confirmPassword > 6 && password !== confirmPassword
|
||||||
? `${t.get('validations.confirm_password.not_match')}`
|
? `${t.get('validations.confirm_password.not_match')}`
|
||||||
@@ -213,6 +219,13 @@ export const onboardingValidation = (fields = {}, step) => {
|
|||||||
return processErrors(error);
|
return processErrors(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateProfileValidation = (fields = {}) => {
|
||||||
|
const schema = updateProfileValidationSchema;
|
||||||
|
const { error } = schema.safeParse(fields);
|
||||||
|
|
||||||
|
return processErrors(error);
|
||||||
|
};
|
||||||
|
|
||||||
// export const createTemplateExerciseValidation = (fields = {}) => {
|
// export const createTemplateExerciseValidation = (fields = {}) => {
|
||||||
// const schema = z.object({
|
// const schema = z.object({
|
||||||
// orgName: z.string().min(5, {
|
// orgName: z.string().min(5, {
|
||||||
|
|||||||
@@ -1329,7 +1329,9 @@
|
|||||||
|
|
||||||
"validations": {
|
"validations": {
|
||||||
"user_profile": {
|
"user_profile": {
|
||||||
"email": "Invalid email address"
|
"email": "Invalid email address",
|
||||||
|
"username":"Username cannot be empty",
|
||||||
|
"fullname":"Name should be minimum of 5 characters"
|
||||||
},
|
},
|
||||||
"organization_name": {
|
"organization_name": {
|
||||||
"min_char": "Organization must contain 5 or more characters",
|
"min_char": "Organization must contain 5 or more characters",
|
||||||
|
|||||||
Reference in New Issue
Block a user