9 Commits

  1. 8
      src/app/api/auth.js
  2. 51
      src/app/api/fetchInstutions.js
  3. 4
      src/app/auth/authClient.js
  4. 10
      src/app/config/constants.js
  5. 37
      src/app/screens/RegisterScreen.js
  6. 39
      src/app/screens/UpdateUserInfoScreen.js

8
src/app/api/auth.js

@ -47,7 +47,7 @@ function signup({
async function userPersonalData() {
const authToken = await authStorage.getToken();
const localClient = create({
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/users",
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/users",
});
localClient.setHeader("Authorization", `Bearer ${authToken}`);
@ -61,7 +61,7 @@ async function userActivation(code) {
// console.log("USER NAME: " + username);
const localClient = create({
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/users",
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/users",
});
localClient.setHeader("Authorization", `Bearer ${authToken}`);
@ -97,7 +97,7 @@ function loginByUsernamAnswers(username, secQuestionId, secQuestionAnswer) {
function updatePassword(authToken, username, password) {
const localClient = create({
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/forgotpasswords",
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/forgotpasswords",
});
localClient.setHeader("Authorization", `Bearer ${authToken}`);
@ -110,7 +110,7 @@ function updatePassword(authToken, username, password) {
async function UpdateUserInfo(authToken,defaultValue,formValues) {
const localClient = create({
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/users",
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/users",
});
localClient.setHeader("Authorization", `Bearer ${authToken}`);

51
src/app/api/fetchInstutions.js

@ -0,0 +1,51 @@
import { create } from "apisauce";
const fetchInstitutions = create({
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/organizations/all",
});
function transformData(institutions) {
const transformedData = {};
institutions.forEach((institution) => {
let { uf, type, name, cidade } = institution;
if (!uf) {
uf = "DF";
}
if (!cidade) {
cidade = "Brasília";
}
if (!transformedData[uf]) {
transformedData[uf] = {};
}
if (!transformedData[uf][cidade]) {
transformedData[uf][cidade] = {};
}
if (!transformedData[uf][cidade][type]) {
transformedData[uf][cidade][type] = [];
}
transformedData[uf][cidade][type].push({ value: name, label: name });
});
return transformedData;
}
export function getInstitutions() {
return fetchInstitutions.get()
.then((response) => {
if (response.ok) {
return transformData(response.data);
} else {
throw new Error("Falha ao tentar buscar instituicoes no banco de dados");
}
})
.catch((error) => {
throw error;
});
}

4
src/app/auth/authClient.js

@ -1,11 +1,11 @@
import { create } from "apisauce";
const authClient = create({
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/users",
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/users",
});
const authChangePswdClient = create({
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/auth/forgotpasswords"
baseURL: "https://wpd.brazilsouth.cloudapp.azure.com/authtest/forgotpasswords"
})
export { authClient, authChangePswdClient};

10
src/app/config/constants.js

@ -1,10 +1,10 @@
export default {
institutionMap: {
E: "Escola",
D: "Defesa Civil",
N: "Não governamental",
O: "Outra",
X: "Nenhuma",
SCHOOL: "Escola",
CIVIL_DEFENSE: "Defesa civil",
NGO: "Não governamental",
OTHER: "Outra",
X: "Nenhuma"
},
roleMap: {
ROLE_CLIENT: "Não responsável",

37
src/app/screens/RegisterScreen.js

@ -20,7 +20,6 @@ import FormDatePicker from "../components/forms/FormDatePicker";
import moment from "moment";
import SearchablePicker from "../components/SearchablePicker";
import { states, statesToCities } from "../assets/cities_states";
import institutions from "../assets/institutions";
import { useFormikContext } from "formik";
import {
signup,
@ -38,6 +37,7 @@ import CheckBox from "../components/forms/CheckBox";
import defaultStyles from "../config/styles";
import PhoneNumberFormField from "../components/forms/PhoneNumberFormField";
import { unMask, mask } from "react-native-mask-text";
import { getInstitutions } from "../api/fetchInstutions";
const phoneRegex = RegExp(
/^\(?[\(]?([0-9]{2})?\)?[)\b]?([0-9]{4,5})[-. ]?([0-9]{4})$/
@ -130,10 +130,10 @@ function GenderPicker({ name }) {
function InstitutionPicker({ name }) {
const [items, setItems] = useState([
{ value: "E", label: "Escola" },
{ value: "D", label: "Defesa civil" },
{ value: "N", label: "Não governamental" },
{ value: "O", label: "Outra" },
{ value: "SCHOOL", label: "Escola" },
{ value: "CIVIL_DEFENSE", label: "Defesa civil" },
{ value: "NGO", label: "Não governamental" },
{ value: "OTHER", label: "Outra" },
{ value: "X", label: "Nenhuma" },
]);
return (
@ -190,20 +190,30 @@ 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([]);
useEffect(() => {
getInstitutions().then((data) => {
setInstitutions(data);
})
.catch((error) => {
console.error(error);
});
}, []);
useEffect(() => {
try {
if (state && instType) {
const insts = institutions[state] && institutions[state][instType];
console.log(insts);
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
@ -213,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..."}
/>
@ -375,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";

39
src/app/screens/UpdateUserInfoScreen.js

@ -4,7 +4,6 @@ import moment from "moment";
import Screen from '../components/Screen';
import SearchablePicker from '../components/SearchablePicker';
import FormDatePicker from '../components/forms/FormDatePicker';
import institutions from "../assets/institutions";
import defaultStyles from "../config/styles";
import constants from "../config/constants";
import ConfirmationModal from '../components/ConfirmationModal';
@ -19,25 +18,37 @@ import { states, statesToCities } from "../assets/cities_states";
import PasswordFormField from "../components/forms/PasswordFormField";
import storage from "../auth/storage";
import { AuthContext } from "../auth/context";
import { getInstitutions } from "../api/fetchInstutions";
//#region PICKERS
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);
})
.catch((error) => {
console.error(error);
});
}, []);
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
@ -47,16 +58,16 @@ 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..."}
/>
);
}
}
function RolePicker({ name }) {
const [items, setItems] = useState([
@ -123,11 +134,11 @@ function CityPicker({ name }) {
function InstitutionPicker({ name }) {
const [items, setItems] = useState([
{ value: "E", label: "Escola" },
{ value: "D", label: "Defesa civil" },
{ value: "N", label: "Não governamental" },
{ value: "O", label: "Outra" },
{ value: "X", label: "Nenhuma" },
{ value: "SCHOOL", label: "Escola" },
{ value: "CIVIL_DEFENSE", label: "Defesa civil" },
{ value: "NGO", label: "Não governamental" },
{ value: "OTHER", label: "Outra" },
{ value: "X", label: "Nenhuma" }
]);
return (
<SearchablePicker

Loading…
Cancel
Save