Skip to content

Commit

Permalink
fix: surveyingUser failsafe storing all valid values
Browse files Browse the repository at this point in the history
  • Loading branch information
hopetambala committed Dec 14, 2020
1 parent 07c61c1 commit e6e6a3b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
10 changes: 6 additions & 4 deletions domains/DataCollection/Forms/IdentificationForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ import { postObjectsToClass } from '../../../../services/parse/crud';

import { storeData } from '../../../../modules/async-storage';
import checkOnlineStatus from '../../../../modules/offline';
import { generateRandomID } from '../../../../modules/utils';
import { generateRandomID, isEmpty } from '../../../../modules/utils';
import { layout } from '../../../../modules/theme';
import I18n from '../../../../modules/i18n';

import PaperButton from '../../../../components/Button';
import PaperInputPicker from '../../../../components/FormikFields/PaperInputPicker';
import yupValidationPicker from '../../../../components/FormikFields/YupValidation';

import { backgroundPostPatient, surveyingUserFailsafe } from './utils';
import backgroundPostPatient from './utils';
import surveyingUserFailsafe from '../utils';

import configArray from './config/config';

const IdentificationForm = ({
scrollViewScroll, setScrollViewScroll,
setSelectedForm, setSurveyee, surveyingOrganization
setSelectedForm, setSurveyee, surveyingUser, surveyingOrganization
}) => {
useEffect(() => {
const interval = setInterval(() => {
Expand Down Expand Up @@ -54,7 +56,7 @@ const IdentificationForm = ({

const formObject = values;
formObject.surveyingOrganization = surveyingOrganization;
formObject.surveyingUser = await surveyingUserFailsafe();
formObject.surveyingUser = await surveyingUserFailsafe(surveyingUser, isEmpty);

formObject.latitude = values.location?.latitude || 0;
formObject.longitude = values.location?.longitude || 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,4 @@ const backgroundPostPatient = () => {
});
};

const surveyingUserFailsafe = async () => {
const user = await getData('currentUser');
return user.username || user.email || user.id || user.firstname || user.lastname;
};

export { backgroundPostPatient, surveyingUserFailsafe };
export default backgroundPostPatient;
5 changes: 3 additions & 2 deletions domains/DataCollection/Forms/SupplementaryForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { postObjectsToClassWithRelation } from '../../../../services/parse/crud'

import { layout } from '../../../../modules/theme';
import I18n from '../../../../modules/i18n';
import { isEmpty } from '../../../../modules/utils';

import PaperInputPicker from '../../../../components/FormikFields/PaperInputPicker';
import yupValidationPicker from '../../../../components/FormikFields/YupValidation';
Expand All @@ -23,7 +24,7 @@ import surveyingUserFailsafe from '../utils';
import { addSelectTextInputs, vitalsBloodPressue } from './utils';

const SupplementaryForm = ({
navigation, selectedForm, setSelectedForm, surveyee, surveyingOrganization,
navigation, selectedForm, setSelectedForm, surveyee, surveyingUser, surveyingOrganization,
customForm
}) => {
const [config, setConfig] = useState({});
Expand Down Expand Up @@ -56,7 +57,7 @@ const SupplementaryForm = ({
onSubmit={async (values, actions) => {
setPhotoFile('Submitted Photo String');
const formObject = values;
formObject.surveyingUser = await surveyingUserFailsafe();
formObject.surveyingUser = await surveyingUserFailsafe(surveyingUser, isEmpty);
formObject.surveyingOrganization = surveyingOrganization;

let formObjectUpdated = addSelectTextInputs(values, formObject);
Expand Down
6 changes: 4 additions & 2 deletions domains/DataCollection/Forms/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { getData } from '../../../../modules/async-storage';

const surveyingUserFailsafe = async () => {
const surveyingUserFailsafe = async (defautValue, validationFail) => {
const user = await getData('currentUser');
return user.username || user.email || user.id || user.firstname || user.lastname;
const userChecks = [defautValue, user.username, user.email, user.id, user.firstname, user.lastname, 'N/A'];
const validIdentifiers = userChecks.filter((uniqueId) => validationFail(uniqueId) === false);
return validIdentifiers[0];
};

export default surveyingUserFailsafe;
2 changes: 1 addition & 1 deletion modules/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const generateRandomID = () => Math.random().toString(20).substr(2, 12);
const isEmpty = (str) => (!str || str.length === 0);
const isEmpty = (str) => (!str || str === undefined || str.length === 0 || !/\S/.test(str));

export { isEmpty, generateRandomID };

0 comments on commit e6e6a3b

Please sign in to comment.