fix: prevent hypen at start or end of organzation or domain name (#340)

* fix: adding hypen to start or end of org or domain name

* fix: add org name validation to settings page

* chore: remove unnecessary variable use

* chore: remove error reset function

* Update OrgSettings.svelte

---------

Co-authored-by: Rotimi Best <[email protected]>
This commit is contained in:
Iniubong Obonguko
2024-05-29 00:23:36 +01:00
committed by GitHub
co-authored by Rotimi Best
parent b4465afb64
commit f0ff06a856
2 changed files with 40 additions and 4 deletions
@@ -3,10 +3,20 @@ import z from 'zod';
import { validateEmail } from './validateEmail';
const getOrgNameValidation = () =>
z.string().min(5, { message: 'Organization must contain 5 or more characters' });
z
.string()
.min(5, { message: 'Organization must contain 5 or more characters' })
.refine((val) => !/^[-]|[-]$/.test(val), {
message: 'Organization name cannot start or end with a hyphen'
});
const getSiteNameValidation = () =>
z.string().min(5, { message: 'Site name must contain 5 or more characters' });
z
.string()
.min(5, { message: 'Site name must contain 5 or more characters' })
.refine((val) => !/^[-]|[-]$/.test(val), {
message: 'Site name cannot start or end with a hyphen'
});
const getNewsfeedValidation = () =>
z.string().min(5, { message: 'Field must contain 5 or more characters' });
@@ -242,6 +252,14 @@ export const createOrgValidation = (fields = {}) => {
return processErrors(error);
};
export const updateOrgNameValidation = (orgName) => {
const schema = z.object({
orgName: getOrgNameValidation()
});
const { error } = schema.safeParse({ orgName });
return processErrors(error);
};
export const updateOrgSiteNameValidation = (siteName) => {
const schema = z.object({
siteName: getSiteNameValidation()