Skip to content

Commit

Permalink
refactor: use common form schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Birkbjo committed Aug 28, 2024
1 parent 700453f commit 73ffc36
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/pages/categoryCombos/form/categoryComboSchema.ts
Original file line number Diff line number Diff line change
@@ -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<CategoryComboFormValues> =
getDefaults(categoryComboSchema)
Expand Down

0 comments on commit 73ffc36

Please sign in to comment.