From 4739d74078fd799003e461e2364552e3fd5bf417 Mon Sep 17 00:00:00 2001 From: Hope Tambala Date: Mon, 30 Nov 2020 22:10:58 -0500 Subject: [PATCH] fix: incorrect usage of current async function --- domains/Auth/PinCode/GetPinCode/index.js | 4 ++-- domains/Auth/SignIn/index.js | 4 ++-- domains/Auth/StoreOrganization/index.js | 18 -------------- .../Forms/IdentificationForm/index.js | 24 ++++--------------- services/parse/auth/index.js | 12 +++++++++- 5 files changed, 20 insertions(+), 42 deletions(-) delete mode 100644 domains/Auth/StoreOrganization/index.js diff --git a/domains/Auth/PinCode/GetPinCode/index.js b/domains/Auth/PinCode/GetPinCode/index.js index c65ba8de9..7294b6588 100644 --- a/domains/Auth/PinCode/GetPinCode/index.js +++ b/domains/Auth/PinCode/GetPinCode/index.js @@ -4,7 +4,7 @@ import { Text, Button } from 'react-native-paper'; import { Formik } from 'formik'; import FormInput from '../../../../components/FormikFields/FormInput'; import { storeData, getData, deleteData } from '../../../../modules/async-storage'; -import { retrieveSignInFunction, retrieveCurrentUserFunction } from '../../../../services/parse/auth'; +import { retrieveSignInFunction, retrieveCurrentUserAsyncFunction } from '../../../../services/parse/auth'; import I18n from '../../../../modules/i18n'; const GetPinCode = ({ navigation }) => { @@ -21,7 +21,7 @@ const GetPinCode = ({ navigation }) => { .then((userCreds) => { retrieveSignInFunction(userCreds.username, userCreds.password) .then(() => { - const currentUser = retrieveCurrentUserFunction(); + const currentUser = retrieveCurrentUserAsyncFunction(); getData('currentUser').then((user) => { if (user !== currentUser) { storeData(currentUser, 'currentUser'); diff --git a/domains/Auth/SignIn/index.js b/domains/Auth/SignIn/index.js index 6e2af862c..2bfd6ed7c 100644 --- a/domains/Auth/SignIn/index.js +++ b/domains/Auth/SignIn/index.js @@ -126,8 +126,8 @@ const SignIn = ({ navigation }) => { const storeUserInformation = async () => { const currentUser = await retrieveCurrentUserAsyncFunction(); getData('organization').then((asyncOrg) => { - if (asyncOrg !== currentUser.get('organization')) { - storeData(currentUser.get('organization'), 'organization'); + if (asyncOrg !== currentUser.organization) { + storeData(currentUser.organization, 'organization'); storeData(currentUser, 'currentUser'); } }); diff --git a/domains/Auth/StoreOrganization/index.js b/domains/Auth/StoreOrganization/index.js deleted file mode 100644 index 91674a2d7..000000000 --- a/domains/Auth/StoreOrganization/index.js +++ /dev/null @@ -1,18 +0,0 @@ -import { retrieveCurrentUserFunction } from '../../../services/parse/auth'; -import { storeData, getData } from '../../../modules/async-storage'; - -// currently not working... -// says 'StoreOrganization.storeorganization is not a function' -export default function storeOrganization() { - const currentUser = retrieveCurrentUserFunction(); - getData('organization').then((organization) => { - if (organization !== currentUser.organization) { - storeData(currentUser.organization, 'organization'); - return true; - } - return false; - }, () => { - // error getting data from async - }); - return true; -} diff --git a/domains/DataCollection/Forms/IdentificationForm/index.js b/domains/DataCollection/Forms/IdentificationForm/index.js index 9f52325f1..21dc8a8bf 100644 --- a/domains/DataCollection/Forms/IdentificationForm/index.js +++ b/domains/DataCollection/Forms/IdentificationForm/index.js @@ -4,35 +4,21 @@ import { View, TouchableWithoutFeedback, Keyboard } from 'react-native'; import { Formik } from 'formik'; -// import * as yup from 'yup'; import { postObjectsToClass } from '../../../../services/parse/crud'; -import { - storeData -} from '../../../../modules/async-storage'; +import { storeData } from '../../../../modules/async-storage'; import checkOnlineStatus from '../../../../modules/offline'; import generateRandomID from '../../../../modules/utils'; import { layout } from '../../../../modules/theme'; -import PaperButton from '../../../../components/Button'; - -import backgroundPostPatient from './utils'; -import configArray from './config/config'; - import I18n from '../../../../modules/i18n'; + +import PaperButton from '../../../../components/Button'; import PaperInputPicker from '../../../../components/FormikFields/PaperInputPicker'; import yupValidationPicker from '../../../../components/FormikFields/YupValidation'; -// const validationSchema = yup.object().shape({ -// fname: yup -// .string() -// .label('First Name') -// .required(), -// lname: yup -// .string() -// .label('Last Name') -// .required() -// }); +import backgroundPostPatient from './utils'; +import configArray from './config/config'; const IdentificationForm = ({ scrollViewScroll, setScrollViewScroll, diff --git a/services/parse/auth/index.js b/services/parse/auth/index.js index 7a47aba72..6804d52d0 100644 --- a/services/parse/auth/index.js +++ b/services/parse/auth/index.js @@ -76,7 +76,17 @@ function retrieveCurrentUserFunction() { } function retrieveCurrentUserAsyncFunction() { - return Parse.User.currentAsync().then((user) => user); + return Parse.User.currentAsync().then((u) => { + const user = {}; + user.id = u.id; + user.username = u.get('username'); + user.firstname = u.get('firstname'); + user.lastname = u.get('lastname'); + user.email = u.get('email'); + user.organization = u.get('organization'); + user.role = u.get('role'); + return user; + }); } function retrieveDeleteUserFunction(params) {