feat: citizenship built
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
"use client"
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import { approveApplication, rejectApplication } from "@/lib/citizenship/actions";
|
||||
import { CitizenshipApplicationWithWarning } from "@/lib/citizenship/types";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import { TriangleAlertIcon } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
|
||||
export default function ApplicationCard({ application, onClose }: { application: CitizenshipApplicationWithWarning | undefined, onClose: () => void }) {
|
||||
const [rejectOpen, setRejectOpen] = useState(false)
|
||||
const [reason, setReason] = useState("")
|
||||
const [isloading, setIsLoading] = useState(false)
|
||||
|
||||
if (!application?.id) {
|
||||
return (
|
||||
<div className="w-sm flex items-center justify-center ring-1 ring-foreground/10 rounded-xl text-muted-foreground px-4">
|
||||
Click on a row to see the application
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
async function handleApprove() {
|
||||
setIsLoading(true)
|
||||
await approveApplication(application.id)
|
||||
setIsLoading(false)
|
||||
onClose()
|
||||
}
|
||||
|
||||
async function handleReject() {
|
||||
if (!reason.trim()) return
|
||||
setIsLoading(true)
|
||||
await rejectApplication(application.id, reason)
|
||||
setIsLoading(false)
|
||||
setRejectOpen(false)
|
||||
onClose()
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Card size="sm" className="mx-auto w-full">
|
||||
<CardHeader>
|
||||
<CardTitle><h3>{application.givenNames} {application.surname}</h3></CardTitle>
|
||||
<CardDescription>{application.applicationType === "PREVIOUS_CITIZENSHIP" ? "Previous citizenship application" : "Naturalization application"}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="max-w-sm">
|
||||
<div className="flex flex-col gap-1">
|
||||
<h4 className="mb-1">Personal information</h4>
|
||||
{ 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>
|
||||
)}
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Given names</p>
|
||||
<p>{application.givenNames}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Surname</p>
|
||||
<p>{application.surname}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Sex</p>
|
||||
<p>{application.sex}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Birthdate</p>
|
||||
<p>{formatDate(application.birthDate)}</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<p className="text-muted-foreground">Address</p>
|
||||
<p className="truncate">{application.address}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Height</p>
|
||||
<p>{application.height} cm</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Eye color</p>
|
||||
<p>{application.eyeColor}</p>
|
||||
</div>
|
||||
<Separator className="my-2" />
|
||||
<h4 className="mb-1">Eligibility proofs</h4>
|
||||
{
|
||||
application.applicationType == "PREVIOUS_CITIZENSHIP" && (
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground truncate">Country of previous citizenship</p>
|
||||
<p className="truncate">{application.previousCountry == "DUS" ? "Duspean Republic" : "Country of Reality"}</p>
|
||||
</div>
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground truncate">Region of previous residence</p>
|
||||
<p className="truncate">{application.previousRegion}</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
{
|
||||
application.applicationType == "NATURALIZATION" && (
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<p className="text-muted-foreground">Naturalization reason</p>
|
||||
<p>{application.naturalizationReason}</p>
|
||||
</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>
|
||||
</Card>
|
||||
<Dialog open={rejectOpen} onOpenChange={setRejectOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle asChild><h3>Reject application</h3></DialogTitle>
|
||||
<DialogDescription>Provide a reason. The applicant will see this.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<Textarea
|
||||
placeholder="Reason for rejection..."
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
/>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setRejectOpen(false)}>Cancel</Button>
|
||||
<Button variant="destructive" onClick={handleReject} disabled={!reason.trim() || isloading}>
|
||||
{isloading && <Spinner />}Confirm rejection
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
"use client"
|
||||
|
||||
import { CitizenshipApplication } from "@/lib/citizenship/types";
|
||||
import { DataTable } from "./data-table";
|
||||
import { columns } from "./columns";
|
||||
import ApplicationCard from "./application-card";
|
||||
import { useState } from "react";
|
||||
|
||||
|
||||
export default function ReviewPageClient({ applications }: { applications: CitizenshipApplication[] }) {
|
||||
const [selectedApplicationId, setSelectedApplicationId] = useState("");
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-row gap-16">
|
||||
<div className="flex flex-col gap-8">
|
||||
<div className="flex flex-col gap-6">
|
||||
<h2>Review citizenship applications</h2>
|
||||
</div>
|
||||
<DataTable columns={columns} data={applications} onRowClick={(app) => setSelectedApplicationId(app.id)} />
|
||||
</div>
|
||||
<ApplicationCard application={applications.find((a) => a.id === selectedApplicationId)} onClose={() => setSelectedApplicationId("")} />
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client"
|
||||
|
||||
import { ColumnDef } from "@tanstack/react-table";
|
||||
import { CitizenshipApplication } from "@/lib/citizenship/types";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
|
||||
export const columns: ColumnDef<CitizenshipApplication>[] = [
|
||||
{
|
||||
accessorKey: "surname",
|
||||
header: "Applicant",
|
||||
cell: ({ row }) => {
|
||||
const application = row.original
|
||||
return <span>{application.givenNames} {application.surname}</span>
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "birthDate",
|
||||
header: "Birth date",
|
||||
cell: ({ row }) => formatDate(row.getValue("birthDate")),
|
||||
},
|
||||
{
|
||||
accessorKey: "applicationType",
|
||||
header: "Type",
|
||||
cell: ({ row }) => {
|
||||
return <span>{row.original.applicationType === "PREVIOUS_CITIZENSHIP" ? "Previous citizenship" : "Naturalization"}</span>
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: "Status",
|
||||
cell: ({ row }) => {
|
||||
const status = row.getValue("status") as string
|
||||
return <Badge variant={status === "PENDING" ? "outline" : "default"}>{status}</Badge>
|
||||
},
|
||||
},
|
||||
]
|
||||
@@ -0,0 +1,51 @@
|
||||
"use client"
|
||||
|
||||
import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
|
||||
interface DataTableProps<TData, TValue> {
|
||||
columns: ColumnDef<TData, TValue>[];
|
||||
data: TData[];
|
||||
onRowClick?: (row: TData) => void;
|
||||
}
|
||||
|
||||
export function DataTable<TData, TValue>({ columns, data, onRowClick }: DataTableProps<TData, TValue>) {
|
||||
const table = useReactTable({
|
||||
data,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="overflow-hidden rounded-md w-full">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
{table.getHeaderGroups().map((headerGroup) => (
|
||||
<TableRow key={headerGroup.id}>
|
||||
{headerGroup.headers.map((header) => (
|
||||
<TableHead key={header.id}>
|
||||
{header.isPlaceholder ? null : flexRender(
|
||||
header.column.columnDef.header,
|
||||
header.getContext()
|
||||
)}
|
||||
</TableHead>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowCount() === 0 && <h5 className="mt-2 text-muted-foreground">There are no pending applications</h5>}
|
||||
{table.getRowModel().rows.map((row) => (
|
||||
<TableRow key={row.id} className="cursor-pointer" onClick={() => onRowClick?.(row.original)}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
<TableCell key={cell.id}>
|
||||
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import Header from "@/components/header";
|
||||
import Footer from "@/components/footer";
|
||||
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";
|
||||
|
||||
export default async function ReviewPage() {
|
||||
const user = await getCurrentUser();
|
||||
if (!user?.isAdmin) redirect("/account/citizenship");
|
||||
|
||||
const applications = await getPendingApplications()
|
||||
|
||||
const applicationsWithWarning = applications.map((app) => ({
|
||||
...app,
|
||||
nameMismatch: app.givenNames !== app.user.firstName || app.surname !== app.user.secondName,
|
||||
}))
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<div className="flex flex-row py-16 gap-8">
|
||||
<AccountMenu />
|
||||
<ReviewPageClient applications={applicationsWithWarning} />
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user