Skip to content

Commit e3c1e41

Browse files
SaddockAimesolangeihirwe03
authored andcommitted
ft-mark-all-notification-as-read (#34)
* [#187584881] ft-mark-all-notification-as-read * [#187584881] ft-mark-all-notification-as-read * Requested changes notifications
1 parent 3c45df7 commit e3c1e41

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

Diff for: package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/pages/SellerDeleteItem.tsx

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { useEffect } from 'react'
2+
import { ISingleProduct } from '../utils/types/product';
3+
import { useAppDispatch, useAppSelector } from '../store/store';
4+
import { deleteItem } from '../store/features/product/productSlice';
5+
6+
interface ProductProps {
7+
id: string;
8+
images: string[];
9+
name: string;
10+
price: string;
11+
stock: number;
12+
description: string;
13+
discount: number;
14+
}
15+
16+
const SellerDeleteItem:React.FC<ProductProps>= ({id, images, name, price}) => {
17+
const dispatch = useAppDispatch();
18+
// const { product, isError, isSuccess, isLoading, message }: ISingleProduct = useAppSelector((state: any) => state.products);
19+
20+
useEffect(()=>{
21+
dispatch(deleteItem(id))
22+
},[dispatch])
23+
24+
25+
return (
26+
<div>
27+
<p>{name}</p>
28+
<p>{price}</p>
29+
<img src={images[0]} alt="" />
30+
</div>
31+
)
32+
}
33+
34+
export default SellerDeleteItem

Diff for: src/router.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import SellerViewProduct from "./pages/seller/SellerViewProduct";
2222
import SellerCollection from "./pages/seller/SellerCollection";
2323
import { SellerLayout } from "./components/layout/SellerLayout";
2424
import SellerDashboard from "./pages/seller/SellerDashboard";
25+
import SellerDeleteItem from "./pages/SellerDeleteItem";
2526

2627
const AppRouter: React.FC = () => {
2728
return (
@@ -59,6 +60,7 @@ const AppRouter: React.FC = () => {
5960
<Route path="shopping-cart" element={<UserViewCart />} />
6061
<Route path="*" element={<NotFound />} />
6162
<Route path="seller/login" element={<SellerLogin />} />
63+
<Route path="/deleteItem" element={<SellerDeleteItem/>}/>
6264
</Route>
6365
<Route path="/seller" element={<SellerLayout/>}>
6466
<Route index element={<Navigate to="dashboard" replace />} />

Diff for: src/store/features/product/productSlice.tsx

+27-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable */
22
import { createSlice, createAsyncThunk, PayloadAction } from "@reduxjs/toolkit";
33
import productService from "./productService";
4-
import { IProduct, SearchCriteria } from "../../../utils/types/product";
4+
import { IProduct, ISingleProduct, SearchCriteria } from "../../../utils/types/product";
55
import { getErrorMessage } from "../../../utils/axios/axiosInstance";
66

77
const initialState: { products: IProduct[] | null; isLoading: boolean; isError: boolean | null; isSuccess: boolean; message: string } = {
@@ -31,6 +31,15 @@ export const searchProduct = createAsyncThunk<IProduct, SearchCriteria>("product
3131
}
3232
);
3333

34+
export const deleteItem = createAsyncThunk<ISingleProduct, string>("product/deleteProduct", async(id, thunkApi)=>{
35+
try{
36+
const response = await productService.deleteItem(id)
37+
return response
38+
} catch(error){
39+
return thunkApi.rejectWithValue(error)
40+
}
41+
})
42+
3443
const productSlice = createSlice({
3544
name: "products",
3645
initialState,
@@ -68,6 +77,23 @@ const productSlice = createSlice({
6877
state.isError = true;
6978
state.message = action.payload;
7079
state.isSuccess = false;
80+
})
81+
.addCase(deleteItem.pending, (state)=>{
82+
state.isLoading = true,
83+
state.isError = false,
84+
state.isSuccess = false
85+
})
86+
.addCase(deleteItem.fulfilled, (state, action: PayloadAction<ISingleProduct>)=>{
87+
state.isLoading = false,
88+
state.isError = false,
89+
state.products = state.products.filter(product => product.id !== action.payload.id),
90+
state.isSuccess = true
91+
})
92+
.addCase(deleteItem.rejected, (state, action: PayloadAction<any>)=>{
93+
state.isLoading = false,
94+
state.isError = true,
95+
state.products = action.payload,
96+
state.isSuccess = false
7197
});
7298
}
7399
})

0 commit comments

Comments
 (0)