import { faPlus } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { createNotification } from "@app/components/notifications"; import { ProjectPermissionCan } from "@app/components/permissions"; import { Button, DeleteActionModal } from "@app/components/v2"; import { ProjectPermissionActions, ProjectPermissionSub, useProject } from "@app/context"; import { CaStatus, CaType, useDeleteCa, useUpdateCa } from "@app/hooks/api"; import { usePopUp } from "@app/hooks/usePopUp"; import { ExternalCaModal } from "./ExternalCaModal"; import { ExternalCaTable } from "./ExternalCaTable"; export const ExternalCaSection = () => { const { currentProject } = useProject(); const { mutateAsync: deleteCa } = useDeleteCa(); const { mutateAsync: updateCa } = useUpdateCa(); const { popUp, handlePopUpOpen, handlePopUpClose, handlePopUpToggle } = usePopUp([ "ca", "deleteCa", "caStatus" // enable / disable ] as const); const onRemoveCaSubmit = async (caName: string, type: CaType) => { try { if (!currentProject?.id) return; await deleteCa({ caName, type, projectId: currentProject.id }); createNotification({ text: "Successfully deleted CA", type: "success" }); handlePopUpClose("deleteCa"); } catch { createNotification({ text: "Failed to delete CA", type: "error" }); } }; const onUpdateCaStatus = async ({ name, type, status }: { name: string; type: CaType; status: CaStatus; }) => { try { if (!currentProject?.slug) return; await updateCa({ caName: name, type, status, projectId: currentProject.id }); createNotification({ text: `Successfully ${status === CaStatus.ACTIVE ? "enabled" : "disabled"} CA`, type: "success" }); handlePopUpClose("caStatus"); } catch (err) { console.error(err); createNotification({ text: `Failed to ${status === CaStatus.ACTIVE ? "enable" : "disable"} CA`, type: "error" }); } }; return (

External Certificate Authorities

{(isAllowed) => ( )}
handlePopUpToggle("deleteCa", isOpen)} deleteKey="confirm" onDeleteApproved={() => onRemoveCaSubmit( (popUp?.deleteCa?.data as { name: string })?.name, (popUp?.deleteCa?.data as { type: CaType })?.type ) } /> handlePopUpToggle("caStatus", isOpen)} buttonText="Proceed" deleteKey="confirm" onDeleteApproved={() => onUpdateCaStatus( popUp?.caStatus?.data as { name: string; type: CaType; status: CaStatus } ) } />
); };