Skip to content

Commit

Permalink
feat: initial setup to deactivate surveyData form
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Feb 18, 2022
1 parent 9f2aa97 commit 2f7e7f8
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 23,044 deletions.
53 changes: 45 additions & 8 deletions domains/DataCollection/Forms/IdentificationForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { layout, theme } from '../../../../modules/theme';
import { isEmpty } from '../../../../modules/utils';
import surveyingUserFailsafe from '../utils';
import configArray from './config/config';
import { retrievePuenteFormModifications } from "../../../../modules/cached-resources";

const IdentificationForm = ({
scrollViewScroll, setScrollViewScroll,
Expand All @@ -33,11 +34,45 @@ const IdentificationForm = ({
const [validationSchema, setValidationSchema] = useState();
const [submitting, setSubmitting] = useState(false);
const [submissionError, setSubmissionError] = useState(false);
const [activeFields, setActiveFields] = useState({
"none_bi": true,
"fname": true,
"lname": true,
"nickname": true,
"dob": true,
"age": true,
"sex": true,
"telephoneNumber": true,
"marriageStatus": true,
"Occupation": true,
"Education Level": true,
"none_location": true,
"communityname": true,
"subcounty": true,
"city": true,
"Province": true,
"region": true,
"country": true,
"location": true,
"photoFile": true,
"none_household": true,
"geolocation_9b11": true
});

useEffect(() => {
setInputs(configArray);
}, [setInputs, configArray]);

useEffect(() => {
retrievePuenteFormModifications(surveyingOrganization).then((forms) => {
forms.forEach((form) => {
if (form.name === "SurveyData") {
setActiveFields(form.activeFields);
}
})
})
}, [surveyingOrganization])

return (
<View>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
Expand Down Expand Up @@ -107,14 +142,16 @@ const IdentificationForm = ({
<View style={layout.formContainer}>
{inputs.length && inputs.map((result) => (
<View key={result.formikKey}>
<PaperInputPicker
data={result}
formikProps={formikProps}
surveyingOrganization={surveyingOrganization}
scrollViewScroll={scrollViewScroll}
setScrollViewScroll={setScrollViewScroll}
customForm={false}
/>
{(activeFields[result.formikKey] === true) && (
<PaperInputPicker
data={result}
formikProps={formikProps}
surveyingOrganization={surveyingOrganization}
scrollViewScroll={scrollViewScroll}
setScrollViewScroll={setScrollViewScroll}
customForm={false}
/>
)}
</View>
))}
<ErrorPicker
Expand Down
4 changes: 3 additions & 1 deletion modules/cached-resources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
customFormsQuery,
getTasksAsync,
residentQuery,
retrievePuenteFormModifications,
} from './read';

export {
Expand All @@ -31,5 +32,6 @@ export {
postIdentificationForm,
postSupplementaryAssetForm,
postSupplementaryForm,
residentQuery
residentQuery,
retrievePuenteFormModifications
};
4 changes: 3 additions & 1 deletion modules/cached-resources/populate-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Constants from 'expo-constants';

import { getData, storeData } from '../async-storage';
import {
assetDataQuery, assetFormsQuery, cacheAutofillData, customFormsQuery
assetDataQuery, assetFormsQuery, cacheAutofillData, customFormsQuery,
retrievePuenteFormModifications
} from './read';

const storeAppVersion = async () => {
Expand All @@ -21,6 +22,7 @@ const populateCache = async (user) => {
cacheAutofillData(enteredUsrOrg),
customFormsQuery(enteredUsrOrg),
storeAppVersion(),
retrievePuenteFormModifications(),
assetDataQuery(enteredUsrOrg).then(() => assetFormsQuery(enteredUsrOrg))
]);
};
Expand Down
23 changes: 22 additions & 1 deletion modules/cached-resources/read.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,33 @@ function assetDataQuery(surveyingOrganization) {
});
}

function retrievePuenteFormModifications(surveyingOrganization) {
return new Promise((resolve, reject) => {
checkOnlineStatus().then((online) => {
if (online) {
customQueryService(0, 10000, 'PuenteFormModifications', 'organizations', surveyingOrganization).then((async (forms) => {
console.log("Mod forms",forms)
await storeData(forms, 'puenteFormModifications')
resolve(JSON.parse(JSON.stringify(forms)))
}))
} else {
getData('puenteFormModifications').then((forms) => {
resolve(forms);
}, (error) => {
reject(error);
})
}
})
})
}

export {
assetDataQuery,
assetFormsQuery,
cacheAutofillData,
cacheResidentDataMulti,
customFormsQuery,
getTasksAsync,
residentQuery
residentQuery,
retrievePuenteFormModifications
};
Loading

0 comments on commit 2f7e7f8

Please sign in to comment.