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>
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user