From 3c2f853fb1fda4fd46230d0ad5b3cf7415408ae8 Mon Sep 17 00:00:00 2001 From: Joseph McCombs Date: Sun, 15 Nov 2020 19:54:16 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20add=20household=20relationship=20and=20?= =?UTF-8?q?update=20UI=20=F0=9F=8E=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HouseholdManager/index.js | 85 +++++++++++++++---- .../FormikFields/PaperInputPicker/index.js | 3 +- 2 files changed, 69 insertions(+), 19 deletions(-) diff --git a/components/FormikFields/PaperInputPicker/HouseholdManager/index.js b/components/FormikFields/PaperInputPicker/HouseholdManager/index.js index 3703ac40d..e346b63f8 100644 --- a/components/FormikFields/PaperInputPicker/HouseholdManager/index.js +++ b/components/FormikFields/PaperInputPicker/HouseholdManager/index.js @@ -3,7 +3,7 @@ import { View, Modal } from 'react-native'; import { - Button, RadioButton, Appbar, Text + Button, RadioButton, Appbar, Text, TextInput } from 'react-native-paper'; import ResidentIdSearchbar from '../../../ResidentIdSearchbar'; @@ -11,14 +11,14 @@ import ResidentIdSearchbar from '../../../ResidentIdSearchbar'; import { theme, layout } from '../../../../modules/theme'; import I18n from '../../../../modules/i18n'; -import { postObjectsToClass } from '../../../../services/parse/crud'; +import { postObjectsToClass, postObjectsToClassWithRelation } from '../../../../services/parse/crud'; import styles from './index.style'; const HouseholdManager = (props) => { - const { formikProps, formikKey, surveyingOrganization } = props; - const { setFieldValue } = formikProps; + const { formikProps, formikKey, surveyingOrganization, values } = props; + const { setFieldValue, handleBlur, handleChange, errors } = formikProps; const [relationships] = useState([ 'Parent', 'Sibling', 'Grand-Parent', 'Cousin', 'Other' ]); @@ -28,8 +28,17 @@ const HouseholdManager = (props) => { const [modalView, setModalView] = useState('zero'); const onSubmit = () => { - setModalView('third'); - attachToExistingHousehold(); + if (!selectPerson) { + alert('You must search and select an individual.') //eslint-disable-line + } + else if (relationship === '') { + alert('You must select a role/relationship in the household.') //eslint-disable-line + } + else { + setModalView('third'); + attachToExistingHousehold(); + postHouseholdRelation(); + } }; const attachToExistingHousehold = () => { @@ -37,6 +46,27 @@ const HouseholdManager = (props) => { setFieldValue(formikKey, selectPerson.householdId || 'No Household Id Found'); }; + const postHouseholdRelation = () => { + let finalRelationship = relationship; + if (relationship === 'Other') { + finalRelationship += '__' + values['other'] + } + const postParams = { + parseParentClassID: selectPerson.householdId, + parseParentClass: 'Household', + parseClass: 'Household', + localObject: { + relationship: finalRelationship, + latitude: 0, + longitude: 0 + } + }; + postObjectsToClassWithRelation(postParams).then((result) => { + setFieldValue(formikKey, result.id) + }) + + } + const createNewHousehold = () => { // create new householdId and attach on the residentIdForm const postParams = { @@ -82,16 +112,14 @@ const HouseholdManager = (props) => { setSurveyee={setSelectPerson} surveyingOrganization={surveyingOrganization} /> - - {I18n.t('householdManager.relationshipHousehold')} + {!selectPerson && ( + Please use the searchbar to find and select the correct Househld. + )} + {selectPerson && ( + {I18n.t('householdManager.relationshipHousehold')} + )} - {relationships.map((result) => ( - // + {selectPerson && relationships.map((result) => ( {relationship === result ? ( @@ -101,9 +129,30 @@ const HouseholdManager = (props) => { ))} - + {relationship === 'Other' && ( + + + + {errors['other']} + + + )} + {selectPerson ? ( + + ) : ( + + )} + )} diff --git a/components/FormikFields/PaperInputPicker/index.js b/components/FormikFields/PaperInputPicker/index.js index 844b4cd85..8bdceb548 100644 --- a/components/FormikFields/PaperInputPicker/index.js +++ b/components/FormikFields/PaperInputPicker/index.js @@ -199,7 +199,7 @@ const PaperInputPicker = ({ {errors[result.textKey]} - )} + )} ))} @@ -258,6 +258,7 @@ const PaperInputPicker = ({ formikProps={formikProps} formikKey={formikKey} surveyingOrganization={surveyingOrganization} + values={values} /> )}