mirror of
https://github.com/ascribe/onion.git
synced 2024-12-22 09:23:13 +01:00
Fetch contractagreements, order them and filter by accepted or pending
Merge remote-tracking branch 'remotes/origin/AD-885-convert-roles-to-acls' into AD-924-apply-contractagreements-to-loan- Conflicts: ownership/serializers.py
This commit is contained in:
parent
b45c68b2dc
commit
23eb3a7fd9
40
js/actions/contract_agreement_list_actions.js
Normal file
40
js/actions/contract_agreement_list_actions.js
Normal file
@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
|
||||
import alt from '../alt';
|
||||
import Q from 'q';
|
||||
|
||||
import OwnershipFetcher from '../fetchers/ownership_fetcher';
|
||||
|
||||
|
||||
class ContractAgreementListActions {
|
||||
constructor() {
|
||||
this.generateActions(
|
||||
'updateContractAgreementList',
|
||||
'flushContractAgreementList'
|
||||
);
|
||||
}
|
||||
|
||||
fetchContractAgreementList(issuer, accepted, pending) {
|
||||
return Q.Promise((resolve, reject) => {
|
||||
OwnershipFetcher.fetchContractAgreementList(issuer, accepted, pending)
|
||||
.then((contractAgreementList) => {
|
||||
if (contractAgreementList.count > 0) {
|
||||
this.actions.updateContractAgreementList(contractAgreementList.results);
|
||||
}
|
||||
else {
|
||||
this.actions.updateContractAgreementList(null);
|
||||
}
|
||||
resolve();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.logGlobal(err);
|
||||
this.actions.updateContractAgreementList(null);
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default alt.createActions(ContractAgreementListActions);
|
@ -12,8 +12,8 @@ import InputTextAreaToggable from './input_textarea_toggable';
|
||||
import InputDate from './input_date';
|
||||
import InputCheckbox from './input_checkbox';
|
||||
|
||||
import ContractStore from '../../stores/contract_store';
|
||||
import ContractActions from '../../actions/contract_actions';
|
||||
import ContractAgreementListStore from '../../stores/contract_agreement_list_store';
|
||||
import ContractAgreementListActions from '../../actions/contract_agreement_list_actions';
|
||||
|
||||
import AppConstants from '../../constants/application_constants';
|
||||
|
||||
@ -48,16 +48,24 @@ let LoanForm = React.createClass({
|
||||
},
|
||||
|
||||
getInitialState() {
|
||||
return ContractStore.getState();
|
||||
return ContractAgreementListStore.getState();
|
||||
},
|
||||
|
||||
componentDidMount() {
|
||||
ContractStore.listen(this.onChange);
|
||||
ContractActions.flushContract.defer();
|
||||
ContractAgreementListStore.listen(this.onChange);
|
||||
if (this.props.email){
|
||||
ContractAgreementListActions.fetchContractAgreementList(
|
||||
this.props.email, 'True', null);
|
||||
}
|
||||
|
||||
/* @Tim:
|
||||
throws Uncaught TypeError: Cannot read property 'defer' of undefined
|
||||
We might not need this
|
||||
ContractAgreementListActions.flushContractAgreementList().defer();*/
|
||||
},
|
||||
|
||||
componentWillUnmount() {
|
||||
ContractStore.unlisten(this.onChange);
|
||||
ContractAgreementListStore.unlisten(this.onChange);
|
||||
},
|
||||
|
||||
onChange(state) {
|
||||
@ -71,17 +79,19 @@ let LoanForm = React.createClass({
|
||||
handleOnChange(event) {
|
||||
// event.target.value is the submitted email of the loanee
|
||||
if(event && event.target && event.target.value && event.target.value.match(/.*@.*/)) {
|
||||
ContractActions.fetchContract(event.target.value);
|
||||
ContractAgreementListActions.fetchContractAgreementList(event.target.value, 'True', null);
|
||||
} else {
|
||||
ContractActions.flushContract();
|
||||
ContractAgreementListActions.flushContractAgreementList();
|
||||
}
|
||||
},
|
||||
|
||||
getContractCheckbox() {
|
||||
if(this.state.contractKey && this.state.contractUrl) {
|
||||
if(this.state.contractAgreementList && this.state.contractAgreementList.length > 0) {
|
||||
// we need to define a key on the InputCheckboxes as otherwise
|
||||
// react is not rerendering them on a store switch and is keeping
|
||||
// the default value of the component (which is in that case true)
|
||||
let contract = this.state.contractAgreementList[0].contract;
|
||||
|
||||
return (
|
||||
<Property
|
||||
name="terms"
|
||||
@ -92,8 +102,8 @@ let LoanForm = React.createClass({
|
||||
defaultChecked={false}>
|
||||
<span>
|
||||
{getLangText('I agree to the')}
|
||||
<a href={this.state.contractUrl} target="_blank">
|
||||
{getLangText('terms of')} {this.state.contractEmail}
|
||||
<a href={contract.blob.url_safe} target="_blank">
|
||||
{getLangText('terms of')} {contract.issuer}
|
||||
</a>
|
||||
</span>
|
||||
</InputCheckbox>
|
||||
|
@ -19,6 +19,18 @@ let OwnershipFetcher = {
|
||||
return requests.get(ApiUrls.ownership_contract_list, isActive);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch the contractagreement between the logged-in user and the email from the API.
|
||||
*/
|
||||
fetchContractAgreementList(issuer, accepted, pending) {
|
||||
let queryParams = {
|
||||
issuer,
|
||||
accepted,
|
||||
pending
|
||||
};
|
||||
return requests.get(ApiUrls.ownership_contract_agreements, queryParams);
|
||||
},
|
||||
|
||||
fetchLoanPieceRequestList(){
|
||||
return requests.get(ApiUrls.ownership_loans_pieces_request);
|
||||
},
|
||||
|
22
js/stores/contract_agreement_list_store.js
Normal file
22
js/stores/contract_agreement_list_store.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
import alt from '../alt';
|
||||
import ContractAgreementListActions from '../actions/contract_agreement_list_actions';
|
||||
|
||||
|
||||
class ContractAgreementListStore {
|
||||
constructor() {
|
||||
this.contractAgreementList = null;
|
||||
this.bindActions(ContractAgreementListActions);
|
||||
}
|
||||
|
||||
onUpdateContractAgreementList(contractAgreementList) {
|
||||
this.contractAgreementList = contractAgreementList;
|
||||
}
|
||||
|
||||
onFlushContractAgreementList() {
|
||||
this.contractAgreementList = null;
|
||||
}
|
||||
}
|
||||
|
||||
export default alt.createStore(ContractAgreementListStore, 'ContractAgreementListStore');
|
Loading…
Reference in New Issue
Block a user