Skip to content

Commit

Permalink
math calculateDateDifference -> dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
bejoinka committed Nov 26, 2024
1 parent 9cb2621 commit 1e70255
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions extensions/math/v1/actions/calculateDateDifference/config/fields.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { z, type ZodTypeAny } from 'zod'
import { type Field, FieldType } from '@awell-health/extensions-core'

const UnitEnum = z.enum([
'seconds',
'minutes',
'hours',
'days',
'weeks',
'months',
'years',
])
export const fields = {
dateLeft: {
id: 'dateLeft',
Expand All @@ -19,24 +28,21 @@ export const fields = {
},
unit: {
id: 'unit',
label: 'The unit you would like to calculate the difference in',
description:
'Choose one of "seconds", "minutes", "hours", "days", "weeks", "months", "years".',
label: 'Duration unit',
description: 'The unit of duration',
required: true,
type: FieldType.STRING,
options: {
dropdownOptions: Object.values(UnitEnum.enum).map((unit) => ({
label: unit,
value: unit,
})),
},
},
} satisfies Record<string, Field>

export const FieldsValidationSchema = z.object({
dateLeft: z.coerce.date(),
dateRight: z.coerce.date(),
unit: z.enum([
'seconds',
'minutes',
'hours',
'days',
'weeks',
'months',
'years',
]),
unit: UnitEnum,
} satisfies Record<keyof typeof fields, ZodTypeAny>)

0 comments on commit 1e70255

Please sign in to comment.