refactor: switch SDK methods to asynchronous
Migrate SDK interactions to asynchronous calls, relax admin setup email constraints, and add event retrieval functionality.
This commit is contained in:
1 parent
81c5e4e2fd
commit
bb938c33c0
36 files changed
+1679
-754
No files matched your search
@@ -14,9 +14,13 @@ function safeNextPath() {
|
||||
: '/vcon/dashboard';
|
||||
}
|
||||
|
||||
export function AdminLogin() {
|
||||
const [email, setEmail] = useState('admin@datastack.dev');
|
||||
const [password, setPassword] = useState('admin12345678');
|
||||
export function AdminLogin({
|
||||
showDemoHint = false,
|
||||
}: {
|
||||
showDemoHint?: boolean;
|
||||
}) {
|
||||
const [email, setEmail] = useState(showDemoHint ? 'admin@datastack.dev' : '');
|
||||
const [password, setPassword] = useState(showDemoHint ? 'admin12345678' : '');
|
||||
const [remember, setRemember] = useState(true);
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
@@ -144,16 +148,18 @@ export function AdminLogin() {
|
||||
Sign in
|
||||
</Button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setEmail('admin@datastack.dev');
|
||||
setPassword('admin12345678');
|
||||
}}
|
||||
className="mt-0.5 text-center font-mono text-[10.5px] text-[var(--accent)] hover:underline cursor-pointer"
|
||||
>
|
||||
admin@datastack.dev / admin12345678
|
||||
</button>
|
||||
{showDemoHint && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setEmail('admin@datastack.dev');
|
||||
setPassword('admin12345678');
|
||||
}}
|
||||
className="mt-0.5 text-center font-mono text-[10.5px] text-[var(--accent)] hover:underline cursor-pointer"
|
||||
>
|
||||
admin@datastack.dev / admin12345678
|
||||
</button>
|
||||
)}
|
||||
</form>
|
||||
|
||||
<footer className="flex items-center justify-end border-t border-[var(--border)] px-4 py-2 text-[10.5px]">
|
||||
|
||||
@@ -26,8 +26,8 @@ export function AdminSetup({
|
||||
event.preventDefault();
|
||||
setErrorMessage('');
|
||||
|
||||
if (password.length < 12) {
|
||||
setErrorMessage('Password must be at least 12 characters.');
|
||||
if (password.length < 8) {
|
||||
setErrorMessage('Password must be at least 8 characters.');
|
||||
return;
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
@@ -94,7 +94,7 @@ export function AdminSetup({
|
||||
value={password}
|
||||
onChange={(event) => setPassword(event.target.value)}
|
||||
compact
|
||||
minLength={12}
|
||||
minLength={8}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
@@ -104,7 +104,7 @@ export function AdminSetup({
|
||||
value={confirmPassword}
|
||||
onChange={(event) => setConfirmPassword(event.target.value)}
|
||||
compact
|
||||
minLength={12}
|
||||
minLength={8}
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
|
||||
@@ -40,7 +40,7 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
const { success, error } = useToast();
|
||||
const [credentials, setCredentials] = useState<ClientCredentials | null>(null);
|
||||
const [confirmAction, setConfirmAction] = useState<{
|
||||
type: 'rotate' | 'revoke';
|
||||
type: 'rotate' | 'revoke' | 'delete';
|
||||
client: ClientItem;
|
||||
} | null>(null);
|
||||
const [processing, setProcessing] = useState(false);
|
||||
@@ -86,6 +86,24 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
}
|
||||
};
|
||||
|
||||
const executeDeleteClient = async (client: ClientItem) => {
|
||||
setProcessing(true);
|
||||
try {
|
||||
const response = await fetch(`/api/clients/${encodeURIComponent(client.clientId)}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleStatus = (client: ClientItem) => {
|
||||
if (client.status === 'active') {
|
||||
setConfirmAction({ type: 'revoke', client });
|
||||
@@ -98,6 +116,8 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
if (!confirmAction) return;
|
||||
if (confirmAction.type === 'rotate') {
|
||||
await executeRotateKey(confirmAction.client);
|
||||
} else if (confirmAction.type === 'delete') {
|
||||
await executeDeleteClient(confirmAction.client);
|
||||
} else {
|
||||
await executeStatusChange(confirmAction.client, 'revoked');
|
||||
}
|
||||
@@ -178,12 +198,22 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
type="button"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
icon={client.status === 'active' ? 'Trash2' : 'ShieldCheck'}
|
||||
className={`h-6 w-6 border border-transparent ${client.status === 'active' ? 'hover:border-[var(--danger)] hover:text-[var(--danger)]' : 'hover:border-[var(--border)] hover:bg-[var(--surface-2)]'}`}
|
||||
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)]'}`}
|
||||
title={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
|
||||
aria-label={`${client.status === 'active' ? 'Revoke' : 'Reactivate'} ${client.clientId}`}
|
||||
onClick={() => toggleStatus(client)}
|
||||
/>
|
||||
<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 })}
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
@@ -197,7 +227,13 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
<Modal
|
||||
isOpen={Boolean(confirmAction)}
|
||||
onClose={() => !processing && setConfirmAction(null)}
|
||||
title={confirmAction?.type === 'rotate' ? 'Rotate credentials' : 'Revoke access'}
|
||||
title={
|
||||
confirmAction?.type === 'rotate'
|
||||
? 'Rotate credentials'
|
||||
: confirmAction?.type === 'delete'
|
||||
? 'Delete client'
|
||||
: 'Revoke access'
|
||||
}
|
||||
maxWidth="xs"
|
||||
footer={
|
||||
<>
|
||||
@@ -206,12 +242,16 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant={confirmAction?.type === 'revoke' ? 'danger' : 'primary'}
|
||||
variant={confirmAction?.type === 'rotate' ? 'primary' : 'danger'}
|
||||
size="xs"
|
||||
loading={processing}
|
||||
onClick={handleConfirm}
|
||||
>
|
||||
{confirmAction?.type === 'rotate' ? 'Rotate' : 'Revoke'}
|
||||
{confirmAction?.type === 'rotate'
|
||||
? 'Rotate'
|
||||
: confirmAction?.type === 'delete'
|
||||
? 'Delete'
|
||||
: 'Revoke'}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
@@ -219,7 +259,9 @@ export function ClientsTable({ clients, now, onStatusChange }: ClientsTableProps
|
||||
<p className="text-[12px] text-[var(--text-muted)]">
|
||||
{confirmAction?.type === 'rotate'
|
||||
? `Rotate credentials for ${confirmAction.client.clientId}? Existing credentials will stop working.`
|
||||
: `Revoke access for ${confirmAction?.client.clientId || ''}?`}
|
||||
: confirmAction?.type === 'delete'
|
||||
? `Permanently delete client ${confirmAction.client.clientId}? This removes the client registration and credentials.`
|
||||
: `Revoke access for ${confirmAction?.client.clientId || ''}?`}
|
||||
</p>
|
||||
</Modal>
|
||||
|
||||
|
||||
@@ -57,10 +57,10 @@ export function ExportWorkspace() {
|
||||
getCached<StorageFile[]>('vcon:storage-files', [])
|
||||
);
|
||||
const [selectedClient, setSelectedClient] = useState('all');
|
||||
const [fromDate, setFromDate] = useState(() => dateString(new Date()));
|
||||
const [toDate, setToDate] = useState(() => dateString(new Date()));
|
||||
const [fromDate, setFromDate] = useState('');
|
||||
const [toDate, setToDate] = useState('');
|
||||
const [format, setFormat] = useState<ExportFormat>('csv');
|
||||
const [preset, setPreset] = useState<RangePreset>('today');
|
||||
const [preset, setPreset] = useState<RangePreset>('all');
|
||||
const [loading, setLoading] = useState(
|
||||
() => getCached<StorageFile[]>('vcon:storage-files', []).length === 0
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user