Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
improvement(pki): migrate legacy certificate workflows to V3 (#8860)
Andrew Huangbfc6463da64a
diff --git a/frontend/src/pages/cert-manager/AlertingPage/components/PkiAlertModal.tsx b/frontend/src/pages/cert-manager/AlertingPage/components/PkiAlertModal.tsxindex 597391c641..7661c534ad 100644--- a/frontend/src/pages/cert-manager/AlertingPage/components/PkiAlertModal.tsx+++ b/frontend/src/pages/cert-manager/AlertingPage/components/PkiAlertModal.tsx@@ -1,4 +1,4 @@-import { useEffect } from "react";+import { useEffect, useId } from "react";import { Controller, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";@@ -6,21 +6,41 @@ import { z } from "zod";import { createNotification } from "@app/components/notifications";import {Button,- FormControl,+ Combobox,+ DiscardChangesAlertDialog,+ Field,+ FieldError,+ FieldLabel,Input,- Modal,- ModalContent,Select,- SelectItem-} from "@app/components/v2";-import { useProject } from "@app/context";+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+ Sheet,+ SheetClose,+ SheetContent,+ SheetDescription,+ SheetFooter,+ SheetHeader,+ SheetTitle+} from "@app/components/v3";+import {+ ProjectPermissionActions,+ ProjectPermissionSub,+ useProject,+ useProjectPermission+} from "@app/context";import {useCreatePkiAlert,useGetPkiAlertById,useListWorkspacePkiCollections,useUpdatePkiAlert} from "@app/hooks/api";-import { UsePopUpState } from "@app/hooks/usePopUp";+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";+import { usePopUp, UsePopUpState } from "@app/hooks/usePopUp";++import { PkiCollectionModal } from "./PkiCollectionModal";enum TimeUnit {DAY = "days",@@ -60,14 +80,17 @@ type Props = {};export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {+ const { permission } = useProjectPermission();+ const collectionPopup = usePopUp(["pkiCollection"] as const);const { currentProject } = useProject();+ const formId = useId();const projectId = currentProject?.id || "";- const { data: alert } = useGetPkiAlertById(- (popUp?.pkiAlert?.data as { alertId: string })?.alertId || ""- );+ const alertId = (popUp?.pkiAlert?.data as { alertId?: string })?.alertId || "";+ const { data: alert } = useGetPkiAlertById(alertId);+ const isAlertReady = !alertId || alert?.id === alertId;- const { data: pkiCollections } = useListWorkspacePkiCollections({+ const { data: pkiCollections, refetch: refetchCollections } = useListWorkspacePkiCollections({projectId});@@ -78,7 +101,8 @@ export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {control,handleSubmit,reset,- formState: { isSubmitting }+ setValue,+ formState: { isSubmitting, isDirty }} = useForm<FormData>({resolver: zodResolver(schema),defaultValues: {@@ -87,6 +111,7 @@ export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {});useEffect(() => {+ if (!popUp.pkiAlert.isOpen || !isAlertReady || isDirty) return;if (alert) {reset({name: alert.name,@@ -104,7 +129,7 @@ export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {})});}- }, [alert, pkiCollections]);+ }, [alert, pkiCollections, popUp.pkiAlert.isOpen, reset, isDirty, isAlertReady]);const onFormSubmit = async ({name,@@ -113,7 +138,7 @@ export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {alertUnit,emails}: FormData) => {- if (!projectId) return;+ if (!projectId || !isAlertReady) return;const emailArray = emails.split(",")@@ -151,135 +176,204 @@ export const PkiAlertModal = ({ popUp, handlePopUpToggle }: Props) => {});};- return (- <Modal- isOpen={popUp?.pkiAlert?.isOpen}- onOpenChange={(isOpen) => {- handlePopUpToggle("pkiAlert", isOpen);+ const { requestDiscard, confirmDiscard, isDiscardDialogOpen, setIsDiscardDialogOpen } =+ useDiscardChangesGuard({+ isDirty,+ onDiscard: () => {reset();- }}- >- <ModalContent title={`${alert ? "Edit" : "Create"} Alert`}>- <form onSubmit={handleSubmit(onFormSubmit)}>- <Controller- control={control}- defaultValue=""- name="name"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Name"- isError={Boolean(error)}- errorText={error?.message}- isRequired- >- <Input {...field} placeholder="My Alert" autoComplete="off" name="pki-alert-name" />- </FormControl>- )}- />- <Controller- control={control}- name="pkiCollectionId"- defaultValue=""- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label="Certificate Collection"- errorText={error?.message}- isError={Boolean(error)}- isRequired- >- <Select- defaultValue={field.value}- {...field}- onValueChange={(e) => onChange(e)}- className="w-full"- >- {(pkiCollections?.collections || []).map(({ id, name }) => (- <SelectItem value={id} key={`project-${id}`}>- {name}- </SelectItem>- ))}- </Select>- </FormControl>- )}- />- <div className="flex items-center">- <Controller- control={control}- defaultValue=""- name="alertBefore"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Alert Before"- isError={Boolean(error)}- errorText={error?.message}- className="w-full"- isRequired- >- <Input {...field} placeholder="5" type="number" min={1} />- </FormControl>- )}- />- <Controller- control={control}- name="alertUnit"- defaultValue={TimeUnit.YEAR}- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- className="ml-4"- label="Alert Unit"- errorText={error?.message}- isError={Boolean(error)}- >- <Select- defaultValue={field.value}- {...field}- onValueChange={(e) => onChange(e)}- className="w-48"- >- <SelectItem value={TimeUnit.DAY}>Days</SelectItem>- <SelectItem value={TimeUnit.WEEK}>Weeks</SelectItem>- <SelectItem value={TimeUnit.MONTH}>Months</SelectItem>- <SelectItem value={TimeUnit.YEAR}>Years</SelectItem>- </Select>- </FormControl>- )}- />- </div>- <Controller- control={control}- defaultValue=""- name="emails"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Emails to Alert"- isError={Boolean(error)}- errorText={error?.message}- isRequired- >- <Input {...field} placeholder="[email protected], [email protected], ..." />- </FormControl>- )}- />- <div className="flex items-center">- <Button- className="mr-4"- size="sm"- type="submit"- isLoading={isSubmitting}- isDisabled={isSubmitting}- >- {alert ? "Update" : "Create"}- </Button>- <Button- colorSchema="secondary"- variant="plain"- onClick={() => handlePopUpToggle("pkiAlert", false)}+ handlePopUpToggle("pkiAlert", false);+ }+ });++ return (+ <>+ <Sheet+ open={popUp?.pkiAlert?.isOpen}+ onOpenChange={(isOpen) => {+ if (!isOpen) requestDiscard();+ }}+ >+ <SheetContent size="form" isPending={isSubmitting}>+ <SheetHeader>+ <SheetTitle>{`${alertId ? "Edit" : "Create"} Alert`}</SheetTitle>+ <SheetDescription>Configure certificate expiration notifications.</SheetDescription>+ </SheetHeader>+ <form onSubmit={handleSubmit(onFormSubmit)} className="flex min-h-0 flex-1 flex-col">+ <fieldset+ disabled={isSubmitting || !isAlertReady}+ className="flex min-h-0 min-w-0 flex-1 flex-col gap-4 overflow-y-auto p-4">- Cancel- </Button>- </div>- </form>- </ModalContent>- </Modal>+ <Controller+ control={control}+ defaultValue=""+ name="name"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-name`}>+ Name <span className="text-danger">*</span>+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-name`}+ {...field}+ placeholder="My Alert"+ autoComplete="off"+ name="pki-alert-name"+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="pkiCollectionId"+ defaultValue=""+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-pkiCollectionId`}>+ Certificate Collection <span className="text-danger">*</span>+ </FieldLabel>+ <Combobox+ id={`${formId}-pkiCollectionId`}+ ref={field.ref}+ name={field.name}+ onBlur={field.onBlur}+ isError={Boolean(error)}+ options={pkiCollections?.collections || []}+ value={+ pkiCollections?.collections.find(({ id }) => id === field.value) ?? null+ }+ onValueChange={(collection) => onChange(collection?.id ?? "")}+ getOptionValue={(collection) => collection.id}+ getOptionLabel={(collection) => collection.name}+ placeholder="Select a certificate collection"+ creation={+ permission.can(+ ProjectPermissionActions.Create,+ ProjectPermissionSub.PkiCollections+ )+ ? {+ mode: "action",+ emptyLabel: "Create New Collection",+ formatLabel: () => "Create New Collection",+ onAction: () => collectionPopup.handlePopUpOpen("pkiCollection")+ }+ : undefined+ }+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <div className="flex items-center">+ <Controller+ control={control}+ defaultValue=""+ name="alertBefore"+ render={({ field, fieldState: { error } }) => (+ <Field className="w-full" data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-alertBefore`}>+ Alert Before <span className="text-danger">*</span>+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-alertBefore`}+ {...field}+ placeholder="5"+ type="number"+ min={1}+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="alertUnit"+ defaultValue={TimeUnit.YEAR}+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (+ <Field className="ml-4" data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-alertUnit`}>Alert Unit</FieldLabel>+ <Select value={field.value} onValueChange={onChange} name={field.name}>+ <SelectTrigger+ id={`${formId}-alertUnit`}+ ref={field.ref}+ onBlur={field.onBlur}+ className="w-full"+ isError={Boolean(error)}+ >+ <SelectValue placeholder="Select an option" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value={TimeUnit.DAY}>Days</SelectItem>+ <SelectItem value={TimeUnit.WEEK}>Weeks</SelectItem>+ <SelectItem value={TimeUnit.MONTH}>Months</SelectItem>+ <SelectItem value={TimeUnit.YEAR}>Years</SelectItem>+ </SelectContent>+ </Select>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ </div>+ <Controller+ control={control}+ defaultValue=""+ name="emails"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-emails`}>+ Emails to Alert <span className="text-danger">*</span>+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-emails`}+ {...field}+ placeholder="[email protected], [email protected], ..."+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ </fieldset>+ <SheetFooter className="justify-end border-t">+ <SheetClose asChild>+ <Button variant="ghost">Cancel</Button>+ </SheetClose>+ <Button+ variant="project"+ type="submit"+ isPending={isSubmitting}+ isDisabled={!isAlertReady}+ >+ {alertId ? "Update" : "Create"}+ </Button>+ </SheetFooter>+ </form>+ </SheetContent>+ </Sheet>+ <PkiCollectionModal+ popUp={collectionPopup.popUp}+ handlePopUpToggle={collectionPopup.handlePopUpToggle}+ onComplete={async (collection) => {+ const result = await refetchCollections();+ if (!result.data?.collections.some((option) => option.id === collection.id)) {+ createNotification({+ type: "error",+ text: "The collection was created, but the list could not be refreshed. Refresh the list to select it."+ });+ return;+ }+ setValue("pkiCollectionId", collection.id, { shouldDirty: true, shouldValidate: true });+ }}+ />+ <DiscardChangesAlertDialog+ open={isDiscardDialogOpen}+ onOpenChange={setIsDiscardDialogOpen}+ onDiscard={confirmDiscard}+ title="Discard Changes?"+ description="Your unsaved changes will be lost."+ />+ </>);};diff --git a/frontend/src/pages/cert-manager/AlertingPage/components/PkiAlertsSection.tsx b/frontend/src/pages/cert-manager/AlertingPage/components/PkiAlertsSection.tsxindex db3c490dd8..087a565d39 100644--- a/frontend/src/pages/cert-manager/AlertingPage/components/PkiAlertsSection.tsx+++ b/frontend/src/pages/cert-manager/AlertingPage/components/PkiAlertsSection.tsx@@ -1,5 +1,13 @@import { createNotification } from "@app/components/notifications";-import { ConfirmationAlertDialog } from "@app/components/v3";+import {+ Badge,+ Card,+ CardContent,+ CardDescription,+ CardHeader,+ CardTitle,+ ConfirmationAlertDialog+} from "@app/components/v3";import { useProject } from "@app/context";import { useDeletePkiAlert } from "@app/hooks/api";import { usePopUp } from "@app/hooks/usePopUp";@@ -33,17 +41,16 @@ export const PkiAlertsSection = () => {};return (- <div className="mb-6 rounded-lg border border-border-control bg-surface-base p-4">- <div className="mb-4 flex items-center justify-between">- <div className="flex items-center gap-x-2">- <p className="text-xl font-medium text-foreground">Alerts</p>- <span className="rounded bg-surface-active px-2 py-0.5 text-xs tracking-wide text-foreground-secondary uppercase">- Legacy- </span>- </div>- <p className="text-xs text-label-secondary">Create new alerts inside an Application.</p>- </div>- <PkiAlertsTable handlePopUpOpen={handlePopUpOpen} />+ <Card>+ <CardHeader>+ <CardTitle>+ Alerts <Badge variant="neutral">Legacy</Badge>+ </CardTitle>+ <CardDescription>Create new alerts inside an Application.</CardDescription>+ </CardHeader>+ <CardContent>+ <PkiAlertsTable handlePopUpOpen={handlePopUpOpen} />+ </CardContent><PkiAlertModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} /><ConfirmationAlertDialogisOpen={popUp.deletePkiAlert.isOpen}@@ -57,6 +64,6 @@ export const PkiAlertsSection = () => {onRemoveAlertSubmit((popUp?.deletePkiAlert?.data as { alertId: string })?.alertId)}/>- </div>+ </Card>);};diff --git a/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionModal.tsx b/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionModal.tsxindex 652106c071..9dd139fe8b 100644--- a/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionModal.tsx+++ b/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionModal.tsx@@ -1,17 +1,33 @@-import { useEffect } from "react";+import { useEffect, useId } from "react";import { Controller, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import { useNavigate } from "@tanstack/react-router";import { z } from "zod";import { createNotification } from "@app/components/notifications";-import { Button, FormControl, Input, Modal, ModalContent } from "@app/components/v2";+import {+ Button,+ Dialog,+ DialogBody,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ DiscardChangesAlertDialog,+ Field,+ FieldError,+ FieldLabel,+ Input+} from "@app/components/v3";import { useOrganization, useProject } from "@app/context";import {useCreatePkiCollection,useGetPkiCollectionById,useUpdatePkiCollection} from "@app/hooks/api";+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";import { UsePopUpState } from "@app/hooks/usePopUp";const schema = z.object({@@ -22,14 +38,16 @@ const schema = z.object({export type FormData = z.infer<typeof schema>;type Props = {+ onComplete?: (collection: { id: string; name: string }) => void | Promise<void>;popUp: UsePopUpState<["pkiCollection"]>;handlePopUpToggle: (popUpName: keyof UsePopUpState<["pkiCollection"]>, state?: boolean) => void;};-export const PkiCollectionModal = ({ popUp, handlePopUpToggle }: Props) => {+export const PkiCollectionModal = ({ popUp, handlePopUpToggle, onComplete }: Props) => {const navigate = useNavigate();const { currentOrg } = useOrganization();const { currentProject } = useProject();+ const formId = useId();const projectId = currentProject?.id || "";const { data: pkiCollection } = useGetPkiCollectionById(@@ -43,7 +61,7 @@ export const PkiCollectionModal = ({ popUp, handlePopUpToggle }: Props) => {control,handleSubmit,reset,- formState: { isSubmitting }+ formState: { isSubmitting, isDirty }} = useForm<FormData>({resolver: zodResolver(schema)});@@ -60,7 +78,7 @@ export const PkiCollectionModal = ({ popUp, handlePopUpToggle }: Props) => {description: ""});}- }, [pkiCollection]);+ }, [pkiCollection, popUp.pkiCollection.isOpen, reset]);const onFormSubmit = async ({ name, description }: FormData) => {if (!projectId) return;@@ -80,13 +98,16 @@ export const PkiCollectionModal = ({ popUp, handlePopUpToggle }: Props) => {description});- navigate({- to: "/organizations/$orgId/cert-manager/pki-collections/$collectionId",- params: {- orgId: currentOrg.id,- collectionId- }- });+ if (onComplete) {+ await onComplete({ id: collectionId, name });+ } else+ navigate({+ to: "/organizations/$orgId/cert-manager/pki-collections/$collectionId",+ params: {+ orgId: currentOrg.id,+ collectionId+ }+ });}handlePopUpToggle("pkiCollection", false);@@ -99,69 +120,92 @@ export const PkiCollectionModal = ({ popUp, handlePopUpToggle }: Props) => {});};- return (- <Modal- isOpen={popUp?.pkiCollection?.isOpen}- onOpenChange={(isOpen) => {- handlePopUpToggle("pkiCollection", isOpen);+ const { requestDiscard, confirmDiscard, isDiscardDialogOpen, setIsDiscardDialogOpen } =+ useDiscardChangesGuard({+ isDirty,+ onDiscard: () => {reset();- }}- >- <ModalContent title={`${pkiCollection ? "Edit" : "Create"} Certificate Collection`}>- <form onSubmit={handleSubmit(onFormSubmit)}>- <Controller- control={control}- defaultValue=""- name="name"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Name"- isError={Boolean(error)}- errorText={error?.message}- isRequired- >- <Input- {...field}- placeholder="My Certificate Collection"- autoComplete="off"- name="pki-collection-name"+ handlePopUpToggle("pkiCollection", false);+ }+ });++ return (+ <>+ <Dialog+ open={popUp?.pkiCollection?.isOpen}+ onOpenChange={(isOpen) => {+ if (!isOpen) requestDiscard();+ }}+ >+ <DialogContent isPending={isSubmitting}>+ <DialogHeader>+ <DialogTitle>{`${pkiCollection ? "Edit" : "Create"} Certificate Collection`}</DialogTitle>+ <DialogDescription>Configure the certificate collection.</DialogDescription>+ </DialogHeader>+ <form+ onSubmit={handleSubmit(onFormSubmit)}+ className="flex min-h-0 flex-1 flex-col gap-6"+ >+ <DialogBody className="flex flex-col gap-4">+ <fieldset disabled={isSubmitting} className="flex min-w-0 flex-col gap-4">+ <Controller+ control={control}+ defaultValue=""+ name="name"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-name`}>+ Name <span className="text-danger">*</span>+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-name`}+ {...field}+ placeholder="My Certificate Collection"+ autoComplete="off"+ name="pki-collection-name"+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}/>- </FormControl>- )}- />- <Controller- control={control}- defaultValue=""- name="description"- render={({ field, fieldState: { error } }) => (- <FormControl label="Description" isError={Boolean(error)} errorText={error?.message}>- <Input- {...field}- placeholder="A collection to house certificates for ACME device"+ <Controller+ control={control}+ defaultValue=""+ name="description"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-description`}>Description</FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-description`}+ {...field}+ placeholder="A collection to house certificates for ACME device"+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}/>- </FormControl>- )}- />- <div className="flex items-center">- <Button- className="mr-4"- size="sm"- type="submit"- isLoading={isSubmitting}- isDisabled={isSubmitting}- >- {pkiCollection ? "Update" : "Create"}- </Button>- <Button- colorSchema="secondary"- variant="plain"- onClick={() => handlePopUpToggle("pkiCollection", false)}- >- Cancel- </Button>- </div>- </form>- </ModalContent>- </Modal>+ </fieldset>+ </DialogBody>+ <DialogFooter>+ <DialogClose asChild>+ <Button variant="ghost">Cancel</Button>+ </DialogClose>+ <Button variant="project" type="submit" isPending={isSubmitting}>+ {pkiCollection ? "Update" : "Create"}+ </Button>+ </DialogFooter>+ </form>+ </DialogContent>+ </Dialog>+ <DiscardChangesAlertDialog+ open={isDiscardDialogOpen}+ onOpenChange={setIsDiscardDialogOpen}+ onDiscard={confirmDiscard}+ title="Discard Changes?"+ description="Your unsaved changes will be lost."+ />+ </>);};diff --git a/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionSection.tsx b/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionSection.tsxindex 47c4918fe8..e6a9d77963 100644--- a/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionSection.tsx+++ b/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionSection.tsx@@ -3,8 +3,15 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";-import { Button } from "@app/components/v2";-import { ConfirmationAlertDialog } from "@app/components/v3";+import {+ Button,+ Card,+ CardAction,+ CardContent,+ CardHeader,+ CardTitle,+ ConfirmationAlertDialog+} from "@app/components/v3";import { ProjectPermissionActions, ProjectPermissionSub, useProject } from "@app/context";import { useDeletePkiCollection } from "@app/hooks/api";import { usePopUp } from "@app/hooks/usePopUp";@@ -38,27 +45,31 @@ export const PkiCollectionSection = () => {};return (- <div className="mb-6 rounded-lg border border-border-control bg-surface-base p-4">- <div className="mb-4 flex justify-between">- <p className="text-xl font-medium text-foreground">Certificate Collections</p>- <ProjectPermissionCan- I={ProjectPermissionActions.Create}- a={ProjectPermissionSub.PkiCollections}- >- {(isAllowed) => (- <Button- colorSchema="primary"- type="submit"- leftIcon={<FontAwesomeIcon icon={faPlus} />}- onClick={() => handlePopUpOpen("pkiCollection")}- isDisabled={!isAllowed}- >- Create- </Button>- )}- </ProjectPermissionCan>- </div>- <PkiCollectionTable handlePopUpOpen={handlePopUpOpen} />+ <Card>+ <CardHeader>+ <CardTitle>Certificate Collections</CardTitle>+ <CardAction>+ <ProjectPermissionCan+ I={ProjectPermissionActions.Create}+ a={ProjectPermissionSub.PkiCollections}+ >+ {(isAllowed) => (+ <Button+ type="submit"+ onClick={() => handlePopUpOpen("pkiCollection")}+ isDisabled={!isAllowed}+ variant="project"+ >+ <FontAwesomeIcon icon={faPlus} />+ Create+ </Button>+ )}+ </ProjectPermissionCan>+ </CardAction>+ </CardHeader>+ <CardContent>+ <PkiCollectionTable handlePopUpOpen={handlePopUpOpen} />+ </CardContent><PkiCollectionModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} /><ConfirmationAlertDialogisOpen={popUp.deletePkiCollection.isOpen}@@ -74,6 +85,6 @@ export const PkiCollectionSection = () => {)}/>- </div>+ </Card>);};diff --git a/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionTable.tsx b/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionTable.tsxindex ad4054d81f..98bd978cbf 100644--- a/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionTable.tsx+++ b/frontend/src/pages/cert-manager/AlertingPage/components/PkiCollectionTable.tsx@@ -1,7 +1,6 @@-import { faBoxesStacked, faEllipsis } from "@fortawesome/free-solid-svg-icons";+import { faEllipsis } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { useNavigate } from "@tanstack/react-router";-import { twMerge } from "tailwind-merge";import { ProjectPermissionCan } from "@app/components/permissions";import {@@ -9,16 +8,18 @@ import {DropdownMenuContent,DropdownMenuItem,DropdownMenuTrigger,- EmptyState,+ Empty,+ EmptyHeader,+ EmptyTitle,+ IconButton,Table,- TableContainer,- TableSkeleton,- TBody,- Td,- Th,- THead,- Tr-} from "@app/components/v2";+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+ TableSkeletonRows+} from "@app/components/v3";import {ProjectPermissionActions,ProjectPermissionSub,@@ -45,102 +46,101 @@ export const PkiCollectionTable = ({ handlePopUpOpen }: Props) => {projectId});+ if (!isPending && !data?.collections?.length) {+ return (+ <Empty className="border">+ <EmptyHeader>+ <EmptyTitle>No certificate collections have been created</EmptyTitle>+ </EmptyHeader>+ </Empty>+ );+ }+return (<div>- <TableContainer>- <Table>- <THead>- <Tr>- <Th>Name</Th>- <Th>Description</Th>- <Th className="w-5" />- </Tr>- </THead>- <TBody>- {isPending && <TableSkeleton columns={3} innerKey="pki-collections" />}- {!isPending &&- data?.collections.map((pkiCollection) => {- return (- <Tr- className="h-10 cursor-pointer transition-colors duration-100 hover:bg-surface-hover"- key={`pki-collection-${pkiCollection.id}`}- onClick={() =>- navigate({- to: "/organizations/$orgId/cert-manager/pki-collections/$collectionId",- params: {- orgId: currentOrg.id,- collectionId: pkiCollection.id- }- })- }- >- <Td>{pkiCollection.name}</Td>- <Td>{pkiCollection.description ? pkiCollection.description : "-"}</Td>- <Td>- <DropdownMenu>- <DropdownMenuTrigger asChild className="rounded-lg">- <div className="hover:text-project data-[state=open]:text-project">- <FontAwesomeIcon size="sm" icon={faEllipsis} />- </div>- </DropdownMenuTrigger>- <DropdownMenuContent align="start" className="p-1">- <ProjectPermissionCan- I={ProjectPermissionActions.Edit}- a={ProjectPermissionSub.PkiCollections}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("pkiCollection", {- collectionId: pkiCollection.id- });- }}- disabled={!isAllowed}- >- Edit Collection- </DropdownMenuItem>- )}- </ProjectPermissionCan>- <ProjectPermissionCan- I={ProjectPermissionActions.Delete}- a={ProjectPermissionSub.PkiCollections}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- isAllowed- ? "hover:bg-danger! hover:text-white!"- : "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("deletePkiCollection", {- collectionId: pkiCollection.id,- name: pkiCollection.name- });- }}- disabled={!isAllowed}- >- Delete Collection- </DropdownMenuItem>- )}- </ProjectPermissionCan>- </DropdownMenuContent>- </DropdownMenu>- </Td>- </Tr>- );- })}- </TBody>- </Table>- {!isPending && !data?.collections?.length && (- <EmptyState title="No certificate collections have been created" icon={faBoxesStacked} />- )}- </TableContainer>+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead>Name</TableHead>+ <TableHead>Description</TableHead>+ <TableHead className="w-5" />+ </TableRow>+ </TableHeader>+ <TableBody>+ {isPending && <TableSkeletonRows columns={3} />}+ {!isPending &&+ data?.collections.map((pkiCollection) => {+ return (+ <TableRow+ key={`pki-collection-${pkiCollection.id}`}+ onClick={() =>+ navigate({+ to: "/organizations/$orgId/cert-manager/pki-collections/$collectionId",+ params: {+ orgId: currentOrg.id,+ collectionId: pkiCollection.id+ }+ })+ }+ >+ <TableCell>{pkiCollection.name}</TableCell>+ <TableCell>+ {pkiCollection.description ? pkiCollection.description : "-"}+ </TableCell>+ <TableCell>+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <IconButton variant="ghost" size="xs" aria-label="More options">+ <FontAwesomeIcon icon={faEllipsis} />+ </IconButton>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start">+ <ProjectPermissionCan+ I={ProjectPermissionActions.Edit}+ a={ProjectPermissionSub.PkiCollections}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("pkiCollection", {+ collectionId: pkiCollection.id+ });+ }}+ isDisabled={!isAllowed}+ >+ Edit Collection+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ <ProjectPermissionCan+ I={ProjectPermissionActions.Delete}+ a={ProjectPermissionSub.PkiCollections}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("deletePkiCollection", {+ collectionId: pkiCollection.id,+ name: pkiCollection.name+ });+ }}+ isDisabled={!isAllowed}+ variant="danger"+ >+ Delete Collection+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ </DropdownMenuContent>+ </DropdownMenu>+ </TableCell>+ </TableRow>+ );+ })}+ </TableBody>+ </Table></div>);};diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateModal.tsxindex a5a1907346..903b62eddb 100644--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateModal.tsx+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateModal.tsx@@ -1,7 +1,5 @@-import { useEffect, useState } from "react";+import { useEffect, useRef, useState } from "react";import { Controller, useForm } from "react-hook-form";-import { faQuestionCircle } from "@fortawesome/free-regular-svg-icons";-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";@@ -13,16 +11,33 @@ import {AccordionTrigger,Button,Checkbox,- FormControl,- FormLabel,+ Combobox,+ DiscardChangesAlertDialog,+ Field,+ FieldFeedback,+ FieldGroup,+ FieldLabel,+ FieldLegend,+ FieldSet,Input,- Modal,- ModalContent,Select,+ SelectContent,SelectItem,- Tooltip-} from "@app/components/v2";-import { useProject } from "@app/context";+ SelectTrigger,+ SelectValue,+ Sheet,+ SheetContent,+ SheetDescription,+ SheetFooter,+ SheetHeader,+ SheetTitle+} from "@app/components/v3";+import {+ ProjectPermissionActions,+ ProjectPermissionSub,+ useProject,+ useProjectPermission+} from "@app/context";import {CaStatus,useCreateCertificate,@@ -39,8 +54,11 @@ import {KEY_USAGES_OPTIONS} from "@app/hooks/api/certificates/constants";import { CertKeyUsage } from "@app/hooks/api/certificates/enums";-import { UsePopUpState } from "@app/hooks/usePopUp";+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";+import { usePopUp, UsePopUpState } from "@app/hooks/usePopUp";+import { useCaCreation } from "@app/pages/cert-manager/components/useCaCreation";+import { PkiCollectionModal } from "../../AlertingPage/components/PkiCollectionModal";import { CertificateContent } from "./CertificateContent";const schema = z.object({@@ -85,17 +103,21 @@ const CERT_TEMPLATE_NONE_VALUE = "none";export const CertificateModal = ({ popUp, handlePopUpToggle, preselectedTemplate }: Props) => {const [certificateDetails, setCertificateDetails] = useState<TCertificateDetails | null>(null);+ const initialValuesRef = useRef<FormData | null>(null);+ const hydratedTemplateId = useRef<string | null>(null);const { currentProject } = useProject();+ const { permission } = useProjectPermission();+ const collectionPopup = usePopUp(["pkiCollection"] as const);const { data: cert } = useGetCert((popUp?.certificate?.data as { serialNumber: string })?.serialNumber || "");- const { data: cas } = useListWorkspaceCas({+ const { data: cas, refetch: refetchCas } = useListWorkspaceCas({projectId: currentProject.id,status: CaStatus.ACTIVE});- const { data } = useListWorkspacePkiCollections({+ const { data, refetch: refetchCollections } = useListWorkspacePkiCollections({projectId: currentProject?.id || ""});@@ -109,7 +131,9 @@ export const CertificateModal = ({ popUp, handlePopUpToggle, preselectedTemplatecontrol,handleSubmit,reset,- formState: { isSubmitting },+ resetField,+ getFieldState,+ formState: { isDirty, isSubmitting, dirtyFields },setValue,watch} = useForm<FormData>({@@ -123,7 +147,31 @@ export const CertificateModal = ({ popUp, handlePopUpToggle, preselectedTemplate}});+ const closeSheet = () => {+ handlePopUpToggle("certificate", false);+ reset();+ setCertificateDetails(null);+ };+ const { confirmDiscard, isDiscardDialogOpen, requestDiscard, setIsDiscardDialogOpen } =+ useDiscardChangesGuard({+ isDirty: !cert && !certificateDetails && isDirty,+ onDiscard: closeSheet+ });+const selectedCertTemplateId = watch("certificateTemplateId");+ const { creation: caCreation, caCreationModals } = useCaCreation<NonNullable<typeof cas>[number]>(+ async (ca) => {+ const result = await refetchCas();+ if (!result.data?.some((option) => option.id === ca.id)) {+ createNotification({+ type: "error",+ text: "The certificate authority was created, but is not available for this certificate request yet."+ });+ return;+ }+ setValue("caId", ca.id, { shouldDirty: true, shouldValidate: true });+ }+ );const hasCertTemplateSelected =selectedCertTemplateId !== "" && selectedCertTemplateId !== CERT_TEMPLATE_NONE_VALUE;@@ -147,8 +195,8 @@ export const CertificateModal = ({ popUp, handlePopUpToggle, preselectedTemplate} else if (popUp?.certificate?.isOpen) {const templateId = preselectedTemplate?.id || CERT_TEMPLATE_NONE_VALUE;- reset({- caId: "",+ const initialValues: FormData = {+ caId: cas?.[0]?.id ?? "",commonName: "",subjectAltNames: "",ttl: "",@@ -158,23 +206,59 @@ export const CertificateModal = ({ popUp, handlePopUpToggle, preselectedTemplate[CertKeyUsage.KEY_ENCIPHERMENT]: true},extendedKeyUsages: {}- });+ };+ initialValuesRef.current = initialValues;+ hydratedTemplateId.current = null;+ reset(initialValues);}- }, [cert, preselectedTemplate, popUp?.certificate?.isOpen]);+ }, [cert, preselectedTemplate?.id, popUp?.certificate?.isOpen]);useEffect(() => {- if (!cert && selectedCertTemplate) {- setValue("ttl", selectedCertTemplate.ttl);- setValue(- "keyUsages",- Object.fromEntries(selectedCertTemplate.keyUsages.map((name) => [name, true]))- );- setValue(- "extendedKeyUsages",- Object.fromEntries(selectedCertTemplate.extendedKeyUsages.map((name) => [name, true]))+ if (!hasCertTemplateSelected) {+ hydratedTemplateId.current = null;+ return;+ }+ if (+ cert ||+ !popUp.certificate.isOpen ||+ !selectedCertTemplate ||+ selectedCertTemplate.id !== selectedCertTemplateId ||+ hydratedTemplateId.current === selectedCertTemplateId+ )+ return;++ const templateValues = {+ ttl: selectedCertTemplate.ttl,+ keyUsages: Object.fromEntries(selectedCertTemplate.keyUsages.map((name) => [name, true])),+ extendedKeyUsages: Object.fromEntries(+ selectedCertTemplate.extendedKeyUsages.map((name) => [name, true])+ )+ };+ if (+ initialValuesRef.current &&+ initialValuesRef.current.certificateTemplateId === selectedCertTemplateId &&+ hydratedTemplateId.current === null+ ) {+ reset(+ { ...initialValuesRef.current, ...templateValues },+ {+ keepDirtyValues: Object.keys(dirtyFields).length > 0+ });+ } else {+ setValue("ttl", templateValues.ttl);+ setValue("keyUsages", templateValues.keyUsages);+ setValue("extendedKeyUsages", templateValues.extendedKeyUsages);}- }, [selectedCertTemplate, cert]);+ hydratedTemplateId.current = selectedCertTemplateId as string;+ }, [+ selectedCertTemplate,+ selectedCertTemplateId,+ hasCertTemplateSelected,+ cert,+ popUp.certificate.isOpen,+ dirtyFields+ ]);const onFormSubmit = async ({caId,@@ -222,300 +306,391 @@ export const CertificateModal = ({ popUp, handlePopUpToggle, preselectedTemplate};useEffect(() => {- if (cas?.length) {- setValue("caId", cas[0].id);+ if (cas?.length && !cert && popUp.certificate.isOpen && !getFieldState("caId").isDirty) {+ resetField("caId", { defaultValue: cas[0].id });}- }, [cas]);+ }, [cas, cert, popUp.certificate.isOpen]);return (- <Modal- isOpen={popUp?.certificate?.isOpen}- onOpenChange={(isOpen) => {- handlePopUpToggle("certificate", isOpen);- reset();- setCertificateDetails(null);- }}- >- <ModalContent title={`${cert ? "View" : "Request"} Certificate`}>- {!certificateDetails ? (- <form onSubmit={handleSubmit(onFormSubmit)}>- <Controller- control={control}- name="certificateTemplateId"- defaultValue=""- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label={- <div>- <FormLabel- isRequired- label="Certificate Template"- icon={- <Tooltip- className="text-center"- content={- <span>- When a template is selected, the details provided are validated- against the template policies.- </span>- }+ <>+ <Sheet+ open={popUp?.certificate?.isOpen}+ onOpenChange={(isOpen) => {+ if (isSubmitting) return;+ if (!isOpen) {+ requestDiscard();+ return;+ }+ handlePopUpToggle("certificate", true);+ }}+ >+ <SheetContent size="form" isPending={isSubmitting}>+ <SheetHeader>+ <SheetTitle>{cert ? "View" : "Request"} Certificate</SheetTitle>+ <SheetDescription>+ {certificateDetails+ ? "Copy or download the issued certificate and private key."+ : "Certificate subject, lifetime, and key usage details."}+ </SheetDescription>+ </SheetHeader>+ {!certificateDetails ? (+ <form+ className="flex min-h-0 flex-1 flex-col"+ onSubmit={(event) => {+ if (isSubmitting || cert) {+ event.preventDefault();+ return;+ }+ handleSubmit(onFormSubmit)(event);+ }}+ >+ <div className="min-h-0 thin-scrollbar flex-1 overflow-y-auto p-4">+ <FieldGroup>+ <Controller+ control={control}+ name="certificateTemplateId"+ defaultValue=""+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="certificate-template">Certificate Template</FieldLabel>+ <Select+ name={field.name}+ value={field.value}+ onValueChange={field.onChange}+ disabled={Boolean(cert) || Boolean(preselectedTemplate) || isSubmitting}+ >+ <SelectTrigger+ id="certificate-template"+ ref={field.ref}+ onBlur={field.onBlur}+ isError={Boolean(error)}+ aria-required+ aria-describedby="certificate-template-feedback">- <FontAwesomeIcon icon={faQuestionCircle} size="sm" />- </Tooltip>- }+ <SelectValue placeholder="Select a template" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value={CERT_TEMPLATE_NONE_VALUE} key="cert-template-none">+ None+ </SelectItem>+ {preselectedTemplate &&+ !templatesData?.certificateTemplates?.find(+ (t) => t.id === preselectedTemplate.id+ ) && (+ <SelectItem+ value={preselectedTemplate.id}+ key={`cert-template-preselected-${preselectedTemplate.id}`}+ >+ {preselectedTemplate.name}+ </SelectItem>+ )}+ {(templatesData?.certificateTemplates || []).map(({ id, name }) => (+ <SelectItem value={id} key={`cert-template-${id}`}>+ {name}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <FieldFeedback+ id="certificate-template-feedback"+ error={error?.message}+ description="When a template is selected, the details provided are validated against the template policies."+ />+ </Field>+ )}+ />+ {(!selectedCertTemplateId ||+ selectedCertTemplateId === CERT_TEMPLATE_NONE_VALUE ||+ cert) && (+ <>+ <Controller+ control={control}+ name="caId"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="certificate-ca">Issuing CA</FieldLabel>+ <Combobox+ ref={field.ref}+ name={field.name}+ id="certificate-ca"+ onBlur={field.onBlur}+ value={cas?.find((ca) => ca.id === field.value) ?? null}+ onValueChange={(ca) => field.onChange(ca.id)}+ options={cas ?? []}+ getOptionValue={(ca) => ca.id}+ getOptionLabel={(ca) => `${caTypeToNameMap[ca.type]}: ${ca.dn}`}+ isClearable={false}+ isDisabled={Boolean(cert) || isSubmitting}+ isError={Boolean(error)}+ aria-required+ aria-describedby="certificate-ca-feedback"+ placeholder="Select a certificate authority"+ creation={!cert ? caCreation : undefined}+ />+ <FieldFeedback id="certificate-ca-feedback" error={error?.message} />+ </Field>+ )}/>- </div>- }- errorText={error?.message}- isError={Boolean(error)}- isRequired- >- <Select- value={field.value}- onValueChange={(e) => onChange(e)}- className="w-full"- isDisabled={Boolean(cert) || Boolean(preselectedTemplate)}- >- <SelectItem value={CERT_TEMPLATE_NONE_VALUE} key="cert-template-none">- None- </SelectItem>- {preselectedTemplate &&- !templatesData?.certificateTemplates?.find(- (t) => t.id === preselectedTemplate.id- ) && (- <SelectItem- value={preselectedTemplate.id}- key={`cert-template-preselected-${preselectedTemplate.id}`}- >- {preselectedTemplate.name}- </SelectItem>- )}- {(templatesData?.certificateTemplates || []).map(({ id, name }) => (- <SelectItem value={id} key={`cert-template-${id}`}>- {name}- </SelectItem>- ))}- </Select>- </FormControl>- )}- />- {(!selectedCertTemplateId ||- selectedCertTemplateId === CERT_TEMPLATE_NONE_VALUE ||- cert) && (- <>- <Controller- control={control}- name="caId"- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label="Issuing CA"- errorText={error?.message}- isError={Boolean(error)}- className="mt-4"- isRequired- >- <Select- defaultValue={field.value}- {...field}- onValueChange={(e) => onChange(e)}- className="w-full"- isDisabled={Boolean(cert)}- >- {(cas || []).map(({ id, type, dn }) => (- <SelectItem value={id} key={`ca-${id}`}>- {`${caTypeToNameMap[type]}: ${dn}`}- </SelectItem>- ))}- </Select>- </FormControl>- )}- />- <Controller- control={control}- name="collectionId"- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label="Certificate Collection (Optional)"- errorText={error?.message}- isError={Boolean(error)}- className="mt-4"- >- <Select- defaultValue={field.value}- {...field}- onValueChange={(e) => onChange(e)}- className="w-full"- isDisabled={Boolean(cert)}- >- {(data?.collections || []).map(({ id, name }) => (- <SelectItem value={id} key={`pki-collection-${id}`}>- {name}- </SelectItem>- ))}- </Select>- </FormControl>+ <Controller+ control={control}+ name="collectionId"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="certificate-collection">+ Certificate Collection (Optional)+ </FieldLabel>+ <Combobox+ ref={field.ref}+ name={field.name}+ id="certificate-collection"+ onBlur={field.onBlur}+ value={+ data?.collections.find(+ (collection) => collection.id === field.value+ ) ?? null+ }+ onValueChange={(collection) => field.onChange(collection.id)}+ options={data?.collections ?? []}+ getOptionValue={(collection) => collection.id}+ getOptionLabel={(collection) => collection.name}+ isClearable={false}+ isDisabled={Boolean(cert) || isSubmitting}+ isError={Boolean(error)}+ aria-describedby="certificate-collection-feedback"+ placeholder="Select a certificate collection"+ creation={+ !cert &&+ permission.can(+ ProjectPermissionActions.Create,+ ProjectPermissionSub.PkiCollections+ )+ ? {+ mode: "action",+ emptyLabel: "Create New Collection",+ formatLabel: () => "Create New Collection",+ onAction: () =>+ collectionPopup.handlePopUpOpen("pkiCollection")+ }+ : undefined+ }+ />+ <FieldFeedback+ id="certificate-collection-feedback"+ error={error?.message}+ />+ </Field>+ )}+ />+ </>)}- />- </>- )}- <Controller- control={control}- defaultValue=""- name="commonName"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Common Name (CN)"- isError={Boolean(error)}- errorText={error?.message}- isRequired- >- <Input {...field} placeholder="service.acme.com" isDisabled={Boolean(cert)} />- </FormControl>- )}- />- <Controller- control={control}- defaultValue=""- name="subjectAltNames"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Alternative Names (SANs)"- isError={Boolean(error)}- errorText={error?.message}- >- <Input- {...field}- placeholder="app1.acme.com, app2.acme.com, ..."- isDisabled={Boolean(cert)}- />- </FormControl>- )}- />- <Controller- control={control}- name="ttl"- render={({ field, fieldState: { error } }) => (- <FormControl- label="TTL"- isError={Boolean(error)}- errorText={error?.message}- isRequired- >- <Input- {...field}- placeholder="2 days, 1d, 2h, 1y, ..."- isDisabled={Boolean(cert)}+ <Controller+ control={control}+ defaultValue=""+ name="commonName"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="certificate-common-name">Common Name (CN)</FieldLabel>+ <Input+ {...field}+ id="certificate-common-name"+ placeholder="service.acme.com"+ disabled={Boolean(cert) || isSubmitting}+ isError={Boolean(error)}+ aria-required+ aria-describedby="certificate-common-name-feedback"+ />+ <FieldFeedback+ id="certificate-common-name-feedback"+ error={error?.message}+ />+ </Field>+ )}/>- </FormControl>- )}- />- <Accordion type="single" collapsible className="w-full">- <AccordionItem value="key-usages" className="data-[state=open]:border-none">- <AccordionTrigger className="h-fit flex-none pl-1 text-sm">- <div className="order-1 ml-3">Key Usage</div>- </AccordionTrigger>- <AccordionContent><Controllercontrol={control}- name="keyUsages"- render={({ field: { onChange, value }, fieldState: { error } }) => {- return (- <FormControl- label="Key Usage"- errorText={error?.message}+ defaultValue=""+ name="subjectAltNames"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="certificate-alternative-names">+ Alternative Names (SANs)+ </FieldLabel>+ <Input+ {...field}+ id="certificate-alternative-names"+ placeholder="app1.acme.com, app2.acme.com, ..."+ disabled={Boolean(cert) || isSubmitting}isError={Boolean(error)}- >- <div className="mt-2 mb-7 grid grid-cols-2 gap-2">- {KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => {- return (- <Checkbox- id={optionValue}- key={optionValue}- isDisabled={Boolean(cert)}- isChecked={value[optionValue]}- onCheckedChange={(state) => {- onChange({- ...value,- [optionValue]: state- });- }}- >- {label}- </Checkbox>- );- })}- </div>- </FormControl>- );- }}+ aria-describedby="certificate-alternative-names-feedback"+ />+ <FieldFeedback+ id="certificate-alternative-names-feedback"+ error={error?.message}+ />+ </Field>+ )}/><Controllercontrol={control}- name="extendedKeyUsages"- render={({ field: { onChange, value }, fieldState: { error } }) => {- return (- <FormControl- label="Extended Key Usage"- errorText={error?.message}+ name="ttl"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor="certificate-ttl">TTL</FieldLabel>+ <Input+ {...field}+ id="certificate-ttl"+ placeholder="2 days, 1d, 2h, 1y, ..."+ disabled={Boolean(cert) || isSubmitting}isError={Boolean(error)}- >- <div className="mt-2 mb-7 grid grid-cols-2 gap-2">- {EXTENDED_KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => {- return (- <Checkbox- id={optionValue}- key={optionValue}- isDisabled={Boolean(cert)}- isChecked={value[optionValue]}- onCheckedChange={(state) => {- onChange({- ...value,- [optionValue]: state- });- }}- >- {label}- </Checkbox>- );- })}- </div>- </FormControl>- );- }}+ aria-required+ aria-describedby="certificate-ttl-feedback"+ />+ <FieldFeedback id="certificate-ttl-feedback" error={error?.message} />+ </Field>+ )}/>- </AccordionContent>- </AccordionItem>- </Accordion>- {!cert && (- <div className="mt-4 flex items-center">- <Button- className="mr-4"- size="sm"- type="submit"- isLoading={isSubmitting}- isDisabled={isSubmitting}- >- Create- </Button>- <Button- colorSchema="secondary"- variant="plain"- onClick={() => handlePopUpToggle("certificate", false)}- >- Cancel+ <Accordion type="single" collapsible variant="ghost">+ <AccordionItem value="key-usages">+ <AccordionTrigger>Key Usage</AccordionTrigger>+ <AccordionContent>+ <FieldGroup>+ <Controller+ control={control}+ name="keyUsages"+ render={({ field: { onChange, value }, fieldState: { error } }) => (+ <FieldSet aria-describedby="certificate-key-usages-feedback">+ <FieldLegend variant="label">Key Usage</FieldLegend>+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-2">+ {KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => (+ <Field+ orientation="horizontal"+ key={optionValue}+ data-disabled={Boolean(cert) || isSubmitting}+ >+ <Checkbox+ id={`certificate-key-usage-${optionValue}`}+ isDisabled={Boolean(cert) || isSubmitting}+ isChecked={Boolean(value[optionValue])}+ onCheckedChange={(state) => {+ onChange({+ ...value,+ [optionValue]: state === true+ });+ }}+ />+ <FieldLabel htmlFor={`certificate-key-usage-${optionValue}`}>+ {label}+ </FieldLabel>+ </Field>+ ))}+ </div>+ <FieldFeedback+ id="certificate-key-usages-feedback"+ error={error?.message}+ />+ </FieldSet>+ )}+ />+ <Controller+ control={control}+ name="extendedKeyUsages"+ render={({ field: { onChange, value }, fieldState: { error } }) => (+ <FieldSet aria-describedby="certificate-extended-key-usages-feedback">+ <FieldLegend variant="label">Extended Key Usage</FieldLegend>+ <div className="grid grid-cols-1 gap-3 sm:grid-cols-2">+ {EXTENDED_KEY_USAGES_OPTIONS.map(+ ({ label, value: optionValue }) => (+ <Field+ orientation="horizontal"+ key={optionValue}+ data-disabled={Boolean(cert) || isSubmitting}+ >+ <Checkbox+ id={`certificate-extended-key-usage-${optionValue}`}+ isDisabled={Boolean(cert) || isSubmitting}+ isChecked={Boolean(value[optionValue])}+ onCheckedChange={(state) => {+ onChange({+ ...value,+ [optionValue]: state === true+ });+ }}+ />+ <FieldLabel+ htmlFor={`certificate-extended-key-usage-${optionValue}`}+ >+ {label}+ </FieldLabel>+ </Field>+ )+ )}+ </div>+ <FieldFeedback+ id="certificate-extended-key-usages-feedback"+ error={error?.message}+ />+ </FieldSet>+ )}+ />+ </FieldGroup>+ </AccordionContent>+ </AccordionItem>+ </Accordion>+ </FieldGroup>+ </div>+ <SheetFooter className="justify-end border-t">+ <Button variant="ghost" onClick={requestDiscard} isDisabled={isSubmitting}>+ {cert ? "Close" : "Cancel"}</Button>+ {!cert && (+ <Button variant="project" type="submit" isPending={isSubmitting}>+ Create+ </Button>+ )}+ </SheetFooter>+ </form>+ ) : (+ <>+ <div className="min-h-0 thin-scrollbar flex-1 overflow-y-auto p-4">+ <CertificateContent+ serialNumber={certificateDetails.serialNumber}+ certificate={certificateDetails.certificate}+ certificateChain={certificateDetails.certificateChain}+ privateKey={certificateDetails.privateKey}+ /></div>- )}- </form>- ) : (- <CertificateContent- serialNumber={certificateDetails.serialNumber}- certificate={certificateDetails.certificate}- certificateChain={certificateDetails.certificateChain}- privateKey={certificateDetails.privateKey}- />- )}- </ModalContent>- </Modal>+ <SheetFooter className="justify-end border-t">+ <Button variant="ghost" onClick={requestDiscard} isDisabled={isSubmitting}>+ Close+ </Button>+ </SheetFooter>+ </>+ )}+ </SheetContent>+ </Sheet>+ {caCreationModals}+ <PkiCollectionModal+ popUp={collectionPopup.popUp}+ handlePopUpToggle={collectionPopup.handlePopUpToggle}+ onComplete={async (collection) => {+ const result = await refetchCollections();+ if (!result.data?.collections.some((option) => option.id === collection.id)) {+ createNotification({+ type: "error",+ text: "The collection was created, but the list could not be refreshed. Refresh the list to select it."+ });+ return;+ }+ setValue("collectionId", collection.id, { shouldDirty: true, shouldValidate: true });+ }}+ />+ <DiscardChangesAlertDialog+ open={isDiscardDialogOpen}+ onOpenChange={setIsDiscardDialogOpen}+ onDiscard={confirmDiscard}+ title="Discard Changes?"+ description="Your unsaved certificate request details will be lost."+ />+ </>);};diff --git a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRevocationModal.tsx b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRevocationModal.tsxindex cad32e26ab..30cb54a2af 100644--- a/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRevocationModal.tsx+++ b/frontend/src/pages/cert-manager/CertificatesPage/components/CertificateRevocationModal.tsx@@ -1,9 +1,28 @@+import { useId } from "react";import { Controller, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";import { createNotification } from "@app/components/notifications";-import { Button, FormControl, Modal, ModalContent, Select, SelectItem } from "@app/components/v2";+import {+ Button,+ Dialog,+ DialogBody,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+ Field,+ FieldError,+ FieldLabel,+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue+} from "@app/components/v3";import { useProject } from "@app/context";import { useRevokeCert } from "@app/hooks/api";import { crlReasons } from "@app/hooks/api/certificates/constants";@@ -35,6 +54,7 @@ type Props = {};export const CertificateRevocationModal = ({ popUp, handlePopUpToggle }: Props) => {+ const revocationReasonId = useId();const { currentProject } = useProject();const { mutateAsync: revokeCertificate } = useRevokeCert();@@ -67,56 +87,69 @@ export const CertificateRevocationModal = ({ popUp, handlePopUpToggle }: Props)};return (- <Modal- isOpen={popUp?.revokeCertificate?.isOpen}+ <Dialog+ open={popUp?.revokeCertificate?.isOpen}onOpenChange={(isOpen) => {handlePopUpToggle("revokeCertificate", isOpen);reset();}}>- <ModalContent title="Revoke Certificate">- <form onSubmit={handleSubmit(onFormSubmit)}>- <Controller- control={control}- name="revocationReason"- defaultValue={CrlReason.UNSPECIFIED}- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label="Revocation Reason"- errorText={error?.message}- isError={Boolean(error)}- >- <Select- defaultValue={field.value}- {...field}- onValueChange={(e) => onChange(e)}- className="w-full"- >- {crlReasons.map(({ label, value }) => (- <SelectItem value={String(value || "")} key={label}>- {label}- </SelectItem>- ))}- </Select>- </FormControl>- )}- />- <div className="flex items-center">- <Button- className="mr-4"- size="sm"- type="submit"- isLoading={isSubmitting}- isDisabled={isSubmitting}- >+ <DialogContent isPending={isSubmitting}>+ <DialogHeader>+ <DialogTitle>Revoke Certificate</DialogTitle>+ <DialogDescription>Mark this certificate as revoked.</DialogDescription>+ </DialogHeader>+ <form className="flex min-h-0 flex-1 flex-col gap-6" onSubmit={handleSubmit(onFormSubmit)}>+ <DialogBody>+ <fieldset disabled={isSubmitting} className="min-w-0">+ <Controller+ control={control}+ name="revocationReason"+ defaultValue={CrlReason.UNSPECIFIED}+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={revocationReasonId}>Revocation Reason</FieldLabel>+ <Select+ value={field.value}+ name={field.name}+ onValueChange={onChange}+ disabled={isSubmitting}+ >+ <SelectTrigger+ id={revocationReasonId}+ ref={field.ref}+ onBlur={field.onBlur}+ className="w-full"+ isError={Boolean(error)}+ >+ <SelectValue placeholder="Select a revocation reason" />+ </SelectTrigger>+ <SelectContent>+ {crlReasons.map(({ label, value }) => (+ <SelectItem value={String(value || "")} key={label}>+ {label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ </fieldset>+ </DialogBody>+ <DialogFooter>+ <DialogClose asChild>+ <Button type="button" variant="ghost">+ Cancel+ </Button>+ </DialogClose>+ <Button variant="danger" type="submit" isPending={isSubmitting}>Revoke</Button>- <Button colorSchema="secondary" variant="plain">- Cancel- </Button>- </div>+ </DialogFooter></form>- </ModalContent>- </Modal>+ </DialogContent>+ </Dialog>);};diff --git a/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/PkiCollectionDetailsByIDPage.tsx b/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/PkiCollectionDetailsByIDPage.tsxindex bfeeaa9b61..cf3a3b5a9c 100644--- a/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/PkiCollectionDetailsByIDPage.tsx+++ b/frontend/src/pages/cert-manager/PkiCollectionDetailsByIDPage/PkiCollectionDetailsByIDPage.tsx@@ -3,19 +3,18 @@ import { useTranslation } from "react-i18next";import { faChevronLeft } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { Link, useNavigate, useParams } from "@tanstack/react-router";-import { twMerge } from "tailwind-merge";import { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";import {Button,+ ConfirmationAlertDialog,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuTrigger,- Tooltip-} from "@app/components/v2";-import { ConfirmationAlertDialog, PageHeader } from "@app/components/v3";+ PageHeader+} from "@app/components/v3";import { ROUTE_PATHS } from "@app/const/routes";import {ProjectPermissionActions,@@ -70,7 +69,7 @@ export const PkiCollectionPage = () => {};return (- <div className="mx-auto flex flex-col justify-between bg-page text-foreground-inverse">+ <div className="mx-auto flex flex-col justify-between bg-page">{data && (<div className="mx-auto mb-6 flex w-full max-w-8xl flex-col"><PageHeader@@ -90,29 +89,22 @@ export const PkiCollectionPage = () => {description="Manage certificate collection"><DropdownMenu>- <DropdownMenuTrigger asChild className="rounded-lg">- <div className="hover:text-project data-[state=open]:text-project">- <Tooltip content="More options">- <Button variant="outline_bg">More</Button>- </Tooltip>- </div>+ <DropdownMenuTrigger asChild>+ <Button variant="outline">More</Button></DropdownMenuTrigger>- <DropdownMenuContent align="end" className="p-1">+ <DropdownMenuContent align="end"><ProjectPermissionCanI={ProjectPermissionActions.Edit}a={ProjectPermissionSub.PkiCollections}>{(isAllowed) => (<DropdownMenuItem- className={twMerge(- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"- )}onClick={() => {handlePopUpOpen("pkiCollection", {collectionId});}}- disabled={!isAllowed}+ isDisabled={!isAllowed}>Edit PKI Collection</DropdownMenuItem>@@ -124,18 +116,14 @@ export const PkiCollectionPage = () => {>{(isAllowed) => (<DropdownMenuItem- className={twMerge(- isAllowed- ? "hover:bg-danger! hover:text-white!"- : "pointer-events-none cursor-not-allowed opacity-50"- )}onClick={() =>handlePopUpOpen("deletePkiCollection", {collectionId: data.id,name: data.name})}- disabled={!isAllowed}+ isDisabled={!isAllowed}+ variant="danger">Delete PKI Collection</DropdownMenuItem>diff --git a/frontend/src/pages/cert-manager/PkiSubscriberDetailsByIDPage/PkiSubscriberDetailsByIDPage.tsx b/frontend/src/pages/cert-manager/PkiSubscriberDetailsByIDPage/PkiSubscriberDetailsByIDPage.tsxindex a69d2e4bf6..95ecf3e2a9 100644--- a/frontend/src/pages/cert-manager/PkiSubscriberDetailsByIDPage/PkiSubscriberDetailsByIDPage.tsx+++ b/frontend/src/pages/cert-manager/PkiSubscriberDetailsByIDPage/PkiSubscriberDetailsByIDPage.tsx@@ -3,19 +3,18 @@ import { useTranslation } from "react-i18next";import { faChevronLeft } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { Link, useNavigate, useParams } from "@tanstack/react-router";-import { twMerge } from "tailwind-merge";import { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";import {Button,+ ConfirmationAlertDialog,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuTrigger,- Tooltip-} from "@app/components/v2";-import { ConfirmationAlertDialog, PageHeader } from "@app/components/v3";+ PageHeader+} from "@app/components/v3";import { LegacyPkiResource } from "@app/const/legacyPkiDeprecation";import { ROUTE_PATHS } from "@app/const/routes";import {@@ -73,7 +72,7 @@ const Page = () => {};return (- <div className="mx-auto flex flex-col justify-between bg-page text-foreground-inverse">+ <div className="mx-auto flex flex-col justify-between bg-page">{data && (<div className="mx-auto mb-6 flex w-full max-w-8xl flex-col"><PageHeader@@ -93,31 +92,23 @@ const Page = () => {description="Manage PKI subscriber"><DropdownMenu>- <DropdownMenuTrigger asChild className="rounded-lg">- <div className="hover:text-project data-[state=open]:text-project">- <Tooltip content="More options">- <Button variant="outline_bg">More</Button>- </Tooltip>- </div>+ <DropdownMenuTrigger asChild>+ <Button variant="outline">More</Button></DropdownMenuTrigger>- <DropdownMenuContent align="end" className="p-1">+ <DropdownMenuContent align="end"><ProjectPermissionCanI={ProjectPermissionPkiSubscriberActions.Delete}a={ProjectPermissionSub.PkiSubscribers}>{(isAllowed) => (<DropdownMenuItem- className={twMerge(- isAllowed- ? "hover:bg-danger! hover:text-white!"- : "pointer-events-none cursor-not-allowed opacity-50"- )}onClick={() =>handlePopUpOpen("deletePkiSubscriber", {subscriberName: data.name})}- disabled={!isAllowed}+ isDisabled={!isAllowed}+ variant="danger">Delete PKI Subscriber</DropdownMenuItem>diff --git a/frontend/src/pages/cert-manager/PkiSubscriberDetailsByIDPage/components/PkiSubscriberDetailsSection.tsx b/frontend/src/pages/cert-manager/PkiSubscriberDetailsByIDPage/components/PkiSubscriberDetailsSection.tsxindex 1f4d18dbb4..0590233755 100644--- a/frontend/src/pages/cert-manager/PkiSubscriberDetailsByIDPage/components/PkiSubscriberDetailsSection.tsx+++ b/frontend/src/pages/cert-manager/PkiSubscriberDetailsByIDPage/components/PkiSubscriberDetailsSection.tsx@@ -7,12 +7,23 @@ import { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";import {Button,- GenericFieldLabel,+ Card,+ CardAction,+ CardContent,+ CardHeader,+ CardTitle,IconButton,- Modal,- ModalContent,- Tooltip-} from "@app/components/v2";+ Sheet,+ SheetClose,+ SheetContent,+ SheetDescription,+ SheetFooter,+ SheetHeader,+ SheetTitle,+ Tooltip,+ TooltipContent,+ TooltipTrigger+} from "@app/components/v3";import {ProjectPermissionPkiSubscriberActions,ProjectPermissionSub,@@ -103,53 +114,65 @@ export const PkiSubscriberDetailsSection = ({ subscriberName, handlePopUpOpen }:);return pkiSubscriber ? (- <div className="rounded-lg border border-border-control bg-surface-base p-4">- <div className="flex items-center justify-between border-b border-border-emphasis pb-4">- <h3 className="text-lg font-normal text-foreground">PKI Subscriber Details</h3>- <ProjectPermissionCan- I={ProjectPermissionPkiSubscriberActions.Edit}- a={ProjectPermissionSub.PkiSubscribers}- >- {(isAllowed) => {- return (- <Tooltip content="Edit PKI Subscriber">- <IconButton- isDisabled={!isAllowed}- ariaLabel="edit icon"- variant="plain"- className="group relative"- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("pkiSubscriber", {- subscriberName: pkiSubscriber.name- });- }}- >- <FontAwesomeIcon icon={faPencil} />- </IconButton>- </Tooltip>- );- }}- </ProjectPermissionCan>- </div>- <div className="pt-4">+ <Card>+ <CardHeader>+ <CardTitle>PKI Subscriber Details</CardTitle>+ <CardAction>+ <ProjectPermissionCan+ I={ProjectPermissionPkiSubscriberActions.Edit}+ a={ProjectPermissionSub.PkiSubscribers}+ >+ {(isAllowed) => {+ return (+ <Tooltip>+ <TooltipTrigger asChild>+ <span className="inline-flex">+ <IconButton+ isDisabled={!isAllowed}+ aria-label="edit icon"+ variant="ghost"+ className="group relative"+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("pkiSubscriber", {+ subscriberName: pkiSubscriber.name+ });+ }}+ >+ <FontAwesomeIcon icon={faPencil} />+ </IconButton>+ </span>+ </TooltipTrigger>+ <TooltipContent>Edit PKI Subscriber</TooltipContent>+ </Tooltip>+ );+ }}+ </ProjectPermissionCan>+ </CardAction>+ </CardHeader>+ <CardContent><div className="mb-4"><p className="text-sm font-medium text-label">PKI Subscriber ID</p><div className="group flex align-top"><p className="text-sm text-label">{pkiSubscriber.id}</p><div className="opacity-0 transition-opacity duration-300 group-hover:opacity-100">- <Tooltip content={copyTextId}>- <IconButton- ariaLabel="copy icon"- variant="plain"- className="group relative ml-2"- onClick={() => {- navigator.clipboard.writeText(pkiSubscriber.id);- setCopyTextId("Copied");- }}- >- <FontAwesomeIcon icon={isCopyingId ? faCheck : faCopy} />- </IconButton>+ <Tooltip>+ <TooltipTrigger asChild>+ <span className="inline-flex">+ <IconButton+ aria-label="copy icon"+ variant="ghost"+ className="group relative ml-2"+ onClick={() => {+ navigator.clipboard.writeText(pkiSubscriber.id);+ setCopyTextId("Copied");+ }}+ >+ <FontAwesomeIcon icon={isCopyingId ? faCheck : faCopy} />+ </IconButton>+ </span>+ </TooltipTrigger>+ <TooltipContent>{copyTextId}</TooltipContent></Tooltip></div></div>@@ -176,32 +199,35 @@ export const PkiSubscriberDetailsSection = ({ subscriberName, handlePopUpOpen }:)}{pkiSubscriber.lastOperationStatus === SubscriberOperationStatus.FAILED && (<div className="mb-4">- <GenericFieldLabel labelClassName="text-danger" label="Last Operation Status">- <p className="rounded-sm bg-surface-active p-2 text-xs break-words">- {pkiSubscriber.lastOperationMessage}- </p>- </GenericFieldLabel>+ <div>+ <p className="text-danger">Last Operation Status</p>+ <div className="text-sm text-foreground">+ <p className="rounded-sm bg-surface-active p-2 text-xs break-words">+ {pkiSubscriber.lastOperationMessage}+ </p>+ </div>+ </div></div>)}{canIssuePkiSubscriberCert && (<ButtonclassName="mt-2 w-full"- colorSchema="primary"type="button"- isLoading={isIssuingCert || isOrderingCert}+ isPending={isIssuingCert || isOrderingCert}onClick={() => {onIssuePkiSubscriberCert();}}+ variant="project">{pkiSubscriber?.supportsImmediateCertIssuance? "Issue Certificate": "Order Certificate"}</Button>)}- </div>+ </CardContent>- <Modal- isOpen={isModalOpen}+ <Sheet+ open={isModalOpen}onOpenChange={(isOpen) => {setIsModalOpen(isOpen);if (!isOpen) {@@ -209,18 +235,29 @@ export const PkiSubscriberDetailsSection = ({ subscriberName, handlePopUpOpen }:}}}>- <ModalContent title="Certificate Details">- {certificateDetails && (- <CertificateContent- serialNumber={certificateDetails.serialNumber}- certificate={certificateDetails.certificate}- certificateChain={certificateDetails.certificateChain}- privateKey={certificateDetails.privateKey}- />- )}- </ModalContent>- </Modal>- </div>+ <SheetContent size="form">+ <SheetHeader>+ <SheetTitle>Certificate Details</SheetTitle>+ <SheetDescription>View certificate details.</SheetDescription>+ </SheetHeader>+ <div className="min-h-0 flex-1 overflow-y-auto p-4">+ {certificateDetails && (+ <CertificateContent+ serialNumber={certificateDetails.serialNumber}+ certificate={certificateDetails.certificate}+ certificateChain={certificateDetails.certificateChain}+ privateKey={certificateDetails.privateKey}+ />+ )}+ </div>+ <SheetFooter className="justify-end border-t">+ <SheetClose asChild>+ <Button variant="ghost">Close</Button>+ </SheetClose>+ </SheetFooter>+ </SheetContent>+ </Sheet>+ </Card>) : (<div />);diff --git a/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscriberModal.tsx b/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscriberModal.tsxindex 929997f366..51aa0000fd 100644--- a/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscriberModal.tsx+++ b/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscriberModal.tsx@@ -1,4 +1,4 @@-import { useEffect, useState } from "react";+import { useEffect, useId, useState } from "react";import { Controller, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";@@ -11,17 +11,30 @@ import {AccordionTrigger,Button,Checkbox,- FormControl,+ Combobox,+ DiscardChangesAlertDialog,+ Field,+ FieldDescription,+ FieldError,+ FieldLabel,Input,- Modal,- ModalContent,Select,+ SelectContent,SelectItem,- Tab,- TabList,- TabPanel,- Tabs-} from "@app/components/v2";+ SelectTrigger,+ SelectValue,+ Sheet,+ SheetClose,+ SheetContent,+ SheetDescription,+ SheetFooter,+ SheetHeader,+ SheetTitle,+ Tabs,+ TabsContent,+ TabsList,+ TabsTrigger+} from "@app/components/v3";import { useProject } from "@app/context";import {CaType,@@ -38,8 +51,10 @@ import {KEY_USAGES_OPTIONS} from "@app/hooks/api/certificates/constants";import { CertExtendedKeyUsage, CertKeyUsage } from "@app/hooks/api/certificates/enums";+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";import { UsePopUpState } from "@app/hooks/usePopUp";import { convertTimeUnitValueToDays, TimeUnit } from "@app/lib/fn/date";+import { useCaCreation } from "@app/pages/cert-manager/components/useCaCreation";type Props = {popUp: UsePopUpState<["pkiSubscriber"]>;@@ -155,16 +170,19 @@ export type FormData = z.infer<typeof schema>;export const PkiSubscriberModal = ({ popUp, handlePopUpToggle }: Props) => {const { currentProject } = useProject();+ const formId = useId();const projectId = currentProject.id;const { data: subscribers } = useListWorkspacePkiSubscribers(projectId);const { data: cas } = useListCasByProjectId();const [tabValue, setTabValue] = useState<FormTab>(FormTab.Configuration);+ const subscriberName =+ (popUp?.pkiSubscriber?.data as { subscriberName?: string })?.subscriberName || "";const { data: pkiSubscriber } = useGetPkiSubscriber({- subscriberName:- (popUp?.pkiSubscriber?.data as { subscriberName: string })?.subscriberName || "",+ subscriberName,projectId});+ const isSubscriberReady = !subscriberName || pkiSubscriber?.name === subscriberName;const { mutateAsync: createMutateAsync } = useCreatePkiSubscriber();const { mutateAsync: updateMutateAsync } = useUpdatePkiSubscriber();@@ -173,9 +191,11 @@ export const PkiSubscriberModal = ({ popUp, handlePopUpToggle }: Props) => {control,handleSubmit,reset,+ resetField,+ getValues,setValue,watch,- formState: { isSubmitting }+ formState: { isSubmitting, isDirty }} = useForm<FormData>({resolver: zodResolver(schema),defaultValues: {@@ -203,6 +223,11 @@ export const PkiSubscriberModal = ({ popUp, handlePopUpToggle }: Props) => {});const selectedCaId = watch("caId");+ const { creation: caCreation, caCreationModals } = useCaCreation<NonNullable<typeof cas>[number]>(+ (ca) => {+ setValue("caId", ca.id, { shouldDirty: true, shouldValidate: true });+ }+ );const selectedCa = cas?.find((ca) => ca.id === selectedCaId);const selectedAutoRenewalState = watch("enableAutoRenewal");@@ -212,46 +237,37 @@ export const PkiSubscriberModal = ({ popUp, handlePopUpToggle }: Props) => {isAzureAdcsCa: true});- // Initialize form with ALL subscriber data including templateuseEffect(() => {- if (pkiSubscriber) {- // Set all values directly and immediately- setValue("name", pkiSubscriber.name);- setValue("caId", pkiSubscriber.caId || "");- setValue("commonName", pkiSubscriber.commonName);- setValue("subjectAlternativeNames", pkiSubscriber.subjectAlternativeNames.join(", "));- setValue("ttl", pkiSubscriber.ttl || "");- setValue(- "keyUsages",- Object.fromEntries((pkiSubscriber.keyUsages || []).map((name) => [name, true]))- );- setValue(- "extendedKeyUsages",- Object.fromEntries((pkiSubscriber.extendedKeyUsages || []).map((name) => [name, true]))- );- setValue("enableAutoRenewal", pkiSubscriber.enableAutoRenewal || false);- setValue("renewalBefore", pkiSubscriber.autoRenewalPeriodInDays || 7);- setValue("renewalUnit", TimeUnit.DAY);-- // Set Azure template immediately- setValue("azureTemplateType", pkiSubscriber.properties?.azureTemplateType || "");-- // Set all Additional Subject Fields immediately- setValue("organization", pkiSubscriber.properties?.organization || "");- setValue("organizationalUnit", pkiSubscriber.properties?.organizationalUnit || "");- setValue("country", pkiSubscriber.properties?.country || "");- setValue("state", pkiSubscriber.properties?.state || "");- setValue("locality", pkiSubscriber.properties?.locality || "");- setValue("emailAddress", pkiSubscriber.properties?.emailAddress || "");+ if (pkiSubscriber && popUp.pkiSubscriber.isOpen && isSubscriberReady) {+ reset({+ name: pkiSubscriber.name,+ caId: pkiSubscriber.caId || "",+ commonName: pkiSubscriber.commonName,+ subjectAlternativeNames: pkiSubscriber.subjectAlternativeNames.join(", "),+ ttl: pkiSubscriber.ttl || "",+ keyUsages: Object.fromEntries((pkiSubscriber.keyUsages || []).map((name) => [name, true])),+ extendedKeyUsages: Object.fromEntries(+ (pkiSubscriber.extendedKeyUsages || []).map((name) => [name, true])+ ),+ enableAutoRenewal: pkiSubscriber.enableAutoRenewal || false,+ renewalBefore: pkiSubscriber.autoRenewalPeriodInDays || 7,+ renewalUnit: TimeUnit.DAY,+ azureTemplateType: pkiSubscriber.properties?.azureTemplateType || "",+ organization: pkiSubscriber.properties?.organization || "",+ organizationalUnit: pkiSubscriber.properties?.organizationalUnit || "",+ country: pkiSubscriber.properties?.country || "",+ state: pkiSubscriber.properties?.state || "",+ locality: pkiSubscriber.properties?.locality || "",+ emailAddress: pkiSubscriber.properties?.emailAddress || ""+ });}- }, [pkiSubscriber, setValue]);+ }, [pkiSubscriber, popUp.pkiSubscriber.isOpen, reset, isSubscriberReady]);useEffect(() => {- if (cas?.length && !pkiSubscriber) {- // Only auto-select first CA when creating new subscriber, not when updating- setValue("caId", cas[0].id);+ if (cas?.length && !subscriberName && popUp.pkiSubscriber.isOpen && !getValues("caId")) {+ resetField("caId", { defaultValue: cas[0].id });}- }, [cas, setValue, pkiSubscriber]);+ }, [cas, subscriberName, popUp.pkiSubscriber.isOpen]);const onFormSubmit = async ({name,@@ -272,7 +288,7 @@ export const PkiSubscriberModal = ({ popUp, handlePopUpToggle }: Props) => {locality,emailAddress}: FormData) => {- if (!projectId) return;+ if (!projectId || !isSubscriberReady) return;if (!caId) {createNotification({@@ -387,436 +403,539 @@ export const PkiSubscriberModal = ({ popUp, handlePopUpToggle }: Props) => {});};- return (- <Modal- isOpen={popUp?.pkiSubscriber?.isOpen}- onOpenChange={(isOpen) => {+ const { requestDiscard, confirmDiscard, isDiscardDialogOpen, setIsDiscardDialogOpen } =+ useDiscardChangesGuard({+ isDirty,+ onDiscard: () => {reset();- handlePopUpToggle("pkiSubscriber", isOpen);- }}- >- <ModalContent title={`${pkiSubscriber ? "Update" : "Add"} PKI Subscriber`}>- <form key={pkiSubscriber?.id || "new"} onSubmit={handleSubmit(onFormSubmit)}>- <Tabs value={tabValue} onValueChange={(value) => setTabValue(value as FormTab)}>- <TabList>- <Tab value={FormTab.Configuration}>Configuration</Tab>- <Tab value={FormTab.Advanced}>Advanced</Tab>- </TabList>- <TabPanel value={FormTab.Configuration}>- {pkiSubscriber && (- <FormControl label="Subscriber ID">- <Input- value={pkiSubscriber.id}- isDisabled- className="bg-foreground-inverse/[0.07]"- />- </FormControl>- )}- <Controller- control={control}- name="name"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Subscriber Name"- isError={Boolean(error)}- errorText={error?.message}- isRequired- >- <Input- {...field}- placeholder="web-service"- autoComplete="off"- name="pki-subscriber-name"- />- </FormControl>- )}- />- <Controller- control={control}- name="caId"- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label="Issuing CA"- errorText={error?.message}- isError={Boolean(error)}- isRequired- >- <Select- value={field.value}- onValueChange={(e) => onChange(e)}- className="w-full"- >- {(cas || []).map(({ id, name, type, configuration }) => {- const displayName =- type === CaType.INTERNAL ? `${name} (${configuration.dn})` : name;+ handlePopUpToggle("pkiSubscriber", false);+ }+ });- return (- <SelectItem value={id} key={`ca-${id}`}>- {displayName}- </SelectItem>- );- })}- </Select>- </FormControl>- )}- />- {selectedCa?.type === CaType.AZURE_AD_CS && (- <Controller- control={control}- name="azureTemplateType"- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label="Certificate Template"- errorText={error?.message}- isError={Boolean(error)}- isRequired- >- <Select- value={field.value}- onValueChange={(e) => onChange(e)}- className="w-full"- >- {(azureTemplates?.templates || []).map(- (template: { id: string; name: string }) => (- <SelectItem value={template.id} key={template.id}>- {template.name}- </SelectItem>- )- )}- </Select>- </FormControl>+ return (+ <>+ <Sheet+ open={popUp?.pkiSubscriber?.isOpen}+ onOpenChange={(isOpen) => {+ if (!isOpen) requestDiscard();+ }}+ >+ <SheetContent size="form" isPending={isSubmitting}>+ <SheetHeader>+ <SheetTitle>{`${subscriberName ? "Update" : "Add"} PKI Subscriber`}</SheetTitle>+ <SheetDescription>Configure the subscriber certificate settings.</SheetDescription>+ </SheetHeader>+ <form+ key={pkiSubscriber?.id || "new"}+ onSubmit={handleSubmit(onFormSubmit)}+ className="flex min-h-0 flex-1 flex-col"+ >+ <fieldset+ disabled={isSubmitting || !isSubscriberReady}+ className="flex min-h-0 min-w-0 flex-1 flex-col gap-4 overflow-y-auto p-4"+ >+ <Tabs value={tabValue} onValueChange={(value) => setTabValue(value as FormTab)}>+ <TabsList>+ <TabsTrigger value={FormTab.Configuration}>Configuration</TabsTrigger>+ <TabsTrigger value={FormTab.Advanced}>Advanced</TabsTrigger>+ </TabsList>+ <TabsContent className="flex flex-col gap-4" value={FormTab.Configuration}>+ {pkiSubscriber && (+ <Field>+ <FieldLabel>Subscriber ID</FieldLabel>+ <Input value={pkiSubscriber.id} disabled />+ </Field>)}- />- )}- <Controller- control={control}- name="commonName"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Common Name"- isError={Boolean(error)}- errorText={error?.message}- isRequired- >- <Input {...field} placeholder="web.example.com" />- </FormControl>- )}- />- <Controller- control={control}- name="subjectAlternativeNames"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Subject Alternative Names (SANs)"- isError={Boolean(error)}- errorText={error?.message}- >- <Input {...field} placeholder="app1.example.com, app2.example.com, ..." />- </FormControl>- )}- />-- {/* Additional Subject Fields - Only for Azure ADCS CAs */}- {selectedCa?.type === CaType.AZURE_AD_CS && (- <Accordion type="single" collapsible className="mb-4 w-full">- <AccordionItem value="subject-fields" className="data-[state=open]:border-none">- <AccordionTrigger className="h-fit flex-none pl-1 text-sm">- <div className="order-1 ml-3">Additional Subject Fields</div>- </AccordionTrigger>- <AccordionContent>- <div className="grid grid-cols-1 gap-4">- <Controller- control={control}- name="organization"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Organization (O)"- isError={Boolean(error)}- errorText={error?.message}- tooltipText="Maximum 64 characters. No special DN characters allowed. Cannot start/end with spaces, hyphens, underscores, or periods."- >- <Input {...field} placeholder="Example Corp" maxLength={64} />- </FormControl>- )}+ <Controller+ control={control}+ name="name"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-name`}>+ Subscriber Name <span className="text-danger">*</span>+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-name`}+ {...field}+ placeholder="web-service"+ autoComplete="off"+ name="pki-subscriber-name"/>- <Controller- control={control}- name="organizationalUnit"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Organizational Unit (OU)"+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="caId"+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-caId`}>+ Issuing CA <span className="text-danger">*</span>+ </FieldLabel>+ <Combobox+ ref={field.ref}+ id={`${formId}-caId`}+ name={field.name}+ onBlur={field.onBlur}+ value={cas?.find((ca) => ca.id === field.value) ?? null}+ onValueChange={(ca) => onChange(ca.id)}+ options={cas ?? []}+ getOptionValue={(ca) => ca.id}+ getOptionLabel={(ca) =>+ ca.type === CaType.INTERNAL+ ? `${ca.name} (${ca.configuration.dn})`+ : ca.name+ }+ isClearable={false}+ isError={Boolean(error)}+ creation={caCreation}+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ {selectedCa?.type === CaType.AZURE_AD_CS && (+ <Controller+ control={control}+ name="azureTemplateType"+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-azureTemplateType`}>+ Certificate Template <span className="text-danger">*</span>+ </FieldLabel>+ <Select value={field.value} onValueChange={onChange} name={field.name}>+ <SelectTrigger+ id={`${formId}-azureTemplateType`}+ ref={field.ref}+ onBlur={field.onBlur}+ className="w-full"isError={Boolean(error)}- errorText={error?.message}- tooltipText="Maximum 64 characters. No special DN characters allowed. Cannot start/end with spaces, hyphens, underscores, or periods.">- <Input {...field} placeholder="IT Department" maxLength={64} />- </FormControl>- )}+ <SelectValue placeholder="Select an option" />+ </SelectTrigger>+ <SelectContent>+ {(azureTemplates?.templates || []).map(+ (template: { id: string; name: string }) => (+ <SelectItem value={template.id} key={template.id}>+ {template.name}+ </SelectItem>+ )+ )}+ </SelectContent>+ </Select>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ )}+ <Controller+ control={control}+ name="commonName"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-commonName`}>+ Common Name <span className="text-danger">*</span>+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-commonName`}+ {...field}+ placeholder="web.example.com"/>- <div className="grid grid-cols-2 gap-4">- <Controller- control={control}- name="country"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Country (C)"- isError={Boolean(error)}- errorText={error?.message}- tooltipText="Exactly 2 uppercase letters (ISO 3166-1 alpha-2 code). Examples: US, CA, GB, DE"- >- <Input- {...field}- placeholder="US"- maxLength={2}- style={{ textTransform: "uppercase" }}- />- </FormControl>- )}- />- <Controller- control={control}- name="state"- render={({ field, fieldState: { error } }) => (- <FormControl- label="State/Province (ST)"- isError={Boolean(error)}- errorText={error?.message}- tooltipText="Maximum 64 characters. No special DN characters allowed. Cannot start/end with spaces, hyphens, underscores, or periods."- >- <Input {...field} placeholder="California" maxLength={64} />- </FormControl>- )}+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="subjectAlternativeNames"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-subjectAlternativeNames`}>+ Subject Alternative Names (SANs)+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-subjectAlternativeNames`}+ {...field}+ placeholder="app1.example.com, app2.example.com, ..."+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ {/* Additional Subject Fields - Only for Azure ADCS CAs */}+ {selectedCa?.type === CaType.AZURE_AD_CS && (+ <Accordion type="single" collapsible variant="ghost">+ <AccordionItem value="subject-fields">+ <AccordionTrigger>+ <div className="order-1 ml-3">Additional Subject Fields</div>+ </AccordionTrigger>+ <AccordionContent>+ <div className="grid grid-cols-1 gap-4">+ <Controller+ control={control}+ name="organization"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-organization`}>+ Organization (O)+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-organization`}+ {...field}+ placeholder="Example Corp"+ maxLength={64}+ />+ <FieldDescription>+ Maximum 64 characters. No special DN characters allowed. Cannot+ start/end with spaces, hyphens, underscores, or periods.+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="organizationalUnit"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-organizationalUnit`}>+ Organizational Unit (OU)+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-organizationalUnit`}+ {...field}+ placeholder="IT Department"+ maxLength={64}+ />+ <FieldDescription>+ Maximum 64 characters. No special DN characters allowed. Cannot+ start/end with spaces, hyphens, underscores, or periods.+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <div className="grid grid-cols-2 gap-4">+ <Controller+ control={control}+ name="country"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-country`}>+ Country (C)+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-country`}+ {...field}+ placeholder="US"+ maxLength={2}+ style={{ textTransform: "uppercase" }}+ />+ <FieldDescription>+ Exactly 2 uppercase letters (ISO 3166-1 alpha-2 code).+ Examples: US, CA, GB, DE+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="state"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-state`}>+ State/Province (ST)+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-state`}+ {...field}+ placeholder="California"+ maxLength={64}+ />+ <FieldDescription>+ Maximum 64 characters. No special DN characters allowed.+ Cannot start/end with spaces, hyphens, underscores, or+ periods.+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ </div>+ <div className="grid grid-cols-2 gap-4">+ <Controller+ control={control}+ name="locality"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-locality`}>+ Locality (L)+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-locality`}+ {...field}+ placeholder="San Francisco"+ maxLength={64}+ />+ <FieldDescription>+ Maximum 64 characters. No special DN characters allowed.+ Cannot start/end with spaces, hyphens, underscores, or+ periods.+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="emailAddress"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-emailAddress`}>+ Email Address+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-emailAddress`}+ {...field}+ type="email"+ placeholder="[email protected]"+ maxLength={64}+ />+ <FieldDescription>+ Valid email format, 6-64 characters. Example:+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ </div>+ </div>+ </AccordionContent>+ </AccordionItem>+ </Accordion>+ )}+ {selectedCa?.type !== CaType.ACME && (+ <Controller+ control={control}+ name="ttl"+ render={({ field, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-ttl`}>+ TTL <span className="text-danger">*</span>+ </FieldLabel>+ <Input+ isError={Boolean(error)}+ id={`${formId}-ttl`}+ {...field}+ placeholder="2 days, 1d, 2h, 1y, ..."/>- </div>- <div className="grid grid-cols-2 gap-4">+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ )}+ {selectedCa?.type !== CaType.ACME && selectedCa?.type !== CaType.AZURE_AD_CS && (+ <Accordion type="single" collapsible variant="ghost">+ <AccordionItem value="key-usages">+ <AccordionTrigger>+ <div className="order-1 ml-3">Key Usage</div>+ </AccordionTrigger>+ <AccordionContent><Controllercontrol={control}- name="locality"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Locality (L)"- isError={Boolean(error)}- errorText={error?.message}- tooltipText="Maximum 64 characters. No special DN characters allowed. Cannot start/end with spaces, hyphens, underscores, or periods."- >- <Input {...field} placeholder="San Francisco" maxLength={64} />- </FormControl>- )}+ name="keyUsages"+ render={({ field: { onChange, value }, fieldState: { error } }) => {+ return (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-keyUsages`}>Key Usage</FieldLabel>+ <div className="mt-2 mb-7 grid grid-cols-2 gap-2">+ {KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => {+ return (+ <Field key={optionValue} orientation="horizontal">+ <Checkbox+ id={optionValue}+ isChecked={value[optionValue]}+ onCheckedChange={(state) => {+ onChange({+ ...value,+ [optionValue]: state+ });+ }}+ variant="project"+ />+ <FieldLabel htmlFor={optionValue}>{label}</FieldLabel>+ </Field>+ );+ })}+ </div>+ <FieldError>{error?.message}</FieldError>+ </Field>+ );+ }}/><Controllercontrol={control}- name="emailAddress"- render={({ field, fieldState: { error } }) => (- <FormControl- label="Email Address"- isError={Boolean(error)}- errorText={error?.message}- tooltipText="Valid email format, 6-64 characters. Example: [email protected]"- >- <Input- {...field}- type="email"- placeholder="[email protected]"- maxLength={64}- />- </FormControl>- )}+ name="extendedKeyUsages"+ render={({ field: { onChange, value }, fieldState: { error } }) => {+ return (+ <Field data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-extendedKeyUsages`}>+ Extended Key Usage+ </FieldLabel>+ <div className="mt-2 mb-7 grid grid-cols-2 gap-2">+ {EXTENDED_KEY_USAGES_OPTIONS.map(+ ({ label, value: optionValue }) => {+ return (+ <Field key={optionValue} orientation="horizontal">+ <Checkbox+ id={optionValue}+ isChecked={value[optionValue]}+ onCheckedChange={(state) => {+ onChange({+ ...value,+ [optionValue]: state+ });+ }}+ variant="project"+ />+ <FieldLabel htmlFor={optionValue}>{label}</FieldLabel>+ </Field>+ );+ }+ )}+ </div>+ <FieldError>{error?.message}</FieldError>+ </Field>+ );+ }}/>- </div>- </div>- </AccordionContent>- </AccordionItem>- </Accordion>- )}-- {selectedCa?.type !== CaType.ACME && (- <Controller- control={control}- name="ttl"- render={({ field, fieldState: { error } }) => (- <FormControl- label="TTL"- isError={Boolean(error)}- errorText={error?.message}- isRequired- >- <Input {...field} placeholder="2 days, 1d, 2h, 1y, ..." />- </FormControl>+ </AccordionContent>+ </AccordionItem>+ </Accordion>)}- />- )}- {selectedCa?.type !== CaType.ACME && selectedCa?.type !== CaType.AZURE_AD_CS && (- <Accordion type="single" collapsible className="w-full">- <AccordionItem value="key-usages" className="data-[state=open]:border-none">- <AccordionTrigger className="h-fit flex-none pl-1 text-sm">- <div className="order-1 ml-3">Key Usage</div>- </AccordionTrigger>- <AccordionContent>+ </TabsContent>+ <TabsContent className="flex flex-col gap-4" value={FormTab.Advanced}>+ <Controller+ control={control}+ name="enableAutoRenewal"+ render={({ field: { onChange, value }, fieldState: { error } }) => (+ <Field data-invalid={Boolean(error)}>+ <Field orientation="horizontal">+ <Checkbox+ id="enableAutoRenewal"+ isChecked={value}+ onCheckedChange={onChange}+ variant="project"+ />+ <FieldLabel htmlFor="enableAutoRenewal">+ Enable Certificate Auto Renewal+ </FieldLabel>+ </Field>+ <FieldDescription>+ If enabled, a new certificate will be issued automatically X days before+ the current certificate expires.+ </FieldDescription>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}+ />+ {selectedAutoRenewalState && (+ <div className="flex items-center"><Controllercontrol={control}- name="keyUsages"- render={({ field: { onChange, value }, fieldState: { error } }) => {- return (- <FormControl- label="Key Usage"- errorText={error?.message}+ defaultValue={7}+ name="renewalBefore"+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (+ <Field className="w-full" data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-renewalBefore`}>+ Renewal Before <span className="text-danger">*</span>+ </FieldLabel>+ <InputisError={Boolean(error)}- >- <div className="mt-2 mb-7 grid grid-cols-2 gap-2">- {KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => {- return (- <Checkbox- id={optionValue}- key={optionValue}- isChecked={value[optionValue]}- onCheckedChange={(state) => {- onChange({- ...value,- [optionValue]: state- });- }}- >- {label}- </Checkbox>- );- })}- </div>- </FormControl>- );- }}+ id={`${formId}-renewalBefore`}+ {...field}+ placeholder="5"+ type="number"+ min={1}+ value={field.value ?? ""}+ onChange={(e) => {+ const val = e.target.value;+ onChange(val === "" ? "" : Number(val));+ }}+ />+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}/><Controllercontrol={control}- name="extendedKeyUsages"- render={({ field: { onChange, value }, fieldState: { error } }) => {- return (- <FormControl- label="Extended Key Usage"- errorText={error?.message}- isError={Boolean(error)}- >- <div className="mt-2 mb-7 grid grid-cols-2 gap-2">- {EXTENDED_KEY_USAGES_OPTIONS.map(- ({ label, value: optionValue }) => {- return (- <Checkbox- id={optionValue}- key={optionValue}- isChecked={value[optionValue]}- onCheckedChange={(state) => {- onChange({- ...value,- [optionValue]: state- });- }}- >- {label}- </Checkbox>- );- }- )}- </div>- </FormControl>- );- }}+ name="renewalUnit"+ defaultValue={TimeUnit.DAY}+ render={({ field: { onChange, ...field }, fieldState: { error } }) => (+ <Field className="ml-4" data-invalid={Boolean(error)}>+ <FieldLabel htmlFor={`${formId}-renewalUnit`}>Unit</FieldLabel>+ <Select value={field.value} onValueChange={onChange} name={field.name}>+ <SelectTrigger+ id={`${formId}-renewalUnit`}+ ref={field.ref}+ onBlur={field.onBlur}+ className="w-full"+ isError={Boolean(error)}+ >+ <SelectValue placeholder="Select an option" />+ </SelectTrigger>+ <SelectContent>+ <SelectItem value={TimeUnit.DAY}>Days</SelectItem>+ <SelectItem value={TimeUnit.WEEK}>Weeks</SelectItem>+ <SelectItem value={TimeUnit.MONTH}>Months</SelectItem>+ <SelectItem value={TimeUnit.YEAR}>Years</SelectItem>+ </SelectContent>+ </Select>+ <FieldError>{error?.message}</FieldError>+ </Field>+ )}/>- </AccordionContent>- </AccordionItem>- </Accordion>- )}- </TabPanel>- <TabPanel value={FormTab.Advanced}>- <Controller- control={control}- name="enableAutoRenewal"- render={({ field: { onChange, value }, fieldState: { error } }) => (- <FormControl- isError={Boolean(error)}- errorText={error?.message}- tooltipText="If enabled, a new certificate will be issued automatically X days before the current certificate expires."- >- <Checkbox id="enableAutoRenewal" isChecked={value} onCheckedChange={onChange}>- Enable Certificate Auto Renewal- </Checkbox>- </FormControl>- )}- />- {selectedAutoRenewalState && (- <div className="flex items-center">- <Controller- control={control}- defaultValue={7}- name="renewalBefore"- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- label="Renewal Before"- isError={Boolean(error)}- errorText={error?.message}- className="w-full"- isRequired- >- <Input- {...field}- placeholder="5"- type="number"- min={1}- value={field.value ?? ""}- onChange={(e) => {- const val = e.target.value;- onChange(val === "" ? "" : Number(val));- }}- />- </FormControl>- )}- />- <Controller- control={control}- name="renewalUnit"- defaultValue={TimeUnit.DAY}- render={({ field: { onChange, ...field }, fieldState: { error } }) => (- <FormControl- className="ml-4"- label="Unit"- errorText={error?.message}- isError={Boolean(error)}- >- <Select- value={field.value}- onValueChange={(e) => onChange(e)}- className="w-48"- >- <SelectItem value={TimeUnit.DAY}>Days</SelectItem>- <SelectItem value={TimeUnit.WEEK}>Weeks</SelectItem>- <SelectItem value={TimeUnit.MONTH}>Months</SelectItem>- <SelectItem value={TimeUnit.YEAR}>Years</SelectItem>- </Select>- </FormControl>- )}- />- </div>- )}- </TabPanel>- </Tabs>- <div className="mt-4 flex items-center">- <Button- className="mr-4"- size="sm"- type="submit"- isLoading={isSubmitting}- isDisabled={isSubmitting}- >- {pkiSubscriber ? "Update" : "Add"}- </Button>- <Button- colorSchema="secondary"- variant="plain"- onClick={() => handlePopUpToggle("pkiSubscriber", false)}- >- Cancel- </Button>- </div>- </form>- </ModalContent>- </Modal>+ </div>+ )}+ </TabsContent>+ </Tabs>+ </fieldset>+ <SheetFooter className="justify-end border-t">+ <SheetClose asChild>+ <Button variant="ghost">Cancel</Button>+ </SheetClose>+ <Button+ variant="project"+ type="submit"+ isPending={isSubmitting}+ isDisabled={!isSubscriberReady}+ >+ {subscriberName ? "Update" : "Add"}+ </Button>+ </SheetFooter>+ </form>+ </SheetContent>+ </Sheet>+ {caCreationModals}+ <DiscardChangesAlertDialog+ open={isDiscardDialogOpen}+ onOpenChange={setIsDiscardDialogOpen}+ onDiscard={confirmDiscard}+ title="Discard Changes?"+ description="Your unsaved changes will be lost."+ />+ </>);};diff --git a/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscriberSection.tsx b/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscriberSection.tsxindex 19bf5cc94b..9548416a99 100644--- a/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscriberSection.tsx+++ b/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscriberSection.tsx@@ -3,8 +3,15 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";-import { Button } from "@app/components/v2";-import { ConfirmationAlertDialog } from "@app/components/v3";+import {+ Button,+ Card,+ CardAction,+ CardContent,+ CardHeader,+ CardTitle,+ ConfirmationAlertDialog+} from "@app/components/v3";import { LegacyPkiResource } from "@app/const/legacyPkiDeprecation";import {ProjectPermissionPkiSubscriberActions,@@ -71,30 +78,33 @@ export const PkiSubscriberSection = () => {const subscriberName = subscriberStatusData?.subscriberName || "";return (- <div className="mb-6 rounded-lg border border-border-control bg-surface-base p-4">- <div className="mb-4 flex justify-between">- <p className="text-xl font-medium text-foreground">Subscribers</p>- <div className="flex w-full justify-end">- <ProjectPermissionCan- I={ProjectPermissionPkiSubscriberActions.Create}- a={ProjectPermissionSub.PkiSubscribers}- >- {(isAllowed) => (- <Button- colorSchema="primary"- type="submit"- leftIcon={<FontAwesomeIcon icon={faPlus} />}- onClick={() => handlePopUpOpen("creationBlocked")}- isDisabled={!isAllowed}- className="ml-4"- >- Add Subscriber- </Button>- )}- </ProjectPermissionCan>- </div>- </div>- <PkiSubscribersTable handlePopUpOpen={handlePopUpOpen} />+ <Card>+ <CardHeader>+ <CardTitle>Subscribers</CardTitle>+ <CardAction>+ <div className="flex w-full justify-end">+ <ProjectPermissionCan+ I={ProjectPermissionPkiSubscriberActions.Create}+ a={ProjectPermissionSub.PkiSubscribers}+ >+ {(isAllowed) => (+ <Button+ type="submit"+ onClick={() => handlePopUpOpen("creationBlocked")}+ isDisabled={!isAllowed}+ variant="project"+ >+ <FontAwesomeIcon icon={faPlus} />+ Add Subscriber+ </Button>+ )}+ </ProjectPermissionCan>+ </div>+ </CardAction>+ </CardHeader>+ <CardContent>+ <PkiSubscribersTable handlePopUpOpen={handlePopUpOpen} />+ </CardContent><PkiSubscriberModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} /><LegacyPkiCreationBlockedModalresource={LegacyPkiResource.PkiSubscriber}@@ -127,6 +137,6 @@ export const PkiSubscriberSection = () => {)}/>- </div>+ </Card>);};diff --git a/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscribersTable.tsx b/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscribersTable.tsxindex e5af549d36..b6962e50ff 100644--- a/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscribersTable.tsx+++ b/frontend/src/pages/cert-manager/PkiSubscribersPage/components/PkiSubscribersTable.tsx@@ -1,32 +1,26 @@-import {- faBan,- faEllipsis,- faPencil,- faTrash,- faUserShield-} from "@fortawesome/free-solid-svg-icons";+import { faBan, faEllipsis, faPencil, faTrash } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { useNavigate } from "@tanstack/react-router";-import { twMerge } from "tailwind-merge";import { ProjectPermissionCan } from "@app/components/permissions";import {+ Badge,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuTrigger,- EmptyState,+ Empty,+ EmptyHeader,+ EmptyTitle,+ IconButton,Table,- TableContainer,- TableSkeleton,- TBody,- Td,- Th,- THead,- Tooltip,- Tr-} from "@app/components/v2";-import { Badge } from "@app/components/v3";+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+ TableSkeletonRows+} from "@app/components/v3";import {ProjectPermissionPkiSubscriberActions,ProjectPermissionSub,@@ -53,137 +47,131 @@ export const PkiSubscribersTable = ({ handlePopUpOpen }: Props) => {const { currentOrg } = useOrganization();const { currentProject } = useProject();const { data, isPending } = useListWorkspacePkiSubscribers(currentProject?.id || "");+ if (!isPending && !data?.length) {+ return (+ <Empty className="border">+ <EmptyHeader>+ <EmptyTitle>No PKI subscribers have been added</EmptyTitle>+ </EmptyHeader>+ </Empty>+ );+ }+return (<div>- <TableContainer>- <Table className="w-full">- <THead>- <Tr>- <Th>Name</Th>- <Th>Status</Th>- <Th>Common Name</Th>- <Th />- </Tr>- </THead>- <TBody>- {isPending && <TableSkeleton columns={4} innerKey="pki-subscribers" />}- {!isPending &&- data &&- data.length > 0 &&- data.map((subscriber) => {- return (- <Tr- className="h-10 cursor-pointer transition-colors duration-100 hover:bg-surface-hover"- key={`pki-subscriber-${subscriber.id}`}- onClick={() =>- navigate({- to: "/organizations/$orgId/cert-manager/subscribers/$subscriberName",- params: {- orgId: currentOrg.id,- subscriberName: subscriber.name- }- })- }- >- <Td>{subscriber.name}</Td>- <Td>- <Badge variant={getPkiSubscriberStatusBadgeVariant(subscriber.status)}>- {pkiSubscriberStatusToNameMap[subscriber.status]}- </Badge>- </Td>- <Td>{subscriber.commonName}</Td>- <Td className="text-right align-middle">- <DropdownMenu>- <DropdownMenuTrigger asChild className="rounded-lg">- <div className="hover:text-project data-[state=open]:text-project">- <Tooltip content="More options">- <FontAwesomeIcon size="lg" icon={faEllipsis} />- </Tooltip>- </div>- </DropdownMenuTrigger>- <DropdownMenuContent align="start" className="p-1">- <ProjectPermissionCan- I={ProjectPermissionPkiSubscriberActions.Edit}- a={ProjectPermissionSub.PkiSubscribers}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("pkiSubscriber", {- subscriberName: subscriber.name- });- }}- disabled={!isAllowed}- icon={<FontAwesomeIcon icon={faPencil} />}- >- Edit Subscriber- </DropdownMenuItem>- )}- </ProjectPermissionCan>- <ProjectPermissionCan- I={ProjectPermissionPkiSubscriberActions.Edit}- a={ProjectPermissionSub.PkiSubscribers}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("pkiSubscriberStatus", {- subscriberName: subscriber.name,- status:- subscriber.status === PkiSubscriberStatus.ACTIVE- ? PkiSubscriberStatus.DISABLED- : PkiSubscriberStatus.ACTIVE- });- }}- disabled={!isAllowed}- icon={<FontAwesomeIcon icon={faBan} />}- >- {`${subscriber.status === PkiSubscriberStatus.ACTIVE ? "Disable" : "Enable"} Subscriber`}- </DropdownMenuItem>- )}- </ProjectPermissionCan>- <ProjectPermissionCan- I={ProjectPermissionPkiSubscriberActions.Delete}- a={ProjectPermissionSub.PkiSubscribers}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- !isAllowed && "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("deletePkiSubscriber", {- subscriberName: subscriber.name- });- }}- disabled={!isAllowed}- icon={<FontAwesomeIcon icon={faTrash} />}- >- Delete Subscriber- </DropdownMenuItem>- )}- </ProjectPermissionCan>- </DropdownMenuContent>- </DropdownMenu>- </Td>- </Tr>- );- })}- </TBody>- </Table>- {!isPending && data?.length === 0 && (- <EmptyState title="No PKI subscribers have been added" icon={faUserShield} />- )}- </TableContainer>+ <Table className="w-full">+ <TableHeader>+ <TableRow>+ <TableHead>Name</TableHead>+ <TableHead>Status</TableHead>+ <TableHead>Common Name</TableHead>+ <TableHead />+ </TableRow>+ </TableHeader>+ <TableBody>+ {isPending && <TableSkeletonRows columns={4} />}+ {!isPending &&+ data &&+ data.length > 0 &&+ data.map((subscriber) => {+ return (+ <TableRow+ key={`pki-subscriber-${subscriber.id}`}+ onClick={() =>+ navigate({+ to: "/organizations/$orgId/cert-manager/subscribers/$subscriberName",+ params: {+ orgId: currentOrg.id,+ subscriberName: subscriber.name+ }+ })+ }+ >+ <TableCell>{subscriber.name}</TableCell>+ <TableCell>+ <Badge variant={getPkiSubscriberStatusBadgeVariant(subscriber.status)}>+ {pkiSubscriberStatusToNameMap[subscriber.status]}+ </Badge>+ </TableCell>+ <TableCell>{subscriber.commonName}</TableCell>+ <TableCell className="text-right align-middle">+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <IconButton variant="ghost" size="xs" aria-label="More options">+ <FontAwesomeIcon icon={faEllipsis} />+ </IconButton>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start">+ <ProjectPermissionCan+ I={ProjectPermissionPkiSubscriberActions.Edit}+ a={ProjectPermissionSub.PkiSubscribers}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("pkiSubscriber", {+ subscriberName: subscriber.name+ });+ }}+ isDisabled={!isAllowed}+ >+ <FontAwesomeIcon icon={faPencil} />+ Edit Subscriber+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ <ProjectPermissionCan+ I={ProjectPermissionPkiSubscriberActions.Edit}+ a={ProjectPermissionSub.PkiSubscribers}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("pkiSubscriberStatus", {+ subscriberName: subscriber.name,+ status:+ subscriber.status === PkiSubscriberStatus.ACTIVE+ ? PkiSubscriberStatus.DISABLED+ : PkiSubscriberStatus.ACTIVE+ });+ }}+ isDisabled={!isAllowed}+ >+ <FontAwesomeIcon icon={faBan} />+ {`${subscriber.status === PkiSubscriberStatus.ACTIVE ? "Disable" : "Enable"} Subscriber`}+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ <ProjectPermissionCan+ I={ProjectPermissionPkiSubscriberActions.Delete}+ a={ProjectPermissionSub.PkiSubscribers}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("deletePkiSubscriber", {+ subscriberName: subscriber.name+ });+ }}+ isDisabled={!isAllowed}+ variant="danger"+ >+ <FontAwesomeIcon icon={faTrash} />+ Delete Subscriber+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ </DropdownMenuContent>+ </DropdownMenu>+ </TableCell>+ </TableRow>+ );+ })}+ </TableBody>+ </Table></div>);};diff --git a/frontend/src/pages/cert-manager/PkiTemplateListPage/PkiTemplateListPage.tsx b/frontend/src/pages/cert-manager/PkiTemplateListPage/PkiTemplateListPage.tsxindex 5a22f2ef7c..411832d333 100644--- a/frontend/src/pages/cert-manager/PkiTemplateListPage/PkiTemplateListPage.tsx+++ b/frontend/src/pages/cert-manager/PkiTemplateListPage/PkiTemplateListPage.tsx@@ -2,7 +2,6 @@ import { useState } from "react";import { Helmet } from "react-helmet";import { useTranslation } from "react-i18next";import {- faCertificate,faCog,faEllipsis,faFileContract,@@ -12,7 +11,6 @@ import {} from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { format } from "date-fns";-import { twMerge } from "tailwind-merge";import {CertificateEnrollmentUpgradeIntent,@@ -21,27 +19,39 @@ import {import { createNotification } from "@app/components/notifications";import { ProjectPermissionCan } from "@app/components/permissions";import {+ Badge,Button,+ Card,+ CardAction,+ CardContent,+ CardFooter,+ CardHeader,+ CardTitle,+ ConfirmationAlertDialog,+ DiscardChangesAlertDialog,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuTrigger,- EmptyState,- Modal,- ModalContent,+ Empty,+ EmptyHeader,+ EmptyTitle,+ IconButton,+ PageHeader,Pagination,+ Sheet,+ SheetContent,+ SheetDescription,+ SheetHeader,+ SheetTitle,Table,- TableContainer,- TableSkeleton,- Tag,- TBody,- Td,- Th,- THead,- Tooltip,- Tr-} from "@app/components/v2";-import { ConfirmationAlertDialog, PageHeader } from "@app/components/v3";+ TableBody,+ TableCell,+ TableHead,+ TableHeader,+ TableRow,+ TableSkeletonRows+} from "@app/components/v3";import { LegacyPkiResource } from "@app/const/legacyPkiDeprecation";import {ProjectPermissionCertificateActions,@@ -54,6 +64,7 @@ import { usePopUp } from "@app/hooks";import { useDeleteCertTemplateV2 } from "@app/hooks/api";import { useListCertificateTemplates } from "@app/hooks/api/certificateTemplates/queries";import { ProjectType } from "@app/hooks/api/projects/types";+import { useDiscardChangesGuard } from "@app/hooks/useDiscardChangesGuard";import { CertificateModal } from "../CertificatesPage/components/CertificateModal";import { CertificateTemplateEnrollmentModal } from "../CertificatesPage/components/CertificateTemplateEnrollmentModal";@@ -102,13 +113,20 @@ export const PkiTemplateListPage = () => {handlePopUpClose("deleteTemplate");};+ const [editorState, setEditorState] = useState({ isDirty: false, isPending: false });+ const { requestDiscard, confirmDiscard, isDiscardDialogOpen, setIsDiscardDialogOpen } =+ useDiscardChangesGuard({+ isDirty: editorState.isDirty,+ onDiscard: () => handlePopUpToggle("certificateTemplate", false)+ });+return (<><Helmet><title>{t("common.head-title", { title: "PKI Templates" })}</title></Helmet><div className="h-full bg-page">- <div className="mx-auto flex flex-col justify-between text-foreground-inverse">+ <div className="mx-auto flex flex-col justify-between"><div className="mx-auto flex w-full max-w-8xl flex-col"><PageHeaderscope={ProjectType.CertificateManager}@@ -117,176 +135,164 @@ export const PkiTemplateListPage = () => {/><div className="flex flex-col gap-8"><LegacyPkiDeprecationAlert resource={LegacyPkiResource.CertificateTemplate} />- <div className="container mx-auto mb-6 max-w-8xl rounded-lg border border-border-control bg-surface-base p-4">- <div className="mb-4 flex justify-between">- <p className="text-xl font-medium text-foreground">Templates</p>- <div className="flex w-full justify-end">- <ProjectPermissionCan- I={ProjectPermissionPkiTemplateActions.Create}- a={ProjectPermissionSub.CertificateTemplates}- >- {(isAllowed) => (- <Button- colorSchema="primary"- type="submit"- leftIcon={<FontAwesomeIcon icon={faPlus} />}- onClick={() => handlePopUpOpen("creationBlocked")}- isDisabled={!isAllowed}- className="ml-4"- >- Add Template- </Button>- )}- </ProjectPermissionCan>- </div>- </div>- <TableContainer>- <Table>- <THead>- <Tr>- <Th>Name</Th>- <Th>Issuing CA</Th>- <Th className="w-64">Last Updated At</Th>- <Th />- </Tr>- </THead>- <TBody>- {isPending && <TableSkeleton columns={4} innerKey="project-cert-templates" />}- {!isPending &&- data?.certificateTemplates?.map((template) => {- return (- <Tr className="h-10" key={`certificate-template-${template.id}`}>- <Td>{template.name}</Td>- <Td>- <Tag size="xs">{template.ca.name}</Tag>- </Td>- <Td>- {format(new Date(template.updatedAt), "yyyy-MM-dd | HH:mm:ss")}- </Td>- <Td className="text-right align-middle">- <DropdownMenu>- <DropdownMenuTrigger asChild className="rounded-lg">- <div className="hover:text-primary-400 data-[state=open]:text-primary-400">- <Tooltip content="More options">- <FontAwesomeIcon size="lg" icon={faEllipsis} />- </Tooltip>- </div>- </DropdownMenuTrigger>- <DropdownMenuContent align="start" className="p-1">- <ProjectPermissionCan- I={ProjectPermissionCertificateActions.Create}- a={ProjectPermissionSub.Certificates}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- !isAllowed &&- "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("certificateFromTemplate", template);- }}- disabled={!isAllowed}- icon={<FontAwesomeIcon icon={faFileContract} />}- >- Issue Certificate- </DropdownMenuItem>- )}- </ProjectPermissionCan>- <ProjectPermissionCan- I={ProjectPermissionPkiTemplateActions.Edit}- a={ProjectPermissionSub.CertificateTemplates}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- !isAllowed &&- "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("certificateTemplate", template);- }}- disabled={!isAllowed}- icon={<FontAwesomeIcon icon={faPencil} />}- >- Edit Template- </DropdownMenuItem>- )}- </ProjectPermissionCan>- <ProjectPermissionCan- I={ProjectPermissionPkiTemplateActions.Edit}- a={ProjectPermissionSub.CertificateTemplates}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- !isAllowed &&- "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- if (!subscription.pkiEst) {- openUpgradeGate({- intent: CertificateEnrollmentUpgradeIntent,- paywallKey: "cert-manager.pki-template-list"+ <Card>+ <CardHeader>+ <CardTitle>Templates</CardTitle>+ <CardAction>+ <div className="flex w-full justify-end">+ <ProjectPermissionCan+ I={ProjectPermissionPkiTemplateActions.Create}+ a={ProjectPermissionSub.CertificateTemplates}+ >+ {(isAllowed) => (+ <Button+ type="submit"+ onClick={() => handlePopUpOpen("creationBlocked")}+ isDisabled={!isAllowed}+ variant="project"+ >+ <FontAwesomeIcon icon={faPlus} />+ Add Template+ </Button>+ )}+ </ProjectPermissionCan>+ </div>+ </CardAction>+ </CardHeader>+ <CardContent>+ {isPending || data?.certificateTemplates?.length ? (+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead>Name</TableHead>+ <TableHead>Issuing CA</TableHead>+ <TableHead className="w-64">Last Updated At</TableHead>+ <TableHead />+ </TableRow>+ </TableHeader>+ <TableBody>+ {isPending && <TableSkeletonRows columns={4} />}+ {!isPending &&+ data?.certificateTemplates?.map((template) => {+ return (+ <TableRow key={`certificate-template-${template.id}`}>+ <TableCell>{template.name}</TableCell>+ <TableCell>+ <Badge variant="neutral">{template.ca.name}</Badge>+ </TableCell>+ <TableCell>+ {format(new Date(template.updatedAt), "yyyy-MM-dd | HH:mm:ss")}+ </TableCell>+ <TableCell className="text-right align-middle">+ <DropdownMenu>+ <DropdownMenuTrigger asChild>+ <IconButton+ variant="ghost"+ size="xs"+ aria-label="More options"+ >+ <FontAwesomeIcon icon={faEllipsis} />+ </IconButton>+ </DropdownMenuTrigger>+ <DropdownMenuContent align="start">+ <ProjectPermissionCan+ I={ProjectPermissionCertificateActions.Create}+ a={ProjectPermissionSub.Certificates}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("certificateFromTemplate", template);+ }}+ isDisabled={!isAllowed}+ >+ <FontAwesomeIcon icon={faFileContract} />+ Issue Certificate+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ <ProjectPermissionCan+ I={ProjectPermissionPkiTemplateActions.Edit}+ a={ProjectPermissionSub.CertificateTemplates}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("certificateTemplate", template);+ }}+ isDisabled={!isAllowed}+ >+ <FontAwesomeIcon icon={faPencil} />+ Edit Template+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ <ProjectPermissionCan+ I={ProjectPermissionPkiTemplateActions.Edit}+ a={ProjectPermissionSub.CertificateTemplates}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ if (!subscription.pkiEst) {+ openUpgradeGate({+ intent: CertificateEnrollmentUpgradeIntent,+ paywallKey: "cert-manager.pki-template-list"+ });+ return;+ }+ handlePopUpOpen("enrollmentOptions", {+ id: template.id});- return;- }- handlePopUpOpen("enrollmentOptions", {- id: template.id- });- }}- disabled={!isAllowed}- icon={<FontAwesomeIcon icon={faCog} />}- >- Manage Enrollment- </DropdownMenuItem>- )}- </ProjectPermissionCan>- <ProjectPermissionCan- I={ProjectPermissionPkiTemplateActions.Delete}- a={ProjectPermissionSub.CertificateTemplates}- >- {(isAllowed) => (- <DropdownMenuItem- className={twMerge(- !isAllowed &&- "pointer-events-none cursor-not-allowed opacity-50"- )}- onClick={(e) => {- e.stopPropagation();- handlePopUpOpen("deleteTemplate", template);- }}- disabled={!isAllowed}- icon={<FontAwesomeIcon icon={faTrash} />}- >- Delete Template- </DropdownMenuItem>- )}- </ProjectPermissionCan>- </DropdownMenuContent>- </DropdownMenu>- </Td>- </Tr>- );- })}- {!isPending && !data?.certificateTemplates?.length && (- <Tr>- <Td colSpan={4}>- <EmptyState- title="No certificate templates found"- icon={faCertificate}- />- </Td>- </Tr>- )}- </TBody>- </Table>- {!isPending &&- data?.totalCount !== undefined &&- data.totalCount >= PER_PAGE_INIT && (+ }}+ isDisabled={!isAllowed}+ >+ <FontAwesomeIcon icon={faCog} />+ Manage Enrollment+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ <ProjectPermissionCan+ I={ProjectPermissionPkiTemplateActions.Delete}+ a={ProjectPermissionSub.CertificateTemplates}+ >+ {(isAllowed) => (+ <DropdownMenuItem+ onClick={(e) => {+ e.stopPropagation();+ handlePopUpOpen("deleteTemplate", template);+ }}+ isDisabled={!isAllowed}+ variant="danger"+ >+ <FontAwesomeIcon icon={faTrash} />+ Delete Template+ </DropdownMenuItem>+ )}+ </ProjectPermissionCan>+ </DropdownMenuContent>+ </DropdownMenu>+ </TableCell>+ </TableRow>+ );+ })}+ </TableBody>+ </Table>+ ) : (+ <Empty className="border">+ <EmptyHeader>+ <EmptyTitle>No certificate templates found</EmptyTitle>+ </EmptyHeader>+ </Empty>+ )}+ </CardContent>+ {!isPending &&+ data?.totalCount !== undefined &&+ data.totalCount >= PER_PAGE_INIT && (+ <CardFooter><Paginationcount={data.totalCount}page={page}@@ -294,8 +300,8 @@ export const PkiTemplateListPage = () => {onChangePage={(newPage) => setPage(newPage)}onChangePerPage={(newPerPage) => setPerPage(newPerPage)}/>- )}- </TableContainer>+ </CardFooter>+ )}<ConfirmationAlertDialogisOpen={popUp.deleteTemplate.isOpen}description="This action is irreversible."@@ -304,28 +310,41 @@ export const PkiTemplateListPage = () => {confirmKey="confirm"onConfirm={() => onRemovePkiSubscriberSubmit()}/>- </div>+ </Card></div></div><div className="container mx-auto max-w-8xl" /></div>- <Modal- isOpen={popUp?.certificateTemplate?.isOpen}- onOpenChange={(isOpen) => handlePopUpToggle("certificateTemplate", isOpen)}+ <Sheet+ open={popUp?.certificateTemplate?.isOpen}+ onOpenChange={(isOpen) => {+ if (!isOpen) requestDiscard();+ }}>- <ModalContent- title={- popUp.certificateTemplate?.data- ? "Certificate Template"- : "Create Certificate Template"- }- >+ <SheetContent size="form" isPending={editorState.isPending}>+ <SheetHeader>+ <SheetTitle>+ {popUp.certificateTemplate?.data+ ? "Certificate Template"+ : "Create Certificate Template"}+ </SheetTitle>+ <SheetDescription>Configure the certificate template.</SheetDescription>+ </SheetHeader><PkiTemplateForm+ onStateChange={setEditorState}+ onCancel={requestDiscard}certTemplate={popUp?.certificateTemplate?.data}handlePopUpToggle={(isOpen) => handlePopUpToggle("certificateTemplate", isOpen)}/>- </ModalContent>- </Modal>+ </SheetContent>+ </Sheet>+ <DiscardChangesAlertDialog+ open={isDiscardDialogOpen}+ onOpenChange={setIsDiscardDialogOpen}+ onDiscard={confirmDiscard}+ title="Discard Changes?"+ description="Your unsaved template changes will be lost."+ /><CertificateTemplateEnrollmentModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} /><LegacyPkiCreationBlockedModalresource={LegacyPkiResource.CertificateTemplate}diff --git a/frontend/src/pages/cert-manager/PkiTemplateListPage/components/PkiTemplateForm.tsx b/frontend/src/pages/cert-manager/PkiTemplateListPage/components/PkiTemplateForm.tsxindex e99882c810..732b835a4a 100644--- a/frontend/src/pages/cert-manager/PkiTemplateListPage/components/PkiTemplateForm.tsx+++ b/frontend/src/pages/cert-manager/PkiTemplateListPage/components/PkiTemplateForm.tsx@@ -1,10 +1,10 @@+import { useEffect } from "react";import { Controller, useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import { CircleHelpIcon } from "lucide-react";import { z } from "zod";import { createNotification } from "@app/components/notifications";-import { FilterableSelect } from "@app/components/v2";import {Accordion,AccordionContent,@@ -12,11 +12,13 @@ import {AccordionTrigger,Button,Checkbox,+ Combobox,Field,FieldContent,FieldError,FieldLabel,Input,+ SheetFooter,Tooltip,TooltipContent,TooltipTrigger@@ -35,6 +37,7 @@ import {import { CertKeyUsage } from "@app/hooks/api/certificates/enums";import { TCertificateTemplateV2 } from "@app/hooks/api/certificateTemplates/types";import { slugSchema } from "@app/lib/schemas";+import { useCaCreation } from "@app/pages/cert-manager/components/useCaCreation";const validateTemplateRegexField = z.string().trim().min(1).max(100);@@ -66,11 +69,18 @@ const schema = z.object({export type FormData = z.infer<typeof schema>;type Props = {+ onCancel: () => void;+ onStateChange: (state: { isDirty: boolean; isPending: boolean }) => void;certTemplate?: TCertificateTemplateV2;handlePopUpToggle: (state?: boolean) => void;};-export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => {+export const PkiTemplateForm = ({+ certTemplate,+ handlePopUpToggle,+ onCancel,+ onStateChange+}: Props) => {const { currentProject } = useProject();const { data: cas, isPending: isCaLoading } = useListCasByProjectId();@@ -82,7 +92,8 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => {control,handleSubmit,reset,- formState: { isSubmitting }+ setValue,+ formState: { isSubmitting, isDirty }} = useForm<FormData>({resolver: zodResolver(schema),defaultValues: async () => {@@ -114,6 +125,10 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => {}});+ useEffect(() => {+ onStateChange({ isDirty, isPending: isSubmitting });+ }, [isDirty, isSubmitting, onStateChange]);+const onFormSubmit = async ({name,commonName,@@ -180,234 +195,259 @@ export const PkiTemplateForm = ({ certTemplate, handlePopUpToggle }: Props) => {handlePopUpToggle(false);};+ const { creation: caCreation, caCreationModals } = useCaCreation<{ id: string; name: string }>(+ (ca) => {+ setValue("ca", { id: ca.id, name: ca.name }, { shouldDirty: true, shouldValidate: true });+ }+ );+return (- <form className="flex flex-col gap-4" onSubmit={handleSubmit(onFormSubmit)}>- {certTemplate && (- <Field>- <FieldLabel htmlFor="pki-template-id">Certificate Template ID</FieldLabel>- <Input id="pki-template-id" value={certTemplate.id} disabled />- </Field>- )}- <Controller- control={control}- defaultValue=""- name="name"- render={({ field, fieldState: { error } }) => (- <Field>- <FieldLabel htmlFor="pki-template-name">- Template Name <span className="text-danger">*</span>- </FieldLabel>- <FieldContent>- <Input- {...field}- id="pki-template-name"- placeholder="my-template"- autoComplete="off"- name="pki-template-name"- isError={Boolean(error)}- />- <FieldError errors={[error]} />- </FieldContent>- </Field>- )}- />- <Controller- render={({ field: { value, onChange }, fieldState: { error } }) => (- <Field>- <FieldLabel htmlFor="pki-template-ca">- Issuing CA <span className="text-danger">*</span>- </FieldLabel>- <FieldContent>- <FilterableSelect- inputId="pki-template-ca"- options={cas || []}- isLoading={isCaLoading}- placeholder="Select CA..."- onChange={onChange}- value={value}- getOptionValue={(option) => option.id}- getOptionLabel={(option) => option.name}- />- <FieldError errors={[error]} />- </FieldContent>- </Field>- )}- control={control}- name="ca"- />- <Controller- control={control}- defaultValue=""- name="commonName"- render={({ field, fieldState: { error } }) => (- <Field>- <FieldLabel htmlFor="pki-template-common-name">- Common Name (CN) <span className="text-danger">*</span>- <Tooltip hoverable delayDuration={50}>- <TooltipTrigger asChild>- <CircleHelpIcon className="size-3.5 text-muted" />- </TooltipTrigger>- <TooltipContent className="max-w-xs text-center">- This field accepts limited regular expressions: spaces, *, ., @, -, \ (for- escaping), and alphanumeric characters only- </TooltipContent>- </Tooltip>- </FieldLabel>- <FieldContent>- <Input- {...field}- id="pki-template-common-name"- placeholder=".*\.acme.com"- isError={Boolean(error)}- />- <FieldError errors={[error]} />- </FieldContent>- </Field>- )}- />- <Controller- control={control}- defaultValue=""- name="subjectAlternativeName"- render={({ field, fieldState: { error } }) => (- <Field>- <FieldLabel htmlFor="pki-template-san">- Alternative Names (SAN) <span className="text-danger">*</span>- <Tooltip hoverable delayDuration={50}>- <TooltipTrigger asChild>- <CircleHelpIcon className="size-3.5 text-muted" />- </TooltipTrigger>- <TooltipContent className="max-w-xs text-center">- This field accepts limited regular expressions: spaces, *, ., @, -, \ (for- escaping), and alphanumeric characters only- </TooltipContent>- </Tooltip>- </FieldLabel>- <FieldContent>- <Input- {...field}- id="pki-template-san"- placeholder="service\.acme.\..*"- isError={Boolean(error)}- />- <FieldError errors={[error]} />- </FieldContent>- </Field>- )}- />- <Controller- control={control}- name="ttl"- render={({ field, fieldState: { error } }) => (- <Field>- <FieldLabel htmlFor="pki-template-ttl">- Max TTL <span className="text-danger">*</span>- </FieldLabel>- <FieldContent>- <Input- {...field}- id="pki-template-ttl"- placeholder="2 days, 1d, 2h, 1y, ..."- isError={Boolean(error)}- />- <FieldError errors={[error]} />- </FieldContent>- </Field>- )}- />- <Accordion type="single" collapsible variant="ghost" className="w-full">- <AccordionItem value="key-usages" className="border-b-0">- <AccordionTrigger>Key Usage</AccordionTrigger>- <AccordionContent>- <Controller- control={control}- name="keyUsages"- render={({ field: { onChange, value }, fieldState: { error } }) => {- return (- <Field className="mb-7">- <FieldLabel>Key Usage</FieldLabel>- <FieldContent>- <div className="mt-2 grid grid-cols-2 gap-2">- {KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => {- return (- <div key={optionValue} className="flex items-center gap-3">- <Checkbox- id={`key-usage-${optionValue}`}- variant="project"- isChecked={value[optionValue]}- onCheckedChange={(state) => {- onChange({- ...value,- [optionValue]: state- });- }}- />- <label- htmlFor={`key-usage-${optionValue}`}- className="cursor-pointer text-sm text-foreground"- >- {label}- </label>- </div>- );- })}- </div>- <FieldError errors={[error]} />- </FieldContent>- </Field>- );- }}- />- <Controller- control={control}- name="extendedKeyUsages"- render={({ field: { onChange, value }, fieldState: { error } }) => {- return (- <Field className="mb-7">- <FieldLabel>Extended Key Usage</FieldLabel>- <FieldContent>- <div className="mt-2 grid grid-cols-2 gap-2">- {EXTENDED_KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => {- return (- <div key={optionValue} className="flex items-center gap-3">- <Checkbox- id={`extended-key-usage-${optionValue}`}- variant="project"- isChecked={value[optionValue]}- onCheckedChange={(state) => {- onChange({- ...value,- [optionValue]: state- });- }}- />- <label- htmlFor={`extended-key-usage-${optionValue}`}- className="cursor-pointer text-sm text-foreground"- >- {label}- </label>- </div>- );- })}- </div>- <FieldError errors={[error]} />- </FieldContent>- </Field>- );- }}- />- </AccordionContent>- </AccordionItem>- </Accordion>- <div className="flex items-center gap-4">- <Button variant="project" type="submit" isPending={isSubmitting} isDisabled={isSubmitting}>- Save- </Button>- <Button variant="ghost" onClick={() => handlePopUpToggle(false)}>- Cancel- </Button>- </div>- </form>+ <>+ <form className="flex min-h-0 flex-1 flex-col" onSubmit={handleSubmit(onFormSubmit)}>+ <fieldset+ disabled={isSubmitting}+ className="flex min-h-0 min-w-0 flex-1 flex-col gap-4 overflow-y-auto p-4"+ >+ {certTemplate && (+ <Field>+ <FieldLabel htmlFor="pki-template-id">Certificate Template ID</FieldLabel>+ <Input id="pki-template-id" value={certTemplate.id} disabled />+ </Field>+ )}+ <Controller+ control={control}+ defaultValue=""+ name="name"+ render={({ field, fieldState: { error } }) => (+ <Field>+ <FieldLabel htmlFor="pki-template-name">+ Template Name <span className="text-danger">*</span>+ </FieldLabel>+ <FieldContent>+ <Input+ {...field}+ id="pki-template-name"+ placeholder="my-template"+ autoComplete="off"+ name="pki-template-name"+ isError={Boolean(error)}+ />+ <FieldError errors={[error]} />+ </FieldContent>+ </Field>+ )}+ />+ <Controller+ render={({ field: { value, onChange, onBlur, name, ref }, fieldState: { error } }) => (+ <Field>+ <FieldLabel htmlFor="pki-template-ca">+ Issuing CA <span className="text-danger">*</span>+ </FieldLabel>+ <FieldContent>+ <Combobox+ ref={ref}+ onBlur={onBlur}+ name={name}+ isError={Boolean(error)}+ id="pki-template-ca"+ options={cas || []}+ isLoading={isCaLoading}+ isClearable={false}+ placeholder="Select CA..."+ onValueChange={onChange}+ value={value?.id ? value : null}+ getOptionValue={(option) => option.id}+ getOptionLabel={(option) => option.name}+ creation={caCreation}+ />+ <FieldError errors={[error]} />+ </FieldContent>+ </Field>+ )}+ control={control}+ name="ca"+ />+ <Controller+ control={control}+ defaultValue=""+ name="commonName"+ render={({ field, fieldState: { error } }) => (+ <Field>+ <FieldLabel htmlFor="pki-template-common-name">+ Common Name (CN) <span className="text-danger">*</span>+ <Tooltip hoverable delayDuration={50}>+ <TooltipTrigger asChild>+ <CircleHelpIcon className="size-3.5 text-muted" />+ </TooltipTrigger>+ <TooltipContent className="max-w-xs text-center">+ This field accepts limited regular expressions: spaces, *, ., @, -, \ (for+ escaping), and alphanumeric characters only+ </TooltipContent>+ </Tooltip>+ </FieldLabel>+ <FieldContent>+ <Input+ {...field}+ id="pki-template-common-name"+ placeholder=".*\.acme.com"+ isError={Boolean(error)}+ />+ <FieldError errors={[error]} />+ </FieldContent>+ </Field>+ )}+ />+ <Controller+ control={control}+ defaultValue=""+ name="subjectAlternativeName"+ render={({ field, fieldState: { error } }) => (+ <Field>+ <FieldLabel htmlFor="pki-template-san">+ Alternative Names (SAN) <span className="text-danger">*</span>+ <Tooltip hoverable delayDuration={50}>+ <TooltipTrigger asChild>+ <CircleHelpIcon className="size-3.5 text-muted" />+ </TooltipTrigger>+ <TooltipContent className="max-w-xs text-center">+ This field accepts limited regular expressions: spaces, *, ., @, -, \ (for+ escaping), and alphanumeric characters only+ </TooltipContent>+ </Tooltip>+ </FieldLabel>+ <FieldContent>+ <Input+ {...field}+ id="pki-template-san"+ placeholder="service\.acme.\..*"+ isError={Boolean(error)}+ />+ <FieldError errors={[error]} />+ </FieldContent>+ </Field>+ )}+ />+ <Controller+ control={control}+ name="ttl"+ render={({ field, fieldState: { error } }) => (+ <Field>+ <FieldLabel htmlFor="pki-template-ttl">+ Max TTL <span className="text-danger">*</span>+ </FieldLabel>+ <FieldContent>+ <Input+ {...field}+ id="pki-template-ttl"+ placeholder="2 days, 1d, 2h, 1y, ..."+ isError={Boolean(error)}+ />+ <FieldError errors={[error]} />+ </FieldContent>+ </Field>+ )}+ />+ <Accordion type="single" collapsible variant="ghost" className="w-full">+ <AccordionItem value="key-usages" className="border-b-0">+ <AccordionTrigger>Key Usage</AccordionTrigger>+ <AccordionContent>+ <Controller+ control={control}+ name="keyUsages"+ render={({ field: { onChange, value }, fieldState: { error } }) => {+ return (+ <Field className="mb-7">+ <FieldLabel>Key Usage</FieldLabel>+ <FieldContent>+ <div className="mt-2 grid grid-cols-2 gap-2">+ {KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => {+ return (+ <div key={optionValue} className="flex items-center gap-3">+ <Checkbox+ id={`key-usage-${optionValue}`}+ variant="project"+ isChecked={value[optionValue]}+ onCheckedChange={(state) => {+ onChange({+ ...value,+ [optionValue]: state+ });+ }}+ />+ <label+ htmlFor={`key-usage-${optionValue}`}+ className="cursor-pointer text-sm text-foreground"+ >+ {label}+ </label>+ </div>+ );+ })}+ </div>+ <FieldError errors={[error]} />+ </FieldContent>+ </Field>+ );+ }}+ />+ <Controller+ control={control}+ name="extendedKeyUsages"+ render={({ field: { onChange, value }, fieldState: { error } }) => {+ return (+ <Field className="mb-7">+ <FieldLabel>Extended Key Usage</FieldLabel>+ <FieldContent>+ <div className="mt-2 grid grid-cols-2 gap-2">+ {EXTENDED_KEY_USAGES_OPTIONS.map(({ label, value: optionValue }) => {+ return (+ <div key={optionValue} className="flex items-center gap-3">+ <Checkbox+ id={`extended-key-usage-${optionValue}`}+ variant="project"+ isChecked={value[optionValue]}+ onCheckedChange={(state) => {+ onChange({+ ...value,+ [optionValue]: state+ });+ }}+ />+ <label+ htmlFor={`extended-key-usage-${optionValue}`}+ className="cursor-pointer text-sm text-foreground"+ >+ {label}+ </label>+ </div>+ );+ })}+ </div>+ <FieldError errors={[error]} />+ </FieldContent>+ </Field>+ );+ }}+ />+ </AccordionContent>+ </AccordionItem>+ </Accordion>+ </fieldset>+ <SheetFooter className="justify-end border-t">+ <Button variant="ghost" isDisabled={isSubmitting} onClick={onCancel}>+ Cancel+ </Button>+ <Button+ variant="project"+ type="submit"+ isPending={isSubmitting}+ isDisabled={isSubmitting}+ >+ Save+ </Button>+ </SheetFooter>+ </form>+ {caCreationModals}+ </>);};diff --git a/frontend/src/views/PkiAlertsV2Page/PkiAlertsV2Page.tsx b/frontend/src/views/PkiAlertsV2Page/PkiAlertsV2Page.tsxindex 752bf1f579..69b73418a0 100644--- a/frontend/src/views/PkiAlertsV2Page/PkiAlertsV2Page.tsx+++ b/frontend/src/views/PkiAlertsV2Page/PkiAlertsV2Page.tsx@@ -1,21 +1,30 @@import { useState } from "react";-import { faSearch } from "@fortawesome/free-solid-svg-icons";-import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";+import { SearchIcon } from "lucide-react";import { createNotification } from "@app/components/notifications";import {- Input,+ Badge,+ Card,+ CardContent,+ CardDescription,+ CardFooter,+ CardHeader,+ CardTitle,+ ConfirmationAlertDialog,+ Empty,+ EmptyHeader,+ EmptyTitle,+ InputGroup,+ InputGroupAddon,+ InputGroupInput,Pagination,- Skeleton,Table,- TableContainer,- TBody,- Td,- Th,- THead,- Tr-} from "@app/components/v2";-import { ConfirmationAlertDialog } from "@app/components/v3";+ TableBody,+ TableHead,+ TableHeader,+ TableRow,+ TableSkeletonRows+} from "@app/components/v3";import { useDebounce } from "@app/hooks";import { useDeletePkiAlertV2, useGetPkiAlertsV2 } from "@app/hooks/api/pkiAlertsV2";@@ -71,124 +80,88 @@ export const PkiAlertsV2Page = ({ hideContainer = false }: Props) => {const totalPages = Math.ceil((alertsData?.total || 0) / perPage);- const renderTableContent = () => {- if (isLoading) {- return Array.from({ length: 5 }, (_, index) => (- <Tr key={`skeleton-${index}`}>- <Td>- <Skeleton className="h-4 w-32" />- </Td>- <Td>- <Skeleton className="h-4 w-24" />- </Td>- <Td>- <Skeleton className="h-4 w-16" />- </Td>- <Td>- <Skeleton className="h-4 w-16" />- </Td>- <Td>- <Skeleton className="h-4 w-20" />- </Td>- <Td className="text-right">- <Skeleton className="ml-auto h-4 w-24" />- </Td>- </Tr>- ));- }-- if (alertsData?.alerts?.length) {- return alertsData.alerts.map((alert) => (- <PkiAlertV2Row- key={alert.id}- alert={alert}- onView={() => setViewModal({ isOpen: true, alertId: alert.id })}- onDelete={() =>- setDeleteModal({- isOpen: true,- alertId: alert.id,- name: alert.name- })- }- />- ));- }-- return (- <Tr>- <Td colSpan={6} className="py-8 text-center text-muted-cool">- {search ? "No alerts found matching your search." : "No PKI alerts configured yet."}- </Td>- </Tr>- );- };-return (- <div className={hideContainer ? "" : "container mx-auto p-6"}>- <div className="flex w-full flex-col gap-3 rounded-lg border border-border-control bg-surface-base px-4 py-3">- <div className="flex items-center justify-between border-b border-border-emphasis pb-2">- <div className="flex items-center gap-x-2">- <h3 className="text-lg font-normal text-foreground">Certificate Alerts</h3>- <span className="rounded bg-surface-active px-2 py-0.5 text-xs tracking-wide text-foreground-secondary uppercase">- Legacy- </span>- </div>- <p className="text-xs text-label-secondary">+ <div className={hideContainer ? "" : "mx-auto max-w-8xl"}>+ <Card>+ <CardHeader>+ <CardTitle>+ Certificate Alerts <Badge variant="neutral">Legacy</Badge>+ </CardTitle>+ <CardDescription>Legacy alerts can only be viewed or deleted. Create new alerts in an application'sSettings tab, or under Settings > Alerts for all of Certificate Manager.- </p>- </div>-- <div className="mb-4 flex items-center">- <div className="relative w-full">- <FontAwesomeIcon- icon={faSearch}- className="absolute top-1/2 left-3 -translate-y-1/2 transform text-muted-cool"- />- <Input+ </CardDescription>+ <InputGroup>+ <InputGroupAddon>+ <SearchIcon />+ </InputGroupAddon>+ <InputGroupInput+ aria-label="Search alerts"placeholder="Search alerts..."value={search}- onChange={(e) => setSearch(e.target.value)}- className="w-full pl-10"+ onChange={(event) => setSearch(event.target.value)}/>- </div>- </div>-- <TableContainer>- <Table>- <THead>- <Tr>- <Th>Name</Th>- <Th>Event Type</Th>- <Th>Status</Th>- <Th>Alert Before</Th>- <Th>Last Run</Th>- <Th className="text-right">Actions</Th>- </Tr>- </THead>- <TBody>{renderTableContent()}</TBody>- </Table>- </TableContainer>-+ </InputGroup>+ </CardHeader>+ <CardContent>+ {!isLoading && !alertsData?.alerts?.length ? (+ <Empty className="border">+ <EmptyHeader>+ <EmptyTitle>+ {search+ ? "No alerts found matching your search."+ : "No PKI alerts configured yet."}+ </EmptyTitle>+ </EmptyHeader>+ </Empty>+ ) : (+ <Table>+ <TableHeader>+ <TableRow>+ <TableHead>Name</TableHead>+ <TableHead>Event Type</TableHead>+ <TableHead>Status</TableHead>+ <TableHead>Alert Before</TableHead>+ <TableHead>Last Run</TableHead>+ <TableHead className="text-right">Actions</TableHead>+ </TableRow>+ </TableHeader>+ <TableBody>+ {isLoading ? (+ <TableSkeletonRows columns={6} rows={5} />+ ) : (+ alertsData?.alerts.map((alert) => (+ <PkiAlertV2Row+ key={alert.id}+ alert={alert}+ onView={() => setViewModal({ isOpen: true, alertId: alert.id })}+ onDelete={() =>+ setDeleteModal({ isOpen: true, alertId: alert.id, name: alert.name })+ }+ />+ ))+ )}+ </TableBody>+ </Table>+ )}+ </CardContent>{totalPages > 1 && (- <div className="mt-4 flex justify-center">+ <CardFooter><Pagination- count={totalPages}+ count={alertsData?.total || 0}page={page}onChangePage={setPage}perPage={perPage}onChangePerPage={setPerPage}/>- </div>+ </CardFooter>)}- </div>-+ </Card><ViewPkiAlertV2ModalisOpen={viewModal.isOpen}onOpenChange={(isOpen) => setViewModal({ isOpen, alertId: undefined })}alertId={viewModal.alertId}/>-<ConfirmationAlertDialogisOpen={deleteModal.isOpen}description="This action is irreversible."diff --git a/frontend/src/views/PkiAlertsV2Page/components/PkiAlertV2Row.tsx b/frontend/src/views/PkiAlertsV2Page/components/PkiAlertV2Row.tsxindex 9b151d7027..88fc94cac4 100644--- a/frontend/src/views/PkiAlertsV2Page/components/PkiAlertV2Row.tsx+++ b/frontend/src/views/PkiAlertsV2Page/components/PkiAlertV2Row.tsx@@ -2,7 +2,6 @@ import { faCircleInfo } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";import { EyeIcon, MoreHorizontalIcon, Trash2Icon } from "lucide-react";-import { Td, Tr } from "@app/components/v2";import {Badge,DropdownMenu,@@ -10,6 +9,8 @@ import {DropdownMenuItem,DropdownMenuTrigger,IconButton,+ TableCell,+ TableRow,Tooltip,TooltipContent,TooltipTrigger@@ -26,8 +27,8 @@ interface Props {export const PkiAlertV2Row = ({ alert, onView, onDelete }: Props) => {return (- <Tr>- <Td>+ <TableRow>+ <TableCell><div className="flex items-center gap-2"><div className="font-medium text-foreground-cool">{alert.name}</div>{alert.description && (@@ -39,23 +40,23 @@ export const PkiAlertV2Row = ({ alert, onView, onDelete }: Props) => {</Tooltip>)}</div>- </Td>- <Td>+ </TableCell>+ <TableCell><span className="text-label-cool">{formatEventType(alert.eventType)}</span>- </Td>- <Td>+ </TableCell>+ <TableCell><Badge variant={alert.enabled ? "success" : "neutral"}>{alert.enabled ? "Enabled" : "Disabled"}</Badge>- </Td>- <Td className="text-label-cool">+ </TableCell>+ <TableCell className="text-label-cool">{alert.eventType === PkiAlertEventTypeV2.EXPIRATION ? (formatAlertBefore(alert.alertBefore)) : (<span className="text-surface-selected">—</span>)}- </Td>- <Td>+ </TableCell>+ <TableCell>{alert.lastRun ? (<Tooltip hoverable delayDuration={50}><TooltipTrigger asChild>@@ -82,8 +83,8 @@ export const PkiAlertV2Row = ({ alert, onView, onDelete }: Props) => {) : (<span className="text-surface-selected">—</span>)}- </Td>- <Td className="text-right">+ </TableCell>+ <TableCell className="text-right"><DropdownMenu><DropdownMenuTrigger asChild><IconButton size="xs" variant="ghost" aria-label="Alert actions">@@ -101,7 +102,7 @@ export const PkiAlertV2Row = ({ alert, onView, onDelete }: Props) => {</DropdownMenuItem></DropdownMenuContent></DropdownMenu>- </Td>- </Tr>+ </TableCell>+ </TableRow>);};diff --git a/frontend/src/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal.tsx b/frontend/src/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal.tsxindex 046c7682bc..5feb8af673 100644--- a/frontend/src/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal.tsx+++ b/frontend/src/views/PkiAlertsV2Page/components/ViewPkiAlertV2Modal.tsx@@ -1,8 +1,21 @@import { faKey } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";-import { GenericFieldLabel, Modal, ModalContent, Skeleton, Tooltip } from "@app/components/v2";-import { Badge } from "@app/components/v3";+import {+ Badge,+ Button,+ Sheet,+ SheetClose,+ SheetContent,+ SheetDescription,+ SheetFooter,+ SheetHeader,+ SheetTitle,+ Skeleton,+ Tooltip,+ TooltipContent,+ TooltipTrigger+} from "@app/components/v3";import {PkiAlertChannelTypeV2,PkiAlertEventTypeV2,@@ -48,32 +61,54 @@ export const ViewPkiAlertV2Modal = ({ isOpen, onOpenChange, alertId }: Props) =>if (isLoadingAlert) {return (- <Modal isOpen={isOpen} onOpenChange={onOpenChange}>- <ModalContent title="Certificate Alert Details" className="max-w-3xl">- <div className="space-y-4">+ <Sheet open={isOpen} onOpenChange={onOpenChange}>+ <SheetContent size="form">+ <SheetHeader>+ <SheetTitle>Certificate Alert Details</SheetTitle>+ <SheetDescription>View certificate details.</SheetDescription>+ </SheetHeader>+ <div className="min-h-0 flex-1 space-y-4 overflow-y-auto p-4"><Skeleton className="h-6 w-1/3" /><Skeleton className="h-24 w-full" /><Skeleton className="h-40 w-full" /></div>- </ModalContent>- </Modal>+ <SheetFooter className="justify-end border-t">+ <SheetClose asChild>+ <Button variant="ghost">Close</Button>+ </SheetClose>+ </SheetFooter>+ </SheetContent>+ </Sheet>);}if (!alert) {return (- <Modal isOpen={isOpen} onOpenChange={onOpenChange}>- <ModalContent title="Certificate Alert Details" className="max-w-3xl">+ <Sheet open={isOpen} onOpenChange={onOpenChange}>+ <SheetContent size="form">+ <SheetHeader>+ <SheetTitle>Certificate Alert Details</SheetTitle>+ <SheetDescription>View certificate details.</SheetDescription>+ </SheetHeader><p className="py-8 text-center text-sm text-muted">Alert not found.</p>- </ModalContent>- </Modal>+ <SheetFooter className="justify-end border-t">+ <SheetClose asChild>+ <Button variant="ghost">Close</Button>+ </SheetClose>+ </SheetFooter>+ </SheetContent>+ </Sheet>);}return (- <Modal isOpen={isOpen} onOpenChange={onOpenChange}>- <ModalContent title="Certificate Alert Details" className="max-w-3xl">- <div className="space-y-6">+ <Sheet open={isOpen} onOpenChange={onOpenChange}>+ <SheetContent size="form">+ <SheetHeader>+ <SheetTitle>Certificate Alert Details</SheetTitle>+ <SheetDescription>View certificate details.</SheetDescription>+ </SheetHeader>+ <div className="min-h-0 flex-1 space-y-6 overflow-y-auto p-4"><div className="flex items-start justify-between gap-3"><div className="min-w-0"><p className="text-xs text-muted">Alert Name</p>@@ -88,20 +123,30 @@ export const ViewPkiAlertV2Modal = ({ isOpen, onOpenChange, alertId }: Props) =><div className="space-y-3"><SectionHeader title="Basic Information" /><div className="grid grid-cols-1 gap-x-6 gap-y-4 md:grid-cols-2 lg:grid-cols-3">- <GenericFieldLabel label="Event Type">- {formatEventType(alert.eventType)}- </GenericFieldLabel>+ <div>+ <p className="text-xs text-accent">Event Type</p>+ <div className="text-sm text-foreground">{formatEventType(alert.eventType)}</div>+ </div>{alert.eventType === PkiAlertEventTypeV2.EXPIRATION && (<>- <GenericFieldLabel label="Alert Before">- {formatAlertBefore(alert.alertBefore, undefined)}- </GenericFieldLabel>- <GenericFieldLabel label="Repeat daily until expiry">- {alert.notificationConfig?.enableDailyNotification ? "Enabled" : "Disabled"}- </GenericFieldLabel>+ <div>+ <p className="text-xs text-accent">Alert Before</p>+ <div className="text-sm text-foreground">+ {formatAlertBefore(alert.alertBefore, undefined)}+ </div>+ </div>+ <div>+ <p className="text-xs text-accent">Repeat daily until expiry</p>+ <div className="text-sm text-foreground">+ {alert.notificationConfig?.enableDailyNotification ? "Enabled" : "Disabled"}+ </div>+ </div></>)}- <GenericFieldLabel label="Created">{formatDate(alert.createdAt)}</GenericFieldLabel>+ <div>+ <p className="text-xs text-accent">Created</p>+ <div className="text-sm text-foreground">{formatDate(alert.createdAt)}</div>+ </div></div></div>@@ -128,8 +173,13 @@ export const ViewPkiAlertV2Modal = ({ isOpen, onOpenChange, alertId }: Props) =>{channel.channelType === PkiAlertChannelTypeV2.WEBHOOK &&(channel.config as TPkiAlertChannelConfigWebhookResponse)?.hasSigningSecret && (- <Tooltip content="Signed webhook">- <FontAwesomeIcon icon={faKey} className="text-xs text-muted" />+ <Tooltip>+ <TooltipTrigger asChild>+ <span className="inline-flex">+ <FontAwesomeIcon icon={faKey} className="text-xs text-muted" />+ </span>+ </TooltipTrigger>+ <TooltipContent>Signed webhook</TooltipContent></Tooltip>)}{!channel.enabled && <Badge variant="neutral">Disabled</Badge>}@@ -145,8 +195,13 @@ export const ViewPkiAlertV2Modal = ({ isOpen, onOpenChange, alertId }: Props) =>const displayed = recipients.slice(0, 3).join(", ");const text = count <= 3 ? displayed : `${displayed} +${count - 3} more`;return count > 3 ? (- <Tooltip content={recipients.join(", ")}>- <p className="mt-1 cursor-help text-xs text-muted">{text}</p>+ <Tooltip>+ <TooltipTrigger asChild>+ <span className="inline-flex">+ <p className="mt-1 cursor-help text-xs text-muted">{text}</p>+ </span>+ </TooltipTrigger>+ <TooltipContent>{recipients.join(", ")}</TooltipContent></Tooltip>) : (<p className="mt-1 text-xs text-muted">{text}</p>@@ -172,7 +227,12 @@ export const ViewPkiAlertV2Modal = ({ isOpen, onOpenChange, alertId }: Props) =>)}</div></div>- </ModalContent>- </Modal>+ <SheetFooter className="justify-end border-t">+ <SheetClose asChild>+ <Button variant="ghost">Close</Button>+ </SheetClose>+ </SheetFooter>+ </SheetContent>+ </Sheet>);};