From 8ab07f6e509b940af4d370281833a9cd0be74055 Mon Sep 17 00:00:00 2001 From: bobmw Date: Sun, 28 Apr 2024 16:35:37 -0300 Subject: [PATCH 1/8] feat: change apis baseurl auth to authtest --- src/app/api/auth.js | 8 ++++---- src/app/auth/authClient.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/api/auth.js b/src/app/api/auth.js index a4efc18..56dccda 100644 --- a/src/app/api/auth.js +++ b/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}`); diff --git a/src/app/auth/authClient.js b/src/app/auth/authClient.js index 290703a..f532073 100644 --- a/src/app/auth/authClient.js +++ b/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}; From ada022d73f3dd5f51eff223d5817d041e9db8880 Mon Sep 17 00:00:00 2001 From: bobmw Date: Sun, 28 Apr 2024 16:36:06 -0300 Subject: [PATCH 2/8] feat: create institutions fetch --- src/app/api/fetchInstutions.js | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/app/api/fetchInstutions.js diff --git a/src/app/api/fetchInstutions.js b/src/app/api/fetchInstutions.js new file mode 100644 index 0000000..3f356d1 --- /dev/null +++ b/src/app/api/fetchInstutions.js @@ -0,0 +1,43 @@ +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 } = institution; + + if (!uf) { + uf = "DF"; + } + + if (!transformedData[uf]) { + transformedData[uf] = {}; + } + + if (!transformedData[uf][type]) { + transformedData[uf][type] = []; + } + + transformedData[uf][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; + }); +} From 649261647157c28bb6a41547fc3b7a2b6467ccfb Mon Sep 17 00:00:00 2001 From: bobmw Date: Sun, 28 Apr 2024 16:37:52 -0300 Subject: [PATCH 3/8] feat: change institutions type constants --- src/app/config/constants.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/app/config/constants.js b/src/app/config/constants.js index 5477467..bfa863b 100644 --- a/src/app/config/constants.js +++ b/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", From 9bd016c440f43c8945a39cecd344e36632348561 Mon Sep 17 00:00:00 2001 From: bobmw Date: Sun, 28 Apr 2024 16:38:49 -0300 Subject: [PATCH 4/8] feat(RegisterScreen): set getInstitutions --- src/app/screens/RegisterScreen.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/app/screens/RegisterScreen.js b/src/app/screens/RegisterScreen.js index 99f74f6..cb9d233 100644 --- a/src/app/screens/RegisterScreen.js +++ b/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 ( @@ -192,12 +192,21 @@ function InstitutionNamePicker({ name }) { const state = values["state"]; 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); insts ? setItems(insts) : setItems([]); } } catch (e) { From 1c8422c80e6b3eb24fcf99cbadcbc22da9134ab8 Mon Sep 17 00:00:00 2001 From: bobmw Date: Sun, 28 Apr 2024 16:39:14 -0300 Subject: [PATCH 5/8] feat(UpdateUserInfoScreen): set getInstitutions --- src/app/screens/UpdateUserInfoScreen.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/app/screens/UpdateUserInfoScreen.js b/src/app/screens/UpdateUserInfoScreen.js index 5794f75..891f4e7 100644 --- a/src/app/screens/UpdateUserInfoScreen.js +++ b/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,6 +18,7 @@ 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 @@ -27,6 +27,16 @@ function InstitutionNamePicker({ name }) { const state = values["state"]; 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 { @@ -123,11 +133,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 ( Date: Mon, 29 Apr 2024 15:42:08 -0300 Subject: [PATCH 6/8] feat: transform data model to includes city indicator --- src/app/api/fetchInstutions.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/app/api/fetchInstutions.js b/src/app/api/fetchInstutions.js index 3f356d1..dcb6b4f 100644 --- a/src/app/api/fetchInstutions.js +++ b/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; From 0bd6188a20766638989918ad39bc95ef09f2bc2c Mon Sep 17 00:00:00 2001 From: bobmw Date: Mon, 29 Apr 2024 15:43:29 -0300 Subject: [PATCH 7/8] feat(RegisterScreen): set institutions filter by UF, City and Type --- src/app/screens/RegisterScreen.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/app/screens/RegisterScreen.js b/src/app/screens/RegisterScreen.js index cb9d233..89deee8 100644 --- a/src/app/screens/RegisterScreen.js +++ b/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 ( @@ -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"; From c952d03a2ca8e13158e8aba63c0f979db2432535 Mon Sep 17 00:00:00 2001 From: bobmw Date: Mon, 29 Apr 2024 15:44:01 -0300 Subject: [PATCH 8/8] 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" },