first commit

This commit is contained in:
bobban committed 2026-10-22 21:00:25 +02:00
commit b7b0f253ce
85 files changed
+7560

No files matched your search

@@ -0,0 +1,33 @@
import { notFound } from "next/navigation";
import { saveEntity } from "@/actions/entities";
import { EntityForm } from "@/components/entity-form";
import { PageBody, PageHeader } from "@/components/page";
import { getT } from "@/i18n/server";
import { KIND_BY_SLUG } from "@/lib/kinds";
import { requireBook } from "@/lib/session";
import { getTemplate } from "@/lib/templates";
export default async function NewEntityPage({ params }: { params: Promise<{ bookId: string; kind: string }> }) {
const { bookId, kind: slug } = await params;
await requireBook(bookId);
const info = KIND_BY_SLUG.get(slug);
if (!info) notFound();
const { t, locale } = await getT();
const { fields } = await getTemplate(bookId, info.kind, locale);
return (
<>
<PageHeader title={t(`kind.${info.kind}.new`)} pretitle={t(`kind.${info.kind}.other`)} />
<PageBody>
<EntityForm
action={saveEntity}
bookId={bookId}
kind={info.kind}
fields={fields}
cancelHref={`/books/${bookId}/e/${slug}`}
t={t}
/>
</PageBody>
</>
);
}
+142
View File
@@ -0,0 +1,142 @@
import Link from "next/link";
import { notFound } from "next/navigation";
import { IconPlus, IconSearch } from "@tabler/icons-react";
import { kindIcons } from "@/components/kind-icons";
import { EmptyState, PageBody, PageHeader } from "@/components/page";
import { getT } from "@/i18n/server";
import { prisma } from "@/lib/db";
import { fileUrl } from "@/lib/files";
import { KIND_BY_SLUG } from "@/lib/kinds";
import { requireBook } from "@/lib/session";
export default async function EntityListPage({
params,
searchParams,
}: {
params: Promise<{ bookId: string; kind: string }>;
searchParams: Promise<{ q?: string; tag?: string }>;
}) {
const { bookId, kind: slug } = await params;
const { q, tag } = await searchParams;
await requireBook(bookId);
const info = KIND_BY_SLUG.get(slug);
if (!info) notFound();
const { t } = await getT();
const Icon = kindIcons[info.kind];
const entities = await prisma.entity.findMany({
where: {
bookId,
kind: info.kind,
...(q
? {
OR: [
{ name: { contains: q, mode: "insensitive" } },
{ summary: { contains: q, mode: "insensitive" } },
{ code: { contains: q, mode: "insensitive" } },
],
}
: {}),
...(tag ? { tags: { has: tag } } : {}),
},
orderBy: { name: "asc" },
});
const base = `/books/${bookId}/e/${slug}`;
return (
<>
<PageHeader
title={t(`kind.${info.kind}.other`)}
actions={
<Link href={`${base}/new`} className="btn btn-primary">
<IconPlus size={18} className="me-1" />
{t(`kind.${info.kind}.new`)}
</Link>
}
/>
<PageBody>
<div className="card">
<div className="card-body border-bottom py-3">
<form className="d-flex gap-2 align-items-center">
<div className="input-icon flex-grow-1">
<span className="input-icon-addon">
<IconSearch size={18} />
</span>
<input name="q" defaultValue={q} className="form-control" placeholder={t("entity.search")} />
</div>
{tag ? <input type="hidden" name="tag" value={tag} /> : null}
<button className="btn" type="submit">
{t("common.search")}
</button>
</form>
{tag ? (
<div className="mt-2">
<Link href={base} className="badge bg-primary-lt text-decoration-none">
{t("entity.filterTag", { tag })} ×
</Link>
</div>
) : null}
</div>
{entities.length === 0 ? (
<div className="card-body">
<EmptyState>{q || tag ? t("common.noResults") : t("entity.empty")}</EmptyState>
</div>
) : (
<div className="table-responsive">
<table className="table table-vcenter card-table">
<tbody>
{entities.map((entity) => {
const image = fileUrl(entity.imageFile);
return (
<tr key={entity.id}>
<td className="w-1">
{image ? (
// eslint-disable-next-line @next/next/no-img-element
<img src={image} alt="" className="bm-thumb" />
) : (
<span className={`avatar bg-${info.color}-lt`}>
<Icon size={20} />
</span>
)}
</td>
<td>
<Link href={`/books/${bookId}/entity/${entity.id}`} className="fw-bold bm-table-link">
{entity.name}
</Link>
{entity.code ? <span className="badge ms-2">{entity.code}</span> : null}
{entity.summary ? (
<div className="text-secondary text-truncate" style={{ maxWidth: "36rem" }}>
{entity.summary}
</div>
) : null}
</td>
<td>
{entity.tags.map((tagName) => (
<Link
key={tagName}
href={`${base}?tag=${encodeURIComponent(tagName)}`}
className="badge bg-azure-lt me-1 text-decoration-none"
>
{tagName}
</Link>
))}
</td>
<td className="text-end w-1">
<Link href={`/books/${bookId}/entity/${entity.id}/edit`} className="btn btn-sm">
{t("common.edit")}
</Link>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
</div>
</PageBody>
</>
);
}