mirror of
https://github.com/ascribe/onion.git
synced 2025-01-03 18:35:09 +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 InputDate from './input_date';
|
||||||
import InputCheckbox from './input_checkbox';
|
import InputCheckbox from './input_checkbox';
|
||||||
|
|
||||||
import ContractStore from '../../stores/contract_store';
|
import ContractAgreementListStore from '../../stores/contract_agreement_list_store';
|
||||||
import ContractActions from '../../actions/contract_actions';
|
import ContractAgreementListActions from '../../actions/contract_agreement_list_actions';
|
||||||
|
|
||||||
import AppConstants from '../../constants/application_constants';
|
import AppConstants from '../../constants/application_constants';
|
||||||
|
|
||||||
@ -48,16 +48,24 @@ let LoanForm = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getInitialState() {
|
getInitialState() {
|
||||||
return ContractStore.getState();
|
return ContractAgreementListStore.getState();
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
ContractStore.listen(this.onChange);
|
ContractAgreementListStore.listen(this.onChange);
|
||||||
ContractActions.flushContract.defer();
|
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() {
|
componentWillUnmount() {
|
||||||
ContractStore.unlisten(this.onChange);
|
ContractAgreementListStore.unlisten(this.onChange);
|
||||||
},
|
},
|
||||||
|
|
||||||
onChange(state) {
|
onChange(state) {
|
||||||
@ -71,17 +79,19 @@ let LoanForm = React.createClass({
|
|||||||
handleOnChange(event) {
|
handleOnChange(event) {
|
||||||
// event.target.value is the submitted email of the loanee
|
// event.target.value is the submitted email of the loanee
|
||||||
if(event && event.target && event.target.value && event.target.value.match(/.*@.*/)) {
|
if(event && event.target && event.target.value && event.target.value.match(/.*@.*/)) {
|
||||||
ContractActions.fetchContract(event.target.value);
|
ContractAgreementListActions.fetchContractAgreementList(event.target.value, 'True', null);
|
||||||
} else {
|
} else {
|
||||||
ContractActions.flushContract();
|
ContractAgreementListActions.flushContractAgreementList();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getContractCheckbox() {
|
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
|
// we need to define a key on the InputCheckboxes as otherwise
|
||||||
// react is not rerendering them on a store switch and is keeping
|
// react is not rerendering them on a store switch and is keeping
|
||||||
// the default value of the component (which is in that case true)
|
// the default value of the component (which is in that case true)
|
||||||
|
let contract = this.state.contractAgreementList[0].contract;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Property
|
<Property
|
||||||
name="terms"
|
name="terms"
|
||||||
@ -92,8 +102,8 @@ let LoanForm = React.createClass({
|
|||||||
defaultChecked={false}>
|
defaultChecked={false}>
|
||||||
<span>
|
<span>
|
||||||
{getLangText('I agree to the')}
|
{getLangText('I agree to the')}
|
||||||
<a href={this.state.contractUrl} target="_blank">
|
<a href={contract.blob.url_safe} target="_blank">
|
||||||
{getLangText('terms of')} {this.state.contractEmail}
|
{getLangText('terms of')} {contract.issuer}
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
</InputCheckbox>
|
</InputCheckbox>
|
||||||
|
@ -19,6 +19,18 @@ let OwnershipFetcher = {
|
|||||||
return requests.get(ApiUrls.ownership_contract_list, isActive);
|
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(){
|
fetchLoanPieceRequestList(){
|
||||||
return requests.get(ApiUrls.ownership_loans_pieces_request);
|
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