174 lines
7.9 KiB
TypeScript
174 lines
7.9 KiB
TypeScript
import React, { useState, useEffect } from 'react';
|
|
import { motion, AnimatePresence } from 'framer-motion';
|
|
import { X, Settings, Key, Sparkles, Image as ImageIcon, Lightbulb, Box } from 'lucide-react';
|
|
import { cn } from '../lib/utils';
|
|
|
|
interface ApiSettingsModalProps {
|
|
isOpen: boolean;
|
|
onClose: () => void;
|
|
}
|
|
|
|
export const ApiSettingsModal: React.FC<ApiSettingsModalProps> = ({ isOpen, onClose }) => {
|
|
const [falApiKey, setFalApiKey] = useState('');
|
|
const [tripoApiKey, setTripoApiKey] = useState('');
|
|
const [meshyApiKey, setMeshyApiKey] = useState('');
|
|
const [stabilityApiKey, setStabilityApiKey] = useState('');
|
|
const [openAiKey, setOpenAiKey] = useState('');
|
|
|
|
useEffect(() => {
|
|
if (isOpen) {
|
|
setFalApiKey(localStorage.getItem('FAL_API_KEY') || '');
|
|
setTripoApiKey(localStorage.getItem('TRIPO_API_KEY') || '');
|
|
setMeshyApiKey(localStorage.getItem('MESHY_API_KEY') || '');
|
|
setStabilityApiKey(localStorage.getItem('stability_api_key') || '');
|
|
setOpenAiKey(localStorage.getItem('openai_api_key') || '');
|
|
}
|
|
}, [isOpen]);
|
|
|
|
const saveKeys = () => {
|
|
localStorage.setItem('FAL_API_KEY', falApiKey);
|
|
localStorage.setItem('TRIPO_API_KEY', tripoApiKey);
|
|
localStorage.setItem('MESHY_API_KEY', meshyApiKey);
|
|
localStorage.setItem('stability_api_key', stabilityApiKey);
|
|
localStorage.setItem('openai_api_key', openAiKey);
|
|
onClose();
|
|
};
|
|
|
|
if (!isOpen) return null;
|
|
|
|
return (
|
|
<AnimatePresence>
|
|
<div className="fixed inset-0 z-[150] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm">
|
|
<motion.div
|
|
initial={{ opacity: 0, scale: 0.95, y: 20 }}
|
|
animate={{ opacity: 1, scale: 1, y: 0 }}
|
|
exit={{ opacity: 0, scale: 0.95, y: 20 }}
|
|
className="w-full max-w-2xl bg-zinc-900 border border-zinc-800 rounded-xl shadow-2xl overflow-hidden flex flex-col h-[80vh]"
|
|
>
|
|
{/* Header */}
|
|
<div className="h-14 bg-zinc-950 flex items-center justify-between px-6 border-b border-zinc-800 shrink-0">
|
|
<div className="flex items-center gap-3">
|
|
<div className="w-8 h-8 rounded-lg bg-gradient-to-tr from-zinc-700 to-zinc-600 flex items-center justify-center">
|
|
<Settings size={16} className="text-white" />
|
|
</div>
|
|
<div>
|
|
<h2 className="text-sm font-bold text-zinc-100">Global API Settings</h2>
|
|
<p className="text-[10px] text-zinc-400">Configure your API keys for AI generation features</p>
|
|
</div>
|
|
</div>
|
|
|
|
<button onClick={onClose} className="p-2 hover:bg-zinc-800 rounded-lg transition-colors">
|
|
<X size={18} className="text-zinc-400" />
|
|
</button>
|
|
</div>
|
|
|
|
{/* Content */}
|
|
<div className="flex-1 overflow-y-auto p-6 bg-zinc-900/50 flex flex-col gap-6 custom-scrollbar">
|
|
|
|
{/* 3D Generation */}
|
|
<div className="flex flex-col gap-4">
|
|
<h3 className="text-xs font-bold text-zinc-500 uppercase tracking-widest flex items-center gap-2">
|
|
<Box size={14} /> Image-to-3D Providers
|
|
</h3>
|
|
|
|
<div className="grid grid-cols-1 gap-4 pl-2 border-l-2 border-zinc-800">
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex items-center justify-between">
|
|
<label className="text-sm font-bold text-zinc-300">Fal.ai Key</label>
|
|
<span className="text-[10px] text-zinc-500">For Hunyuan3D</span>
|
|
</div>
|
|
<input
|
|
type="password"
|
|
placeholder="Enter Fal.ai API Key..."
|
|
value={falApiKey}
|
|
onChange={(e) => setFalApiKey(e.target.value)}
|
|
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-zinc-500"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex items-center justify-between">
|
|
<label className="text-sm font-bold text-zinc-300">Tripo3D Key</label>
|
|
<span className="text-[10px] text-zinc-500">For Native Tripo3D</span>
|
|
</div>
|
|
<input
|
|
type="password"
|
|
placeholder="Enter Tripo3D API Key..."
|
|
value={tripoApiKey}
|
|
onChange={(e) => setTripoApiKey(e.target.value)}
|
|
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-zinc-500"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex items-center justify-between">
|
|
<label className="text-sm font-bold text-zinc-300">Meshy.ai Key</label>
|
|
<span className="text-[10px] text-zinc-500">For Native Meshy</span>
|
|
</div>
|
|
<input
|
|
type="password"
|
|
placeholder="Enter Meshy API Key..."
|
|
value={meshyApiKey}
|
|
onChange={(e) => setMeshyApiKey(e.target.value)}
|
|
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-zinc-500"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="h-px bg-zinc-800/50 w-full" />
|
|
|
|
{/* Viz AI (Image-to-Image & LLM) */}
|
|
<div className="flex flex-col gap-4">
|
|
<h3 className="text-xs font-bold text-zinc-500 uppercase tracking-widest flex items-center gap-2">
|
|
<Sparkles size={14} /> Titan3d AI & Mockup Generation
|
|
</h3>
|
|
|
|
<div className="grid grid-cols-1 gap-4 pl-2 border-l-2 border-zinc-800">
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex items-center justify-between">
|
|
<label className="text-sm font-bold text-blue-400">Stability AI Key</label>
|
|
<span className="text-[10px] text-zinc-500">For Scene rendering (Image-to-Image)</span>
|
|
</div>
|
|
<input
|
|
type="password"
|
|
placeholder="sk-..."
|
|
value={stabilityApiKey}
|
|
onChange={(e) => setStabilityApiKey(e.target.value)}
|
|
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-blue-500/50"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex items-center justify-between">
|
|
<label className="text-sm font-bold text-green-400">OpenAI Key</label>
|
|
<span className="text-[10px] text-zinc-500">For AI Idea Prompt Generation</span>
|
|
</div>
|
|
<input
|
|
type="password"
|
|
placeholder="sk-..."
|
|
value={openAiKey}
|
|
onChange={(e) => setOpenAiKey(e.target.value)}
|
|
className="bg-zinc-950 border border-zinc-800 rounded-lg px-4 py-2 text-sm text-white focus:outline-none focus:border-green-500/50"
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="p-6 bg-zinc-950 border-t border-zinc-800 shrink-0">
|
|
<button
|
|
onClick={saveKeys}
|
|
className="w-full py-3 bg-white hover:bg-zinc-200 text-black font-bold rounded-xl transition-colors flex items-center justify-center gap-2"
|
|
>
|
|
<Key size={16} />
|
|
Save Keys
|
|
</button>
|
|
</div>
|
|
</motion.div>
|
|
</div>
|
|
</AnimatePresence>
|
|
);
|
|
};
|