From a37cabe51bb0c65713f8a1baa2c492d9bc70b0bd Mon Sep 17 00:00:00 2001 From: Bianca Date: Fri, 13 Nov 2026 20:59:26 +0100 Subject: [PATCH 1/3] feat(web): manage website documents from the dashboard --- README.md | 17 + src/components/shell/nav.ts | 7 + src/features/documents/document-dialogs.tsx | 462 +++++++++++ src/features/documents/documents-page.tsx | 765 ++++++++++++++++++ src/features/documents/documents.functions.ts | 121 +++ .../documents/documents.validation.ts | 117 +++ src/features/documents/types.ts | 6 + src/features/projects/projects-page.tsx | 2 +- src/routeTree.gen.ts | 21 + src/routes/dashboard/web/documents.tsx | 30 + tests/documents.test.mjs | 108 +++ tests/server-security.test.mjs | 17 + 12 files changed, 1672 insertions(+), 1 deletion(-) create mode 100644 src/features/documents/document-dialogs.tsx create mode 100644 src/features/documents/documents-page.tsx create mode 100644 src/features/documents/documents.functions.ts create mode 100644 src/features/documents/documents.validation.ts create mode 100644 src/features/documents/types.ts create mode 100644 src/routes/dashboard/web/documents.tsx create mode 100644 tests/documents.test.mjs diff --git a/README.md b/README.md index 8f731634..97d05c69 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,23 @@ rerun `pnpm check`, `pnpm typecheck`, `pnpm test` and `pnpm build`. Until that u expected to report the missing Freshman contract. No declaration patches or type-error suppression directives are used. The running backend must also include the Freshman router and its migration before using this page. +## Website documents + +Web › Documents manages the categories and documents shown at `/documents` on the website. Create a category, +add a document, then upload a dated PDF version (up to 10 MB). Documents without versions stay in the dashboard +until their first upload. Each document keeps its version history; the greatest date is current, with the most +recent upload breaking ties. Deleting the current version restores the next one, and deleting the only version +hides the document from the website. Only empty categories can be deleted. + +Categories and documents can be dragged into their public order. An outdated list is rejected without overwriting +other edits. Reads require `admin:access`; every mutation and its controls require `web:content:write`. + +This page depends on [backend #132](https://github.com/PoliNetworkOrg/backend/pull/132), its documents migration, +and a published `@polinetwork/backend` package exposing `web.documents`. Until that release, `^4.0.0` does not provide +the required types. Verification against the local package succeeds; update the dependency and lockfile after +publication and rerun the normal checks before merging. The production catalog starts empty; upload real documents +from this dashboard. + ## Production and cutover `pnpm build` writes `.output/`; `pnpm start` runs it. Main-branch CI publishes `ghcr.io/polinetworkorg/admin:latest`. diff --git a/src/components/shell/nav.ts b/src/components/shell/nav.ts index beb7b16a..095d8434 100644 --- a/src/components/shell/nav.ts +++ b/src/components/shell/nav.ts @@ -6,6 +6,7 @@ import { Cloud, Crown, FilePenLine, + FileText, Files, Flag, FolderKanban, @@ -127,6 +128,7 @@ export type PageMatch = | { kind: "web-projects" } | { kind: "web-associations" } | { kind: "web-freshman" } + | { kind: "web-documents" } | { kind: "web-faqs" } | { kind: "web-labels" } | { kind: "web-categories" } @@ -346,6 +348,7 @@ const web: Service = { searchPlaceholder: "Search associations…", }, { id: "freshman", title: "Freshman", icon: BookOpen, path: "/dashboard/web/freshman" }, + { id: "documents", title: "Documents", icon: FileText, path: "/dashboard/web/documents" }, { id: "faqs", title: "FAQs", @@ -538,6 +541,7 @@ export function matchPath(pathname: string): PageMatch { if (second === "associations") return { kind: "web-associations" } if (second === "freshman") return { kind: "web-freshman" } if (second === "guides") return { kind: "web-freshman" } + if (second === "documents") return { kind: "web-documents" } if (second === "faqs") return { kind: "web-faqs" } if (second === "group-labels") return { kind: "web-labels" } if (second === "groups-by-label") return { kind: "web-categories" } @@ -601,6 +605,7 @@ export function serviceFor(match: PageMatch): Service { case "web-projects": case "web-associations": case "web-freshman": + case "web-documents": case "web-faqs": case "web-labels": case "web-categories": @@ -670,6 +675,8 @@ export function sectionFor(match: PageMatch): Section | null { return section(web, "associations") case "web-freshman": return section(web, "freshman") + case "web-documents": + return section(web, "documents") case "web-faqs": return section(web, "faqs") case "web-labels": diff --git a/src/features/documents/document-dialogs.tsx b/src/features/documents/document-dialogs.tsx new file mode 100644 index 00000000..5130e680 --- /dev/null +++ b/src/features/documents/document-dialogs.tsx @@ -0,0 +1,462 @@ +import { useServerFn } from "@tanstack/react-start" +import { useId, useState } from "react" + +import { + DateField, + fieldControl, + fieldHintId, + FileButton, + FormDialog, + FormField, + SelectField, +} from "@/components/primitives" +import { Input } from "@/components/ui/input" +import { Textarea } from "@/components/ui/textarea" +import { dateOnlyValue, parseDateOnly } from "@/lib/date-only" +import { errorHasCode } from "@/lib/errors" +import { cn } from "@/lib/utils" + +import { + addDocumentVersion, + createDocument, + createDocumentCategory, + updateDocument, + updateDocumentCategory, +} from "./documents.functions" +import { + DOCUMENT_DESCRIPTION_MAX_LENGTH, + DOCUMENT_SLUG_MAX_LENGTH, + DOCUMENT_TITLE_MAX_LENGTH, + DOCUMENT_VERSION_MAX_LENGTH, + documentCategoryInput, + documentInput, + documentsErrorMessage, + fieldErrors, + isValidDocumentFile, + slugFromTitle, +} from "./documents.validation" +import type { DocumentCategory, DocumentVersion, WebDocument } from "./types" + +const TEXT_FIELDS = ["title", "slug", "description"] as const +type TextErrors = Partial> +type TextValues = { title: string; slug: string; description: string } + +/** + * Title, slug and description, shared by both dialogs. A new record's slug follows its title until it is edited by + * hand; an existing record's slug never changes on its own. + */ +function useTextFields(initial: TextValues, followTitle: boolean) { + const [values, setValues] = useState(initial) + const [slugEdited, setSlugEdited] = useState(!followTitle) + const [errors, setErrors] = useState({}) + const dirty = + values.title !== initial.title || values.slug !== initial.slug || values.description !== initial.description + + function setTitle(title: string) { + setValues((current) => ({ ...current, title, slug: slugEdited ? current.slug : slugFromTitle(title) })) + } + + function setSlug(slug: string) { + setSlugEdited(true) + setValues((current) => ({ ...current, slug })) + } + + return { values, setValues, setTitle, setSlug, errors, setErrors, dirty } +} + +type TextFieldsProps = { + prefix: string + fields: ReturnType + slugHint: string + descriptionOptional: boolean + descriptionPlaceholder: string +} + +function TextFields({ prefix, fields, slugHint, descriptionOptional, descriptionPlaceholder }: TextFieldsProps) { + const { values, errors } = fields + const id = (field: string) => `${prefix}-${field}` + return ( + <> + + fields.setTitle(event.target.value)} + /> + + + fields.setSlug(event.target.value)} + /> + + +