3 Commits

  1. 16
      src/app/api/fetchInstutions.js
  2. 16
      src/app/screens/RegisterScreen.js
  3. 15
      src/app/screens/UpdateUserInfoScreen.js

16
src/app/api/fetchInstutions.js

@ -8,21 +8,29 @@ function transformData(institutions) {
const transformedData = {};
institutions.forEach((institution) => {
let { uf, type, name } = institution;
let { uf, type, name, cidade } = institution;
if (!uf) {
uf = "DF";
}
if (!cidade) {
cidade = "Brasília";
}
if (!transformedData[uf]) {
transformedData[uf] = {};
}
if (!transformedData[uf][type]) {
transformedData[uf][type] = [];
if (!transformedData[uf][cidade]) {
transformedData[uf][cidade] = {};
}
if (!transformedData[uf][cidade][type]) {
transformedData[uf][cidade][type] = [];
}
transformedData[uf][type].push({ value: name, label: name });
transformedData[uf][cidade][type].push({ value: name, label: name });
});
return transformedData;

16
src/app/screens/RegisterScreen.js

@ -190,6 +190,7 @@ function CityPicker({ name }) {
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([]);
@ -205,14 +206,14 @@ function InstitutionNamePicker({ name }) {
useEffect(() => {
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([]);
}
} catch (e) {
console.log(e);
}
}, [state, instType]);
}, [state,city, instType, institutions]);
return (
<SearchablePicker
@ -222,11 +223,11 @@ function InstitutionNamePicker({ name }) {
formPlaceholder={"Selecione o nome da instituição"}
doubleItemLine={true}
nothingToShow={
institutions?.state?.instType
institutions?.state?.city?.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"
: (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..."}
/>
@ -384,7 +385,6 @@ export default function RegisterScreen(props) {
};
const copnfirmations = (form, actions) => {
console.log(form);
var current_mask =
form.number.length >= 11 ? "(99) 99999-9999" : "(99) 9999-9999";

15
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([]);
@ -40,14 +41,14 @@ function InstitutionNamePicker({ name }) {
useEffect(() => {
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([]);
}
} catch (e) {
console.log(e);
}
}, [state, instType]);
}, [state,city, instType, institutions]);
return (
<SearchablePicker
@ -57,11 +58,11 @@ function InstitutionNamePicker({ name }) {
formPlaceholder={"Selecione o nome da instituição"}
doubleItemLine={true}
nothingToShow={
institutions?.state?.instType
institutions?.state?.city?.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"
: (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..."}
/>

Loading…
Cancel
Save