feat: citizenship applications
This commit is contained in:
@@ -0,0 +1,291 @@
|
||||
"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;
|
||||
};
|
||||
|
||||
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" | "BORN_IN_TERRITORY" | "NATURALIZATION";
|
||||
|
||||
export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDate }: Props) {
|
||||
const [appType, setAppType] = useState<AppType | "">("");
|
||||
const [state, formAction, isPending] = useActionState(submitCitizenshipApplication, initialState);
|
||||
|
||||
return (
|
||||
<form action={formAction}>
|
||||
<FieldGroup>
|
||||
<FieldSet>
|
||||
<FieldLegend>Personal information</FieldLegend>
|
||||
<Alert className="border-amber-200 bg-amber-50 text-amber-900">
|
||||
<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="born-territory">
|
||||
<Field orientation="horizontal">
|
||||
<RadioGroupItem value="BORN_IN_TERRITORY" id="born-territory" />
|
||||
<FieldContent>
|
||||
<span className="text-sm font-medium">Born in territory</span>
|
||||
<FieldDescription>
|
||||
I was born in the European Federation, the former Duspean
|
||||
Republic, or the Country of Reality, and do not hold citizenship.
|
||||
</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. The list of regions is <Link href="/page/regions">here</Link>.
|
||||
</FieldDescription>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
)}
|
||||
{appType === "BORN_IN_TERRITORY" && (
|
||||
<FieldSet>
|
||||
<FieldLegend>Birth details</FieldLegend>
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="birthRegion">Region of birth</FieldLabel>
|
||||
<Input
|
||||
id="birthRegion"
|
||||
name="birthRegion"
|
||||
placeholder="City, Region, Country"
|
||||
required
|
||||
/>
|
||||
<FieldDescription>
|
||||
The municipality, region, and country where you were born. The list of regions is <Link href="/page/regions">here</Link>.
|
||||
</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>Additional information</FieldLegend>
|
||||
<FieldDescription>
|
||||
Provide details required for your identity document.
|
||||
</FieldDescription>
|
||||
<FieldGroup>
|
||||
<Field>
|
||||
<FieldLabel htmlFor="address">Current address</FieldLabel>
|
||||
<Input
|
||||
id="address"
|
||||
name="address"
|
||||
placeholder="Street, City, Region"
|
||||
required
|
||||
/>
|
||||
<FieldDescription>
|
||||
Your current place of residence.
|
||||
</FieldDescription>
|
||||
</Field>
|
||||
<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 && (
|
||||
<div className="rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-900">
|
||||
<ul className="list-disc pl-4">
|
||||
{state.errors.map((err, i) => (
|
||||
<li key={i}>{err}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
<Field orientation="horizontal">
|
||||
<Button type="submit">{isPending && <Spinner />}Submit application</Button>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user