Files
eu/app/account/citizenship/review/application-card.tsx
T
2026-07-11 21:20:57 +03:00

184 lines
8.1 KiB
TypeScript

"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 { 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 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)
const [reason, setReason] = useState("")
const [isloading, setIsLoading] = useState(false)
if (!application?.id) {
return (
<div className="max-w-sm w-full flex items-center justify-center ring-1 ring-foreground/10 rounded-xl text-muted-foreground px-4 py-1">
Click on a row to see the application
</div>
)
}
const applicationId = application.id;
async function handleApprove() {
setIsLoading(true)
const result = await approveApplication(applicationId)
setIsLoading(false)
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)
const result = await rejectApplication(applicationId, reason)
setIsLoading(false)
if (result.success) {
toast.success("Application rejected")
setRejectOpen(false)
onClose()
} else {
toast.error(result.error ?? "Failed to reject application")
}
}
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-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 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>
)}
{ 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>
</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>
<Tooltip>
<TooltipTrigger>
<p className="text-start truncate">{application.address}</p>
</TooltipTrigger>
<TooltipContent>
<p>{application.address}</p>
</TooltipContent>
</Tooltip>
</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 onClick={handleReject} disabled={!reason.trim() || isloading}>
{isloading && <Spinner />}Confirm rejection
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
)
}