feat: images upload
This commit is contained in:
@@ -15,12 +15,7 @@ const menuItems = [
|
||||
href: "/account/citizenship",
|
||||
label: "Citizenship",
|
||||
icon: BookOpenTextIcon,
|
||||
},
|
||||
{
|
||||
href: "/account/signature",
|
||||
label: "Signature",
|
||||
icon: SignatureIcon,
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
export function AccountMenu() {
|
||||
|
||||
@@ -25,37 +25,37 @@ export function ApplicationsDialog({ applications }: { applications: Citizenship
|
||||
<DialogHeader>
|
||||
<DialogTitle asChild><h3>Citizenship applications</h3></DialogTitle>
|
||||
<DialogDescription>Here are your citizenship applications</DialogDescription>
|
||||
<Accordion type="single" collapsible>
|
||||
{applications.map((application, i) => (
|
||||
<AccordionItem key={application.id} value={application.id}>
|
||||
<AccordionTrigger><h3>Application №{i + 1}</h3></AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-row gap-2 items-center text-muted-foreground">
|
||||
<PlusIcon size={16} /><p>Created on {formatDate(application.createdAt)}</p>
|
||||
</div>
|
||||
<div className={cn("flex flex-row gap-2 items-center", application.status !== "PENDING" && "text-muted-foreground")}>
|
||||
<ClockFadingIcon size={16} /><p>{application.status === "PENDING" ? "On review" : application.reviewedAt ? `Reviewed on ${formatDate(application.reviewedAt)}` : "Reviewed"}</p>
|
||||
</div>
|
||||
{application.status === "REJECTED" && (
|
||||
<div className="flex flex-col gap-0.5 mt-2">
|
||||
<div className="flex flex-row gap-2 items-center text-destructive">
|
||||
<XIcon size={16} /><p>Rejected</p>
|
||||
</div>
|
||||
<p className="text-muted-foreground">{application.rejectionReason}</p>
|
||||
</div>
|
||||
)}
|
||||
{application.status === "APPROVED" && (
|
||||
<div className="flex flex-row gap-2 items-center mt-2">
|
||||
<CheckIcon size={16} /><p>Approved</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
))}
|
||||
</Accordion>
|
||||
</DialogHeader>
|
||||
<Accordion type="single" collapsible>
|
||||
{applications.map((application, i) => (
|
||||
<AccordionItem key={application.id} value={application.id}>
|
||||
<AccordionTrigger><h3>Application №{i + 1}</h3></AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex flex-row gap-2 items-center text-muted-foreground">
|
||||
<PlusIcon size={16} /><p>Created on {formatDate(application.createdAt)}</p>
|
||||
</div>
|
||||
<div className={cn("flex flex-row gap-2 items-center", application.status !== "PENDING" && "text-muted-foreground")}>
|
||||
<ClockFadingIcon size={16} /><p>{application.status === "PENDING" ? "On review" : application.reviewedAt ? `Reviewed on ${formatDate(application.reviewedAt)}` : "Reviewed"}</p>
|
||||
</div>
|
||||
{application.status === "REJECTED" && (
|
||||
<div className="flex flex-col gap-0.5 mt-2">
|
||||
<div className="flex flex-row gap-2 items-center text-destructive">
|
||||
<XIcon size={16} /><p>Rejected</p>
|
||||
</div>
|
||||
<p className="text-muted-foreground">{application.rejectionReason}</p>
|
||||
</div>
|
||||
)}
|
||||
{application.status === "APPROVED" && (
|
||||
<div className="flex flex-row gap-2 items-center mt-2">
|
||||
<CheckIcon size={16} /><p>Approved</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
))}
|
||||
</Accordion>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useActionState, useState } from "react";
|
||||
import { useActionState, useEffect, useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Field,
|
||||
FieldContent,
|
||||
FieldDescription,
|
||||
FieldError,
|
||||
FieldGroup,
|
||||
FieldLabel,
|
||||
FieldLegend,
|
||||
@@ -21,27 +23,22 @@ import {
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
|
||||
import {
|
||||
Alert,
|
||||
AlertDescription,
|
||||
AlertTitle,
|
||||
} from "@/components/ui/alert";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { InfoIcon } from "lucide-react";
|
||||
import { submitCitizenshipApplication, type ApplicationState } from "@/lib/citizenship/actions";
|
||||
import { submitCitizenshipApplication } from "@/lib/citizenship/actions";
|
||||
import { initialFormState } from "@/lib/form-action";
|
||||
import { EYE_COLORS } from "@/lib/citizenship/types";
|
||||
import Link from "next/link";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { ImageUploadField } from "./image-upload-field";
|
||||
|
||||
type Props = {
|
||||
firstName: string;
|
||||
secondName: string;
|
||||
sex: string;
|
||||
birthDate: Date | null;
|
||||
birthDate: Date;
|
||||
regions: { id: string; name: string }[];
|
||||
};
|
||||
|
||||
const initialState: ApplicationState = { success: false, errors: [] };
|
||||
|
||||
function formatDate(d: Date | null): string {
|
||||
if (!d) return "";
|
||||
return d.toISOString().split("T")[0];
|
||||
@@ -51,9 +48,17 @@ type AppType = "PREVIOUS_CITIZENSHIP" | "NATURALIZATION";
|
||||
|
||||
export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDate, regions }: Props) {
|
||||
const [appType, setAppType] = useState<AppType | "">("");
|
||||
const [state, formAction, isPending] = useActionState(submitCitizenshipApplication, initialState);
|
||||
const [state, formAction, isPending] = useActionState(submitCitizenshipApplication, initialFormState);
|
||||
const [isEuResident, setIsEuResident] = useState<boolean | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (state.error) {
|
||||
toast.error(state.error);
|
||||
}
|
||||
}, [state.error]);
|
||||
|
||||
const errors = state.fieldErrors ?? {};
|
||||
|
||||
return (
|
||||
<form action={formAction}>
|
||||
<FieldGroup>
|
||||
@@ -70,65 +75,42 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="surname">Surname</FieldLabel>
|
||||
<Input
|
||||
id="surname"
|
||||
value={secondName}
|
||||
readOnly
|
||||
className="bg-muted text-muted-foreground"
|
||||
/>
|
||||
<Input id="surname" value={secondName} readOnly className="bg-muted text-muted-foreground" />
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="givenNames">Given names</FieldLabel>
|
||||
<Input
|
||||
id="givenNames"
|
||||
value={firstName}
|
||||
readOnly
|
||||
className="bg-muted text-muted-foreground"
|
||||
/>
|
||||
<Input id="givenNames" value={firstName} readOnly className="bg-muted text-muted-foreground" />
|
||||
</Field>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<Field>
|
||||
<FieldLabel htmlFor="sex">Sex</FieldLabel>
|
||||
<Input
|
||||
id="sex"
|
||||
value={sex === "MALE" ? "Male" : "Female"}
|
||||
readOnly
|
||||
className="bg-muted text-muted-foreground"
|
||||
/>
|
||||
<Input id="sex" value={sex === "MALE" ? "Male" : "Female"} readOnly className="bg-muted text-muted-foreground" />
|
||||
</Field>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="birthDate">Date of birth</FieldLabel>
|
||||
<Input
|
||||
id="birthDate"
|
||||
value={formatDate(birthDate)}
|
||||
readOnly
|
||||
className="bg-muted text-muted-foreground"
|
||||
/>
|
||||
<Input id="birthDate" value={formatDate(birthDate)} readOnly className="bg-muted text-muted-foreground" />
|
||||
</Field>
|
||||
</div>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
|
||||
<FieldSet>
|
||||
<FieldLegend>Eligibility basis</FieldLegend>
|
||||
<FieldDescription>
|
||||
Select the basis on which you are applying for citizenship.
|
||||
</FieldDescription>
|
||||
<FieldDescription>Select the basis on which you are applying for citizenship.</FieldDescription>
|
||||
<RadioGroup
|
||||
name="applicationType"
|
||||
value={appType}
|
||||
onValueChange={(v) => setAppType(v as AppType)}
|
||||
aria-invalid={!!errors.applicationType?.length}
|
||||
required
|
||||
>
|
||||
<FieldLabel htmlFor="prev-citizen">
|
||||
<Field orientation="horizontal">
|
||||
<RadioGroupItem value="PREVIOUS_CITIZENSHIP" id="prev-citizen" />
|
||||
<FieldContent>
|
||||
<span className="text-sm font-medium">
|
||||
Previous citizenship holder
|
||||
</span>
|
||||
<span className="text-sm font-medium">Previous citizenship holder</span>
|
||||
<FieldDescription>
|
||||
I held citizenship of the Duspean Republic or the Country of
|
||||
Reality on 31 March 2026.
|
||||
I held citizenship of the Duspean Republic or the Country of Reality on 31 March 2026.
|
||||
</FieldDescription>
|
||||
</FieldContent>
|
||||
</Field>
|
||||
@@ -138,22 +120,22 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
<RadioGroupItem value="NATURALIZATION" id="naturalization" />
|
||||
<FieldContent>
|
||||
<span className="text-sm font-medium">Naturalisation</span>
|
||||
<FieldDescription>
|
||||
I am a foreign national seeking naturalisation.
|
||||
</FieldDescription>
|
||||
<FieldDescription>I am a foreign national seeking naturalisation.</FieldDescription>
|
||||
</FieldContent>
|
||||
</Field>
|
||||
</FieldLabel>
|
||||
</RadioGroup>
|
||||
{errors.applicationType && <FieldError>{errors.applicationType[0]}</FieldError>}
|
||||
</FieldSet>
|
||||
|
||||
{appType === "PREVIOUS_CITIZENSHIP" && (
|
||||
<FieldSet>
|
||||
<FieldLegend>Previous citizenship details</FieldLegend>
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.previousCountry?.length}>
|
||||
<FieldLabel htmlFor="previousCountry">Country</FieldLabel>
|
||||
<Select name="previousCountry" defaultValue="">
|
||||
<SelectTrigger id="previousCountry">
|
||||
<SelectTrigger id="previousCountry" aria-invalid={!!errors.previousCountry?.length}>
|
||||
<SelectValue placeholder="Select country" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
@@ -161,27 +143,29 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
<SelectItem value="REA">Country of Reality</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.previousCountry && <FieldError>{errors.previousCountry[0]}</FieldError>}
|
||||
</Field>
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.previousRegion?.length}>
|
||||
<FieldLabel htmlFor="previousRegion">Region of issuance</FieldLabel>
|
||||
<Input
|
||||
id="previousRegion"
|
||||
name="previousRegion"
|
||||
placeholder="State, region, or territory"
|
||||
aria-invalid={!!errors.previousRegion?.length}
|
||||
required
|
||||
/>
|
||||
<FieldDescription>
|
||||
The region or authority that issued your previous citizenship.
|
||||
</FieldDescription>
|
||||
<FieldDescription>The region or authority that issued your previous citizenship.</FieldDescription>
|
||||
{errors.previousRegion && <FieldError>{errors.previousRegion[0]}</FieldError>}
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
)}
|
||||
|
||||
{appType === "NATURALIZATION" && (
|
||||
<FieldSet>
|
||||
<FieldLegend>Naturalisation statement</FieldLegend>
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.naturalizationReason?.length}>
|
||||
<FieldLabel htmlFor="naturalizationReason">
|
||||
Why do you wish to become a citizen of the European Federation?
|
||||
</FieldLabel>
|
||||
@@ -190,24 +174,22 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
name="naturalizationReason"
|
||||
placeholder="Explain your motivation for seeking citizenship..."
|
||||
rows={4}
|
||||
aria-invalid={!!errors.naturalizationReason?.length}
|
||||
required
|
||||
/>
|
||||
{errors.naturalizationReason && <FieldError>{errors.naturalizationReason[0]}</FieldError>}
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
)}
|
||||
|
||||
<FieldSet>
|
||||
<FieldLegend>Place of residence</FieldLegend>
|
||||
<FieldDescription>
|
||||
This will appear on your identity document.
|
||||
</FieldDescription>
|
||||
<FieldDescription>This will appear on your identity document.</FieldDescription>
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel>Is your residence in the European Federation?</FieldLabel>
|
||||
<RadioGroup
|
||||
name="isEuResident"
|
||||
onValueChange={(v) => setIsEuResident(v === "yes")}
|
||||
>
|
||||
<RadioGroup name="isEuResident" onValueChange={(v) => setIsEuResident(v === "yes")}>
|
||||
<Field orientation="horizontal">
|
||||
<RadioGroupItem value="yes" id="eu-yes" />
|
||||
<FieldLabel htmlFor="eu-yes">Yes</FieldLabel>
|
||||
@@ -221,56 +203,56 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
|
||||
{isEuResident === true && (
|
||||
<>
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.regionId?.length}>
|
||||
<FieldLabel htmlFor="regionId">Region</FieldLabel>
|
||||
<Select name="regionId" required>
|
||||
<SelectTrigger id="regionId">
|
||||
<SelectTrigger id="regionId" aria-invalid={!!errors.regionId?.length}>
|
||||
<SelectValue placeholder="Select region" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{regions.map((r) => (
|
||||
<SelectItem key={r.id} value={r.id}>
|
||||
{r.name}
|
||||
</SelectItem>
|
||||
<SelectItem key={r.id} value={r.id}>{r.name}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.regionId && <FieldError>{errors.regionId[0]}</FieldError>}
|
||||
</Field>
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.city?.length}>
|
||||
<FieldLabel htmlFor="city">City</FieldLabel>
|
||||
<Input id="city" name="city" placeholder="City or town" required />
|
||||
<Input id="city" name="city" placeholder="City or town" aria-invalid={!!errors.city?.length} required />
|
||||
{errors.city && <FieldError>{errors.city[0]}</FieldError>}
|
||||
</Field>
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.street?.length}>
|
||||
<FieldLabel htmlFor="street">Street and house number</FieldLabel>
|
||||
<Input id="street" name="street" placeholder="12 Via di Roma" required />
|
||||
<Input id="street" name="street" placeholder="12 Via di Roma" aria-invalid={!!errors.street?.length} required />
|
||||
{errors.street && <FieldError>{errors.street[0]}</FieldError>}
|
||||
</Field>
|
||||
</>
|
||||
)}
|
||||
|
||||
{isEuResident === false && (
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.customAddress?.length}>
|
||||
<FieldLabel htmlFor="customAddress">Full address</FieldLabel>
|
||||
<Input
|
||||
id="customAddress"
|
||||
name="customAddress"
|
||||
placeholder="Street, City, Country"
|
||||
aria-invalid={!!errors.customAddress?.length}
|
||||
required
|
||||
/>
|
||||
<FieldDescription>
|
||||
Enter your full address as it should appear on the document.
|
||||
</FieldDescription>
|
||||
<FieldDescription>Enter your full address as it should appear on the document.</FieldDescription>
|
||||
{errors.customAddress && <FieldError>{errors.customAddress[0]}</FieldError>}
|
||||
</Field>
|
||||
)}
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
|
||||
<FieldSet>
|
||||
<FieldLegend>Additional information</FieldLegend>
|
||||
<FieldDescription>
|
||||
Provide details required for your identity document.
|
||||
</FieldDescription>
|
||||
<FieldDescription>Provide details required for your identity document.</FieldDescription>
|
||||
<FieldGroup>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.height?.length}>
|
||||
<FieldLabel htmlFor="height">Height (in cm)</FieldLabel>
|
||||
<Input
|
||||
id="height"
|
||||
@@ -278,40 +260,54 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
name="height"
|
||||
min={60}
|
||||
max={240}
|
||||
aria-invalid={!!errors.height?.length}
|
||||
required
|
||||
/>
|
||||
{errors.height && <FieldError>{errors.height[0]}</FieldError>}
|
||||
</Field>
|
||||
<Field>
|
||||
<Field data-invalid={!!errors.eyeColor?.length}>
|
||||
<FieldLabel htmlFor="eyeColor">Eye colour</FieldLabel>
|
||||
<Select name="eyeColor" defaultValue="">
|
||||
<SelectTrigger id="eyeColor">
|
||||
<SelectTrigger id="eyeColor" aria-invalid={!!errors.eyeColor?.length}>
|
||||
<SelectValue placeholder="Select eye colour" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{EYE_COLORS.map((color) => (
|
||||
<SelectItem key={color} value={color}>
|
||||
{color}
|
||||
</SelectItem>
|
||||
<SelectItem key={color} value={color}>{color}</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{errors.eyeColor && <FieldError>{errors.eyeColor[0]}</FieldError>}
|
||||
</Field>
|
||||
</div>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
{state.errors.length > 0 && (
|
||||
<Alert className="bg-red-50 p-3 text-red-900">
|
||||
<ul className="list-disc pl-4">
|
||||
{state.errors.map((err, i) => (
|
||||
<li key={i}>{err}</li>
|
||||
))}
|
||||
</ul>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<FieldSet>
|
||||
<FieldLegend>Images</FieldLegend>
|
||||
<FieldDescription>Provide your profile image and your signature for your identity document.</FieldDescription>
|
||||
<FieldGroup>
|
||||
<ImageUploadField
|
||||
id="profile"
|
||||
name="profile"
|
||||
label="Profile"
|
||||
description="Select a profile image to upload. The image should be taken on a neutral background."
|
||||
error={errors.profile?.[0]}
|
||||
/>
|
||||
<ImageUploadField
|
||||
id="signature"
|
||||
name="signature"
|
||||
label="Signature"
|
||||
description="Select a signature to upload."
|
||||
error={errors.signature?.[0]}
|
||||
/>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
|
||||
<Field orientation="horizontal">
|
||||
<Button type="submit" disabled={isPending}>{isPending && <Spinner />}Submit application</Button>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type Props = {
|
||||
id: string;
|
||||
name: string;
|
||||
label: string;
|
||||
description: string;
|
||||
error?: string;
|
||||
};
|
||||
|
||||
export function ImageUploadField({ id, name, label, description, error }: Props) {
|
||||
const [previewUrl, setPreviewUrl] = useState<string | null>(null);
|
||||
const [clientError, setClientError] = useState<string | null>(null);
|
||||
|
||||
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];
|
||||
if (previewUrl) URL.revokeObjectURL(previewUrl);
|
||||
|
||||
if (!file) {
|
||||
setPreviewUrl(null);
|
||||
setClientError(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ACCEPTED_TYPES.includes(file.type)) {
|
||||
setClientError("Only JPEG, PNG, or WEBP images are allowed.");
|
||||
setPreviewUrl(null);
|
||||
e.target.value = "";
|
||||
return;
|
||||
}
|
||||
|
||||
if (file.size > MAX_SIZE) {
|
||||
setClientError("Image must be smaller than 5MB.");
|
||||
setPreviewUrl(null);
|
||||
e.target.value = "";
|
||||
return;
|
||||
}
|
||||
|
||||
setClientError(null);
|
||||
setPreviewUrl(URL.createObjectURL(file));
|
||||
}
|
||||
|
||||
const displayedError = clientError ?? error;
|
||||
|
||||
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"
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<Input
|
||||
id={id}
|
||||
name={name}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
aria-invalid={!!displayedError}
|
||||
onChange={handleChange}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<FieldDescription>{description}</FieldDescription>
|
||||
{displayedError && <FieldError>{displayedError}</FieldError>}
|
||||
</Field>
|
||||
);
|
||||
}
|
||||
@@ -4,17 +4,16 @@ import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AccountMenu } from "../../account-menu";
|
||||
import { CitizenshipApplicationForm } from "./form";
|
||||
import { getUserApplications } from "@/lib/citizenship/repository";
|
||||
import { getApplicationEligibility } from "@/lib/citizenship/repository";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { InfoIcon } from "lucide-react";
|
||||
|
||||
export default async function CitizenshipApplication() {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) redirect("/");
|
||||
|
||||
const applications = await getUserApplications(user.id);
|
||||
const canApply = applications.length === 0 || applications.every((a) => a.status === "REJECTED");
|
||||
if (!canApply) redirect("/account/citizenship");
|
||||
|
||||
const eligibility = await getApplicationEligibility(user.id, user.birthDate);
|
||||
const regions = await prisma.region.findMany({ orderBy: { name: "asc" } });
|
||||
|
||||
return (
|
||||
@@ -26,13 +25,21 @@ export default async function CitizenshipApplication() {
|
||||
<div className="flex flex-col gap-6">
|
||||
<h2>Citizenship application</h2>
|
||||
<div className="w-96 flex flex-col gap-6">
|
||||
<CitizenshipApplicationForm
|
||||
firstName={user.firstName}
|
||||
secondName={user.secondName}
|
||||
sex={user.sex}
|
||||
birthDate={user.birthDate}
|
||||
regions={regions}
|
||||
/>
|
||||
{!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>
|
||||
@@ -40,4 +47,4 @@ export default async function CitizenshipApplication() {
|
||||
<Footer />
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import IdentityCard from "@/components/identity-card";
|
||||
import { getIdentityCardData } from "@/lib/id/repository";
|
||||
import { TriangleAlertIcon } from "lucide-react";
|
||||
import { RenunciationDialog } from "./renunciation-dialog";
|
||||
import { getActiveCitizenship } from "@/lib/citizenship/repository";
|
||||
|
||||
export async function HasCitizenship({ userId }: { userId: string }) {
|
||||
const identityDocument = await getIdentityCardData(userId);
|
||||
const citizenship = await getActiveCitizenship(userId);
|
||||
|
||||
if (!identityDocument) {
|
||||
return (
|
||||
<Alert variant="warning">
|
||||
<TriangleAlertIcon />
|
||||
<AlertTitle>Identity document unavailable</AlertTitle>
|
||||
<AlertDescription>
|
||||
Your citizenship record exists, but no identity document was found. Contact the competent authority.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
if (!citizenship) {
|
||||
return (
|
||||
<Alert variant="warning">
|
||||
<TriangleAlertIcon />
|
||||
<AlertTitle>Citizenship record unavailable</AlertTitle>
|
||||
<AlertDescription>
|
||||
We couldn't verify your active citizenship record. Contact the competent authority.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-8">
|
||||
<IdentityCard data={identityDocument} />
|
||||
<div className="flex flex-col gap-2">
|
||||
<RenunciationDialog citizenship={citizenship} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { InfoIcon } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from "@/components/ui/accordion";
|
||||
import { ApplicationsDialog } from "./applications-dialog";
|
||||
import { getUserApplications } from "@/lib/citizenship/repository";
|
||||
|
||||
export async function NoCitizenship({ userId }: { userId: string }) {
|
||||
const applications = await getUserApplications(userId);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-6">
|
||||
<Alert variant="warning">
|
||||
<InfoIcon />
|
||||
<AlertTitle>You are not a citizen of the European Federation</AlertTitle>
|
||||
<AlertDescription>
|
||||
You currently hold non-citizen status. Certain civic services and
|
||||
identity documents are available only to citizens of the European Federation.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-row gap-3 w-max">
|
||||
<Link href="/page/citizenship">
|
||||
<Button variant="secondary">Learn more about citizenship</Button>
|
||||
</Link>
|
||||
<Link href="/account/citizenship/apply">
|
||||
<Button>Apply for citizenship</Button>
|
||||
</Link>
|
||||
</div>
|
||||
{applications.length > 0 && <ApplicationsDialog applications={applications} />}
|
||||
</div>
|
||||
|
||||
<Accordion type="single" collapsible>
|
||||
<AccordionItem value="eligibility">
|
||||
<AccordionTrigger><h4>Who is eligible for citizenship?</h4></AccordionTrigger>
|
||||
<AccordionContent>
|
||||
Citizenship may be granted to persons born in the European
|
||||
Federation, the former Duspean Republic, or the Country of Reality,
|
||||
as well as to individuals who held citizenship of the Duspean
|
||||
Republic or the Country of Reality on 31 March 2026.
|
||||
<br /><br />
|
||||
Foreign nationals who demonstrate a commitment to the development,
|
||||
prosperity, and values of the European Federation may also be
|
||||
eligible for naturalisation under federal law.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="rights">
|
||||
<AccordionTrigger><h4>What rights does citizenship provide?</h4></AccordionTrigger>
|
||||
<AccordionContent>
|
||||
Citizens enjoy all rights and protections guaranteed by the
|
||||
Constitution and laws of the European Federation, including the
|
||||
right to obtain federal identity documents, participate in federal
|
||||
elections, and receive protection from federal authorities.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="documents">
|
||||
<AccordionTrigger><h4>What documents are required?</h4></AccordionTrigger>
|
||||
<AccordionContent>
|
||||
Applicants may be asked to provide proof of
|
||||
residence in the European Federation, evidence of eligibility, and any additional documents
|
||||
required by the competent authority.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="processing">
|
||||
<AccordionTrigger><h4>How long does the application process take?</h4></AccordionTrigger>
|
||||
<AccordionContent>
|
||||
Processing times vary depending on the complexity of the
|
||||
application and the volume of requests currently under review.
|
||||
Applicants can track the status of their application through their
|
||||
account.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="dual">
|
||||
<AccordionTrigger><h4>Is dual citizenship permitted?</h4></AccordionTrigger>
|
||||
<AccordionContent>
|
||||
The European Federation generally permits dual citizenship unless
|
||||
otherwise restricted by federal law or international agreements.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -3,41 +3,18 @@ import Header from "@/components/header";
|
||||
import { getCurrentUser } from "@/lib/user";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AccountMenu } from "../account-menu";
|
||||
import { InfoIcon } from "lucide-react";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import Link from "next/link";
|
||||
import {
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionItem,
|
||||
AccordionTrigger,
|
||||
} from "@/components/ui/accordion";
|
||||
import { ApplicationsDialog } from "./applications-dialog";
|
||||
import { getPendingApplicationsCount, getUserApplications } from "@/lib/citizenship/repository";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { CitizenshipApplication } from "@/lib/citizenship/types";
|
||||
import { getIdentityCardData, IdentityCardData } from "@/lib/id/repository";
|
||||
import IdCard from "@/components/id-card";
|
||||
import { getPendingApplicationsCount, getActiveCitizenship } from "@/lib/citizenship/repository";
|
||||
import { HasCitizenship } from "./has-citizenship";
|
||||
import { NoCitizenship } from "./no-citizenship";
|
||||
|
||||
export default async function Citizenship() {
|
||||
const user = await getCurrentUser()
|
||||
if (!user) redirect("/")
|
||||
|
||||
const citizenship = await prisma.citizenship.findUnique({ where: { userId: user.id } })
|
||||
|
||||
let applications: CitizenshipApplication[] = []
|
||||
let pendingCount = 0
|
||||
let identityDocument: IdentityCardData | null = null
|
||||
|
||||
if (citizenship) {
|
||||
identityDocument = await getIdentityCardData(user.id)
|
||||
} else {
|
||||
applications = await getUserApplications(user.id)
|
||||
if (user.isAdmin) {
|
||||
pendingCount = await getPendingApplicationsCount()
|
||||
}
|
||||
}
|
||||
const citizenship = await getActiveCitizenship(user.id)
|
||||
const pendingCount = user.isAdmin ? await getPendingApplicationsCount() : 0
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -47,103 +24,18 @@ export default async function Citizenship() {
|
||||
<div className="flex flex-col gap-8 max-w-lg">
|
||||
<div className="flex flex-col gap-6 w-min">
|
||||
<h2>Citizenship</h2>
|
||||
{citizenship ? (
|
||||
<div className="flex flex-col gap-8">
|
||||
<IdCard data={identityDocument} />
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col gap-6 w-min">
|
||||
<Alert variant="warning">
|
||||
<InfoIcon />
|
||||
<AlertTitle>You are not a citizen of the European Federation</AlertTitle>
|
||||
<AlertDescription>
|
||||
You currently hold non-citizen status. Certain civic services and
|
||||
identity documents are available only to citizens of the European Federation.
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
<div className="flex flex-col gap-3">
|
||||
<div className="flex flex-row gap-3 w-max">
|
||||
<Link href="/page/citizenship">
|
||||
<Button variant="secondary">Learn more about citizenship</Button>
|
||||
</Link>
|
||||
<Link href="/account/citizenship/apply">
|
||||
<Button>Apply for citizenship</Button>
|
||||
</Link>
|
||||
|
||||
{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>
|
||||
{applications.length > 0 && (
|
||||
<ApplicationsDialog applications={applications} />
|
||||
)}
|
||||
{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>
|
||||
<Accordion type="single" collapsible>
|
||||
<AccordionItem value="eligibility">
|
||||
<AccordionTrigger>
|
||||
<h4>Who is eligible for citizenship?</h4>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
Citizenship may be granted to persons born in the European
|
||||
Federation, the former Duspean Republic, or the Country of Reality,
|
||||
as well as to individuals who held citizenship of the Duspean
|
||||
Republic or the Country of Reality on 31 March 2026.
|
||||
<br />
|
||||
<br />
|
||||
Foreign nationals who demonstrate a commitment to the development,
|
||||
prosperity, and values of the European Federation may also be
|
||||
eligible for naturalisation under federal law.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="rights">
|
||||
<AccordionTrigger>
|
||||
<h4>What rights does citizenship provide?</h4>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
Citizens enjoy all rights and protections guaranteed by the
|
||||
Constitution and laws of the European Federation, including the
|
||||
right to obtain federal identity documents, participate in federal
|
||||
elections, and receive protection from federal authorities.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="documents">
|
||||
<AccordionTrigger>
|
||||
<h4>What documents are required?</h4>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
Applicants may be asked to provide proof of
|
||||
residence in the European Federation, evidence of eligibility, and any additional documents
|
||||
required by the competent authority.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="processing">
|
||||
<AccordionTrigger>
|
||||
<h4>How long does the application process take?</h4>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
Processing times vary depending on the complexity of the
|
||||
application and the volume of requests currently under review.
|
||||
Applicants can track the status of their application through their
|
||||
account.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
<AccordionItem value="dual">
|
||||
<AccordionTrigger>
|
||||
<h4>Is dual citizenship permitted?</h4>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
The European Federation generally permits dual citizenship unless
|
||||
otherwise restricted by federal law or international agreements.
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
</Button>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import {
|
||||
Dialog,
|
||||
DialogClose,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import { useAction } from "@/hooks/useAction";
|
||||
import { renounceCitizenship } from "@/lib/citizenship/actions";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
|
||||
type Citizenship = {
|
||||
id: string;
|
||||
userId: string;
|
||||
issuedAt: Date;
|
||||
};
|
||||
|
||||
export function RenunciationDialog({ citizenship }: { citizenship: Citizenship }) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const { run, isPending } = useAction(renounceCitizenship, {
|
||||
successMessage: "Citizenship renounced",
|
||||
onSuccess: () => setOpen(false),
|
||||
});
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild><Button variant="secondary">Renunciation of citizenship</Button></DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle asChild><h3>Renunciation of citizenship</h3></DialogTitle>
|
||||
<DialogDescription>
|
||||
This action is permanent and cannot be undone. If you continue, you will lose your citizenship of the European Federation, along with all associated rights and obligations.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<p>You are about to permanently renounce your citizenship of the European Federation, issued on {formatDate(citizenship.issuedAt)}.</p>
|
||||
<DialogFooter>
|
||||
<DialogClose asChild>
|
||||
<Button variant="secondary">Cancel</Button>
|
||||
</DialogClose>
|
||||
<Button variant="destructive" disabled={isPending} onClick={() => run()}>
|
||||
{isPending && <Spinner />}Renounce citizenship
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
@@ -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 (
|
||||
<>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { useTransition } from "react";
|
||||
import {
|
||||
Dialog, DialogClose, DialogContent, DialogDescription,
|
||||
DialogFooter, DialogHeader, DialogTitle, DialogTrigger,
|
||||
@@ -8,9 +7,10 @@ import {
|
||||
import { deleteUserAction } from "@/lib/user/actions";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { useAction } from "@/hooks/useAction";
|
||||
|
||||
export function DeleteDialog({ userId }: { userId: string }) {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
export function DeleteDialog() {
|
||||
const { run, isPending } = useAction(deleteUserAction);
|
||||
|
||||
return (
|
||||
<Dialog>
|
||||
@@ -33,7 +33,7 @@ export function DeleteDialog({ userId }: { userId: string }) {
|
||||
</DialogClose>
|
||||
<Button
|
||||
disabled={isPending}
|
||||
onClick={() => startTransition(() => deleteUserAction(userId))}
|
||||
onClick={() => run()}
|
||||
>
|
||||
{isPending && <Spinner />}Delete
|
||||
</Button>
|
||||
|
||||
@@ -1,19 +1,14 @@
|
||||
"use client";
|
||||
|
||||
import { useTransition } from "react";
|
||||
import { useAction } from "@/hooks/useAction";
|
||||
import { logout } from "@/lib/user/actions";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { logout } from "@/lib/user/actions";
|
||||
|
||||
export function LogoutButton() {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const { run, isPending } = useAction(logout);
|
||||
return (
|
||||
<Button
|
||||
variant="secondary"
|
||||
disabled={isPending}
|
||||
onClick={() => startTransition(() => logout())}
|
||||
>
|
||||
<Button variant="secondary" disabled={isPending} onClick={() => run()}>
|
||||
{isPending && <Spinner />}Log out
|
||||
</Button>
|
||||
);
|
||||
|
||||
@@ -64,7 +64,7 @@ export default async function Account() {
|
||||
<h4>Delete account</h4>
|
||||
<p className="text-muted-foreground">Permanently delete your account and all associated data</p>
|
||||
</div>
|
||||
<DeleteDialog userId={user.id} />
|
||||
<DeleteDialog />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,29 +1,13 @@
|
||||
"use client";
|
||||
|
||||
import { useTransition } from "react";
|
||||
import { useAction } from "@/hooks/useAction";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { toast } from "sonner";
|
||||
import { updateUserAction } from "@/lib/user/actions";
|
||||
|
||||
export function UpdateButton() {
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const { run, isPending } = useAction(updateUserAction, { successMessage: "Profile updated" });
|
||||
return (
|
||||
<Button
|
||||
variant="secondary"
|
||||
disabled={isPending}
|
||||
onClick={() =>
|
||||
startTransition(async () => {
|
||||
try {
|
||||
await updateUserAction();
|
||||
toast.success("Profile updated");
|
||||
} catch {
|
||||
toast.error("Failed to update profile. Your session may have expired. Try signing in again.");
|
||||
}
|
||||
})
|
||||
}
|
||||
>
|
||||
<Button variant="secondary" disabled={isPending} onClick={() => run()}>
|
||||
{isPending && <Spinner />}Update
|
||||
</Button>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user