feat: citizenship applications
This commit is contained in:
@@ -14,16 +14,17 @@ import { PencilIcon, XIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { PageType } from "@/lib/pages/types";
|
||||
|
||||
type Draft = { id: string; title: string; slug: string; updatedAt: Date };
|
||||
type Draft = { id: string; type: PageType; title: string; slug: string; updatedAt: Date | null };
|
||||
|
||||
export default function DraftsDialog({ drafts }: { drafts: Draft[]}) {
|
||||
const [isDeletingId, setIsDeletingId] = useState("");
|
||||
|
||||
async function deletePage(id: string) {
|
||||
async function deletePage(id: string, type: PageType) {
|
||||
setIsDeletingId(id);
|
||||
try {
|
||||
await deletePageAction(id)
|
||||
await deletePageAction(id, type)
|
||||
} finally {
|
||||
setIsDeletingId("")
|
||||
}
|
||||
@@ -51,7 +52,7 @@ export default function DraftsDialog({ drafts }: { drafts: Draft[]}) {
|
||||
<Link href={`/news/${draft.slug}/edit`}>
|
||||
<Button variant="secondary" size="icon-sm"><PencilIcon /></Button>
|
||||
</Link>
|
||||
<Button disabled={isDeletingId === draft.id} variant="secondary" size="icon-sm" onClick={() => deletePage(draft.id)}>
|
||||
<Button disabled={isDeletingId === draft.id} variant="secondary" size="icon-sm" onClick={() => deletePage(draft.id, draft.type)}>
|
||||
{isDeletingId === draft.id ? <Spinner /> : <XIcon />}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
+13
-7
@@ -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: "" };
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import Image from "next/image";
|
||||
import { Button } from "./ui/button";
|
||||
import login from "@/app/actions/login";
|
||||
import { login } from "@/lib/user/actions";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import Link from "next/link";
|
||||
import { getNavLinks } from "@/lib/navlinks/repository";
|
||||
@@ -23,7 +23,7 @@ export default async function Header() {
|
||||
<div className="absolute left-1/2 -translate-x-1/2 flex items-center gap-6">
|
||||
{
|
||||
links.map((link) => (
|
||||
<Link className="hover:underline underline-offset-8 decoration-2 duration-200" key={link.id} href={link.href || `/${link.page.type.toLowerCase()}/${link.page.slug}`}><h3>{link.label ?? link.page?.title}</h3></Link>
|
||||
<Link className="hover:underline underline-offset-8 decoration-2 duration-200" key={link.id} href={link.href || (link.page ? `/${link.page.type.toLowerCase()}/${link.page.slug}` : "/")}><h3>{link.label ?? link.page?.title}</h3></Link>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@ export function NewsCard({ news }: { news: Page }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-2">
|
||||
<Link href={`/news/${news.slug}`} className="w-max">
|
||||
<h2 className="hover: duration-200 cursor-pointer">{news.title}</h2>
|
||||
<h2 className="hover:underline underline-offset-8 decoration-2 hover:duration-200 cursor-pointer">{news.title}</h2>
|
||||
</Link>
|
||||
<div className="flex flex-row gap-8 items-center">
|
||||
<p className="flex gap-2 items-center"><CalendarIcon size={16} />{formatDate(news.publishedAt)}</p>
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"
|
||||
import { Accordion as AccordionPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Accordion({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Root>) {
|
||||
return (
|
||||
<AccordionPrimitive.Root
|
||||
data-slot="accordion"
|
||||
className={cn("flex w-full flex-col", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Item>) {
|
||||
return (
|
||||
<AccordionPrimitive.Item
|
||||
data-slot="accordion-item"
|
||||
className={cn("not-last:border-b", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionTrigger({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Trigger>) {
|
||||
return (
|
||||
<AccordionPrimitive.Header className="flex">
|
||||
<AccordionPrimitive.Trigger
|
||||
data-slot="accordion-trigger"
|
||||
className={cn(
|
||||
"group/accordion-trigger relative flex flex-1 items-start justify-between rounded-lg border border-transparent py-2.5 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:after:border-ring disabled:pointer-events-none disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-muted-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<ChevronDownIcon
|
||||
data-slot="accordion-trigger-icon"
|
||||
className="pointer-events-none shrink-0 group-aria-expanded/accordion-trigger:hidden"
|
||||
/>
|
||||
<ChevronUpIcon
|
||||
data-slot="accordion-trigger-icon"
|
||||
className="pointer-events-none hidden shrink-0 group-aria-expanded/accordion-trigger:inline"
|
||||
/>
|
||||
</AccordionPrimitive.Trigger>
|
||||
</AccordionPrimitive.Header>
|
||||
)
|
||||
}
|
||||
|
||||
function AccordionContent({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof AccordionPrimitive.Content>) {
|
||||
return (
|
||||
<AccordionPrimitive.Content
|
||||
data-slot="accordion-content"
|
||||
className={cn(
|
||||
"overflow-hidden text-sm data-[state=open]:animate-accordion-down data-[state=closed]:animate-accordion-up",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div className="pt-0 pb-2.5 [&_a]:underline [&_a]:underline-offset-3 [&_a]:hover:text-foreground [&_p:not(:last-child)]:mb-4">
|
||||
{children}
|
||||
</div>
|
||||
</AccordionPrimitive.Content>
|
||||
)
|
||||
}
|
||||
|
||||
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
|
||||
@@ -242,7 +242,7 @@ function DropdownMenuSubContent({
|
||||
return (
|
||||
<DropdownMenuPrimitive.SubContent
|
||||
data-slot="dropdown-menu-sub-content"
|
||||
className={cn("z-50 min-w-[96px] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className )}
|
||||
className={cn("z-50 min-w-24 origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-lg bg-popover p-1 text-popover-foreground shadow-lg ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", className )}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
"use client"
|
||||
|
||||
import * as React from "react"
|
||||
import { RadioGroup as RadioGroupPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function RadioGroup({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof RadioGroupPrimitive.Root>) {
|
||||
return (
|
||||
<RadioGroupPrimitive.Root
|
||||
data-slot="radio-group"
|
||||
className={cn("grid gap-2", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function RadioGroupItem({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof RadioGroupPrimitive.Item>) {
|
||||
return (
|
||||
<RadioGroupPrimitive.Item
|
||||
data-slot="radio-group-item"
|
||||
className={cn(
|
||||
"aspect-square size-4 shrink-0 rounded-full border border-input shadow-xs outline-none transition-[color,box-shadow] focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<RadioGroupPrimitive.Indicator className="flex items-center justify-center">
|
||||
<div className="size-1.5 rounded-full bg-current" />
|
||||
</RadioGroupPrimitive.Indicator>
|
||||
</RadioGroupPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
export { RadioGroup, RadioGroupItem }
|
||||
@@ -0,0 +1,25 @@
|
||||
"use client"
|
||||
|
||||
import { Toaster as SonnerToaster, type ToasterProps } from "sonner"
|
||||
|
||||
const Toaster = ({ ...props }: ToasterProps) => {
|
||||
return (
|
||||
<SonnerToaster
|
||||
className="toaster group"
|
||||
toastOptions={{
|
||||
classNames: {
|
||||
toast:
|
||||
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
||||
description: "group-[.toast]:text-muted-foreground",
|
||||
actionButton:
|
||||
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
||||
cancelButton:
|
||||
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
|
||||
},
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Toaster }
|
||||
Reference in New Issue
Block a user