Skip to content

Commit

Permalink
feat: deep link to user in asset and asset forms 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-mccombs committed Jun 10, 2021
1 parent c06e779 commit 46d42dc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
13 changes: 11 additions & 2 deletions domains/DataCollection/Assets/NewAssets/AssetCore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import { stylesDefault, stylesPaper } from '../../../../../components/FormikFiel
import { postAssetForm } from '../../../../../modules/cached-resources';
import getLocation from '../../../../../modules/geolocation';
import I18n from '../../../../../modules/i18n';
import { generateRandomID } from '../../../../../modules/utils';
import { generateRandomID, isEmpty } from '../../../../../modules/utils';
import styles from './index.styles';
import PeopleModal from './PeopleModal';
import { getData } from '../../../../../modules/async-storage';

const AssetCore = ({ setSelectedAsset, surveyingOrganization }) => {
import surveyingUserFailsafe from '../../../Forms/utils';

const AssetCore = ({ setSelectedAsset, surveyingOrganization, surveyingUser }) => {
const [people, setPeople] = useState([{ firstName: '', lastName: '' }]);
const [location, setLocation] = useState();
const [locationLoading, setLocationLoading] = useState(false);
Expand Down Expand Up @@ -62,14 +65,19 @@ const AssetCore = ({ setSelectedAsset, surveyingOrganization }) => {
initialValues={{}}
onSubmit={async (values, { resetForm }) => {
const formObject = values;
const user = await getData('currentUser');

formObject.surveyingUser = await surveyingUserFailsafe(user, surveyingUser, isEmpty)
formObject.relatedPeople = people;
formObject.surveyingOrganization = surveyingOrganization;
formObject.appVersion = await getData('appVersion');
formObject.latitude = values.location?.latitude || 0;
formObject.longitude = values.location?.longitude || 0;
formObject.altitude = values.location?.altitude || 0;

const postParams = {
parseClass: 'Assets',
parseUser: user.objectId,
signature: 'Asset Signature',
photoFile: 'photo',
localObject: formObject
Expand All @@ -79,6 +87,7 @@ const AssetCore = ({ setSelectedAsset, surveyingOrganization }) => {
.then((e) => {
const asset = JSON.parse(JSON.stringify(e));
setSelectedAsset(asset);
console.log(e)
})
.then(() => resetForm())
.catch((e) => console.log(e)); //eslint-disable-line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import { addSelectTextInputs } from '../../../Forms/SupplementaryForm/utils';
import SelectedAsset from '../../ViewAssets/SelectedAsset';
import AssetFormSelect from './AssetFormSelect';
import styles from './index.styles';
import { getData } from '../../../../../modules/async-storage';
import surveyingUserFailsafe from '../../../Forms/utils'
import { isEmpty } from '../../../../../modules/utils';

const AssetSupplementary = ({ selectedAsset, setSelectedAsset, surveyingOrganization }) => {
const AssetSupplementary = ({ selectedAsset, setSelectedAsset, surveyingOrganization, surveyingUser }) => {
const [selectedForm, setSelectedForm] = useState();
const [photoFile, setPhotoFile] = useState('State Photo String');

Expand All @@ -25,12 +28,17 @@ const AssetSupplementary = ({ selectedAsset, setSelectedAsset, surveyingOrganiza
setPhotoFile('Submitted Photo String');

const formObject = values;
const user = await getData('currentUser');

const surveyingUser_FailSafe = await surveyingUserFailsafe(user, surveyingUser, isEmpty);
const appVersion = await getData('appVersion');

const formObjectUpdated = addSelectTextInputs(values, formObject);

const postParams = {
parseParentClassID: selectedAsset.objectId,
parseParentClass: 'Assets',
parseUser: user.objectId,
parseClass: 'FormAssetResults',
photoFile,
localObject: formObjectUpdated,
Expand All @@ -48,6 +56,8 @@ const AssetSupplementary = ({ selectedAsset, setSelectedAsset, surveyingOrganiza
formSpecificationsId: selectedForm.objectId,
fields: fieldsArray,
surveyingOrganization,
surveyingUser: surveyingUser_FailSafe,
appVersion
};

const submitAction = () => {
Expand All @@ -58,7 +68,8 @@ const AssetSupplementary = ({ selectedAsset, setSelectedAsset, surveyingOrganiza
};

postSupplementaryAssetForm(postParams)
.then(() => {
.then((r) => {
console.log(r)
submitAction();
})
.then(() => actions.resetForm())
Expand Down
5 changes: 4 additions & 1 deletion domains/DataCollection/Assets/NewAssets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import AssetCore from './AssetCore';
import AssetSupplementary from './AssetSupplementary';

const NewAsset = ({
selectedAsset, setSelectedAsset, surveyingOrganization, assetPageIndex
selectedAsset, setSelectedAsset, surveyingOrganization, assetPageIndex,
surveyingUser
}) => (
<View>
<PagerView style={styles.viewPager} initialPage={assetPageIndex}>
Expand All @@ -15,13 +16,15 @@ const NewAsset = ({
setSelectedAsset={setSelectedAsset}
selectedAsset={selectedAsset}
surveyingOrganization={surveyingOrganization}
surveyingUser={surveyingUser}
/>
</View>
<View key="2" style={styles.page}>
<AssetSupplementary
setSelectedAsset={setSelectedAsset}
selectedAsset={selectedAsset}
surveyingOrganization={surveyingOrganization}
surveyingUser={surveyingUser}
/>
</View>
</PagerView>
Expand Down
1 change: 1 addition & 0 deletions domains/DataCollection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const DataCollection = ({ navigation }) => {
</Button>
<Assets
surveyingOrganization={surveyingOrganization}
surveyingUser={surveyingUser}
selectedAsset={selectedAsset}
setSelectedAsset={setSelectedAsset}
navigateToNewAssets={navigateToNewAssets}
Expand Down

0 comments on commit 46d42dc

Please sign in to comment.