forked from coracle/caravel
Implement more stuff
This commit is contained in:
@@ -1,14 +1,56 @@
|
||||
import { useParams, A } from "@solidjs/router"
|
||||
import { createResource, createSignal, Show } from "solid-js"
|
||||
import { adminDeactivateRelay, adminGetRelay } from "../../lib/api"
|
||||
|
||||
export default function AdminRelayDetail() {
|
||||
const params = useParams()
|
||||
const relayId = () => params.id ?? ""
|
||||
const [relay, { refetch }] = createResource(relayId, adminGetRelay)
|
||||
const [busy, setBusy] = createSignal(false)
|
||||
const [error, setError] = createSignal("")
|
||||
|
||||
async function handleDeactivate() {
|
||||
if (busy()) return
|
||||
setError("")
|
||||
setBusy(true)
|
||||
try {
|
||||
await adminDeactivateRelay(relayId())
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Failed to deactivate relay")
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="max-w-4xl mx-auto px-4 py-8">
|
||||
<div class="flex items-center gap-2 mb-6">
|
||||
<A href="/admin/relays" class="text-gray-500 hover:text-gray-700">← Relays</A>
|
||||
</div>
|
||||
<h1 class="text-2xl font-bold text-gray-900 mb-4">Relay {params.id}</h1>
|
||||
|
||||
<Show when={relay.loading}>
|
||||
<p class="text-gray-500 mb-4">Loading relay...</p>
|
||||
</Show>
|
||||
<Show when={relay.error && !relay.loading}>
|
||||
<p class="text-red-600 mb-4">Failed to load relay.</p>
|
||||
</Show>
|
||||
|
||||
<Show when={relay()}>
|
||||
{(r) => (
|
||||
<div class="mb-6">
|
||||
<h1 class="text-2xl font-bold text-gray-900 mb-1">{r().name}</h1>
|
||||
<p class="text-sm text-gray-500">{r().subdomain}.spaces.coracle.social</p>
|
||||
<p class="text-sm text-gray-500 mt-2 break-all">Tenant: {r().tenant}</p>
|
||||
<p class="text-sm text-gray-700 mt-2">Plan: <span class="uppercase">{r().plan}</span></p>
|
||||
<p class="text-sm text-gray-700">Status: <span class="uppercase">{r().status}</span></p>
|
||||
<Show when={r().description.trim()}>
|
||||
<p class="mt-3 text-gray-700">{r().description}</p>
|
||||
</Show>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
|
||||
<div class="flex gap-3">
|
||||
<A
|
||||
href={`/admin/relays/${params.id}/edit`}
|
||||
@@ -16,10 +58,17 @@ export default function AdminRelayDetail() {
|
||||
>
|
||||
Edit
|
||||
</A>
|
||||
<button class="py-2 px-4 border border-red-300 text-red-600 font-medium rounded-lg hover:bg-red-50 transition-colors">
|
||||
Deactivate
|
||||
<button
|
||||
class="py-2 px-4 border border-red-300 text-red-600 font-medium rounded-lg hover:bg-red-50 transition-colors disabled:opacity-50"
|
||||
onClick={handleDeactivate}
|
||||
disabled={busy()}
|
||||
>
|
||||
{busy() ? "Deactivating..." : "Deactivate"}
|
||||
</button>
|
||||
</div>
|
||||
<Show when={error()}>
|
||||
<p class="mt-3 text-sm text-red-600">{error()}</p>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,63 @@
|
||||
import { useParams, A } from "@solidjs/router"
|
||||
import { A, useNavigate, useParams } from "@solidjs/router"
|
||||
import { Show, createEffect, createResource, createSignal } from "solid-js"
|
||||
import { adminGetRelay, adminUpdateRelay } from "../../lib/api"
|
||||
|
||||
const PLANS = ["free", "basic", "growth"] as const
|
||||
type PlanId = (typeof PLANS)[number]
|
||||
|
||||
function slugify(s: string) {
|
||||
return s
|
||||
.toLowerCase()
|
||||
.trim()
|
||||
.normalize("NFD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "")
|
||||
}
|
||||
|
||||
export default function AdminRelayEdit() {
|
||||
const navigate = useNavigate()
|
||||
const params = useParams()
|
||||
const relayId = () => params.id ?? ""
|
||||
const [relay] = createResource(relayId, adminGetRelay)
|
||||
|
||||
const [name, setName] = createSignal("")
|
||||
const [subdomain, setSubdomain] = createSignal("")
|
||||
const [icon, setIcon] = createSignal("")
|
||||
const [description, setDescription] = createSignal("")
|
||||
const [plan, setPlan] = createSignal<PlanId>("free")
|
||||
const [error, setError] = createSignal("")
|
||||
const [submitting, setSubmitting] = createSignal(false)
|
||||
|
||||
createEffect(() => {
|
||||
const data = relay()
|
||||
if (!data) return
|
||||
setName(data.name)
|
||||
setSubdomain(data.subdomain)
|
||||
setIcon(data.icon)
|
||||
setDescription(data.description)
|
||||
setPlan(PLANS.includes(data.plan as PlanId) ? (data.plan as PlanId) : "free")
|
||||
})
|
||||
|
||||
async function handleSubmit(e: Event) {
|
||||
e.preventDefault()
|
||||
setError("")
|
||||
setSubmitting(true)
|
||||
try {
|
||||
await adminUpdateRelay(relayId(), {
|
||||
name: name().trim(),
|
||||
subdomain: slugify(subdomain()),
|
||||
icon: icon().trim(),
|
||||
description: description().trim(),
|
||||
plan: plan(),
|
||||
})
|
||||
navigate(`/admin/relays/${relayId()}`)
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Failed to update relay")
|
||||
} finally {
|
||||
setSubmitting(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="max-w-2xl mx-auto px-4 py-8">
|
||||
@@ -9,7 +65,81 @@ export default function AdminRelayEdit() {
|
||||
<A href={`/admin/relays/${params.id}`} class="text-gray-500 hover:text-gray-700">← Back</A>
|
||||
</div>
|
||||
<h1 class="text-2xl font-bold text-gray-900 mb-6">Edit Relay (Admin)</h1>
|
||||
<p class="text-gray-500">Edit form coming soon.</p>
|
||||
|
||||
<Show when={relay.loading}>
|
||||
<p class="text-gray-500">Loading relay...</p>
|
||||
</Show>
|
||||
<Show when={relay.error && !relay.loading}>
|
||||
<p class="text-red-600">Failed to load relay.</p>
|
||||
</Show>
|
||||
|
||||
<Show when={relay() && !relay.loading}>
|
||||
<form onSubmit={handleSubmit} class="space-y-4">
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Relay Name</label>
|
||||
<input
|
||||
value={name()}
|
||||
onInput={e => setName(e.currentTarget.value)}
|
||||
required
|
||||
class="w-full border border-gray-300 rounded-lg px-3 py-2"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Subdomain</label>
|
||||
<div class="flex items-center border border-gray-300 rounded-lg overflow-hidden">
|
||||
<input
|
||||
value={subdomain()}
|
||||
onInput={e => setSubdomain(e.currentTarget.value)}
|
||||
required
|
||||
class="flex-1 px-3 py-2"
|
||||
/>
|
||||
<span class="px-3 py-2 bg-gray-50 text-gray-500 text-sm border-l border-gray-300">.spaces.coracle.social</span>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Icon URL</label>
|
||||
<input
|
||||
type="url"
|
||||
value={icon()}
|
||||
onInput={e => setIcon(e.currentTarget.value)}
|
||||
class="w-full border border-gray-300 rounded-lg px-3 py-2"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-1">Description</label>
|
||||
<textarea
|
||||
value={description()}
|
||||
onInput={e => setDescription(e.currentTarget.value)}
|
||||
rows={3}
|
||||
class="w-full border border-gray-300 rounded-lg px-3 py-2"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-medium text-gray-700 mb-2">Plan</label>
|
||||
<div class="flex gap-2">
|
||||
{PLANS.map(p => (
|
||||
<button
|
||||
type="button"
|
||||
class={`rounded-lg border px-3 py-2 text-sm capitalize ${plan() === p ? "border-blue-600 text-blue-700" : "border-gray-300 text-gray-700"}`}
|
||||
onClick={() => setPlan(p)}
|
||||
>
|
||||
{p}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<Show when={error()}>
|
||||
<p class="text-sm text-red-600">{error()}</p>
|
||||
</Show>
|
||||
<button
|
||||
type="submit"
|
||||
disabled={submitting()}
|
||||
class="w-full py-2 px-4 bg-blue-600 text-white font-medium rounded-lg hover:bg-blue-700 disabled:opacity-50"
|
||||
>
|
||||
{submitting() ? "Saving..." : "Save Changes"}
|
||||
</button>
|
||||
</form>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,13 +1,60 @@
|
||||
import { A } from "@solidjs/router"
|
||||
import { createMemo, createResource, createSignal, For, Show } from "solid-js"
|
||||
import { adminListRelays } from "../../lib/api"
|
||||
|
||||
export default function AdminRelays() {
|
||||
const [query, setQuery] = createSignal("")
|
||||
const [relays] = createResource(adminListRelays)
|
||||
|
||||
const filtered = createMemo(() => {
|
||||
const q = query().trim().toLowerCase()
|
||||
return (relays() ?? []).filter((relay) => {
|
||||
if (!q) return true
|
||||
return (
|
||||
relay.name.toLowerCase().includes(q)
|
||||
|| relay.subdomain.toLowerCase().includes(q)
|
||||
|| relay.tenant.toLowerCase().includes(q)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
return (
|
||||
<div class="max-w-4xl mx-auto px-4 py-8">
|
||||
<h1 class="text-2xl font-bold text-gray-900 mb-6">All Relays</h1>
|
||||
<input
|
||||
type="search"
|
||||
value={query()}
|
||||
onInput={(e) => setQuery(e.currentTarget.value)}
|
||||
placeholder="Search relays..."
|
||||
class="w-full border border-gray-300 rounded-lg px-3 py-2 mb-6 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
<p class="text-gray-500">No relays found.</p>
|
||||
|
||||
<Show when={relays.loading}>
|
||||
<p class="text-gray-500">Loading relays...</p>
|
||||
</Show>
|
||||
<Show when={relays.error && !relays.loading}>
|
||||
<p class="text-red-600">Failed to load relays.</p>
|
||||
</Show>
|
||||
<Show when={(filtered().length ?? 0) > 0} fallback={<p class="text-gray-500">No relays found.</p>}>
|
||||
<ul class="space-y-3">
|
||||
<For each={filtered()}>
|
||||
{(relay) => (
|
||||
<li>
|
||||
<A href={`/admin/relays/${relay.id}`} class="block border border-gray-200 rounded-lg p-4 bg-white hover:border-gray-300">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<div>
|
||||
<p class="font-medium text-gray-900">{relay.name}</p>
|
||||
<p class="text-xs text-gray-500">{relay.subdomain}.spaces.coracle.social</p>
|
||||
<p class="text-xs text-gray-500 break-all mt-1">Tenant: {relay.tenant}</p>
|
||||
</div>
|
||||
<p class="text-xs uppercase tracking-wide text-gray-500">{relay.status}</p>
|
||||
</div>
|
||||
</A>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
</ul>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
import { useParams, A } from "@solidjs/router"
|
||||
import { createResource, createSignal, For, Show } from "solid-js"
|
||||
import { adminGetTenant, adminUpdateTenantStatus } from "../../lib/api"
|
||||
|
||||
export default function AdminTenantDetail() {
|
||||
const params = useParams()
|
||||
const tenantId = () => params.id ?? ""
|
||||
const [detail, { refetch }] = createResource(tenantId, adminGetTenant)
|
||||
const [busy, setBusy] = createSignal(false)
|
||||
const [error, setError] = createSignal("")
|
||||
|
||||
async function setStatus(status: string) {
|
||||
if (busy()) return
|
||||
setBusy(true)
|
||||
setError("")
|
||||
try {
|
||||
await adminUpdateTenantStatus(tenantId(), status)
|
||||
await refetch()
|
||||
} catch (e) {
|
||||
setError(e instanceof Error ? e.message : "Failed to update tenant")
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="max-w-4xl mx-auto px-4 py-8">
|
||||
@@ -9,14 +29,69 @@ export default function AdminTenantDetail() {
|
||||
<A href="/admin/tenants" class="text-gray-500 hover:text-gray-700">← Tenants</A>
|
||||
</div>
|
||||
<h1 class="text-2xl font-bold text-gray-900 mb-6">Tenant {params.id}</h1>
|
||||
|
||||
<Show when={detail.loading}>
|
||||
<p class="text-gray-500 mb-4">Loading tenant...</p>
|
||||
</Show>
|
||||
<Show when={detail.error && !detail.loading}>
|
||||
<p class="text-red-600 mb-4">Failed to load tenant.</p>
|
||||
</Show>
|
||||
|
||||
<div class="space-y-6">
|
||||
<section class="bg-white border border-gray-200 rounded-xl p-6">
|
||||
<h2 class="text-lg font-semibold mb-4">Relays</h2>
|
||||
<p class="text-gray-500">No relays.</p>
|
||||
<h2 class="text-lg font-semibold mb-4">Status</h2>
|
||||
<Show when={detail()}>
|
||||
{(d) => (
|
||||
<div class="space-y-3">
|
||||
<p class="text-sm text-gray-700">
|
||||
Current: <span class="font-medium uppercase tracking-wide">{d().tenant.status}</span>
|
||||
</p>
|
||||
<div class="flex gap-2">
|
||||
<button
|
||||
class="py-2 px-4 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 disabled:opacity-50"
|
||||
onClick={() => void setStatus("active")}
|
||||
disabled={busy()}
|
||||
>
|
||||
Activate
|
||||
</button>
|
||||
<button
|
||||
class="py-2 px-4 border border-red-300 text-red-600 rounded-lg hover:bg-red-50 disabled:opacity-50"
|
||||
onClick={() => void setStatus("deactivated")}
|
||||
disabled={busy()}
|
||||
>
|
||||
Deactivate
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Show>
|
||||
</section>
|
||||
<button class="py-2 px-4 border border-red-300 text-red-600 font-medium rounded-lg hover:bg-red-50 transition-colors">
|
||||
Deactivate Tenant
|
||||
</button>
|
||||
|
||||
<section class="bg-white border border-gray-200 rounded-xl p-6">
|
||||
<h2 class="text-lg font-semibold mb-4">Relays</h2>
|
||||
<Show when={(detail()?.relays.length ?? 0) > 0} fallback={<p class="text-gray-500">No relays.</p>}>
|
||||
<ul class="space-y-3">
|
||||
<For each={detail()?.relays ?? []}>
|
||||
{(relay) => (
|
||||
<li>
|
||||
<A href={`/admin/relays/${relay.id}`} class="block rounded-lg border border-gray-200 p-3 hover:border-gray-300">
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<div>
|
||||
<p class="font-medium text-gray-900">{relay.name}</p>
|
||||
<p class="text-xs text-gray-500">{relay.subdomain}.spaces.coracle.social</p>
|
||||
</div>
|
||||
<span class="text-xs uppercase tracking-wide text-gray-500">{relay.status}</span>
|
||||
</div>
|
||||
</A>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
</ul>
|
||||
</Show>
|
||||
</section>
|
||||
<Show when={error()}>
|
||||
<p class="text-sm text-red-600">{error()}</p>
|
||||
</Show>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -1,13 +1,52 @@
|
||||
import { A } from "@solidjs/router"
|
||||
import { createMemo, createResource, createSignal, For, Show } from "solid-js"
|
||||
import { adminListTenants } from "../../lib/api"
|
||||
|
||||
export default function AdminTenants() {
|
||||
const [query, setQuery] = createSignal("")
|
||||
const [tenants] = createResource(adminListTenants)
|
||||
|
||||
const filtered = createMemo(() => {
|
||||
const q = query().trim().toLowerCase()
|
||||
return (tenants() ?? []).filter((tenant) => {
|
||||
if (!q) return true
|
||||
return tenant.pubkey.toLowerCase().includes(q) || tenant.status.toLowerCase().includes(q)
|
||||
})
|
||||
})
|
||||
|
||||
return (
|
||||
<div class="max-w-4xl mx-auto px-4 py-8">
|
||||
<h1 class="text-2xl font-bold text-gray-900 mb-6">Tenants</h1>
|
||||
<input
|
||||
type="search"
|
||||
value={query()}
|
||||
onInput={(e) => setQuery(e.currentTarget.value)}
|
||||
placeholder="Search tenants..."
|
||||
class="w-full border border-gray-300 rounded-lg px-3 py-2 mb-6 focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
/>
|
||||
<p class="text-gray-500">No tenants found.</p>
|
||||
|
||||
<Show when={tenants.loading}>
|
||||
<p class="text-gray-500">Loading tenants...</p>
|
||||
</Show>
|
||||
<Show when={tenants.error && !tenants.loading}>
|
||||
<p class="text-red-600">Failed to load tenants.</p>
|
||||
</Show>
|
||||
<Show when={(filtered().length ?? 0) > 0} fallback={<p class="text-gray-500">No tenants found.</p>}>
|
||||
<ul class="space-y-3">
|
||||
<For each={filtered()}>
|
||||
{(tenant) => (
|
||||
<li>
|
||||
<A href={`/admin/tenants/${tenant.pubkey}`} class="block border border-gray-200 rounded-lg p-4 bg-white hover:border-gray-300">
|
||||
<div class="flex items-center justify-between gap-3">
|
||||
<p class="text-sm break-all text-gray-700">{tenant.pubkey}</p>
|
||||
<p class="text-xs uppercase tracking-wide text-gray-500">{tenant.status}</p>
|
||||
</div>
|
||||
</A>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
</ul>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user