feat: enforce rule of orgsite name min 5 char (#184)

This commit is contained in:
Rotimi Best
2024-02-28 02:51:42 +01:00
committed by GitHub
parent b9388615a6
commit 474e83c3d9
3 changed files with 41 additions and 18 deletions
@@ -86,6 +86,7 @@
});
$: video = get(courseData, 'metadata.videoUrl');
$: allowNewStudent = get(courseData, 'metadata.allowNewStudent');
$: bannerImage = get(courseData, 'logo');
$: lessons = get(courseData, 'lessons', []);
$: instructor = get(courseData, 'metadata.instructor') || {};
@@ -120,7 +121,7 @@
if (editMode) return;
startCoursePayment = true;
}}
isDisabled={!courseData.metadata.allowNewStudent}
isDisabled={!allowNewStudent}
/>
{#if $handleOpenWidget.open}
<UploadWidget bind:imageURL={$course.logo} />
@@ -11,14 +11,28 @@
import { snackbar } from '$lib/components/Snackbar/store';
import SectionTitle from '../SectionTitle.svelte';
import VisitOrgSiteButton from '$lib/components/Buttons/VisitOrgSite.svelte';
import { updateOrgSiteNameValidation } from '$lib/utils/functions/validator';
type Error = {
siteName: string;
};
let siteName = '';
let errors = '';
let errors: Error = {
siteName: ''
};
let isLoading = false;
async function handleChangeDomain() {
errors = updateOrgSiteNameValidation(siteName) as Error;
if (Object.values(errors).length) {
isLoading = false;
return;
}
if (blockedSubdomain.includes(siteName || '')) {
errors = 'Sitename already exists.';
errors.siteName = 'Sitename already exists.';
return;
}
isLoading = true;
@@ -31,7 +45,7 @@
console.log('Updating organisation', org);
if (error) {
console.log('Error: create organisation', error);
errors = 'Sitename already exists.';
errors.siteName = 'Sitename already exists.';
} else {
snackbar.success();
$currentOrg.siteName = siteName;
@@ -49,8 +63,8 @@
}
function resetErrors(_siteName: string) {
if (errors) {
errors = '';
if (errors.siteName) {
errors.siteName = '';
}
}
@@ -76,7 +90,7 @@
placeholder="e.g traversymedia"
className="mb-5 w-full"
labelClassName=""
errorMessage={errors}
errorMessage={errors.siteName}
/>
<div class="flex items-center mb-6">
<PrimaryButton
@@ -2,6 +2,11 @@ import isNumber from 'lodash/isNumber';
import z from 'zod';
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({
title: z.string().min(6, {
message: 'Must be 6 or more characters long',
@@ -76,9 +81,9 @@ const resetValidationSchema = z.object({
const onboardingValidationSchema = {
stepOne: z.object({
fullname: z.string().min(1, { message: 'Enter your fullname' }),
orgName: z.string().min(1, { message: 'Enter your organisation name' }),
siteName: z.string().min(1, { message: 'Enter your site name' })
fullname: z.string().min(5, { message: 'Fullname must contain 5 or more characters' }),
orgName: getOrgNameValidation(),
siteName: getSiteNameValidation()
}),
stepTwo: z.object({
goal: z
@@ -196,20 +201,23 @@ export const onboardingValidation = (fields = {}, step) => {
export const createOrgValidation = (fields = {}) => {
const schema = z.object({
orgName: z.string().min(5, {
message: 'Must be 5 or more characters long',
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'
})
orgName: getOrgNameValidation(),
siteName: getSiteNameValidation()
});
const { error } = schema.safeParse(fields);
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 = {}) => {
const { error } = createQuizValidationSchema.safeParse(fields);