wip: zen style api keys

This commit is contained in:
Frank
2025-10-10 13:45:06 -04:00
parent 0bc00bef32
commit d83af721a6
2 changed files with 52 additions and 47 deletions

View File

@@ -1,4 +1,11 @@
.root {
[data-slot="title-row"] {
display: flex;
justify-content: space-between;
align-items: center;
gap: var(--space-4);
}
[data-component="empty-state"] {
padding: var(--space-20) var(--space-6);
text-align: center;
@@ -150,6 +157,7 @@
}
@media (max-width: 40rem) {
th,
td {
padding: var(--space-2) var(--space-3);
@@ -157,16 +165,22 @@
}
th {
&:nth-child(3) /* Date */ {
&:nth-child(3)
/* Date */
{
display: none;
}
}
td {
&:nth-child(3) /* Date */ {
&:nth-child(3)
/* Date */
{
display: none;
}
}
}
}
}
}

View File

@@ -43,8 +43,9 @@ const listKeys = query(async (workspaceID: string) => {
return withActor(() => Key.list(), workspaceID)
}, "key.list")
export function KeyCreateForm() {
export function KeySection() {
const params = useParams()
const keys = createAsync(() => listKeys(params.id))
const submission = useSubmission(createKey)
const [store, setStore] = createStore({ show: false })
@@ -52,69 +53,59 @@ export function KeyCreateForm() {
createEffect(() => {
if (!submission.pending && submission.result && !submission.result.error) {
hide()
setStore("show", false)
}
})
function show() {
// submission.clear() does not clear the result in some cases, ie.
// 1. Create key with empty name => error shows
// 2. Put in a key name and creates the key => form hides
// 3. Click add key button again => form shows with the same error if
// submission.clear() is called only once
while (true) {
submission.clear()
if (!submission.result) break
}
setStore("show", true)
input.focus()
setTimeout(() => input?.focus(), 0)
}
function hide() {
setStore("show", false)
}
return (
<Show
when={store.show}
fallback={
<button data-color="primary" onClick={() => show()}>
Create API Key
</button>
}
>
<form action={createKey} method="post" data-slot="create-form">
<div data-slot="input-container">
<input ref={(r) => (input = r)} data-component="input" name="name" type="text" placeholder="Enter key name" />
<Show when={submission.result && submission.result.error}>
{(err) => <div data-slot="form-error">{err()}</div>}
</Show>
</div>
<input type="hidden" name="workspaceID" value={params.id} />
<div data-slot="form-actions">
<button type="reset" data-color="ghost" onClick={() => hide()}>
Cancel
</button>
<button type="submit" data-color="primary" disabled={submission.pending}>
{submission.pending ? "Creating..." : "Create"}
</button>
</div>
</form>
</Show>
)
}
export function KeySection() {
const params = useParams()
const keys = createAsync(() => listKeys(params.id))
return (
<section class={styles.root}>
<div data-slot="section-title">
<h2>API Keys</h2>
<p>Manage your API keys for accessing opencode services.</p>
<div data-slot="title-row">
<p>Manage your API keys for accessing opencode services.</p>
<button data-color="primary" onClick={() => show()}>
Create API Key
</button>
</div>
</div>
<KeyCreateForm />
<Show when={store.show}>
<form action={createKey} method="post" data-slot="create-form">
<div data-slot="input-container">
<input
ref={(r) => (input = r)}
data-component="input"
name="name"
type="text"
placeholder="Enter key name"
/>
<Show when={submission.result && submission.result.error}>
{(err) => <div data-slot="form-error">{err()}</div>}
</Show>
</div>
<input type="hidden" name="workspaceID" value={params.id} />
<div data-slot="form-actions">
<button type="reset" data-color="ghost" onClick={() => hide()}>
Cancel
</button>
<button type="submit" data-color="primary" disabled={submission.pending}>
{submission.pending ? "Creating..." : "Create"}
</button>
</div>
</form>
</Show>
<div data-slot="api-keys-table">
<Show
when={keys()?.length}