Review changes

This commit is contained in:
Vesa Luusua 2018-01-25 14:00:07 +02:00
parent 5655de04e6
commit 3f0d3b5790
8 changed files with 50 additions and 57 deletions

View file

@ -50,7 +50,17 @@ const EditListingDescriptionPanel = props => {
className={css.form}
initialValues={{ title, description, ...customAttributes }}
saveActionMsg={submitButtonText}
onSubmit={onSubmit}
onSubmit={values => {
const { title, description, category } = values;
const updateValues = {
title,
description,
customAttributes: { category },
publicData: { category },
};
onSubmit(updateValues);
}}
onChange={onChange}
updated={panelUpdated}
updateError={errors.updateListingError}

View file

@ -63,7 +63,17 @@ const EditListingLocationPanel = props => {
<EditListingLocationForm
className={css.form}
initialValues={initialSearchFormValues}
onSubmit={onSubmit}
onSubmit={values => {
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}

View file

@ -46,7 +46,14 @@ const EditListingPoliciesPanel = props => {
<EditListingPoliciesForm
className={css.form}
publicData={publicData}
onSubmit={onSubmit}
onSubmit={values => {
const updateValues = {
publicData: {
...values,
},
};
onSubmit(updateValues);
}}
onChange={onChange}
saveActionMsg={submitButtonText}
updated={panelUpdated}

View file

@ -56,7 +56,7 @@ const tabCompleted = (tab, listing) => {
case DESCRIPTION:
return !!(description && title);
case POLICY:
return !!(publicData && typeof publicData.saunaRules !== 'undefined');
return !!(publicData && typeof publicData.rules !== 'undefined');
case LOCATION:
return !!(geolocation && publicData && publicData.location && publicData.location.address);
case PRICING:
@ -107,6 +107,7 @@ class EditListingWizard extends Component {
const { id, className, rootClassName, params, listing, viewport, intl, ...rest } = this.props;
const selectedTab = params.tab;
const isNew = params.type === 'new';
const rootClasses = rootClassName || css.root;
const classes = classNames(rootClasses, className);
const currentListing = ensureListing(listing);
@ -148,7 +149,7 @@ class EditListingWizard extends Component {
tabLabel={tabLabel(intl, tab)}
tabLinkProps={tabLink(tab)}
selected={selectedTab === tab}
disabled={!tabsStatus[tab]}
disabled={isNew && !tabsStatus[tab]}
tab={tab}
intl={intl}
params={params}

View file

@ -64,12 +64,9 @@ const EditListingWizardTab = props => {
const isNew = params.type === 'new';
const currentListing = ensureListing(listing);
const onUpsertListingDraft = currentListing.id ? onUpdateListingDraft : onCreateListingDraft;
const update = (tab, values) => {
onUpdateListing(tab, { ...values, id: currentListing.id });
};
const onCompleteEditListingWizardTab = (tab, updateValues) => {
if (isNew) {
const onUpsertListingDraft = currentListing.id ? onUpdateListingDraft : onCreateListingDraft;
onUpsertListingDraft(updateValues);
// Redirect to next tab
const pathParams = pathParamsToNextTab(params, tab, marketplaceTabs);
@ -77,7 +74,7 @@ const EditListingWizardTab = props => {
createResourceLocatorString('EditListingPage', routeConfiguration(), pathParams, {})
);
} else {
update(tab, updateValues);
onUpdateListing(tab, { ...updateValues, id: currentListing.id });
}
};
@ -102,15 +99,7 @@ const EditListingWizardTab = props => {
{...panelProps(DESCRIPTION)}
submitButtonText={intl.formatMessage({ id: submitButtonTranslationKey })}
onSubmit={values => {
const { title, description, category } = values;
const updateValues = {
title,
description,
customAttributes: { category },
publicData: { category },
};
onCompleteEditListingWizardTab(tab, updateValues);
onCompleteEditListingWizardTab(tab, values);
}}
/>
);
@ -124,13 +113,7 @@ const EditListingWizardTab = props => {
{...panelProps(POLICY)}
submitButtonText={intl.formatMessage({ id: submitButtonTranslationKey })}
onSubmit={values => {
const updateValues = {
publicData: {
...values,
},
};
onCompleteEditListingWizardTab(tab, updateValues);
onCompleteEditListingWizardTab(tab, values);
}}
/>
);
@ -144,16 +127,7 @@ const EditListingWizardTab = props => {
{...panelProps(LOCATION)}
submitButtonText={intl.formatMessage({ id: submitButtonTranslationKey })}
onSubmit={values => {
const { building = '', location } = values;
const { selectedPlace: { address, origin } } = location;
const updateValues = {
geolocation: origin,
publicData: {
location: { address, building },
},
};
onCompleteEditListingWizardTab(tab, updateValues);
onCompleteEditListingWizardTab(tab, values);
}}
/>
);
@ -189,13 +163,13 @@ const EditListingWizardTab = props => {
onPayoutDetailsSubmit={onPayoutDetailsSubmit}
onSubmit={values => {
const { images: updatedImages } = values;
const updateValues = { ...listing.attributes, images: updatedImages };
const imageIds = updatedImages.map(img => img.imageId || img.id);
const updateValues = { ...listing.attributes, images: imageIds };
if (isNew) {
onCreateListing(updateValues);
} else {
const imageIds = updatedImages.map(img => img.imageId || img.id);
update(PHOTOS, { images: imageIds });
onUpdateListing(PHOTOS, { images: imageIds, id: currentListing.id });
}
}}
onUpdateImageOrder={onUpdateImageOrder}

View file

@ -29,15 +29,6 @@ import css from './EditListingPage.css';
const { UUID } = sdkTypes;
const formatRequestData = values => {
const { images, ...rest } = values;
return {
images: images.map(i => i.imageId),
...rest,
};
};
// N.B. All the presentational content needs to be extracted to their own components
export const EditListingPageComponent = props => {
const {
@ -227,7 +218,7 @@ const mapStateToProps = state => {
};
const mapDispatchToProps = dispatch => ({
onCreateListing: values => dispatch(requestCreateListing(formatRequestData(values))),
onCreateListing: values => dispatch(requestCreateListing(values)),
onUpdateListing: (tab, values) => dispatch(requestUpdateListing(tab, values)),
onCreateListingDraft: values => dispatch(createListingDraft(values)),
onImageUpload: data => dispatch(requestImageUpload(data)),

View file

@ -16,8 +16,8 @@ export class EditListingPoliciesFormComponent extends Component {
// Initialize form inside this component reduces the amount of files that are tied to
// marketplace specific content in publicData.
const { initialize, publicData } = props;
const { saunaRules = '' } = publicData;
initialize({ saunaRules });
const { rules = '' } = publicData;
initialize({ rules });
}
render() {
@ -36,7 +36,7 @@ export class EditListingPoliciesFormComponent extends Component {
} = this.props;
const rulesLabelMessage = intl.formatMessage({ id: 'EditListingPoliciesForm.rulesLabel' });
const saunaRulesPlaceholderMessage = intl.formatMessage({
const rulesPlaceholderMessage = intl.formatMessage({
id: 'EditListingPoliciesForm.rulesPlaceholder',
});
@ -58,10 +58,10 @@ export class EditListingPoliciesFormComponent extends Component {
<TextInputField
className={css.policy}
type="textarea"
name="saunaRules"
id={`${form}.saunaRules`}
name="rules"
id={`${form}.rules`}
label={rulesLabelMessage}
placeholder={saunaRulesPlaceholderMessage}
placeholder={rulesPlaceholderMessage}
/>
<Button

View file

@ -6,9 +6,9 @@ exports[`EditListingPoliciesForm matches snapshot 1`] = `
onSubmit={[Function]}
>
<TextInputField
id="fakeTestForm.saunaRules"
id="fakeTestForm.rules"
label="EditListingPoliciesForm.rulesLabel"
name="saunaRules"
name="rules"
placeholder="EditListingPoliciesForm.rulesPlaceholder"
type="textarea"
/>