diff --git a/packages/client/src/v2-events/features/workqueues/EventOverview/components/EventSummary.tsx b/packages/client/src/v2-events/features/workqueues/EventOverview/components/EventSummary.tsx index 7a088c5cf2..02caa13d91 100644 --- a/packages/client/src/v2-events/features/workqueues/EventOverview/components/EventSummary.tsx +++ b/packages/client/src/v2-events/features/workqueues/EventOverview/components/EventSummary.tsx @@ -10,6 +10,7 @@ */ import React from 'react' +import { useIntl } from 'react-intl' import { Summary } from '@opencrvs/components/lib/Summary' import { SummaryConfig } from '@opencrvs/commons/events' import { EventIndex } from '@opencrvs/commons/client' @@ -26,6 +27,7 @@ export function EventSummary({ event: EventIndex summary: SummaryConfig }) { + const intl = useIntl() const { toString } = useTransformer(event.type) const data = toString(event.data) return ( @@ -36,9 +38,10 @@ export function EventSummary({ diff --git a/packages/client/src/v2-events/features/workqueues/Workqueue.tsx b/packages/client/src/v2-events/features/workqueues/Workqueue.tsx index 91d7eaba83..e325effca8 100644 --- a/packages/client/src/v2-events/features/workqueues/Workqueue.tsx +++ b/packages/client/src/v2-events/features/workqueues/Workqueue.tsx @@ -18,7 +18,7 @@ import { orderBy, mapKeys, get } from 'lodash' import { useTypedSearchParams } from 'react-router-typesafe-routes/dom' import { Link } from 'react-router-dom' -import { EventIndex, getCurrentEventState } from '@opencrvs/commons/client' +import { EventIndex } from '@opencrvs/commons/client' import { useWindowSize } from '@opencrvs/components/lib/hooks' import { WorkqueueConfig } from '@opencrvs/commons' import { diff --git a/packages/commons/src/events/EventConfig.ts b/packages/commons/src/events/EventConfig.ts index 0fc8267520..75f3cbfd25 100644 --- a/packages/commons/src/events/EventConfig.ts +++ b/packages/commons/src/events/EventConfig.ts @@ -11,7 +11,7 @@ import { z } from 'zod' import { ActionConfig } from './ActionConfig' import { TranslationConfig } from './TranslationConfig' -import { SummaryConfig } from './SummaryConfig' +import { SummaryConfig, SummaryConfigInput } from './SummaryConfig' import { WorkqueueConfig } from './WorkqueueConfig' import { FormConfig, FormConfigInput } from './FormConfig' @@ -32,8 +32,12 @@ export const EventConfig = z.object({ workqueues: z.array(WorkqueueConfig) }) +export const EventConfigInput = EventConfig.extend({ + summary: SummaryConfigInput +}) + export type EventConfig = z.infer -export type EventConfigInput = z.input +export type EventConfigInput = z.input export const defineForm = (form: FormConfigInput): FormConfig => FormConfig.parse(form) diff --git a/packages/commons/src/events/SummaryConfig.ts b/packages/commons/src/events/SummaryConfig.ts index 2e209cd372..d9190b6653 100644 --- a/packages/commons/src/events/SummaryConfig.ts +++ b/packages/commons/src/events/SummaryConfig.ts @@ -11,19 +11,27 @@ import { z } from 'zod' import { TranslationConfig } from './TranslationConfig' +const Field = z.object({ + id: z.string().describe('Id of a field defined under form.'), + label: TranslationConfig, + emptyValueMessage: TranslationConfig.optional() +}) + +const FieldInput = Field.extend({ + // label is enforced during runtime. + label: TranslationConfig.optional() +}) + export const SummaryConfig = z .object({ title: TranslationConfig.describe('Header title of summary'), - fields: z - .array( - z.object({ - id: z.string().describe('Id of a field defined under form.'), - label: TranslationConfig.optional() - }) - ) - .describe('Fields to be rendered under in summary.') + fields: z.array(Field).describe('Fields rendered in summary view.') }) .describe('Configuration for summary in event.') +export const SummaryConfigInput = SummaryConfig.extend({ + fields: z.array(FieldInput) +}) + export type SummaryConfig = z.infer -export type SummaryConfigInput = z.input +export type SummaryConfigInput = z.input diff --git a/packages/commons/src/events/defineConfig.ts b/packages/commons/src/events/defineConfig.ts index d5e6908901..c9dfb77b82 100644 --- a/packages/commons/src/events/defineConfig.ts +++ b/packages/commons/src/events/defineConfig.ts @@ -17,20 +17,20 @@ import { findPageFields, resolveFieldLabels } from './utils' * @param config - Event specific configuration */ export const defineConfig = (config: EventConfigInput) => { - const parsed = EventConfig.parse(config) + const input = EventConfigInput.parse(config) - const pageFields = findPageFields(parsed).map(({ id, label }) => ({ + const pageFields = findPageFields(input).map(({ id, label }) => ({ id, label })) return EventConfig.parse({ - ...parsed, + ...input, summary: resolveFieldLabels({ - config: parsed.summary, + config: input.summary, pageFields }), - workqueues: parsed.workqueues.map((workqueue) => + workqueues: input.workqueues.map((workqueue) => resolveFieldLabels({ config: workqueue, pageFields diff --git a/packages/commons/src/fixtures/tennis-club-membership-event.ts b/packages/commons/src/fixtures/tennis-club-membership-event.ts index 4003d51ed5..2c2041257c 100644 --- a/packages/commons/src/fixtures/tennis-club-membership-event.ts +++ b/packages/commons/src/fixtures/tennis-club-membership-event.ts @@ -25,7 +25,12 @@ export const tennisClubMembershipEvent = defineConfig({ }, fields: [ { - id: 'applicant.firstname' + id: 'applicant.firstname', + emptyValueMessage: { + defaultMessage: 'First name is not provided', + description: 'This is the message to show when the field is empty', + id: 'event.tennis-club-membership.summary.field.firstname.empty' + } } ] }, diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 8e13ed80ed..05ac70d02f 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -1,6 +1,6 @@ { "name": "@opencrvs/toolkit", - "version": "0.0.7-events", + "version": "0.0.9-events", "description": "OpenCRVS toolkit for building country configurations", "license": "MPL-2.0", "exports": {