Skip to content

Commit

Permalink
feat(puente-forms): add disabled inputs for sup forms
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Mar 8, 2022
1 parent 2f7e7f8 commit cedad83
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
47 changes: 22 additions & 25 deletions domains/DataCollection/Forms/IdentificationForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,44 @@ 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);
}, [setInputs, configArray]);

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 (
<View>
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
{loading === true ? (
<ActivityIndicator
size="large"
color={theme.colors.primary}
/>
) : (
<TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={false}>
<Formik
initialValues={{}}
onSubmit={async (values,) => {
Expand Down Expand Up @@ -180,6 +176,7 @@ const IdentificationForm = ({
)}
</Formik>
</TouchableWithoutFeedback>
)}
</View>
);
};
Expand Down
39 changes: 39 additions & 0 deletions domains/DataCollection/Forms/SupplementaryForm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,30 +34,64 @@ 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);
}
}, [selectedForm, config]);

return (
<View>
{loading === true ? (
<ActivityIndicator
size="large"
color={theme.colors.primary}
/>
) : (
<Formik
initialValues={{}}
onSubmit={async (values) => {
Expand Down Expand Up @@ -132,6 +167,7 @@ const SupplementaryForm = ({
<View style={layout.formContainer}>
{config.fields && config.fields.map((result) => (
<View key={result.formikKey}>
{(activeFields[result.formikKey] === true) && (
<PaperInputPicker
data={result}
formikProps={formikProps}
Expand All @@ -140,6 +176,7 @@ const SupplementaryForm = ({
loopsAdded={loopsAdded}
setLoopsAdded={setLoopsAdded}
/>
)}
</View>
))}

Expand Down Expand Up @@ -171,6 +208,8 @@ const SupplementaryForm = ({
</View>
)}
</Formik>
)}
</View>
);
};

Expand Down

0 comments on commit cedad83

Please sign in to comment.