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/package.json b/package.json index b453317e..7e1ffb53 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "@dnd-kit/react": "^0.4.0", "@fontsource-variable/dm-sans": "^5.3.0", "@fontsource/dm-mono": "^5.3.0", - "@polinetwork/backend": "^4.0.0", + "@polinetwork/backend": "^9.3.0", "@t3-oss/env-core": "^0.13.10", "@tanstack/charts": "1.1.0", "@tanstack/react-charts": "1.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7398e31f..30abbeb9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -32,8 +32,8 @@ importers: specifier: ^5.3.0 version: 5.3.0 '@polinetwork/backend': - specifier: ^4.0.0 - version: 4.0.0 + specifier: ^9.3.0 + version: 9.3.0 '@t3-oss/env-core': specifier: ^0.13.10 version: 0.13.11(typescript@6.0.3)(zod@4.3.5) @@ -1046,8 +1046,8 @@ packages: resolution: {integrity: sha512-SEeaJLb3qBNF/OaXnaR1NmmBbFYk1zC0ZH/52fATcRPLFg/p791YrcyFFy44Bo9sLaGuSuLp5Q6axbb/O+v/RA==} engines: {node: ^14.18.0 || >=16.0.0} - '@polinetwork/backend@4.0.0': - resolution: {integrity: sha512-hKvjzwMMm8qZJojEhIGOA9sHg29xlw2Tu/XH2Wlq9xdkyucEFHp5QNLzGWccjzjHd8fja4qF20OQJppaFrEVtA==} + '@polinetwork/backend@9.3.0': + resolution: {integrity: sha512-07NF/p0w/5JgIWbPDD8Gvv9lzFdrBN0h4IizcLfLK0DZDjeMBw1aSHiyyQ2QzOW732rmSj7E3l8jPBumJPmZqw==} '@polka/url@1.0.0-next.29': resolution: {integrity: sha512-wwQAWhWSuHaag8c4q/KN/vCoeOJYshAIvMQwD4GpSb3OiZklFfvAgmj0VCBBImRpuF/aFgIRzllXlVX93Jevww==} @@ -5968,7 +5968,7 @@ snapshots: '@pkgr/core@0.3.6': {} - '@polinetwork/backend@4.0.0': {} + '@polinetwork/backend@9.3.0': {} '@polka/url@1.0.0-next.29': {} diff --git a/src/components/primitives/file-button.tsx b/src/components/primitives/file-button.tsx index 74c8278f..671bf457 100644 --- a/src/components/primitives/file-button.tsx +++ b/src/components/primitives/file-button.tsx @@ -16,6 +16,8 @@ type FileButtonProps = { label?: string invalid?: boolean id?: string + /** Overrides the description, e.g. a `FormField`'s hint and error (`fieldHintId(id)`). */ + describedBy?: string className?: string } @@ -83,6 +85,7 @@ export function FileButton({ label = "Choose file", invalid = false, id, + describedBy, className, }: FileButtonProps) { const generatedId = useId() @@ -97,7 +100,7 @@ export function FileButton({ accept={accept} label={label} invalid={invalid} - describedBy={hint ? hintId : undefined} + describedBy={describedBy ?? (hint ? hintId : undefined)} onFiles={(files) => onChange(files[0] ?? null)} /> {file && ( 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..00fa3765 --- /dev/null +++ b/src/features/documents/document-dialogs.tsx @@ -0,0 +1,481 @@ +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)} + /> + + +