2026-10-23 19:56:38 -07:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { Button } from '@/components/ui/Button';
|
|
|
|
|
import { CopyButton } from '@/components/ui/CopyButton';
|
2026-11-18 05:18:55 +06:00
|
|
|
import { Input, Textarea } from '@/components/ui/Input';
|
2026-10-23 19:56:38 -07:00
|
|
|
import { Modal } from '@/components/ui/Modal';
|
|
|
|
|
import {
|
2026-11-17 00:24:33 +06:00
|
|
|
Table,
|
|
|
|
|
TableBody,
|
|
|
|
|
TableCell,
|
|
|
|
|
TableEmpty,
|
|
|
|
|
TableHead,
|
|
|
|
|
TableHeader,
|
|
|
|
|
TableRow,
|
|
|
|
|
TableWrap,
|
2026-10-23 19:56:38 -07:00
|
|
|
} from '@/components/ui/Table';
|
|
|
|
|
import { useToast } from '@/components/ui/Toast';
|
2026-11-16 23:10:44 +06:00
|
|
|
import { useRouter } from 'next/navigation';
|
2026-10-23 19:56:38 -07:00
|
|
|
import { useState } from 'react';
|
|
|
|
|
import type { ClientCredentials, ClientItem } from './clients/types';
|
|
|
|
|
|
|
|
|
|
interface ClientsTableProps {
|
|
|
|
|
clients: ClientItem[];
|
|
|
|
|
now: number;
|
|
|
|
|
onStatusChange: () => Promise<void>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function relativeTime(timestamp: string | undefined, now: number) {
|
|
|
|
|
if (!timestamp) return 'Never';
|
|
|
|
|
const seconds = Math.max(0, Math.floor((now - new Date(timestamp).getTime()) / 1000));
|
|
|
|
|
if (seconds < 10) return 'Just now';
|
|
|
|
|
if (seconds < 60) return `${seconds}s ago`;
|
|
|
|
|
if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`;
|
|
|
|
|
if (seconds < 86_400) return `${Math.floor(seconds / 3600)}h ago`;
|
|
|
|
|
return `${Math.floor(seconds / 86_400)}d ago`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps) {
|
2026-11-16 23:10:44 +06:00
|
|
|
const router = useRouter();
|
2026-10-23 19:56:38 -07:00
|
|
|
const { success, error } = useToast();
|
|
|
|
|
const [credentials, setCredentials] = useState<ClientCredentials | null>(null);
|
2026-11-16 21:58:18 +06:00
|
|
|
const [confirmAction, setConfirmAction] = useState<{
|
2026-11-17 20:05:00 +06:00
|
|
|
type: 'rotate' | 'revoke' | 'delete';
|
2026-11-16 21:58:18 +06:00
|
|
|
client: ClientItem;
|
|
|
|
|
} | null>(null);
|
2026-11-18 05:18:55 +06:00
|
|
|
const [editClient, setEditClient] = useState<ClientItem | null>(null);
|
|
|
|
|
const [editName, setEditName] = useState('');
|
|
|
|
|
const [editRateLimit, setEditRateLimit] = useState('100');
|
|
|
|
|
const [editError, setEditError] = useState('');
|
2026-11-16 21:58:18 +06:00
|
|
|
const [processing, setProcessing] = useState(false);
|
2026-10-23 19:56:38 -07:00
|
|
|
|
2026-11-18 05:18:55 +06:00
|
|
|
const openEditModal = (client: ClientItem) => {
|
|
|
|
|
setEditClient(client);
|
|
|
|
|
setEditName(client.name);
|
|
|
|
|
setEditRateLimit(String(client.rateLimit || 100));
|
|
|
|
|
setEditError('');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const executeEditClient = async (event: React.FormEvent<HTMLFormElement>) => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
if (!editClient) return;
|
|
|
|
|
|
|
|
|
|
const trimmedName = editName.trim();
|
|
|
|
|
const numericRateLimit = Number(editRateLimit);
|
|
|
|
|
if (!trimmedName) {
|
|
|
|
|
setEditError('Display name is required.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!Number.isFinite(numericRateLimit) || numericRateLimit < 1 || numericRateLimit > 10000) {
|
|
|
|
|
setEditError('Rate limit must be between 1 and 10,000 events/s.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setEditError('');
|
|
|
|
|
setProcessing(true);
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/api/clients/${encodeURIComponent(editClient.clientId)}`, {
|
|
|
|
|
method: 'PATCH',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
name: trimmedName,
|
|
|
|
|
rateLimit: Math.floor(numericRateLimit),
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
if (response.status === 401) {
|
|
|
|
|
window.location.assign('/vcon/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
if (!response.ok) throw new Error(data.error || 'Unable to update client');
|
|
|
|
|
success('Client updated', `${editClient.clientId} settings saved.`);
|
|
|
|
|
setEditClient(null);
|
|
|
|
|
await onStatusChange();
|
|
|
|
|
} catch (updateError) {
|
|
|
|
|
error('Client update failed', updateError instanceof Error ? updateError.message : 'Unknown error');
|
|
|
|
|
} finally {
|
|
|
|
|
setProcessing(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-16 21:58:18 +06:00
|
|
|
const executeRotateKey = async (client: ClientItem) => {
|
|
|
|
|
setProcessing(true);
|
2026-10-23 19:56:38 -07:00
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
|
|
|
|
method: 'PATCH',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({ action: 'regenerate_token' }),
|
|
|
|
|
});
|
2026-11-18 05:18:55 +06:00
|
|
|
if (response.status === 401) {
|
|
|
|
|
window.location.assign('/vcon/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-10-23 19:56:38 -07:00
|
|
|
const data = await response.json();
|
|
|
|
|
if (!response.ok) throw new Error(data.error || 'Unable to rotate credentials');
|
2026-11-16 21:58:18 +06:00
|
|
|
setConfirmAction(null);
|
2026-10-23 19:56:38 -07:00
|
|
|
setCredentials(data.client);
|
|
|
|
|
success('Credentials rotated', `New credentials issued for ${client.clientId}.`);
|
|
|
|
|
await onStatusChange();
|
|
|
|
|
} catch (rotateError) {
|
|
|
|
|
error('Credential rotation failed', rotateError instanceof Error ? rotateError.message : 'Unknown error');
|
2026-11-16 21:58:18 +06:00
|
|
|
} finally {
|
|
|
|
|
setProcessing(false);
|
2026-10-23 19:56:38 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-16 21:58:18 +06:00
|
|
|
const executeStatusChange = async (client: ClientItem, status: 'active' | 'revoked') => {
|
|
|
|
|
setProcessing(true);
|
2026-10-23 19:56:38 -07:00
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
|
|
|
|
method: 'PATCH',
|
|
|
|
|
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
body: JSON.stringify({ status }),
|
|
|
|
|
});
|
2026-11-18 05:18:55 +06:00
|
|
|
if (response.status === 401) {
|
|
|
|
|
window.location.assign('/vcon/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-10-23 19:56:38 -07:00
|
|
|
const data = await response.json();
|
|
|
|
|
if (!response.ok) throw new Error(data.error || 'Unable to update client status');
|
2026-11-16 21:58:18 +06:00
|
|
|
setConfirmAction(null);
|
2026-10-23 19:56:38 -07:00
|
|
|
success('Client status updated', `${client.clientId} is now ${status}.`);
|
|
|
|
|
await onStatusChange();
|
|
|
|
|
} catch (statusError) {
|
|
|
|
|
error('Status update failed', statusError instanceof Error ? statusError.message : 'Unknown error');
|
2026-11-16 21:58:18 +06:00
|
|
|
} finally {
|
|
|
|
|
setProcessing(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-17 20:05:00 +06:00
|
|
|
const executeDeleteClient = async (client: ClientItem) => {
|
|
|
|
|
setProcessing(true);
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
|
|
|
|
method: 'DELETE',
|
|
|
|
|
});
|
2026-11-18 05:18:55 +06:00
|
|
|
if (response.status === 401) {
|
|
|
|
|
window.location.assign('/vcon/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-11-17 20:05:00 +06:00
|
|
|
const data = await response.json();
|
|
|
|
|
if (!response.ok) throw new Error(data.error || 'Unable to delete client');
|
|
|
|
|
setConfirmAction(null);
|
|
|
|
|
success('Client deleted', `${client.clientId} has been permanently removed.`);
|
|
|
|
|
await onStatusChange();
|
|
|
|
|
} catch (deleteError) {
|
|
|
|
|
error('Client deletion failed', deleteError instanceof Error ? deleteError.message : 'Unknown error');
|
|
|
|
|
} finally {
|
|
|
|
|
setProcessing(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-16 21:58:18 +06:00
|
|
|
const toggleStatus = (client: ClientItem) => {
|
|
|
|
|
if (client.status === 'active') {
|
|
|
|
|
setConfirmAction({ type: 'revoke', client });
|
|
|
|
|
} else {
|
|
|
|
|
void executeStatusChange(client, 'active');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleConfirm = async () => {
|
|
|
|
|
if (!confirmAction) return;
|
|
|
|
|
if (confirmAction.type === 'rotate') {
|
|
|
|
|
await executeRotateKey(confirmAction.client);
|
2026-11-17 20:05:00 +06:00
|
|
|
} else if (confirmAction.type === 'delete') {
|
|
|
|
|
await executeDeleteClient(confirmAction.client);
|
2026-11-16 21:58:18 +06:00
|
|
|
} else {
|
|
|
|
|
await executeStatusChange(confirmAction.client, 'revoked');
|
2026-10-23 19:56:38 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2026-11-17 00:24:33 +06:00
|
|
|
<TableWrap className="border-0 bg-transparent">
|
|
|
|
|
<Table>
|
2026-10-23 19:56:38 -07:00
|
|
|
<TableHeader>
|
|
|
|
|
<TableRow>
|
|
|
|
|
<TableHead>Client</TableHead>
|
2026-11-18 05:18:55 +06:00
|
|
|
<TableHead>Credentials</TableHead>
|
2026-10-23 19:56:38 -07:00
|
|
|
<TableHead className="text-right">Events</TableHead>
|
|
|
|
|
<TableHead>Last seen</TableHead>
|
|
|
|
|
<TableHead className="text-right">Actions</TableHead>
|
|
|
|
|
</TableRow>
|
|
|
|
|
</TableHeader>
|
|
|
|
|
<TableBody>
|
|
|
|
|
{clients.length === 0 ? (
|
2026-11-16 21:58:18 +06:00
|
|
|
<TableEmpty colSpan={5} message="No matching clients" />
|
2026-10-23 19:56:38 -07:00
|
|
|
) : (
|
|
|
|
|
clients.map((client) => {
|
2026-11-18 05:18:55 +06:00
|
|
|
const revoked = client.status === 'revoked';
|
2026-10-23 19:56:38 -07:00
|
|
|
const online = client.status === 'active' && Boolean(client.lastActive) &&
|
|
|
|
|
now - new Date(client.lastActive!).getTime() < 60_000;
|
|
|
|
|
const pending = client.status === 'active' && !client.lastActive;
|
2026-11-18 05:18:55 +06:00
|
|
|
const label = revoked ? 'revoked' : pending ? 'pending' : online ? 'online' : 'offline';
|
|
|
|
|
const dotClass = revoked
|
|
|
|
|
? 'bg-[var(--danger)]'
|
|
|
|
|
: online
|
|
|
|
|
? 'bg-[var(--accent)]'
|
|
|
|
|
: pending
|
|
|
|
|
? 'bg-[var(--warning)]'
|
|
|
|
|
: 'bg-[var(--text-faint)]';
|
2026-10-23 19:56:38 -07:00
|
|
|
|
|
|
|
|
return (
|
2026-11-16 21:58:18 +06:00
|
|
|
<TableRow key={client.clientId}>
|
|
|
|
|
<TableCell>
|
|
|
|
|
<div className="flex min-w-0 items-center gap-2">
|
2026-10-23 19:56:38 -07:00
|
|
|
<span className={`h-1.5 w-1.5 shrink-0 ${dotClass}`} title={label} />
|
|
|
|
|
<div className="min-w-0 leading-tight">
|
2026-11-18 05:18:55 +06:00
|
|
|
<div className="flex items-center gap-1.5">
|
|
|
|
|
<span className="truncate font-medium text-[var(--text)]">{client.name}</span>
|
|
|
|
|
{revoked && (
|
|
|
|
|
<span className="border border-[var(--danger)] bg-[var(--danger-soft)] px-1 py-0 text-[9px] uppercase tracking-wider text-[var(--danger)]">
|
|
|
|
|
revoked
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-11-17 00:24:33 +06:00
|
|
|
<div className="mt-0.5 truncate font-mono text-[10.5px] text-[var(--text-faint)]">{client.clientId}</div>
|
2026-10-23 19:56:38 -07:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
2026-11-17 00:24:33 +06:00
|
|
|
<TableCell className="font-mono">
|
2026-11-18 05:18:55 +06:00
|
|
|
<div className="truncate text-[11px] text-[var(--text)]">
|
|
|
|
|
{client.tokenPreview || 'JWT Active'}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="mt-0.5 text-[10px] text-[var(--text-faint)]">
|
|
|
|
|
{client.rateLimit}/s limit
|
|
|
|
|
</div>
|
2026-10-23 19:56:38 -07:00
|
|
|
</TableCell>
|
2026-11-17 00:24:33 +06:00
|
|
|
<TableCell className="text-right font-mono tabular-nums">
|
2026-10-23 19:56:38 -07:00
|
|
|
{client.totalEvents.toLocaleString()}
|
|
|
|
|
</TableCell>
|
2026-11-17 00:24:33 +06:00
|
|
|
<TableCell className="font-mono tabular-nums">
|
2026-10-23 19:56:38 -07:00
|
|
|
{client.lastActive ? new Date(client.lastActive).toLocaleTimeString([], { hour12: false }) : '—'}
|
2026-11-17 00:24:33 +06:00
|
|
|
<span className="ml-1.5 font-sans text-[10.5px] text-[var(--text-faint)]">{relativeTime(client.lastActive, now)}</span>
|
2026-10-23 19:56:38 -07:00
|
|
|
</TableCell>
|
2026-11-16 21:58:18 +06:00
|
|
|
<TableCell className="text-right">
|
2026-10-23 19:56:38 -07:00
|
|
|
<div className="inline-flex gap-0.5">
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="icon"
|
|
|
|
|
size="icon"
|
|
|
|
|
icon="Activity"
|
2026-11-16 21:58:18 +06:00
|
|
|
className="h-6 w-6 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
|
2026-10-23 19:56:38 -07:00
|
|
|
title={`View events for ${client.clientId}`}
|
|
|
|
|
aria-label={`View events for ${client.clientId}`}
|
2026-11-16 23:10:44 +06:00
|
|
|
onClick={() => router.push(`/vcon/data?clientId=${encodeURIComponent(client.clientId)}`)}
|
2026-10-23 19:56:38 -07:00
|
|
|
/>
|
2026-11-18 05:18:55 +06:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="icon"
|
|
|
|
|
size="icon"
|
|
|
|
|
icon="Pencil"
|
|
|
|
|
className="h-6 w-6 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
|
|
|
|
|
title={`Edit ${client.clientId}`}
|
|
|
|
|
aria-label={`Edit ${client.clientId}`}
|
|
|
|
|
onClick={() => openEditModal(client)}
|
|
|
|
|
/>
|
2026-10-23 19:56:38 -07:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="icon"
|
|
|
|
|
size="icon"
|
|
|
|
|
icon="RefreshCw"
|
2026-11-16 21:58:18 +06:00
|
|
|
className="h-6 w-6 border border-transparent hover:border-[var(--border)] hover:bg-[var(--surface-2)]"
|
2026-10-23 19:56:38 -07:00
|
|
|
title={`Rotate key for ${client.clientId}`}
|
|
|
|
|
aria-label={`Rotate key for ${client.clientId}`}
|
2026-11-16 21:58:18 +06:00
|
|
|
onClick={() => setConfirmAction({ type: 'rotate', client })}
|
2026-10-23 19:56:38 -07:00
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="icon"
|
|
|
|
|
size="icon"
|
2026-11-17 20:05:00 +06:00
|
|
|
icon={client.status === 'active' ? 'ShieldOff' : 'ShieldCheck'}
|
|
|
|
|
className={`h-6 w-6 border border-transparent ${client.status === 'active' ? 'hover:border-[var(--warning)] hover:text-[var(--warning)]' : 'hover:border-[var(--border)] hover:bg-[var(--surface-2)]'}`}
|
2026-10-23 19:56:38 -07:00
|
|
|
title={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
|
|
|
|
|
aria-label={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
|
|
|
|
|
onClick={() => toggleStatus(client)}
|
|
|
|
|
/>
|
2026-11-17 20:05:00 +06:00
|
|
|
<Button
|
|
|
|
|
type="button"
|
|
|
|
|
variant="icon"
|
|
|
|
|
size="icon"
|
|
|
|
|
icon="Trash2"
|
|
|
|
|
className="h-6 w-6 border border-transparent hover:border-[var(--danger)] hover:text-[var(--danger)]"
|
|
|
|
|
title={`Delete ${client.clientId}`}
|
|
|
|
|
aria-label={`Delete ${client.clientId}`}
|
|
|
|
|
onClick={() => setConfirmAction({ type: 'delete', client })}
|
|
|
|
|
/>
|
2026-10-23 19:56:38 -07:00
|
|
|
</div>
|
|
|
|
|
</TableCell>
|
|
|
|
|
</TableRow>
|
|
|
|
|
);
|
|
|
|
|
})
|
|
|
|
|
)}
|
|
|
|
|
</TableBody>
|
|
|
|
|
</Table>
|
|
|
|
|
</TableWrap>
|
|
|
|
|
|
2026-11-18 05:18:55 +06:00
|
|
|
<Modal
|
|
|
|
|
isOpen={Boolean(editClient)}
|
|
|
|
|
onClose={() => !processing && setEditClient(null)}
|
|
|
|
|
title={`Edit client: ${editClient?.clientId || ''}`}
|
|
|
|
|
maxWidth="xs"
|
|
|
|
|
footer={
|
|
|
|
|
<>
|
|
|
|
|
<Button type="button" variant="ghost" size="xs" disabled={processing} onClick={() => setEditClient(null)}>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
form="edit-client-form"
|
|
|
|
|
variant="primary"
|
|
|
|
|
size="xs"
|
|
|
|
|
loading={processing}
|
|
|
|
|
>
|
|
|
|
|
Save changes
|
|
|
|
|
</Button>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<form id="edit-client-form" onSubmit={executeEditClient} className="flex flex-col gap-2.5">
|
|
|
|
|
<Input
|
|
|
|
|
label="Display name"
|
|
|
|
|
compact
|
|
|
|
|
value={editName}
|
|
|
|
|
onChange={(event) => setEditName(event.target.value)}
|
|
|
|
|
placeholder="Service display name"
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
<Input
|
|
|
|
|
label="Rate limit (events/s)"
|
|
|
|
|
compact
|
|
|
|
|
type="number"
|
|
|
|
|
min="1"
|
|
|
|
|
max="10000"
|
|
|
|
|
value={editRateLimit}
|
|
|
|
|
onChange={(event) => setEditRateLimit(event.target.value)}
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
{editError && (
|
|
|
|
|
<p role="alert" className="text-[11px] text-[var(--danger)]">
|
|
|
|
|
{editError}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</form>
|
|
|
|
|
</Modal>
|
|
|
|
|
|
2026-11-16 21:58:18 +06:00
|
|
|
<Modal
|
|
|
|
|
isOpen={Boolean(confirmAction)}
|
|
|
|
|
onClose={() => !processing && setConfirmAction(null)}
|
2026-11-17 20:05:00 +06:00
|
|
|
title={
|
|
|
|
|
confirmAction?.type === 'rotate'
|
|
|
|
|
? 'Rotate credentials'
|
|
|
|
|
: confirmAction?.type === 'delete'
|
|
|
|
|
? 'Delete client'
|
|
|
|
|
: 'Revoke access'
|
|
|
|
|
}
|
2026-11-16 21:58:18 +06:00
|
|
|
maxWidth="xs"
|
|
|
|
|
footer={
|
|
|
|
|
<>
|
|
|
|
|
<Button type="button" variant="ghost" size="xs" disabled={processing} onClick={() => setConfirmAction(null)}>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
type="button"
|
2026-11-17 20:05:00 +06:00
|
|
|
variant={confirmAction?.type === 'rotate' ? 'primary' : 'danger'}
|
2026-11-16 21:58:18 +06:00
|
|
|
size="xs"
|
|
|
|
|
loading={processing}
|
|
|
|
|
onClick={handleConfirm}
|
|
|
|
|
>
|
2026-11-17 20:05:00 +06:00
|
|
|
{confirmAction?.type === 'rotate'
|
|
|
|
|
? 'Rotate'
|
|
|
|
|
: confirmAction?.type === 'delete'
|
|
|
|
|
? 'Delete'
|
|
|
|
|
: 'Revoke'}
|
2026-11-16 21:58:18 +06:00
|
|
|
</Button>
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<p className="text-[12px] text-[var(--text-muted)]">
|
|
|
|
|
{confirmAction?.type === 'rotate'
|
|
|
|
|
? `Rotate credentials for ${confirmAction.client.clientId}? Existing credentials will stop working.`
|
2026-11-17 20:05:00 +06:00
|
|
|
: confirmAction?.type === 'delete'
|
|
|
|
|
? `Permanently delete client ${confirmAction.client.clientId}? This removes the client registration and credentials.`
|
|
|
|
|
: `Revoke access for ${confirmAction?.client.clientId || ''}?`}
|
2026-11-16 21:58:18 +06:00
|
|
|
</p>
|
|
|
|
|
</Modal>
|
|
|
|
|
|
2026-10-23 19:56:38 -07:00
|
|
|
<Modal
|
|
|
|
|
isOpen={Boolean(credentials)}
|
|
|
|
|
onClose={() => setCredentials(null)}
|
|
|
|
|
title={`Credentials: ${credentials?.clientId || ''}`}
|
2026-11-16 21:58:18 +06:00
|
|
|
footer={<Button type="button" size="xs" onClick={() => setCredentials(null)}>Close</Button>}
|
2026-10-23 19:56:38 -07:00
|
|
|
>
|
2026-11-16 21:58:18 +06:00
|
|
|
{credentials && <CredentialsDisplay credentials={credentials} />}
|
2026-10-23 19:56:38 -07:00
|
|
|
</Modal>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-16 21:58:18 +06:00
|
|
|
export function CredentialsDisplay({ credentials }: { credentials: ClientCredentials }) {
|
2026-10-23 19:56:38 -07:00
|
|
|
return (
|
2026-11-16 21:58:18 +06:00
|
|
|
<div className="flex flex-col gap-2.5">
|
|
|
|
|
<CredentialItem label="Client ID" value={credentials.clientId} />
|
|
|
|
|
<CredentialItem label="Secret key" value={credentials.secret} />
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
|
<div className="flex items-center justify-between gap-2">
|
|
|
|
|
<label htmlFor={`token-${credentials.clientId}`} className="text-[10px] uppercase tracking-wider text-[var(--text-faint)]">
|
|
|
|
|
JWT token
|
|
|
|
|
</label>
|
|
|
|
|
<CopyButton value={credentials.token} />
|
|
|
|
|
</div>
|
|
|
|
|
<Textarea
|
|
|
|
|
id={`token-${credentials.clientId}`}
|
|
|
|
|
readOnly
|
|
|
|
|
value={credentials.token}
|
|
|
|
|
rows={3}
|
|
|
|
|
className="font-mono text-[11px] text-[var(--accent)]"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CredentialItem({ label, value }: { label: string; value: string }) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-1">
|
|
|
|
|
<span className="text-[10px] uppercase tracking-wider text-[var(--text-faint)]">{label}</span>
|
|
|
|
|
<div className="flex min-w-0 items-center justify-between gap-2 border border-[var(--border)] bg-[var(--bg)] p-2">
|
|
|
|
|
<code className="min-w-0 truncate font-mono text-[11px] text-[var(--text)]">{value}</code>
|
2026-10-23 19:56:38 -07:00
|
|
|
<CopyButton value={value} />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|