@@ -19,7 +19,7 @@ const emptyTerritoryPath: TerritoryOption[] = [];
|
||||
export function ProvinceSelect({
|
||||
value,
|
||||
onChange,
|
||||
endpoint = '/api/v1/catalogs/jurisdictions',
|
||||
endpoint = '/api/v1/investment/territory-options',
|
||||
placeholder = 'Seleccione uma província',
|
||||
className = control,
|
||||
label = 'Província',
|
||||
@@ -107,7 +107,7 @@ export function ProvinceSelect({
|
||||
export function TerritoryFields({
|
||||
initial = emptyTerritoryPath,
|
||||
onChange,
|
||||
endpoint = '/api/v1/catalogs/jurisdictions',
|
||||
endpoint = '/api/v1/investment/territory-options',
|
||||
}: {
|
||||
initial?: TerritoryOption[];
|
||||
onChange?: (path: TerritoryOption[]) => void;
|
||||
@@ -174,7 +174,9 @@ export function TerritoryLevel({
|
||||
const [error, setError] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [retry, setRetry] = useState(0);
|
||||
const [search, setSearch] = useState('');
|
||||
const enabled = index === 0 || Boolean(parent);
|
||||
useEffect(() => { setPage(1); setSearch(''); }, [parent, index]);
|
||||
useEffect(() => {
|
||||
setOptions([]);
|
||||
setMore(false);
|
||||
@@ -189,6 +191,7 @@ export function TerritoryLevel({
|
||||
type: levels[index],
|
||||
parent_id: parent,
|
||||
page: String(page),
|
||||
q: search,
|
||||
});
|
||||
const response = await fetch(`${endpoint}?${params}`, {
|
||||
signal: controller.signal,
|
||||
@@ -215,12 +218,13 @@ export function TerritoryLevel({
|
||||
clearTimeout(timer);
|
||||
controller.abort();
|
||||
};
|
||||
}, [index, parent, page, enabled, endpoint, retry]);
|
||||
}, [index, parent, page, enabled, endpoint, retry, search]);
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<label htmlFor={id} className="font-medium">
|
||||
{labels[index]}
|
||||
</label>
|
||||
<input className={control} aria-label={`Pesquisar ${labels[index]}`} disabled={!enabled} maxLength={100} value={search} onChange={(event) => { setSearch(event.target.value); setPage(1); }} placeholder={`Pesquisar ${labels[index].toLowerCase()}`} />
|
||||
<select
|
||||
id={id}
|
||||
aria-invalid={Boolean(fieldError)}
|
||||
|
||||
Reference in New Issue
Block a user