Add notifications and redirect after trying to register

This commit is contained in:
Jonny 2019-06-18 13:49:12 +02:00
parent 4f9942e242
commit 70047a2e55
2 changed files with 19 additions and 3 deletions

View File

@ -50,6 +50,7 @@ const reducerUserinfo = (state = defaultStateUserinfo, action) => {
__store.dispatch({ __store.dispatch({
type: actionTypesUserinfo.REGISTER_RESULT_SUCCESS type: actionTypesUserinfo.REGISTER_RESULT_SUCCESS
}); });
action.parameters.successCallback();
storeOptionalToken(resp); storeOptionalToken(resp);
}).catch(error => { }).catch(error => {
if (error.response) { if (error.response) {
@ -70,6 +71,7 @@ const reducerUserinfo = (state = defaultStateUserinfo, action) => {
} }
}); });
} }
action.parameters.errorCallback();
}); });
return Object.assign({}, state, {}); return Object.assign({}, state, {});
case actionTypesUserinfo.REGISTER_RESULT_SUCCESS: case actionTypesUserinfo.REGISTER_RESULT_SUCCESS:
@ -357,13 +359,15 @@ export function verifyCredentials() {
} }
} }
export function register(username, email, password) { export function register(username, email, password, successCallback, errorCallback) {
__store.dispatch({ __store.dispatch({
type: actionTypesUserinfo.REGISTER, type: actionTypesUserinfo.REGISTER,
parameters: { parameters: {
username: username, username: username,
email: email, email: email,
password: password password: password,
successCallback: successCallback,
errorCallback: errorCallback
}, },
state: __store.getState() state: __store.getState()
}); });

View File

@ -1,6 +1,8 @@
import Head from 'next/head'; import Head from 'next/head';
import React from 'react'; import React from 'react';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {notify} from 'react-notify-toast';
import Router from 'next/router';
import { import {
Button, Card, CardBody, Container, Form, FormGroup, FormText, Input, Label Button, Card, CardBody, Container, Form, FormGroup, FormText, Input, Label
} from 'reactstrap'; } from 'reactstrap';
@ -95,12 +97,22 @@ class RegisterForm extends React.Component {
<FormText className="mb-2 mt-4"> <FormText className="mb-2 mt-4">
Du akzeptierst die <a href="/privacy">Datenschutzbestimmungen</a>, wenn du auf Registrieren klickst. Du akzeptierst die <a href="/privacy">Datenschutzbestimmungen</a>, wenn du auf Registrieren klickst.
</FormText> </FormText>
<Button onClick={register.bind(this, this.state.username, this.state.email, this.state.password)} <Button onClick={() => this.registerUser()}
color="success" size="lg" className="w-100 shadow-sm">Registrieren</Button> color="success" size="lg" className="w-100 shadow-sm">Registrieren</Button>
<VisibleRegisterErrorList/> <VisibleRegisterErrorList/>
</Form>); </Form>);
} }
registerUser() {
register(
this.state.username, this.state.email, this.state.password, () => {
notify.show('Sie wurden erfolgreich registriert, ' + this.state.username + '!', 'success', 5000);
Router.push('/');
}, () => {
notify.show('Sie konnten nicht registriert werden.', 'warning', 5000);
});
}
handlePasswordInput(input) { handlePasswordInput(input) {
this.setState({password: input.target.value}); this.setState({password: input.target.value});
} }