feat: images upload
This commit is contained in:
@@ -11,7 +11,9 @@ import { approveApplication, rejectApplication } from "@/lib/citizenship/actions
|
||||
import { CitizenshipApplicationWithWarning } from "@/lib/citizenship/types";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import { TriangleAlertIcon } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export default function ApplicationCard({ application, onClose }: { application: CitizenshipApplicationWithWarning | undefined, onClose: () => void }) {
|
||||
const [rejectOpen, setRejectOpen] = useState(false)
|
||||
@@ -26,20 +28,32 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
)
|
||||
}
|
||||
|
||||
const applicationId = application.id;
|
||||
|
||||
async function handleApprove() {
|
||||
setIsLoading(true)
|
||||
await approveApplication(application.id)
|
||||
const result = await approveApplication(applicationId)
|
||||
setIsLoading(false)
|
||||
onClose()
|
||||
if (result.success) {
|
||||
toast.success("Application approved")
|
||||
onClose()
|
||||
} else {
|
||||
toast.error(result.error ?? "Failed to approve application")
|
||||
}
|
||||
}
|
||||
|
||||
async function handleReject() {
|
||||
if (!reason.trim()) return
|
||||
setIsLoading(true)
|
||||
await rejectApplication(application.id, reason)
|
||||
const result = await rejectApplication(applicationId, reason)
|
||||
setIsLoading(false)
|
||||
setRejectOpen(false)
|
||||
onClose()
|
||||
if (result.success) {
|
||||
toast.success("Application rejected")
|
||||
setRejectOpen(false)
|
||||
onClose()
|
||||
} else {
|
||||
toast.error(result.error ?? "Failed to reject application")
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -50,6 +64,18 @@ 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-2 mb-2">
|
||||
<img
|
||||
src={application.profileUrl}
|
||||
alt="Profile"
|
||||
className={"w-18 h-24 rounded-md object-cover ring-1 ring-foreground/10 shrink-0"}
|
||||
/>
|
||||
<img
|
||||
src={application.signatureUrl}
|
||||
alt="Profile"
|
||||
className={"w-36 h-18 rounded-md object-cover ring-1 ring-foreground/10 shrink-0"}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1">
|
||||
<h4 className="mb-1">Personal information</h4>
|
||||
{ application.nameMismatch && (
|
||||
@@ -59,6 +85,13 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
<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 && (
|
||||
<Alert className="mb-2" variant="warning">
|
||||
<TriangleAlertIcon />
|
||||
<AlertTitle>Previous citizenship holder</AlertTitle>
|
||||
<AlertDescription className="w-fit max-w-full">This person previously held citizenship of the European Federation. Please verify the reason for renunciation.</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
<div className="flex flex-row gap-4 items-center">
|
||||
<p className="text-muted-foreground">Given names</p>
|
||||
<p>{application.givenNames}</p>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
"use client"
|
||||
|
||||
import { CitizenshipApplication } from "@/lib/citizenship/types";
|
||||
import { CitizenshipApplicationWithWarning } 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[] }) {
|
||||
export default function ReviewPageClient({ applications }: { applications: CitizenshipApplicationWithWarning[] }) {
|
||||
const [selectedApplicationId, setSelectedApplicationId] = useState("");
|
||||
|
||||
return (
|
||||
@@ -17,9 +17,16 @@ export default function ReviewPageClient({ applications }: { applications: Citiz
|
||||
<div className="flex flex-col gap-6">
|
||||
<h2>Review citizenship applications</h2>
|
||||
</div>
|
||||
<DataTable columns={columns} data={applications} onRowClick={(app) => setSelectedApplicationId(app.id)} />
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={applications}
|
||||
onRowClick={(application) => setSelectedApplicationId(application.id)}
|
||||
/>
|
||||
</div>
|
||||
<ApplicationCard application={applications.find((a) => a.id === selectedApplicationId)} onClose={() => setSelectedApplicationId("")} />
|
||||
<ApplicationCard
|
||||
application={applications.find((application) => application.id === selectedApplicationId)}
|
||||
onClose={() => setSelectedApplicationId("")}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -34,7 +34,7 @@ export function DataTable<TData, TValue>({ columns, data, onRowClick }: DataTabl
|
||||
))}
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{table.getRowCount() === 0 && <h5 className="mt-2 text-muted-foreground">There are no pending applications</h5>}
|
||||
{table.getRowCount() === 0 && <TableRow><TableCell colSpan={columns.length} className="text-center text-muted-foreground">There are no pending applications</TableCell></TableRow>}
|
||||
{table.getRowModel().rows.map((row) => (
|
||||
<TableRow key={row.id} className="cursor-pointer" onClick={() => onRowClick?.(row.original)}>
|
||||
{row.getVisibleCells().map((cell) => (
|
||||
|
||||
@@ -5,17 +5,28 @@ import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AccountMenu } from "../../account-menu";
|
||||
import { getPendingApplications } from "@/lib/citizenship/repository";
|
||||
import { getImageUrl } from "@/lib/image";
|
||||
|
||||
export default async function ReviewPage() {
|
||||
const user = await getCurrentUser();
|
||||
if (!user?.isAdmin) redirect("/account/citizenship");
|
||||
|
||||
const applications = await getPendingApplications()
|
||||
const applications = await getPendingApplications();
|
||||
|
||||
const applicationsWithWarning = applications.map((app) => ({
|
||||
...app,
|
||||
nameMismatch: app.givenNames !== app.user.firstName || app.surname !== app.user.secondName,
|
||||
}))
|
||||
const applicationsWithWarning = await Promise.all(
|
||||
applications.map(async (application) => ({
|
||||
...application,
|
||||
profileUrl: await getImageUrl(application.profileKey),
|
||||
signatureUrl: await getImageUrl(application.signatureKey),
|
||||
|
||||
nameMismatch:
|
||||
application.givenNames !== application.user.firstName ||
|
||||
application.surname !== application.user.secondName,
|
||||
|
||||
previousCitizenship:
|
||||
application.user._count.citizenships > 0,
|
||||
}))
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user