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 { 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';
|
||||||
|
|
||||||
let avatar = '';
|
let avatar = '';
|
||||||
let loading = false;
|
let loading = false;
|
||||||
let hasLangChanged = false;
|
let hasLangChanged = false;
|
||||||
let locale = '';
|
let locale = '';
|
||||||
|
|
||||||
|
let errors = {
|
||||||
|
email: ''
|
||||||
|
}
|
||||||
|
|
||||||
async function handleUpdate() {
|
async function handleUpdate() {
|
||||||
|
errors = updateProfileEmailValidation($profile.email)
|
||||||
|
|
||||||
|
if (Object.values(errors).length) {
|
||||||
|
loading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log({ hasLangChanged });
|
console.log({ hasLangChanged });
|
||||||
loading = true;
|
loading = true;
|
||||||
@@ -103,6 +115,7 @@
|
|||||||
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}
|
||||||
/>
|
/>
|
||||||
<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>
|
||||||
|
|||||||
@@ -271,6 +271,14 @@ export const updateOrgSiteNameValidation = (siteName) => {
|
|||||||
|
|
||||||
return processErrors(error);
|
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 = {}) => {
|
export const createQuizValidation = (fields = {}) => {
|
||||||
const { error } = createQuizValidationSchema.safeParse(fields);
|
const { error } = createQuizValidationSchema.safeParse(fields);
|
||||||
|
|||||||
@@ -1328,6 +1328,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"validations": {
|
"validations": {
|
||||||
|
"user_profile": {
|
||||||
|
"email": "Invalid email address"
|
||||||
|
},
|
||||||
"organization_name": {
|
"organization_name": {
|
||||||
"min_char": "Organization must contain 5 or more characters",
|
"min_char": "Organization must contain 5 or more characters",
|
||||||
"hyphen_rule": "Organization name cannot start or end with a hyphen"
|
"hyphen_rule": "Organization name cannot start or end with a hyphen"
|
||||||
|
|||||||
Reference in New Issue
Block a user