Fakultas Ilmu Komputer UI

ApplicationState.jsx 1018 Bytes
Newer Older
1
2
3
4
5
6
import React, { useReducer } from "react";
import AuthReducer, { initialState } from "./store/reducers/auth_reducer";
import * as ACTIONS from "./store/actions/actions";
import AuthContext from "./utils/contex";
import Routes from "./routes";
import Loader from "./component/Loader";
7
import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

const ApplicationState = () => {
  const [stateAuthReducer, dispatchAuthReducer] = useReducer(
    AuthReducer,
    initialState()
  );

  const handleLogin = (profile) => {
    dispatchAuthReducer(ACTIONS.login(profile));
  };

  const handleLogout = () => {
    dispatchAuthReducer(ACTIONS.logout());
  };

23
24
  const theme = createMuiTheme();

25
  return (
26
    <ThemeProvider theme={theme}>
27
28
29
30
31
32
33
34
35
36
      <Loader />
      <AuthContext.Provider
        value={{
          ...stateAuthReducer,
          handleLogin,
          handleLogout,
        }}
      >
        <Routes />
      </AuthContext.Provider>
37
    </ThemeProvider>
38
39
40
  );
};
export default ApplicationState;