import React from 'react';
import { useHistory } from 'react-router-dom';
import { connect } from 'react-redux';
import { withFormik, Form, FieldArray } from 'formik';
import * as Yup from 'yup';
import { Button, TextInput, Heading } from 'evergreen-ui';
import { LocationDocumentRelationFormArray } from './form-arrays/LocationDocumentRelationFormArray';
import styled from 'styled-components';
import { locationActions } from '../../../../state-management/location/actions';
import Location from '../../../../data/Location';
const FormStyle = styled.div`
padding: 3em;
form {
display: flex;
flex-direction: column;
}
`;
const LocationCreate = (props) => {
const {
values,
touched,
errors,
dirty,
handleChange,
handleBlur,
handleSubmit,
handleReset,
isSubmitting,
} = props;
let history = useHistory();
return (
Location: Create New
)
};
const formikEnhancer = withFormik({
mapPropsToValues: ({
name,
latitude,
longitude,
documentRelation,
dateCreated,
updatedAt,
lastModifiedBy
}) => {
return {
name: name || '',
latitude: latitude || '',
longitude: longitude || '',
documentRelation: documentRelation || [{}],
dateCreated: dateCreated,
updatedAt: updatedAt,
lastModifiedBy: lastModifiedBy
}
},
validationSchema: Yup.object().shape({
name: Yup.string().required('Name is required')
}),
handleSubmit: (values, { props, setSubmitting }) => {
let newLocation = new Location();
newLocation.name = values.name || '';
newLocation.latitude = values.latitude || '';
newLocation.longitude = values.longitude || '';
newLocation.documentRelation = values.documentRelation || [{}];
newLocation.dateCreated = values.dateCreated || new Date();
newLocation.updatedAt = values.updatedAt || new Date();
newLocation.lastModifiedBy = values.lastModifiedBy;
props.dispatch(locationActions.insertLocation(newLocation.apiObject()));
setSubmitting(false);
}
})(LocationCreate);
function mapStateToProps(state) {
const { } = state;
return { };
}
const LocationCreateConnection = connect(mapStateToProps)(formikEnhancer);
export { LocationCreateConnection as LocationCreate };