Commit f6961248 authored by Pavel Mishakov's avatar Pavel Mishakov

93 done FRONT

parent a124cb34
......@@ -4,4 +4,5 @@ export default interface IUser {
password: string
active: boolean
token: string
role: string
}
\ No newline at end of file
import IUSer from "./IUser";
import IUser from "./IUser";
export default interface IUserGetDto {
_id: IUSer['_id']
username: IUSer['username']
token: IUSer['token']
_id: IUser['_id']
username: IUser['username']
token: IUser['token']
role: IUser['role']
}
\ No newline at end of file
......@@ -55,7 +55,7 @@ export const productsSlice = createSlice({
})
.addCase(getProducts.fulfilled, (state, action) => {
state.loadingProducts = false
state.products = action.payload.result as IProduct[]
state.products = action.payload.result as IProduct[] || []
state.messageProducts = action.payload.message
})
.addCase(getProductById.rejected, (state) => {
......
import { configureStore, ThunkAction, Action } from "@reduxjs/toolkit"
import { configureStore, ThunkAction, Action, getDefaultMiddleware } from "@reduxjs/toolkit"
import { useDispatch } from 'react-redux'
import { productsSlice } from "./products/products.slice"
import { usersSlice } from "./users/users.slice"
const localStorageMiddleware = ({ getState }: any) => {
return (next: any) => (action: any) => {
const result = next(action);
localStorage.setItem('applicationState', JSON.stringify(getState()));
return result;
};
};
const reHydrateStore = () => {
if (localStorage.getItem('applicationState') !== null) {
return JSON.parse(localStorage.getItem('applicationState') || ''); // re-hydrate the store
}
};
const makeStore = () => {
return configureStore({
reducer: {
products: productsSlice.reducer,
users: usersSlice.reducer
}
},
preloadedState: reHydrateStore(),
middleware: (mw) => mw().concat(localStorageMiddleware)
})
}
export const store = makeStore()
const store = makeStore()
export type AppDispatch = typeof store.dispatch;
export type AppStore = ReturnType<typeof makeStore>;
export type AppState = ReturnType<AppStore["getState"]>;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment