feat: enforce rule of orgsite name min 5 char (#184)
This commit is contained in:
@@ -86,6 +86,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
$: video = get(courseData, 'metadata.videoUrl');
|
$: video = get(courseData, 'metadata.videoUrl');
|
||||||
|
$: allowNewStudent = get(courseData, 'metadata.allowNewStudent');
|
||||||
$: bannerImage = get(courseData, 'logo');
|
$: bannerImage = get(courseData, 'logo');
|
||||||
$: lessons = get(courseData, 'lessons', []);
|
$: lessons = get(courseData, 'lessons', []);
|
||||||
$: instructor = get(courseData, 'metadata.instructor') || {};
|
$: instructor = get(courseData, 'metadata.instructor') || {};
|
||||||
@@ -120,7 +121,7 @@
|
|||||||
if (editMode) return;
|
if (editMode) return;
|
||||||
startCoursePayment = true;
|
startCoursePayment = true;
|
||||||
}}
|
}}
|
||||||
isDisabled={!courseData.metadata.allowNewStudent}
|
isDisabled={!allowNewStudent}
|
||||||
/>
|
/>
|
||||||
{#if $handleOpenWidget.open}
|
{#if $handleOpenWidget.open}
|
||||||
<UploadWidget bind:imageURL={$course.logo} />
|
<UploadWidget bind:imageURL={$course.logo} />
|
||||||
|
|||||||
@@ -11,14 +11,28 @@
|
|||||||
import { snackbar } from '$lib/components/Snackbar/store';
|
import { snackbar } from '$lib/components/Snackbar/store';
|
||||||
import SectionTitle from '../SectionTitle.svelte';
|
import SectionTitle from '../SectionTitle.svelte';
|
||||||
import VisitOrgSiteButton from '$lib/components/Buttons/VisitOrgSite.svelte';
|
import VisitOrgSiteButton from '$lib/components/Buttons/VisitOrgSite.svelte';
|
||||||
|
import { updateOrgSiteNameValidation } from '$lib/utils/functions/validator';
|
||||||
|
|
||||||
|
type Error = {
|
||||||
|
siteName: string;
|
||||||
|
};
|
||||||
|
|
||||||
let siteName = '';
|
let siteName = '';
|
||||||
let errors = '';
|
let errors: Error = {
|
||||||
|
siteName: ''
|
||||||
|
};
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
|
||||||
async function handleChangeDomain() {
|
async function handleChangeDomain() {
|
||||||
|
errors = updateOrgSiteNameValidation(siteName) as Error;
|
||||||
|
|
||||||
|
if (Object.values(errors).length) {
|
||||||
|
isLoading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (blockedSubdomain.includes(siteName || '')) {
|
if (blockedSubdomain.includes(siteName || '')) {
|
||||||
errors = 'Sitename already exists.';
|
errors.siteName = 'Sitename already exists.';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
@@ -31,7 +45,7 @@
|
|||||||
console.log('Updating organisation', org);
|
console.log('Updating organisation', org);
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log('Error: create organisation', error);
|
console.log('Error: create organisation', error);
|
||||||
errors = 'Sitename already exists.';
|
errors.siteName = 'Sitename already exists.';
|
||||||
} else {
|
} else {
|
||||||
snackbar.success();
|
snackbar.success();
|
||||||
$currentOrg.siteName = siteName;
|
$currentOrg.siteName = siteName;
|
||||||
@@ -49,8 +63,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function resetErrors(_siteName: string) {
|
function resetErrors(_siteName: string) {
|
||||||
if (errors) {
|
if (errors.siteName) {
|
||||||
errors = '';
|
errors.siteName = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +90,7 @@
|
|||||||
placeholder="e.g traversymedia"
|
placeholder="e.g traversymedia"
|
||||||
className="mb-5 w-full"
|
className="mb-5 w-full"
|
||||||
labelClassName=""
|
labelClassName=""
|
||||||
errorMessage={errors}
|
errorMessage={errors.siteName}
|
||||||
/>
|
/>
|
||||||
<div class="flex items-center mb-6">
|
<div class="flex items-center mb-6">
|
||||||
<PrimaryButton
|
<PrimaryButton
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ import isNumber from 'lodash/isNumber';
|
|||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
import { validateEmail } from './validateEmail';
|
import { validateEmail } from './validateEmail';
|
||||||
|
|
||||||
|
const getOrgNameValidation = () =>
|
||||||
|
z.string().min(5, { message: 'Organization must contain 5 or more characters' });
|
||||||
|
const getSiteNameValidation = () =>
|
||||||
|
z.string().min(5, { message: 'Site name must contain 5 or more characters' });
|
||||||
|
|
||||||
const createQuizValidationSchema = z.object({
|
const createQuizValidationSchema = z.object({
|
||||||
title: z.string().min(6, {
|
title: z.string().min(6, {
|
||||||
message: 'Must be 6 or more characters long',
|
message: 'Must be 6 or more characters long',
|
||||||
@@ -76,9 +81,9 @@ const resetValidationSchema = z.object({
|
|||||||
|
|
||||||
const onboardingValidationSchema = {
|
const onboardingValidationSchema = {
|
||||||
stepOne: z.object({
|
stepOne: z.object({
|
||||||
fullname: z.string().min(1, { message: 'Enter your fullname' }),
|
fullname: z.string().min(5, { message: 'Fullname must contain 5 or more characters' }),
|
||||||
orgName: z.string().min(1, { message: 'Enter your organisation name' }),
|
orgName: getOrgNameValidation(),
|
||||||
siteName: z.string().min(1, { message: 'Enter your site name' })
|
siteName: getSiteNameValidation()
|
||||||
}),
|
}),
|
||||||
stepTwo: z.object({
|
stepTwo: z.object({
|
||||||
goal: z
|
goal: z
|
||||||
@@ -196,20 +201,23 @@ export const onboardingValidation = (fields = {}, step) => {
|
|||||||
|
|
||||||
export const createOrgValidation = (fields = {}) => {
|
export const createOrgValidation = (fields = {}) => {
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
orgName: z.string().min(5, {
|
orgName: getOrgNameValidation(),
|
||||||
message: 'Must be 5 or more characters long',
|
siteName: getSiteNameValidation()
|
||||||
invalid_type_error: 'Must not be empty'
|
|
||||||
}),
|
|
||||||
siteName: z.string().min(5, {
|
|
||||||
message: 'Must be 5 or more characters long',
|
|
||||||
invalid_type_error: 'Must not be empty'
|
|
||||||
})
|
|
||||||
});
|
});
|
||||||
const { error } = schema.safeParse(fields);
|
const { error } = schema.safeParse(fields);
|
||||||
|
|
||||||
return processErrors(error);
|
return processErrors(error);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateOrgSiteNameValidation = (siteName) => {
|
||||||
|
const schema = z.object({
|
||||||
|
siteName: getSiteNameValidation()
|
||||||
|
});
|
||||||
|
const { error } = schema.safeParse({ siteName });
|
||||||
|
|
||||||
|
return processErrors(error);
|
||||||
|
};
|
||||||
|
|
||||||
export const createQuizValidation = (fields = {}) => {
|
export const createQuizValidation = (fields = {}) => {
|
||||||
const { error } = createQuizValidationSchema.safeParse(fields);
|
const { error } = createQuizValidationSchema.safeParse(fields);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user