Files
eu/app/account/citizenship/apply/form.tsx
T

318 lines
11 KiB
TypeScript

"use client";
import { useActionState, useState } from "react";
import { Button } from "@/components/ui/button";
import {
Field,
FieldContent,
FieldDescription,
FieldGroup,
FieldLabel,
FieldLegend,
FieldSet,
} from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import {
Alert,
AlertDescription,
AlertTitle,
} from "@/components/ui/alert";
import { InfoIcon } from "lucide-react";
import { submitCitizenshipApplication, type ApplicationState } from "@/lib/citizenship/actions";
import { EYE_COLORS } from "@/lib/citizenship/types";
import Link from "next/link";
import { Spinner } from "@/components/ui/spinner";
type Props = {
firstName: string;
secondName: string;
sex: string;
birthDate: Date | null;
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];
}
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 [isEuResident, setIsEuResident] = useState<boolean | null>(null);
return (
<form action={formAction}>
<FieldGroup>
<FieldSet>
<FieldLegend>Personal information</FieldLegend>
<Alert variant="warning">
<InfoIcon />
<AlertTitle>Important notice</AlertTitle>
<AlertDescription>
Personal data is sourced from your account profile. Please ensure that all information is accurate.
If corrections are required, update your details in Kotosoft ID and synchronise your account.
</AlertDescription>
</Alert>
<FieldGroup>
<Field>
<FieldLabel htmlFor="surname">Surname</FieldLabel>
<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"
/>
</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"
/>
</Field>
<Field>
<FieldLabel htmlFor="birthDate">Date of birth</FieldLabel>
<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>
<RadioGroup
name="applicationType"
value={appType}
onValueChange={(v) => setAppType(v as AppType)}
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>
<FieldDescription>
I held citizenship of the Duspean Republic or the Country of
Reality on 31 March 2026.
</FieldDescription>
</FieldContent>
</Field>
</FieldLabel>
<FieldLabel htmlFor="naturalization">
<Field orientation="horizontal">
<RadioGroupItem value="NATURALIZATION" id="naturalization" />
<FieldContent>
<span className="text-sm font-medium">Naturalisation</span>
<FieldDescription>
I am a foreign national seeking naturalisation.
</FieldDescription>
</FieldContent>
</Field>
</FieldLabel>
</RadioGroup>
</FieldSet>
{appType === "PREVIOUS_CITIZENSHIP" && (
<FieldSet>
<FieldLegend>Previous citizenship details</FieldLegend>
<FieldGroup>
<Field>
<FieldLabel htmlFor="previousCountry">Country</FieldLabel>
<Select name="previousCountry" defaultValue="">
<SelectTrigger id="previousCountry">
<SelectValue placeholder="Select country" />
</SelectTrigger>
<SelectContent>
<SelectItem value="DUS">Duspean Republic</SelectItem>
<SelectItem value="REA">Country of Reality</SelectItem>
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel htmlFor="previousRegion">Region of issuance</FieldLabel>
<Input
id="previousRegion"
name="previousRegion"
placeholder="State, region, or territory"
required
/>
<FieldDescription>
The region or authority that issued your previous citizenship.
</FieldDescription>
</Field>
</FieldGroup>
</FieldSet>
)}
{appType === "NATURALIZATION" && (
<FieldSet>
<FieldLegend>Naturalisation statement</FieldLegend>
<FieldGroup>
<Field>
<FieldLabel htmlFor="naturalizationReason">
Why do you wish to become a citizen of the European Federation?
</FieldLabel>
<Textarea
id="naturalizationReason"
name="naturalizationReason"
placeholder="Explain your motivation for seeking citizenship..."
rows={4}
required
/>
</Field>
</FieldGroup>
</FieldSet>
)}
<FieldSet>
<FieldLegend>Place of residence</FieldLegend>
<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")}
>
<Field orientation="horizontal">
<RadioGroupItem value="yes" id="eu-yes" />
<FieldLabel htmlFor="eu-yes">Yes</FieldLabel>
</Field>
<Field orientation="horizontal">
<RadioGroupItem value="no" id="eu-no" />
<FieldLabel htmlFor="eu-no">No</FieldLabel>
</Field>
</RadioGroup>
</Field>
{isEuResident === true && (
<>
<Field>
<FieldLabel htmlFor="regionId">Region</FieldLabel>
<Select name="regionId" required>
<SelectTrigger id="regionId">
<SelectValue placeholder="Select region" />
</SelectTrigger>
<SelectContent>
{regions.map((r) => (
<SelectItem key={r.id} value={r.id}>
{r.name}
</SelectItem>
))}
</SelectContent>
</Select>
</Field>
<Field>
<FieldLabel htmlFor="city">City</FieldLabel>
<Input id="city" name="city" placeholder="City or town" required />
</Field>
<Field>
<FieldLabel htmlFor="street">Street and house number</FieldLabel>
<Input id="street" name="street" placeholder="12 Via di Roma" required />
</Field>
</>
)}
{isEuResident === false && (
<Field>
<FieldLabel htmlFor="customAddress">Full address</FieldLabel>
<Input
id="customAddress"
name="customAddress"
placeholder="Street, City, Country"
required
/>
<FieldDescription>
Enter your full address as it should appear on the document.
</FieldDescription>
</Field>
)}
</FieldGroup>
</FieldSet>
<FieldSet>
<FieldLegend>Additional information</FieldLegend>
<FieldDescription>
Provide details required for your identity document.
</FieldDescription>
<FieldGroup>
<div className="grid grid-cols-2 gap-4">
<Field>
<FieldLabel htmlFor="height">Height (in cm)</FieldLabel>
<Input
id="height"
type="number"
name="height"
min={60}
max={240}
required
/>
</Field>
<Field>
<FieldLabel htmlFor="eyeColor">Eye colour</FieldLabel>
<Select name="eyeColor" defaultValue="">
<SelectTrigger id="eyeColor">
<SelectValue placeholder="Select eye colour" />
</SelectTrigger>
<SelectContent>
{EYE_COLORS.map((color) => (
<SelectItem key={color} value={color}>
{color}
</SelectItem>
))}
</SelectContent>
</Select>
</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>
)}
<Field orientation="horizontal">
<Button type="submit" disabled={isPending}>{isPending && <Spinner />}Submit application</Button>
</Field>
</FieldGroup>
</form>
);
}