diff --git a/apps/portal/src/app/features/licensing/pages/LicenseApplicationPage.tsx b/apps/portal/src/app/features/licensing/pages/LicenseApplicationPage.tsx index 193eb4dbe..dc82f5e50 100644 --- a/apps/portal/src/app/features/licensing/pages/LicenseApplicationPage.tsx +++ b/apps/portal/src/app/features/licensing/pages/LicenseApplicationPage.tsx @@ -45,7 +45,6 @@ import { useGetApplicationQuery, useGetAttachmentsQuery, useGetLicenseTypeRequirementsQuery, - useGetMyApplicationsQuery, useGetMyVesselsQuery, usePatchSectionMutation, useRemoveStaffMutation, @@ -104,42 +103,25 @@ export function LicenseApplicationPage() { const { data: vessels } = useGetMyVesselsQuery(); const [createApplication] = useCreateApplicationMutation(); const [appId, setAppId] = useState(applicationId); - // Only fetched to recover from the 409 below — a fresh visit never needs - // the applicant's whole application list, so this stays lazy. - const { data: myApplications, refetch: fetchMyApplications } = - useGetMyApplicationsQuery(undefined, { skip: true }); // Create (or resume) the draft up front, so uploads have a real owner to // attach to and nothing is lost if the browser is closed mid-wizard. + // For a one-shot registration (e.g. seafarer) already submitted or further + // along, the API returns that existing application instead of a new draft — + // "Apply" reopens it rather than erroring, the same way it reopens a DRAFT. useEffect(() => { if (appId || !config) return; createApplication({ licenseType: typeCode }) .unwrap() .then((app) => setAppId(app.id)) - .catch(async (err) => { - // A one-shot registration (e.g. seafarer) already has a submitted (or - // further along) application — the backend refuses a second one - // rather than silently resuming it, unlike an unfinished DRAFT. The - // applicant's intent was still "open my registration", so find the - // existing one and load it instead of leaving the page stuck on this - // toast with nothing to fetch. - if (err?.status === 409) { - const mine = myApplications ?? (await fetchMyApplications().unwrap()); - const existing = mine.items.find( - (a) => a.licenseTypeId === config.licenseType.id, - ); - if (existing) { - setAppId(existing.id); - return; - } - } + .catch((err) => notifications.show({ color: "red", title: "Could not start application", message: extractErrorMessage(err), - }); - }); - }, [appId, config, createApplication, typeCode, myApplications, fetchMyApplications]); + }), + ); + }, [appId, config, createApplication, typeCode]); const { data: detail, refetch } = useGetApplicationQuery(appId as string, { skip: !appId,