From b85ce62b2f0e3f7687adbeaf57df33353ed77e16 Mon Sep 17 00:00:00 2001 From: Felix Hamme Date: Tue, 23 Apr 2019 15:41:43 +0200 Subject: [PATCH] Greet the user after login with a toast --- js/api.js | 17 ++++++++++++++++- js/components/Navigation.js | 14 ++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/js/api.js b/js/api.js index 7877298..d178f70 100644 --- a/js/api.js +++ b/js/api.js @@ -20,7 +20,8 @@ const actiontypes_userinfo = { 'LOGIN' : 'LOGIN', 'LOGIN_RESULT_SUCCESS' : 'LOGIN_RESULT_SUCCESS', 'LOGIN_RESULT_ERROR' : 'LOGIN_RESULT_ERROR', - + 'GREET' : 'GREET', + 'CLEAR_ERRORS' : 'CLEAR_ERRORS', 'LOGOUT' : 'LOGOUT', @@ -37,6 +38,7 @@ const actiontypes_userinfo = { const defaultstate_userinfo = { isSignedIn : false, + wasGreeted : false, username : null, error : false, errorMessages : [], @@ -214,6 +216,7 @@ const reducer_userinfo = (state = defaultstate_userinfo, action) => { case actiontypes_userinfo.LOGIN_RESULT_SUCCESS: return Object.assign({}, state, { isSignedIn : true, + wasGreeted : false, error : false, errorMessages : [], username : action.parameters.username, @@ -235,6 +238,10 @@ const reducer_userinfo = (state = defaultstate_userinfo, action) => { __store.dispatch({ type : actiontypes_userinfo.CLEAR }); }); return Object.assign({}, state, {}); + case actiontypes_userinfo.GREET: + return Object.assign({}, state, { + wasGreeted : true, + }); case actiontypes_userinfo.STORE_AUTH_HEADERS: return Object.assign({}, state, { accesstoken : action.parameters.accesstoken, @@ -396,6 +403,14 @@ export function login(email, password) { }); } +export function greet() { + __store.dispatch({ + type: actiontypes_userinfo.GREET, + parameters: {}, + state: __store.getState() + }); +} + export function logout() { __store.dispatch({ type : actiontypes_userinfo.LOGOUT, diff --git a/js/components/Navigation.js b/js/components/Navigation.js index b9d0775..a1bbb77 100644 --- a/js/components/Navigation.js +++ b/js/components/Navigation.js @@ -13,7 +13,8 @@ import { import { connect } from 'react-redux'; import React from 'react'; -import { logout } from '../api'; +import {greet, logout} from '../api'; +import {notify} from "react-notify-toast"; export class TurniereNavigation extends React.Component { @@ -67,7 +68,12 @@ function Betabadge() { class InvisibleLoginLogoutButtons extends React.Component { render() { - const { isSignedIn, username } = this.props; + const {isSignedIn, username, wasGreeted} = this.props; + + if (isSignedIn && !wasGreeted) { + notify.show('Willkommen, ' + username + '!', 'success', 3000); + greet(); + } if(isSignedIn) { return ( @@ -88,8 +94,8 @@ class InvisibleLoginLogoutButtons extends React.Component { } const mapStateToLoginLogoutButtonProperties = (state) => { - const { isSignedIn, username } = state.userinfo; - return { isSignedIn, username }; + const {isSignedIn, username, wasGreeted} = state.userinfo; + return {isSignedIn, username, wasGreeted}; }; const LoginLogoutButtons = connect(