diff --git a/components/FormikFields/PaperInputPicker/index.js b/components/FormikFields/PaperInputPicker/index.js index 6b163e1a5..9fa4a6cc2 100644 --- a/components/FormikFields/PaperInputPicker/index.js +++ b/components/FormikFields/PaperInputPicker/index.js @@ -25,7 +25,7 @@ const PaperInputPicker = ({ customForm, ...rest }) => { const { - label, formikKey, fieldType, sideLabel + label, formikKey, fieldType, sideLabel } = data; const { diff --git a/domains/DataCollection/Assets/NewAssets/AssetCore/config/config.js b/domains/DataCollection/Assets/NewAssets/AssetCore/config/config.js new file mode 100644 index 000000000..a374ef98f --- /dev/null +++ b/domains/DataCollection/Assets/NewAssets/AssetCore/config/config.js @@ -0,0 +1,42 @@ +const configArray = [ + { + label: 'assetCore.nameOfAssets', + formikKey: '', + value: '', + fieldType: 'input', + validation: false + }, + { + label: 'assetCore.getLocation', + formikKey: 'location', + value: {}, + fieldType: 'geolocation', + validation: false + }, + { + label: 'global.commName', + formikKey: 'communityname', + value: '', + fieldType: 'autofill', + parameter: 'Communities', + validation: false + }, + { + label: 'identificationForm.province', + formikKey: 'province', + value: '', + fieldType: 'autofill', + parameter: 'Province', + validation: false + }, + { + label: 'assetCore.country', + formikKey: 'country', + value: '', + fieldType: 'autofill', + parameter: 'Country', + validation: false + } +]; + +export default configArray; \ No newline at end of file diff --git a/domains/DataCollection/Assets/NewAssets/AssetCore/index.js b/domains/DataCollection/Assets/NewAssets/AssetCore/index.js index d8adbb4da..6eaf78a82 100644 --- a/domains/DataCollection/Assets/NewAssets/AssetCore/index.js +++ b/domains/DataCollection/Assets/NewAssets/AssetCore/index.js @@ -1,63 +1,81 @@ import { Formik } from 'formik'; import _ from 'lodash'; -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { - ActivityIndicator, Modal, + ActivityIndicator,/* Modal,*/ ScrollView, View } from 'react-native'; import { - Provider, Text, - TextInput + Provider, /*Text/*, + TextInput*/ } from 'react-native-paper'; +import ErrorPicker from '../../../../../components/FormikFields/ErrorPicker'; +import yupValidationPicker from '../../../../../components/FormikFields/YupValidation'; +import PaperInputPicker from '../../../../../components/FormikFields/PaperInputPicker'; import PaperButton from '../../../../../components/Button'; -import { stylesDefault, stylesPaper } from '../../../../../components/FormikFields/PaperInputPicker/index.style'; +//import { stylesDefault, stylesPaper } from '../../../../../components/FormikFields/PaperInputPicker/index.style'; import { getData } from '../../../../../modules/async-storage'; import { postAssetForm } from '../../../../../modules/cached-resources'; -import getLocation from '../../../../../modules/geolocation'; +//import getLocation from '../../../../../modules/geolocation'; import I18n from '../../../../../modules/i18n'; -import { generateRandomID, isEmpty } from '../../../../../modules/utils'; +import { /*generateRandomID,*/ isEmpty } from '../../../../../modules/utils'; import surveyingUserFailsafe from '../../../Forms/utils'; import styles from './index.styles'; -import PeopleModal from './PeopleModal'; +//import PeopleModal from './PeopleModal'; +import { layout, theme } from '../../../../../modules/theme'; +import configArray from './config/config'; + +const AssetCore = ({ scrollViewScroll, setScrollViewScroll, + /*setSelectedForm, setSurveyee,*/ surveyingUser, surveyingOrganization }) => { + + useEffect(() => { + setValidationSchema(yupValidationPicker(configArray)); + }, []); -const AssetCore = ({ setSelectedAsset, surveyingOrganization, surveyingUser }) => { const [people, setPeople] = useState([{ firstName: '', lastName: '' }]); - const [location, setLocation] = useState(); - const [locationLoading, setLocationLoading] = useState(false); + // const [location, setLocation] = useState(); + // const [locationLoading, setLocationLoading] = useState(false); const [visible, setVisible] = useState(false); - + const [inputs, setInputs] = useState({}); const toggleModal = () => setVisible(!visible); + const [submitting, setSubmitting] = useState(false); + const [validationSchema, setValidationSchema] = useState(); + + useEffect(() => { + setInputs(configArray); + }, [setInputs, configArray]); - const handleFormikPropsLocation = async (formikProps) => { - setLocationLoading(true); - const currentLocation = await getLocation().then().catch((e) => e); - const { latitude, longitude } = currentLocation.coords; - formikProps.setFieldValue('location', { latitude, longitude }); - setLocation(currentLocation.coords); - setLocationLoading(false); - }; + // const handleFormikPropsLocation = async (formikProps) => { + // setLocationLoading(true); + // const currentLocation = await getLocation().then().catch((e) => e); + // const { latitude, longitude } = currentLocation.coords; + // formikProps.setFieldValue('location', { latitude, longitude }); + // //setLocation(currentLocation.coords); + // // setLocationLoading(false); + // }; // handle input change - const handleInputChange = (text, index, name) => { - const list = [...people]; - list[index][name] = text; - setPeople(list); - }; + // const handleInputChange = (text, index, name) => { + // const list = [...people]; + // list[index][name] = text; + // setPeople(list); + // }; // handle click event of the Remove button - const handleRemoveClick = (index) => { - const list = [...people]; - list.splice(index, 1); - setPeople(list); - }; + // const handleRemoveClick = (index) => { + // const list = [...people]; + // list.splice(index, 1); + // setPeople(list); + // }; // handle click event of the Add button - const handleAddClick = () => { - setPeople([...people, { firstName: '', lastName: '' }]); - }; + // const handleAddClick = () => { + // setPeople([...people, { firstName: '', lastName: '' }]); + // }; return ( + { const formObject = values; const user = await getData('currentUser'); - + setSubmitting(true); + formObject.surveyingUser = await surveyingUserFailsafe(user, surveyingUser, isEmpty); formObject.relatedPeople = people; formObject.surveyingOrganization = surveyingOrganization; @@ -86,13 +105,56 @@ const AssetCore = ({ setSelectedAsset, surveyingOrganization, surveyingUser }) = .then((e) => { const asset = JSON.parse(JSON.stringify(e)); setSelectedAsset(asset); + }) .then(() => resetForm()) .catch((e) => console.log(e)); //eslint-disable-line + setSubmitting(false); }} + > - + {(formikProps) => ( + + + {inputs.length && inputs.map((result) => ( + + + {console.log(result)} + + ) + )} + + {submitting ? ( + + ) : ( + + )} + + + + )} + + {/* {(formikProps) => ( - + - {formikProps.isSubmitting ? ( - - ) : ( - formikProps.handleSubmit()} - buttonText={_.isEmpty(formikProps.values) ? I18n.t('global.emptyForm') : I18n.t('assetForms.createAsset')} - icon={_.isEmpty(formikProps.values) ? 'alert-octagon' : 'plus'} - style={{ backgroundColor: _.isEmpty(formikProps.values) ? 'red' : 'green' }} - /> - )} - + - )} + )}*/ } diff --git a/domains/DataCollection/Assets/NewAssets/index.js b/domains/DataCollection/Assets/NewAssets/index.js index a8d6d3ee7..99defb7ad 100644 --- a/domains/DataCollection/Assets/NewAssets/index.js +++ b/domains/DataCollection/Assets/NewAssets/index.js @@ -7,7 +7,7 @@ import AssetSupplementary from './AssetSupplementary'; const NewAsset = ({ selectedAsset, setSelectedAsset, surveyingOrganization, assetPageIndex, - surveyingUser + surveyingUser, scrollViewScroll, setScrollViewScroll }) => ( @@ -17,6 +17,7 @@ const NewAsset = ({ selectedAsset={selectedAsset} surveyingOrganization={surveyingOrganization} surveyingUser={surveyingUser} + scrollViewScroll={setScrollViewScroll} /> diff --git a/domains/DataCollection/Assets/index.js b/domains/DataCollection/Assets/index.js index aa3cce401..04ba95941 100644 --- a/domains/DataCollection/Assets/index.js +++ b/domains/DataCollection/Assets/index.js @@ -5,7 +5,7 @@ import NewAssets from './NewAssets'; import ViewAssets from './ViewAssets'; const Assets = ({ - selectedAsset, setSelectedAsset, surveyingOrganization + selectedAsset, setSelectedAsset, surveyingOrganization, scrollViewScroll, setScrollViewScroll }) => { const [page, setPage] = useState(0); @@ -22,6 +22,8 @@ const Assets = ({ selectedAsset={selectedAsset} surveyingOrganization={surveyingOrganization} assetPageIndex={page} + scrollViewScroll={scrollViewScroll} + setScrollViewScroll={setScrollViewScroll} /> )} {selectedAsset === null && ( diff --git a/domains/DataCollection/index.js b/domains/DataCollection/index.js index 3b5218872..f8f762e80 100644 --- a/domains/DataCollection/index.js +++ b/domains/DataCollection/index.js @@ -213,6 +213,8 @@ const DataCollection = ({ navigation }) => { setSelectedAsset={setSelectedAsset} navigateToNewAssets={navigateToNewAssets} navigateToViewAllAssets={navigateToViewAllAssets} + scrollViewScroll={scrollViewScroll} + setScrollViewScroll={setScrollViewScroll} /> )}