Skip to content

Commit 01e5c89

Browse files
committed
provide default SubBranding values on empty fields, on upsert; cleanup: sub branding validation schema
1 parent 145ae49 commit 01e5c89

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

components/territory-branding.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ export default function TerritoryBrandingForm ({ sub }) {
3333
variables: {
3434
subName: sub.name,
3535
branding: {
36-
title: values.title,
37-
description: values.description,
38-
primaryColor: values.primaryColor,
39-
secondaryColor: values.secondaryColor,
36+
title: values.title || sub.name,
37+
description: values.description || sub.desc,
38+
primaryColor: values.primaryColor || '#FADA5E',
39+
secondaryColor: values.secondaryColor || '#F6911D',
4040
logoId: values.logoId,
4141
faviconId: values.faviconId
4242
}

lib/validate.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,19 +368,20 @@ export function customDomainSchema (args) {
368368
// Sub Branding validation schema
369369
// sanitize the input for correct colors and text
370370
export function subBrandingSchema (args) {
371+
const hexRegex = /^#([0-9a-fA-F]{6})$/
371372
return object({
372-
title: string().max(100, 'must be at most 100 characters').matches(/^[a-zA-Z0-9\s]+$/, {
373+
title: string().max(50, 'must be at most 50 characters').matches(/^[a-zA-Z0-9\s]+$/, {
373374
message: 'title must only contain letters, numbers, and spaces'
374375
}).nullable().trim(),
375-
description: string().max(250, 'must be at most 250 characters').matches(/^[a-zA-Z0-9\s]+$/, {
376+
description: string().max(100, 'must be at most 100 characters').matches(/^[a-zA-Z0-9\s]+$/, {
376377
message: 'description must only contain letters, numbers, and spaces'
377378
}).nullable().trim(),
378379
logoId: intValidator.nullable().positive('must be positive').integer('must be an integer'),
379380
faviconId: intValidator.nullable().positive('must be positive').integer('must be an integer'),
380-
primaryColor: string().matches(/^#([0-9a-fA-F]{6})$/, {
381+
primaryColor: string().matches(hexRegex, {
381382
message: 'primary color must be a valid hex color'
382383
}).nullable(),
383-
secondaryColor: string().matches(/^#([0-9a-fA-F]{6})$/, {
384+
secondaryColor: string().matches(hexRegex, {
384385
message: 'secondary color must be a valid hex color'
385386
}).nullable()
386387
})

0 commit comments

Comments
 (0)