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. 15
      src/app/screens/UpdateUserInfoScreen.js

15
src/app/screens/UpdateUserInfoScreen.js

@ -25,6 +25,7 @@ import { getInstitutions } from "../api/fetchInstutions";
function InstitutionNamePicker({ name }) { function InstitutionNamePicker({ name }) {
const { values } = useFormikContext(); const { values } = useFormikContext();
const state = values["state"]; const state = values["state"];
const city = values["city"];
const instType = values["institution"]; const instType = values["institution"];
const [items, setItems] = useState([]); const [items, setItems] = useState([]);
const [institutions, setInstitutions] = useState([]); const [institutions, setInstitutions] = useState([]);
@ -40,14 +41,14 @@ function InstitutionNamePicker({ name }) {
useEffect(() => { useEffect(() => {
try { try {
if (state && instType) {
const insts = institutions[state] && institutions[state][instType];
if (state && city && instType) {
const insts = institutions[state] && institutions[state][city] && institutions[state][city][instType];
insts ? setItems(insts) : setItems([]); insts ? setItems(insts) : setItems([]);
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
}, [state, instType]);
}, [state,city, instType, institutions]);
return ( return (
<SearchablePicker <SearchablePicker
@ -57,11 +58,11 @@ function InstitutionNamePicker({ name }) {
formPlaceholder={"Selecione o nome da instituição"} formPlaceholder={"Selecione o nome da instituição"}
doubleItemLine={true} doubleItemLine={true}
nothingToShow={ nothingToShow={
institutions?.state?.instType
institutions?.state?.city?.instType
? "Não encontramos nada com esse termo" ? "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"
: (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..."} searchPlaceholder={"Busca..."}
/> />

Loading…
Cancel
Save