30 lines
784 B
TypeScript
30 lines
784 B
TypeScript
import { createAsyncThunk } from '@reduxjs/toolkit';
|
|
import { getCategoriesApi, getProductsApi, GetProductsResponse } from '@api';
|
|
|
|
export const getAllProductsThunk = createAsyncThunk<
|
|
GetProductsResponse,
|
|
void,
|
|
{ rejectValue: string }
|
|
>('home/getAllProducts', async (_, { rejectWithValue }) => {
|
|
try {
|
|
const response = await getProductsApi();
|
|
return response;
|
|
} catch (error: any) {
|
|
return rejectWithValue(
|
|
error.response?.data?.message || 'Failed to fetch products',
|
|
);
|
|
}
|
|
});
|
|
|
|
export const getAllCategoriesThunk = createAsyncThunk(
|
|
'categories/getAll',
|
|
async (_, { rejectWithValue }) => {
|
|
try {
|
|
const response = await getCategoriesApi();
|
|
return response;
|
|
} catch (error) {
|
|
return rejectWithValue(error);
|
|
}
|
|
},
|
|
);
|