From c952d03a2ca8e13158e8aba63c0f979db2432535 Mon Sep 17 00:00:00 2001 From: bobmw Date: Mon, 29 Apr 2024 15:44:01 -0300 Subject: [PATCH] feat(UpdateUserInfoScreen): set institutions filter by UF, City and Type --- src/app/screens/UpdateUserInfoScreen.js | 57 +++++++++++++------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/app/screens/UpdateUserInfoScreen.js b/src/app/screens/UpdateUserInfoScreen.js index 891f4e7..c5b2d32 100644 --- a/src/app/screens/UpdateUserInfoScreen.js +++ b/src/app/screens/UpdateUserInfoScreen.js @@ -25,10 +25,11 @@ 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([]); - + useEffect(() => { getInstitutions().then((data) => { setInstitutions(data); @@ -37,37 +38,37 @@ function InstitutionNamePicker({ name }) { console.error(error); }); }, []); - + 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 ( - + ); -} - + } + function RolePicker({ name }) { const [items, setItems] = useState([ { value: "ROLE_INSTITUTION", label: "Responsável" },