mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 10:25:08 +01:00
Load piece when necessary in MarketRegisterPiece
This commit is contained in:
parent
8d9df43339
commit
4c4e5e0004
@ -6,11 +6,15 @@ import { History } from 'react-router';
|
|||||||
import Col from 'react-bootstrap/lib/Col';
|
import Col from 'react-bootstrap/lib/Col';
|
||||||
import Row from 'react-bootstrap/lib/Row';
|
import Row from 'react-bootstrap/lib/Row';
|
||||||
|
|
||||||
|
import PieceStore from '../../../../../stores/piece_store';
|
||||||
import PieceActions from '../../../../../actions/piece_actions';
|
import PieceActions from '../../../../../actions/piece_actions';
|
||||||
|
|
||||||
import PieceListStore from '../../../../../stores/piece_list_store';
|
import PieceListStore from '../../../../../stores/piece_list_store';
|
||||||
import PieceListActions from '../../../../../actions/piece_list_actions';
|
import PieceListActions from '../../../../../actions/piece_list_actions';
|
||||||
|
|
||||||
import UserStore from '../../../../../stores/user_store';
|
import UserStore from '../../../../../stores/user_store';
|
||||||
import UserActions from '../../../../../actions/user_actions';
|
import UserActions from '../../../../../actions/user_actions';
|
||||||
|
|
||||||
import WhitelabelActions from '../../../../../actions/whitelabel_actions';
|
import WhitelabelActions from '../../../../../actions/whitelabel_actions';
|
||||||
import WhitelabelStore from '../../../../../stores/whitelabel_store';
|
import WhitelabelStore from '../../../../../stores/whitelabel_store';
|
||||||
|
|
||||||
@ -35,6 +39,7 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
getInitialState(){
|
getInitialState(){
|
||||||
return mergeOptions(
|
return mergeOptions(
|
||||||
PieceListStore.getState(),
|
PieceListStore.getState(),
|
||||||
|
PieceStore.getInitialState(),
|
||||||
UserStore.getState(),
|
UserStore.getState(),
|
||||||
WhitelabelStore.getState(),
|
WhitelabelStore.getState(),
|
||||||
{
|
{
|
||||||
@ -44,19 +49,27 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
PieceListStore.listen(this.onChange);
|
PieceListStore.listen(this.onChange);
|
||||||
|
PieceStore.listen(this.onChange);
|
||||||
UserStore.listen(this.onChange);
|
UserStore.listen(this.onChange);
|
||||||
WhitelabelStore.listen(this.onChange);
|
WhitelabelStore.listen(this.onChange);
|
||||||
|
|
||||||
UserActions.fetchCurrentUser();
|
UserActions.fetchCurrentUser();
|
||||||
WhitelabelActions.fetchWhitelabel();
|
WhitelabelActions.fetchWhitelabel();
|
||||||
|
|
||||||
// Reset the piece store to make sure that we don't display old data
|
const queryParams = this.props.location.query;
|
||||||
// if the user repeatedly registers works
|
|
||||||
PieceActions.updatePiece({});
|
// Load the correct piece if the user loads the second step directly
|
||||||
|
// by pressing on the back button or using the url
|
||||||
|
// We're using 'in' here as we want to know if 'piece_id' is present in the url,
|
||||||
|
// we don't care about the value.
|
||||||
|
if ('piece_id' in queryParams) {
|
||||||
|
PieceActions.fetchPiece(queryParams.piece_id);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
PieceListStore.unlisten(this.onChange);
|
PieceListStore.unlisten(this.onChange);
|
||||||
|
PieceStore.unlisten(this.onChange);
|
||||||
UserStore.unlisten(this.onChange);
|
UserStore.unlisten(this.onChange);
|
||||||
WhitelabelStore.unlisten(this.onChange);
|
WhitelabelStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
@ -68,15 +81,12 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
handleRegisterSuccess(response) {
|
handleRegisterSuccess(response) {
|
||||||
this.refreshPieceList();
|
this.refreshPieceList();
|
||||||
|
|
||||||
// Use the response's piece for the next step if available
|
// Also load the newly registered piece for the next step
|
||||||
let pieceId = null;
|
|
||||||
if (response && response.piece) {
|
if (response && response.piece) {
|
||||||
pieceId = response.piece.id;
|
|
||||||
PieceActions.updatePiece(response.piece);
|
PieceActions.updatePiece(response.piece);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.incrementStep();
|
this.nextSlide({ piece_id: response.piece.id });
|
||||||
this.refs.slidesContainer.nextSlide({ piece_id: pieceId });
|
|
||||||
},
|
},
|
||||||
|
|
||||||
handleAdditionalDataSuccess() {
|
handleAdditionalDataSuccess() {
|
||||||
@ -85,21 +95,13 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
this.history.push('/collection');
|
this.history.push('/collection');
|
||||||
},
|
},
|
||||||
|
|
||||||
// We need to increase the step to lock the forms that are already filled out
|
nextSlide(queryParams) {
|
||||||
incrementStep() {
|
// We need to increase the step to lock the forms that are already filled out
|
||||||
this.setState({
|
this.setState({
|
||||||
step: this.state.step + 1
|
step: this.state.step + 1
|
||||||
});
|
});
|
||||||
},
|
|
||||||
|
|
||||||
getPieceFromQueryParam() {
|
this.refs.slidesContainer.nextSlide(queryParams);
|
||||||
const queryParams = this.props.location.query;
|
|
||||||
|
|
||||||
// Since every step of this register process is atomic,
|
|
||||||
// we may need to enter the process at step 1 or 2.
|
|
||||||
// If this is the case, we'll need the piece number to complete submission.
|
|
||||||
// It is encoded in the URL as a queryParam and we're checking for it here.
|
|
||||||
return queryParams && queryParams.piece_id;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
refreshPieceList() {
|
refreshPieceList() {
|
||||||
@ -114,7 +116,9 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { location } = this.props;
|
||||||
const {
|
const {
|
||||||
|
piece,
|
||||||
step,
|
step,
|
||||||
whitelabel: {
|
whitelabel: {
|
||||||
name: whitelabelName = 'Market'
|
name: whitelabelName = 'Market'
|
||||||
@ -130,7 +134,7 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
pending: 'glyphicon glyphicon-chevron-right',
|
pending: 'glyphicon glyphicon-chevron-right',
|
||||||
completed: 'glyphicon glyphicon-lock'
|
completed: 'glyphicon glyphicon-lock'
|
||||||
}}
|
}}
|
||||||
location={this.props.location}>
|
location={location}>
|
||||||
<div data-slide-title={getLangText('Register work')}>
|
<div data-slide-title={getLangText('Register work')}>
|
||||||
<Row className="no-margin">
|
<Row className="no-margin">
|
||||||
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
|
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
|
||||||
@ -142,7 +146,7 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
isFineUploaderActive={true}
|
isFineUploaderActive={true}
|
||||||
enableSeparateThumbnail={false}
|
enableSeparateThumbnail={false}
|
||||||
handleSuccess={this.handleRegisterSuccess}
|
handleSuccess={this.handleRegisterSuccess}
|
||||||
location={this.props.location}>
|
location={location}>
|
||||||
<Property
|
<Property
|
||||||
name="num_editions"
|
name="num_editions"
|
||||||
label={getLangText('Specify editions')}>
|
label={getLangText('Specify editions')}>
|
||||||
@ -160,8 +164,10 @@ let MarketRegisterPiece = React.createClass({
|
|||||||
<Row className="no-margin">
|
<Row className="no-margin">
|
||||||
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
|
<Col xs={12} sm={10} md={8} smOffset={1} mdOffset={2}>
|
||||||
<MarketAdditionalDataForm
|
<MarketAdditionalDataForm
|
||||||
|
extraData={piece.extra_data}
|
||||||
handleSuccess={this.handleAdditionalDataSuccess}
|
handleSuccess={this.handleAdditionalDataSuccess}
|
||||||
pieceId={this.getPieceFromQueryParam()}
|
otherData={piece.other_data}
|
||||||
|
pieceId={piece.id}
|
||||||
showHeading />
|
showHeading />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
Loading…
Reference in New Issue
Block a user