import { useEffect, useState } from "react"; import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useNavigate, useRouterState } from "@tanstack/react-router"; import { SecretRotationV2Form } from "@app/components/secret-rotations-v2/forms"; import { TSecretRotationV2Form } from "@app/components/secret-rotations-v2/forms/schemas"; import { SecretRotationV2ModalHeader } from "@app/components/secret-rotations-v2/SecretRotationV2ModalHeader"; import { SecretRotationV2Select } from "@app/components/secret-rotations-v2/SecretRotationV2Select"; import { Modal, ModalContent } from "@app/components/v2"; import { ProjectEnv } from "@app/hooks/api/projects/types"; import { SecretRotation, TSecretRotationV2 } from "@app/hooks/api/secretRotationsV2"; type SharedProps = { secretPath: string; environment?: string; environments?: ProjectEnv[]; }; type Props = { isOpen: boolean; onOpenChange: (isOpen: boolean) => void; } & SharedProps; type ContentProps = { onComplete: (secretRotation: TSecretRotationV2) => void; selectedRotation: SecretRotation | null; setSelectedRotation: (selectedRotation: SecretRotation | null) => void; initialFormData?: Partial; onCancel: () => void; } & SharedProps; const Content = ({ setSelectedRotation, selectedRotation, initialFormData, onCancel, ...props }: ContentProps) => { if (selectedRotation) { return ( ); } return ; }; export const CreateSecretRotationV2Modal = ({ onOpenChange, isOpen, ...props }: Props) => { const [selectedRotation, setSelectedRotation] = useState(null); const [initialFormData, setInitialFormData] = useState>(); const { location: { search: { connectionId, connectionName, ...search }, pathname } } = useRouterState(); const navigate = useNavigate(); useEffect(() => { if (connectionId && connectionName) { const storedFormData = localStorage.getItem("secretRotationFormData"); if (!storedFormData) return; let form: Partial = {}; try { form = JSON.parse(storedFormData) as TSecretRotationV2Form; } catch { return; } finally { localStorage.removeItem("secretRotationFormData"); } onOpenChange(true); setSelectedRotation(form.type ?? null); setInitialFormData({ ...form, connection: { id: connectionId, name: connectionName } }); navigate({ to: pathname, search }); } }, [connectionId, connectionName]); const handleReset = () => { setSelectedRotation(null); setInitialFormData(undefined); }; return ( { if (!open) { handleReset(); } onOpenChange(open); }} > ) : (
Add Secret Rotation
Docs
) } className={selectedRotation ? "max-w-2xl" : "max-w-3xl"} subTitle={ selectedRotation ? undefined : "Select a provider to create a secret rotation for." } bodyClassName="overflow-visible" > { handleReset(); onOpenChange(false); }} onCancel={handleReset} initialFormData={initialFormData} selectedRotation={selectedRotation} setSelectedRotation={setSelectedRotation} {...props} />
); };