Skip to content

Commit 24defac

Browse files
committed
Creates header redux module
1 parent 06cc30d commit 24defac

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/modules/__tests__/header.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import header, { setCustom } from '../header';
2+
3+
describe('header redux module', () => {
4+
describe('reducer', () => {
5+
const initialState = {
6+
custom: false,
7+
userLogo: null,
8+
};
9+
it('should have initialState', () => {
10+
const state = header(undefined, {});
11+
expect(state).toEqual(initialState);
12+
});
13+
it('handles SET_CUSTOM action', () => {
14+
let state = header(initialState, setCustom(true));
15+
expect(state.custom).toBe(true);
16+
state = header(initialState, setCustom(false));
17+
expect(state.custom).toBe(false);
18+
});
19+
});
20+
});

src/modules/header.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createReducer, updateKey } from '../lib/utils';
2+
import { createStandardAction } from 'typesafe-actions';
3+
4+
const SET_CUSTOM = 'header/SET_CUSTOM';
5+
6+
export const setCustom = createStandardAction(SET_CUSTOM)<boolean>();
7+
8+
type UserLogo = {
9+
title: string;
10+
logo_image: string;
11+
};
12+
13+
interface HeaderState {
14+
custom: boolean;
15+
userLogo: null | UserLogo;
16+
}
17+
18+
type SetCustom = ReturnType<typeof setCustom>;
19+
20+
const initialState = {
21+
custom: false,
22+
userLogo: null,
23+
};
24+
25+
const header = createReducer(
26+
{
27+
[SET_CUSTOM]: (state, action: SetCustom) => {
28+
return updateKey(state, 'custom', action.payload);
29+
},
30+
},
31+
initialState,
32+
);
33+
34+
export default header;

0 commit comments

Comments
 (0)