Browse Source

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

feat/institutions_data_from_api
bobmw 5 months ago
parent
commit
0bd6188a20
  1. 16
      src/app/screens/RegisterScreen.js

16
src/app/screens/RegisterScreen.js

@ -190,6 +190,7 @@ function CityPicker({ name }) {
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([]);
@ -205,14 +206,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
@ -222,11 +223,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..."}
/> />
@ -384,7 +385,6 @@ export default function RegisterScreen(props) {
}; };
const copnfirmations = (form, actions) => { const copnfirmations = (form, actions) => {
console.log(form);
var current_mask = var current_mask =
form.number.length >= 11 ? "(99) 99999-9999" : "(99) 9999-9999"; form.number.length >= 11 ? "(99) 99999-9999" : "(99) 9999-9999";

Loading…
Cancel
Save