58 lines
2.3 KiB
TypeScript
58 lines
2.3 KiB
TypeScript
import { useState } from 'react';
|
|
import { AdministrativeLocation } from '@/components/administrative-location';
|
|
import type {
|
|
GeographyReference,
|
|
GeographyDescription,
|
|
} from '@/components/administrative-location';
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
export function CandidateLocationPicker({
|
|
companyId,
|
|
apply,
|
|
label = 'Escolher a disponibilidade principal no catálogo',
|
|
}: {
|
|
companyId: number;
|
|
label?: string;
|
|
apply: (
|
|
reference: GeographyReference,
|
|
location: { province: string; district: string; locality: string },
|
|
) => void;
|
|
}) {
|
|
const [selection, setSelection] = useState<GeographyReference | null>(null);
|
|
const [description, setDescription] = useState<GeographyDescription>(null);
|
|
const province = description?.path.find((node) => node.level === 1)?.name;
|
|
const district = description?.path.find((node) => node.level === 2)?.name;
|
|
const locality = description?.path.find((node) => node.level === 4)?.name;
|
|
return (
|
|
<details className="space-y-3 rounded-lg border p-4">
|
|
<summary className="cursor-pointer font-medium">{label}</summary>
|
|
<AdministrativeLocation
|
|
endpoint={`/candidaturas/${companyId}/divisao-administrativa`}
|
|
maxLevel={4}
|
|
value={selection}
|
|
onChange={(value, detail) => {
|
|
setSelection(value);
|
|
setDescription(detail ?? null);
|
|
}}
|
|
legend="Local de disponibilidade"
|
|
hint="Complete o percurso até à localidade. Ao aplicar, os três campos de disponibilidade serão preenchidos com as designações da fonte."
|
|
/>
|
|
<Button
|
|
type="button"
|
|
variant="outline"
|
|
disabled={!selection || !province || !district || !locality}
|
|
onClick={() => {
|
|
if (selection && province && district && locality)
|
|
apply(selection, { province, district, locality });
|
|
}}
|
|
>
|
|
Usar esta localidade
|
|
</Button>
|
|
<p className="text-sm text-muted-foreground">
|
|
O preenchimento manual continua disponível para locais ausentes,
|
|
estrangeiros ou pendentes de revisão.
|
|
</p>
|
|
</details>
|
|
);
|
|
}
|