fixed domain list problem

This commit is contained in:
Zai Shi 2025-01-21 10:40:39 -08:00
parent 4d3936e050
commit e62559c52f
2 changed files with 20 additions and 3 deletions

View File

@ -46,7 +46,24 @@ function EditDialog(props: {
addWww: yup.boolean(),
});
const canAddWww = (domain: string | undefined) => domain && isValidUrl('https://' + domain) && !domain.startsWith('www.') && isValidUrl('https://www.' + domain);
const canAddWww = (domain: string | undefined) => {
if (!domain) {
return false;
}
const httpsUrl = 'https://' + domain;
if (!isValidUrl(httpsUrl)) {
return false;
}
if (domain.startsWith('www.')) {
return false;
}
const wwwUrl = 'https://www.' + domain;
console.log(wwwUrl, isValidUrl(wwwUrl));
return isValidUrl(wwwUrl);
};
return <FormDialog
open={props.open}
@ -70,7 +87,7 @@ function EditDialog(props: {
domain: values.domain,
handlerPath: values.handlerPath,
},
...(canAddWww(values.domain) && values.addWww ? [{
...(canAddWww(values.domain.slice(8)) && values.addWww ? [{
domain: 'https://www.' + values.domain.slice(8),
handlerPath: values.handlerPath,
}] : []),

View File

@ -271,7 +271,7 @@ export const emailUsernameSchema = yupString().meta({ openapiField: { descriptio
export const emailSenderEmailSchema = emailSchema.meta({ openapiField: { description: 'Email sender email. Needs to be specified when using type="standard"', exampleValue: 'example@your-domain.com' } });
export const emailPasswordSchema = passwordSchema.meta({ openapiField: { description: 'Email password. Needs to be specified when using type="standard"', exampleValue: 'your-email-password' } });
// Project domain config
export const projectTrustedDomainSchema = yupString().test('is-https', 'Trusted domain must start with https://', (value) => value?.startsWith('https://')).meta({ openapiField: { description: 'Your domain URL. Make sure you own and trust this domain. Needs to start with https://', exampleValue: 'https://example.com' } });
export const projectTrustedDomainSchema = urlSchema.test('is-https', 'Trusted domain must start with https://', (value) => value?.startsWith('https://')).meta({ openapiField: { description: 'Your domain URL. Make sure you own and trust this domain. Needs to start with https://', exampleValue: 'https://example.com' } });
export const handlerPathSchema = yupString().test('is-handler-path', 'Handler path must start with /', (value) => value?.startsWith('/')).meta({ openapiField: { description: 'Handler path. If you did not setup a custom handler path, it should be "/handler" by default. It needs to start with /', exampleValue: '/handler' } });
// Users