mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 12:43:11 +10:00
Try to keep policy related publicData inside EditListingPoliciesForm
This commit is contained in:
parent
0718ebc663
commit
5655de04e6
5 changed files with 67 additions and 54 deletions
|
|
@ -45,7 +45,7 @@ const EditListingPoliciesPanel = props => {
|
|||
<h1 className={css.title}>{panelTitle}</h1>
|
||||
<EditListingPoliciesForm
|
||||
className={css.form}
|
||||
initialValues={{ ...publicData }}
|
||||
publicData={publicData}
|
||||
onSubmit={onSubmit}
|
||||
onChange={onChange}
|
||||
saveActionMsg={submitButtonText}
|
||||
|
|
|
|||
|
|
@ -124,10 +124,9 @@ const EditListingWizardTab = props => {
|
|||
{...panelProps(POLICY)}
|
||||
submitButtonText={intl.formatMessage({ id: submitButtonTranslationKey })}
|
||||
onSubmit={values => {
|
||||
const { saunaRules = '' } = values;
|
||||
const updateValues = {
|
||||
publicData: {
|
||||
saunaRules,
|
||||
...values,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import EditListingPoliciesForm from './EditListingPoliciesForm';
|
|||
export const Empty = {
|
||||
component: EditListingPoliciesForm,
|
||||
props: {
|
||||
publicData: {},
|
||||
onSubmit: values => {
|
||||
console.log('Submit EditListingPoliciesForm with (unformatted) values:', values);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import React from 'react';
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { compose } from 'redux';
|
||||
import { reduxForm, propTypes as formPropTypes } from 'redux-form';
|
||||
|
|
@ -9,62 +9,74 @@ import { Form, Button, TextInputField } from '../../components';
|
|||
|
||||
import css from './EditListingPoliciesForm.css';
|
||||
|
||||
export const EditListingPoliciesFormComponent = props => {
|
||||
const {
|
||||
className,
|
||||
disabled,
|
||||
handleSubmit,
|
||||
intl,
|
||||
form,
|
||||
invalid,
|
||||
saveActionMsg,
|
||||
submitting,
|
||||
updated,
|
||||
updateError,
|
||||
updateInProgress,
|
||||
} = props;
|
||||
export class EditListingPoliciesFormComponent extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
const rulesLabelMessage = intl.formatMessage({ id: 'EditListingPoliciesForm.rulesLabel' });
|
||||
const saunaRulesPlaceholderMessage = intl.formatMessage({
|
||||
id: 'EditListingPoliciesForm.rulesPlaceholder',
|
||||
});
|
||||
// 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 errorMessage = updateError ? (
|
||||
<p className={css.error}>
|
||||
<FormattedMessage id="EditListingPoliciesForm.updateFailed" />
|
||||
</p>
|
||||
) : null;
|
||||
render() {
|
||||
const {
|
||||
className,
|
||||
disabled,
|
||||
handleSubmit,
|
||||
intl,
|
||||
form,
|
||||
invalid,
|
||||
saveActionMsg,
|
||||
submitting,
|
||||
updated,
|
||||
updateError,
|
||||
updateInProgress,
|
||||
} = this.props;
|
||||
|
||||
const classes = classNames(css.root, className);
|
||||
const submitReady = updated;
|
||||
const submitInProgress = submitting || updateInProgress;
|
||||
const submitDisabled = invalid || disabled || submitInProgress;
|
||||
const rulesLabelMessage = intl.formatMessage({ id: 'EditListingPoliciesForm.rulesLabel' });
|
||||
const saunaRulesPlaceholderMessage = intl.formatMessage({
|
||||
id: 'EditListingPoliciesForm.rulesPlaceholder',
|
||||
});
|
||||
|
||||
return (
|
||||
<Form className={classes} onSubmit={handleSubmit}>
|
||||
{errorMessage}
|
||||
const errorMessage = updateError ? (
|
||||
<p className={css.error}>
|
||||
<FormattedMessage id="EditListingPoliciesForm.updateFailed" />
|
||||
</p>
|
||||
) : null;
|
||||
|
||||
<TextInputField
|
||||
className={css.policy}
|
||||
type="textarea"
|
||||
name="saunaRules"
|
||||
id={`${form}.saunaRules`}
|
||||
label={rulesLabelMessage}
|
||||
placeholder={saunaRulesPlaceholderMessage}
|
||||
/>
|
||||
const classes = classNames(css.root, className);
|
||||
const submitReady = updated;
|
||||
const submitInProgress = submitting || updateInProgress;
|
||||
const submitDisabled = invalid || disabled || submitInProgress;
|
||||
|
||||
<Button
|
||||
className={css.submitButton}
|
||||
type="submit"
|
||||
inProgress={submitInProgress}
|
||||
disabled={submitDisabled}
|
||||
ready={submitReady}
|
||||
>
|
||||
{saveActionMsg}
|
||||
</Button>
|
||||
</Form>
|
||||
);
|
||||
};
|
||||
return (
|
||||
<Form className={classes} onSubmit={handleSubmit}>
|
||||
{errorMessage}
|
||||
|
||||
<TextInputField
|
||||
className={css.policy}
|
||||
type="textarea"
|
||||
name="saunaRules"
|
||||
id={`${form}.saunaRules`}
|
||||
label={rulesLabelMessage}
|
||||
placeholder={saunaRulesPlaceholderMessage}
|
||||
/>
|
||||
|
||||
<Button
|
||||
className={css.submitButton}
|
||||
type="submit"
|
||||
inProgress={submitInProgress}
|
||||
disabled={submitDisabled}
|
||||
ready={submitReady}
|
||||
>
|
||||
{saveActionMsg}
|
||||
</Button>
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
EditListingPoliciesFormComponent.defaultProps = {
|
||||
selectedPlace: null,
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ describe('EditListingPoliciesForm', () => {
|
|||
const tree = renderShallow(
|
||||
<EditListingPoliciesFormComponent
|
||||
{...fakeFormProps}
|
||||
publicData={{}}
|
||||
intl={fakeIntl}
|
||||
dispatch={noop}
|
||||
onSubmit={v => v}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue