diff --git a/src/components/EditListingLocationPanel/EditListingLocationPanel.js b/src/components/EditListingLocationPanel/EditListingLocationPanel.js
index c9aa33c0..43f537b2 100644
--- a/src/components/EditListingLocationPanel/EditListingLocationPanel.js
+++ b/src/components/EditListingLocationPanel/EditListingLocationPanel.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { FormattedMessage } from 'react-intl';
@@ -8,77 +8,100 @@ import { EditListingLocationForm } from '../../forms';
import css from './EditListingLocationPanel.css';
-const EditListingLocationPanel = props => {
- const {
- className,
- rootClassName,
- listing,
- onSubmit,
- onChange,
- submitButtonText,
- panelUpdated,
- updateInProgress,
- errors,
- } = props;
+class EditListingLocationPanel extends Component {
+ constructor(props) {
+ super(props);
- const classes = classNames(rootClassName || css.root, className);
- const currentListing = ensureOwnListing(listing);
- const { geolocation, publicData } = currentListing.attributes;
+ this.getInitialValues = this.getInitialValues.bind(this);
- const panelTitle = currentListing.id ? (
- }}
- />
- ) : (
-
- );
+ this.state = {
+ initialValues: this.getInitialValues(),
+ };
+ }
- // Only render current search if full place object is available in the URL params
- // TODO bounds and country are missing - those need to be queried directly from Google Places
- const locationFieldsPresent =
- publicData && publicData.location && publicData.location.address && geolocation;
- const location = publicData && publicData.location ? publicData.location : {};
- const { address, building } = location;
+ getInitialValues() {
+ const { listing } = this.props;
+ const currentListing = ensureOwnListing(listing);
+ const { geolocation, publicData } = currentListing.attributes;
- const initialSearchFormValues = {
- building,
- location: locationFieldsPresent
- ? {
- search: address,
- selectedPlace: { address, origin: geolocation },
- }
- : null,
- };
+ // Only render current search if full place object is available in the URL params
+ // TODO bounds and country are missing - those need to be queried directly from Google Places
+ const locationFieldsPresent =
+ publicData && publicData.location && publicData.location.address && geolocation;
+ const location = publicData && publicData.location ? publicData.location : {};
+ const { address, building } = location;
- return (
-
-
{panelTitle}
- {
- const { building = '', location } = values;
- const {
- selectedPlace: { address, origin },
- } = location;
- const updateValues = {
- geolocation: origin,
- publicData: {
- location: { address, building },
- },
- };
- onSubmit(updateValues);
- }}
- onChange={onChange}
- saveActionMsg={submitButtonText}
- updated={panelUpdated}
- updateError={errors.updateListingError}
- updateInProgress={updateInProgress}
+ return {
+ building,
+ location: locationFieldsPresent
+ ? {
+ search: address,
+ selectedPlace: { address, origin: geolocation },
+ }
+ : null,
+ };
+ }
+
+ render() {
+ const {
+ className,
+ rootClassName,
+ listing,
+ onSubmit,
+ onChange,
+ submitButtonText,
+ panelUpdated,
+ updateInProgress,
+ errors,
+ } = this.props;
+
+ const classes = classNames(rootClassName || css.root, className);
+ const currentListing = ensureOwnListing(listing);
+
+ const panelTitle = currentListing.id ? (
+ }}
/>
-
- );
-};
+ ) : (
+
+ );
+
+ return (
+
+
{panelTitle}
+ {
+ const { building = '', location } = values;
+ const {
+ selectedPlace: { address, origin },
+ } = location;
+ const updateValues = {
+ geolocation: origin,
+ publicData: {
+ location: { address, building },
+ },
+ };
+ this.setState({
+ initialValues: {
+ building,
+ location: { search: address, selectedPlace: { address, origin } },
+ },
+ });
+ onSubmit(updateValues);
+ }}
+ onChange={onChange}
+ saveActionMsg={submitButtonText}
+ updated={panelUpdated}
+ updateError={errors.updateListingError}
+ updateInProgress={updateInProgress}
+ />
+
+ );
+ }
+}
const { func, object, string, bool } = PropTypes;