This commit is contained in:
Nati
2026-08-24 07:49:10 +00:00
parent 302c0242dd
commit a84177cf12

View File

@@ -23,11 +23,10 @@ import {
useArchiveLicenseTemplateMutation, useArchiveLicenseTemplateMutation,
useCreateLicenseTemplateMutation, useCreateLicenseTemplateMutation,
useDeleteLicenseTemplateMutation, useDeleteLicenseTemplateMutation,
useGetActiveDepartmentsQuery,
useGetBuiltInTemplateQuery, useGetBuiltInTemplateQuery,
useGetLicenseTemplatesQuery, useGetLicenseTemplatesQuery,
useGetLicenseTypesQuery, useGetLicenseTypesQuery,
useGetRankLadderQuery, useGetRanksQuery,
useGetTemplateVariablesQuery, useGetTemplateVariablesQuery,
usePublishLicenseTemplateMutation, usePublishLicenseTemplateMutation,
useUpdateLicenseValidityMutation, useUpdateLicenseValidityMutation,
@@ -103,18 +102,17 @@ export function CertificateDesignerPage() {
const selectedType = licenseTypes?.items?.find((type) => type.id === typeId); const selectedType = licenseTypes?.items?.find((type) => type.id === typeId);
// A rank ladder only exists for CoC/CoP — every other licence type designs // A rank ladder only exists for CoC/CoP — every other licence type designs
// one certificate for everyone who holds it. // one certificate for everyone who holds it. CoC/CoP are each a single
// LicenseType spanning every department's ladder (stcwDepartment is null
// on both — the applicant's own department, not the type, decides which
// ladder they climb), so the picker offers every rank in the category
// across all departments rather than one department's ladder.
const isRankScoped = const isRankScoped =
selectedType?.certificateCategory === 'COC' || selectedType?.certificateCategory === 'COP'; selectedType?.certificateCategory === 'COC' || selectedType?.certificateCategory === 'COP';
const { data: departments } = useGetActiveDepartmentsQuery(undefined, { skip: !isRankScoped }); const { data: allRanks } = useGetRanksQuery(undefined, { skip: !isRankScoped });
const department = departments?.find((d) => d.code === selectedType?.stcwDepartment); const ranks = (allRanks?.items ?? [])
const { data: ranks = [] } = useGetRankLadderQuery( .filter((r) => r.certificateCategory === selectedType?.certificateCategory)
{ .sort((a, b) => a.sortOrder - b.sortOrder);
departmentId: department?.id ?? '',
certificateCategory: (selectedType?.certificateCategory ?? 'COC') as 'COC' | 'COP',
},
{ skip: !isRankScoped || !department },
);
// Default to the first licence type so the page is never an empty shell. // Default to the first licence type so the page is never an empty shell.
useEffect(() => { useEffect(() => {