diff --git a/src/pages/categoryCombos/form/categoryComboSchema.ts b/src/pages/categoryCombos/form/categoryComboSchema.ts index 6be3086b..e78ec0de 100644 --- a/src/pages/categoryCombos/form/categoryComboSchema.ts +++ b/src/pages/categoryCombos/form/categoryComboSchema.ts @@ -1,25 +1,24 @@ import { z } from 'zod' -import { getDefaults } from '../../../lib' +import { getDefaults, modelFormSchemas } from '../../../lib' import { createFormValidate } from '../../../lib/form/validate' import { CategoryComboFormValues } from '../Edit' import { CategoryCombo } from './../../../types/generated/models' -/* Note that this describes what we send to the server, - and not what is stored in the form. */ +const { identifiable, withAttributeValues, referenceCollection } = + modelFormSchemas -export const categoryComboSchema = z.object({ - id: z.string().optional(), - name: z.string().trim(), - code: z.string().trim().optional(), - dataDimensionType: z - .nativeEnum(CategoryCombo.dataDimensionType) - .default(CategoryCombo.dataDimensionType.DISAGGREGATION), - skipTotal: z.boolean().default(false), - categories: z - .array(z.object({ id: z.string() })) - .min(1, 'At least one category is required') - .default([]), -}) +export const categoryComboSchema = identifiable + .merge(withAttributeValues) + .extend({ + code: z.string().trim().optional(), + dataDimensionType: z + .nativeEnum(CategoryCombo.dataDimensionType) + .default(CategoryCombo.dataDimensionType.DISAGGREGATION), + skipTotal: z.boolean().default(false), + categories: referenceCollection + .min(1, 'At least one category is required') + .default([]), + }) export const initialValues: Partial = getDefaults(categoryComboSchema)