From ef20687f1a50be00e57967de2dba17cbd14d57f2 Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 18 Aug 2016 22:56:29 -0300 Subject: [PATCH] Ivan - Create Ticket Form - Add /ticket/create fixture and add ticket create form logic [skip ci] --- .../create-ticket-form.js | 54 +++++++++++++++++-- .../create-ticket-form.scss | 6 +++ client/src/data/fixtures/ticket-fixtures.js | 25 +++++++++ client/src/data/languages/en.js | 2 + client/src/lib-app/fixtures-loader.js | 1 + 5 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.scss create mode 100644 client/src/data/fixtures/ticket-fixtures.js 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 062883ae..27ddc0bf 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 @@ -1,5 +1,6 @@ import React from 'react'; import ReCAPTCHA from 'react-google-recaptcha'; +import { browserHistory } from 'react-router'; import i18n from 'lib-app/i18n'; import API from 'lib-app/api-call'; @@ -10,14 +11,24 @@ import Form from 'core-components/form'; import FormField from 'core-components/form-field'; class CreateTicketForm extends React.Component { + + constructor(props) { + super(props); + + this.state = { + loading: false, + message: null + }; + } + render() { return ( -
+

Create Ticket

-
+
- Create Ticket + {this.renderMessage()}
); } + renderMessage() { + switch (this.state.message) { + case 'success': + return {i18n('TICKET_SENT')}; + case 'fail': + return {i18n('TICKET_SENT_ERROR')}; + default: + return null; + } + } + onSubmit(formState) { - console.log(formState); + this.setState({ + loading: true + }); + + API.call({ + path: '/ticket/create', + data: formState + }).then(this.onTicketSuccess.bind(this)).catch(this.onTicketFail.bind(this)); + } + + onTicketSuccess() { + this.setState({ + loading: false, + message: 'success' + }); + + setTimeout(() => {browserHistory.push('/dashboard')}, 2000); + } + + onTicketFail() { + this.setState({ + loading: false, + message: 'fail' + }); } } diff --git a/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.scss b/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.scss new file mode 100644 index 00000000..82aebdc9 --- /dev/null +++ b/client/src/app/main/dashboard/dashboard-create-ticket/create-ticket-form.scss @@ -0,0 +1,6 @@ +.create-ticket-form { + + &__message { + margin-top: 20px; + } +} \ No newline at end of file diff --git a/client/src/data/fixtures/ticket-fixtures.js b/client/src/data/fixtures/ticket-fixtures.js new file mode 100644 index 00000000..16d169cd --- /dev/null +++ b/client/src/data/fixtures/ticket-fixtures.js @@ -0,0 +1,25 @@ +module.exports = [ + { + path: '/ticket/create', + time: 2000, + response: function (data) { + let response; + + if (data.title !== 'error') { + response = { + status: 'success', + data: { + 'ticketNumber': 121444 + } + }; + } else { + response = { + status: 'fail', + message: 'Ticket could not be created' + }; + } + + return response; + } + } +]; \ No newline at end of file diff --git a/client/src/data/languages/en.js b/client/src/data/languages/en.js index fde7f84b..f780f49c 100644 --- a/client/src/data/languages/en.js +++ b/client/src/data/languages/en.js @@ -25,9 +25,11 @@ export default { 'ERROR_CONTENT_SHORT': 'Content too short', 'PASSWORD_NOT_MATCH': 'Password does not match', 'INVALID_RECOVER': 'Invalid recover data', + 'TICKET_SENT_ERROR': 'An error occurred while trying to create the ticket.', //MESSAGES 'SIGNUP_SUCCESS': 'You have registered successfully in our support system.', + 'TICKET_SENT': 'Ticket has been created successfully.', 'VALID_RECOVER': 'Password recovered successfully', 'EMAIL_EXISTS': 'Email already exists, please try to log in or recover password' }; \ No newline at end of file diff --git a/client/src/lib-app/fixtures-loader.js b/client/src/lib-app/fixtures-loader.js index 8cbb9dbd..fcf645a2 100644 --- a/client/src/lib-app/fixtures-loader.js +++ b/client/src/lib-app/fixtures-loader.js @@ -17,6 +17,7 @@ let fixtures = (function () { // FIXTURES fixtures.add(require('data/fixtures/user-fixtures')); +fixtures.add(require('data/fixtures/ticket-fixtures')); fixtures.add(require('data/fixtures/system-fixtures')); _.each(fixtures.getAll(), function (fixture) {