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 ( +
+ {/* Tab/Header Bar */} +
+
+ + {filename} +
+
+ + + +
+
+ + {/* Editor Body */} +
+ + + {lines.map((line, idx) => { + return ( + + + + ); + })} + +
+
+
+ {line.isComment ? ( + {line.val} + ) : ( + <> + {line.key} + = + {revealAll ? ( + {line.val} + ) : ( + •••••••••••••••••••• + )} + + )} +
+
+
+
+
+ ); +} function getEnvFileContent(props: { projectId: string, @@ -90,6 +201,7 @@ export function APIEnvKeys(props: { + ); } @@ -141,12 +248,6 @@ export function ViteEnvKeys(props: { .join("\n"); return ( - + ); }