Ivan - Add create ticket for no user system [skip ci]

This commit is contained in:
Ivan Diaz 2017-01-19 17:37:51 -03:00
parent e20760e8bb
commit 4119509cc4
7 changed files with 84 additions and 18 deletions

View File

@ -13,6 +13,7 @@ import MainSignUpPage from 'app/main/main-signup/main-signup-page';
import MainVerifyTokenPage from 'app/main/main-verify-token-page';
import MainRecoverPasswordPage from 'app/main/main-recover-password/main-recover-password-page';
import MainMaintenancePage from 'app/main/main-maintenance-page';
import MainCheckTicketPage from 'app/main/main-check-ticket-page';
import DashboardLayout from 'app/main/dashboard/dashboard-layout';
import DashboardListTicketsPage from 'app/main/dashboard/dashboard-list-tickets/dashboard-list-tickets-page';
@ -63,6 +64,12 @@ export default (
<Route path='verify-token/:email/:token' component={MainVerifyTokenPage}/>
<Route path='recover-password' component={MainRecoverPasswordPage}/>
<Route path='maintenance' component={MainMaintenancePage}/>
<Route path='create-ticket' component={DashboardCreateTicketPage}/>
<Route path='check-ticket' component={MainCheckTicketPage}/>
<Route path='ticket/:ticketNumber/:email' component={DashboardTicketPage}/>
<Route path='articles' component={DashboardListArticlesPage}/>
<Route path='dashboard' component={DashboardLayout}>
<IndexRoute component={DashboardListTicketsPage} />
<Route path='articles' component={DashboardListArticlesPage}/>

View File

@ -10,6 +10,7 @@ import SessionStore from 'lib-app/session-store';
import store from 'app/store';
import SessionActions from 'actions/session-actions';
import LanguageSelector from 'app-components/language-selector';
import Captcha from 'app/main/captcha';
import Header from 'core-components/header';
import Form from 'core-components/form';
@ -34,6 +35,8 @@ class CreateTicketForm extends React.Component {
title: '',
content: RichTextEditor.createEmptyValue(),
departmentIndex: 0,
email: '',
name: '',
language: 'en'
}
};
@ -79,7 +82,7 @@ class CreateTicketForm extends React.Component {
renderCaptcha() {
return (
<div className="create-ticket-form__captcha">
<Captcha />
<Captcha ref="captcha"/>
</div>
);
}
@ -105,16 +108,23 @@ class CreateTicketForm extends React.Component {
}
onSubmit(formState) {
this.setState({
loading: true
});
let captcha = this.refs.captcha && this.refs.captcha.getWrappedInstance();
API.call({
path: '/ticket/create',
data: _.extend({}, formState, {
departmentId: SessionStore.getDepartments()[formState.departmentIndex].id
})
}).then(this.onTicketSuccess.bind(this)).catch(this.onTicketFail.bind(this));
if (captcha && !captcha.getValue()) {
captcha.focus();
} else {
this.setState({
loading: true
});
API.call({
path: '/ticket/create',
data: _.extend({}, formState, {
captcha: captcha && captcha.getValue(),
departmentId: SessionStore.getDepartments()[formState.departmentIndex].id
})
}).then(this.onTicketSuccess.bind(this)).catch(this.onTicketFail.bind(this));
}
}
onTicketSuccess() {
@ -123,9 +133,10 @@ class CreateTicketForm extends React.Component {
message: 'success'
});
store.dispatch(SessionActions.getUserData());
setTimeout(() => {browserHistory.push('/dashboard')}, 2000);
if(this.props.userLogged) {
store.dispatch(SessionActions.getUserData());
setTimeout(() => {browserHistory.push('/dashboard')}, 2000);
}
}
onTicketFail() {

View File

@ -1,16 +1,45 @@
import React from 'react';
import classNames from 'classnames';
import {connect} from 'react-redux';
import Captcha from 'app/main/captcha';
import CreateTicketForm from 'app/main/dashboard/dashboard-create-ticket/create-ticket-form';
import Widget from 'core-components/widget';
class DashboardCreateTicketPage extends React.Component {
static propTypes = {
userSystemEnabled: React.PropTypes.bool
};
render() {
let Wrapper = 'div';
if(!this.props.userSystemEnabled) {
Wrapper = Widget;
}
return (
<div>
<CreateTicketForm />
<div className={this.getClass()}>
<Wrapper>
<CreateTicketForm userLogged={this.props.userSystemEnabled} />
</Wrapper>
</div>
);
}
getClass() {
let classes = {
'dashboard-create-ticket-page': true,
'dashboard-create-ticket-page_wrapped': (!this.props.userSystemEnabled)
};
return classNames(classes);
}
}
export default DashboardCreateTicketPage;
export default connect((store) => {
return {
userSystemEnabled: store.config['user-system-enabled']
};
})(DashboardCreateTicketPage);

View File

@ -0,0 +1,6 @@
.dashboard-create-ticket-page {
&_wrapped {
padding: 0 10px;
}
}

View File

@ -0,0 +1,13 @@
import React from 'react';
class MainCheckTicketPage extends React.Component {
render() {
return (
<div className="main-check-ticket-page">
</div>
)
}
}
export default MainCheckTicketPage;

View File

@ -63,7 +63,7 @@ class MainSignUpPageWidget extends React.Component {
return {
loading: this.state.loading,
className: 'signup-widget__form',
onSubmit: this.onLoginFormSubmit.bind(this)
onSubmit: this.onSignupFormSubmit.bind(this)
};
}
@ -77,7 +77,7 @@ class MainSignUpPageWidget extends React.Component {
};
}
onLoginFormSubmit(formState) {
onSignupFormSubmit(formState) {
const captcha = this.refs.captcha.getWrappedInstance();
if (!captcha.getValue()) {