Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events v2: add conditionality for when a register action can be performed #341

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
375 changes: 157 additions & 218 deletions src/form/tennis-club-membership.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,121 @@
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { defineConfig } from '@opencrvs/toolkit/events'
import { defineConfig, defineForm } from '@opencrvs/toolkit/events'

Check failure on line 12 in src/form/tennis-club-membership.ts

View workflow job for this annotation

GitHub Actions / test

Module '"@opencrvs/toolkit/events"' has no exported member 'defineForm'.
import {
defineConditional,
or,
eventHasAction,
userHasScope,
and,
not
} from '@opencrvs/toolkit/conditionals'

Check failure on line 20 in src/form/tennis-club-membership.ts

View workflow job for this annotation

GitHub Actions / test

Cannot find module '@opencrvs/toolkit/conditionals' or its corresponding type declarations.

const TENNIS_CLUB_FORM = defineForm({
label: {
id: 'event.tennis-club-membership.action.declare.form.label',
defaultMessage: 'Tennis club membership application',
description: 'This is what this form is referred as in the system'
},
review: {
title: {
id: 'event.tennis-club-membership.action.declare.form.review.title',
defaultMessage: 'Member declaration for {firstname} {surname}',
description: 'Title of the form to show in review page'
}
},
active: true,
version: {
id: '1.0.0',
label: {
id: 'event.tennis-club-membership.action.declare.form.version.1',
defaultMessage: 'Version 1',
description: 'This is the first version of the form'
}
},
pages: [
{
id: 'applicant',
title: {
id: 'event.tennis-club-membership.action.declare.form.section.who.title',
defaultMessage: 'Who is applying for the membership?',
description: 'This is the title of the section'
},
fields: [
{
id: 'applicant.firstname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Applicant's first name",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.firstname.label'
}
},
{
id: 'applicant.surname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Applicant's surname",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.surname.label'
}
},
{
id: 'applicant.dob',
type: 'DATE',
required: true,
label: {
defaultMessage: "Applicant's date of birth",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.dob.label'
}
}
]
},
{
id: 'recommender',
title: {
id: 'event.tennis-club-membership.action.declare.form.section.recommender.title',
defaultMessage: 'Who is recommending the applicant?',
description: 'This is the title of the section'
},
fields: [
{
id: 'recommender.firstname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's first name",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.firstname.label'
}
},
{
id: 'recommender.surname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's surname",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.surname.label'
}
},
{
id: 'recommender.id',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's membership ID",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.id.label'
}
}
]
}
]
})

export const tennisClubMembershipEvent = defineConfig({
id: 'TENNIS_CLUB_MEMBERSHIP',
Expand Down Expand Up @@ -119,234 +233,59 @@
{
type: 'DECLARE',
label: {
defaultMessage: 'Send an application',
defaultMessage: 'Declare',
description:
'This is shown as the action name anywhere the user can trigger the action from',
id: 'event.tennis-club-membership.action.declare.label'
},
forms: [
{
label: {
id: 'event.tennis-club-membership.action.declare.form.label',
defaultMessage: 'Tennis club membership application',
description: 'This is what this form is referred as in the system'
},
review: {
title: {
id: 'event.tennis-club-membership.action.declare.form.review.title',
defaultMessage: 'Member declaration for {firstname} {surname}',
description: 'Title of the form to show in review page'
}
},
active: true,
version: {
id: '1.0.0',
label: {
id: 'event.tennis-club-membership.action.declare.form.version.1',
defaultMessage: 'Version 1',
description: 'This is the first version of the form'
}
},
pages: [
{
id: 'applicant',
title: {
id: 'event.tennis-club-membership.action.declare.form.section.who.title',
defaultMessage: 'Who is applying for the membership?',
description: 'This is the title of the section'
},
fields: [
{
id: 'applicant.firstname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Applicant's first name",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.firstname.label'
}
},
{
id: 'applicant.surname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Applicant's surname",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.surname.label'
}
},
{
id: 'applicant.dob',
type: 'DATE',
required: true,
label: {
defaultMessage: "Applicant's date of birth",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.dob.label'
}
}
]
},
{
id: 'recommender',
title: {
id: 'event.tennis-club-membership.action.declare.form.section.recommender.title',
defaultMessage: 'Who is recommending the applicant?',
description: 'This is the title of the section'
},
fields: [
{
id: 'recommender.firstname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's first name",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.firstname.label'
}
},
{
id: 'recommender.surname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's surname",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.surname.label'
}
},
{
id: 'recommender.id',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's membership ID",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.id.label'
}
}
]
}
]
}
]
forms: [TENNIS_CLUB_FORM],
allowedWhen: defineConditional(not(eventHasAction('DECLARE')))

Check failure on line 242 in src/form/tennis-club-membership.ts

View workflow job for this annotation

GitHub Actions / test

Type '{ type: "DECLARE"; label: { defaultMessage: string; description: string; id: string; }; forms: any[]; allowedWhen: any; }' is not assignable to type '{ type: "CREATE"; label: { id: string; description: string; defaultMessage: string; }; forms: { active: boolean; version: { id: string; label: { id: string; description: string; defaultMessage: string; }; }; label: { ...; }; pages: { ...; }[]; }[]; } | { ...; } | { ...; }'.
},
{
type: 'VALIDATE',

Check failure on line 245 in src/form/tennis-club-membership.ts

View workflow job for this annotation

GitHub Actions / test

Type '"VALIDATE"' is not assignable to type '"CREATE" | "DECLARE" | "REGISTER"'.
label: {
defaultMessage: 'Validate',
description:
'This is shown as the action name anywhere the user can trigger the action from',
id: 'event.tennis-club-membership.action.validate.label'
},
allowedWhen: defineConditional(eventHasAction('DECLARE')),
forms: [TENNIS_CLUB_FORM]
},
{
type: 'REGISTER',
label: {
defaultMessage: 'Send an application',
defaultMessage: 'Register',
description:
'This is shown as the action name anywhere the user can trigger the action from',
id: 'event.tennis-club-membership.action.declare.label'
id: 'event.tennis-club-membership.action.register.label'
},
forms: [
{
label: {
id: 'event.tennis-club-membership.action.declare.form.label',
defaultMessage: 'Tennis club membership application',
description: 'This is what this form is referred as in the system'
},
review: {
title: {
id: 'event.tennis-club-membership.action.declare.form.review.title',
defaultMessage: 'Member registration for {firstname} {surname}',
description: 'Title of the form to show in registration page'
}
},
active: true,
version: {
id: '1.0.0',
label: {
id: 'event.tennis-club-membership.action.declare.form.version.1',
defaultMessage: 'Version 1',
description: 'This is the first version of the form'
}
},
pages: [
{
id: 'applicant',
title: {
id: 'event.tennis-club-membership.action.declare.form.section.who.title',
defaultMessage: 'Who is applying for the membership?',
description: 'This is the title of the section'
},
fields: [
{
id: 'applicant.firstname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Applicant's first name",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.firstname.label'
}
},
{
id: 'applicant.surname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Applicant's surname",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.surname.label'
}
},
{
id: 'applicant.dob',
type: 'DATE',
required: true,
label: {
defaultMessage: "Applicant's date of birth",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.who.field.dob.label'
}
}
]
},
{
id: 'recommender',
title: {
id: 'event.tennis-club-membership.action.declare.form.section.recommender.title',
defaultMessage: 'Who is recommending the applicant?',
description: 'This is the title of the section'
},
fields: [
{
id: 'recommender.firstname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's first name",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.firstname.label'
}
},
{
id: 'recommender.surname',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's surname",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.surname.label'
}
},
{
id: 'recommender.id',
type: 'TEXT',
required: true,
label: {
defaultMessage: "Recommender's membership ID",
description: 'This is the label for the field',
id: 'event.tennis-club-membership.action.declare.form.section.recommender.field.id.label'
}
}
]
}
]
}
]
allowedWhen: defineConditional(

Check failure on line 263 in src/form/tennis-club-membership.ts

View workflow job for this annotation

GitHub Actions / test

Type '{ type: "REGISTER"; label: { defaultMessage: string; description: string; id: string; }; allowedWhen: any; forms: any[]; }' is not assignable to type '{ type: "CREATE"; label: { id: string; description: string; defaultMessage: string; }; forms: { active: boolean; version: { id: string; label: { id: string; description: string; defaultMessage: string; }; }; label: { ...; }; pages: { ...; }[]; }[]; } | { ...; } | { ...; }'.
and(
or(
eventHasAction('VALIDATE'),
and(eventHasAction('DECLARE'), userHasScope('register'))
),
not(eventHasAction('REGISTER'))
)
),
forms: [TENNIS_CLUB_FORM]
},
{
type: 'CUSTOM',

Check failure on line 275 in src/form/tennis-club-membership.ts

View workflow job for this annotation

GitHub Actions / test

Type '"CUSTOM"' is not assignable to type '"CREATE" | "DECLARE" | "REGISTER"'.
label: {
defaultMessage: 'My custom action',
description:
'This is shown as the action name anywhere the user can trigger the action from',
id: 'event.tennis-club-membership.action.sdf.label'
},
allowedWhen: defineConditional(
or(
eventHasAction('VALIDATE'),
and(eventHasAction('DECLARE'), userHasScope('register'))
)
),
forms: []
}
]
})
Loading