From 961b8ee58d57e46ad7ee9a23a6e7db7ad902952d Mon Sep 17 00:00:00 2001 From: ddejongh Date: Fri, 29 May 2015 15:16:42 +0200 Subject: [PATCH] errors for non-fields, 500 removed retry consign_form --- js/components/ascribe_forms/form_consign.js | 66 +++++++++++++++++++ js/components/ascribe_forms/input_text.js | 3 +- js/components/ascribe_forms/input_textarea.js | 3 +- js/components/ascribe_modal/modal_consign.js | 43 ++++++++++++ js/components/ascribe_modal/modal_share.js | 8 +-- js/components/ascribe_modal/modal_transfer.js | 8 +-- js/components/edition.js | 2 + js/constants/api_urls.js | 3 +- js/mixins/alert_mixin.js | 5 +- js/mixins/form_mixin.js | 22 +++++-- js/mixins/modal_mixin.js | 11 ++++ 11 files changed, 151 insertions(+), 23 deletions(-) create mode 100644 js/components/ascribe_forms/form_consign.js create mode 100644 js/components/ascribe_modal/modal_consign.js create mode 100644 js/mixins/modal_mixin.js diff --git a/js/components/ascribe_forms/form_consign.js b/js/components/ascribe_forms/form_consign.js new file mode 100644 index 00000000..cf68d429 --- /dev/null +++ b/js/components/ascribe_forms/form_consign.js @@ -0,0 +1,66 @@ +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 InputTextArea from './input_textarea'; +import ButtonSubmitOrClose from './button_submit_close'; + +let ConsignForm = React.createClass({ + mixins: [FormMixin], + + url() { + return ApiUrls.ownership_consigns + }, + getFormData() { + return { + bitcoin_id: this.props.edition.bitcoin_id, + consignee: this.refs.consignee.state.value, + consign_message: this.refs.consign_message.state.value, + password: this.refs.password.state.value + } + }, + renderForm() { + let title = this.props.edition.title; + let username = this.props.currentUser.username; + let message = +`Hi, + +I consign \" ${title} \" to you. + +Truly yours, +${username}`; + + return ( +
+ + + + + + + + ); + } +}); + +export default ConsignForm; \ No newline at end of file diff --git a/js/components/ascribe_forms/input_text.js b/js/components/ascribe_forms/input_text.js index a65bcc8f..9d4d4b61 100644 --- a/js/components/ascribe_forms/input_text.js +++ b/js/components/ascribe_forms/input_text.js @@ -8,8 +8,7 @@ let InputText = React.createClass({ getInitialState() { return {value: null, - alerts: null, // needed in AlertMixin - retry: 0 // needed in AlertMixin for generating unique alerts + alerts: null }; }, handleChange(event) { diff --git a/js/components/ascribe_forms/input_textarea.js b/js/components/ascribe_forms/input_textarea.js index b5f64b66..c4e0d7b1 100644 --- a/js/components/ascribe_forms/input_textarea.js +++ b/js/components/ascribe_forms/input_textarea.js @@ -8,8 +8,7 @@ let InputTextArea = React.createClass({ getInitialState() { return {value: this.props.defaultValue, - alerts: null, // needed in AlertMixin - retry: 0 // needed in AlertMixin for generating unique alerts + alerts: null // needed in AlertMixin }; }, handleChange(event) { diff --git a/js/components/ascribe_modal/modal_consign.js b/js/components/ascribe_modal/modal_consign.js new file mode 100644 index 00000000..bcd47973 --- /dev/null +++ b/js/components/ascribe_modal/modal_consign.js @@ -0,0 +1,43 @@ +import React from 'react'; +import Modal from 'react-bootstrap/lib/Modal'; +import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger'; +import ModalTrigger from 'react-bootstrap/lib/ModalTrigger'; +import Tooltip from 'react-bootstrap/lib/Tooltip'; + +import ConsignForm from '../ascribe_forms/form_consign' +import ModalMixin from '../../mixins/modal_mixin' + +let ConsignModalButton = React.createClass({ + render() { + return ( + Have someone else sell the artwork}> + }> +
+ CONSIGN +
+
+
+ ) + } +}); + +let ConsignModal = React.createClass({ + mixins : [ModalMixin], + + render() { + return ( + +
+ +
+
+ ) + } +}); + + +export default ConsignModalButton; diff --git a/js/components/ascribe_modal/modal_share.js b/js/components/ascribe_modal/modal_share.js index 176541ee..4ada244c 100644 --- a/js/components/ascribe_modal/modal_share.js +++ b/js/components/ascribe_modal/modal_share.js @@ -4,6 +4,7 @@ import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger'; import ModalTrigger from 'react-bootstrap/lib/ModalTrigger'; import Tooltip from 'react-bootstrap/lib/Tooltip'; +import ModalMixin from '../../mixins/modal_mixin' import ShareForm from '../ascribe_forms/form_share_email' @@ -24,11 +25,8 @@ let ShareModalButton = React.createClass({ }); let ShareModal = React.createClass({ - onRequestHide(e){ - if (e) - e.preventDefault(); - this.props.onRequestHide(); - }, + mixins : [ModalMixin], + render() { return ( diff --git a/js/components/ascribe_modal/modal_transfer.js b/js/components/ascribe_modal/modal_transfer.js index b57064ff..12b40524 100644 --- a/js/components/ascribe_modal/modal_transfer.js +++ b/js/components/ascribe_modal/modal_transfer.js @@ -5,7 +5,7 @@ import ModalTrigger from 'react-bootstrap/lib/ModalTrigger'; import Tooltip from 'react-bootstrap/lib/Tooltip'; import TransferForm from '../ascribe_forms/form_transfer' - +import ModalMixin from '../../mixins/modal_mixin' let TransferModalButton = React.createClass({ render() { @@ -24,10 +24,8 @@ let TransferModalButton = React.createClass({ }); let TransferModal = React.createClass({ - onRequestHide(e){ - e.preventDefault(); - this.props.onRequestHide(); - }, + mixins : [ModalMixin], + render() { return ( diff --git a/js/components/edition.js b/js/components/edition.js index ffeb9b25..65fa2a51 100644 --- a/js/components/edition.js +++ b/js/components/edition.js @@ -1,6 +1,7 @@ import React from 'react'; import ImageViewer from './ascribe_media/image_viewer'; +import ConsignModalButton from './ascribe_modal/modal_consign'; import TransferModalButton from './ascribe_modal/modal_transfer'; import ShareModalButton from './ascribe_modal/modal_share'; @@ -47,6 +48,7 @@ let EditionDetails = React.createClass({
+
diff --git a/js/constants/api_urls.js b/js/constants/api_urls.js index f0c7f9b6..d26352bc 100644 --- a/js/constants/api_urls.js +++ b/js/constants/api_urls.js @@ -2,7 +2,8 @@ import AppConstants from './application_constants'; let apiUrls = { 'ownership_shares_mail' : AppConstants.baseUrl + 'ownership/shares/mail/', - 'ownership_transfers' : AppConstants.baseUrl + 'ownership/transfers/' + 'ownership_transfers' : AppConstants.baseUrl + 'ownership/transfers/', + 'ownership_consigns' : AppConstants.baseUrl + 'ownership/consigns/' }; export default apiUrls; \ No newline at end of file diff --git a/js/mixins/alert_mixin.js b/js/mixins/alert_mixin.js index 90289d22..f52890c7 100644 --- a/js/mixins/alert_mixin.js +++ b/js/mixins/alert_mixin.js @@ -5,11 +5,10 @@ let AlertMixin = { setAlerts(errors){ let alerts = errors.map( function(error) { - let key = error + this.state.retry; - return ; + return ; }.bind(this) ); - this.setState({alerts: alerts, retry: this.state.retry + 1}); + this.setState({alerts: alerts}); }, clearAlerts(){ this.setState({alerts: null}); diff --git a/js/mixins/form_mixin.js b/js/mixins/form_mixin.js index 060a297e..65983653 100644 --- a/js/mixins/form_mixin.js +++ b/js/mixins/form_mixin.js @@ -1,5 +1,6 @@ import React from 'react'; +import EditionActions from '../actions/edition_actions' import AppConstants from '../constants/application_constants' import AlertDismissable from '../components/ascribe_forms/alert' @@ -8,6 +9,7 @@ export const FormMixin = { return { submitted: false , status: null + , errors: [] } }, submit(e) { @@ -15,7 +17,7 @@ export const FormMixin = { for (var ref in this.refs){ this.refs[ref].clearAlerts(); } - this.setState({submitted: true}); + this.setState({submitted: true, errors: []}); fetch(this.url(), { method: 'post', headers: { @@ -30,15 +32,16 @@ export const FormMixin = { ); }, handleResponse(response){ + let submitted = false; if (response.status >= 200 && response.status < 300){ + EditionActions.fetchOne(this.props.edition.id); this.props.onRequestHide(); + submitted = true; } else if (response.status >= 400 && response.status < 500) { this.handleError(response); } - else { - this.setState({submitted: false, status: response.status}); - } + this.setState({submitted: submitted, status: response.status}); }, handleError(response){ response.json().then((response) => this.dispatchErrors(response.errors)); @@ -49,14 +52,23 @@ export const FormMixin = { if (this.refs && this.refs[input] && this.refs[input].state){ this.refs[input].setAlerts(errors[input]); } + else{ + this.setState({errors: this.state.errors.concat(errors[input])}); + } } - this.setState({submitted: false}); }, render(){ let alert = null; if (this.state.status >= 500){ alert = ; } + if (this.state.errors.length > 0){ + alert = this.state.errors.map( + function(error) { + return ; + }.bind(this) + ); + } return (
{alert} diff --git a/js/mixins/modal_mixin.js b/js/mixins/modal_mixin.js new file mode 100644 index 00000000..7dee243b --- /dev/null +++ b/js/mixins/modal_mixin.js @@ -0,0 +1,11 @@ +import React from 'react'; + +let ModalMixin = { + onRequestHide(e){ + if (e) + e.preventDefault(); + this.props.onRequestHide(); + } +}; + +export default ModalMixin; \ No newline at end of file