commit 39d7450370aa02c14218575f0d4240b2bbe2ab65
Author: Vaclav Honzik <vaclavhonzik98@gmail.com>
Date:   Sat Apr 2 18:39:34 2022 +0200

    re #9369 - catalog item thunks

diff --git a/frontend/src/features/Auth/userSlice.ts b/frontend/src/features/Auth/userSlice.ts
index acb7a65..0c8c0ab 100644
--- a/frontend/src/features/Auth/userSlice.ts
+++ b/frontend/src/features/Auth/userSlice.ts
@@ -1,4 +1,4 @@
-import { createSlice, PayloadAction } from '@reduxjs/toolkit'
+import { createSlice } from '@reduxjs/toolkit'
 import { persistReducer } from 'redux-persist'
 import storage from 'redux-persist/lib/storage'
 import { logIn } from './userThunks'
@@ -42,7 +42,6 @@ export const userSlice = createSlice({
             lastErr: action.payload,
         }),
         setUserState: (state, action) => {
-            console.log('user state set')
             return ({ ...state, ...action.payload })
         },
     },
@@ -60,6 +59,7 @@ export const userSlice = createSlice({
     },
 })
 
+
 const userReducer = persistReducer(persistConfig, userSlice.reducer)
 
 export const { logout, refreshTokens, setErr, setUserState } = userSlice.actions
diff --git a/frontend/src/features/Auth/userThunks.ts b/frontend/src/features/Auth/userThunks.ts
index 813f254..a7a16d7 100644
--- a/frontend/src/features/Auth/userThunks.ts
+++ b/frontend/src/features/Auth/userThunks.ts
@@ -1,9 +1,7 @@
 import { createAsyncThunk } from '@reduxjs/toolkit'
 import axiosInstance from '../../api/api'
-import { UserDto } from '../../swagger/data-contracts'
-import { setErr, setUserState, UserState } from './userSlice'
+import {  UserState } from './userSlice'
 import jwt from 'jwt-decode' 
-import { RootState } from '../redux/store'
 
 const loginError =
     'Server error occurred while logging in. Please contact help service to resolve this issue or try again later.'
@@ -16,7 +14,7 @@ export interface UserLogin {
 
 export const logIn = createAsyncThunk(
     'user/login',
-    async (userDto: UserLogin, { dispatch, getState }) => {
+    async (userDto: UserLogin, { getState }) => {
         try {
             // @ts-ignore
             if (getState().user.isLoggedIn) {
@@ -47,7 +45,6 @@ export const logIn = createAsyncThunk(
             
             return userState
         } catch (err: any) {
-            console.log(err)
             return Promise.reject(loginError)
         }
     }
diff --git a/frontend/src/features/Catalog/catalogSlice.ts b/frontend/src/features/Catalog/catalogSlice.ts
new file mode 100644
index 0000000..8ecfb64
--- /dev/null
+++ b/frontend/src/features/Catalog/catalogSlice.ts
@@ -0,0 +1,36 @@
+import { createSlice } from '@reduxjs/toolkit'
+import { CatalogItemDto } from '../../swagger/data-contracts'
+import { getCatalogItem, getCatalogItems } from './catalogThunks'
+
+export interface CatalogState {
+    catalogItems: CatalogItemDto[] // Items shown in the table
+    isListLoading: boolean
+    lastErr?: string
+    catalogItem?: CatalogItemDto // Item shown in detail
+    isItemLoading: boolean
+}
+
+const initialState: CatalogState = {
+    catalogItems: [],
+    isListLoading: true,
+    isItemLoading: true,
+}
+
+export const catalogSlice = createSlice({
+    name: 'catalog',
+
+    initialState,
+
+    reducers: {},
+
+    extraReducers: (builder) => {
+        builder.addCase(getCatalogItems.fulfilled, (state, action) => ({
+            ...state,
+            catalogItems: action.payload,
+            isListLoading: false,
+        }))
+        builder.addCase(getCatalogItems.rejected, (state, action) => ({
+            ...state, lastErr: action.payload as string
+        }))
+    },
+})
diff --git a/frontend/src/features/Catalog/catalogThunks.ts b/frontend/src/features/Catalog/catalogThunks.ts
new file mode 100644
index 0000000..2cd107b
--- /dev/null
+++ b/frontend/src/features/Catalog/catalogThunks.ts
@@ -0,0 +1,37 @@
+import { createAsyncThunk } from '@reduxjs/toolkit'
+import axiosInstance from '../../api/api'
+
+const apiError =
+    'Error while fetching data from the server, please try again later.'
+
+export const getCatalogItems = createAsyncThunk(
+    'catalog/getCatalogItems',
+    async () => {
+        try {
+            const { data, status } = await axiosInstance.get('/catalog-items')
+            if (status !== 200) {
+                return Promise.reject(apiError)
+            }
+            return data
+        } catch (err: any) {
+            return Promise.reject(apiError)
+        }
+    }
+)
+
+export const getCatalogItem = createAsyncThunk(
+    'catalog/getCatalogItem',
+    async (id: number) => {
+        try {
+            const { data, status } = await axiosInstance.get(
+                `/catalog-items/${id}`
+            )
+            if (status !== 200) {
+                return Promise.reject(apiError)
+            }
+            return data
+        } catch (err: any) {
+            return Promise.reject(apiError)
+        }
+    }
+)
