diff --git a/js/actions/contract_agreement_list_actions.js b/js/actions/contract_agreement_list_actions.js
index cd78b52b..589c1f51 100644
--- a/js/actions/contract_agreement_list_actions.js
+++ b/js/actions/contract_agreement_list_actions.js
@@ -35,27 +35,47 @@ class ContractAgreementListActions {
);
}
- fetchAvailableContractAgreementList(issuer){
+ fetchAvailableContractAgreementList(issuer, createContractAgreement) {
return Q.Promise((resolve, reject) => {
- this.actions.fetchContractAgreementList(issuer, true, null)
- .then((contractAgreementListAccepted) => {
- if (!contractAgreementListAccepted) {
- // fetch pending agreements if no accepted ones
- return this.actions.fetchContractAgreementList(issuer, null, true);
+ OwnershipFetcher.fetchContractAgreementList(issuer, true, null)
+ .then((acceptedContractAgreementList) => {
+ // if there is at least an accepted contract agreement, we're going to
+ // use it
+ if(acceptedContractAgreementList.count > 0) {
+ this.actions.updateContractAgreementList(acceptedContractAgreementList.results);
+ } else {
+ // otherwise, we're looking for contract agreements that are still pending
+ //
+ // Normally nesting promises, but for this conditional one, it makes sense to not
+ // overcomplicate the method
+ OwnershipFetcher.fetchContractAgreementList(issuer, null, true)
+ .then((pendingContractAgreementList) => {
+ if(pendingContractAgreementList.count > 0) {
+ this.actions.updateContractAgreementList(pendingContractAgreementList.results);
+ } else {
+ // if there was neither a pending nor an active contractAgreement
+ // found and createContractAgreement is set to true, we create a
+ // new contract agreement
+ if(createContractAgreement) {
+ this.actions.createContractAgreementFromPublicContract(issuer);
+ }
+ }
+ })
+ .catch((err) => {
+ console.logGlobal(err);
+ reject(err);
+ });
}
- else {
- resolve(contractAgreementListAccepted);
- }
- }).then((contractAgreementListPending) => {
- resolve(contractAgreementListPending);
- }).catch((err) => {
+ })
+ .catch((err) => {
console.logGlobal(err);
reject(err);
});
- });
+ }
+ );
}
- createContractAgreementFromPublicContract(issuer){
+ createContractAgreementFromPublicContract(issuer) {
ContractListActions.fetchContractList(null, null, issuer)
.then((publicContract) => {
// create an agreement with the public contract if there is one
diff --git a/js/components/ascribe_forms/form_loan.js b/js/components/ascribe_forms/form_loan.js
index 5f7c5d78..b9942ea8 100644
--- a/js/components/ascribe_forms/form_loan.js
+++ b/js/components/ascribe_forms/form_loan.js
@@ -59,10 +59,13 @@ let LoanForm = React.createClass({
this.getContractAgreementsOrCreatePublic(this.props.email);
},
+ /**
+ * This method needs to be in form_loan as some whitelabel pages (Cyland) load
+ * the loanee's email async!
+ *
+ * SO LEAVE IT IN!
+ */
componentWillReceiveProps(nextProps) {
- // however, it can also be that at the time the component is mounting,
- // the email is not defined (because it's asynchronously fetched from the server).
- // Then we need to update it as soon as it is included into LoanForm's props.
if(nextProps && nextProps.email && this.props.email !== nextProps.email) {
this.getContractAgreementsOrCreatePublic(nextProps.email);
}
@@ -80,14 +83,7 @@ let LoanForm = React.createClass({
ContractAgreementListActions.flushContractAgreementList.defer();
if (email) {
// fetch the available contractagreements (pending/accepted)
- ContractAgreementListActions.fetchAvailableContractAgreementList(email).then(
- (contractAgreementList) => {
- if (!contractAgreementList && this.props.createPublicContractAgreement) {
- // for public contracts: fetch the public contract and create a contractagreement if available
- ContractAgreementListActions.createContractAgreementFromPublicContract(email);
- }
- }
- );
+ ContractAgreementListActions.fetchAvailableContractAgreementList(email, true);
}
},
@@ -119,25 +115,46 @@ let LoanForm = React.createClass({
// 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;
+ let contractAgreement = this.state.contractAgreementList[0];
+ let contract = contractAgreement.contract;
- return (
-
-
-
- {getLangText('I agree to the')}
-
- {getLangText('terms of ')} {contract.issuer}
-
-
-
-
- );
+ if(contractAgreement.datetime_accepted) {
+ return (
+
+
+ {/* We still need to send the server information that we're accepting */}
+
+
+ );
+ } else {
+ return (
+
+
+
+ {getLangText('I agree to the')}
+
+ {getLangText('terms of ')} {contract.issuer}
+
+
+
+
+ );
+ }
} else {
return (
-
{getLangText('Appendix')}
-
- {appendix.default}
-
-
+
+
{appendix.default}
+
);
}
}
@@ -214,7 +230,7 @@ let LoanForm = React.createClass({
name='loanee'
label={getLangText('Loanee Email')}
editable={!this.props.email}
- onBlur={this.handleOnChange}
+ onChange={this.handleOnChange}
overrideForm={!!this.props.email}>
+ {this.getContractCheckbox()}
+ {this.getAppendix()}
- {this.getContractCheckbox()}
- {this.getAppendix()}
{this.props.children}
);
diff --git a/js/components/ascribe_forms/input_checkbox.js b/js/components/ascribe_forms/input_checkbox.js
index 275b2374..38885441 100644
--- a/js/components/ascribe_forms/input_checkbox.js
+++ b/js/components/ascribe_forms/input_checkbox.js
@@ -25,7 +25,10 @@ let InputCheckbox = React.createClass({
// provided by Property
disabled: React.PropTypes.bool,
- onChange: React.PropTypes.func
+ onChange: React.PropTypes.func,
+
+ // can be used to style the component from the outside
+ style: React.PropTypes.object
},
// As HTML inputs, we're setting the default value for an input to checked === false
@@ -98,6 +101,7 @@ let InputCheckbox = React.createClass({
return (
-
-