feat: citizenship applications

This commit is contained in:
Ivan Rezchikov
2026-06-23 19:03:10 +03:00
parent 58ec75c948
commit c60ab9e8f9
44 changed files with 1254 additions and 130 deletions
+13 -7
View File
@@ -1,9 +1,10 @@
"use client";
import { useState, useEffect, useRef } from "react";
import { v4 as uuidv4 } from "uuid";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Field, FieldGroup, FieldLabel, FieldSet } from "@/components/ui/field";
import { Field, FieldError, FieldGroup, FieldLabel, FieldSet } from "@/components/ui/field";
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group";
import { Block, BlockType, Page, PageMeta, PageType } from "@/lib/pages/types";
import { Globe2Icon, PlusIcon, Trash2Icon, XIcon, GripVerticalIcon, ChevronDownIcon, ImageIcon, QuoteIcon, AlertCircleIcon, MinusIcon, ListIcon, TableIcon, TypeIcon, AlignLeftIcon, InfoIcon, DotIcon, ListOrderedIcon, LinkIcon } from "lucide-react";
@@ -29,6 +30,7 @@ type EditorProps = {
type?: PageType;
initialBlocks?: Block[];
onChange: (data: EditorData) => void;
errors?: { title?: string[]; slug?: string[] };
};
const BLOCK_ICONS: Record<BlockType, React.ReactNode> = {
@@ -55,7 +57,7 @@ const BLOCK_LABELS: Record<BlockType, string> = {
LINK: "Link"
};
export default function Editor({ page, initialBlocks = [], onChange }: EditorProps) {
export default function Editor({ page, initialBlocks = [], onChange, errors }: EditorProps) {
const meta = (page?.meta as PageMeta) ?? {};
const [title, setTitle] = useState(page?.title ?? "");
@@ -94,7 +96,7 @@ export default function Editor({ page, initialBlocks = [], onChange }: EditorPro
setBlocks([
...blocks,
{
id: crypto.randomUUID(),
id: uuidv4(),
pageId: page?.id ?? "",
parentId: null,
type: blockType,
@@ -139,11 +141,12 @@ export default function Editor({ page, initialBlocks = [], onChange }: EditorPro
<FieldSet>
<h2 className=" mb-6">Meta</h2>
<FieldGroup>
<Field>
<Field data-invalid={!!errors?.title?.length}>
<FieldLabel htmlFor="title">Title</FieldLabel>
<InputGroup>
<InputGroupInput
id="title"
aria-invalid={!!errors?.title?.length}
value={title}
placeholder="Enter page title"
onChange={(e) => {
@@ -152,6 +155,7 @@ export default function Editor({ page, initialBlocks = [], onChange }: EditorPro
}}
/>
</InputGroup>
{errors?.title && <FieldError errors={errors.title.map(m => ({ message: m }))} />}
</Field>
<Field>
<FieldLabel htmlFor="type">Page type</FieldLabel>
@@ -167,11 +171,12 @@ export default function Editor({ page, initialBlocks = [], onChange }: EditorPro
</SelectContent>
</Select>
</Field>
<Field>
<Field data-invalid={!!errors?.slug?.length}>
<FieldLabel htmlFor="slug">Slug</FieldLabel>
<InputGroup>
<InputGroupInput id="slug" value={slug} placeholder="page-slug" onChange={(e) => setSlug(e.target.value)} />
<InputGroupInput id="slug" aria-invalid={!!errors?.slug?.length} value={slug} placeholder="page-slug" onChange={(e) => setSlug(e.target.value)} />
</InputGroup>
{errors?.slug && <FieldError errors={errors.slug.map(m => ({ message: m }))} />}
</Field>
{type === "NEWS" && (
<Field>
@@ -193,7 +198,7 @@ export default function Editor({ page, initialBlocks = [], onChange }: EditorPro
value={tagInput}
placeholder="Add a tag and press Enter"
onChange={(e) => setTagInput(e.target.value)}
onKeyDown={(e) => e.key === "Enter" && addTag()}
onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); addTag(); } }}
/>
<InputGroupAddon align="inline-end">
<InputGroupButton onClick={addTag}>Add</InputGroupButton>
@@ -617,6 +622,7 @@ function getDefaultContent(type: BlockType): Block["content"] {
case "LIST": return { type: "LIST", style: "BULLET", items: [""] };
case "TABLE": return { type: "TABLE", headers: ["", ""], rows: [["", ""]] };
case "IMAGE": return { type: "IMAGE", url: "", caption: "" };
case "LINK": return { type: "LINK", label: "", href: "" };
default: return { type: "PARAGRAPH", text: "" };
}
}