Skip to content

Commit

Permalink
Save booking data to session storage in CheckoutPage.setInitialValues…
Browse files Browse the repository at this point in the history
… function instead of on ListingPage
  • Loading branch information
OtterleyW committed Oct 2, 2020
1 parent 3d6099a commit c18f14c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
9 changes: 8 additions & 1 deletion src/containers/CheckoutPage/CheckoutPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,14 @@ const CheckoutPage = compose(
injectIntl
)(CheckoutPageComponent);

CheckoutPage.setInitialValues = initialValues => setInitialValues(initialValues);
CheckoutPage.setInitialValues = (initialValues, saveToSessionStorage = false) => {
if (saveToSessionStorage) {
const { listing, bookingData, bookingDates } = initialValues;
storeData(bookingData, bookingDates, listing, null, STORAGE_KEY);
}

return setInitialValues(initialValues);
};

CheckoutPage.displayName = 'CheckoutPage';

Expand Down
25 changes: 5 additions & 20 deletions src/containers/ListingPage/ListingPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ import SectionRulesMaybe from './SectionRulesMaybe';
import SectionMapMaybe from './SectionMapMaybe';
import css from './ListingPage.css';

import { storeData } from '../CheckoutPage/CheckoutPageSessionHelpers';
// This storage key is used in sessionStorage and it needs to be same as on CheckoutPage
const STORAGE_KEY = 'CheckoutPage';

const MIN_LENGTH_FOR_LONG_WORDS_IN_TITLE = 16;

const { UUID } = sdkTypes;
Expand Down Expand Up @@ -123,25 +119,13 @@ export class ListingPageComponent extends Component {
confirmPaymentError: null,
};

if (!this.props.currentUser) {
// Save information about booking to sessionStorage so that we can redirect
// user directly to CheckoutPage after authentication with idp (e.g. Facebook)
storeData(
bookingData,
{
bookingStart: bookingDates.startDate,
bookingEnd: bookingDates.endDate,
},
listing,
null,
STORAGE_KEY
);
}
const saveToSessionStorage = !this.props.currentUser;

const routes = routeConfiguration();
// Customize checkout page state with current listing and selected bookingDates
const { setInitialValues } = findRouteByRouteName('CheckoutPage', routes);
callSetInitialValues(setInitialValues, initialValues);

callSetInitialValues(setInitialValues, initialValues, saveToSessionStorage);

// Clear previous Stripe errors from store if there is any
onInitializeCardPaymentData();
Expand Down Expand Up @@ -618,7 +602,8 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => ({
onManageDisableScrolling: (componentId, disableScrolling) =>
dispatch(manageDisableScrolling(componentId, disableScrolling)),
callSetInitialValues: (setInitialValues, values) => dispatch(setInitialValues(values)),
callSetInitialValues: (setInitialValues, values, saveToSessionStorage) =>
dispatch(setInitialValues(values, saveToSessionStorage)),
onFetchTransactionLineItems: (bookingData, listingId, isOwnListing) =>
dispatch(fetchTransactionLineItems(bookingData, listingId, isOwnListing)),
onSendEnquiry: (listingId, message) => dispatch(sendEnquiry(listingId, message)),
Expand Down

0 comments on commit c18f14c

Please sign in to comment.