refactor: improve auth defaults, update UI, and docs
- Provide fallback values for auth environment variables - Refine global CSS styles and typography - Update application metadata descriptions - Add toast error handling to clients page - Formalize phase implementation guidelines in AGENTS.md
This commit is contained in:
1 parent
df14ee1a9a
commit
fde2c86b1e
48 files changed
+1062
-1665
No files matched your search
@@ -1,11 +1,11 @@
|
||||
'use client';
|
||||
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { CopyButton } from '@/components/ui/CopyButton';
|
||||
import { Input, Textarea } from '@/components/ui/Input';
|
||||
import { Input } from '@/components/ui/Input';
|
||||
import { Modal } from '@/components/ui/Modal';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
import { useState } from 'react';
|
||||
import { CredentialsDisplay } from './ClientsTable';
|
||||
import type { ClientCredentials } from './clients/types';
|
||||
|
||||
interface NewClientModalProps {
|
||||
@@ -24,12 +24,19 @@ export function NewClientModal({ open, onClose, onCreated }: NewClientModalProps
|
||||
|
||||
const createClient = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
const trimmedId = clientId.trim();
|
||||
const trimmedName = name.trim();
|
||||
if (!trimmedId || !trimmedName) {
|
||||
error('Validation error', 'Client ID and Name are required.');
|
||||
return;
|
||||
}
|
||||
const clampedRateLimit = Math.max(1, Math.min(5000, Number(rateLimit) || 100));
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const response = await fetch('/api/clients', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ clientId: clientId.trim(), name: name.trim(), rateLimit: Number(rateLimit) || 100 }),
|
||||
body: JSON.stringify({ clientId: trimmedId, name: trimmedName, rateLimit: clampedRateLimit }),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (!response.ok) throw new Error(data.error || 'Client registration failed');
|
||||
@@ -53,43 +60,40 @@ export function NewClientModal({ open, onClose, onCreated }: NewClientModalProps
|
||||
<Modal
|
||||
isOpen={open}
|
||||
onClose={onClose}
|
||||
title="Create client"
|
||||
title="New client"
|
||||
maxWidth="xs"
|
||||
footer={
|
||||
<>
|
||||
<Button type="button" variant="ghost" size="sm" onClick={onClose}>Cancel</Button>
|
||||
<Button type="submit" form="new-client-form" variant="primary" size="sm" loading={submitting}>Create client</Button>
|
||||
<Button type="button" variant="ghost" size="xs" onClick={onClose}>Cancel</Button>
|
||||
<Button type="submit" form="new-client-form" variant="primary" size="xs" loading={submitting}>Create</Button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<form id="new-client-form" onSubmit={createClient} className="flex flex-col gap-3.5">
|
||||
<form id="new-client-form" onSubmit={createClient} className="flex flex-col gap-2.5">
|
||||
<Input
|
||||
compact
|
||||
label="Client ID"
|
||||
placeholder="e.g. py_order_service_04"
|
||||
placeholder="py_order_service_04"
|
||||
value={clientId}
|
||||
onChange={(event) => setClientId(event.target.value)}
|
||||
className="h-8 border-[var(--border)] bg-[var(--bg)] px-2.5 text-[12.5px] focus:border-[var(--border-strong)]"
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
compact
|
||||
label="Client name"
|
||||
placeholder="e.g. Order Service"
|
||||
label="Name"
|
||||
placeholder="Order Service"
|
||||
value={name}
|
||||
onChange={(event) => setName(event.target.value)}
|
||||
className="h-8 border-[var(--border)] bg-[var(--bg)] px-2.5 text-[12.5px] focus:border-[var(--border-strong)]"
|
||||
required
|
||||
/>
|
||||
<Input
|
||||
compact
|
||||
label="Rate limit (requests per second)"
|
||||
label="Rate limit (req/s)"
|
||||
type="number"
|
||||
min="1"
|
||||
max="5000"
|
||||
value={rateLimit}
|
||||
onChange={(event) => setRateLimit(event.target.value)}
|
||||
className="h-8 border-[var(--border)] bg-[var(--bg)] px-2.5 text-[12.5px] focus:border-[var(--border-strong)]"
|
||||
/>
|
||||
</form>
|
||||
</Modal>
|
||||
@@ -98,35 +102,10 @@ export function NewClientModal({ open, onClose, onCreated }: NewClientModalProps
|
||||
isOpen={Boolean(credentials)}
|
||||
onClose={() => setCredentials(null)}
|
||||
title={`Credentials: ${credentials?.clientId || ''}`}
|
||||
description="Copy these credentials now. The secret is only shown after creation."
|
||||
footer={<Button type="button" size="sm" onClick={() => setCredentials(null)}>Close</Button>}
|
||||
footer={<Button type="button" size="xs" onClick={() => setCredentials(null)}>Close</Button>}
|
||||
>
|
||||
{credentials && (
|
||||
<div className="flex flex-col gap-3">
|
||||
<Credential label="Client ID" value={credentials.clientId} />
|
||||
<Credential label="Client secret key" value={credentials.secret} />
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<label htmlFor="new-client-token" className="text-xs uppercase text-[var(--text-faint)]">JWT handshake bearer token</label>
|
||||
<CopyButton value={credentials.token} />
|
||||
</div>
|
||||
<Textarea id="new-client-token" readOnly value={credentials.token} rows={4} className="font-mono text-xs text-[var(--accent)]" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{credentials && <CredentialsDisplay credentials={credentials} />}
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function Credential({ label, value }: { label: string; value: string }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1.5">
|
||||
<span className="text-xs uppercase 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.5">
|
||||
<code className="min-w-0 truncate font-mono text-xs text-[var(--text)]">{value}</code>
|
||||
<CopyButton value={value} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user