mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-31 02:26:50 +10:00
Clean up submit handling and naming
This commit is contained in:
parent
549811e6a4
commit
006f649f5a
1 changed files with 15 additions and 8 deletions
|
|
@ -62,20 +62,28 @@ export class ListingPageComponent extends Component {
|
|||
imageCarouselOpen: false,
|
||||
};
|
||||
|
||||
this.onSubmit = this.onSubmit.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
onSubmit(values) {
|
||||
handleSubmit(values) {
|
||||
const { flattenedRoutes, history, getListing, params, useInitialValues } = this.props;
|
||||
const listing = getListing(new UUID(params.id));
|
||||
|
||||
this.setState({ isBookingModalOpenOnMobile: false });
|
||||
|
||||
const { bookingDates } = values;
|
||||
|
||||
const initialValues = {
|
||||
listing,
|
||||
bookingDates: {
|
||||
bookingStart: bookingDates.startDate,
|
||||
bookingEnd: bookingDates.endDate,
|
||||
},
|
||||
};
|
||||
|
||||
// Customize checkout page state with current listing and selected bookingDates
|
||||
const { setInitialValues } = findRouteByRouteName('CheckoutPage', flattenedRoutes);
|
||||
const { startDate: bookingStart, endDate: bookingEnd } = values.bookingDates;
|
||||
const bookingDates = { bookingStart, bookingEnd };
|
||||
useInitialValues(setInitialValues, { listing, bookingDates, initiateOrderError: null });
|
||||
useInitialValues(setInitialValues, initialValues);
|
||||
|
||||
// Redirect to CheckoutPage
|
||||
history.push(
|
||||
|
|
@ -186,7 +194,7 @@ export class ListingPageComponent extends Component {
|
|||
if (isOwnListing || isClosed) {
|
||||
window.scrollTo(0, 0);
|
||||
} else {
|
||||
this.onSubmit(values);
|
||||
this.handleSubmit(values);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -418,8 +426,7 @@ const mapDispatchToProps = dispatch => ({
|
|||
onLogout: historyPush => dispatch(logout(historyPush)),
|
||||
onManageDisableScrolling: (componentId, disableScrolling) =>
|
||||
dispatch(manageDisableScrolling(componentId, disableScrolling)),
|
||||
useInitialValues: (setInitialValues, { listing, bookingDates, initiateOrderError }) =>
|
||||
dispatch(setInitialValues({ listing, bookingDates, initiateOrderError })),
|
||||
useInitialValues: (setInitialValues, values) => dispatch(setInitialValues(values)),
|
||||
});
|
||||
|
||||
const ListingPage = compose(connect(mapStateToProps, mapDispatchToProps), withRouter, injectIntl)(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue