- {userCart.length > 0 && (
+ {userCart?.length > 0 && (
{userCart?.length}
diff --git a/src/redux/reducers/listAddSlice.ts b/src/redux/reducers/listAddSlice.ts
new file mode 100644
index 0000000..71ddc56
--- /dev/null
+++ b/src/redux/reducers/listAddSlice.ts
@@ -0,0 +1,39 @@
+import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
+
+import axios from "../api/api";
+
+export const createAds = createAsyncThunk("listAdds", async () => {
+ const response = await axios.get("/products/ads", {
+ headers: {
+ "Content-Type": "application/json",
+ },
+ });
+ return response.data;
+});
+
+const createAdsSlice = createSlice({
+ name: "ads",
+ initialState: {
+ isLoading: false,
+ data: [],
+ error: false,
+ },
+ reducers: {},
+ extraReducers: (builder) => {
+ builder
+ .addCase(createAds.pending, (state) => {
+ state.isLoading = true;
+ state.error = false;
+ })
+ .addCase(createAds.fulfilled, (state, action) => {
+ state.isLoading = false;
+ state.data = action.payload;
+ })
+ .addCase(createAds.rejected, (state, action) => {
+ state.isLoading = false;
+ state.isLoading = true;
+ });
+ },
+});
+
+export default createAdsSlice.reducer;
diff --git a/src/redux/store.ts b/src/redux/store.ts
index c057976..5dccda1 100644
--- a/src/redux/store.ts
+++ b/src/redux/store.ts
@@ -19,6 +19,7 @@ import authReducer from "./reducers/authSlice";
import wishListSlice from "./reducers/wishListSlice";
import ordersReducer from "./reducers/ordersSlice";
import PaymentSlice from "./reducers/payment";
+import adsReducer from "./reducers/listAddSlice";
const store = configureStore({
reducer: {
@@ -41,6 +42,7 @@ const store = configureStore({
wishes: wishListSlice,
order: ordersReducer,
payment: PaymentSlice,
+ ads: adsReducer,
},
});
export type RootState = ReturnType
;
diff --git a/src/routes/AppRoutes.tsx b/src/routes/AppRoutes.tsx
index 6829c49..9153c1e 100644
--- a/src/routes/AppRoutes.tsx
+++ b/src/routes/AppRoutes.tsx
@@ -42,14 +42,12 @@ const AppRoutes = () => {
setNavigate(navigate);
// setNavigateFunction(navigate);
}, [navigate]);
-
const AlreadyLogged = ({ children }) => {
const navigate = useNavigate();
const token = localStorage.getItem("accessToken");
const decodedToken = token ? JSON.parse(atob(token!.split(".")[1])) : {};
const tokenIsValid = decodedToken.id && decodedToken.roleId;
const isSeller = decodedToken.roleId === 2;
-
useEffect(() => {
if (tokenIsValid) {
isSeller ? navigate("/dashboard") : navigate("/");
@@ -58,7 +56,6 @@ const AppRoutes = () => {
return tokenIsValid ? null : children;
};
-
return (
@@ -117,5 +114,4 @@ const AppRoutes = () => {
);
};
-
export default AppRoutes;