MCPcopy Create free account
hub / github.com/flatlogic/react-material-admin / userReducer

Function userReducer

src/context/UserContext.js:14–52  ·  view source on GitHub ↗
(state, action)

Source from the content-addressed store, hash-verified

12let UserDispatchContext = React.createContext();
13
14function userReducer(state, action) {
15 switch (action.type) {
16 case 'LOGIN_SUCCESS':
17 return {
18 ...state,
19 ...action.payload,
20 };
21 case 'REGISTER_REQUEST':
22 case 'RESET_REQUEST':
23 case 'PASSWORD_RESET_EMAIL_REQUEST':
24 return {
25 ...state,
26 isFetching: true,
27 errorMessage: '',
28 };
29 case 'SIGN_OUT_SUCCESS':
30 return { ...state };
31 case 'AUTH_INIT_ERROR':
32 return Object.assign({}, state, {
33 currentUser: null,
34 loadingInit: false,
35 });
36 case 'REGISTER_SUCCESS':
37 case 'RESET_SUCCESS':
38 case 'PASSWORD_RESET_EMAIL_SUCCESS':
39 return Object.assign({}, state, {
40 isFetching: false,
41 errorMessage: '',
42 });
43 case 'AUTH_FAILURE':
44 return Object.assign({}, state, {
45 isFetching: false,
46 errorMessage: action.payload,
47 });
48 default: {
49 throw new Error(`Unhandled action type: ${action.type}`);
50 }
51 }
52}
53
54function UserProvider({ children }) {
55 let [state, dispatch] = React.useReducer(userReducer, {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected