mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-07 14:15:45 +00:00
Merge remote-tracking branch 'origin/dev' into fix/coc-exam-workflow-defects
# Conflicts: # apps/portal/src/app/features/licensing/pages/MyApplicationsPage/index.tsx # libs/api/src/lib/features/licensing/licensing-api.ts # libs/api/src/lib/features/licensing/licensing.types.ts
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { isValidPhoneNumber } from 'libphonenumber-js';
|
||||
import { resolveTokenFromStorage } from '../../session';
|
||||
import { BASE_API_URL } from '../../base-api/base-query-with-reauth';
|
||||
import type {
|
||||
ApplicationKind,
|
||||
Bilingual,
|
||||
FamilyKind,
|
||||
FieldCondition,
|
||||
@@ -11,9 +13,10 @@ import type {
|
||||
ValidationIssue,
|
||||
} from './licensing.types';
|
||||
|
||||
const BASE_API_URL =
|
||||
(import.meta as { env?: Record<string, string> }).env?.['VITE_BASE_API_URL'] ??
|
||||
'http://localhost:3000/api';
|
||||
/** A section with no `applicationKinds` applies to every kind, as before that field existed. */
|
||||
function sectionAppliesToKind(section: FormSectionConfig, kind: ApplicationKind): boolean {
|
||||
return !section.applicationKinds?.length || section.applicationKinds.includes(kind);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploads a document straight to the API.
|
||||
@@ -63,6 +66,7 @@ export const STATUS_LABELS: Record<LicenseStatus, string> = {
|
||||
DRAFT: 'Draft',
|
||||
SUBMITTED: 'Submitted',
|
||||
UNDER_REVIEW: 'Under Review',
|
||||
AWAITING_BIOMETRICS: 'Awaiting Biometrics',
|
||||
UNDER_EVALUATION: 'Under Evaluation',
|
||||
RESUBMIT_REQUIRED: 'Resubmit Required',
|
||||
INSPECTION_PENDING: 'Inspection Pending',
|
||||
@@ -95,6 +99,7 @@ export const STATUS_COLORS: Record<LicenseStatus, string> = {
|
||||
DRAFT: 'gray',
|
||||
SUBMITTED: 'blue',
|
||||
UNDER_REVIEW: 'indigo',
|
||||
AWAITING_BIOMETRICS: 'indigo',
|
||||
UNDER_EVALUATION: 'indigo',
|
||||
RESUBMIT_REQUIRED: 'orange',
|
||||
INSPECTION_PENDING: 'cyan',
|
||||
@@ -134,6 +139,7 @@ export const STATUS_PROGRESS: Record<LicenseStatus, number> = {
|
||||
DRAFT: 5,
|
||||
SUBMITTED: 15,
|
||||
UNDER_REVIEW: 30,
|
||||
AWAITING_BIOMETRICS: 30,
|
||||
UNDER_EVALUATION: 45,
|
||||
RESUBMIT_REQUIRED: 30,
|
||||
INSPECTION_PENDING: 55,
|
||||
@@ -396,6 +402,15 @@ const ERROR_MESSAGES: Record<string, string> = {
|
||||
inspection_not_passed:
|
||||
'Approval requires a passed inspection. Schedule a re-inspection or request corrections.',
|
||||
license_type_inactive: 'This licence type is not currently accepting applications.',
|
||||
|
||||
// Licence-type configuration guards. Each of these refuses a change that
|
||||
// would leave applications already in progress unable to move.
|
||||
license_type_in_use:
|
||||
'Applications of this type are already in progress, and this setting decides the course they run. Wait until those have been decided, or change something else.',
|
||||
stage_fee_in_use:
|
||||
'Candidates are currently waiting to pay this fee. Removing it would leave them unable to pay and unable to continue — set a different amount instead.',
|
||||
form_schema_missing_protected_paths:
|
||||
'The form for this licence type does not contain the field this setting depends on. Add the field to the form first.',
|
||||
};
|
||||
|
||||
export function extractErrorMessage(error: unknown, fallback = 'Something went wrong'): string {
|
||||
@@ -451,12 +466,28 @@ export function buildWizardSteps(
|
||||
* instead of showing an empty page.
|
||||
*/
|
||||
hasStaff?: boolean;
|
||||
/**
|
||||
* Whether this application has any document requirements to upload.
|
||||
* False for a Damaged/Reissue application, which asks nothing beyond the
|
||||
* Damage Information step — showing an empty Documents page would be a
|
||||
* page to click past for nothing.
|
||||
*/
|
||||
hasDocuments?: boolean;
|
||||
/** Active UI language. Components get this from `useLocalized`; this is a
|
||||
* pure function, so the caller passes `i18n.language` through. */
|
||||
language?: string;
|
||||
/**
|
||||
* The application's kind — NEW unless the caller is renewing or
|
||||
* reissuing. A section scoped to a different kind via
|
||||
* `applicationKinds` is left out entirely, the same as a `showWhen`
|
||||
* that never holds.
|
||||
*/
|
||||
applicationKind?: ApplicationKind;
|
||||
},
|
||||
): WizardStep[] {
|
||||
const kind = options?.applicationKind ?? 'NEW';
|
||||
const visible = [...sections]
|
||||
.filter((section) => sectionAppliesToKind(section, kind))
|
||||
.filter((section) => conditionHolds(section.showWhen, formData))
|
||||
.sort((a, b) => (a.sortOrder ?? 0) - (b.sortOrder ?? 0));
|
||||
|
||||
@@ -511,7 +542,9 @@ export function buildWizardSteps(
|
||||
...(options?.hasStaff === false
|
||||
? []
|
||||
: [{ key: 'staff', label: 'Staff', kind: 'staff', sections: [] } as WizardStep]),
|
||||
{ key: 'documents', label: 'Documents', kind: 'documents', sections: [] },
|
||||
...(options?.hasDocuments === false
|
||||
? []
|
||||
: [{ key: 'documents', label: 'Documents', kind: 'documents', sections: [] } as WizardStep]),
|
||||
{ key: 'review', label: 'Review', kind: 'review', sections: reviewSections },
|
||||
];
|
||||
}
|
||||
@@ -597,6 +630,49 @@ interface ConditionLike {
|
||||
anyOf?: ConditionLike[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Section keys a condition reads, recursing `anyOf`.
|
||||
*
|
||||
* `FieldCondition.field` is a `sectionKey.fieldKey` path, so the prefix names
|
||||
* the section whose answer decides the condition.
|
||||
*/
|
||||
export function conditionSections(
|
||||
condition: FieldCondition | undefined | null,
|
||||
): string[] {
|
||||
if (!condition) return [];
|
||||
if (condition.anyOf) return condition.anyOf.flatMap(conditionSections);
|
||||
if (!condition.field) return [];
|
||||
const [sectionKey] = condition.field.split('.');
|
||||
return sectionKey ? [sectionKey] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sections whose visibility hangs on an answer in one of `flagged`.
|
||||
*
|
||||
* Mirrors the server's `sectionsDependingOn`: an officer flagging the section
|
||||
* that holds the vessel category is asking for an answer that decides which
|
||||
* fields in other sections are required, so those sections have to open too —
|
||||
* otherwise the applicant sees newly-required fields they cannot edit and
|
||||
* cannot resubmit.
|
||||
*/
|
||||
export function sectionsDependingOn(
|
||||
sections: FormSectionConfig[],
|
||||
flagged: Set<string>,
|
||||
): Set<string> {
|
||||
const dependent = new Set<string>();
|
||||
if (flagged.size === 0) return dependent;
|
||||
|
||||
for (const section of sections) {
|
||||
if (flagged.has(section.key)) continue;
|
||||
const reads = [
|
||||
section.showWhen,
|
||||
...(section.fields ?? []).map((field) => field.showWhen),
|
||||
].flatMap(conditionSections);
|
||||
if (reads.some((key) => flagged.has(key))) dependent.add(section.key);
|
||||
}
|
||||
return dependent;
|
||||
}
|
||||
|
||||
export function conditionHolds(
|
||||
condition: FieldCondition | undefined | null,
|
||||
formData: Record<string, Record<string, unknown>>,
|
||||
|
||||
Reference in New Issue
Block a user