feat: init apikey widget
This commit is contained in:
parent
36bab4ddaa
commit
9facc1621c
|
|
@ -0,0 +1,126 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
|
||||
interface ApiKeyWidgetProps {
|
||||
organizationSlug: string;
|
||||
projectSlug: string;
|
||||
apiKey: string;
|
||||
onRevoke: () => void;
|
||||
}
|
||||
|
||||
export function ApiKeyWidget({
|
||||
organizationSlug,
|
||||
projectSlug,
|
||||
apiKey,
|
||||
onRevoke,
|
||||
}: ApiKeyWidgetProps) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const [keyVisible, setKeyVisible] = useState(false);
|
||||
|
||||
return (
|
||||
<div className="fixed top-4 right-4 z-40">
|
||||
{!expanded ? (
|
||||
// Minimized badge
|
||||
<button
|
||||
onClick={() => setExpanded(true)}
|
||||
className="group px-4 py-2 bg-slate-900/95 backdrop-blur-sm border border-slate-700 rounded-full hover:border-amber-500/50 transition-all shadow-lg"
|
||||
aria-label="Expand API key details"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="w-2 h-2 rounded-full bg-green-400"></div>
|
||||
<span className="text-sm text-gray-300 font-medium">
|
||||
{organizationSlug} / {projectSlug}
|
||||
</span>
|
||||
<svg
|
||||
className="w-4 h-4 text-gray-400 group-hover:text-amber-400 transition-colors"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M19 9l-7 7-7-7"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
</button>
|
||||
) : (
|
||||
// Expanded card
|
||||
<div className="w-96 p-4 bg-slate-900/95 backdrop-blur-sm border border-slate-700 rounded-2xl shadow-2xl animate-fade-in">
|
||||
<div className="flex items-start justify-between mb-3">
|
||||
<div>
|
||||
<h3 className="text-sm font-semibold text-white mb-1">API Key Active</h3>
|
||||
<p className="text-xs text-gray-400">
|
||||
{organizationSlug} / {projectSlug}
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setExpanded(false)}
|
||||
className="w-8 h-8 rounded-lg bg-slate-800 hover:bg-slate-700 text-gray-400 hover:text-white flex items-center justify-center transition-colors"
|
||||
aria-label="Minimize API key details"
|
||||
>
|
||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M5 15l7-7 7 7"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="mb-3">
|
||||
<label className="text-xs text-gray-500 mb-1 block">Key</label>
|
||||
<div className="flex gap-2">
|
||||
<div className="flex-1 px-3 py-2 bg-slate-800 border border-slate-700 rounded-lg text-xs text-gray-300 font-mono overflow-hidden">
|
||||
{keyVisible ? apiKey : '•'.repeat(32)}
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setKeyVisible(!keyVisible)}
|
||||
className="px-3 py-2 bg-slate-800 hover:bg-slate-700 border border-slate-700 rounded-lg text-gray-400 hover:text-white transition-colors"
|
||||
aria-label={keyVisible ? 'Hide API key' : 'Show API key'}
|
||||
>
|
||||
{keyVisible ? (
|
||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"
|
||||
/>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
strokeWidth={2}
|
||||
d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={onRevoke}
|
||||
className="w-full px-3 py-2 bg-red-900/20 hover:bg-red-900/30 border border-red-700/50 hover:border-red-600 rounded-lg text-red-400 text-xs font-medium transition-colors"
|
||||
>
|
||||
Revoke & Use Different Key
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
Reference in New Issue