import fetch from 'isomorphic-fetch'; import React from 'react'; import ApiUrls from '../../constants/api_urls'; import FormMixin from '../../mixins/form_mixin'; import InputText from './input_text'; import InputHidden from './input_hidden'; import InputCheckbox from './input_checkbox'; import InputDate from './input_date'; import InputTextArea from './input_textarea'; import OwnershipFetcher from '../../fetchers/ownership_fetcher' import ButtonSubmitOrClose from './button_submit_close'; let LoanForm = React.createClass({ mixins: [FormMixin], url() { return ApiUrls.ownership_loans }, componentDidMount(){ this.setState({contract_key: null, contract_url: null, loaneeHasContract: false}); }, getFormData() { return { bitcoin_id: this.getBitcoinIds().join(), loanee: this.refs.loanee.state.value, gallery_name: this.refs.gallery_name.state.value, startdate: this.refs.startdate.state.value.format("YYYY-MM-DD"), enddate: this.refs.enddate.state.value.format("YYYY-MM-DD"), loan_message: this.refs.loan_message.state.value, password: this.refs.password.state.value, terms: this.refs.terms.state.value } }, handleLoanEmailBlur(e){ OwnershipFetcher.fetchLoanContract(this.refs.loanee.state.value) .then((res) => { if (res && res.length > 0) { this.setState({contract_key: res[0].s3Key, contract_url: res[0].s3Url, loaneeHasContract: true}); } else{ this.resetLoanContract(); } }) .catch((err) => { console.log(err); this.resetLoanContract(); }); }, resetLoanContract(){ this.setState({contract_key: null, contract_url: null, loaneeHasContract: false }); }, renderForm() { let title = this.getTitlesString().join(""); let username = this.props.currentUser.username; let message = `Hi, I loan : ${title}to you. Truly yours, ${username}`; let contract = ; if (this.state.loaneeHasContract){ let label =
I agree to the  terms of {this.refs.loanee.state.value}
; contract = } return (
{contract} ); } }); export default LoanForm;