mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-09-07 20:05:42 +00:00
Merge branch 'createNewLicenseType' of https://github.com/Tria-plc/emaui into createNewLicenseType
This commit is contained in:
@@ -10,7 +10,7 @@ import { resolveSessionContext } from "../session";
|
||||
export const BASE_API_URL =
|
||||
(import.meta as { env?: Record<string, string> }).env?.[
|
||||
"VITE_BASE_API_URL"
|
||||
]?.trim() || "http://localhost:3000/api";
|
||||
]?.trim() || "https://ema-api-dev.triaplc.com/api";
|
||||
|
||||
let _onTokenExpired: (() => Promise<string>) | null = null;
|
||||
let _onAuthFailure: (() => void) | null = null;
|
||||
|
||||
@@ -74,6 +74,51 @@ const handlers: MockHandler[] = [
|
||||
pattern: /^\/license-types$/,
|
||||
respond: () => paginated(clone(mockLicenseTypes)),
|
||||
},
|
||||
{
|
||||
method: 'POST',
|
||||
pattern: /^\/license-types$/,
|
||||
respond: (req) => {
|
||||
const body = (req.body ?? {}) as Record<string, unknown>;
|
||||
const key = String(body.key ?? '').trim().toUpperCase();
|
||||
if (mockLicenseTypes.some((t) => t.key === key)) return undefined;
|
||||
const created = {
|
||||
id: `lt-${key.toLowerCase()}`,
|
||||
category: 'MARITIME_PERSONNEL',
|
||||
familyKind: 'LOGISTICS_LICENSE',
|
||||
serviceKind: 'LICENSE',
|
||||
workflowProfile: 'STANDARD',
|
||||
feeNewApplication: null,
|
||||
feeRenewal: null,
|
||||
feeCurrency: 'ETB',
|
||||
capitalThreshold: null,
|
||||
validityMonths: 12,
|
||||
slaHours: null,
|
||||
inspectionRequired: true,
|
||||
issuesCertificate: true,
|
||||
renewalEnabled: true,
|
||||
requiresIssuanceScheduling: false,
|
||||
requiresOperatorMode: true,
|
||||
formSchema: { sections: [] },
|
||||
isActive: true,
|
||||
sortOrder: mockLicenseTypes.length,
|
||||
...body,
|
||||
key,
|
||||
};
|
||||
(mockLicenseTypes as unknown[]).push(created);
|
||||
return clone(created);
|
||||
},
|
||||
},
|
||||
{
|
||||
method: 'PATCH',
|
||||
pattern: /^\/license-types\/([\w-]+)\/status$/,
|
||||
respond: (req, match) => {
|
||||
const found = mockLicenseTypes.find((t) => t.id === match[1]);
|
||||
if (!found) return undefined;
|
||||
const body = (req.body ?? {}) as { isActive?: boolean };
|
||||
(found as { isActive: boolean }).isActive = body.isActive ?? found.isActive;
|
||||
return clone(found);
|
||||
},
|
||||
},
|
||||
{
|
||||
method: 'GET',
|
||||
pattern: /^\/license-types\/requirements\/([\w-]+)$/,
|
||||
|
||||
@@ -29,6 +29,8 @@ import type {
|
||||
DocumentDecision,
|
||||
DocumentReview,
|
||||
ExportResult,
|
||||
FamilyKind,
|
||||
LicenseCategory,
|
||||
LicenseTemplate,
|
||||
Paginated,
|
||||
PickupAppointment,
|
||||
@@ -111,6 +113,28 @@ const TAGS = [
|
||||
const listTag = (type: (typeof TAGS)[number]) => ({ type, id: 'LIST' }) as const;
|
||||
const itemTag = (type: (typeof TAGS)[number], id: string) => ({ type, id }) as const;
|
||||
|
||||
/** What `POST /license-types` accepts. Mirrors the server's create DTO. */
|
||||
export interface CreateLicenseTypeInput {
|
||||
key: string;
|
||||
name: { en: string; am: string };
|
||||
description?: { en: string; am: string };
|
||||
category?: LicenseCategory;
|
||||
familyKind?: FamilyKind;
|
||||
serviceKind?: ServiceKind;
|
||||
workflowProfile?: WorkflowProfile;
|
||||
certificatePrefix: string;
|
||||
feeNewApplication?: number;
|
||||
feeRenewal?: number;
|
||||
feeCurrency?: string;
|
||||
capitalThreshold?: number;
|
||||
validityMonths?: number;
|
||||
inspectionRequired?: boolean;
|
||||
issuesCertificate?: boolean;
|
||||
renewalEnabled?: boolean;
|
||||
sortOrder?: number;
|
||||
isActive?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Typed licensing endpoints, shared by the portal and the backoffice.
|
||||
*
|
||||
@@ -256,7 +280,6 @@ export const licensingApi = baseApi
|
||||
id: string;
|
||||
workflowProfile?: WorkflowProfile;
|
||||
serviceKind?: ServiceKind;
|
||||
/** Licence / certificate / document — see `FamilyKind`. */
|
||||
familyKind?: FamilyKind;
|
||||
completionEffect?: CompletionEffect | null;
|
||||
certificateCategory?: CertificateCategory | null;
|
||||
@@ -288,6 +311,36 @@ export const licensingApi = baseApi
|
||||
error ? [] : [listTag('LicenseType'), itemTag('LicenseType', id)],
|
||||
}),
|
||||
|
||||
/**
|
||||
* Creates a licence type. The bare minimum a type needs to exist and
|
||||
* be classified; its form, documents, fees and behaviour are configured
|
||||
* afterwards on their own screens. The server upper-cases and trims the
|
||||
* key, refuses a taken one with 409 `license_type_key_taken`, and lints
|
||||
* a form schema if one is supplied.
|
||||
*/
|
||||
createLicenseType: builder.mutation<LicenseType, CreateLicenseTypeInput>({
|
||||
query: (body) => ({ url: '/license-types', method: 'POST', body }),
|
||||
invalidatesTags: (_r, error) => (error ? [] : [listTag('LicenseType')]),
|
||||
}),
|
||||
|
||||
/**
|
||||
* Opens or closes a type to new applications. Applications already in
|
||||
* flight hold the type by id and keep running; only the portal
|
||||
* catalogue changes.
|
||||
*/
|
||||
updateLicenseStatus: builder.mutation<
|
||||
LicenseType,
|
||||
{ id: string; isActive: boolean }
|
||||
>({
|
||||
query: ({ id, isActive }) => ({
|
||||
url: `/license-types/${id}/status`,
|
||||
method: 'PATCH',
|
||||
body: { isActive },
|
||||
}),
|
||||
invalidatesTags: (_r, error, { id }) =>
|
||||
error ? [] : [itemTag('LicenseType', id), listTag('LicenseType')],
|
||||
}),
|
||||
|
||||
/** Validity is edited beside the certificate design, not with the fees. */
|
||||
updateLicenseValidity: builder.mutation<
|
||||
LicenseType,
|
||||
@@ -1419,6 +1472,7 @@ export const {
|
||||
useUpdateRankMutation,
|
||||
useDeleteRankMutation,
|
||||
useUpdateLicenseValidityMutation,
|
||||
useUpdateLicenseStatusMutation,
|
||||
useGetLicenseTypeRequirementsQuery,
|
||||
useCreateApplicationMutation,
|
||||
useGetExamStateForApplicationQuery,
|
||||
|
||||
@@ -411,6 +411,18 @@ const ERROR_MESSAGES: Record<string, string> = {
|
||||
'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.',
|
||||
license_type_key_taken:
|
||||
'A licence type with this key already exists (it may be archived). Choose a different key.',
|
||||
license_type_key_in_use:
|
||||
'Applications already reference this licence type, so its key can no longer be changed.',
|
||||
invalid_form_schema:
|
||||
'The form schema is not consistent — a condition or field reference points at something the form does not define.',
|
||||
|
||||
// Exam certification catalogue.
|
||||
rank_not_found:
|
||||
'That STCW rank is not in the ranks registry, or has been switched off. Pick a rank from the list.',
|
||||
certification_in_use:
|
||||
'Exam sessions or question-bank items still use this certification. Reassign or remove those first.',
|
||||
};
|
||||
|
||||
export function extractErrorMessage(error: unknown, fallback = 'Something went wrong'): string {
|
||||
|
||||
Reference in New Issue
Block a user