Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TertiaryButton
} from '@opencrvs/components/lib/buttons'
import { Icon, IconProps } from '@opencrvs/components/src/Icon'
import { Stack } from '@opencrvs/components/lib/Stack'
import {
ActionType,
CustomActionConfig,
Expand Down Expand Up @@ -157,15 +158,17 @@ function QuickActionModal({
width={898}
onClose={() => close({ result: false })}
>
<FormFieldGenerator
fields={config.fields ?? []}
id={'quick-action-modal-form'}
validatorContext={validatorContext}
onChange={handleChange}
/>
<Text color="grey500" element="p" variant="reg16">
{config.description ? intl.formatMessage(config.description) : null}
</Text>
<Stack alignItems="left" direction="column" gap={16}>
<Text color="grey500" element="p" variant="reg16">
{config.description ? intl.formatMessage(config.description) : null}
</Text>
<FormFieldGenerator
fields={config.fields ?? []}
id={'quick-action-modal-form'}
validatorContext={validatorContext}
onChange={handleChange}
/>
</Stack>
</Dialog>
)
}
Expand Down
11 changes: 10 additions & 1 deletion packages/client/src/v2-events/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
SystemVariables,
Scope,
ActionScopes,
ConfigurableActionScopes,
parseConfigurableScope,
WorkqueueConfigWithoutQuery,
joinValues,
UUID,
Expand Down Expand Up @@ -232,7 +234,14 @@ export enum CoreWorkqueues {
}

export function hasOutboxWorkqueue(scopes: Scope[]) {
return scopes.some((scope) => ActionScopes.safeParse(scope).success)
const hasLiteralActionScopes = scopes.some(
(scope) => ActionScopes.safeParse(scope).success
)
const parsedScopes = scopes.map(parseConfigurableScope)
const hasConfigurableActionScopes = parsedScopes.some(
(scope) => ConfigurableActionScopes.safeParse(scope).success
)
return hasLiteralActionScopes || hasConfigurableActionScopes
}

export function hasDraftWorkqueue(scopes: Scope[]) {
Expand Down
3 changes: 3 additions & 0 deletions packages/commons/src/conditionals/conditionals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,9 @@ describe('"flag" conditionals', () => {
expect(validate(flag(InherentFlags.CORRECTION_REQUESTED), params)).toBe(
false
)
expect(
validate(not(flag(InherentFlags.CORRECTION_REQUESTED)), params)
).toBe(true)
})

it('validation fails if params dont include flags', () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/commons/src/events/EventConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { DeclarationFormConfig } from './FormConfig'

import { FieldType } from './FieldType'
import { FieldReference } from './FieldConfig'
import { FlagConfig } from './Flag'
import { FlagConfig, InherentFlags } from './Flag'

/**
* Description of event features defined by the country. Includes configuration for process steps and forms involved.
Expand Down Expand Up @@ -134,17 +134,23 @@ export const EventConfig = z
}
}

const isInherentFlag = (value: unknown): value is InherentFlags =>
Object.values(InherentFlags).includes(value as InherentFlags)

// Validate that all referenced action flags are configured in the event flags array.
const configuredFlagIds = event.flags.map((flag) => flag.id)
const actionFlagIds = event.actions.flatMap((action) =>
action.flags.map((flag) => flag.id)
)

for (const actionFlagId of actionFlagIds) {
if (!configuredFlagIds.includes(actionFlagId)) {
const isConfigured = configuredFlagIds.includes(actionFlagId)
const isInherent = isInherentFlag(actionFlagId)

if (!isConfigured && !isInherent) {
ctx.addIssue({
code: 'custom',
message: `Action flag id must match a configured flag in the flags array. Invalid action flag ID for event '${event.id}': '${actionFlagId}'`,
message: `Action flag id must match an inherent flag or a configured flag in the flags array. Invalid action flag ID for event '${event.id}': '${actionFlagId}'`,
path: ['actions']
})
}
Expand Down
2 changes: 1 addition & 1 deletion packages/commons/src/events/Flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export type FlagConfig = z.infer<typeof FlagConfig>
* Configuration for a flag action, which is executed when the action is performed.
*/
export const ActionFlagConfig = z.object({
id: CustomFlag,
id: Flag,
operation: z
.enum(['add', 'remove'])
.describe('Operation to perform on the flag.'),
Expand Down
3 changes: 2 additions & 1 deletion packages/commons/src/events/state/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ const updateActions = ActionTypes.extract([
ActionType.REJECT,
ActionType.ARCHIVE,
ActionType.PRINT_CERTIFICATE,
ActionType.REQUEST_CORRECTION
ActionType.REQUEST_CORRECTION,
ActionType.CUSTOM
])

/**
Expand Down
1 change: 1 addition & 0 deletions packages/commons/src/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export const AvailableIcons = z.enum([
'Plus',
'Printer',
'SignOut',
'Stamp',
'Star',
'Target',
'TextT',
Expand Down
6 changes: 6 additions & 0 deletions packages/commons/src/scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ const ConfigurableRawScopes = z.discriminatedUnion('type', [
CustomActionScope
])

export const ConfigurableActionScopes = z.discriminatedUnion('type', [
// @TODO - Record scope holds non-action scopes as well e.g., `record.read`
RecordScope,
CustomActionScope
])

type ConfigurableRawScopes = z.infer<typeof ConfigurableRawScopes>
export type ConfigurableScopeType = ConfigurableRawScopes['type']

Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/Icon/all-icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export {
Users,
WarningCircle,
Webcam,
X
X,
Stamp
} from 'phosphor-react'
export * from './custom-icons'