Skip to content

Commit

Permalink
Merge branch 'develop' into ocrvs-6213
Browse files Browse the repository at this point in the history
  • Loading branch information
jamil314 authored Jan 8, 2025
2 parents 6e0d174 + 1ff163d commit e109ba4
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 (
Expand All @@ -36,9 +38,10 @@ export function EventSummary({
<Summary.Row
key={field.id}
data-testid={field.id}
label={field.label?.defaultMessage ?? ''}
label={intl.formatMessage(field.label)}
placeholder={
'@todo: These placeholder values need to be configurable like "No place of birth"'
field.emptyValueMessage &&
intl.formatMessage(field.emptyValueMessage)
}
value={data[field.id]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions packages/commons/src/events/EventConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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<typeof EventConfig>
export type EventConfigInput = z.input<typeof EventConfig>
export type EventConfigInput = z.input<typeof EventConfigInput>

export const defineForm = (form: FormConfigInput): FormConfig =>
FormConfig.parse(form)
26 changes: 17 additions & 9 deletions packages/commons/src/events/SummaryConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof SummaryConfig>
export type SummaryConfigInput = z.input<typeof SummaryConfig>
export type SummaryConfigInput = z.input<typeof SummaryConfigInput>
10 changes: 5 additions & 5 deletions packages/commons/src/events/defineConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion packages/toolkit/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit e109ba4

Please sign in to comment.