Skip to content

Commit

Permalink
Merge pull request #95 from jamesgiegerich94/PLATFORM-437
Browse files Browse the repository at this point in the history
Platform 437
  • Loading branch information
joseph-mccombs authored Sep 13, 2021
2 parents f2e1da2 + d2ad479 commit f5127e9
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 55 deletions.
2 changes: 1 addition & 1 deletion components/FormikFields/PaperInputPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const PaperInputPicker = ({
customForm, ...rest
}) => {
const {
label, formikKey, fieldType, sideLabel
label, formikKey, fieldType, sideLabel
} = data;

const {
Expand Down
42 changes: 42 additions & 0 deletions domains/DataCollection/Assets/NewAssets/AssetCore/config/config.js
Original file line number Diff line number Diff line change
@@ -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;
152 changes: 100 additions & 52 deletions domains/DataCollection/Assets/NewAssets/AssetCore/index.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,90 @@
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 (

<ScrollView>
<Provider>
<Formik
initialValues={{}}
onSubmit={async (values, { resetForm }) => {
const formObject = values;
const user = await getData('currentUser');

setSubmitting(true);

formObject.surveyingUser = await surveyingUserFailsafe(user, surveyingUser, isEmpty);
formObject.relatedPeople = people;
formObject.surveyingOrganization = surveyingOrganization;
Expand All @@ -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) => (
<View style={styles.assetContainer}>

{inputs.length && inputs.map((result) => (

<View key={result.formikKey}>
<PaperInputPicker
data={result}
formikProps={formikProps}
surveyingOrganization={surveyingOrganization}
scrollViewScroll={scrollViewScroll}
setScrollViewScroll={setScrollViewScroll}
customForm={false}
/>{console.log(result)}
</View>
)
)}
<ErrorPicker
formikProps={formikProps}
inputs={inputs}
/>
{submitting ? (
<ActivityIndicator />
) : (
<PaperButton
onPressEvent={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' }}
/>
)}
<PaperButton
icon="gesture-swipe"
mode="text"
buttonText={I18n.t('assetCore.swipeAttachForm')}
/>
</View>

)}

{/* {(formikProps) => (
<View style={styles.assetContainer}>
<View id="top">
<TextInput
Expand All @@ -104,7 +166,7 @@ const AssetCore = ({ setSelectedAsset, surveyingOrganization, surveyingUser }) =
theme={stylesPaper}
style={stylesDefault.label}
/>
</View>
</View>
<View style={{ flexDirection: 'row', justifyContent: 'space-evenly' }}>
<PaperButton
buttonText={I18n.t('assetCore.addPeople')}
Expand Down Expand Up @@ -179,23 +241,9 @@ const AssetCore = ({ setSelectedAsset, surveyingOrganization, surveyingUser }) =
theme={stylesPaper}
style={stylesDefault.label}
/>
{formikProps.isSubmitting ? (
<ActivityIndicator />
) : (
<PaperButton
onPressEvent={() => 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' }}
/>
)}
<PaperButton
icon="gesture-swipe"
mode="text"
buttonText={I18n.t('assetCore.swipeAttachForm')}
/>
</View>
)}
)}*/ }
</Formik>
</Provider>

Expand Down
3 changes: 2 additions & 1 deletion domains/DataCollection/Assets/NewAssets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import AssetSupplementary from './AssetSupplementary';

const NewAsset = ({
selectedAsset, setSelectedAsset, surveyingOrganization, assetPageIndex,
surveyingUser
surveyingUser, scrollViewScroll, setScrollViewScroll
}) => (
<View>
<PagerView style={styles.viewPager} initialPage={assetPageIndex}>
Expand All @@ -17,6 +17,7 @@ const NewAsset = ({
selectedAsset={selectedAsset}
surveyingOrganization={surveyingOrganization}
surveyingUser={surveyingUser}
scrollViewScroll={setScrollViewScroll}
/>
</View>
<View key="2" style={styles.page}>
Expand Down
4 changes: 3 additions & 1 deletion domains/DataCollection/Assets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -22,6 +22,8 @@ const Assets = ({
selectedAsset={selectedAsset}
surveyingOrganization={surveyingOrganization}
assetPageIndex={page}
scrollViewScroll={scrollViewScroll}
setScrollViewScroll={setScrollViewScroll}
/>
)}
{selectedAsset === null && (
Expand Down
2 changes: 2 additions & 0 deletions domains/DataCollection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ const DataCollection = ({ navigation }) => {
setSelectedAsset={setSelectedAsset}
navigateToNewAssets={navigateToNewAssets}
navigateToViewAllAssets={navigateToViewAllAssets}
scrollViewScroll={scrollViewScroll}
setScrollViewScroll={setScrollViewScroll}
/>
</View>
)}
Expand Down

0 comments on commit f5127e9

Please sign in to comment.