add: news search bar, application history
This commit is contained in:
@@ -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,14 +62,14 @@ 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 && (
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user