mirror of
https://github.com/ascribe/onion.git
synced 2024-12-23 01:39:36 +01:00
fixed tests
refactored contractagreement actions
This commit is contained in:
parent
7fd5516b79
commit
0ce298879b
@ -36,18 +36,28 @@ class ContractAgreementListActions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fetchAvailableContractAgreementList(issuer){
|
fetchAvailableContractAgreementList(issuer){
|
||||||
this.actions.fetchContractAgreementList(issuer, 'True', null)
|
return Q.Promise((resolve, reject) => {
|
||||||
.then((contractAgreementListAccepted) => {
|
this.actions.fetchContractAgreementList(issuer, 'True', null)
|
||||||
if (!contractAgreementListAccepted) {
|
.then((contractAgreementListAccepted) => {
|
||||||
// fetch pending agreements if no accepted ones
|
if (!contractAgreementListAccepted) {
|
||||||
return this.actions.fetchContractAgreementList(issuer, null, 'True');
|
// fetch pending agreements if no accepted ones
|
||||||
}
|
return this.actions.fetchContractAgreementList(issuer, null, 'True');
|
||||||
}).then((contractAgreementListPending) => {
|
}
|
||||||
// fetch public contract if no accepted nor pending agreements
|
else {
|
||||||
if (!contractAgreementListPending) {
|
resolve(contractAgreementListAccepted);
|
||||||
return ContractListActions.fetchContractList(null, null, issuer);
|
}
|
||||||
}
|
}).then((contractAgreementListPending) => {
|
||||||
}).then((publicContract) => {
|
resolve(contractAgreementListPending);
|
||||||
|
}).catch((err) => {
|
||||||
|
console.logGlobal(err);
|
||||||
|
reject(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
createContractAgreementFromPublicContract(issuer){
|
||||||
|
ContractListActions.fetchContractList(null, null, issuer)
|
||||||
|
.then((publicContract) => {
|
||||||
// create an agreement with the public contract if there is one
|
// create an agreement with the public contract if there is one
|
||||||
if (publicContract && publicContract.length > 0) {
|
if (publicContract && publicContract.length > 0) {
|
||||||
return this.actions.createContractAgreement(null, publicContract[0]);
|
return this.actions.createContractAgreement(null, publicContract[0]);
|
||||||
|
@ -54,9 +54,7 @@ let LoanForm = React.createClass({
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
ContractAgreementListStore.listen(this.onChange);
|
ContractAgreementListStore.listen(this.onChange);
|
||||||
if (this.props.email){
|
this.getContractAgreementsOrCreatePublic(this.props.email);
|
||||||
ContractAgreementListActions.fetchAvailableContractAgreementList.defer(this.props.email);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
@ -67,6 +65,18 @@ let LoanForm = React.createClass({
|
|||||||
this.setState(state);
|
this.setState(state);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getContractAgreementsOrCreatePublic(email){
|
||||||
|
if (email) {
|
||||||
|
ContractAgreementListActions.fetchAvailableContractAgreementList(email).then(
|
||||||
|
(contractAgreementList) => {
|
||||||
|
if (!contractAgreementList) {
|
||||||
|
ContractAgreementListActions.createContractAgreementFromPublicContract.defer(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getFormData(){
|
getFormData(){
|
||||||
return mergeOptions(
|
return mergeOptions(
|
||||||
this.props.id,
|
this.props.id,
|
||||||
@ -76,8 +86,8 @@ 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(/.*@.*\..*/)) {
|
||||||
ContractAgreementListActions.fetchContractAgreementList(event.target.value, 'True', null);
|
this.getContractAgreementsOrCreatePublic(event.target.value);
|
||||||
} else {
|
} else {
|
||||||
ContractAgreementListActions.flushContractAgreementList();
|
ContractAgreementListActions.flushContractAgreementList();
|
||||||
}
|
}
|
||||||
@ -172,8 +182,8 @@ let LoanForm = React.createClass({
|
|||||||
<Property
|
<Property
|
||||||
name='loanee'
|
name='loanee'
|
||||||
label={getLangText('Loanee Email')}
|
label={getLangText('Loanee Email')}
|
||||||
onChange={this.handleOnChange}
|
|
||||||
editable={!this.props.email}
|
editable={!this.props.email}
|
||||||
|
onBlur={this.handleOnChange}
|
||||||
overrideForm={!!this.props.email}>
|
overrideForm={!!this.props.email}>
|
||||||
<input
|
<input
|
||||||
value={this.props.email}
|
value={this.props.email}
|
||||||
|
Loading…
Reference in New Issue
Block a user