import { ReactNode } from "react"; import { faRotate } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { format } from "date-fns"; import { Modal, ModalContent, Spinner } from "@app/components/v2"; import { SECRET_ROTATION_MAP } from "@app/helpers/secretRotationsV2"; import { SecretRotation, TSecretRotationV2, useViewSecretRotationV2GeneratedCredentials } from "@app/hooks/api/secretRotationsV2"; import { ViewSqlRotationGeneratedCredentials } from "./shared"; type Props = { secretRotation?: TSecretRotationV2; isOpen: boolean; onOpenChange: (isOpen: boolean) => void; }; type ContentProps = { secretRotation: TSecretRotationV2; }; const Content = ({ secretRotation }: ContentProps) => { const { id: rotationId, type, nextRotationAt } = secretRotation; const { data: generatedCredentialsResponse, isPending } = useViewSecretRotationV2GeneratedCredentials({ rotationId, type }); if (isPending) { return (

Loading generated credentials...

); } let Component: ReactNode; switch (generatedCredentialsResponse!.type) { case SecretRotation.PostgresCredentials: case SecretRotation.MsSqlCredentials: Component = ( ); break; default: throw new Error("Unhandled View Generated Credential Rotation Type"); } return (
{Component} {nextRotationAt && (
Next rotation occurs on: {format(nextRotationAt, "MM/dd/yyyy")} at{" "} {format(nextRotationAt, "h:mm aa")}{" "} (Local Time)
)}
); }; export const ViewSecretRotationV2GeneratedCredentialsModal = ({ isOpen, onOpenChange, secretRotation }: Props) => { if (!secretRotation) return null; const rotationType = SECRET_ROTATION_MAP[secretRotation.type].name; return ( { event.preventDefault(); }} title="Generated Credentials" subTitle={`View the current and retired ${rotationType}.`} > ); };