From ec18363058928df136e13424402641a30d3e0f81 Mon Sep 17 00:00:00 2001 From: Ivan Diaz Date: Thu, 19 Jan 2017 19:48:55 -0300 Subject: [PATCH] Ivan - Add check ticket page [skip ci] --- client/src/app/Routes.js | 4 +- .../create-ticket-form.js | 8 +- client/src/app/main/main-check-ticket-page.js | 86 ++++++++++++++++++- .../src/app/main/main-check-ticket-page.scss | 24 ++++++ 4 files changed, 115 insertions(+), 7 deletions(-) diff --git a/client/src/app/Routes.js b/client/src/app/Routes.js index 59b5f961..c6b0b52b 100644 --- a/client/src/app/Routes.js +++ b/client/src/app/Routes.js @@ -66,8 +66,8 @@ export default ( - - + + diff --git a/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.js b/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.js index a4c17908..1ce083b3 100644 --- a/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.js +++ b/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.js @@ -2,7 +2,7 @@ import React from 'react'; import _ from 'lodash'; import ReCAPTCHA from 'react-google-recaptcha'; import { browserHistory } from 'react-router'; -import RichTextEditor from 'react-rte-browserify'; +import RichTextEditor from 'react-rte-browserify'; import i18n from 'lib-app/i18n'; import API from 'lib-app/api-call'; @@ -123,11 +123,11 @@ class CreateTicketForm extends React.Component { captcha: captcha && captcha.getValue(), departmentId: SessionStore.getDepartments()[formState.departmentIndex].id }) - }).then(this.onTicketSuccess.bind(this)).catch(this.onTicketFail.bind(this)); + }).then(this.onTicketSuccess.bind(this, formState.email)).catch(this.onTicketFail.bind(this)); } } - onTicketSuccess() { + onTicketSuccess(email, result) { this.setState({ loading: false, message: 'success' @@ -136,6 +136,8 @@ class CreateTicketForm extends React.Component { if(this.props.userLogged) { store.dispatch(SessionActions.getUserData()); setTimeout(() => {browserHistory.push('/dashboard')}, 2000); + } else { + setTimeout(() => {browserHistory.push('/check-ticket/' + email + '/' + result.data.ticketNumber)}, 2000); } } diff --git a/client/src/app/main/main-check-ticket-page.js b/client/src/app/main/main-check-ticket-page.js index 25ebb95a..4eb84a37 100644 --- a/client/src/app/main/main-check-ticket-page.js +++ b/client/src/app/main/main-check-ticket-page.js @@ -1,12 +1,94 @@ import React from 'react'; +import { browserHistory } from 'react-router'; + +import i18n from 'lib-app/i18n'; +import API from 'lib-app/api-call'; +import SessionStore from 'lib-app/session-store'; + +import Widget from 'core-components/widget'; +import Header from 'core-components/header'; +import Form from 'core-components/form'; +import FormField from 'core-components/form-field'; +import SubmitButton from 'core-components/submit-button'; +import Captcha from 'app/main/captcha'; class MainCheckTicketPage extends React.Component { + + state = { + loading: false, + form: { + email: this.props.params.email || '', + ticketNumber: this.props.params.ticketNumber || '' + }, + errors: {} + }; + render() { return (
- + +
+
+
+
+ +
+
+ +
+
+
+ +
+ {i18n('CHECK_TICKET')} +
+
- ) + ); + } + + getFormProps() { + return { + className: 'main-check-ticket-page__form', + loading: this.state.loading, + values: this.state.form, + errors: this.state.errors, + onChange: (form) => this.setState({form}), + onValidateErrors: (errors) => this.setState({errors}), + onSubmit: this.onFormSubmit.bind(this) + }; + } + + onFormSubmit(form) { + const captcha = this.refs.captcha.getWrappedInstance(); + + if (!captcha.getValue()) { + captcha.focus(); + } else { + this.setState({ + loading: true + }); + + API.call({ + path: '/ticket/get', + data: { + captcha: captcha && captcha.getValue(), + ticketNumber: form.ticketNumber, + email: form.email + } + }).then(this.onTicketGetSuccess.bind(this)).catch(() => this.setState({ + loading: false, + errors: { + email: i18n('INVALID_EMAIL_OR_TICKET_NUMBER'), + ticketNumber: i18n('INVALID_EMAIL_OR_TICKET_NUMBER') + } + })); + } + } + + onTicketGetSuccess(result) { + SessionStore.setItem('token', result.data.token); + setTimeout(() => {browserHistory.push('/view-ticket/' + this.state.form.email + '/' + this.state.form.ticketNumber)}, 2000); } } diff --git a/client/src/app/main/main-check-ticket-page.scss b/client/src/app/main/main-check-ticket-page.scss index e69de29b..935387f8 100644 --- a/client/src/app/main/main-check-ticket-page.scss +++ b/client/src/app/main/main-check-ticket-page.scss @@ -0,0 +1,24 @@ +.main-check-ticket-page { + padding: 0 15px; + + &__form { + margin: 0 auto; + max-width: 790px; + } + + &__inputs { + display: inline-block; + margin: 0 auto; + } + + &__input { + display: inline-block; + margin: 0 20px; + } + + &__captcha { + margin: 20px auto 20px; + height: 78px; + width: 304px; + } +} \ No newline at end of file