161 lines
6.2 KiB
TypeScript
161 lines
6.2 KiB
TypeScript
import { IdentityCardData } from "@/lib/id/repository";
|
|
import { formatDate } from "@/lib/utils";
|
|
import Image from "next/image";
|
|
import { Button } from "./ui/button";
|
|
import { Menu } from "lucide-react";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
} from "@/components/ui/dialog";
|
|
|
|
type DialogField = {
|
|
key: keyof IdentityCardData;
|
|
label: string;
|
|
};
|
|
|
|
const DIALOG_FIELDS: DialogField[] = [
|
|
{ key: "sex", label: "Sex" },
|
|
{ key: "birthDate", label: "Date of birth" },
|
|
{ key: "authority", label: "Authority" },
|
|
{ key: "nationality", label: "Nationality" },
|
|
{ key: "issueDate", label: "Date of issue" },
|
|
{ key: "expiryDate", label: "Date of expiry" },
|
|
{ key: "issuingCountry", label: "Issuing country" },
|
|
{ key: "origin", label: "Place of origin" },
|
|
{ key: "height", label: "Height" },
|
|
{ key: "eyeColor", label: "Eye color" },
|
|
];
|
|
|
|
const ADDRESS_FIELD: DialogField = { key: "address", label: "Address" };
|
|
|
|
function formatFieldValue(key: keyof IdentityCardData, value: unknown) {
|
|
if (value instanceof Date) return formatDate(value);
|
|
if (value == null) return "—";
|
|
if (key === "height") return `${value} cm`;
|
|
return String(value);
|
|
}
|
|
|
|
function CardPattern() {
|
|
return (
|
|
<svg className="absolute inset-0 w-full h-full" aria-hidden="true">
|
|
<defs>
|
|
<pattern id="id-card-waves" width="120" height="16" patternUnits="userSpaceOnUse">
|
|
<path d="M0 8 Q15 2 30 8 T60 8 T90 8 T120 8" fill="none" stroke="#bfdbfe" strokeWidth="1" />
|
|
</pattern>
|
|
<pattern id="id-card-dots" width="24" height="24" patternUnits="userSpaceOnUse">
|
|
<circle cx="4" cy="4" r="1.5" fill="white" />
|
|
<circle cx="16" cy="14" r="1.5" fill="white" />
|
|
</pattern>
|
|
</defs>
|
|
<rect width="100%" height="100%" fill="url(#id-card-waves)" />
|
|
<rect width="100%" height="100%" fill="url(#id-card-dots)" />
|
|
</svg>
|
|
);
|
|
}
|
|
|
|
export default function IdCard({ data }: { data: IdentityCardData }) {
|
|
return (
|
|
<div className="relative w-96 bg-blue-50 rounded-lg p-4 overflow-hidden">
|
|
<CardPattern />
|
|
<div className="relative z-10">
|
|
<div className="flex flex-row items-center justify-between">
|
|
<div className="flex flex-row gap-3 items-center">
|
|
<Image src="/emblem.png" width={24} height={24} alt="Emblem" />
|
|
<h2>ID Card</h2>
|
|
</div>
|
|
<h3>{data.documentNumber}</h3>
|
|
<Dialog>
|
|
<DialogTrigger asChild>
|
|
<Button size="icon-sm">
|
|
<Menu />
|
|
</Button>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<div className="flex flex-row gap-3">
|
|
<div className="relative w-12 h-14 shrink-0 rounded overflow-hidden">
|
|
<Image src="/profile.png" fill alt="Profile" className="object-cover" />
|
|
</div>
|
|
<div className="flex flex-col gap-0 justify-center">
|
|
<DialogTitle asChild>
|
|
<h4 className="uppercase">{data.surname} {data.givenNames}</h4>
|
|
</DialogTitle>
|
|
<h4 className="text-muted-foreground">{data.documentNumber}</h4>
|
|
</div>
|
|
</div>
|
|
</DialogHeader>
|
|
<div className="grid grid-cols-2 gap-x-6 gap-y-2">
|
|
{DIALOG_FIELDS.map(({ key, label }) => (
|
|
<div className="flex flex-col" key={key}>
|
|
<h5 className="text-blue-500">{label}</h5>
|
|
<h4 className="leading-6">{formatFieldValue(key, data[key])}</h4>
|
|
</div>
|
|
))}
|
|
<div className="flex flex-col col-span-2">
|
|
<h5 className="text-blue-500">{ADDRESS_FIELD.label}</h5>
|
|
<h4 className="leading-6">{formatFieldValue(ADDRESS_FIELD.key, data[ADDRESS_FIELD.key])}</h4>
|
|
</div>
|
|
</div>
|
|
</DialogContent>
|
|
</Dialog>
|
|
</div>
|
|
|
|
<div className="flex flex-row gap-8 mt-4">
|
|
<div className="flex flex-col gap-4 w-24 shrink-0">
|
|
<div className="relative w-24 h-28 shrink-0">
|
|
<Image src="/profile.png" fill alt="Profile" className="object-cover" />
|
|
</div>
|
|
<div className="relative w-24 h-12 shrink-0">
|
|
<Image src="/signature.png" fill alt="Signature" className="object-contain" />
|
|
</div>
|
|
</div>
|
|
<div className="flex flex-col gap-2">
|
|
<div className="flex flex-wrap gap-x-6 gap-y-2">
|
|
<div className="flex flex-col min-w-fit">
|
|
<h5 className="text-blue-500">Surname</h5>
|
|
<h4 className="uppercase">{data.surname}</h4>
|
|
</div>
|
|
<div className="flex flex-col min-w-fit">
|
|
<h5 className="text-blue-500">Given name(s)</h5>
|
|
<h4 className="uppercase">{data.givenNames}</h4>
|
|
</div>
|
|
</div>
|
|
<div className="flex flex-wrap gap-x-6 gap-y-2">
|
|
<div className="flex flex-col min-w-fit">
|
|
<h5 className="text-blue-500">Sex</h5>
|
|
<h4>{data.sex}</h4>
|
|
</div>
|
|
<div className="flex flex-col min-w-fit">
|
|
<h5 className="text-blue-500">Date of birth</h5>
|
|
<h4>{formatDate(data.birthDate)}</h4>
|
|
</div>
|
|
</div>
|
|
<div className="flex flex-wrap gap-x-6 gap-y-2">
|
|
<div className="flex flex-col min-w-fit">
|
|
<h5 className="text-blue-500">Authority</h5>
|
|
<h4 className="leading-6">{data.authority}</h4>
|
|
</div>
|
|
<div className="flex flex-col min-w-fit">
|
|
<h5 className="text-blue-500">Nationality</h5>
|
|
<h4>{data.nationality}</h4>
|
|
</div>
|
|
</div>
|
|
<div className="flex flex-wrap gap-x-6 gap-y-2">
|
|
<div className="flex flex-col min-w-fit">
|
|
<h5 className="text-blue-500">Issue date</h5>
|
|
<h4>{formatDate(data.issueDate)}</h4>
|
|
</div>
|
|
<div className="flex flex-col min-w-fit">
|
|
<h5 className="text-blue-500">Date of expiry</h5>
|
|
<h4>{formatDate(data.expiryDate)}</h4>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
} |