diff --git a/apps/backoffice/src/app/features/certificate-requirements/components/BehaviorTab.tsx b/apps/backoffice/src/app/features/certificate-requirements/components/BehaviorTab.tsx index d1606b697..41ce93dd3 100644 --- a/apps/backoffice/src/app/features/certificate-requirements/components/BehaviorTab.tsx +++ b/apps/backoffice/src/app/features/certificate-requirements/components/BehaviorTab.tsx @@ -21,7 +21,6 @@ import { type CertificateCategory, type CompletionEffect, type LicenseType, - type ServiceKind, type WorkflowProfile, } from '@ema-platform/api'; import { useRequirementActions } from '../hooks/useRequirementActions'; @@ -29,7 +28,6 @@ import { useRequirementActions } from '../hooks/useRequirementActions'; /** The shape the form edits — every field the behaviour endpoint accepts. */ interface Draft { workflowProfile: WorkflowProfile; - serviceKind: ServiceKind; completionEffect: CompletionEffect | null; certificateCategory: CertificateCategory | null; requiresExamination: boolean; @@ -57,7 +55,6 @@ const REMINDER_OFFSETS = ['90', '60', '30', '14', '7']; function toDraft(licenseType: LicenseType): Draft { return { workflowProfile: licenseType.workflowProfile ?? 'STANDARD', - serviceKind: licenseType.serviceKind ?? 'LICENSE', completionEffect: licenseType.completionEffect ?? null, certificateCategory: licenseType.certificateCategory ?? null, requiresExamination: licenseType.requiresExamination ?? false, @@ -154,12 +151,22 @@ export function BehaviorTab({ licenseType }: { licenseType: LicenseType }) { ...rest } = draft; + // A type switched from "does not expire" straight to a term in days still + // carries `validityMonths: 0`, which the server's 6-month floor refuses. + // Days win over months at issuance, so the zero is simply left alone. + const term = expires + ? { + validityDays, + ...(validityMonths > 0 ? { validityMonths } : {}), + } + : {}; + const ok = await run( () => save({ id: licenseType.id, ...rest, - ...(expires ? { validityMonths, validityDays } : {}), + ...term, ...(expires && draft.renewalEnabled ? { renewalWindowDays, expiryReminderDays } : {}), @@ -241,21 +248,10 @@ export function BehaviorTab({ licenseType }: { licenseType: LicenseType }) { disabled={!canEdit} /> -