import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { listTokens, createToken, revokeToken, deleteToken, TokenDto } from "../../lib/api"; import { Card, CardHeader, CardTitle, CardDescription, CardContent, Button, Badge, FormField, FormInput, FormSelect, FormRow } from "../components/ui"; import { getServerTranslations } from "../../lib/i18n/server"; export const dynamic = "force-dynamic"; export default async function TokensPage({ searchParams }: { searchParams: Promise<{ created?: string }>; }) { const { t } = await getServerTranslations(); const params = await searchParams; const tokens = await listTokens().catch(() => [] as TokenDto[]); async function createTokenAction(formData: FormData) { "use server"; const name = formData.get("name") as string; const scope = formData.get("scope") as string; if (name) { const result = await createToken(name, scope); revalidatePath("/tokens"); redirect(`/tokens?created=${encodeURIComponent(result.token)}`); } } async function revokeTokenAction(formData: FormData) { "use server"; const id = formData.get("id") as string; await revokeToken(id); revalidatePath("/tokens"); } async function deleteTokenAction(formData: FormData) { "use server"; const id = formData.get("id") as string; await deleteToken(id); revalidatePath("/tokens"); } return ( <>
{params.created}
| {t("tokens.name")} | {t("tokens.scope")} | {t("tokens.prefix")} | {t("tokens.status")} | {t("tokens.actions")} |
|---|---|---|---|---|
| {token.name} |
|
{token.prefix}
|
{token.revoked_at ? (
|
{!token.revoked_at ? ( ) : ( )} |