FIX;Auth reducer init state as default parameter

This commit is contained in:
Roman Jaroš 2021-02-24 22:54:21 +01:00
parent 884c1a9350
commit 30952c7d94
9 changed files with 21 additions and 16 deletions

View file

@ -93,8 +93,8 @@ const App = (): React.ReactElement => {
const userMenuItems: IMenuItem[] = useMemo( const userMenuItems: IMenuItem[] = useMemo(
() => [ () => [
{ label: getMessage(MenuLocalization.signOut), href: '/signin' }, { label: getMessage(MenuLocalization.signIn), href: '/signin' },
{ label: getMessage(MenuLocalization.signOut), href: '/signin' }, { label: getMessage(MenuLocalization.signOut), href: '/signout' },
], ],
[] []
); );

View file

@ -168,10 +168,10 @@ exports[`App should match snapshot 1`] = `
"user": Array [ "user": Array [
Object { Object {
"href": "/signin", "href": "/signin",
"label": "Sign out", "label": "Sign in",
}, },
Object { Object {
"href": "/signin", "href": "/signout",
"label": "Sign out", "label": "Sign out",
}, },
], ],

View file

@ -19,6 +19,7 @@ export class InternalMenuLocalization {
@withNS public calendar: string; @withNS public calendar: string;
@withNS public checkbox: string; @withNS public checkbox: string;
@withNS public home: string; @withNS public home: string;
@withNS public signIn: string;
@withNS public signOut: string; @withNS public signOut: string;
@withNS public localization: string; @withNS public localization: string;
@withNS public localizationStart: string; @withNS public localizationStart: string;

View file

@ -17,6 +17,7 @@ export const menu: InternalMenuLocalization = {
table: 'Tabulka', table: 'Tabulka',
textField: 'Textové pole', textField: 'Textové pole',
toaster: 'Toaster', toaster: 'Toaster',
signIn: 'Přihlásit se',
signOut: 'Odhlásit se', signOut: 'Odhlásit se',
localization: 'Lokalizace', localization: 'Lokalizace',
localizationStart: 'Jak začít', localizationStart: 'Jak začít',

View file

@ -17,6 +17,7 @@ export const menu: InternalMenuLocalization = {
table: 'Table', table: 'Table',
textField: 'Text field', textField: 'Text field',
toaster: 'Toaster', toaster: 'Toaster',
signIn: 'Sign in',
signOut: 'Sign out', signOut: 'Sign out',
localization: 'Localization', localization: 'Localization',
localizationStart: 'Get started', localizationStart: 'Get started',

View file

@ -4,6 +4,7 @@ import { useDispatch } from 'react-redux';
import { setAuthenticated } from '@treejs/auth/actions'; import { setAuthenticated } from '@treejs/auth/actions';
import Button from '@treejs/components/Button'; import Button from '@treejs/components/Button';
import { Grid, GridCol } from '@treejs/components/Grid';
import { STATUS } from '@treejs/types/common'; import { STATUS } from '@treejs/types/common';
import history from 'documentation/utils/history'; import history from 'documentation/utils/history';
@ -28,13 +29,11 @@ export const SignIn: React.FC = () => {
}, []); }, []);
return ( return (
<> <Grid cols={4}>
<GridCol>
<Button label="Sing in" status={STATUS.info} onClick={authenticate} /> <Button label="Sing in" status={STATUS.info} onClick={authenticate} />
</GridCol>
<a href="#" onClick={handleSignOut}> </Grid>
Show sign out page
</a>
</>
); );
}; };

View file

@ -5,6 +5,7 @@ import { useDispatch } from 'react-redux';
import { setAuthenticated } from '@treejs/auth/actions'; import { setAuthenticated } from '@treejs/auth/actions';
import authRequired, { IAuthHOCInjectProps } from '@treejs/auth/hoc/authRequired'; import authRequired, { IAuthHOCInjectProps } from '@treejs/auth/hoc/authRequired';
import Button from '@treejs/components/Button'; import Button from '@treejs/components/Button';
import { Grid, GridCol } from '@treejs/components/Grid';
import { STATUS } from '@treejs/types/common'; import { STATUS } from '@treejs/types/common';
import history from 'documentation/utils/history'; import history from 'documentation/utils/history';
@ -33,9 +34,11 @@ export const SignOut: React.FC<IProps> = () => {
}, []); }, []);
return ( return (
<> <Grid cols={4}>
<GridCol>
<Button label="Sign out" status={STATUS.warning} onClick={authenticate} /> <Button label="Sign out" status={STATUS.warning} onClick={authenticate} />
</> </GridCol>
</Grid>
); );
}; };

View file

@ -12,8 +12,7 @@ const initialState: AuthReducer<any> = {
type Payload = SetAuthenticatedPayload<any>; type Payload = SetAuthenticatedPayload<any>;
const reducer = (state: AuthReducer<any>, action: Action<Payload, ACTIONS>): AuthReducer<any> => { const reducer = (state = initialState, action: Action<Payload, ACTIONS>): AuthReducer<any> => {
state = initialState;
if (action.type === ACTIONS.SET_AUTHENTICATE) { if (action.type === ACTIONS.SET_AUTHENTICATE) {
return { return {
...state, ...state,

View file

@ -86,6 +86,7 @@ const field = (theme) => ({
}, },
'.logo': { '.logo': {
margin: '0.25rem', margin: '0.25rem',
marginLeft: '1rem',
fontSize: '1rem', fontSize: '1rem',
textAlign: 'center', textAlign: 'center',
}, },