From 680366e998fbe52b7b0e4cdc1cbd1c4651e04422 Mon Sep 17 00:00:00 2001 From: Antoine Moreaux Date: Thu, 5 Dec 2024 17:30:23 +0100 Subject: [PATCH] fix(): validate subdomain (#8902) Fix #8876 --- .../settings/workspace/SettingsDomain.tsx | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/twenty-front/src/pages/settings/workspace/SettingsDomain.tsx b/packages/twenty-front/src/pages/settings/workspace/SettingsDomain.tsx index 057c6f3605..007a959107 100644 --- a/packages/twenty-front/src/pages/settings/workspace/SettingsDomain.tsx +++ b/packages/twenty-front/src/pages/settings/workspace/SettingsDomain.tsx @@ -23,8 +23,12 @@ const validationSchema = z .object({ subdomain: z .string() - .min(1, { message: 'Subdomain can not be empty' }) - .max(63, { message: 'Subdomain can not be longer than 63 characters' }), + .min(3, { message: 'Subdomain can not be shorter than 3 characters' }) + .max(30, { message: 'Subdomain can not be longer than 30 characters' }) + .regex(/^[a-z0-9][a-z0-9-]{1,28}[a-z0-9]$/, { + message: + 'Use letter, number and dash only. Start and finish with a letter or a number', + }), }) .required(); @@ -36,10 +40,11 @@ const StyledDomainFromWrapper = styled.div` `; const StyledDomain = styled.h2` + align-self: flex-start; color: ${({ theme }) => theme.font.color.secondary}; font-size: ${({ theme }) => theme.font.size.md}; font-weight: ${({ theme }) => theme.font.weight.medium}; - margin-left: ${({ theme }) => theme.spacing(2)}; + margin: ${({ theme }) => theme.spacing(2)}; `; export const SettingsDomain = () => { @@ -90,6 +95,7 @@ export const SettingsDomain = () => { formState: { isValid }, } = useForm
({ mode: 'onChange', + delayError: 500, defaultValues: { subdomain: currentWorkspace?.subdomain ?? '', }, @@ -133,18 +139,22 @@ export const SettingsDomain = () => { field: { onChange, value }, fieldState: { error }, }) => ( - + <> + + {isDefined(domainConfiguration.frontDomain) && ( + + .{domainConfiguration.frontDomain} + + )} + )} /> - {isDefined(domainConfiguration.frontDomain) && ( - .{domainConfiguration.frontDomain} - )} )}