Custom attributes: EditListingPage can handle customAttributes

This commit is contained in:
Vesa Luusua 2017-12-19 19:35:32 +02:00
parent 105dfbce3d
commit 5c37ecdccd
4 changed files with 17 additions and 9 deletions

View file

@ -24,7 +24,7 @@ const EditListingDescriptionPanel = props => {
const classes = classNames(rootClassName || css.root, className);
const currentListing = ensureListing(listing);
const { description, title } = currentListing.attributes;
const { description, title, customAttributes } = currentListing.attributes;
const listingTitle = title || '';
const listingLink = currentListing.id ? (
<NamedLink name="ListingPage" params={{ id: currentListing.id.uuid, slug: createSlug(title) }}>
@ -48,7 +48,7 @@ const EditListingDescriptionPanel = props => {
<h1 className={css.title}>{panelTitle}</h1>
<EditListingDescriptionForm
className={css.form}
initialValues={{ title, description }}
initialValues={{ title, description, ...customAttributes }}
saveActionMsg={submitButtonText}
onSubmit={onSubmit}
onChange={onChange}

View file

@ -129,15 +129,18 @@ const EditListingWizard = props => {
submitButtonText={submitText(intl, isNew, DESCRIPTION)}
onChange={onChange}
onSubmit={values => {
const { title, description, ...rest } = values;
const updateValues = { title, description, customAttributes: { ...rest } };
if (isNew) {
onUpsertListingDraft(values);
onUpsertListingDraft(updateValues);
const pathParams = tabParams(LOCATION);
// Redirect to location tab
history.push(
createResourceLocatorString('EditListingPage', routeConfiguration(), pathParams, {})
);
} else {
update(DESCRIPTION, values);
update(DESCRIPTION, updateValues);
}
}}
/>
@ -272,6 +275,7 @@ EditListingWizard.propTypes = {
listing: shape({
attributes: shape({
address: string,
customAttributes: object, // structure (key: value) can be defined in management console
description: string,
geolocation: object,
pricing: object,

View file

@ -187,18 +187,21 @@ export const updateImageOrder = imageOrder => ({
});
export const createListingDraft = listingData => {
const { description, title } = listingData;
const { title, description, customAttributes } = listingData;
return {
type: CREATE_LISTING_DRAFT,
payload: { attributes: { title, description } },
payload: { attributes: { title, description, customAttributes } },
};
};
export const updateListingDraft = listingData => {
const { address, description, title, geolocation, images, price } = listingData;
const { address, description, title, geolocation, images, price, customAttributes } = listingData;
return {
type: UPDATE_LISTING_DRAFT,
payload: { attributes: { address, description, geolocation, price, title }, images },
payload: {
attributes: { address, description, geolocation, price, title, customAttributes },
images,
},
};
};

View file

@ -28,7 +28,7 @@ import {
import css from './EditListingPage.css';
const formatRequestData = values => {
const { address, description, images, geolocation, price, title } = values;
const { address, description, images, geolocation, price, title, customAttributes } = values;
return {
address,
@ -37,6 +37,7 @@ const formatRequestData = values => {
images: images.map(i => i.imageId),
price,
title,
customAttributes,
};
};