mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 20:53:24 +10:00
Merge pull request #470 from sharetribe/address-parsing-fix
Address parsing changed
This commit is contained in:
commit
123ada3a0b
3 changed files with 28 additions and 18 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React, { PropTypes } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import { ensureListing } from '../../util/data';
|
||||
import { ensureListing, parseAddress } from '../../util/data';
|
||||
import { createSlug } from '../../util/urlHelpers';
|
||||
import { NamedLink } from '../../components';
|
||||
import { EditListingLocationForm } from '../../containers';
|
||||
|
|
@ -47,15 +47,7 @@ const EditListingLocationPanel = props => {
|
|||
|
||||
// TODO location address is currently serialized inside address field (API will change later)
|
||||
// Content is something like { locationAddress: 'Street, Province, Country', building: 'A 42' };
|
||||
let locationAddress = '';
|
||||
let building = '';
|
||||
try {
|
||||
const deserializedAddress = JSON.parse(address || '{}');
|
||||
locationAddress = deserializedAddress.locationAddress;
|
||||
building = deserializedAddress.building;
|
||||
} catch (e) {
|
||||
locationAddress = address;
|
||||
}
|
||||
const { locationAddress, building } = parseAddress(address);
|
||||
|
||||
const initialSearchFormValues = {
|
||||
building,
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import { types } from '../../util/sdkLoader';
|
|||
import { createSlug } from '../../util/urlHelpers';
|
||||
import { formatMoney } from '../../util/currency';
|
||||
import { createResourceLocatorString, findRouteByRouteName } from '../../util/routes';
|
||||
import { ensureListing, ensureUser } from '../../util/data';
|
||||
import { ensureListing, ensureUser, parseAddress } from '../../util/data';
|
||||
import {
|
||||
AvatarLarge,
|
||||
AvatarMedium,
|
||||
|
|
@ -259,13 +259,7 @@ export class ListingPageComponent extends Component {
|
|||
|
||||
// TODO location address is currently serialized inside address field (API will change later)
|
||||
// Content is something like { locationAddress: 'Street, Province, Country', building: 'A 42' };
|
||||
let locationAddress = '';
|
||||
try {
|
||||
const deserializedAddress = JSON.parse(address || '{}');
|
||||
locationAddress = deserializedAddress.locationAddress;
|
||||
} catch (e) {
|
||||
locationAddress = address;
|
||||
}
|
||||
const { locationAddress } = parseAddress(address);
|
||||
|
||||
const bookBtnMessage = intl.formatMessage({ id: 'ListingPage.ctaButtonMessage' });
|
||||
const { formattedPrice, priceTitle } = priceData(price, intl);
|
||||
|
|
|
|||
|
|
@ -214,3 +214,27 @@ export const userAbbreviatedName = (user, bannedUserAbbreviatedName) => {
|
|||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Temporary utility function to parse address field.
|
||||
* Location address is currently serialized inside address field.
|
||||
*
|
||||
* TODO: address will be moved to custom field, when API supports custom fields.
|
||||
*/
|
||||
export const parseAddress = address => {
|
||||
if (typeof address !== 'string') {
|
||||
throw new Error('Address must be a string.');
|
||||
}
|
||||
|
||||
// Content is serialized as { locationAddress: 'Street, Province, Country', building: 'A 42' };
|
||||
let locationAddress = '';
|
||||
let building = '';
|
||||
try {
|
||||
const deserializedAddress = JSON.parse(address || '{}');
|
||||
locationAddress = deserializedAddress.locationAddress || '';
|
||||
building = deserializedAddress.building || '';
|
||||
} catch (e) {
|
||||
locationAddress = address;
|
||||
}
|
||||
return { locationAddress, building };
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue