Skip to content

Commit 1160a36

Browse files
committed
migration
1 parent 41bd685 commit 1160a36

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

front/src/contexts/auth/context/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createContext } from 'react';
22

3-
// #region flow types
3+
// #region types
44
export type User = {
55
email: string;
66
};

front/src/contexts/auth/providerComponent/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default class AuthProvider extends Component<
6868
// #endregion
6969

7070
checkIsAuthenticated = (): boolean => {
71-
const checkUserHasId = (user: User) => user && user.id;
71+
const checkUserHasId = (user: User) => user && user?.id;
7272
const user = auth.getUserInfo() ? auth.getUserInfo() : null;
7373
const isAuthenticated = auth.getToken() && checkUserHasId(user);
7474

@@ -114,7 +114,7 @@ export default class AuthProvider extends Component<
114114

115115
setUserInfo = (user: User) => {
116116
if (typeof user === 'object') {
117-
auth.setUserInfo(user);
117+
auth.setUserInfo(JSON.stringify(user));
118118

119119
devToolsStore &&
120120
devToolsStore.dispatch({

front/src/contexts/withDevTools/index.js renamed to front/src/contexts/withDevTools/index.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,53 @@
1-
// @flow
2-
3-
// #region flow types
1+
// #region types
42
export type DevToolsMessageType = 'DISPATCH' | string;
53

64
export type DevToolsMessagePayload = {
7-
type?: string,
8-
state?: any,
9-
...any,
5+
type?: string;
6+
state?: any;
107
};
118

129
export type DevToolsMessage = {
13-
type?: DevToolsMessageType,
14-
payload?: DevToolsMessagePayload,
15-
...any,
10+
type?: DevToolsMessageType;
11+
payload?: DevToolsMessagePayload;
1612
};
1713

1814
export type DevTools = {
19-
connect: () => any,
20-
subscribe: (message: DevToolsMessage) => any,
21-
send: (type: string, state: any) => any,
22-
unsubscribe: () => any,
23-
dispatch: (action: { type: string, ...any }) => any,
24-
disconnect: () => any,
25-
...any,
15+
connect: () => any;
16+
subscribe: (message: DevToolsMessage) => any;
17+
send: (action: { type: string; state?: any }, newState: any) => any;
18+
unsubscribe: () => any;
19+
dispatch: (action: { type: string }) => any;
20+
disconnect: () => any;
2621
};
2722
// #endregion
2823

2924
// #region constants
3025
const isDEV = process.env.NODE_ENV === 'development';
3126

3227
export const withDevTools =
33-
isDEV && typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__;
28+
isDEV &&
29+
typeof window !== 'undefined' &&
30+
(window as any).__REDUX_DEVTOOLS_EXTENSION__;
3431

35-
// $FlowIgnore
3632
const devTools: DevTools = !withDevTools
3733
? null
38-
: window.__REDUX_DEVTOOLS_EXTENSION__.connect();
34+
: (window as any).__REDUX_DEVTOOLS_EXTENSION__.connect();
3935
// #endregion
4036

4137
// #region devtools reducer
42-
const initialState = {
38+
type State = {
39+
auth: any;
40+
};
41+
type Action = {
42+
type: string;
43+
state?: any;
44+
};
45+
46+
const initialState: State = {
4347
auth: {},
4448
};
4549

46-
export const reducer = (
47-
state: any = initialState,
48-
action: { type: string, ...any },
49-
) => {
50+
export const reducer = (state: State = initialState, action: Action) => {
5051
/* eslint-disable no-unused-vars */
5152
switch (action.type) {
5253
// #region auth context
@@ -68,7 +69,7 @@ export const reducer = (
6869
// #endregion
6970

7071
// #region singleton devtools local state
71-
let state;
72+
let state: State;
7273
// #endregion
7374

7475
// #region devToolsStore (redux like)
@@ -77,7 +78,7 @@ export const devToolsStore = !withDevTools
7778
? null
7879
: {
7980
...devTools,
80-
dispatch: action => {
81+
dispatch: (action: Action) => {
8182
// #region action validation
8283
if (!action) {
8384
throw new Error('devTools dispatched action should be defined');

0 commit comments

Comments
 (0)