Skip to content

Commit e4a7b62

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 ef00773 commit e4a7b62

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

package-lock.json

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

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

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)