diff --git a/apps/backoffice/src/app/features/license-review/pages/LicenseQueuePage.tsx b/apps/backoffice/src/app/features/license-review/pages/LicenseQueuePage.tsx index 16b49e6d1..8b7c33c47 100644 --- a/apps/backoffice/src/app/features/license-review/pages/LicenseQueuePage.tsx +++ b/apps/backoffice/src/app/features/license-review/pages/LicenseQueuePage.tsx @@ -33,8 +33,10 @@ import { import { notifications } from "@mantine/notifications"; import { useTranslation } from "react-i18next"; import { + APPLICANT_NAME_TYPE_KEYS, STATUS_COLORS, STATUS_LABELS, + applicantOrCompanyName, extractErrorMessage, useClaimApplicationMutation, useGetAllApplicationsQuery, @@ -89,27 +91,6 @@ const ALL_STATUSES: LicenseStatus[] = [ "REJECTED", ]; -/** Licence types with no `companyName` — the queue's "company" column falls - * back to the applicant name captured in the form instead. */ -const APPLICANT_NAME_TYPE_KEYS = [ - "SEAFARER_REGISTRATION", - "CERTIFICATE_OF_COMPETENCY", - "CERTIFICATE_OF_PROFICIENCY", - "VESSEL_REGISTRATION", - "VESSEL_OWNERSHIP_TRANSFER", - "ENDORSEMENT_COC", - "ENDORSEMENT_GOC", -]; - -function applicantOrCompanyName(app: LicenseApplication): string | undefined { - if (!app.licenseType?.key || !APPLICANT_NAME_TYPE_KEYS.includes(app.licenseType.key)) { - return app.companyName ?? undefined; - } - const applicantName = (app.formData?.account as Record | undefined) - ?.applicantName; - return typeof applicantName === "string" && applicantName ? applicantName : undefined; -} - /** * The officer work pool. * diff --git a/apps/portal/src/app/features/licensing/pages/MyApplicationsPage.tsx b/apps/portal/src/app/features/licensing/pages/MyApplicationsPage.tsx index 328591367..f85478a01 100644 --- a/apps/portal/src/app/features/licensing/pages/MyApplicationsPage.tsx +++ b/apps/portal/src/app/features/licensing/pages/MyApplicationsPage.tsx @@ -21,6 +21,7 @@ import { notifications } from '@mantine/notifications'; import { STATUS_COLORS, STATUS_LABELS, + applicantOrCompanyName, extractErrorMessage, localized, useBypassPaymentMutation, @@ -120,7 +121,7 @@ export function MyApplicationsPage() { const q = search.trim().toLowerCase(); return allItems.filter((app) => { if (q) { - const haystack = `${app.applicationNumber} ${app.companyName ?? ''}`.toLowerCase(); + const haystack = `${app.applicationNumber} ${applicantOrCompanyName(app) ?? ''}`.toLowerCase(); if (!haystack.includes(q)) return false; } if (statusFilter && app.status !== statusFilter) return false; @@ -201,7 +202,7 @@ export function MyApplicationsPage() { }, { header: 'Company', - cell: ({ row }) => {row.original.companyName ?? '—'}, + cell: ({ row }) => {applicantOrCompanyName(row.original) ?? '—'}, }, { header: 'Status', diff --git a/libs/api/src/lib/features/licensing/licensing.helpers.ts b/libs/api/src/lib/features/licensing/licensing.helpers.ts index bd32482c7..001164e40 100644 --- a/libs/api/src/lib/features/licensing/licensing.helpers.ts +++ b/libs/api/src/lib/features/licensing/licensing.helpers.ts @@ -2,6 +2,7 @@ import { resolveTokenFromStorage } from '../../session'; import type { Bilingual, FormSectionConfig, + LicenseApplication, LicenseStatus, ValidationIssue, } from './licensing.types'; @@ -129,6 +130,28 @@ export const TERMINAL_STATUSES: LicenseStatus[] = [ 'REJECTED', ]; +/** Licence types with no `companyName` — these are filed by a person, not a + * business, so display falls back to the applicant name captured in the form. */ +export const APPLICANT_NAME_TYPE_KEYS = [ + 'SEAFARER_REGISTRATION', + 'CERTIFICATE_OF_COMPETENCY', + 'CERTIFICATE_OF_PROFICIENCY', + 'VESSEL_REGISTRATION', + 'VESSEL_OWNERSHIP_TRANSFER', + 'ENDORSEMENT_COC', + 'ENDORSEMENT_GOC', +]; + +/** Company name, or applicant name for licence types that have no company. */ +export function applicantOrCompanyName(app: LicenseApplication): string | undefined { + if (!app.licenseType?.key || !APPLICANT_NAME_TYPE_KEYS.includes(app.licenseType.key)) { + return app.companyName ?? undefined; + } + const applicantName = (app.formData?.account as Record | undefined) + ?.applicantName; + return typeof applicantName === 'string' && applicantName ? applicantName : undefined; +} + /** Reads a bilingual value for the active language, falling back to English. */ export function localized(value: Bilingual | undefined, language = 'en'): string { if (!value) return '';