prod
This commit is contained in:
@@ -64,7 +64,7 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
<FieldGroup>
|
||||
<FieldSet>
|
||||
<FieldLegend>Personal information</FieldLegend>
|
||||
<Alert variant="warning">
|
||||
<Alert className="mt-2" variant="warning">
|
||||
<InfoIcon />
|
||||
<AlertTitle>Important notice</AlertTitle>
|
||||
<AlertDescription>
|
||||
@@ -251,7 +251,7 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
<FieldLegend>Additional information</FieldLegend>
|
||||
<FieldDescription>Provide details required for your identity document.</FieldDescription>
|
||||
<FieldGroup>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="grid md:grid-cols-2 gap-4">
|
||||
<Field data-invalid={!!errors.height?.length}>
|
||||
<FieldLabel htmlFor="height">Height (in cm)</FieldLabel>
|
||||
<Input
|
||||
@@ -293,6 +293,8 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
label="Profile"
|
||||
description="Select a profile image to upload. The image should be taken on a neutral background."
|
||||
error={errors.profile?.[0]}
|
||||
previewClassName="aspect-4/5"
|
||||
removeBg
|
||||
/>
|
||||
<ImageUploadField
|
||||
id="signature"
|
||||
@@ -300,6 +302,7 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
label="Signature"
|
||||
description="Select a signature to upload."
|
||||
error={errors.signature?.[0]}
|
||||
previewClassName="aspect-5/2"
|
||||
/>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useRef, useState } from "react";
|
||||
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { XIcon, ImageIcon } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { removeBackground } from "@imgly/background-removal";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
|
||||
type Props = {
|
||||
id: string;
|
||||
@@ -11,41 +15,74 @@ type Props = {
|
||||
label: string;
|
||||
description: string;
|
||||
error?: string;
|
||||
previewClassName?: string;
|
||||
removeBg?: boolean;
|
||||
};
|
||||
|
||||
export function ImageUploadField({ id, name, label, description, error }: Props) {
|
||||
const MAX_SIZE = 5 * 1024 * 1024;
|
||||
const ACCEPTED_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
||||
|
||||
function formatFileSize(bytes: number): string {
|
||||
return bytes < 1024 * 1024 ? `${Math.round(bytes / 1024)} KB` : `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||
}
|
||||
|
||||
export function ImageUploadField({ id, name, label, description, error, previewClassName, removeBg }: Props) {
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
||||
const [fileInfo, setFileInfo] = useState<{ name: string; size: number } | null>(null);
|
||||
const [clientError, setClientError] = useState<string | null>(null);
|
||||
const [isProcessing, setIsProcessing] = useState(false);
|
||||
|
||||
const MAX_SIZE = 5 * 1024 * 1024;
|
||||
const ACCEPTED_TYPES = ["image/jpeg", "image/png", "image/webp"];
|
||||
|
||||
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = e.target.files?.[0];
|
||||
function reset() {
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
setPreviewUrl(null);
|
||||
setFileInfo(null);
|
||||
if (inputRef.current) inputRef.current.value = "";
|
||||
}
|
||||
|
||||
if (!file) {
|
||||
setPreviewUrl(null);
|
||||
setClientError(null);
|
||||
return;
|
||||
}
|
||||
async function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) { reset(); setClientError(null); return; }
|
||||
|
||||
if (!ACCEPTED_TYPES.includes(file.type)) {
|
||||
setClientError("Only JPEG, PNG, or WEBP images are allowed.");
|
||||
setPreviewUrl(null);
|
||||
e.target.value = "";
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > MAX_SIZE) {
|
||||
setClientError("Image must be smaller than 5MB.");
|
||||
setPreviewUrl(null);
|
||||
e.target.value = "";
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
setClientError(null);
|
||||
setPreviewUrl(URL.createObjectURL(file));
|
||||
|
||||
if (!removeBg) {
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
setPreviewUrl(URL.createObjectURL(file));
|
||||
setFileInfo({ name: file.name, size: file.size });
|
||||
return;
|
||||
}
|
||||
|
||||
setIsProcessing(true);
|
||||
try {
|
||||
const resultBlob = await removeBackground(file);
|
||||
const processedFile = new File([resultBlob], file.name, { type: "image/png" });
|
||||
|
||||
const dt = new DataTransfer();
|
||||
dt.items.add(processedFile);
|
||||
if (inputRef.current) inputRef.current.files = dt.files;
|
||||
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
setPreviewUrl(URL.createObjectURL(processedFile));
|
||||
setFileInfo({ name: processedFile.name, size: processedFile.size });
|
||||
} catch {
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
setPreviewUrl(URL.createObjectURL(file));
|
||||
setFileInfo({ name: file.name, size: file.size });
|
||||
} finally {
|
||||
setIsProcessing(false);
|
||||
}
|
||||
}
|
||||
|
||||
const displayedError = clientError ?? error;
|
||||
@@ -53,27 +90,47 @@ export function ImageUploadField({ id, name, label, description, error }: Props)
|
||||
return (
|
||||
<Field data-invalid={!!displayedError}>
|
||||
<FieldLabel htmlFor={id}>{label}</FieldLabel>
|
||||
<div className="flex items-center gap-4">
|
||||
{previewUrl && (
|
||||
<img
|
||||
src={previewUrl}
|
||||
alt=""
|
||||
className={cn(
|
||||
"w-16 h-16 rounded-md object-cover ring-1 ring-foreground/10 shrink-0"
|
||||
)}
|
||||
<div className="flex flex-col md:flex-row items-start gap-4">
|
||||
<div
|
||||
className={cn(
|
||||
"w-28 rounded-md border border-dashed border-foreground/15 bg-muted flex items-center justify-center overflow-hidden shrink-0",
|
||||
previewClassName ?? "aspect-4/5"
|
||||
)}
|
||||
>
|
||||
{isProcessing ? (
|
||||
<Spinner className="text-muted-foreground" />
|
||||
) : previewUrl ? (
|
||||
<img src={previewUrl} alt="" className="w-full h-full object-cover" />
|
||||
) : (
|
||||
<ImageIcon className="text-muted-foreground" size={24} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-1 flex-1 min-w-0">
|
||||
<Input
|
||||
ref={inputRef}
|
||||
id={id}
|
||||
name={name}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
aria-invalid={!!displayedError}
|
||||
onChange={handleChange}
|
||||
disabled={isProcessing}
|
||||
required={!fileInfo}
|
||||
/>
|
||||
)}
|
||||
<Input
|
||||
id={id}
|
||||
name={name}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
aria-invalid={!!displayedError}
|
||||
onChange={handleChange}
|
||||
required
|
||||
/>
|
||||
{fileInfo && (
|
||||
<div className="flex items-center gap-2 text-sm text-muted-foreground w-full min-w-0">
|
||||
<span className="flex-1 min-w-0 truncate">
|
||||
{fileInfo.name} ({formatFileSize(fileInfo.size)})
|
||||
</span>
|
||||
<Button type="button" variant="ghost" size="icon" className="h-6 w-6" onClick={reset} disabled={isProcessing}>
|
||||
<XIcon size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
<FieldDescription className="mt-1">{description}</FieldDescription>
|
||||
</div>
|
||||
</div>
|
||||
<FieldDescription>{description}</FieldDescription>
|
||||
{displayedError && <FieldError>{displayedError}</FieldError>}
|
||||
</Field>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import Footer from "@/components/footer";
|
||||
import Header from "@/components/header";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AccountMenu } from "../../account-menu";
|
||||
@@ -17,34 +15,30 @@ export default async function CitizenshipApplication() {
|
||||
const regions = await prisma.region.findMany({ orderBy: { name: "asc" } });
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<div className="flex flex-row py-16 gap-8">
|
||||
<AccountMenu />
|
||||
<div className="flex flex-col gap-8">
|
||||
<div className="flex flex-col gap-6">
|
||||
<h2>Citizenship application</h2>
|
||||
<div className="w-96 flex flex-col gap-6">
|
||||
{!eligibility.eligible ? (
|
||||
<Alert variant="warning">
|
||||
<InfoIcon />
|
||||
<AlertTitle>Cannot submit application</AlertTitle>
|
||||
<AlertDescription>{eligibility.reason}</AlertDescription>
|
||||
</Alert>
|
||||
) : (
|
||||
<CitizenshipApplicationForm
|
||||
firstName={user.firstName}
|
||||
secondName={user.secondName}
|
||||
sex={user.sex}
|
||||
birthDate={user.birthDate!}
|
||||
regions={regions}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex flex-col md:flex-row p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
||||
<AccountMenu />
|
||||
<div className="flex flex-col gap-8 w-full">
|
||||
<div className="flex flex-col gap-6">
|
||||
<h2>Citizenship application</h2>
|
||||
<div className="max-w-96 w-full flex flex-col gap-6">
|
||||
{!eligibility.eligible ? (
|
||||
<Alert variant="warning">
|
||||
<InfoIcon />
|
||||
<AlertTitle>Cannot submit application</AlertTitle>
|
||||
<AlertDescription>{eligibility.reason}</AlertDescription>
|
||||
</Alert>
|
||||
) : (
|
||||
<CitizenshipApplicationForm
|
||||
firstName={user.firstName}
|
||||
secondName={user.secondName}
|
||||
sex={user.sex}
|
||||
birthDate={user.birthDate!}
|
||||
regions={regions}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -34,11 +34,9 @@ export async function HasCitizenship({ userId }: { userId: string }) {
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-8">
|
||||
<div className="flex flex-col gap-6 md:gap-8">
|
||||
<IdentityCard data={identityDocument} />
|
||||
<div className="flex flex-col gap-2">
|
||||
<RenunciationDialog citizenship={citizenship} />
|
||||
</div>
|
||||
<RenunciationDialog citizenship={citizenship} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,13 +25,13 @@ export async function NoCitizenship({ userId }: { userId: string }) {
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-row gap-3 w-max">
|
||||
<div className="flex flex-col gap-3 w-full">
|
||||
<div className="flex flex-col md:flex-row gap-3">
|
||||
<Link href="/page/citizenship">
|
||||
<Button variant="secondary">Learn more about citizenship</Button>
|
||||
<Button variant="secondary" className="w-full">Learn more about citizenship</Button>
|
||||
</Link>
|
||||
<Link href="/account/citizenship/apply">
|
||||
<Button>Apply for citizenship</Button>
|
||||
<Button className="w-full">Apply for citizenship</Button>
|
||||
</Link>
|
||||
</div>
|
||||
{applications.length > 0 && <ApplicationsDialog applications={applications} />}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import Footer from "@/components/footer";
|
||||
import Header from "@/components/header";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AccountMenu } from "../account-menu";
|
||||
@@ -17,30 +15,26 @@ export default async function Citizenship() {
|
||||
const pendingCount = user.isAdmin ? await getPendingApplicationsCount() : 0
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<div className="flex flex-row py-16 gap-8">
|
||||
<AccountMenu />
|
||||
<div className="flex flex-col gap-8 max-w-lg">
|
||||
<div className="flex flex-col gap-6 w-min">
|
||||
<h2>Citizenship</h2>
|
||||
<div className="flex flex-col md:flex-row p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
||||
<AccountMenu />
|
||||
<div className="flex flex-col gap-8 max-w-lg">
|
||||
<div className="flex flex-col gap-6 md:w-min">
|
||||
<h2>Citizenship</h2>
|
||||
|
||||
{citizenship ? <HasCitizenship userId={user.id} /> : <NoCitizenship userId={user.id} />}
|
||||
{citizenship ? <HasCitizenship userId={user.id} /> : <NoCitizenship userId={user.id} />}
|
||||
|
||||
{user.isAdmin && (
|
||||
<Link href="/account/citizenship/review">
|
||||
<Button variant="secondary" className="w-full">
|
||||
Review citizenship applications
|
||||
<div className="flex items-center justify-center bg-black/50 text-white w-3.5 h-3.5 text-xs rounded-full">
|
||||
{pendingCount}
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
{user.isAdmin && (
|
||||
<Link href="/account/citizenship/review">
|
||||
<Button variant="secondary" className="w-full">
|
||||
Review citizenship applications
|
||||
<div className="flex items-center justify-center bg-black/50 text-white w-3.5 h-3.5 text-xs rounded-full">
|
||||
{pendingCount}
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -45,7 +45,7 @@ export function RenunciationDialog({ citizenship }: { citizenship: Citizenship }
|
||||
<DialogClose asChild>
|
||||
<Button variant="secondary">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button variant="destructive" disabled={isPending} onClick={() => run()}>
|
||||
<Button disabled={isPending} onClick={() => run()}>
|
||||
{isPending && <Spinner />}Renounce citizenship
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, D
|
||||
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";
|
||||
@@ -22,7 +23,7 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
|
||||
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">
|
||||
<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>
|
||||
)
|
||||
@@ -64,18 +65,14 @@ 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 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 && (
|
||||
@@ -110,7 +107,14 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
</div>
|
||||
<div className="flex flex-col gap-0.5">
|
||||
<p className="text-muted-foreground">Address</p>
|
||||
<p className="truncate">{application.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>
|
||||
@@ -169,7 +173,7 @@ export default function ApplicationCard({ application, onClose }: { application:
|
||||
/>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setRejectOpen(false)}>Cancel</Button>
|
||||
<Button variant="destructive" onClick={handleReject} disabled={!reason.trim() || isloading}>
|
||||
<Button onClick={handleReject} disabled={!reason.trim() || isloading}>
|
||||
{isloading && <Spinner />}Confirm rejection
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function ReviewPageClient({ applications }: { applications: Citiz
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-row gap-16">
|
||||
<div className="flex flex-col-reverse md:flex-row gap-8 md:gap-16">
|
||||
<div className="flex flex-col gap-8">
|
||||
<div className="flex flex-col gap-6">
|
||||
<h2>Review citizenship applications</h2>
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import Header from "@/components/header";
|
||||
import Footer from "@/components/footer";
|
||||
import ReviewPageClient from "./client";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
@@ -29,13 +27,9 @@ export default async function ReviewPage() {
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header />
|
||||
<div className="flex flex-row py-16 gap-8">
|
||||
<AccountMenu />
|
||||
<ReviewPageClient applications={applicationsWithWarning} />
|
||||
</div>
|
||||
<Footer />
|
||||
</>
|
||||
<div className="flex flex-col md:flex-row p-4 md:p-16 gap-8 md:gap-16 mb-4 md:mb-0">
|
||||
<AccountMenu />
|
||||
<ReviewPageClient applications={applicationsWithWarning} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user