import React, { useState, useEffect } from "react";
import "@mts/icon/dist/esm/index.css";
import "@mts/icon-button/dist/esm/index.css";
import "@mts/checkbox/dist/esm/index.css";
import "@mts/spinner/dist/esm/index.css";
import "@mts/box/dist/esm/index.css";
import "@mts/text/dist/esm/index.css";
import "@mts/button/dist/esm/index.css";
import "@mts/popup/dist/esm/index.css";
import "@mts/tab/dist/esm/index.css";
import "@mts/input/dist/esm/index.css";
import "@mts/calendar/dist/esm/index.css";
import "@mts/toast/dist/esm/index.css";
import "@mts/pagination/dist/esm/index.css";
import "@mts/base/dist/mtsBase.css";
import { Routes, Route } from "react-router-dom";
import NotFound from "./components/WindowError/NotFound";
import { BebetterContext } from "./Contexts/BebetterContext";
import WindowError from "./components/WindowError/WindowError";
import LoadingApp from "./components/LoadingApp/LoadingApp";
import LocalAuthentication from "./components/Authentication/LocalAuthentication";
import LoginSSO from "./components/Authentication/LoginSSO";
import Alert from "./components/Alert/Alert";
import "./mts.css"; // Наши стили
import jwtDecode from "jwt-decode";
import { useAppDispatch, useAppSelector } from "./hooks/redux";
import { fetchAuthUser } from "./store/actions/getUserInfoActions";
import NoAccess from "./components/NoAccess/NoAccess";
import SalesView from "./pages/sales/SalesView";
import { AdminSalesView } from "./pages/sales/AdminSalesView";
import { routes } from "./Helpers/Constants/routes";
import { ModalAddingView } from "./pages/sales/ModalAddingCategory";
import Layout from "./Layout";

const App = () => {
  
  //----------------------
  const dispatch = useAppDispatch();

  const access_token = localStorage.getItem("access_token");
  // const jwt = localStorage.getItem('jwt');

  const { userInfo, loading } = useAppSelector((state) => state.userInfo);
  console.log("userInfo!!!!",userInfo);
  const{tableBody}=useAppSelector((state) => state.tableBody);
  
  console.log("tableBody!!!!!",tableBody,);import { PayloadAction, createSlice } from "@reduxjs/toolkit";
import { ITableBodyListShema} from "../../models/salesTableBodyShema";

export interface initialStateTypes {
  tadleBody: ITableBodyListShema[];
  loading: boolean;
  error: boolean;
}

const initialState: initialStateTypes = {
  tadleBody: [],
  loading: false,
  error: false,
};

export const tableBodySlice = createSlice({
  name: "tableBody",
  initialState: initialState,
  reducers: {
    fetching(state) {
      state.loading = true;
      state.error = false;
    },
    fetchSuccess(state) {
      state.loading = false;
    },
    fetchSuccessTableBody(state, action: PayloadAction<ITableBodyListShema[]>) {
      state.tadleBody = action.payload;
    },

    fetchingError(state) {
      state.error = true;
    },
  },
});

export default tableBodySlice.reducer;import { AppDispatch } from "..";
import axios from "axios";
import { userInfoShema } from "../../models/userInfoShema";
import { userInfoSlice } from "../slices/userInfoSlice";
import { tableBodySlice } from "../slices/tableBodySlice";
import { tableBodyListShema } from "../../models/salesTableBodyShema";
export const fetchAuthUser = (access_token: string) => {
  return async (dispatch: AppDispatch) => {
    let header = { Authorization: `Bearer ${access_token}` };
    try {
      dispatch(tableBodySlice.actions.fetching());
      // @ts-ignore
      const url = `${window.location.origin}/interaction/api/0.1/get_category`;

      const response_table = axios.get<tableBodyListShema>(url, {
        headers: header,
      });

      Promise.all([response_table]).then((responeses) => {
        let isError = responeses.some(
          (response) => response.data.return_code !== 0
        );

        if (!isError) {
          if (responeses[0].data.tableBody.length > 0) {
            // Получаем первый элемент массива tableBody
            const firstTableBody = responeses[0].data.tableBody[0];
            if (firstTableBody.id !== 0) {
              localStorage.setItem("jwt", String(firstTableBody.id));;
            }

            dispatch(
              tableBodySlice.actions.fetchSuccessTableBody(
                responeses[0].data.tableBody
              )
            );

            dispatch(tableBodySlice.actions.fetchSuccess());
          } else {
            dispatch(tableBodySlice.actions.fetchingError());
          }
        }
      });
    } catch (error) {
      dispatch(tableBodySlice.actions.fetchingError());
    }
  };
};
import { responseDataShema } from "../types";

export interface tableBodyListShema extends responseDataShema {
  tableBody: ITableBodyListShema[];
}

export interface ITableBodyListShema {
  id: number;
  title: string;
  dateСreate: string;
  closingDate: string;
}
import { combineReducers, configureStore } from '@reduxjs/toolkit';
import userInfoReducer from './slices/userInfoSlice';
import tableBodySlice from './slices/tableBodySlice';


const rootReducer = combineReducers({
	userInfo: userInfoReducer,
	tableBody:tableBodySlice,
	
});

export const setupStore = () => {
	return configureStore({
		reducer: rootReducer,
		middleware: (getDefaultMiddleware) =>
			getDefaultMiddleware({
				serializableCheck: false,
			}),
	});
};

export type RootState = ReturnType<typeof rootReducer>;
export type AppStore = ReturnType<typeof setupStore>;
export type AppDispatch = AppStore['dispatch'];отвечай на русском почему console.log("tableBody!!!!!",tableBody,); tableBody!!!!! undefined в чем ошибка