/* * * Edit * */ import React from 'react'; import { connect } from 'react-redux'; import { createStructuredSelector } from 'reselect'; import Container from 'components/Container'; import EditForm from 'components/EditForm'; import { setCurrentModelName, loadRecord, setRecordAttribute, editRecord, } from './actions'; import { makeSelectRecord, makeSelectLoading, makeSelectCurrentModelName, makeSelectEditing, } from './selectors'; import { makeSelectModels, } from 'containers/App/selectors'; export class Edit extends React.Component { // eslint-disable-line react/prefer-stateless-function componentWillMount() { this.props.setCurrentModelName(this.props.routeParams.slug.toLowerCase()); this.props.loadRecord(this.props.routeParams.id); } render() { // Detect current model structure from models list const currentModel = this.props.models[this.props.currentModelName]; const PluginHeader = this.props.exposedComponents.PluginHeader; let content =

Loading...

; if (currentModel && currentModel.attributes) { content = ( ); } const headersActions = [{ label: 'Cancel', class: 'btn-default', }, { label: this.props.editing ? 'Editing...' : 'Submit', class: 'btn-primary', onClick: this.props.editRecord, disabled: this.props.editing, }, { label: 'Delete', class: 'btn-danger', }]; return (
${this.props.routeParams.slug}` }} description={{ id: 'plugin-content-manager-description', defaultMessage: `Manage your ${this.props.routeParams.slug}` }} actions={headersActions} />

{content}
); } } Edit.propTypes = { setCurrentModelName: React.PropTypes.func, loadRecord: React.PropTypes.func, loading: React.PropTypes.bool, record: React.PropTypes.oneOfType([ React.PropTypes.object, React.PropTypes.bool, ]), models: React.PropTypes.oneOfType([ React.PropTypes.object, React.PropTypes.bool, ]), editRecord: React.PropTypes.func, editing: React.PropTypes.bool, }; const mapStateToProps = createStructuredSelector({ record: makeSelectRecord(), loading: makeSelectLoading(), currentModelName: makeSelectCurrentModelName(), models: makeSelectModels(), editing: makeSelectEditing(), }); function mapDispatchToProps(dispatch) { return { setCurrentModelName: (currentModelName) => dispatch(setCurrentModelName(currentModelName)), loadRecord: (id) => dispatch(loadRecord(id)), setRecordAttribute: (key, value) => dispatch(setRecordAttribute(key, value)), editRecord: () => dispatch(editRecord()), dispatch, }; } export default connect(mapStateToProps, mapDispatchToProps)(Edit);