1
0
mirror of https://github.com/ascribe/onion.git synced 2024-06-28 16:48:04 +02:00

Show AdditionalDetailsModal from SubmitButton when details need to be filled in

This commit is contained in:
Brett Sun 2015-11-05 11:58:32 +01:00
parent adf0d411d6
commit 4ca8ca8feb

View File

@ -3,19 +3,30 @@
import React from 'react'; import React from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import LumenusAdditionalDataForm from '../lumenus_forms/lumenus_additional_data_form';
import ConsignButton from '../../../../../ascribe_buttons/acls/consign_button'; import ConsignButton from '../../../../../ascribe_buttons/acls/consign_button';
import AclFormFactory from '../../../../../ascribe_forms/acl_form_factory';
import ConsignForm from '../../../../../ascribe_forms/form_consign';
import ModalWrapper from '../../../../../ascribe_modal/modal_wrapper';
import PieceActions from '../../../../../../actions/piece_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';
import ApiUrls from '../../../../../../constants/api_urls';
import { getAclFormDataId } from '../../../../../../utils/form_utils';
import { getLangText } from '../../../../../../utils/lang_utils'; import { getLangText } from '../../../../../../utils/lang_utils';
let LumenusSubmitButton = React.createClass({ let LumenusSubmitButton = React.createClass({
propTypes: { propTypes: {
availableAcls: React.PropTypes.object.isRequired, availableAcls: React.PropTypes.object.isRequired,
currentUser: React.PropTypes.object, currentUser: React.PropTypes.object.isRequired,
pieceOrEditions: React.PropTypes.array, editions: React.PropTypes.array.isRequired,
handleSuccess: React.PropTypes.func, handleSuccess: React.PropTypes.func.isRequired,
className: React.PropTypes.string, className: React.PropTypes.string,
}, },
@ -25,6 +36,7 @@ let LumenusSubmitButton = React.createClass({
componentDidMount() { componentDidMount() {
WhitelabelStore.listen(this.onChange); WhitelabelStore.listen(this.onChange);
WhitelabelActions.fetchWhitelabel(); WhitelabelActions.fetchWhitelabel();
}, },
@ -36,19 +48,79 @@ let LumenusSubmitButton = React.createClass({
this.setState(state); this.setState(state);
}, },
render() { getFormDataId() {
const { availableAcls, currentUser, className, pieceOrEditions, handleSuccess } = this.props; return getAclFormDataId(false, this.props.editions);
},
return ( getAggregateEditionDetails() {
<ConsignButton const { editions } = this.props;
availableAcls={availableAcls}
buttonAcceptName={getLangText('CONSIGN TO LUMENUS')} // Currently, we only care if all the given editions are from the same parent piece
email={this.state.whitelabel.user} // and if they can be submitted
currentUser={currentUser} return editions.reduce((details, curEdition) => {
handleSuccess={handleSuccess} return {
pieceOrEditions={pieceOrEditions} solePieceId: details.solePieceId === curEdition.parent ? details.solePieceId : null,
className={className} /> canSubmit: details.canSubmit && curEdition.acl.acl_wallet_submit
); };
}, {
solePieceId: editions.length > 0 ? editions[0].parent : null,
canSubmit: editions.length > 0 ? editions[0].acl.acl_wallet_submit : false
});
},
handleAdditionalDataSuccess(pieceId) {
// Fetch newly updated piece to update the views
PieceActions.fetchOne(pieceId);
this.refs.consignModal.show();
},
render() {
const { availableAcls, currentUser, className, editions, handleSuccess } = this.props;
const buttonTitle = getLangText('CONSIGN TO LUMENUS');
const { solePieceId, canSubmit } = this.getAggregateEditionDetails();
if (solePieceId && !canSubmit) {
return (
<span>
<ModalWrapper
trigger={
<button className={classNames('btn', 'btn-default', 'btn-sm', className)}>
{buttonTitle}
</button>
}
handleSuccess={this.handleAdditionalDataSuccess.bind(this, solePieceId)}
title={getLangText('Add additional information')}>
<LumenusAdditionalDataForm
pieceId={solePieceId} />
</ModalWrapper>
<ModalWrapper
ref="consignModal"
handleSuccess={handleSuccess}
title={getLangText('Consign artwork')}>
<AclFormFactory
action='acl_consign'
currentUser={currentUser}
email={this.state.whitelabel.user}
pieceOrEditions={editions}
showNotification />
</ModalWrapper>
</span>
);
} else {
return (
<ConsignButton
availableAcls={availableAcls}
buttonAcceptName={buttonTitle}
email={this.state.whitelabel.user}
currentUser={currentUser}
handleSuccess={handleSuccess}
pieceOrEditions={editions}
className={className} />
);
}
} }
}); });