feat: add validation for updating email on use profile (#391)
This commit is contained in:
@@ -13,13 +13,25 @@
|
||||
import { t } from '$lib/utils/functions/translations';
|
||||
import LanguagePicker from './LanguagePicker.svelte';
|
||||
import { handleLocaleChange } from '$lib/utils/functions/translations';
|
||||
import { updateProfileEmailValidation } from '$lib/utils/functions/validator';
|
||||
|
||||
let avatar = '';
|
||||
let loading = false;
|
||||
let hasLangChanged = false;
|
||||
let locale = '';
|
||||
|
||||
let errors = {
|
||||
email: ''
|
||||
}
|
||||
|
||||
async function handleUpdate() {
|
||||
errors = updateProfileEmailValidation($profile.email)
|
||||
|
||||
if (Object.values(errors).length) {
|
||||
loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log({ hasLangChanged });
|
||||
loading = true;
|
||||
@@ -103,6 +115,7 @@
|
||||
label={$t('settings.profile.personal_information.email')}
|
||||
bind:value={$profile.email}
|
||||
className="w-full lg:w-60 mb-4"
|
||||
errorMessage={errors.email}
|
||||
/>
|
||||
<LanguagePicker bind:hasLangChanged bind:value={locale} className="w-full lg:w-60 mb-4" />
|
||||
</Column>
|
||||
|
||||
@@ -271,6 +271,14 @@ export const updateOrgSiteNameValidation = (siteName) => {
|
||||
|
||||
return processErrors(error);
|
||||
};
|
||||
export const updateProfileEmailValidation = (email) => {
|
||||
const schema = z.object({
|
||||
email: z.string().email({ message: `${t.get('validations.user_profile.email')}` })
|
||||
});
|
||||
const { error } = schema.safeParse({ email });
|
||||
|
||||
return processErrors(error);
|
||||
};
|
||||
|
||||
export const createQuizValidation = (fields = {}) => {
|
||||
const { error } = createQuizValidationSchema.safeParse(fields);
|
||||
|
||||
@@ -1328,6 +1328,9 @@
|
||||
},
|
||||
|
||||
"validations": {
|
||||
"user_profile": {
|
||||
"email": "Invalid email address"
|
||||
},
|
||||
"organization_name": {
|
||||
"min_char": "Organization must contain 5 or more characters",
|
||||
"hyphen_rule": "Organization name cannot start or end with a hyphen"
|
||||
|
||||
Reference in New Issue
Block a user