Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89012c215f | ||
|
|
e234407a17 | ||
|
|
e826e7b099 | ||
|
|
2e4ea8a052 | ||
|
|
e46235600b | ||
|
|
8aeacaf0ea | ||
|
|
00ed4f923b | ||
|
|
670a7d31c9 | ||
|
|
3f03ee0742 | ||
|
|
e957879212 |
-82
@@ -1,82 +0,0 @@
|
||||
kind: pipeline
|
||||
type: docker
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: lint frontend
|
||||
image: node:20-alpine
|
||||
commands:
|
||||
- npm install
|
||||
- npm run lint
|
||||
|
||||
- name: build and push frontend
|
||||
image: docker:24
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
- name: appdir
|
||||
path: /opt/app
|
||||
commands:
|
||||
- docker build
|
||||
-t localhost:5000/eu:latest
|
||||
-f ./Dockerfile
|
||||
.
|
||||
- docker push localhost:5000/eu:latest
|
||||
|
||||
- name: deploy
|
||||
image: docker:24
|
||||
volumes:
|
||||
- name: dockersock
|
||||
path: /var/run/docker.sock
|
||||
- name: appdir
|
||||
path: /opt/app
|
||||
environment:
|
||||
PUBLIC_URL:
|
||||
from_secret: PUBLIC_URL
|
||||
DATABASE_URL:
|
||||
from_secret: DATABASE_URL
|
||||
KOTOSOFT_ID_API_PUBLIC_URL:
|
||||
from_secret: KOTOSOFT_ID_API_PUBLIC_URL
|
||||
KOTOSOFT_ID_API_URL:
|
||||
from_secret: KOTOSOFT_ID_API_URL
|
||||
KOTOSOFT_CLIENT_ID:
|
||||
from_secret: KOTOSOFT_CLIENT_ID
|
||||
KOTOSOFT_CLIENT_SECRET:
|
||||
from_secret: KOTOSOFT_CLIENT_SECRET
|
||||
JWT_SECRET:
|
||||
from_secret: JWT_SECRET
|
||||
MINIO_URL:
|
||||
from_secret: MINIO_URL
|
||||
MINIO_ACCESS_KEY:
|
||||
from_secret: MINIO_ACCESS_KEY
|
||||
MINIO_SECRET_KEY:
|
||||
from_secret: MINIO_SECRET_KEY
|
||||
MINIO_PUBLIC_URL:
|
||||
from_secret: MINIO_PUBLIC_URL
|
||||
VIRTUAL_HOST:
|
||||
from_secret: API_DOMAIN
|
||||
LETSENCRYPT_HOST:
|
||||
from_secret: API_DOMAIN
|
||||
LETSENCRYPT_EMAIL:
|
||||
from_secret: LETSENCRYPT_EMAIL
|
||||
DOMAIN:
|
||||
from_secret: DOMAIN
|
||||
commands:
|
||||
- apk add --no-cache docker-cli-compose
|
||||
- mkdir -p /opt/app
|
||||
- cp docker-compose.yml /opt/app/docker-compose.yml
|
||||
- cd /opt/app
|
||||
- docker compose -p eu pull
|
||||
- docker compose -p eu up -d --remove-orphans
|
||||
|
||||
volumes:
|
||||
- name: dockersock
|
||||
host:
|
||||
path: /var/run/docker.sock
|
||||
- name: appdir
|
||||
host:
|
||||
path: /opt/drone/eu
|
||||
|
||||
trigger:
|
||||
branch:
|
||||
- main
|
||||
@@ -0,0 +1,87 @@
|
||||
name: Build and Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
lint-frontend:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Lint frontend
|
||||
run: npm run lint
|
||||
|
||||
build-frontend:
|
||||
needs: lint-frontend
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
cache: 'npm'
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Build frontend
|
||||
run: npm run build
|
||||
|
||||
- name: Build and push Docker image
|
||||
run: |
|
||||
docker build -t ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE }}:latest .
|
||||
docker push ${{ vars.DOCKER_REGISTRY }}/${{ vars.DOCKER_IMAGE }}:latest
|
||||
|
||||
deploy:
|
||||
needs: build-frontend
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup SSH key
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
cat > ~/.ssh/deploy_key << 'EOF'
|
||||
${{ secrets.DEPLOY_SSH_KEY }}
|
||||
EOF
|
||||
chmod 600 ~/.ssh/deploy_key
|
||||
ssh-keyscan -p ${{ vars.DEPLOY_PORT }} ${{ vars.DEPLOY_HOST }} >> ~/.ssh/known_hosts 2>/dev/null || true
|
||||
|
||||
- name: Create .env file on server
|
||||
run: |
|
||||
ssh -i ~/.ssh/deploy_key -p ${{ vars.DEPLOY_PORT }} ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }} \
|
||||
"cat > /opt/app/.env" << 'ENVEOF'
|
||||
PUBLIC_URL=${{ vars.PUBLIC_URL }}
|
||||
DATABASE_URL=${{ secrets.DATABASE_URL }}
|
||||
KOTOSOFT_ID_API_PUBLIC_URL=${{ vars.KOTOSOFT_ID_API_PUBLIC_URL }}
|
||||
KOTOSOFT_ID_API_URL=${{ vars.KOTOSOFT_ID_API_URL }}
|
||||
KOTOSOFT_CLIENT_ID=${{ secrets.KOTOSOFT_CLIENT_ID }}
|
||||
KOTOSOFT_CLIENT_SECRET=${{ secrets.KOTOSOFT_CLIENT_SECRET }}
|
||||
JWT_SECRET=${{ secrets.JWT_SECRET }}
|
||||
MINIO_ACCESS_KEY=${{ secrets.MINIO_ACCESS_KEY }}
|
||||
MINIO_SECRET_KEY=${{ secrets.MINIO_SECRET_KEY }}
|
||||
MINIO_PUBLIC_URL=${{ vars.MINIO_PUBLIC_URL }}
|
||||
LETSENCRYPT_HOST=${{ vars.DOMAIN }}
|
||||
LETSENCRYPT_EMAIL=${{ vars.LETSENCRYPT_EMAIL }}
|
||||
DOMAIN=${{ vars.DOMAIN }}
|
||||
ENVEOF
|
||||
|
||||
- name: Deploy with Docker Compose
|
||||
run: |
|
||||
ssh -i ~/.ssh/deploy_key -p ${{ vars.DEPLOY_PORT }} ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }} \
|
||||
"cd /opt/app && docker compose -p ${{ vars.DOCKER_COMPOSE_PROJECT }} up -d"
|
||||
@@ -16,11 +16,8 @@ COPY --from=builder /app/.next ./.next
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/prisma ./prisma
|
||||
COPY --from=builder /app/next.config.ts ./next.config.ts
|
||||
COPY entrypoint.sh /app/entrypoint.sh
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
RUN npm prune --omit=dev
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["/app/entrypoint.sh"]
|
||||
CMD ["npm", "start", "--", "-p", "3000", "-H", "0.0.0.0"]
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||
CMD wget -q --spider http://localhost:3000/ || exit 1
|
||||
+24
-14
@@ -14,6 +14,7 @@ import { getNavLinkByPageId } from "@/lib/navlinks/repository";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import { Metadata } from "next";
|
||||
import { getImageUrl } from "@/lib/image";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
|
||||
function makeDescription(text?: string, maxLength = 160) {
|
||||
if (!text) return undefined;
|
||||
@@ -127,7 +128,7 @@ function BlockRenderer({ block }: { block: Block }) {
|
||||
|
||||
case "CALLOUT":
|
||||
return (
|
||||
<Alert className="md:w-max">
|
||||
<Alert className="max-w-xl">
|
||||
<InfoIcon />
|
||||
<AlertTitle>{b.title}</AlertTitle>
|
||||
<AlertDescription>{b.text}</AlertDescription>
|
||||
@@ -200,8 +201,8 @@ function BlockRenderer({ block }: { block: Block }) {
|
||||
return <Separator />;
|
||||
|
||||
case "LINK":
|
||||
return <Link href={b.href} target="_blank">
|
||||
<Button variant="secondary" className="max-w-full">{b.label}</Button>
|
||||
return <Link href={b.href} className="w-max " target="_blank">
|
||||
<Button variant="secondary">{b.label}</Button>
|
||||
</Link>
|
||||
|
||||
default:
|
||||
@@ -249,6 +250,8 @@ export default async function Page({ params }: { params: Promise<{ type: string;
|
||||
user?.isAdmin && wasUpdatedByOther && updatedBy
|
||||
? `${updatedBy.firstName} ${updatedBy.secondName}`
|
||||
: null,
|
||||
|
||||
tags: isNews ? page.meta.tags : null,
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -273,18 +276,25 @@ export default async function Page({ params }: { params: Promise<{ type: string;
|
||||
{meta.author && <p className="flex gap-1.5 items-center"><UserIcon size={16} />{meta.author}</p>}
|
||||
{meta.updatedBy && <p className="flex gap-1.5 items-center"><UserIcon size={16} />Last update by {meta.updatedBy}</p>}
|
||||
</div>
|
||||
{isNews && (<div className="flex flex-row gap-4">
|
||||
{((meta as PageMeta)?.tags)?.map((tag) => (
|
||||
<Badge key={tag}>{tag}</Badge>
|
||||
))}
|
||||
</div>)}
|
||||
</div>
|
||||
<div className="flex flex-col gap-6">
|
||||
{isArchived && (
|
||||
<Alert className="md:w-max">
|
||||
<InfoIcon />
|
||||
<AlertTitle>This page is archived</AlertTitle>
|
||||
<AlertDescription>It can be seen only by administrators. Make any edits to make it visible again.</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{resolvedBlocks.map((block) => (
|
||||
<BlockRenderer key={block.id} block={block} />
|
||||
))}
|
||||
<div className={cn(isNews && `max-w-2xl mx-auto`)}>
|
||||
<div className="flex flex-col gap-6 [&>a+a]:-my-2.5">
|
||||
{isArchived && (
|
||||
<Alert className="md:w-max">
|
||||
<InfoIcon />
|
||||
<AlertTitle>This page is archived</AlertTitle>
|
||||
<AlertDescription>It can be seen only by administrators. Make any edits to make it visible again.</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{resolvedBlocks.map((block) => (
|
||||
<BlockRenderer key={block.id} block={block} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { BookOpenTextIcon, UserIcon } from "lucide-react";
|
||||
import { BookOpenTextIcon, BriefcaseBusinessIcon, UserIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
|
||||
@@ -15,6 +15,11 @@ const menuItems = [
|
||||
href: "/account/citizenship",
|
||||
label: "Citizenship",
|
||||
icon: BookOpenTextIcon,
|
||||
},
|
||||
{
|
||||
href: "/account/positions",
|
||||
label: "Positions",
|
||||
icon: BriefcaseBusinessIcon,
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import { Textarea } from "@/components/ui/textarea";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { approveApplication, rejectApplication } from "@/lib/citizenship/actions";
|
||||
import { CitizenshipApplicationWithWarning } from "@/lib/citizenship/types";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import { TriangleAlertIcon } from "lucide-react";
|
||||
import { cn, formatDate } from "@/lib/utils";
|
||||
import { CheckIcon, ClockFadingIcon, PlusIcon, TriangleAlertIcon, XIcon } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
@@ -36,7 +36,6 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
setIsLoading(false)
|
||||
if (result.success) {
|
||||
toast.success("Application approved")
|
||||
onClose()
|
||||
} else {
|
||||
toast.error(result.error ?? "Failed to approve application")
|
||||
}
|
||||
@@ -50,7 +49,6 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
if (result.success) {
|
||||
toast.success("Application rejected")
|
||||
setRejectOpen(false)
|
||||
onClose()
|
||||
} else {
|
||||
toast.error(result.error ?? "Failed to reject application")
|
||||
}
|
||||
@@ -64,24 +62,24 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
<CardDescription>{application.applicationType === "PREVIOUS_CITIZENSHIP" ? "Previous citizenship application" : "Naturalization application"}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="max-w-sm">
|
||||
<div className="flex flex-row gap-3 mb-4">
|
||||
{application.status !== "REJECTED" && (<div className="flex flex-row gap-3 mb-4">
|
||||
<div className="w-20 aspect-4/5 rounded-md overflow-hidden ring-1 ring-foreground/10 shrink-0">
|
||||
<img src={application.profileUrl} alt="Profile photo" className="w-full h-full object-cover" />
|
||||
</div>
|
||||
<div className="w-40 px-2 aspect-5/2 rounded-md overflow-hidden ring-1 ring-foreground/10 shrink-0 bg-white">
|
||||
<img src={application.signatureUrl} alt="Signature" className="w-full h-full object-contain" />
|
||||
</div>
|
||||
</div>
|
||||
</div>)}
|
||||
<div className="flex flex-col gap-1">
|
||||
<h4 className="mb-1">Personal information</h4>
|
||||
{ application.nameMismatch && (
|
||||
{ application.status === "PENDING" && application.nameMismatch && (
|
||||
<Alert className="mb-2" variant="warning">
|
||||
<TriangleAlertIcon />
|
||||
<AlertTitle>Name mismatch</AlertTitle>
|
||||
<AlertDescription className="w-fit max-w-full">The name on this application differs from the applicant's Kotosoft ID. Verify before approving.</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
{ application.previousCitizenship && (
|
||||
{ application.status === "PENDING" && application.previousCitizenship && (
|
||||
<Alert className="mb-2" variant="warning">
|
||||
<TriangleAlertIcon />
|
||||
<AlertTitle>Previous citizenship holder</AlertTitle>
|
||||
@@ -147,17 +145,51 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
</div>
|
||||
)
|
||||
}
|
||||
<Separator className="my-2" />
|
||||
<div className="flex flex-col gap-1">
|
||||
<h4 className="mb-1">Application history</h4>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-row gap-2 items-center text-muted-foreground">
|
||||
<PlusIcon size={16} /><p>Created on {formatDate(application.createdAt)}</p>
|
||||
</div>
|
||||
{application.status !== "PENDING" && (<div className="flex flex-row gap-2 items-center text-muted-foreground">
|
||||
<ClockFadingIcon size={16} /><p>{application.reviewedAt ? `Reviewed on ${formatDate(application.reviewedAt)} by ${application.reviewer?.firstName} ${application.reviewer?.secondName}` : "Reviewed"}</p>
|
||||
</div>)}
|
||||
{application.status === "REJECTED" && (
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<div className="flex flex-row gap-2 items-center text-destructive">
|
||||
<XIcon size={16} /><p>Rejected</p>
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<p>Rejection reason</p>
|
||||
<p className="text-muted-foreground">{application.rejectionReason}</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{application.status === "APPROVED" && (
|
||||
<div className="flex flex-row gap-2 items-center">
|
||||
<CheckIcon size={16} /><p>Approved</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
<CardFooter className="gap-2">
|
||||
<Button onClick={handleApprove} disabled={isloading}>
|
||||
{isloading && <Spinner />}Approve
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setRejectOpen(true)} disabled={isloading}>
|
||||
{isloading && <Spinner />}Reject
|
||||
</Button>
|
||||
<Button variant="outline" onClick={onClose}>Close</Button>
|
||||
</CardFooter>
|
||||
{application.status === "PENDING" ? (
|
||||
<CardFooter className="gap-2">
|
||||
<Button onClick={handleApprove} disabled={isloading}>
|
||||
{isloading && <Spinner />}Approve
|
||||
</Button>
|
||||
<Button variant="outline" onClick={() => setRejectOpen(true)} disabled={isloading}>
|
||||
{isloading && <Spinner />}Reject
|
||||
</Button>
|
||||
<Button variant="outline" onClick={onClose}>Close</Button>
|
||||
</CardFooter>
|
||||
) : (
|
||||
<CardFooter>
|
||||
<Button variant="outline" onClick={onClose}>Close</Button>
|
||||
</CardFooter>
|
||||
)}
|
||||
</Card>
|
||||
<Dialog open={rejectOpen} onOpenChange={setRejectOpen}>
|
||||
<DialogContent>
|
||||
|
||||
@@ -5,6 +5,14 @@ import { CitizenshipApplication } from "@/lib/citizenship/types";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
|
||||
type BadgeVariant = "default" | "outline" | "destructive";
|
||||
|
||||
const variants: Record<string, BadgeVariant> = {
|
||||
PENDING: "outline",
|
||||
REJECTED: "destructive",
|
||||
APPROVED: "default",
|
||||
}
|
||||
|
||||
export const columns: ColumnDef<CitizenshipApplication>[] = [
|
||||
{
|
||||
accessorKey: "surname",
|
||||
@@ -31,7 +39,7 @@ export const columns: ColumnDef<CitizenshipApplication>[] = [
|
||||
header: "Status",
|
||||
cell: ({ row }) => {
|
||||
const status = row.getValue("status") as string
|
||||
return <Badge variant={status === "PENDING" ? "outline" : "default"}>{status}</Badge>
|
||||
return <Badge variant={variants[status] ?? "default"}>{status}</Badge>
|
||||
},
|
||||
},
|
||||
]
|
||||
@@ -2,9 +2,10 @@ import ReviewPageClient from "./client";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AccountMenu } from "../../account-menu";
|
||||
import { getPendingApplications } from "@/lib/citizenship/repository";
|
||||
import { getAllApplications } from "@/lib/citizenship/repository";
|
||||
import { getImageUrl } from "@/lib/image";
|
||||
import { Metadata } from "next";
|
||||
import { findUserById } from "@/lib/user/repository";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Review citizenship applications",
|
||||
@@ -18,21 +19,31 @@ export default async function ReviewPage() {
|
||||
const user = await getCurrentUser();
|
||||
if (!user?.isAdmin) redirect("/account/citizenship");
|
||||
|
||||
const applications = await getPendingApplications();
|
||||
const applications = await getAllApplications();
|
||||
|
||||
const applicationsWithWarning = await Promise.all(
|
||||
applications.map(async (application) => ({
|
||||
...application,
|
||||
profileUrl: await getImageUrl(application.profileKey),
|
||||
signatureUrl: await getImageUrl(application.signatureKey),
|
||||
applications.map(async (application) => {
|
||||
const reviewerUser = application.reviewedBy
|
||||
? await findUserById(application.reviewedBy)
|
||||
: null;
|
||||
|
||||
nameMismatch:
|
||||
application.givenNames !== application.user.firstName ||
|
||||
application.surname !== application.user.secondName,
|
||||
return {
|
||||
...application,
|
||||
profileUrl: await getImageUrl(application.profileKey),
|
||||
signatureUrl: await getImageUrl(application.signatureKey),
|
||||
|
||||
previousCitizenship:
|
||||
application.user._count.citizenships > 0,
|
||||
}))
|
||||
nameMismatch:
|
||||
application.givenNames !== application.user.firstName ||
|
||||
application.surname !== application.user.secondName,
|
||||
|
||||
previousCitizenship:
|
||||
application.user._count.citizenships > 0,
|
||||
|
||||
reviewer: reviewerUser
|
||||
? { firstName: reviewerUser.firstName, secondName: reviewerUser.secondName }
|
||||
: null,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
"use client";
|
||||
|
||||
import {
|
||||
Dialog, DialogClose, DialogContent,
|
||||
DialogFooter, DialogHeader, DialogTitle, DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { createPosition } from "@/lib/positions/actions";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { startTransition, useActionState, useEffect, useState } from "react";
|
||||
import { initialFormState } from "@/lib/form-action";
|
||||
import { Field, FieldError, FieldGroup, FieldLabel } from "@/components/ui/field";
|
||||
import { Institution } from "@/lib/acts/types";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export function CreatePositionDialog({ institutions }: { institutions: Institution[] }) {
|
||||
const [state, formAction, isPending] = useActionState(createPosition, initialFormState);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [name, setName] = useState("");
|
||||
const [institutionId, setInstitutionId] = useState("");
|
||||
|
||||
const handleSubmit = () => {
|
||||
const formData = new FormData();
|
||||
formData.set("name", name);
|
||||
formData.set("institutionId", institutionId);
|
||||
|
||||
startTransition(() => formAction(formData));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (state.success) {
|
||||
setIsOpen(false);
|
||||
setName("");
|
||||
setInstitutionId("");
|
||||
toast("Position successfully created")
|
||||
}
|
||||
}, [state.success]);
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="secondary" className="w-max">Create a new position</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle asChild><h3>Create a new position</h3></DialogTitle>
|
||||
</DialogHeader>
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="name">Position name</FieldLabel>
|
||||
<Input
|
||||
placeholder="Position name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
/>
|
||||
{state.fieldErrors?.name && <FieldError>{state.fieldErrors.name}</FieldError>}
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="name">Institution</FieldLabel>
|
||||
<Select onValueChange={setInstitutionId} value={institutionId}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Select institution" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{
|
||||
institutions.map((institution) => (
|
||||
<SelectItem key={institution.id} value={institution.id}>{institution.name}</SelectItem>
|
||||
))
|
||||
}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{state.fieldErrors?.institutionId && <FieldError>{state.fieldErrors.institutionId}</FieldError>}
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
{state.error && <FieldError>{state.error}</FieldError>}
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="outline" disabled={isPending}>Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button
|
||||
type="submit"
|
||||
disabled={isPending}
|
||||
onClick={handleSubmit}>
|
||||
{isPending && <Spinner />}Create
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { getCurrentUser, getUsers } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AccountMenu } from "../account-menu";
|
||||
import { Metadata } from "next";
|
||||
import { getUserPositions } from "@/lib/positions/repository";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { CreatePositionDialog } from "./create-position-dialog";
|
||||
import { getInstitutions } from "@/lib/acts/repository";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import Link from "next/link";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Positions",
|
||||
robots: {
|
||||
index: false,
|
||||
follow: false,
|
||||
},
|
||||
};
|
||||
|
||||
export default async function Account() {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) redirect("/");
|
||||
|
||||
const userPositions = await getUserPositions(user.id);
|
||||
const institutions = await getInstitutions();
|
||||
|
||||
return (
|
||||
<div className="flex flex-col md:flex-row p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
||||
<AccountMenu />
|
||||
<div className="flex flex-col gap-8 max-w-lg">
|
||||
<div className="flex flex-col gap-6">
|
||||
<div className="flex flex-col gap-1">
|
||||
<h2>Positions</h2>
|
||||
<p className="text-muted-foreground text-sm">Here are your positions in the European Federation</p>
|
||||
</div>
|
||||
{userPositions.length === 0 ? <p className="text-muted-foreground">You do not have any positions</p> :
|
||||
<div className="flex flex-col gap-4">
|
||||
{userPositions.map((position) => (
|
||||
<div key={position.id} className="flex flex-col gap-0.5">
|
||||
<h4>{position.position.name}</h4>
|
||||
<p className="text-muted-foreground">Assigned on {formatDate(position.assignedAt)} by <Link href={`/acts/${position.actId}`} className="underline">{position.act?.actType.name} {position.act?.numberInSeries && `№${position.act.numberInSeries}/${position.act.numberYear}`}</Link></p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
}
|
||||
{user.isAdmin && (
|
||||
<div className="flex flex-col gap-2">
|
||||
<CreatePositionDialog institutions={institutions} />
|
||||
<p className="text-muted-foreground">
|
||||
To assign or dismiss someone from a position, create an appointment act.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { useAction } from "@/hooks/useAction";
|
||||
import { approveActAction } from "@/lib/acts/actions";
|
||||
import { CheckIcon } from "lucide-react";
|
||||
|
||||
export function ApproveButton({ actId }: { actId: string }) {
|
||||
const { run, isPending } = useAction(approveActAction, {
|
||||
successMessage: "Approved",
|
||||
});
|
||||
|
||||
return (
|
||||
<Button className="w-max" disabled={isPending} onClick={() => run(actId)}>
|
||||
{isPending ? <Spinner /> : <CheckIcon />}
|
||||
Approve
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import {
|
||||
ArticleContent,
|
||||
PreambleContent,
|
||||
LEGAL_STATUS_LABELS,
|
||||
} from "@/lib/acts/types";
|
||||
import {
|
||||
getActById,
|
||||
getActTypeById,
|
||||
getInstitutionById,
|
||||
getActVersions,
|
||||
getCurrentActVersion,
|
||||
getActBlocks,
|
||||
getActApprovals,
|
||||
} from "@/lib/acts/repository";
|
||||
import { getPositions, getCitizenshipPositions } from "@/lib/positions/repository";
|
||||
import { getActiveCitizenship } from "@/lib/citizenship/repository";
|
||||
import { getActFlow, getNextPhase } from "@/lib/acts/flows";
|
||||
import { ApproveButton } from "./approve-button";
|
||||
import { VetoButton } from "./veto-button";
|
||||
import { getCurrentUser, getUsers } from "@/lib/user";
|
||||
import { cn, formatDate } from "@/lib/utils";
|
||||
import { Metadata } from "next";
|
||||
import { Merriweather } from "next/font/google";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
const documentText = Merriweather({ weight: "400" });
|
||||
const documentHeading = Merriweather({ weight: "700" });
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<{ id: string }> }): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
|
||||
const act = await getActById(id);
|
||||
if (!act) return {};
|
||||
|
||||
const type = await getActTypeById(act.actTypeId);
|
||||
|
||||
return {
|
||||
title: `${type?.name ?? ""}${act.title ? ` “${act.title}”` : ""}`,
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Act({ params }: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await params;
|
||||
const user = await getCurrentUser();
|
||||
|
||||
const act = await getActById(id);
|
||||
if (!act) notFound();
|
||||
|
||||
const type = await getActTypeById(act.actTypeId);
|
||||
const institution = await getInstitutionById(act.issuingInstitutionId);
|
||||
const [author] = await getUsers(act.authorId);
|
||||
const versions = await getActVersions(id);
|
||||
const version = await getCurrentActVersion(id);
|
||||
if (!version) notFound();
|
||||
|
||||
const blocks = await getActBlocks(version.id);
|
||||
const needsRegion = institution?.kind === "REGION";
|
||||
const preamble = blocks.find((b) => b.type === "PREAMBLE");
|
||||
const preambleContent = preamble?.content as PreambleContent | undefined;
|
||||
|
||||
const approvals = await getActApprovals(version.id);
|
||||
const positions = await getPositions();
|
||||
const positionNames = new Map(positions.map((p) => [p.id, p.name]));
|
||||
|
||||
const flow = getActFlow(type?.code ?? "");
|
||||
const phase = getNextPhase(flow, approvals);
|
||||
const stageLabel = phase?.label ?? "Completed";
|
||||
|
||||
let canApprove = false;
|
||||
let canVeto = false;
|
||||
|
||||
if (user && act.legalStatus === "DRAFT" && phase) {
|
||||
const citizenship = await getActiveCitizenship(user.id);
|
||||
if (citizenship) {
|
||||
const citizenshipPositions = await getCitizenshipPositions(citizenship.id);
|
||||
const holds = citizenshipPositions.some(
|
||||
(p) => !p.resignedAt && p.position.capabilities.some((c) => c.capability === phase.capability)
|
||||
);
|
||||
canApprove = holds;
|
||||
canVeto = holds && !!phase.allowVeto;
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
||||
<div className="flex flex-col gap-8 md:flex-row justify-between">
|
||||
<div className="flex flex-col gap-8">
|
||||
<Card size="sm" className="h-max">
|
||||
<CardHeader>
|
||||
<CardTitle>
|
||||
<h3>
|
||||
{type?.name} {act.title && `“${act.title}”`}{" "}
|
||||
{act.numberInSeries ? `№${act.numberInSeries}/${act.numberYear}` : <span className="text-muted-foreground">without a number</span>}
|
||||
</h3>
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-col">
|
||||
<p className="text-muted-foreground">Issuing institution</p>
|
||||
<p>{institution?.name}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Author</p>
|
||||
<p>{author?.firstName} {author?.secondName}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Created</p>
|
||||
<p>{formatDate(act.createdAt)}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Version from</p>
|
||||
<p>{formatDate(version.createdAt)}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Process stage</p>
|
||||
<p>{stageLabel}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Legal status</p>
|
||||
{act.legalStatus === "NOT_ADOPTED" ? <Badge variant="destructive">{LEGAL_STATUS_LABELS[act.legalStatus]}</Badge> : <p>{LEGAL_STATUS_LABELS[act.legalStatus]}</p>}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card size="sm" className="h-max">
|
||||
<CardHeader>
|
||||
<CardTitle><h3>History</h3></CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="flex flex-col gap-4">
|
||||
{versions.map((v) =>
|
||||
v.id === version.id ? (
|
||||
<div className="flex flex-col gap-1" key={v.id}>
|
||||
<h4>Version from {formatDate(v.createdAt)}</h4>
|
||||
<Badge>Current</Badge>
|
||||
</div>
|
||||
) : (
|
||||
<Link href={`/acts/${act.id}/${v.id}`} className="flex flex-col gap-1" key={v.id}>
|
||||
<h4 className="text-muted-foreground">Version from {formatDate(v.createdAt)}</h4>
|
||||
<Badge variant="secondary">Outdated</Badge>
|
||||
</Link>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{ (canApprove || canVeto) && (
|
||||
<Card size="sm" className="h-max">
|
||||
<CardHeader>
|
||||
<CardTitle><h3>Signature</h3></CardTitle>
|
||||
<CardDescription><p>You are able to sign or reject this act</p></CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="flex flex-row gap-3">
|
||||
{canApprove && <ApproveButton actId={act.id} />}
|
||||
{canVeto && <VetoButton actId={act.id} vetoLabel={phase?.vetoLabel || "Veto"} />}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-1 flex-col gap-6">
|
||||
<div className="flex flex-col items-center gap-6">
|
||||
<Image src="/emblems/europe.png" width={52} height={32} alt="Emblem of the European Federation" />
|
||||
<div className={cn("flex flex-col gap-1", documentHeading.className)}>
|
||||
<h3 className="text-center">{!needsRegion ? "European Federation" : "Region"}</h3>
|
||||
<h3 className="text-center">{institution?.name}</h3>
|
||||
</div>
|
||||
<h3 className={cn("text-center", documentHeading.className)}>
|
||||
{type?.name} {act.numberInSeries && `№${act.numberInSeries}/${act.numberYear}`} {act.title && `“${act.title}”`}
|
||||
</h3>
|
||||
</div>
|
||||
<div className="flex flex-col gap-4">
|
||||
{preambleContent && (
|
||||
<h4 className={cn("shrink-0", documentText.className)}>{preambleContent.text}</h4>
|
||||
)}
|
||||
{blocks
|
||||
.filter((b) => b.type === "ARTICLE")
|
||||
.map((block, index) => {
|
||||
const article = block.content as ArticleContent;
|
||||
return (
|
||||
<div className="flex flex-col gap-2" key={block.stableKey}>
|
||||
<div className="flex items-center gap-2">
|
||||
<h4 className={cn("shrink-0", documentHeading.className)}>
|
||||
Article {index + 1}{article.title && `. ${article.title}.`}
|
||||
</h4>
|
||||
</div>
|
||||
{article.intro && <h4 className={documentText.className}>{article.intro}</h4>}
|
||||
<div className="flex flex-col gap-2">
|
||||
{article.clauses.map((clause, clauseIndex) => (
|
||||
<h4 key={clause.id} className={documentText.className}>
|
||||
{article.markerStyle === "NUMBERS" && `${clauseIndex + 1}. `}
|
||||
{article.markerStyle === "LETTERS" && `${String.fromCharCode(97 + clauseIndex)}) `}
|
||||
{clause.kind === "APPOINTMENT"
|
||||
? `${clause.action === "ASSIGN" ? "Appoint" : "Dismiss"} ${clause.citizenshipName} ${clause.action === "ASSIGN" ? "to" : "from"} ${positionNames.get(clause.positionId) ?? "an unknown position"}.`
|
||||
: clause.text}
|
||||
</h4>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
<div className="flex flex-col gap-4">
|
||||
{approvals.map((a) => (
|
||||
<div className="flex flex-col gap-1 border-4 border-primary w-max p-2" key={a.id}>
|
||||
<h4 className={documentHeading.className}>{a.name}</h4>
|
||||
<h4 className={documentText.className}>{a.role}</h4>
|
||||
<p className={documentText.className}>
|
||||
{a.decision === "APPROVE" ? "Approved" : "Vetoed"} at {formatDate(a.decidedAt)}
|
||||
</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { useAction } from "@/hooks/useAction";
|
||||
import { vetoActAction } from "@/lib/acts/actions";
|
||||
import { XIcon } from "lucide-react";
|
||||
|
||||
export function VetoButton({ actId, vetoLabel }: { actId: string, vetoLabel: string }) {
|
||||
const { run, isPending } = useAction(vetoActAction, {
|
||||
successMessage: "Vetoed",
|
||||
});
|
||||
|
||||
return (
|
||||
<Button variant="destructive" className="w-max" disabled={isPending} onClick={() => run(actId)}>
|
||||
{isPending ? <Spinner /> : <XIcon />}
|
||||
{vetoLabel}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
"use client";
|
||||
|
||||
import { useRef } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import ActEditor from "./editor";
|
||||
import { saveActAction } from "@/lib/acts/actions";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { useAction } from "@/hooks/useAction";
|
||||
import { ActEditorData } from "@/lib/acts/types";
|
||||
|
||||
export default function CreateActClient({ actTypes, institutions, regions, positions }: {
|
||||
actTypes: { id: string; name: string; allowedIssuerKind: string }[];
|
||||
institutions: { id: string; name: string; kind: string; appointedByInstitutionId: string | null }[];
|
||||
regions: { id: string; name: string }[];
|
||||
positions: { id: string; name: string; institutionId: string }[];
|
||||
}) {
|
||||
const router = useRouter();
|
||||
|
||||
const { run, isPending } = useAction(saveActAction, {
|
||||
successMessage: "Act saved",
|
||||
onSuccess: () => router.push("/acts"),
|
||||
});
|
||||
|
||||
const dataRef = useRef<ActEditorData>({
|
||||
actTypeId: "",
|
||||
issuingInstitutionId: "",
|
||||
title: "",
|
||||
preambleText: "",
|
||||
regionId: null,
|
||||
articles: [],
|
||||
});
|
||||
|
||||
function handleSave() {
|
||||
const data = dataRef.current;
|
||||
run(data);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col p-4 md:p-16 gap-6 md:gap-12 mb-4 md:mb-0">
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between">
|
||||
<h1>Create act</h1>
|
||||
<div className="flex flex-row gap-3">
|
||||
<Button disabled={isPending} onClick={handleSave}>
|
||||
{isPending && <Spinner />}
|
||||
Save
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<ActEditor
|
||||
actTypes={actTypes}
|
||||
institutions={institutions}
|
||||
regions={regions}
|
||||
positions={positions}
|
||||
onChange={(data) => { dataRef.current = data; }}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FieldError, FieldGroup, FieldLabel, FieldSet } from "@/components/ui/field";
|
||||
import { InputGroup, InputGroupInput } from "@/components/ui/input-group";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { PlusIcon, XIcon, ChevronDownIcon, ChevronUpIcon, Trash2Icon, ListOrderedIcon, CaseLowerIcon, UserCogIcon } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import Image from "next/image";
|
||||
import { Merriweather } from "next/font/google";
|
||||
import { ActEditorData, ActType, ArticleContent, Clause, ClauseMarkerStyle, Institution, PositionOption, Region } from "@/lib/acts/types";
|
||||
import { searchCitizensAction } from "@/lib/citizenship/actions";
|
||||
|
||||
const documentText = Merriweather({ weight: "400" });
|
||||
const documentHeading = Merriweather({ weight: "700" });
|
||||
|
||||
type ActEditorProps = {
|
||||
actTypes: ActType[];
|
||||
institutions: Institution[];
|
||||
regions: Region[];
|
||||
positions: PositionOption[];
|
||||
initial?: Partial<ActEditorData>;
|
||||
onChange: (data: ActEditorData) => void;
|
||||
errors?: { title?: string[]; issuingInstitutionId?: string[] };
|
||||
};
|
||||
|
||||
const LETTER_MARKERS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"];
|
||||
|
||||
function computeMarker(style: ClauseMarkerStyle, index: number): string | null {
|
||||
if (style === "NONE") return null;
|
||||
if (style === "LETTERS") return `${LETTER_MARKERS[index] ?? index + 1})`;
|
||||
return `${index + 1}.`;
|
||||
}
|
||||
|
||||
function makeEmptyTextClause(): Clause {
|
||||
return { id: uuidv4(), kind: "TEXT", text: "" };
|
||||
}
|
||||
|
||||
function makeEmptyAppointmentClause(): Clause {
|
||||
return { id: uuidv4(), kind: "APPOINTMENT", action: "ASSIGN", positionId: "", citizenshipId: "", citizenshipName: "" };
|
||||
}
|
||||
|
||||
function makeEmptyArticle(): ArticleContent {
|
||||
return { id: uuidv4(), title: "", markerStyle: "NONE", clauses: [makeEmptyTextClause()] };
|
||||
}
|
||||
|
||||
export default function ActEditor({ actTypes, institutions, regions, positions, initial, onChange, errors }: ActEditorProps) {
|
||||
const [issuingInstitutionId, setIssuingInstitutionId] = useState(initial?.issuingInstitutionId ?? "");
|
||||
const [actTypeId, setActTypeId] = useState(initial?.actTypeId ?? "");
|
||||
const [regionId, setRegionId] = useState(initial?.regionId ?? "");
|
||||
const [title, setTitle] = useState(initial?.title ?? "");
|
||||
const [preambleText, setPreambleText] = useState(initial?.preambleText ?? "");
|
||||
const [articles, setArticles] = useState<ArticleContent[]>(initial?.articles ?? [makeEmptyArticle()]);
|
||||
|
||||
const onChangeRef = useRef(onChange);
|
||||
useEffect(() => { onChangeRef.current = onChange; });
|
||||
|
||||
useEffect(() => {
|
||||
onChangeRef.current({ actTypeId, issuingInstitutionId, regionId, title, preambleText, articles });
|
||||
}, [actTypeId, issuingInstitutionId, regionId, title, preambleText, articles]);
|
||||
|
||||
const appointablePositions = positions.filter((p) => {
|
||||
const owner = institutions.find((i) => i.id === p.institutionId);
|
||||
const requiredIssuerId = owner?.appointedByInstitutionId ?? owner?.id;
|
||||
return requiredIssuerId === issuingInstitutionId;
|
||||
});
|
||||
|
||||
const selectedInstitution = institutions.find((i) => i.id === issuingInstitutionId);
|
||||
const availableActTypes = selectedInstitution
|
||||
? actTypes.filter((t) => t.allowedIssuerKind === selectedInstitution.kind)
|
||||
: [];
|
||||
const needsRegion = selectedInstitution?.kind === "REGION";
|
||||
|
||||
function updateArticle(id: string, patch: Partial<ArticleContent>) {
|
||||
setArticles(articles.map((a) => (a.id === id ? { ...a, ...patch } : a)));
|
||||
}
|
||||
|
||||
function addArticle() {
|
||||
setArticles([...articles, makeEmptyArticle()]);
|
||||
}
|
||||
|
||||
function removeArticle(id: string) {
|
||||
setArticles(articles.filter((a) => a.id !== id));
|
||||
}
|
||||
|
||||
function moveArticle(from: number, to: number) {
|
||||
const updated = [...articles];
|
||||
const [moved] = updated.splice(from, 1);
|
||||
updated.splice(to, 0, moved);
|
||||
setArticles(updated);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-10">
|
||||
<FieldSet>
|
||||
<h2 className="md:mb-4">Meta</h2>
|
||||
<FieldGroup>
|
||||
<Field data-invalid={!!errors?.issuingInstitutionId?.length}>
|
||||
<FieldLabel>Issuing institution</FieldLabel>
|
||||
<Select
|
||||
value={issuingInstitutionId}
|
||||
onValueChange={(v) => {
|
||||
setIssuingInstitutionId(v);
|
||||
setActTypeId("");
|
||||
setRegionId("");
|
||||
}}
|
||||
>
|
||||
<SelectTrigger><SelectValue placeholder="Select an institution" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
{institutions.map((i) => (
|
||||
<SelectItem key={i.id} value={i.id}>{i.name}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors?.issuingInstitutionId && <FieldError errors={errors.issuingInstitutionId.map((m) => ({ message: m }))} />}
|
||||
</Field>
|
||||
|
||||
<Field>
|
||||
<FieldLabel>Act type</FieldLabel>
|
||||
<Select value={actTypeId} onValueChange={setActTypeId}>
|
||||
<SelectTrigger><SelectValue placeholder={issuingInstitutionId ? "Select a type" : "Select an institution first"} /></SelectTrigger>
|
||||
<SelectContent>
|
||||
{availableActTypes.map((t) => (
|
||||
<SelectItem key={t.id} value={t.id}>{t.name}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
|
||||
{needsRegion && (
|
||||
<Field>
|
||||
<FieldLabel>Region</FieldLabel>
|
||||
<Select value={regionId} onValueChange={setRegionId}>
|
||||
<SelectTrigger><SelectValue placeholder="Select a region" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
{regions.map((r) => (
|
||||
<SelectItem key={r.id} value={r.id}>{r.name}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</Field>
|
||||
)}
|
||||
|
||||
<Field data-invalid={!!errors?.title?.length}>
|
||||
<FieldLabel htmlFor="title">Title</FieldLabel>
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
id="title"
|
||||
value={title}
|
||||
placeholder="On Citizenship"
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
/>
|
||||
</InputGroup>
|
||||
{errors?.title && <FieldError errors={errors.title.map((m) => ({ message: m }))} />}
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
|
||||
<div className="flex flex-col gap-6">
|
||||
<div className="flex flex-col items-center gap-6">
|
||||
<Image src="/emblems/europe.png" width={52} height={32} alt="Emblem of the European Federation" />
|
||||
<div className={cn("flex flex-col items-center gap-1", documentHeading.className)}>
|
||||
<h3>{!needsRegion ? "European Federation" : regions.find((region) => region.id === regionId)?.name}</h3>
|
||||
<h3>{institutions.find((i) => i.id === issuingInstitutionId)?.name}</h3>
|
||||
</div>
|
||||
<h3 className={documentHeading.className}>
|
||||
Draft of a {actTypes.find((a) => a.id === actTypeId)?.name} {title && `“${title}”`}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<AutoResizeTextarea
|
||||
className={cn("w-full bg-transparent resize-none outline-none leading-relaxed placeholder:text-muted-foreground", documentText.className)}
|
||||
placeholder="Preamble (optional)"
|
||||
value={preambleText}
|
||||
onChange={(e) => setPreambleText(e.target.value)}
|
||||
/>
|
||||
<div className="flex flex-col gap-6">
|
||||
{articles.map((article, index) => (
|
||||
<div key={article.id} className="group relative flex flex-row gap-2 items-start">
|
||||
<div className="flex-1 min-w-0">
|
||||
<ArticleEditor
|
||||
content={article}
|
||||
articleIndex={index}
|
||||
appointablePositions={positions}
|
||||
onChange={(patch) => updateArticle(article.id, patch)}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 items-center lg:opacity-0 group-hover:opacity-100 transition-opacity shrink-0 pt-2">
|
||||
<Button variant="ghost" size="icon-sm" onClick={() => moveArticle(index, index - 1)} disabled={index === 0}>
|
||||
<ChevronUpIcon />
|
||||
</Button>
|
||||
<Button variant="ghost" size="icon-sm" onClick={() => moveArticle(index, index + 1)} disabled={index === articles.length - 1}>
|
||||
<ChevronDownIcon />
|
||||
</Button>
|
||||
{articles.length > 1 && (
|
||||
<Button variant="ghost" size="icon-sm" onClick={() => removeArticle(article.id)}>
|
||||
<Trash2Icon />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<Button variant="outline" size="sm" className="w-max mt-4 gap-1.5 text-muted-foreground" onClick={addArticle}>
|
||||
<PlusIcon size={14} />
|
||||
Add article
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ArticleEditor({
|
||||
content,
|
||||
articleIndex,
|
||||
appointablePositions,
|
||||
onChange,
|
||||
}: {
|
||||
content: ArticleContent;
|
||||
articleIndex: number;
|
||||
appointablePositions: PositionOption[];
|
||||
onChange: (patch: Partial<ArticleContent>) => void;
|
||||
}) {
|
||||
const clauses = content.clauses ?? [makeEmptyTextClause()];
|
||||
|
||||
function updateClause(id: string, patch: Partial<Clause>) {
|
||||
onChange({ clauses: clauses.map((c) => (c.id === id ? { ...c, ...patch } as Clause : c)) });
|
||||
}
|
||||
|
||||
function addClause(afterIndex: number, clause: Clause) {
|
||||
const updated = [...clauses];
|
||||
updated.splice(afterIndex + 1, 0, clause);
|
||||
onChange({ clauses: updated });
|
||||
}
|
||||
|
||||
function removeClause(id: string) {
|
||||
const updated = clauses.filter((c) => c.id !== id);
|
||||
onChange({ clauses: updated.length ? updated : [makeEmptyTextClause()] });
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<h4 className={cn("shrink-0", documentHeading.className)}>Article {articleIndex + 1}</h4>
|
||||
<input
|
||||
className={cn("flex-1 min-w-0 bg-transparent outline-none placeholder:text-muted-foreground", documentHeading.className)}
|
||||
placeholder="Article title (optional)"
|
||||
value={content.title ?? ""}
|
||||
onChange={(e) => onChange({ title: e.target.value })}
|
||||
/>
|
||||
<Select value={content.markerStyle} onValueChange={(v) => onChange({ markerStyle: v as ClauseMarkerStyle })}>
|
||||
<SelectTrigger className="w-36 h-7"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="NONE">No markers</SelectItem>
|
||||
<SelectItem value="LETTERS"><CaseLowerIcon /> Letters</SelectItem>
|
||||
<SelectItem value="NUMBERS"><ListOrderedIcon /> Numbers</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{content.markerStyle !== "NONE" && (
|
||||
<AutoResizeTextarea
|
||||
className={cn("flex-1 min-w-0 bg-transparent outline-none placeholder:text-muted-foreground", documentText.className)}
|
||||
placeholder="Introductory text..."
|
||||
value={content.intro ?? ""}
|
||||
onChange={(e) => onChange({ intro: e.target.value })}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
{clauses.map((clause, i) => {
|
||||
const marker = computeMarker(content.markerStyle, i);
|
||||
return (
|
||||
<div key={clause.id} className="flex gap-2 items-start group">
|
||||
{marker && <span className="text-muted-foreground shrink-0 pt-1">{marker}</span>}
|
||||
{clause.kind === "APPOINTMENT" ? (
|
||||
<AppointmentClauseEditor
|
||||
clause={clause}
|
||||
positions={appointablePositions}
|
||||
onChange={(patch) => updateClause(clause.id, patch)}
|
||||
/>
|
||||
) : (
|
||||
<AutoResizeTextarea
|
||||
className={cn(
|
||||
"flex-1 min-w-0 bg-transparent resize-none outline-none placeholder:text-muted-foreground",
|
||||
documentText.className,
|
||||
marker && "italic"
|
||||
)}
|
||||
placeholder="Text..."
|
||||
value={clause.text}
|
||||
onChange={(e) => updateClause(clause.id, { text: e.target.value })}
|
||||
/>
|
||||
)}
|
||||
<div className="flex gap-0.5 opacity-0 group-hover:opacity-100 shrink-0">
|
||||
<Button variant="ghost" size="icon-sm" title="Add text clause" onClick={() => addClause(i, makeEmptyTextClause())}><PlusIcon /></Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
title="Add appointment clause"
|
||||
disabled={appointablePositions.length === 0}
|
||||
onClick={() => addClause(i, makeEmptyAppointmentClause())}
|
||||
>
|
||||
<UserCogIcon />
|
||||
</Button>
|
||||
{clauses.length > 1 && (
|
||||
<Button variant="ghost" size="icon-sm" onClick={() => removeClause(clause.id)}><XIcon /></Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Renders an appointment clause inline as a fill-in-the-blank sentence:
|
||||
// "[Appoint|Dismiss] [citizen] [to|from] [position]."
|
||||
function AppointmentClauseEditor({
|
||||
clause,
|
||||
positions,
|
||||
onChange,
|
||||
}: {
|
||||
clause: Extract<Clause, { kind: "APPOINTMENT" }>;
|
||||
positions: PositionOption[];
|
||||
onChange: (patch: Partial<Clause>) => void;
|
||||
}) {
|
||||
return (
|
||||
<div className={cn("flex-1 min-w-0 flex flex-wrap items-center gap-1.5", documentText.className)}>
|
||||
<Select value={clause.action} onValueChange={(v) => onChange({ action: v as "ASSIGN" | "DISMISS" })}>
|
||||
<SelectTrigger className="h-7 w-28"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ASSIGN">Appoint</SelectItem>
|
||||
<SelectItem value="DISMISS">Dismiss</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<CitizenshipPicker
|
||||
value={clause.citizenshipId ? { id: clause.citizenshipId, name: clause.citizenshipName } : null}
|
||||
onSelect={(c) => onChange({ citizenshipId: c?.id ?? "", citizenshipName: c?.name ?? "" })}
|
||||
/>
|
||||
<span className="text-muted-foreground">{clause.action === "ASSIGN" ? "to" : "from"}</span>
|
||||
<Select value={clause.positionId} onValueChange={(v) => onChange({ positionId: v })}>
|
||||
<SelectTrigger className="h-7 min-w-40"><SelectValue placeholder="a position" /></SelectTrigger>
|
||||
<SelectContent>
|
||||
{positions.map((p) => (
|
||||
<SelectItem key={p.id} value={p.id}>{p.name}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<span>.</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function CitizenshipPicker({
|
||||
value,
|
||||
onSelect,
|
||||
}: {
|
||||
value: { id: string; name: string } | null;
|
||||
onSelect: (value: { id: string; name: string } | null) => void;
|
||||
}) {
|
||||
const [query, setQuery] = useState("");
|
||||
const [results, setResults] = useState<{ id: string; firstName: string; secondName: string }[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!query.trim()) { setResults([]); return; }
|
||||
const timeout = setTimeout(async () => {
|
||||
const result = await searchCitizensAction(query);
|
||||
if (result.success) setResults(result.data);
|
||||
}, 250);
|
||||
return () => clearTimeout(timeout);
|
||||
}, [query]);
|
||||
|
||||
if (value) {
|
||||
return (
|
||||
<span className="inline-flex items-center gap-1 border-b border-dotted">
|
||||
{value.name}
|
||||
<Button variant="ghost" size="icon-sm" className="h-5 w-5" onClick={() => onSelect(null)}><XIcon size={12} /></Button>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<span className="relative inline-block">
|
||||
<input
|
||||
className="bg-transparent outline-none border-b border-dotted placeholder:text-muted-foreground w-40"
|
||||
placeholder="a citizen"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
/>
|
||||
{results.length > 0 && (
|
||||
<div className="absolute z-10 mt-1 w-48 bg-popover border rounded-md shadow-md">
|
||||
{results.map((c) => (
|
||||
<button
|
||||
key={c.id}
|
||||
type="button"
|
||||
className="w-full text-left px-3 py-1.5 hover:bg-accent text-sm not-italic"
|
||||
onClick={() => { onSelect({ id: c.id, name: `${c.firstName} ${c.secondName}` }); setQuery(""); setResults([]); }}
|
||||
>
|
||||
{c.firstName} {c.secondName}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
function AutoResizeTextarea({ value, onChange, className, placeholder }: { value: string; onChange: (e: React.ChangeEvent<HTMLTextAreaElement>) => void; className?: string; placeholder?: string }) {
|
||||
const ref = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (ref.current) {
|
||||
ref.current.style.height = "auto";
|
||||
ref.current.style.height = `${ref.current.scrollHeight}px`;
|
||||
}
|
||||
}, [value]);
|
||||
|
||||
return <textarea ref={ref} rows={1} className={cn("overflow-hidden", className)} placeholder={placeholder} value={value} onChange={onChange} />;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import CreateActClient from "./client";
|
||||
import { Metadata } from "next";
|
||||
import { getActTypes, getInstitutions, getRegions } from "@/lib/acts/repository";
|
||||
import { getPositions, getUserPositions } from "@/lib/positions/repository";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Create act",
|
||||
robots: { index: false, follow: false },
|
||||
};
|
||||
|
||||
export default async function CreateAct() {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) redirect("/");
|
||||
|
||||
const [actTypes, institutions, regions, positions, userPositions] = await Promise.all([
|
||||
getActTypes(),
|
||||
getInstitutions(),
|
||||
getRegions(),
|
||||
getPositions(),
|
||||
getUserPositions(user.id),
|
||||
]);
|
||||
|
||||
if (userPositions.length === 0) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
return <CreateActClient actTypes={actTypes} institutions={institutions.filter((institution) => userPositions.some((position) => position.position.institutionId === institution.id))} regions={regions} positions={positions} />;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import SearchBar from "../../components/searchBar";
|
||||
import { getAllActs } from "@/lib/acts/actions";
|
||||
import { CalendarIcon, LandmarkIcon } from "lucide-react";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
|
||||
export const metadata: Metadata = { title: "Acts" };
|
||||
|
||||
export default async function Acts({ searchParams }: { searchParams: Promise<{ q?: string }> }) {
|
||||
const { q } = await searchParams;
|
||||
const user = await getCurrentUser();
|
||||
const acts = await getAllActs();
|
||||
|
||||
const query = q?.trim().toLowerCase() ?? "";
|
||||
|
||||
const filteredActs = query
|
||||
? acts.filter((a) =>
|
||||
`${a.actType.name.toLowerCase()} ${a.title.toLowerCase()} ${a.issuingInstitution.name.toLowerCase()}`.includes(query)
|
||||
)
|
||||
: acts;
|
||||
|
||||
return (
|
||||
<div className="flex flex-col p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between">
|
||||
<h1>Acts</h1>
|
||||
<SearchBar />
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
{user?.isAdmin && (
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
<Link href="/acts/create/"><Button variant="secondary">Create a new act</Button></Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-6">
|
||||
{
|
||||
filteredActs.length > 0 ? filteredActs.map((a) => (
|
||||
<div className="flex flex-col gap-2 md:gap-1" key={a.id}>
|
||||
<Link href={`/acts/${a.id}`} className="max-w-vh">
|
||||
<h3 className="hover:underline underline-offset-8 decoration-2 cursor-pointer truncate">{a.actType.name} {a.numberInSeries && `${a.numberInSeries}/${a.numberYear}`} “{a.title}”</h3>
|
||||
</Link>
|
||||
<div className="flex flex-col md:flex-row gap-0.5 md:gap-8 md:items-center">
|
||||
<p className="flex gap-2 items-center"><LandmarkIcon size={16} /><span className="truncate">{a.issuingInstitution.name}</span></p>
|
||||
<p className="flex gap-2 items-center"><CalendarIcon size={16} />{formatDate(a.createdAt)}</p>
|
||||
</div>
|
||||
</div>
|
||||
)) : <h2 className="text-muted-foreground">There are no acts yet...</h2>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+18
-7
@@ -5,13 +5,23 @@ import { getPages } from "@/lib/pages/repository";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import SearchBar from "../../components/searchBar";
|
||||
|
||||
export const metadata: Metadata = { title: "News" };
|
||||
|
||||
export default async function News() {
|
||||
export default async function News({ searchParams }: { searchParams: Promise<{ q?: string }> }) {
|
||||
const { q } = await searchParams;
|
||||
const user = await getCurrentUser();
|
||||
const news = await getPages("NEWS", "PUBLISHED");
|
||||
|
||||
const query = q?.trim().toLowerCase() ?? "";
|
||||
|
||||
const filteredNews = query
|
||||
? news.filter((n) =>
|
||||
`${n.title.toLowerCase()} ${n.meta.tags?.join(" ").toLowerCase() ?? ""}`.includes(query)
|
||||
)
|
||||
: news;
|
||||
|
||||
const newsDrafts = await getPages("NEWS", "DRAFT");
|
||||
const pageDrafts = await getPages("PAGE", "DRAFT");
|
||||
|
||||
@@ -21,6 +31,7 @@ export default async function News() {
|
||||
<div className="flex flex-col p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
||||
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between">
|
||||
<h1>News</h1>
|
||||
<SearchBar />
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
{user?.isAdmin && (
|
||||
<div className="flex flex-row items-center gap-4">
|
||||
@@ -31,12 +42,12 @@ export default async function News() {
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-col gap-6">
|
||||
{
|
||||
news.length > 0 ? news.map((n) => (
|
||||
<NewsCard news={n} key={n.id} />
|
||||
)) : <h2 className="text-muted-foreground">There are no news yet...</h2>
|
||||
}
|
||||
{
|
||||
filteredNews.length > 0 ? filteredNews.map((n) => (
|
||||
<NewsCard news={n} key={n.id} />
|
||||
)) : <h2 className="text-muted-foreground">There are no news yet...</h2>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NewsCard } from "@/components/news-card";
|
||||
import { getPages } from "@/lib/pages/repository";
|
||||
import { ArrowRightIcon } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
|
||||
export default async function Home() {
|
||||
|
||||
@@ -6,7 +6,7 @@ export default function Footer() {
|
||||
<footer className="flex flex-col w-full px-4 lg:px-16 py-8 gap-8 bg-muted">
|
||||
<div className="flex flex-col lg:flex-row lg:items-center gap-4">
|
||||
<Image
|
||||
src="/emblem.png"
|
||||
src="/emblems/europe.png"
|
||||
width={28}
|
||||
height={28}
|
||||
alt="Emblem of the European Federation"
|
||||
|
||||
@@ -19,7 +19,7 @@ export default async function Header() {
|
||||
return (
|
||||
<header className="relative flex items-center justify-between w-full h-16 px-4 sm:px-8 bg-white sm:bg-gray-100">
|
||||
<Link href="/" className="flex items-center gap-4 shrink-0">
|
||||
<Image src="/emblem.png" width={28} height={28} alt="Emblem of the European Federation" />
|
||||
<Image src="/emblems/europe.png" width={28} height={28} alt="Emblem of the European Federation" />
|
||||
<h3 className="hidden sm:block">European Federation</h3>
|
||||
</Link>
|
||||
<div className="hidden md:flex absolute left-1/2 -translate-x-1/2 items-center gap-6">
|
||||
|
||||
@@ -75,7 +75,7 @@ export default function IdentityCard({ data }: { data: IdentityCardData }) {
|
||||
<div className="relative z-10">
|
||||
<div className="flex flex-row items-center justify-between">
|
||||
<div className="flex flex-row gap-3 items-center">
|
||||
<Image src="/emblem.png" width={24} height={24} alt="Emblem" />
|
||||
<Image src="/emblems/europe.png" width={24} height={24} alt="Emblem" />
|
||||
<h2>ID Card</h2>
|
||||
</div>
|
||||
<h3>{data.documentNumber}</h3>
|
||||
|
||||
@@ -21,7 +21,7 @@ export function MobileNav({ links, isAuthenticated }: { links: NavLink[]; isAuth
|
||||
<div className="fixed inset-0 z-50 bg-white flex flex-col">
|
||||
<div className="flex items-center justify-between h-16 px-4">
|
||||
<Link href="/" onClick={() => setOpen(false)} className="flex items-center gap-4 shrink-0">
|
||||
<Image src="/emblem.png" width={28} height={28} alt="Emblem of the European Federation" />
|
||||
<Image src="/emblems/europe.png" width={28} height={28} alt="Emblem of the European Federation" />
|
||||
<h3 className="hidden sm:block">European Federation</h3>
|
||||
</Link>
|
||||
<Button variant="ghost" size="icon" onClick={() => setOpen(false)} aria-label="Close menu">
|
||||
|
||||
@@ -7,8 +7,8 @@ import { formatDate } from "@/lib/utils";
|
||||
export function NewsCard({ news }: { news: PagePublic }) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1">
|
||||
<Link href={`/news/${news.slug}`} className="w-max">
|
||||
<h2 className="hover:underline underline-offset-8 decoration-2 cursor-pointer">{news.title}</h2>
|
||||
<Link href={`/news/${news.slug}`} className="max-w-vh">
|
||||
<h2 className="hover:underline underline-offset-8 decoration-2 cursor-pointer truncate">{news.title}</h2>
|
||||
</Link>
|
||||
<div className="flex flex-col md:flex-row gap-2 md:gap-8 md:items-center">
|
||||
<div className="flex flex-row gap-4 md:gap-8">
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"use client"
|
||||
|
||||
import { SearchIcon } from "lucide-react";
|
||||
import { InputGroup, InputGroupAddon, InputGroupInput } from "@/components/ui/input-group";
|
||||
import { Field } from "@/components/ui/field";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
import { useState, useTransition } from "react";
|
||||
|
||||
export default function SearchBar() {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
const [value, setValue] = useState(searchParams.get("q") ?? "");
|
||||
const [, startTransition] = useTransition();
|
||||
|
||||
function handleChange(next: string) {
|
||||
setValue(next);
|
||||
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
if (next) {
|
||||
params.set("q", next);
|
||||
} else {
|
||||
params.delete("q");
|
||||
}
|
||||
|
||||
startTransition(() => {
|
||||
router.replace(`${pathname}?${params.toString()}`, { scroll: false });
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<Field className="max-w-sm">
|
||||
<InputGroup>
|
||||
<InputGroupInput
|
||||
placeholder="Search..."
|
||||
value={value}
|
||||
onChange={(e) => handleChange(e.target.value)}
|
||||
/>
|
||||
<InputGroupAddon align="inline-start">
|
||||
<SearchIcon className="text-muted-foreground" />
|
||||
</InputGroupAddon>
|
||||
</InputGroup>
|
||||
</Field>
|
||||
)
|
||||
}
|
||||
+1
-3
@@ -1,9 +1,7 @@
|
||||
services:
|
||||
eu:
|
||||
image: localhost:5000/eu:latest
|
||||
image: 172.17.0.1:5000/eu:latest
|
||||
restart: unless-stopped
|
||||
extra_hosts:
|
||||
- "assets.dusiburg.ru:172.18.0.4"
|
||||
environment:
|
||||
PUBLIC_URL: ${PUBLIC_URL}
|
||||
DATABASE_URL: ${DATABASE_URL}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
NGINX_PROXY_NAME="${NGINX_PROXY_CONTAINER_NAME:-nginx-proxy}"
|
||||
|
||||
TARGET_DOMAIN=$(echo "$MINIO_PUBLIC_URL" | sed -E 's#^https?://##; s#/.*##; s#:.*##')
|
||||
|
||||
if [ -n "$TARGET_DOMAIN" ]; then
|
||||
IP=$(getent hosts "$NGINX_PROXY_NAME" | awk '{ print $1 }' | head -n1)
|
||||
|
||||
if [ -n "$IP" ]; then
|
||||
echo "$IP $TARGET_DOMAIN" >> /etc/hosts
|
||||
echo "[entrypoint] resolved $NGINX_PROXY_NAME -> $IP for $TARGET_DOMAIN"
|
||||
else
|
||||
echo "[entrypoint] WARNING: could not resolve $NGINX_PROXY_NAME, using public DNS as fallback"
|
||||
fi
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -0,0 +1,136 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
import { validateAct } from "./validation";
|
||||
import { requireAdmin, requireUser } from "../user/require";
|
||||
import { runAction } from "../run-action";
|
||||
import { AppError, type ActionResult } from "../action-result";
|
||||
import {
|
||||
createAct, getActApprovals, getActById, getActs, getActTypeById, getCurrentActVersion,
|
||||
getInstitutionById, putActIntoForce, recordApproval, recordVeto,
|
||||
} from "./repository";
|
||||
import { getPositionById, getCitizenshipPositions } from "../positions/repository";
|
||||
import { getActiveCitizenship } from "../citizenship/repository";
|
||||
import { ActEditorData, AppointmentClause } from "./types";
|
||||
import { ActCapability, getActFlow, getNextPhase } from "./flows";
|
||||
|
||||
export async function saveActAction(params: ActEditorData): Promise<ActionResult> {
|
||||
return runAction(async () => {
|
||||
await requireAdmin();
|
||||
|
||||
const parsed = validateAct(params);
|
||||
if (!parsed.success) {
|
||||
throw new AppError("Please ensure that at least 1 article here is in the act");
|
||||
}
|
||||
|
||||
const actType = await getActTypeById(parsed.data.actTypeId);
|
||||
if (!actType) throw new AppError("Selected act type does not exist");
|
||||
|
||||
const institution = await getInstitutionById(parsed.data.issuingInstitutionId);
|
||||
if (!institution) throw new AppError("Selected institution does not exist");
|
||||
|
||||
if (actType.allowedIssuerKind !== institution.kind) {
|
||||
throw new AppError("This act type is not allowed for the selected institution");
|
||||
}
|
||||
if (actType.allowedIssuerInstitutionCode && institution.code !== actType.allowedIssuerInstitutionCode) {
|
||||
throw new AppError(`This act type can only be issued by ${actType.allowedIssuerInstitutionCode}`);
|
||||
}
|
||||
|
||||
const appointmentClauses = parsed.data.articles
|
||||
.flatMap((a) => a.clauses)
|
||||
.filter((c): c is AppointmentClause => c.kind === "APPOINTMENT");
|
||||
|
||||
for (const clause of appointmentClauses) {
|
||||
const position = await getPositionById(clause.positionId);
|
||||
if (!position) throw new AppError("One of the selected positions does not exist");
|
||||
|
||||
const requiredIssuerId = position.institution.appointedByInstitutionId ?? position.institutionId;
|
||||
if (requiredIssuerId !== institution.id) {
|
||||
throw new AppError(`${institution.name} does not have the authority to appoint or dismiss ${position.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
const act = await createAct(parsed.data);
|
||||
revalidatePath("/acts");
|
||||
redirect(`/acts/${act.id}`);
|
||||
});
|
||||
}
|
||||
|
||||
async function userHoldsCapability(userId: string, capability: ActCapability) {
|
||||
const citizenship = await getActiveCitizenship(userId);
|
||||
if (!citizenship) return { citizenship: null, position: null };
|
||||
|
||||
const positions = await getCitizenshipPositions(citizenship.id);
|
||||
const position = positions.find(
|
||||
(p) => !p.resignedAt && p.position.capabilities.some((c) => c.capability === capability)
|
||||
);
|
||||
return { citizenship, position };
|
||||
}
|
||||
|
||||
async function loadDecidablePhase(actId: string) {
|
||||
const act = await getActById(actId);
|
||||
if (!act) throw new AppError("Act not found");
|
||||
if (act.legalStatus !== "DRAFT") throw new AppError("This act has already been decided on");
|
||||
|
||||
const actType = await getActTypeById(act.actTypeId);
|
||||
if (!actType) throw new AppError("Act type not found");
|
||||
|
||||
const version = await getCurrentActVersion(actId);
|
||||
if (!version) throw new AppError("Act version not found");
|
||||
|
||||
const approvals = await getActApprovals(version.id);
|
||||
const flow = getActFlow(actType.code);
|
||||
const phase = getNextPhase(flow, approvals);
|
||||
if (!phase) throw new AppError("This act has completed its approval process");
|
||||
|
||||
return { act, version, phase };
|
||||
}
|
||||
|
||||
export async function approveActAction(actId: string): Promise<ActionResult> {
|
||||
return runAction(async () => {
|
||||
const user = await requireUser();
|
||||
const { version, phase } = await loadDecidablePhase(actId);
|
||||
|
||||
const { citizenship, position } = await userHoldsCapability(user.id, phase.capability);
|
||||
if (!citizenship) throw new AppError("Only citizens can decide on acts");
|
||||
if (!position) throw new AppError("You do not hold a position with the authority to approve this act at its current phase");
|
||||
|
||||
await recordApproval(
|
||||
actId, version.id, phase.key, citizenship.id,
|
||||
`${user.firstName} ${user.secondName}`, position.position.name, phase.isFinal
|
||||
);
|
||||
revalidatePath(`/acts/${actId}`);
|
||||
});
|
||||
}
|
||||
|
||||
export async function vetoActAction(actId: string): Promise<ActionResult> {
|
||||
return runAction(async () => {
|
||||
const user = await requireUser();
|
||||
const { version, phase } = await loadDecidablePhase(actId);
|
||||
if (!phase.allowVeto) throw new AppError("This phase cannot veto the act");
|
||||
|
||||
const { citizenship, position } = await userHoldsCapability(user.id, phase.capability);
|
||||
if (!citizenship) throw new AppError("Only citizens can decide on acts");
|
||||
if (!position) throw new AppError("You do not hold a position with the authority to veto this act");
|
||||
|
||||
await recordVeto(actId, version.id, phase.key, citizenship.id, `${user.firstName} ${user.secondName}`, position.position.name);
|
||||
revalidatePath(`/acts/${actId}`);
|
||||
});
|
||||
}
|
||||
|
||||
export async function putActIntoForceAction(actId: string): Promise<ActionResult> {
|
||||
return runAction(async () => {
|
||||
await requireAdmin();
|
||||
|
||||
const act = await getActById(actId);
|
||||
if (!act) throw new AppError("Act not found");
|
||||
|
||||
await putActIntoForce(actId);
|
||||
revalidatePath(`/acts/${actId}`);
|
||||
});
|
||||
}
|
||||
|
||||
export async function getAllActs() {
|
||||
return await getActs();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
export type ActCapability =
|
||||
| "SIGN_FEDERAL_LAW_SENATE"
|
||||
| "SIGN_FEDERAL_LAW_HOUSE"
|
||||
| "SIGN_AS_HEAD_OF_STATE"
|
||||
| "SIGN_SENATE_APPOINTMENT"
|
||||
| "SIGN_TREATY"
|
||||
| "SIGN_RATIFICATION"
|
||||
| "SIGN_REGIONAL_ACT";
|
||||
|
||||
export type FlowPhase = {
|
||||
key: string;
|
||||
label: string;
|
||||
capability: ActCapability;
|
||||
isFinal: boolean;
|
||||
allowVeto?: boolean;
|
||||
vetoLabel?: string;
|
||||
};
|
||||
|
||||
export type ActFlow = FlowPhase[];
|
||||
|
||||
const singleSignature = (capability: ActCapability, label: string): ActFlow => [
|
||||
{ key: "ADOPTION", label, capability, isFinal: true, allowVeto: true, vetoLabel: "Reject" },
|
||||
];
|
||||
|
||||
const FEDERAL_LAW_FLOW: ActFlow = [
|
||||
{ key: "SENATE_ADOPTION", label: "Awaiting the Senate", capability: "SIGN_FEDERAL_LAW_SENATE", isFinal: false, allowVeto: true, vetoLabel: "Reject" },
|
||||
{ key: "HOUSE_ADOPTION", label: "Awaiting the House of Representatives", capability: "SIGN_FEDERAL_LAW_HOUSE", isFinal: false, allowVeto: true, vetoLabel: "Reject" },
|
||||
{ key: "PRESIDENT_DECISION", label: "Under review by the President", capability: "SIGN_AS_HEAD_OF_STATE", isFinal: true, allowVeto: true, vetoLabel: "Veto" },
|
||||
];
|
||||
|
||||
const FLOWS_BY_ACT_TYPE_CODE: Record<string, ActFlow> = {
|
||||
FEDERAL_LAW: FEDERAL_LAW_FLOW,
|
||||
SENATE_APPOINTMENT: singleSignature("SIGN_SENATE_APPOINTMENT", "Awaiting the Senate"),
|
||||
TREATY: singleSignature("SIGN_TREATY", "Awaiting the President's signature"),
|
||||
RATIFICATION_ACT: singleSignature("SIGN_RATIFICATION", "Awaiting the Senate"),
|
||||
REGIONAL_ACT: singleSignature("SIGN_REGIONAL_ACT", "Awaiting the regional government"),
|
||||
};
|
||||
|
||||
export function getActFlow(actTypeCode: string): ActFlow {
|
||||
const flow = FLOWS_BY_ACT_TYPE_CODE[actTypeCode];
|
||||
if (!flow) throw new Error(`No flow configured for act type "${actTypeCode}"`);
|
||||
return flow;
|
||||
}
|
||||
|
||||
export function getNextPhase(flow: ActFlow, approvals: { phaseKey: string }[]): FlowPhase | undefined {
|
||||
const done = new Set(approvals.map((a) => a.phaseKey));
|
||||
return flow.find((p) => !done.has(p.key));
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
import { prisma } from "../prisma";
|
||||
import { getCurrentUser } from "../user";
|
||||
import { ActFormData } from "./validation";
|
||||
import { ActBlockRecord, ArticleContent, AppointmentClause } from "./types";
|
||||
import { Prisma } from "@/lib/generated/prisma/client";
|
||||
|
||||
const actTypeSelect = {
|
||||
id: true, name: true, code: true, allowedIssuerKind: true, allowedIssuerInstitutionCode: true,
|
||||
} as const;
|
||||
const institutionSelect = { id: true, name: true, kind: true, code: true, appointedByInstitutionId: true } as const;
|
||||
const regionSelect = { id: true, name: true } as const;
|
||||
|
||||
export async function getActTypes() {
|
||||
return prisma.actType.findMany({ select: actTypeSelect });
|
||||
}
|
||||
|
||||
export async function getInstitutions() {
|
||||
return prisma.institution.findMany({ where: { isActive: true }, select: institutionSelect });
|
||||
}
|
||||
|
||||
export async function getRegions() {
|
||||
return prisma.region.findMany({ select: regionSelect });
|
||||
}
|
||||
|
||||
export async function getActTypeById(id: string) {
|
||||
return prisma.actType.findUnique({ where: { id }, select: actTypeSelect });
|
||||
}
|
||||
|
||||
export async function getInstitutionById(id: string) {
|
||||
return prisma.institution.findUnique({ where: { id }, select: institutionSelect });
|
||||
}
|
||||
|
||||
export async function createAct(data: ActFormData) {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) throw new Error("Failed to fetch user");
|
||||
|
||||
return prisma.$transaction(async (tx) => {
|
||||
const act = await tx.act.create({
|
||||
data: {
|
||||
actTypeId: data.actTypeId,
|
||||
issuingInstitutionId: data.issuingInstitutionId,
|
||||
regionId: data.regionId || null,
|
||||
authorId: user.id,
|
||||
title: data.title,
|
||||
legalStatus: "DRAFT",
|
||||
},
|
||||
});
|
||||
|
||||
const version = await tx.actVersion.create({
|
||||
data: { actId: act.id, isCurrent: true, createdBy: user.id },
|
||||
});
|
||||
|
||||
let position = 0;
|
||||
const blocks: { versionId: string; stableKey: string; type: string; position: number; content: object }[] = [];
|
||||
|
||||
if (data.preambleText?.trim()) {
|
||||
blocks.push({
|
||||
versionId: version.id,
|
||||
stableKey: "preamble",
|
||||
type: "PREAMBLE",
|
||||
position: position++,
|
||||
content: { text: data.preambleText },
|
||||
});
|
||||
}
|
||||
|
||||
for (const article of data.articles) {
|
||||
blocks.push({
|
||||
versionId: version.id,
|
||||
stableKey: article.id,
|
||||
type: "ARTICLE",
|
||||
position: position++,
|
||||
content: {
|
||||
title: article.title ?? null,
|
||||
intro: article.intro ?? null,
|
||||
markerStyle: article.markerStyle,
|
||||
clauses: article.clauses,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
await tx.actBlock.createMany({ data: blocks });
|
||||
|
||||
return act;
|
||||
});
|
||||
}
|
||||
|
||||
export async function getActs() {
|
||||
return prisma.act.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
numberInSeries: true,
|
||||
numberYear: true,
|
||||
createdAt: true,
|
||||
legalStatus: true,
|
||||
actType: { select: actTypeSelect },
|
||||
issuingInstitution: { select: institutionSelect },
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
});
|
||||
}
|
||||
|
||||
export async function getActById(id: string) {
|
||||
return prisma.act.findUnique({ where: { id } });
|
||||
}
|
||||
|
||||
export async function getActVersions(actId: string) {
|
||||
return prisma.actVersion.findMany({ where: { actId }, orderBy: { createdAt: "desc" } });
|
||||
}
|
||||
|
||||
export async function getCurrentActVersion(actId: string) {
|
||||
return prisma.actVersion.findFirst({ where: { actId, isCurrent: true } });
|
||||
}
|
||||
|
||||
export async function getActApprovals(actVersionId: string) {
|
||||
return prisma.actApproval.findMany({
|
||||
where: { actVersionId },
|
||||
select: { id: true, phaseKey: true, decision: true, citizenshipId: true, name: true, role: true, decidedAt: true },
|
||||
orderBy: { decidedAt: "asc" },
|
||||
});
|
||||
}
|
||||
|
||||
export async function recordApproval(
|
||||
actId: string, actVersionId: string, phaseKey: string,
|
||||
citizenshipId: string, name: string, role: string, isFinal: boolean
|
||||
) {
|
||||
return prisma.$transaction(async (tx) => {
|
||||
await tx.actApproval.create({ data: { actVersionId, phaseKey, decision: "APPROVE", citizenshipId, name, role } });
|
||||
const act = await tx.act.findUniqueOrThrow({ where: { id: actId } });
|
||||
if (!isFinal) return act;
|
||||
|
||||
const acts = await prisma.act.findMany({ where: { issuingInstitutionId: act.issuingInstitutionId, legalStatus: "IN_FORCE", numberYear: new Date().getFullYear() }, orderBy: { updatedAt: "desc" } });
|
||||
await applyAppointmentEffects(tx, actId, actVersionId);
|
||||
return tx.act.update({ where: { id: actId }, data: { legalStatus: "IN_FORCE", numberInSeries: acts[0]?.numberInSeries || 0 + 1, numberYear: new Date().getFullYear() } });
|
||||
});
|
||||
}
|
||||
|
||||
export async function recordVeto(
|
||||
actId: string, actVersionId: string, phaseKey: string,
|
||||
citizenshipId: string, name: string, role: string
|
||||
) {
|
||||
return prisma.$transaction(async (tx) => {
|
||||
await tx.actApproval.create({ data: { actVersionId, phaseKey, decision: "VETO", citizenshipId, name, role } });
|
||||
return tx.act.update({ where: { id: actId }, data: { legalStatus: "NOT_ADOPTED" } });
|
||||
});
|
||||
}
|
||||
|
||||
export async function getActBlocks(versionId: string): Promise<ActBlockRecord[]> {
|
||||
return prisma.actBlock.findMany({
|
||||
where: { versionId },
|
||||
orderBy: { position: "asc" },
|
||||
}) as Promise<ActBlockRecord[]>;
|
||||
}
|
||||
|
||||
async function applyAppointmentEffects(tx: Prisma.TransactionClient, actId: string, versionId: string) {
|
||||
const articleBlocks = await tx.actBlock.findMany({ where: { versionId, type: "ARTICLE" } });
|
||||
|
||||
const appointmentClauses = articleBlocks.flatMap((block) => {
|
||||
const content = block.content as unknown as ArticleContent;
|
||||
return content.clauses.filter((c): c is AppointmentClause => c.kind === "APPOINTMENT");
|
||||
});
|
||||
|
||||
for (const clause of appointmentClauses) {
|
||||
if (clause.action === "ASSIGN") {
|
||||
await tx.citizenshipPosition.updateMany({
|
||||
where: { positionId: clause.positionId, resignedAt: null },
|
||||
data: { resignedAt: new Date() },
|
||||
});
|
||||
await tx.citizenshipPosition.create({
|
||||
data: { citizenshipId: clause.citizenshipId, positionId: clause.positionId, actId },
|
||||
});
|
||||
} else {
|
||||
await tx.citizenshipPosition.updateMany({
|
||||
where: { positionId: clause.positionId, citizenshipId: clause.citizenshipId, resignedAt: null },
|
||||
data: { resignedAt: new Date() },
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function putActIntoForce(actId: string) {
|
||||
return prisma.$transaction(async (tx) => {
|
||||
const version = await tx.actVersion.findFirstOrThrow({ where: { actId, isCurrent: true } });
|
||||
await applyAppointmentEffects(tx, actId, version.id);
|
||||
return tx.act.update({ where: { id: actId }, data: { legalStatus: "IN_FORCE" } });
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
export const CLAUSE_MARKER_STYLES = ["NONE", "LETTERS", "NUMBERS"] as const;
|
||||
export type ClauseMarkerStyle = typeof CLAUSE_MARKER_STYLES[number];
|
||||
|
||||
export type ActLegalStatus = "DRAFT" | "IN_FORCE" | "AMENDED" | "REPEALED" | "EXPIRED" | "NOT_ADOPTED";
|
||||
|
||||
export const LEGAL_STATUS_LABELS: Record<ActLegalStatus, string> = {
|
||||
DRAFT: "Not yet in force",
|
||||
IN_FORCE: "In force",
|
||||
AMENDED: "Amended",
|
||||
REPEALED: "Repealed",
|
||||
EXPIRED: "Expired",
|
||||
NOT_ADOPTED: "Not adopted",
|
||||
};
|
||||
|
||||
export type TextClause = { id: string; kind: "TEXT"; text: string };
|
||||
|
||||
export type AppointmentClause = {
|
||||
id: string;
|
||||
kind: "APPOINTMENT";
|
||||
action: "ASSIGN" | "DISMISS";
|
||||
positionId: string;
|
||||
citizenshipId: string;
|
||||
citizenshipName: string;
|
||||
};
|
||||
|
||||
export type Clause = TextClause | AppointmentClause;
|
||||
|
||||
export type ArticleContent = {
|
||||
id: string;
|
||||
title: string;
|
||||
intro?: string;
|
||||
markerStyle: ClauseMarkerStyle;
|
||||
clauses: Clause[];
|
||||
};
|
||||
|
||||
export type PreambleContent = { text: string };
|
||||
|
||||
export type ActBlockContent = ArticleContent | PreambleContent;
|
||||
|
||||
export type ActBlockType = "PREAMBLE" | "ARTICLE";
|
||||
|
||||
export type ActBlockRecord = {
|
||||
id: string;
|
||||
versionId: string;
|
||||
stableKey: string;
|
||||
type: ActBlockType;
|
||||
position: number;
|
||||
content: ActBlockContent;
|
||||
};
|
||||
|
||||
export type ActEditorData = {
|
||||
actTypeId: string;
|
||||
issuingInstitutionId: string;
|
||||
regionId: string | null;
|
||||
title?: string;
|
||||
preambleText?: string;
|
||||
articles: ArticleContent[];
|
||||
};
|
||||
|
||||
export type ActType = { id: string; name: string; code: string; allowedIssuerKind: string };
|
||||
export type Institution = { id: string; name: string; kind: string; appointedByInstitutionId: string | null };
|
||||
export type Region = { id: string; name: string };
|
||||
export type PositionOption = { id: string; name: string; institutionId: string };
|
||||
|
||||
export type ActSignature = {
|
||||
id: string;
|
||||
citizenshipId: string;
|
||||
name: string;
|
||||
role: string;
|
||||
signedAt: Date;
|
||||
};
|
||||
|
||||
export type ApprovalDecision = "APPROVE" | "VETO";
|
||||
|
||||
export type ActApprovalRecord = {
|
||||
id: string;
|
||||
phaseKey: string;
|
||||
decision: ApprovalDecision;
|
||||
citizenshipId: string;
|
||||
name: string;
|
||||
role: string;
|
||||
decidedAt: Date;
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
import { z } from "zod";
|
||||
import { CLAUSE_MARKER_STYLES } from "./types";
|
||||
|
||||
const textClauseSchema = z.object({
|
||||
id: z.string(),
|
||||
kind: z.literal("TEXT"),
|
||||
text: z.string().min(1),
|
||||
});
|
||||
|
||||
const appointmentClauseSchema = z.object({
|
||||
id: z.string(),
|
||||
kind: z.literal("APPOINTMENT"),
|
||||
action: z.enum(["ASSIGN", "DISMISS"]),
|
||||
positionId: z.string().min(1, "A position is required"),
|
||||
citizenshipId: z.string().min(1, "A citizen must be selected"),
|
||||
citizenshipName: z.string().min(1),
|
||||
});
|
||||
|
||||
const clauseSchema = z.discriminatedUnion("kind", [textClauseSchema, appointmentClauseSchema]);
|
||||
|
||||
const articleSchema = z.object({
|
||||
id: z.string(),
|
||||
title: z.string().optional(),
|
||||
intro: z.string().optional(),
|
||||
markerStyle: z.enum(CLAUSE_MARKER_STYLES),
|
||||
clauses: z.array(clauseSchema).min(1),
|
||||
});
|
||||
|
||||
export const actSchema = z.object({
|
||||
actTypeId: z.string().min(1, "Act type is required"),
|
||||
issuingInstitutionId: z.string().min(1, "Issuing institution is required"),
|
||||
regionId: z.string().nullable(),
|
||||
title: z.string().min(1, "Act must have a title"),
|
||||
preambleText: z.string().optional(),
|
||||
articles: z.array(articleSchema).min(1, "At least one article is required"),
|
||||
});
|
||||
|
||||
export type ActFormData = z.infer<typeof actSchema>;
|
||||
|
||||
export function validateAct(data: unknown): { success: true; data: ActFormData } | { success: false; errors: string[] } {
|
||||
const result = actSchema.safeParse(data);
|
||||
if (!result.success) {
|
||||
const fieldErrors = result.error.flatten().fieldErrors ?? {};
|
||||
const messages = Object.values(fieldErrors).flat().filter(Boolean);
|
||||
return { success: false, errors: messages };
|
||||
}
|
||||
return { success: true, data: result.data };
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import { runAction, isPrismaError } from "@/lib/run-action";
|
||||
import { AppError, type ActionResult } from "@/lib/action-result";
|
||||
import { formAction } from "@/lib/form-action";
|
||||
import { citizenshipApplicationSchema } from "./validation";
|
||||
import { createApplication, getActiveCitizenship, getApplicationEligibility } from "./repository";
|
||||
import { createApplication, getActiveCitizenship, getApplicationEligibility, searchActiveCitizenships } from "./repository";
|
||||
import { prisma } from "../prisma";
|
||||
import { formatAddress } from "@/lib/address";
|
||||
import { Prisma } from "@/lib/generated/prisma/client";
|
||||
@@ -179,6 +179,17 @@ export async function rejectApplication(id: string, reason: string): Promise<Act
|
||||
});
|
||||
}
|
||||
|
||||
export async function searchCitizensAction(query: string): Promise<ActionResult<{ id: string; firstName: string; secondName: string }[]>> {
|
||||
return runAction(async () => {
|
||||
// Gate behind admin for now, same as act creation - refine once
|
||||
// position-based authority exists.
|
||||
await requireAdmin();
|
||||
|
||||
const results = await searchActiveCitizenships(query);
|
||||
return results.map((c) => ({ id: c.id, firstName: c.user.firstName, secondName: c.user.secondName }));
|
||||
});
|
||||
}
|
||||
|
||||
export async function renounceCitizenship(): Promise<ActionResult> {
|
||||
return runAction(async () => {
|
||||
const user = await requireUser();
|
||||
|
||||
@@ -77,9 +77,8 @@ export async function getUserApplications(userId: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function getPendingApplications() {
|
||||
export async function getAllApplications() {
|
||||
return prisma.citizenshipApplication.findMany({
|
||||
where: { status: "PENDING" },
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: {
|
||||
user: {
|
||||
@@ -103,4 +102,28 @@ export async function getActiveCitizenship(userId: string) {
|
||||
return prisma.citizenship.findFirst({
|
||||
where: { userId, revokedAt: null },
|
||||
});
|
||||
}
|
||||
|
||||
// Used by the acts appointment picker - only active citizens are eligible
|
||||
// to hold a position.
|
||||
export async function searchActiveCitizenships(query: string) {
|
||||
const q = query.trim();
|
||||
if (!q) return [];
|
||||
|
||||
return prisma.citizenship.findMany({
|
||||
where: {
|
||||
revokedAt: null,
|
||||
user: {
|
||||
OR: [
|
||||
{ firstName: { contains: q, mode: "insensitive" } },
|
||||
{ secondName: { contains: q, mode: "insensitive" } },
|
||||
],
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
user: { select: { firstName: true, secondName: true } },
|
||||
},
|
||||
take: 10,
|
||||
});
|
||||
}
|
||||
@@ -43,4 +43,5 @@ export type CitizenshipApplicationWithWarning = CitizenshipApplication & {
|
||||
previousCitizenship: boolean;
|
||||
profileUrl: string;
|
||||
signatureUrl: string;
|
||||
};
|
||||
reviewer: { firstName: string; secondName: string } | null;
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { AppError } from "../action-result";
|
||||
import { prisma } from "../prisma";
|
||||
import { requireAdmin } from "../user/require";
|
||||
import { formAction } from "../form-action";
|
||||
import z from "zod";
|
||||
|
||||
const createPositionSchema = z.object({
|
||||
name: z.string().min(1, "Name of a position cannot be empty"),
|
||||
institutionId: z.string().min(1, "Incorrect institution is provided"),
|
||||
});
|
||||
|
||||
// Defines an office (e.g. "Mayor of X") within an institution. This does NOT
|
||||
// assign anyone to it - filling/vacating a position happens through an
|
||||
// appointment act, see lib/acts.
|
||||
export const createPosition = formAction(createPositionSchema, async (data) => {
|
||||
await requireAdmin();
|
||||
|
||||
const institution = await prisma.institution.findUnique({ where: { id: data.institutionId } });
|
||||
if (!institution) {
|
||||
throw new AppError("Incorrect institution is provided");
|
||||
}
|
||||
|
||||
await prisma.position.create({ data: { name: data.name, institutionId: data.institutionId } });
|
||||
revalidatePath("/account/positions");
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { prisma } from "../prisma";
|
||||
import { Position } from "./types";
|
||||
|
||||
const positionSelect = {
|
||||
id: true,
|
||||
name: true,
|
||||
institutionId: true,
|
||||
institution: { select: { id: true, name: true, kind: true } },
|
||||
capabilities: { select: { capability: true } },
|
||||
} as const;
|
||||
|
||||
export async function getPositions() {
|
||||
return prisma.position.findMany({ select: positionSelect, orderBy: { name: "asc" } });
|
||||
}
|
||||
|
||||
export async function getPositionById(id: string) {
|
||||
return prisma.position.findUnique({ where: { id }, select: positionSelect });
|
||||
}
|
||||
|
||||
export async function createPosition(position: Omit<Position, "id">) {
|
||||
return prisma.position.create({ data: position });
|
||||
}
|
||||
|
||||
// Current (non-resigned) holder of a position, if any.
|
||||
export async function getCurrentHolder(positionId: string) {
|
||||
return prisma.citizenshipPosition.findFirst({
|
||||
where: { positionId, resignedAt: null },
|
||||
include: { citizenship: { include: { user: { select: { firstName: true, secondName: true } } } } },
|
||||
});
|
||||
}
|
||||
|
||||
export async function getCitizenshipPositions(citizenshipId: string) {
|
||||
return prisma.citizenshipPosition.findMany({
|
||||
where: { citizenshipId },
|
||||
include: { position: { select: positionSelect } },
|
||||
orderBy: { assignedAt: "desc" },
|
||||
});
|
||||
}
|
||||
|
||||
export async function getUserPositions(userId: string) {
|
||||
return prisma.citizenshipPosition.findMany({
|
||||
where: { citizenship: { userId }, resignedAt: null },
|
||||
include: { position: { select: positionSelect }, act: { select: { title: true, numberInSeries: true, numberYear: true, actType: { select: { name: true } } } } },
|
||||
orderBy: { assignedAt: "desc" },
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
export type Position = {
|
||||
id: string;
|
||||
name: string;
|
||||
institutionId: string;
|
||||
}
|
||||
|
||||
export type CitizenshipPosition = {
|
||||
id: string;
|
||||
citizenshipId: string;
|
||||
positionId: string;
|
||||
assignedAt: Date;
|
||||
resignedAt: Date | null;
|
||||
actId: string | null;
|
||||
}
|
||||
+5
-2
@@ -5,6 +5,9 @@ import { PrismaClient } from "@/lib/generated/prisma/client";
|
||||
const connectionString = `${process.env.DATABASE_URL}`;
|
||||
|
||||
const adapter = new PrismaPg({ connectionString });
|
||||
const prisma = new PrismaClient({ adapter });
|
||||
|
||||
export { prisma };
|
||||
const globalForPrisma = globalThis as unknown as { prisma: PrismaClient };
|
||||
|
||||
export const prisma = globalForPrisma.prisma ?? new PrismaClient({ adapter });
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
|
||||
+255
-65
@@ -27,23 +27,25 @@ enum EyeColor {
|
||||
}
|
||||
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
kotosoftId String @unique
|
||||
email String @unique
|
||||
id String @id @default(uuid())
|
||||
kotosoftId String @unique
|
||||
email String @unique
|
||||
firstName String
|
||||
secondName String
|
||||
sex Sex
|
||||
birthDate DateTime?
|
||||
createdAt DateTime @default(now())
|
||||
isAdmin Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
isAdmin Boolean @default(false)
|
||||
|
||||
pages Page[] @relation("PageAuthor")
|
||||
editedPages Page[] @relation("PageEditor")
|
||||
pages Page[] @relation("PageAuthor")
|
||||
editedPages Page[] @relation("PageEditor")
|
||||
|
||||
citizenshipApplications CitizenshipApplication[]
|
||||
reviewedApplications CitizenshipApplication[] @relation("CitizenshipReviewer")
|
||||
reviewedApplications CitizenshipApplication[] @relation("CitizenshipReviewer")
|
||||
|
||||
citizenships Citizenship[]
|
||||
|
||||
acts Act[]
|
||||
}
|
||||
|
||||
enum PageStatus {
|
||||
@@ -68,20 +70,20 @@ model Page {
|
||||
updatedAt DateTime @updatedAt
|
||||
publishedAt DateTime?
|
||||
|
||||
createdBy String?
|
||||
author User? @relation("PageAuthor", fields: [createdBy], references: [id])
|
||||
createdBy String?
|
||||
author User? @relation("PageAuthor", fields: [createdBy], references: [id])
|
||||
|
||||
updatedBy String?
|
||||
editor User? @relation("PageEditor", fields: [updatedBy], references: [id])
|
||||
updatedBy String?
|
||||
editor User? @relation("PageEditor", fields: [updatedBy], references: [id])
|
||||
|
||||
blocks Block[]
|
||||
navLinks NavLink[]
|
||||
blocks Block[]
|
||||
navLinks NavLink[]
|
||||
}
|
||||
|
||||
model Block {
|
||||
id String @id @default(uuid())
|
||||
pageId String
|
||||
page Page @relation(fields: [pageId], references: [id], onDelete: Cascade)
|
||||
id String @id @default(uuid())
|
||||
pageId String
|
||||
page Page @relation(fields: [pageId], references: [id], onDelete: Cascade)
|
||||
|
||||
parentId String?
|
||||
parent Block? @relation("BlockChildren", fields: [parentId], references: [id])
|
||||
@@ -95,13 +97,13 @@ model Block {
|
||||
}
|
||||
|
||||
model NavLink {
|
||||
id String @id @default(uuid())
|
||||
label String?
|
||||
id String @id @default(uuid())
|
||||
label String?
|
||||
order Int
|
||||
|
||||
pageId String?
|
||||
page Page? @relation(fields: [pageId], references: [id], onDelete: SetNull)
|
||||
href String?
|
||||
pageId String?
|
||||
page Page? @relation(fields: [pageId], references: [id], onDelete: SetNull)
|
||||
href String?
|
||||
}
|
||||
|
||||
enum CitizenshipApplicationStatus {
|
||||
@@ -116,35 +118,35 @@ enum ApplicationType {
|
||||
}
|
||||
|
||||
model CitizenshipApplication {
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
surname String
|
||||
givenNames String
|
||||
sex Sex
|
||||
birthDate DateTime
|
||||
applicationType ApplicationType
|
||||
previousCountry String?
|
||||
previousRegion String?
|
||||
id String @id @default(uuid())
|
||||
userId String
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
surname String
|
||||
givenNames String
|
||||
sex Sex
|
||||
birthDate DateTime
|
||||
applicationType ApplicationType
|
||||
previousCountry String?
|
||||
previousRegion String?
|
||||
naturalizationReason String?
|
||||
address String
|
||||
regionId String?
|
||||
region Region? @relation(fields: [regionId], references: [id])
|
||||
city String?
|
||||
street String?
|
||||
customAddress String?
|
||||
height Int
|
||||
eyeColor EyeColor
|
||||
status CitizenshipApplicationStatus @default(PENDING)
|
||||
rejectionReason String?
|
||||
reviewedAt DateTime?
|
||||
reviewedBy String?
|
||||
reviewer User? @relation("CitizenshipReviewer", fields: [reviewedBy], references: [id])
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
profileKey String
|
||||
signatureKey String
|
||||
citizenship Citizenship?
|
||||
address String
|
||||
regionId String?
|
||||
region Region? @relation(fields: [regionId], references: [id])
|
||||
city String?
|
||||
street String?
|
||||
customAddress String?
|
||||
height Int
|
||||
eyeColor EyeColor
|
||||
status CitizenshipApplicationStatus @default(PENDING)
|
||||
rejectionReason String?
|
||||
reviewedAt DateTime?
|
||||
reviewedBy String?
|
||||
reviewer User? @relation("CitizenshipReviewer", fields: [reviewedBy], references: [id])
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
profileKey String
|
||||
signatureKey String
|
||||
citizenship Citizenship?
|
||||
}
|
||||
|
||||
model Citizenship {
|
||||
@@ -154,37 +156,225 @@ model Citizenship {
|
||||
issuedAt DateTime @default(now())
|
||||
revokedAt DateTime?
|
||||
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
application CitizenshipApplication @relation(fields: [applicationId], references: [id])
|
||||
user User @relation(fields: [userId], references: [id])
|
||||
application CitizenshipApplication @relation(fields: [applicationId], references: [id])
|
||||
identityDocuments IdentityDocument[]
|
||||
positions CitizenshipPosition[]
|
||||
approvals ActApproval[]
|
||||
|
||||
@@index([userId])
|
||||
}
|
||||
|
||||
model IdentityDocument {
|
||||
id String @id @default(uuid())
|
||||
citizenshipId String
|
||||
citizenship Citizenship @relation(fields: [citizenshipId], references: [id], onDelete: Cascade)
|
||||
id String @id @default(uuid())
|
||||
citizenshipId String
|
||||
citizenship Citizenship @relation(fields: [citizenshipId], references: [id], onDelete: Cascade)
|
||||
|
||||
documentNumber String @unique
|
||||
documentNumber String @unique
|
||||
address String
|
||||
|
||||
regionId String?
|
||||
region Region? @relation(fields: [regionId], references: [id])
|
||||
city String?
|
||||
street String?
|
||||
customAddress String?
|
||||
regionId String?
|
||||
region Region? @relation(fields: [regionId], references: [id])
|
||||
city String?
|
||||
street String?
|
||||
customAddress String?
|
||||
|
||||
issuedAt DateTime @default(now())
|
||||
expiresAt DateTime
|
||||
issuedAt DateTime @default(now())
|
||||
expiresAt DateTime
|
||||
|
||||
@@index([citizenshipId, issuedAt])
|
||||
}
|
||||
|
||||
model Region {
|
||||
id String @id
|
||||
id String @id
|
||||
name String
|
||||
capital String
|
||||
documents IdentityDocument[]
|
||||
applications CitizenshipApplication[]
|
||||
}
|
||||
acts Act[]
|
||||
}
|
||||
|
||||
enum InstitutionKind {
|
||||
LEGISLATIVE_CHAMBER
|
||||
HEAD_OF_STATE
|
||||
HEAD_OF_GOVERNMENT
|
||||
DEPARTMENT
|
||||
AGENCY
|
||||
REGION
|
||||
COURT
|
||||
}
|
||||
|
||||
model Institution {
|
||||
id String @id @default(uuid())
|
||||
kind InstitutionKind
|
||||
name String
|
||||
code String? @unique
|
||||
parentId String?
|
||||
parent Institution? @relation("InstitutionHierarchy", fields: [parentId], references: [id])
|
||||
children Institution[] @relation("InstitutionHierarchy")
|
||||
isActive Boolean @default(true)
|
||||
|
||||
appointedByInstitutionId String?
|
||||
appointedBy Institution? @relation("InstitutionAppointer", fields: [appointedByInstitutionId], references: [id])
|
||||
appointsInto Institution[] @relation("InstitutionAppointer")
|
||||
|
||||
acts Act[]
|
||||
|
||||
positions Position[]
|
||||
}
|
||||
|
||||
enum ActCapability {
|
||||
SIGN_FEDERAL_LAW_SENATE
|
||||
SIGN_FEDERAL_LAW_HOUSE
|
||||
SIGN_AS_HEAD_OF_STATE
|
||||
SIGN_AS_HEAD_OF_GOVERNMENT
|
||||
SIGN_AS_HEAD_OF_DEPARTMENT
|
||||
SIGN_AS_HEAD_OF_AGENCY
|
||||
SIGN_AS_JUDGE
|
||||
SIGN_SENATE_APPOINTMENT
|
||||
SIGN_TREATY
|
||||
SIGN_RATIFICATION
|
||||
SIGN_REGIONAL_ACT
|
||||
}
|
||||
|
||||
model Position {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
institutionId String
|
||||
institution Institution @relation(fields: [institutionId], references: [id], onDelete: Cascade)
|
||||
|
||||
capabilities PositionCapability[]
|
||||
holders CitizenshipPosition[]
|
||||
|
||||
@@unique([institutionId, name])
|
||||
}
|
||||
|
||||
model PositionCapability {
|
||||
id String @id @default(uuid())
|
||||
positionId String
|
||||
position Position @relation(fields: [positionId], references: [id], onDelete: Cascade)
|
||||
capability ActCapability
|
||||
|
||||
@@unique([positionId, capability])
|
||||
}
|
||||
|
||||
model CitizenshipPosition {
|
||||
id String @id @default(uuid())
|
||||
citizenshipId String
|
||||
citizenship Citizenship @relation(fields: [citizenshipId], references: [id], onDelete: Cascade)
|
||||
positionId String
|
||||
position Position @relation(fields: [positionId], references: [id], onDelete: Cascade)
|
||||
assignedAt DateTime @default(now())
|
||||
resignedAt DateTime?
|
||||
|
||||
actId String?
|
||||
act Act? @relation(fields: [actId], references: [id])
|
||||
|
||||
@@index([positionId, resignedAt])
|
||||
@@index([citizenshipId])
|
||||
}
|
||||
|
||||
model ActType {
|
||||
id String @id @default(uuid())
|
||||
code String @unique
|
||||
name String
|
||||
allowedIssuerKind InstitutionKind
|
||||
allowedIssuerInstitutionCode String?
|
||||
legalRank Int
|
||||
numberingScope String
|
||||
|
||||
acts Act[]
|
||||
}
|
||||
|
||||
enum ActLegalStatus {
|
||||
DRAFT
|
||||
IN_FORCE
|
||||
AMENDED
|
||||
REPEALED
|
||||
EXPIRED
|
||||
NOT_ADOPTED
|
||||
}
|
||||
|
||||
model Act {
|
||||
id String @id @default(uuid())
|
||||
|
||||
actTypeId String
|
||||
actType ActType @relation(fields: [actTypeId], references: [id])
|
||||
|
||||
issuingInstitutionId String
|
||||
issuingInstitution Institution @relation(fields: [issuingInstitutionId], references: [id])
|
||||
|
||||
regionId String?
|
||||
region Region? @relation(fields: [regionId], references: [id])
|
||||
|
||||
authorId String
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
|
||||
numberYear Int?
|
||||
numberInSeries Int?
|
||||
|
||||
legalStatus ActLegalStatus @default(DRAFT)
|
||||
|
||||
title String
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
versions ActVersion[]
|
||||
citizenshipPositions CitizenshipPosition[]
|
||||
}
|
||||
|
||||
model ActVersion {
|
||||
id String @id @default(uuid())
|
||||
actId String
|
||||
act Act @relation(fields: [actId], references: [id], onDelete: Cascade)
|
||||
|
||||
effectiveFrom DateTime?
|
||||
isCurrent Boolean @default(true)
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
createdBy String
|
||||
|
||||
blocks ActBlock[]
|
||||
approvals ActApproval[]
|
||||
|
||||
@@index([actId, effectiveFrom])
|
||||
}
|
||||
|
||||
model ActBlock {
|
||||
id String @id @default(uuid())
|
||||
versionId String
|
||||
version ActVersion @relation(fields: [versionId], references: [id], onDelete: Cascade)
|
||||
|
||||
stableKey String
|
||||
type String
|
||||
position Float
|
||||
content Json
|
||||
|
||||
@@unique([versionId, stableKey])
|
||||
@@index([versionId, position])
|
||||
}
|
||||
|
||||
enum ApprovalDecision {
|
||||
APPROVE
|
||||
VETO
|
||||
}
|
||||
|
||||
model ActApproval {
|
||||
id String @id @default(uuid())
|
||||
actVersionId String
|
||||
actVersion ActVersion @relation(fields: [actVersionId], references: [id], onDelete: Cascade)
|
||||
|
||||
phaseKey String
|
||||
decision ApprovalDecision
|
||||
|
||||
citizenshipId String
|
||||
citizenship Citizenship @relation(fields: [citizenshipId], references: [id])
|
||||
|
||||
name String
|
||||
role String
|
||||
|
||||
decidedAt DateTime @default(now())
|
||||
|
||||
@@unique([actVersionId, phaseKey])
|
||||
}
|
||||
|
||||
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 81 KiB |
Reference in New Issue
Block a user