feat: citizenship built
This commit is contained in:
@@ -37,6 +37,7 @@ type Props = {
|
||||
secondName: string;
|
||||
sex: string;
|
||||
birthDate: Date | null;
|
||||
regions: { id: string; name: string }[];
|
||||
};
|
||||
|
||||
const initialState: ApplicationState = { success: false, errors: [] };
|
||||
@@ -46,18 +47,19 @@ function formatDate(d: Date | null): string {
|
||||
return d.toISOString().split("T")[0];
|
||||
}
|
||||
|
||||
type AppType = "PREVIOUS_CITIZENSHIP" | "BORN_IN_TERRITORY" | "NATURALIZATION";
|
||||
type AppType = "PREVIOUS_CITIZENSHIP" | "NATURALIZATION";
|
||||
|
||||
export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDate }: Props) {
|
||||
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 className="border-amber-200 bg-amber-50 text-amber-900">
|
||||
<Alert variant="warning">
|
||||
<InfoIcon />
|
||||
<AlertTitle>Important notice</AlertTitle>
|
||||
<AlertDescription>
|
||||
@@ -131,18 +133,6 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
</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" />
|
||||
@@ -181,26 +171,7 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
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>.
|
||||
The region or authority that issued your previous citizenship.
|
||||
</FieldDescription>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
@@ -225,24 +196,79 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
</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>
|
||||
<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>
|
||||
@@ -274,16 +300,16 @@ export function CitizenshipApplicationForm({ firstName, secondName, sex, birthDa
|
||||
</FieldGroup>
|
||||
</FieldSet>
|
||||
{state.errors.length > 0 && (
|
||||
<div className="rounded-lg border border-red-200 bg-red-50 p-3 text-sm text-red-900">
|
||||
<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>
|
||||
</div>
|
||||
</Alert>
|
||||
)}
|
||||
<Field orientation="horizontal">
|
||||
<Button type="submit">{isPending && <Spinner />}Submit application</Button>
|
||||
<Button type="submit" disabled={isPending}>{isPending && <Spinner />}Submit application</Button>
|
||||
</Field>
|
||||
</FieldGroup>
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user