Skip to content

Commit

Permalink
in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
tareq89 committed Jan 22, 2025
1 parent 9d1c056 commit 2c19902
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { ROUTES } from '@client/v2-events/routes'
import { useEventFormData } from '@client/v2-events/features/events/useEventFormData'
import { FormLayout } from '@client/v2-events/layouts/form'
import { defaultCertificateCollectorFormConfig } from './defaultCertificateCollectorFormConfig'
import { FormPage } from '@opencrvs/commons'

export function Pages() {
const { eventId, pageId } = useTypedParams(
Expand Down Expand Up @@ -53,7 +54,7 @@ export function Pages() {
const { eventConfiguration: configuration } = useEventConfiguration(
event.type
)
const formPages = configuration.actions
let formPages = configuration.actions
.find((action) => action.type === ActionType.COLLECT_CERTIFICATE)
?.forms.find((form) => form.active)?.pages

Expand All @@ -65,8 +66,9 @@ export function Pages() {
defaultCertificateCollectorFormConfig,
formPages.length ? formPages[0] : {}
)
const currentPageId =
formPages.find((p) => p.id === pageId)?.id || collectFormPage.id
const currentPageId = formPages.find(
(p) => p.id === collectFormPage[0].id
)?.id

if (!currentPageId) {
throw new Error('Form does not have any pages')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,61 +11,90 @@ import { FormPage } from '@opencrvs/commons'
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

export const defaultCertificateCollectorFormConfig: FormPage = {
id: 'collector',
title: {
id: 'event.tennis-club-membership.action.certificate.form.section.who.title',
defaultMessage: 'Who is collecting the certificate?',
description: 'This is the title of the section'
},
fields: [
{
id: 'collector.firstname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Collector's first name",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.certificate.form.section.who.field.firstname.label'
}
},
{
id: 'collector.surname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Collector's surname",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.certificate.form.section.who.field.surname.label'
}
export const defaultCertificateCollectorFormConfig: FormPage[] = [
{
id: 'collector',
title: {
id: 'event.tennis-club-membership.action.certificate.form.section.who.title',
defaultMessage: 'Who is collecting the certificate?',
description: 'This is the title of the section'
},
{
id: 'collector.certificateTemplateId',
type: 'RADIO_GROUP',
required: true,
label: {
defaultMessage: 'Select Certificate Template',
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.certificate.form.section.who.field.surname.label'
},
options: [
{
label: {
id: 'certificates.tennis-club-membership.certificate.copy',
defaultMessage: 'Tennis Club Membership Certificate copy',
description: 'The label for a tennis-club-membership certificate'
fields: [
{
id: 'collector.certificateTemplateId',
type: 'SELECT',
required: true,
label: {
defaultMessage: 'Select Certificate Template',
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.certificate.form.section.who.field.surname.label'
},
validation: [
{
message: {
id: '',
defaultMessage: '',
description: ''
}
// validator: field
}
],
options: [
{
label: {
id: 'certificates.tennis-club-membership.certificate.copy',
defaultMessage: 'Tennis Club Membership Certificate copy',
description: 'The label for a tennis-club-membership certificate'
},
value: 'tennis-club-membership-certificate'
},
value: 'tennis-club-membership-certificate'
{
label: {
id: 'certificates.tennis-club-membership.certificate.certified-copy',
defaultMessage:
'Tennis Club Membership Certificate certified copy',
description: 'The label for a tennis-club-membership certificate'
},
value: 'tennis-club-membership-certified-certificate'
}
]
},
{
id: 'collector.requesterId',
type: 'SELECT',
required: true,
label: {
defaultMessage: 'Requester',
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.certificate.form.section.requester.label'
},
{
label: {
id: 'certificates.tennis-club-membership.certificate.certified-copy',
defaultMessage: 'Tennis Club Membership Certificate certified copy',
description: 'The label for a tennis-club-membership certificate'
options: [
{
label: {
id: 'event.tennis-club-membership.action.certificate.form.section.requester.informant.label',
defaultMessage: 'Print and issue Informant',
description: 'This is the label for the field'
},
value: 'INFORMANT'
},
value: 'tennis-club-membership-certified-certificate'
}
]
}
]
}
{
label: {
id: 'event.tennis-club-membership.action.certificate.form.section.requester.other.label',
defaultMessage: 'Print and issue someone else',
description: 'This is the label for the field'
},
value: 'OTHER'
},
{
label: {
id: 'event.tennis-club-membership.action.certificate.form.section.requester.printInAdvance.label',
defaultMessage: 'Print in advance',
description: 'This is the label for the field'
},
value: 'PRINT_IN_ADVANCE'
}
]
}
]
}
]
2 changes: 1 addition & 1 deletion packages/client/src/v2-events/layouts/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function FormLayout({
children: React.ReactNode
onSaveAndExit: () => void
}) {
const { eventId } = useTypedParams(route)
const { eventId, pageId } = useTypedParams(route)
const events = useEvents()

const [event] = events.getEvent.useSuspenseQuery(eventId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ describe('when user starts a new declaration', () => {
app.update()
expect(window.location.href).toContain('/')
})
it('check toggle menu toggle button handler', async () => {
it.only('check toggle menu toggle button handler', async () => {
app
.find('#eventToggleMenu-Dropdown-Content')
.hostNodes()
Expand Down
10 changes: 5 additions & 5 deletions packages/commons/src/conditionals/conditionals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { z } from 'zod'
import { ActionFormData, EventDocument } from '../events'

export function Conditional() {
/*
* Using JSONSchema directly here would cause a
* "The inferred type of this node exceeds the maximum length the compiler will serialize."
* error, so I've copied the type here
*/
/*
* Using JSONSchema directly here would cause a
* "The inferred type of this node exceeds the maximum length the compiler will serialize."
* error, so I've copied the type here
*/
return z.any()
}

Expand Down
19 changes: 7 additions & 12 deletions packages/events/src/router/event/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { presignFilesInEvent } from '@events/service/files'
import { getIndexedEvents } from '@events/service/indexing/indexing'
import { EventConfig, getUUID } from '@opencrvs/commons'
import {
CollectCertificateActionInput,
DeclareActionInput,
EventIndex,
EventInput,
Expand Down Expand Up @@ -55,7 +54,13 @@ function validateEventType({
export const eventRouter = router({
config: router({
get: publicProcedure.output(z.array(EventConfig)).query(async (options) => {
return getEventConfigurations(options.ctx.token)
try {
return getEventConfigurations(options.ctx.token)
} catch (error) {
console.log(options.ctx.token)

Check warning on line 60 in packages/events/src/router/event/index.ts

View workflow job for this annotation

GitHub Actions / Test (packages/events)

Unexpected console statement
console.log(error)

Check warning on line 61 in packages/events/src/router/event/index.ts

View workflow job for this annotation

GitHub Actions / Test (packages/events)

Unexpected console statement
return getEventConfigurations(options.ctx.token)
}
})
}),
create: publicProcedure.input(EventInput).mutation(async (options) => {
Expand Down Expand Up @@ -150,16 +155,6 @@ export const eventRouter = router({
token: options.ctx.token
}
)
}),
collectCertificate: publicProcedure
.input(CollectCertificateActionInput)
.mutation(async (options) => {
return addAction(options.input, {
eventId: options.input.eventId,
createdBy: options.ctx.user.id,
createdAtLocation: options.ctx.user.primaryOfficeId,
token: options.ctx.token
})
})
}),
list: publicProcedure.output(z.array(EventIndex)).query(getIndexedEvents)
Expand Down
15 changes: 10 additions & 5 deletions packages/toolkit/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ npx tsc --build

# Build common events
npx esbuild src/events/index.ts --bundle --format=cjs --outdir=./dist/events --allow-overwrite --packages=external
cp -r ../commons/build/dist/common/events/*.d.ts ./dist/events
mkdir -p ./dist/commons/events
cp -r ../commons/build/dist/common/events/*.d.ts ./dist/commons/events

# Build common conditionals
npx esbuild src/conditionals/index.ts --bundle --format=cjs --outdir=./dist/conditionals --allow-overwrite --packages=external
cp -r ../commons/build/dist/common/conditionals/*.d.ts ./dist/conditionals
mkdir -p ./dist/commons/conditionals
cp -r ../commons/build/dist/common/conditionals/*.d.ts ./dist/commons/conditionals

# Build api client
npx esbuild src/api/index.ts --bundle --format=cjs --outdir=./dist/api --allow-overwrite --packages=external
cp -r ../events/build/types/router/router.d.ts ./dist/api
mkdir -p ./dist/commons/api
cp -r ../events/build/types/router/router.d.ts ./dist/commons/api
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' 's|@opencrvs/events/build/types|.|g' dist/api/index.d.ts
sed -i '' 's|@opencrvs/events/build/types|../commons/api|g' dist/api/index.d.ts
find dist -type f -exec sed -i '' 's|@opencrvs/commons|../commons|g' {} +
else
sed -i 's|@opencrvs/events/build/types|.|g' dist/api/index.d.ts
sed -i 's|@opencrvs/events/build/types|../commons/api|g' dist/api/index.d.ts
find dist -type f -exec sed -i 's|@opencrvs/commons|../commons|g' {} +
fi

echo "Build completed successfully."
15 changes: 15 additions & 0 deletions packages/toolkit/src/conditionals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ export function eventHasAction(type: ActionDocument['type']) {

export function field(fieldId: string) {
return {
isRequired: () => ({
type: 'object',
properties: {
$form: {
type: 'object',
properties: {
[fieldId]: {
type: 'string'
}
},
required: [fieldId]
}
},
required: ['$form']
}),
isBeforeNow: () => ({
type: 'object',
properties: {
Expand Down

0 comments on commit 2c19902

Please sign in to comment.