diff --git a/domains/DataCollection/Forms/IdentificationForm/index.js b/domains/DataCollection/Forms/IdentificationForm/index.js index aa91b549f..8340d0936 100644 --- a/domains/DataCollection/Forms/IdentificationForm/index.js +++ b/domains/DataCollection/Forms/IdentificationForm/index.js @@ -34,30 +34,8 @@ 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 - }); + const [activeFields, setActiveFields] = useState({}); + const [loading, setLoading] = useState(true); useEffect(() => { setInputs(configArray); @@ -65,17 +43,35 @@ const IdentificationForm = ({ useEffect(() => { retrievePuenteFormModifications(surveyingOrganization).then((forms) => { + let foundForm = false; forms.forEach((form) => { if (form.name === "SurveyData") { setActiveFields(form.activeFields); + foundForm = true; + setLoading(false); } }) + if (foundForm === false) { + const tempActiveFields = {} + inputs.forEach((input) => { + tempActiveFields[input.formikKey] = true + }) + setActiveFields(tempActiveFields) + setLoading(false); + } }) }, [surveyingOrganization]) + return ( - + {loading === true ? ( + + ) : ( + { @@ -180,6 +176,7 @@ const IdentificationForm = ({ )} + )} ); }; diff --git a/domains/DataCollection/Forms/SupplementaryForm/index.js b/domains/DataCollection/Forms/SupplementaryForm/index.js index 457628da3..a964b23cf 100644 --- a/domains/DataCollection/Forms/SupplementaryForm/index.js +++ b/domains/DataCollection/Forms/SupplementaryForm/index.js @@ -22,6 +22,7 @@ import envConfig from './configs/envhealth.config'; import medConfig from './configs/medical-evaluation.config'; import vitalsConfig from './configs/vitals.config'; import { addSelectTextInputs, cleanLoopSubmissions, vitalsBloodPressue } from './utils'; +import { retrievePuenteFormModifications } from '../../../../modules/cached-resources'; const SupplementaryForm = ({ navigation, selectedForm, setSelectedForm, surveyee, surveyingUser, surveyingOrganization, @@ -33,23 +34,50 @@ const SupplementaryForm = ({ const [submitting, setSubmitting] = useState(false); const [loopsAdded, setLoopsAdded] = useState(0); const [submissionError, setSubmissionError] = useState(false); + const [activeFields, setActiveFields] = useState({}); + const [loading, setLoading] = useState(true); const toRoot = () => { navigation.navigate('Root'); setSelectedForm(''); }; + const setActiveFieldsForSupForm = (formName) => { + retrievePuenteFormModifications(surveyingOrganization).then((forms) => { + let foundForm = false; + forms.forEach((form) => { + if (form.name === formName) { + setActiveFields(form.activeFields); + foundForm = true; + setLoading(false); + } + }) + if (foundForm === false) { + const tempActiveFields = {} + config.fields.forEach((field) => { + console.log(field) + tempActiveFields[field.formikKey] = true; + }) + setActiveFields(tempActiveFields) + setLoading(false); + } + }) + } + useEffect(() => { if (selectedForm === 'env') { setConfig(envConfig); + setActiveFieldsForSupForm("EnvironmentalHealth"); setValidationSchema(yupValidationPicker(envConfig.fields)); } if (selectedForm === 'med-eval') { setConfig(medConfig); + setActiveFieldsForSupForm("MedicalEvaluation") setValidationSchema(yupValidationPicker(medConfig.fields)); } if (selectedForm === 'vitals') { setConfig(vitalsConfig); + setActiveFieldsForSupForm("Vitals"); } if (selectedForm === 'custom') { setConfig(customForm); @@ -57,6 +85,13 @@ const SupplementaryForm = ({ }, [selectedForm, config]); return ( + + {loading === true ? ( + + ) : ( { @@ -132,6 +167,7 @@ const SupplementaryForm = ({ {config.fields && config.fields.map((result) => ( + {(activeFields[result.formikKey] === true) && ( + )} ))} @@ -171,6 +208,8 @@ const SupplementaryForm = ({ )} + )} + ); };