From 46afbc71218bcb54ad0f019b267441d8446b2f7b Mon Sep 17 00:00:00 2001 From: Hope Tambala Date: Mon, 10 Oct 2022 13:25:59 -0400 Subject: [PATCH] fix: app version in data --- .../NewAssets/AssetSupplementary/index.js | 3 ++- .../Forms/IdentificationForm/index.js | 4 ++- modules/cached-resources/populate-cache.js | 10 +++----- package-lock.json | 1 + package.json | 3 ++- services/parse/client/index.js | 25 ++++++++++++++----- 6 files changed, 30 insertions(+), 16 deletions(-) diff --git a/domains/DataCollection/Assets/NewAssets/AssetSupplementary/index.js b/domains/DataCollection/Assets/NewAssets/AssetSupplementary/index.js index e49f328bb..7a8373ded 100644 --- a/domains/DataCollection/Assets/NewAssets/AssetSupplementary/index.js +++ b/domains/DataCollection/Assets/NewAssets/AssetSupplementary/index.js @@ -11,6 +11,7 @@ import PaperInputPicker from '../../../../../components/FormikFields/PaperInputP import PopupError from '../../../../../components/PopupError'; import { getData } from '../../../../../modules/async-storage'; import { postSupplementaryAssetForm } from '../../../../../modules/cached-resources'; +import { storeAppVersion } from '../../../../../modules/cached-resources/populate-cache'; import I18n from '../../../../../modules/i18n'; import { theme } from '../../../../../modules/theme'; import { isEmpty } from '../../../../../modules/utils'; @@ -45,7 +46,7 @@ const AssetSupplementary = ({ const user = await getData('currentUser'); const surveyingUserFailSafe = await surveyingUserFailsafe(user, surveyingUser, isEmpty); - const appVersion = await getData('appVersion') || ''; + const appVersion = await storeAppVersion() || ''; let formObjectUpdated = addSelectTextInputs(values, formObject); formObjectUpdated = cleanLoopSubmissions(values, formObjectUpdated); diff --git a/domains/DataCollection/Forms/IdentificationForm/index.js b/domains/DataCollection/Forms/IdentificationForm/index.js index 4908435ac..1d2be4e53 100644 --- a/domains/DataCollection/Forms/IdentificationForm/index.js +++ b/domains/DataCollection/Forms/IdentificationForm/index.js @@ -15,6 +15,7 @@ import yupValidationPicker from '../../../../components/FormikFields/YupValidati import PopupError from '../../../../components/PopupError'; import { getData } from '../../../../modules/async-storage'; import { postIdentificationForm } from '../../../../modules/cached-resources'; +import { storeAppVersion } from '../../../../modules/cached-resources/populate-cache'; import I18n from '../../../../modules/i18n'; import { layout, theme } from '../../../../modules/theme'; import { isEmpty } from '../../../../modules/utils'; @@ -52,7 +53,8 @@ const IdentificationForm = ({ formObject.surveyingOrganization = surveyingOrganization || user.organization; formObject.surveyingUser = await surveyingUserFailsafe(user, surveyingUser, isEmpty); - formObject.appVersion = await getData('appVersion') || ''; + + formObject.appVersion = await storeAppVersion() || ''; formObject.phoneOS = Platform.OS || ''; formObject.latitude = values.location?.latitude || 0; diff --git a/modules/cached-resources/populate-cache.js b/modules/cached-resources/populate-cache.js index a75bf3f57..ee2f0e3b6 100644 --- a/modules/cached-resources/populate-cache.js +++ b/modules/cached-resources/populate-cache.js @@ -1,17 +1,13 @@ import Constants from 'expo-constants'; -import { getData, storeData } from '../async-storage'; +import { storeData } from '../async-storage'; import { assetDataQuery, assetFormsQuery, cacheAutofillData, customFormsQuery } from './read'; -const storeAppVersion = async () => { +export const storeAppVersion = async () => { const appVersion = Constants.manifest.version; - await getData('appVersion').then(async (currentAppVersion) => { - if (appVersion !== currentAppVersion && appVersion) { - await storeData(appVersion, 'appVersion'); - } - }); + return storeData(appVersion, 'appVersion'); }; const populateCache = async (user) => { diff --git a/package-lock.json b/package-lock.json index 7ce84b016..7bc96075b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "axios": "0.21.1", "deprecated-react-native-prop-types": "^2.3.0", "expo": "^46.0.0", + "expo-application": "~4.2.2", "expo-asset": "~8.6.1", "expo-camera": "~12.3.0", "expo-constants": "~13.2.4", diff --git a/package.json b/package.json index 37668c068..b582f1a8b 100644 --- a/package.json +++ b/package.json @@ -83,7 +83,8 @@ "react-native-screens": "~3.15.0", "react-native-svg": "12.3.0", "react-native-uuid": "^2.0.1", - "yup": "0.29.3" + "yup": "0.29.3", + "expo-application": "~4.2.2" }, "devDependencies": { "@babel/core": "^7.18.6", diff --git a/services/parse/client/index.js b/services/parse/client/index.js index 05534adbf..1e58cbe03 100644 --- a/services/parse/client/index.js +++ b/services/parse/client/index.js @@ -1,11 +1,24 @@ +// import AsyncStorage from '@react-native-async-storage/async-storage'; + +// const client = (isTest) => { +// if (isTest) { +// const { Parse } = import ('parse/node'); +// return Parse +// }; +// const { Parse } = import('parse/react-native'); + +// Parse.setAsyncStorage(AsyncStorage); +// return Parse; +// }; + +// export default client; + import AsyncStorage from '@react-native-async-storage/async-storage'; -import { Parse as ParseNode } from 'parse/node'; -import { Parse as ParseRN } from 'parse/react-native'; +import { Parse } from 'parse/react-native'; -const client = (isTest) => { - if (isTest) return ParseNode; - ParseRN.setAsyncStorage(AsyncStorage); - return ParseRN; +const client = () => { + Parse.setAsyncStorage(AsyncStorage); + return Parse; }; export default client;