"use client"; import { useState } from "react"; import { Credenza, CredenzaBody, CredenzaClose, CredenzaContent, CredenzaDescription, CredenzaFooter, CredenzaHeader, CredenzaTitle } from "@app/components/Credenza"; import { Button } from "@app/components/ui/button"; import { Alert, AlertDescription, AlertTitle } from "@app/components/ui/alert"; import { InfoIcon, AlertTriangle } from "lucide-react"; import { useTranslations } from "next-intl"; import { InfoSection, InfoSectionContent, InfoSections, InfoSectionTitle } from "@app/components/InfoSection"; import CopyToClipboard from "@app/components/CopyToClipboard"; import CopyTextBox from "@app/components/CopyTextBox"; import { QRCodeCanvas } from "qrcode.react"; type CredentialType = "site-wireguard" | "site-newt" | "client-olm" | "remote-exit-node"; interface RegenerateCredentialsModalProps { open: boolean; onOpenChange: (open: boolean) => void; type: CredentialType; onConfirmRegenerate: () => Promise; dashboardUrl: string; credentials?: { // For WireGuard sites wgConfig?: string; Id?: string; Secret?: string; }; } export default function RegenerateCredentialsModal({ open, onOpenChange, type, onConfirmRegenerate, dashboardUrl, credentials }: RegenerateCredentialsModalProps) { const t = useTranslations(); const [stage, setStage] = useState<"confirm" | "show">("confirm"); const [loading, setLoading] = useState(false); const handleConfirm = async () => { try { setLoading(true); await onConfirmRegenerate(); setStage("show"); } catch (error) { } finally { setLoading(false); } }; const handleClose = () => { setStage("confirm"); onOpenChange(false); }; const getTitle = () => { if (stage === "confirm") { return t("regeneratecredentials"); } switch (type) { case "site-wireguard": return t("WgConfiguration"); case "site-newt": return t("siteNewtCredentials"); case "client-olm": return t("clientOlmCredentials"); case "remote-exit-node": return t("remoteExitNodeCreate.generate.title"); } }; const getDescription = () => { if (stage === "confirm") { return t("regenerateCredentialsWarning"); } switch (type) { case "site-wireguard": return t("WgConfigurationDescription"); case "site-newt": return t("siteNewtCredentialsDescription"); case "client-olm": return t("clientOlmCredentialsDescription"); case "remote-exit-node": return t("remoteExitNodeCreate.generate.description"); } }; return ( {getTitle()} {getDescription()} {stage === "confirm" ? ( {t("warning")} {t("regenerateCredentialsConfirmation")} ) : ( <> {credentials?.wgConfig && (
{t("copyandsavethesecredentials")} {t("copyandsavethesecredentialsdescription")}
)} {credentials?.Id && credentials.Secret && (
{t("endpoint")} {t("Id")} {t("SecretKey")} {t("copyandsavethesecredentials")} {t("copyandsavethesecredentialsdescription")}
)} )}
{stage === "confirm" ? ( <> ) : ( )}
); }