diff --git a/apps/dashboard/src/components/env-keys.tsx b/apps/dashboard/src/components/env-keys.tsx index 20488d943..62d4dbffc 100644 --- a/apps/dashboard/src/components/env-keys.tsx +++ b/apps/dashboard/src/components/env-keys.tsx @@ -1,5 +1,116 @@ +"use client"; + import { getPublicEnvVar } from '@/lib/env'; import { Button, CopyField, Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui"; +import React, { useState } from "react"; +import { EyeIcon, EyeSlashIcon, CopyIcon, CheckIcon, FileTextIcon } from "@phosphor-icons/react"; +import { cn } from "@/lib/utils"; +import { runAsynchronously } from "@hexclave/shared/dist/utils/promises"; + +type EnvFileViewerProps = { + filename: string; + value: string; +} + +export function EnvFileViewer({ filename, value }: EnvFileViewerProps) { + const [revealAll, setRevealAll] = useState(false); + const [copied, setCopied] = useState(false); + + const lines = value.split("\n").map((line, idx) => { + const eqIndex = line.indexOf("="); + if (eqIndex === -1) return { key: `comment_${idx}`, val: line, isComment: true }; + const key = line.substring(0, eqIndex); + const val = line.substring(eqIndex + 1); + return { key, val, isComment: false }; + }); + + const handleCopyAll = () => { + runAsynchronously(async () => { + await navigator.clipboard.writeText(value); + setCopied(true); + setTimeout(() => setCopied(false), 2000); + }); + }; + + return ( +
|
+
+
+
+ {line.isComment ? (
+ {line.val}
+ ) : (
+ <>
+ {line.key}
+ =
+ {revealAll ? (
+ {line.val}
+ ) : (
+ ••••••••••••••••••••
+ )}
+ >
+ )}
+
+ |
+