From 0896d4fac76e30ce5f09c31bc73b9ee0ded09260 Mon Sep 17 00:00:00 2001 From: Carlos Monastyrski Date: Thu, 23 Oct 2025 21:15:16 -0300 Subject: [PATCH] Fix certificate list issuance modal not showing algorithm options --- .../components/CertificateIssuanceModal.tsx | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx index c92844eed..dc0dffb0d 100644 --- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx +++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateIssuanceModal.tsx @@ -111,6 +111,7 @@ type TCertificateDetails = { export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId }: Props) => { const [certificateDetails, setCertificateDetails] = useState(null); + const [shouldShowSubjectSection, setShouldShowSubjectSection] = useState(true); const { currentProject } = useProject(); const inputSerialNumber = @@ -127,19 +128,9 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId } const { mutateAsync: createCertificate } = useCreateCertificateV3(); - const selectedProfileId = useMemo(() => { - const form = document.querySelector('select[name="profileId"]') as HTMLSelectElement; - return form?.value || profileId || ""; - }, [profileId]); - - const selectedProfile = useMemo( - () => profilesData?.certificateProfiles?.find((p) => p.id === selectedProfileId), - [profilesData?.certificateProfiles, selectedProfileId] - ); - - const { data: templateData } = useGetCertificateTemplateV2ById({ - templateId: selectedProfile?.certificateTemplateId || "" - }); + const formResolver = useMemo(() => { + return zodResolver(createSchema(shouldShowSubjectSection)); + }, [shouldShowSubjectSection]); const { control, @@ -150,7 +141,7 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId } formState, formState: { isSubmitting } } = useForm({ - resolver: zodResolver(createSchema((templateData?.subject?.length || 0) > 0)), + resolver: formResolver, defaultValues: { profileId: profileId || "", subjectAttributes: [], @@ -169,6 +160,16 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId } [profilesData?.certificateProfiles, actualSelectedProfileId] ); + const { data: templateData } = useGetCertificateTemplateV2ById({ + templateId: actualSelectedProfile?.certificateTemplateId || "" + }); + + useEffect(() => { + if (templateData !== undefined) { + setShouldShowSubjectSection((templateData?.subject?.length || 0) > 0); + } + }, [templateData]); + const { constraints, filteredKeyUsages, @@ -186,6 +187,7 @@ export const CertificateIssuanceModal = ({ popUp, handlePopUpToggle, profileId } const resetAllState = useCallback(() => { setCertificateDetails(null); + setShouldShowSubjectSection(true); resetConstraints(); reset(); }, [reset, resetConstraints]);