From ae0103be414cd752e85a54985b37d3e3b1cbe9e2 Mon Sep 17 00:00:00 2001 From: Hope Tambala Date: Wed, 9 Dec 2020 22:17:01 -0800 Subject: [PATCH] feat: hotfix for not populating surveyor names --- domains/Auth/SignIn/index.js | 9 +++------ .../Forms/IdentificationForm/index.js | 11 ++++++----- .../Forms/IdentificationForm/utils/index.js | 7 ++++++- .../Forms/SupplementaryForm/index.js | 16 ++++++++-------- domains/DataCollection/index.js | 2 -- modules/utils/index.js | 3 ++- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/domains/Auth/SignIn/index.js b/domains/Auth/SignIn/index.js index 7f3c0efa6..eb5684260 100644 --- a/domains/Auth/SignIn/index.js +++ b/domains/Auth/SignIn/index.js @@ -130,12 +130,9 @@ const SignIn = ({ navigation }) => { }; const storeUserInformation = async () => { - const currentUser = await retrieveCurrentUserAsyncFunction(); - getData('organization').then((asyncOrg) => { - if (asyncOrg !== currentUser.organization) { - storeData(currentUser.organization, 'organization'); - storeData(currentUser, 'currentUser'); - } + await retrieveCurrentUserAsyncFunction().then((currentUser) => { + storeData(currentUser.organization, 'organization'); + storeData(currentUser, 'currentUser'); }); }; diff --git a/domains/DataCollection/Forms/IdentificationForm/index.js b/domains/DataCollection/Forms/IdentificationForm/index.js index 21dc8a8bf..c60a7ee81 100644 --- a/domains/DataCollection/Forms/IdentificationForm/index.js +++ b/domains/DataCollection/Forms/IdentificationForm/index.js @@ -9,7 +9,7 @@ import { postObjectsToClass } from '../../../../services/parse/crud'; import { storeData } from '../../../../modules/async-storage'; import checkOnlineStatus from '../../../../modules/offline'; -import generateRandomID from '../../../../modules/utils'; +import { generateRandomID } from '../../../../modules/utils'; import { layout } from '../../../../modules/theme'; import I18n from '../../../../modules/i18n'; @@ -17,12 +17,12 @@ import PaperButton from '../../../../components/Button'; import PaperInputPicker from '../../../../components/FormikFields/PaperInputPicker'; import yupValidationPicker from '../../../../components/FormikFields/YupValidation'; -import backgroundPostPatient from './utils'; +import { backgroundPostPatient, surveyingUserFailsafe } from './utils'; import configArray from './config/config'; const IdentificationForm = ({ scrollViewScroll, setScrollViewScroll, - setSelectedForm, setSurveyee, surveyingOrganization, surveyingUser + setSelectedForm, setSurveyee, surveyingOrganization }) => { useEffect(() => { const interval = setInterval(() => { @@ -49,12 +49,13 @@ const IdentificationForm = ({ { + onSubmit={async (values, actions) => { setPhotoFile('Submitted Photo String'); const formObject = values; formObject.surveyingOrganization = surveyingOrganization; - formObject.surveyingUser = surveyingUser; + formObject.surveyingUser = await surveyingUserFailsafe(); + formObject.latitude = values.location?.latitude || 0; formObject.longitude = values.location?.longitude || 0; formObject.altitude = values.location?.altitude || 0; diff --git a/domains/DataCollection/Forms/IdentificationForm/utils/index.js b/domains/DataCollection/Forms/IdentificationForm/utils/index.js index 2249ea478..d7719bbee 100644 --- a/domains/DataCollection/Forms/IdentificationForm/utils/index.js +++ b/domains/DataCollection/Forms/IdentificationForm/utils/index.js @@ -30,4 +30,9 @@ const backgroundPostPatient = () => { }); }; -export default backgroundPostPatient; +const surveyingUserFailsafe = async () => { + const user = await getData('currentUser'); + return user.username || user.email || user.id || user.firstname || user.lastname; +}; + +export { backgroundPostPatient, surveyingUserFailsafe }; diff --git a/domains/DataCollection/Forms/SupplementaryForm/index.js b/domains/DataCollection/Forms/SupplementaryForm/index.js index 89c823b7a..40341bed7 100644 --- a/domains/DataCollection/Forms/SupplementaryForm/index.js +++ b/domains/DataCollection/Forms/SupplementaryForm/index.js @@ -112,14 +112,14 @@ const SupplementaryForm = ({ {formikProps.isSubmitting ? ( ) : ( - - )} + + )} )} diff --git a/domains/DataCollection/index.js b/domains/DataCollection/index.js index a65941386..a88e79cae 100644 --- a/domains/DataCollection/index.js +++ b/domains/DataCollection/index.js @@ -52,8 +52,6 @@ const DataCollection = ({ navigation }) => { useEffect(() => { getData('currentUser').then((user) => { setSurveyingUser(`${user.firstname || ''} ${user.lastname || ''}`); - }).catch(() => { - setSurveyingUser(`${''} ${''}`); }); getData('organization').then((org) => { diff --git a/modules/utils/index.js b/modules/utils/index.js index b2de050e2..d3d230c71 100644 --- a/modules/utils/index.js +++ b/modules/utils/index.js @@ -1,3 +1,4 @@ const generateRandomID = () => Math.random().toString(20).substr(2, 12); +const isEmpty = (str) => (!str || str.length === 0); -export default generateRandomID; +export { isEmpty, generateRandomID };