Browse Source

feat(UpdateUserInfoScreen): set institutions filter by UF, City and Type

feat/institutions_data_from_api
bobmw 5 months ago
parent
commit
c952d03a2c
  1. 49
      src/app/screens/UpdateUserInfoScreen.js

49
src/app/screens/UpdateUserInfoScreen.js

@ -25,6 +25,7 @@ import { getInstitutions } from "../api/fetchInstutions";
function InstitutionNamePicker({ name }) {
const { values } = useFormikContext();
const state = values["state"];
const city = values["city"];
const instType = values["institution"];
const [items, setItems] = useState([]);
const [institutions, setInstitutions] = useState([]);
@ -39,34 +40,34 @@ function InstitutionNamePicker({ name }) {
}, []);
useEffect(() => {
try {
if (state && instType) {
const insts = institutions[state] && institutions[state][instType];
insts ? setItems(insts) : setItems([]);
}
} catch (e) {
console.log(e);
try {
if (state && city && instType) {
const insts = institutions[state] && institutions[state][city] && institutions[state][city][instType];
insts ? setItems(insts) : setItems([]);
}
}, [state, instType]);
} catch (e) {
console.log(e);
}
}, [state,city, instType, institutions]);
return (
<SearchablePicker
name={name}
items={items}
setItems={setItems}
formPlaceholder={"Selecione o nome da instituição"}
doubleItemLine={true}
nothingToShow={
institutions?.state?.instType
? "Não encontramos nada com esse termo"
: state && instType
? `Nenhuma instituição do tipo ${constants.institutionMap[instType]} no ${constants.statesMap[state]}`
: "Selecione o Estado e o tipo da instituição primeiro"
}
searchPlaceholder={"Busca..."}
/>
<SearchablePicker
name={name}
items={items}
setItems={setItems}
formPlaceholder={"Selecione o nome da instituição"}
doubleItemLine={true}
nothingToShow={
institutions?.state?.city?.instType
? "Não encontramos nada com esse termo"
: (state && instType) || state || instType
? "Selecione uma cidade"
: state && instType && city ? `Nenhuma instituição do tipo ${constants.institutionMap[instType]} em ${city} (${constants.statesMap[state]})` : "Selecione o Estado, Cidade e o tipo da instituição primeiro"
}
searchPlaceholder={"Busca..."}
/>
);
}
}
function RolePicker({ name }) {
const [items, setItems] = useState([

Loading…
Cancel
Save