mirror of
https://github.com/ascribe/onion.git
synced 2025-02-14 21:10:27 +01:00
Update RequestActionForm to use form utils
This commit is contained in:
parent
7e1f6a382a
commit
67fbfbd470
@ -16,9 +16,9 @@ import GlobalNotificationActions from '../../actions/global_notification_actions
|
|||||||
|
|
||||||
import ApiUrls from '../../constants/api_urls';
|
import ApiUrls from '../../constants/api_urls';
|
||||||
|
|
||||||
|
import { getAclFormDataId } from '../../utils/form_utils';
|
||||||
import { getLangText } from '../../utils/lang_utils.js';
|
import { getLangText } from '../../utils/lang_utils.js';
|
||||||
|
|
||||||
|
|
||||||
let RequestActionForm = React.createClass({
|
let RequestActionForm = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
pieceOrEditions: React.PropTypes.oneOfType([
|
pieceOrEditions: React.PropTypes.oneOfType([
|
||||||
@ -30,26 +30,26 @@ let RequestActionForm = React.createClass({
|
|||||||
handleSuccess: React.PropTypes.func
|
handleSuccess: React.PropTypes.func
|
||||||
},
|
},
|
||||||
|
|
||||||
isPiece(){
|
isPiece() {
|
||||||
return this.props.pieceOrEditions.constructor !== Array;
|
return this.props.pieceOrEditions.constructor !== Array;
|
||||||
},
|
},
|
||||||
|
|
||||||
getUrls() {
|
getUrls() {
|
||||||
let urls = {};
|
let urls = {};
|
||||||
|
|
||||||
if (this.props.notifications.action === 'consign'){
|
if (this.props.notifications.action === 'consign') {
|
||||||
urls.accept = ApiUrls.ownership_consigns_confirm;
|
urls.accept = ApiUrls.ownership_consigns_confirm;
|
||||||
urls.deny = ApiUrls.ownership_consigns_deny;
|
urls.deny = ApiUrls.ownership_consigns_deny;
|
||||||
} else if (this.props.notifications.action === 'unconsign'){
|
} else if (this.props.notifications.action === 'unconsign') {
|
||||||
urls.accept = ApiUrls.ownership_unconsigns;
|
urls.accept = ApiUrls.ownership_unconsigns;
|
||||||
urls.deny = ApiUrls.ownership_unconsigns_deny;
|
urls.deny = ApiUrls.ownership_unconsigns_deny;
|
||||||
} else if (this.props.notifications.action === 'loan' && !this.isPiece()){
|
} else if (this.props.notifications.action === 'loan' && !this.isPiece()) {
|
||||||
urls.accept = ApiUrls.ownership_loans_confirm;
|
urls.accept = ApiUrls.ownership_loans_confirm;
|
||||||
urls.deny = ApiUrls.ownership_loans_deny;
|
urls.deny = ApiUrls.ownership_loans_deny;
|
||||||
} else if (this.props.notifications.action === 'loan' && this.isPiece()){
|
} else if (this.props.notifications.action === 'loan' && this.isPiece()) {
|
||||||
urls.accept = ApiUrls.ownership_loans_pieces_confirm;
|
urls.accept = ApiUrls.ownership_loans_pieces_confirm;
|
||||||
urls.deny = ApiUrls.ownership_loans_pieces_deny;
|
urls.deny = ApiUrls.ownership_loans_pieces_deny;
|
||||||
} else if (this.props.notifications.action === 'loan_request' && this.isPiece()){
|
} else if (this.props.notifications.action === 'loan_request' && this.isPiece()) {
|
||||||
urls.accept = ApiUrls.ownership_loans_pieces_request_confirm;
|
urls.accept = ApiUrls.ownership_loans_pieces_request_confirm;
|
||||||
urls.deny = ApiUrls.ownership_loans_pieces_request_deny;
|
urls.deny = ApiUrls.ownership_loans_pieces_request_deny;
|
||||||
}
|
}
|
||||||
@ -57,37 +57,29 @@ let RequestActionForm = React.createClass({
|
|||||||
return urls;
|
return urls;
|
||||||
},
|
},
|
||||||
|
|
||||||
getFormData(){
|
getFormData() {
|
||||||
if (this.isPiece()) {
|
return getAclFormDataId(this.isPiece(), this.props.pieceOrEditions);
|
||||||
return {piece_id: this.props.pieceOrEditions.id};
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return {bitcoin_id: this.props.pieceOrEditions.map(function(edition){
|
|
||||||
return edition.bitcoin_id;
|
|
||||||
}).join()};
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
showNotification(option, action, owner) {
|
showNotification(option, action, owner) {
|
||||||
return () => {
|
return () => {
|
||||||
let message = getLangText('You have successfully') + ' ' + option + ' the ' + action + ' request ' + getLangText('from') + ' ' + owner;
|
const message = getLangText('You have successfully') + ' ' + option + ' the ' + action + ' request ' + getLangText('from') + ' ' + owner;
|
||||||
|
|
||||||
let notifications = new GlobalNotificationModel(message, 'success');
|
const notifications = new GlobalNotificationModel(message, 'success');
|
||||||
GlobalNotificationActions.appendGlobalNotification(notifications);
|
GlobalNotificationActions.appendGlobalNotification(notifications);
|
||||||
|
|
||||||
this.handleSuccess();
|
this.handleSuccess();
|
||||||
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSuccess() {
|
handleSuccess() {
|
||||||
if (this.isPiece()){
|
if (this.isPiece()) {
|
||||||
NotificationActions.fetchPieceListNotifications();
|
NotificationActions.fetchPieceListNotifications();
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
NotificationActions.fetchEditionListNotifications();
|
NotificationActions.fetchEditionListNotifications();
|
||||||
}
|
}
|
||||||
if(this.props.handleSuccess) {
|
|
||||||
|
if (typeof this.props.handleSuccess === 'function') {
|
||||||
this.props.handleSuccess();
|
this.props.handleSuccess();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -101,7 +93,7 @@ let RequestActionForm = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getAcceptButtonForm(urls) {
|
getAcceptButtonForm(urls) {
|
||||||
if(this.props.notifications.action === 'unconsign') {
|
if (this.props.notifications.action === 'unconsign') {
|
||||||
return (
|
return (
|
||||||
<UnconsignButton
|
<UnconsignButton
|
||||||
availableAcls={{'acl_unconsign': true}}
|
availableAcls={{'acl_unconsign': true}}
|
||||||
@ -110,7 +102,7 @@ let RequestActionForm = React.createClass({
|
|||||||
currentUser={this.props.currentUser}
|
currentUser={this.props.currentUser}
|
||||||
handleSuccess={this.handleSuccess} />
|
handleSuccess={this.handleSuccess} />
|
||||||
);
|
);
|
||||||
} else if(this.props.notifications.action === 'loan_request') {
|
} else if (this.props.notifications.action === 'loan_request') {
|
||||||
return (
|
return (
|
||||||
<LoanRequestButton
|
<LoanRequestButton
|
||||||
availableAcls={{'acl_loan_request': true}}
|
availableAcls={{'acl_loan_request': true}}
|
||||||
@ -141,8 +133,8 @@ let RequestActionForm = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getButtonForm() {
|
getButtonForm() {
|
||||||
let urls = this.getUrls();
|
const urls = this.getUrls();
|
||||||
let acceptButtonForm = this.getAcceptButtonForm(urls);
|
const acceptButtonForm = this.getAcceptButtonForm(urls);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@ -157,7 +149,7 @@ let RequestActionForm = React.createClass({
|
|||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
className='btn btn-danger btn-delete btn-sm ascribe-margin-1px'>
|
className='btn btn-danger btn-delete btn-sm ascribe-margin-1px'>
|
||||||
{getLangText('REJECT')}
|
{getLangText('REJECT')}
|
||||||
</button>
|
</button>
|
||||||
</Form>
|
</Form>
|
||||||
{acceptButtonForm}
|
{acceptButtonForm}
|
||||||
@ -169,7 +161,7 @@ let RequestActionForm = React.createClass({
|
|||||||
return (
|
return (
|
||||||
<ActionPanel
|
<ActionPanel
|
||||||
content={this.getContent()}
|
content={this.getContent()}
|
||||||
buttons={this.getButtonForm()}/>
|
buttons={this.getButtonForm()} />
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user