fix(): validate subdomain (#8902)

Fix #8876
This commit is contained in:
Antoine Moreaux 2024-12-05 17:30:23 +01:00 committed by GitHub
parent f4c5d03b98
commit 680366e998
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,8 +23,12 @@ const validationSchema = z
.object({ .object({
subdomain: z subdomain: z
.string() .string()
.min(1, { message: 'Subdomain can not be empty' }) .min(3, { message: 'Subdomain can not be shorter than 3 characters' })
.max(63, { message: 'Subdomain can not be longer than 63 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(); .required();
@ -36,10 +40,11 @@ const StyledDomainFromWrapper = styled.div`
`; `;
const StyledDomain = styled.h2` const StyledDomain = styled.h2`
align-self: flex-start;
color: ${({ theme }) => theme.font.color.secondary}; color: ${({ theme }) => theme.font.color.secondary};
font-size: ${({ theme }) => theme.font.size.md}; font-size: ${({ theme }) => theme.font.size.md};
font-weight: ${({ theme }) => theme.font.weight.medium}; font-weight: ${({ theme }) => theme.font.weight.medium};
margin-left: ${({ theme }) => theme.spacing(2)}; margin: ${({ theme }) => theme.spacing(2)};
`; `;
export const SettingsDomain = () => { export const SettingsDomain = () => {
@ -90,6 +95,7 @@ export const SettingsDomain = () => {
formState: { isValid }, formState: { isValid },
} = useForm<Form>({ } = useForm<Form>({
mode: 'onChange', mode: 'onChange',
delayError: 500,
defaultValues: { defaultValues: {
subdomain: currentWorkspace?.subdomain ?? '', subdomain: currentWorkspace?.subdomain ?? '',
}, },
@ -133,6 +139,7 @@ export const SettingsDomain = () => {
field: { onChange, value }, field: { onChange, value },
fieldState: { error }, fieldState: { error },
}) => ( }) => (
<>
<TextInputV2 <TextInputV2
value={value} value={value}
type="text" type="text"
@ -140,11 +147,14 @@ export const SettingsDomain = () => {
error={error?.message} error={error?.message}
fullWidth fullWidth
/> />
{isDefined(domainConfiguration.frontDomain) && (
<StyledDomain>
.{domainConfiguration.frontDomain}
</StyledDomain>
)}
</>
)} )}
/> />
{isDefined(domainConfiguration.frontDomain) && (
<StyledDomain>.{domainConfiguration.frontDomain}</StyledDomain>
)}
</StyledDomainFromWrapper> </StyledDomainFromWrapper>
)} )}
</Section> </Section>