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 { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||||
import { approveApplication, rejectApplication } from "@/lib/citizenship/actions";
|
import { approveApplication, rejectApplication } from "@/lib/citizenship/actions";
|
||||||
import { CitizenshipApplicationWithWarning } from "@/lib/citizenship/types";
|
import { CitizenshipApplicationWithWarning } from "@/lib/citizenship/types";
|
||||||
import { formatDate } from "@/lib/utils";
|
import { cn, formatDate } from "@/lib/utils";
|
||||||
import { TriangleAlertIcon } from "lucide-react";
|
import { CheckIcon, ClockFadingIcon, PlusIcon, TriangleAlertIcon, XIcon } from "lucide-react";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
|
|
||||||
@@ -36,7 +36,6 @@ export default function ApplicationCard({ application, onClose }: { application:
|
|||||||
setIsLoading(false)
|
setIsLoading(false)
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
toast.success("Application approved")
|
toast.success("Application approved")
|
||||||
onClose()
|
|
||||||
} else {
|
} else {
|
||||||
toast.error(result.error ?? "Failed to approve application")
|
toast.error(result.error ?? "Failed to approve application")
|
||||||
}
|
}
|
||||||
@@ -50,7 +49,6 @@ export default function ApplicationCard({ application, onClose }: { application:
|
|||||||
if (result.success) {
|
if (result.success) {
|
||||||
toast.success("Application rejected")
|
toast.success("Application rejected")
|
||||||
setRejectOpen(false)
|
setRejectOpen(false)
|
||||||
onClose()
|
|
||||||
} else {
|
} else {
|
||||||
toast.error(result.error ?? "Failed to reject application")
|
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>
|
<CardDescription>{application.applicationType === "PREVIOUS_CITIZENSHIP" ? "Previous citizenship application" : "Naturalization application"}</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="max-w-sm">
|
<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">
|
<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" />
|
<img src={application.profileUrl} alt="Profile photo" className="w-full h-full object-cover" />
|
||||||
</div>
|
</div>
|
||||||
<div className="w-40 px-2 aspect-5/2 rounded-md overflow-hidden ring-1 ring-foreground/10 shrink-0 bg-white">
|
<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" />
|
<img src={application.signatureUrl} alt="Signature" className="w-full h-full object-contain" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>)}
|
||||||
<div className="flex flex-col gap-1">
|
<div className="flex flex-col gap-1">
|
||||||
<h4 className="mb-1">Personal information</h4>
|
<h4 className="mb-1">Personal information</h4>
|
||||||
{ application.nameMismatch && (
|
{ application.nameMismatch && (
|
||||||
@@ -147,17 +145,51 @@ export default function ApplicationCard({ application, onClose }: { application:
|
|||||||
</div>
|
</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>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<CardFooter className="gap-2">
|
{application.status === "PENDING" ? (
|
||||||
<Button onClick={handleApprove} disabled={isloading}>
|
<CardFooter className="gap-2">
|
||||||
{isloading && <Spinner />}Approve
|
<Button onClick={handleApprove} disabled={isloading}>
|
||||||
</Button>
|
{isloading && <Spinner />}Approve
|
||||||
<Button variant="outline" onClick={() => setRejectOpen(true)} disabled={isloading}>
|
</Button>
|
||||||
{isloading && <Spinner />}Reject
|
<Button variant="outline" onClick={() => setRejectOpen(true)} disabled={isloading}>
|
||||||
</Button>
|
{isloading && <Spinner />}Reject
|
||||||
<Button variant="outline" onClick={onClose}>Close</Button>
|
</Button>
|
||||||
</CardFooter>
|
<Button variant="outline" onClick={onClose}>Close</Button>
|
||||||
|
</CardFooter>
|
||||||
|
) : (
|
||||||
|
<CardFooter>
|
||||||
|
<Button variant="outline" onClick={onClose}>Close</Button>
|
||||||
|
</CardFooter>
|
||||||
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
<Dialog open={rejectOpen} onOpenChange={setRejectOpen}>
|
<Dialog open={rejectOpen} onOpenChange={setRejectOpen}>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ import { CitizenshipApplication } from "@/lib/citizenship/types";
|
|||||||
import { Badge } from "@/components/ui/badge";
|
import { Badge } from "@/components/ui/badge";
|
||||||
import { formatDate } from "@/lib/utils";
|
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>[] = [
|
export const columns: ColumnDef<CitizenshipApplication>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "surname",
|
accessorKey: "surname",
|
||||||
@@ -31,7 +39,7 @@ export const columns: ColumnDef<CitizenshipApplication>[] = [
|
|||||||
header: "Status",
|
header: "Status",
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const status = row.getValue("status") as string
|
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 { getCurrentUser } from "@/lib/user";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import { AccountMenu } from "../../account-menu";
|
import { AccountMenu } from "../../account-menu";
|
||||||
import { getPendingApplications } from "@/lib/citizenship/repository";
|
import { getAllApplications } from "@/lib/citizenship/repository";
|
||||||
import { getImageUrl } from "@/lib/image";
|
import { getImageUrl } from "@/lib/image";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
|
import { findUserById } from "@/lib/user/repository";
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "Review citizenship applications",
|
title: "Review citizenship applications",
|
||||||
@@ -18,21 +19,31 @@ export default async function ReviewPage() {
|
|||||||
const user = await getCurrentUser();
|
const user = await getCurrentUser();
|
||||||
if (!user?.isAdmin) redirect("/account/citizenship");
|
if (!user?.isAdmin) redirect("/account/citizenship");
|
||||||
|
|
||||||
const applications = await getPendingApplications();
|
const applications = await getAllApplications();
|
||||||
|
|
||||||
const applicationsWithWarning = await Promise.all(
|
const applicationsWithWarning = await Promise.all(
|
||||||
applications.map(async (application) => ({
|
applications.map(async (application) => {
|
||||||
...application,
|
const reviewerUser = application.reviewedBy
|
||||||
profileUrl: await getImageUrl(application.profileKey),
|
? await findUserById(application.reviewedBy)
|
||||||
signatureUrl: await getImageUrl(application.signatureKey),
|
: null;
|
||||||
|
|
||||||
nameMismatch:
|
return {
|
||||||
application.givenNames !== application.user.firstName ||
|
...application,
|
||||||
application.surname !== application.user.secondName,
|
profileUrl: await getImageUrl(application.profileKey),
|
||||||
|
signatureUrl: await getImageUrl(application.signatureKey),
|
||||||
|
|
||||||
previousCitizenship:
|
nameMismatch:
|
||||||
application.user._count.citizenships > 0,
|
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 (
|
return (
|
||||||
|
|||||||
+18
-7
@@ -5,13 +5,23 @@ import { getPages } from "@/lib/pages/repository";
|
|||||||
import { getCurrentUser } from "@/lib/user";
|
import { getCurrentUser } from "@/lib/user";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import SearchBar from "./searchBar";
|
||||||
|
|
||||||
export const metadata: Metadata = { title: "News" };
|
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 user = await getCurrentUser();
|
||||||
const news = await getPages("NEWS", "PUBLISHED");
|
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 newsDrafts = await getPages("NEWS", "DRAFT");
|
||||||
const pageDrafts = await getPages("PAGE", "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 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">
|
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between">
|
||||||
<h1>News</h1>
|
<h1>News</h1>
|
||||||
|
<SearchBar />
|
||||||
<div className="flex flex-row items-center gap-4">
|
<div className="flex flex-row items-center gap-4">
|
||||||
{user?.isAdmin && (
|
{user?.isAdmin && (
|
||||||
<div className="flex flex-row items-center gap-4">
|
<div className="flex flex-row items-center gap-4">
|
||||||
@@ -31,12 +42,12 @@ export default async function News() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
{
|
{
|
||||||
news.length > 0 ? news.map((n) => (
|
filteredNews.length > 0 ? filteredNews.map((n) => (
|
||||||
<NewsCard news={n} key={n.id} />
|
<NewsCard news={n} key={n.id} />
|
||||||
)) : <h2 className="text-muted-foreground">There are no news yet...</h2>
|
)) : <h2 className="text-muted-foreground">There are no news yet...</h2>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -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>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -77,9 +77,8 @@ export async function getUserApplications(userId: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getPendingApplications() {
|
export async function getAllApplications() {
|
||||||
return prisma.citizenshipApplication.findMany({
|
return prisma.citizenshipApplication.findMany({
|
||||||
where: { status: "PENDING" },
|
|
||||||
orderBy: { createdAt: "desc" },
|
orderBy: { createdAt: "desc" },
|
||||||
include: {
|
include: {
|
||||||
user: {
|
user: {
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ export type CitizenshipApplicationWithWarning = CitizenshipApplication & {
|
|||||||
previousCitizenship: boolean;
|
previousCitizenship: boolean;
|
||||||
profileUrl: string;
|
profileUrl: string;
|
||||||
signatureUrl: string;
|
signatureUrl: string;
|
||||||
};
|
reviewer: { firstName: string; secondName: string } | null;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user