Skip to content

Commit

Permalink
fix: store surveyData on sign in
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Jan 28, 2021
1 parent a5d433d commit be8f088
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
21 changes: 15 additions & 6 deletions domains/Auth/SignIn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import TermsModal from '../../../components/TermsModal';
import BlackLogo from '../../../assets/graphics/static/Logo-Black.svg';
import ForgotPassword from './ForgotPassword';
import checkOnlineStatus from '../../../modules/offline';
import { populateCache } from '../../../modules/cached-resources';
import { populateCache, cacheResidentData } from '../../../modules/cached-resources';

// components/FormikFields/PaperInputPicker';
const validationSchema = yup.object().shape({
Expand Down Expand Up @@ -73,8 +73,8 @@ const SignIn = ({ navigation }) => {
Alert.alert(
I18n.t('signIn.unableLogin'),
I18n.t('signIn.usernamePasswordIncorrect'), [
{ text: 'OK' }
],
{ text: 'OK' }
],
{ cancelable: true }
);
};
Expand Down Expand Up @@ -139,7 +139,16 @@ const SignIn = ({ navigation }) => {
credentials.store = 'No';
storeData(credentials, 'credentials');
}
populateCache(userData);
populateCache(userData)
const queryParams = {
skip: 0,
offset: 0,
limit: 100000,
parseColumn: 'surveyingOrganization',
parseParam: userData.get("organization"),
};
// cacheResidentData()
// })
};

return (
Expand Down Expand Up @@ -244,8 +253,8 @@ const SignIn = ({ navigation }) => {
{formikProps.isSubmitting ? (
<ActivityIndicator />
) : (
<Button mode="contained" theme={theme} style={styles.submitButton} onPress={formikProps.handleSubmit}>{I18n.t('signIn.login')}</Button>
)}
<Button mode="contained" theme={theme} style={styles.submitButton} onPress={formikProps.handleSubmit}>{I18n.t('signIn.login')}</Button>
)}
<CredentialsModal
modalVisible={modalVisible}
formikProps={formikProps}
Expand Down
2 changes: 2 additions & 0 deletions modules/cached-resources/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
residentQuery,
cacheResidentData,
cacheAutofillData,
customFormsQuery,
getTasksAsync
Expand All @@ -15,6 +16,7 @@ import populateCache from './populate-cache';

export {
residentQuery,
cacheResidentData,
cacheAutofillData,
customFormsQuery,
getTasksAsync,
Expand Down
14 changes: 12 additions & 2 deletions modules/cached-resources/populate-cache.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cacheAutofillData } from './read';
import { cacheAutofillData, cacheResidentData } from './read';
import { retrieveCurrentUserAsyncFunction } from '../../services/parse/auth';
import { storeData } from '../async-storage';

Expand All @@ -22,5 +22,15 @@ export default function populateCache(user) {
await storeData(currentUser, 'currentUser');
});
}
});
})
.then(() => {
const queryParams = {
skip: 0,
offset: 0,
limit: 100000,
parseColumn: 'surveyingOrganization',
parseParam: user.get("organization"),
};
cacheResidentData(queryParams);
})
}
7 changes: 7 additions & 0 deletions modules/cached-resources/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ async function residentQuery(queryParams) {
return records;
}

async function cacheResidentData(queryParams) {
const records = await residentQuery(queryParams);
storeData(records, 'residentData');
console.log("Stored records")
}

async function cacheAutofillData(parameter) {
return new Promise((resolve, reject) => {
checkOnlineStatus().then((connected) => {
Expand Down Expand Up @@ -77,6 +83,7 @@ function getTasksAsync() {

export {
residentQuery,
cacheResidentData,
cacheAutofillData,
customFormsQuery,
getTasksAsync
Expand Down

0 comments on commit be8f088

Please sign in to comment.