0) {
+ ContractAgreementListActions.flushContractAgreementList();
+ }
+ },
+
+ componentWillUnmount() {
+ ContractAgreementListStore.unlisten(this.onChange);
+ },
+
+ onChange(state) {
+ this.setState(state);
+ },
+
+ getFormDataForProperty() {
+ return this.getContractAgreementId();
+ },
+
+ getContractAgreementId() {
+ if (this.state.contractAgreementList && this.state.contractAgreementList.length > 0) {
+ return { 'contract_agreement_id': this.state.contractAgreementList[0].id };
+ } else {
+ return {};
+ }
+ },
+
+ getContractAgreementsOrCreatePublic(email) {
+ ContractAgreementListActions.flushContractAgreementList.defer();
+
+ if (email) {
+ // fetch the available contractagreements (pending/accepted)
+ ContractAgreementListActions.fetchAvailableContractAgreementList(email, this.props.createPublicContractAgreement);
+ }
+ },
+
+ getAppendix() {
+ const { contractAgreementList } = this.state;
+
+ if (contractAgreementList && contractAgreementList.length > 0) {
+ const appendix = contractAgreementList[0].appendix;
+ if (appendix && appendix.default) {
+ return (
+
+ {appendix.default}
+
+ );
+ }
+ }
+ },
+
+ getContractCheckbox() {
+ const { contractAgreementList } = this.state;
+
+ if (contractAgreementList && 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)
+ const contractAgreement = contractAgreementList[0];
+ const { issuer: contractIssuer, blob: { url_safe: contractUrl } } = contractAgreement.contract;
+
+ if (contractAgreement.datetime_accepted) {
+ return (
+
+
+
+ {getLangText('Download contract')}
+
+ {/* We still need to send the server information that we're accepting */}
+
+
+ );
+ } else {
+ return (
+
+
+
+ {getLangText('I agree to the')}
+
+ {getLangText('terms of ')} {contractIssuer}
+
+
+
+
+ );
+ }
+ } else {
+ return (
+
+
+
+ );
+ }
+ },
+
+ render() {
+ return (
+
+ {this.getContractCheckbox()}
+ {this.getAppendix()}
+
+ );
+ }
+});
+
+export default ContractAgreementProperty;
diff --git a/js/utils/regex_utils.js b/js/utils/regex_utils.js
new file mode 100644
index 00000000..af948b2b
--- /dev/null
+++ b/js/utils/regex_utils.js
@@ -0,0 +1,7 @@
+'use strict'
+
+export function isEmail(string) {
+ // This is a bit of a weak test for an email, but you really can't win them all
+ // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address
+ return !!string && string.match(/.*@.*\..*/);
+}