Skip to content

Commit 251d039

Browse files
[start 187584874] seller delete item
1 parent 0cc232d commit 251d039

File tree

8 files changed

+129
-62
lines changed

8 files changed

+129
-62
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
@import "./assets/styles/liveChat.scss";
3434
@import "./assets//styles/UserProfile.scss";
3535
@import "./assets/styles/SellerSideProduct.scss";
36+
@import "./assets/styles/SellerDeleteItem.scss"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
@import "./Colors";
2+
3+
.confirm-dialog {
4+
margin-left: 27rem;
5+
border-radius: 2.2rem;
6+
margin-top: 9rem;
7+
width: 80%;
8+
height: 87vh;
9+
position: fixed;
10+
top: 0;
11+
left: 0;
12+
right: 0;
13+
bottom: 0;
14+
background-color: rgba(0, 0, 0, 0.5);
15+
display: flex;
16+
justify-content: center;
17+
align-items: center;
18+
z-index: 1000;
19+
font-size: 1.6rem;
20+
21+
.confirm-dialog-content {
22+
background-color: white;
23+
padding: 20px;
24+
border-radius: 8px;
25+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
26+
text-align: center;
27+
28+
.modal-header {
29+
font-size: 1.8rem;
30+
font-weight: bold;
31+
margin-bottom: 1.5;
32+
display: flex;
33+
flex-direction: column;
34+
align-items: center;
35+
36+
.icon__delete {
37+
color: $red-color;
38+
font-size: 3rem;
39+
}
40+
}
41+
p{
42+
padding: 1rem 0;
43+
i{
44+
text-transform: uppercase;
45+
font-weight: bold;
46+
}
47+
}
48+
.modal-footer{
49+
float: right;
50+
button {
51+
margin: 0 10px;
52+
padding: .7rem 3rem;
53+
border: none;
54+
border-radius: 1rem;
55+
font-family: $text-family;
56+
}
57+
.delete-btn{
58+
background: $red-middle-color;
59+
color: $red-color;
60+
}
61+
.cancel-btn{
62+
background: lighten($fifth-color, 19%);
63+
color: $fifth-color;
64+
}
65+
}
66+
}
67+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable */
2+
import React from 'react';
3+
import DeleteIcon from '@mui/icons-material/Delete';
4+
5+
interface ConfirmModalProps {
6+
isOpen: boolean;
7+
title: string;
8+
message: string;
9+
onConfirm: () => void;
10+
onCancel: () => void;
11+
}
12+
13+
const ConfirmModal: React.FC<ConfirmModalProps> = ({ isOpen, title, message, onConfirm, onCancel }) => {
14+
if (!isOpen) return null;
15+
16+
return (
17+
<div className="confirm-dialog">
18+
<div className="confirm-dialog-content">
19+
<div className="modal-header">
20+
<DeleteIcon className='icon__delete' /> {title}
21+
</div>
22+
<p dangerouslySetInnerHTML={{ __html: message }} />
23+
<div className="modal-footer">
24+
<button onClick={onCancel} className='cancel-btn'>Cancel</button>
25+
<button onClick={onConfirm} className='delete-btn'>Delete</button>
26+
</div>
27+
</div>
28+
</div>
29+
);
30+
};
31+
32+
export default ConfirmModal;

src/pages/SellerDeleteItem.tsx

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/store/features/product/productSlice.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,6 @@ 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-
4334
const productSlice = createSlice({
4435
name: "products",
4536
initialState,
@@ -78,23 +69,7 @@ const productSlice = createSlice({
7869
state.message = action.payload;
7970
state.isSuccess = false;
8071
})
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
97-
});
72+
;
9873
}
9974
})
10075

src/store/features/product/sellerCollectionProductsSlice.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,21 @@ const initialState: ISellerCollectionProductInitialResponse = {
2121
export const fetchSellerCollectionProduct = createAsyncThunk<ISellerCollectionProductResponse>("products/fetchSellerCollectionProducts", async (_,thunkApi) => {
2222
try {
2323
const response = await productService.fetchSellerProducts();
24+
console.log(response)
2425
return response;
2526
} catch (error) {
2627
return thunkApi.rejectWithValue(getErrorMessage(error));
2728
}
2829
});
2930

31+
export const deleteItem = createAsyncThunk<ISellerCollectionProductResponse, string>("product/deleteProduct", async(id, thunkApi)=>{
32+
try{
33+
const response = await productService.SellerDeleteItem(id)
34+
return response
35+
} catch(error){
36+
return thunkApi.rejectWithValue(error)
37+
}
38+
})
3039

3140
const sellerCollectionProductsSlice = createSlice({
3241
name: "sellerCollectionProducts",
@@ -49,6 +58,23 @@ const sellerCollectionProductsSlice = createSlice({
4958
state.isError = false;
5059
state.isSuccess = false;
5160
state.message = action.payload.message || null
61+
})
62+
.addCase(deleteItem.pending, (state)=>{
63+
state.isLoading = true,
64+
state.isError = false,
65+
state.isSuccess = false
66+
})
67+
.addCase(deleteItem.fulfilled, (state, action: PayloadAction<ISellerCollectionProductResponse>)=>{
68+
state.isLoading = false,
69+
state.isError = false,
70+
state.data= action.payload.data,
71+
state.isSuccess = true
72+
})
73+
.addCase(deleteItem.rejected, (state, action: PayloadAction<any>)=>{
74+
state.isLoading = false,
75+
state.isError = true,
76+
state.message = action.payload,
77+
state.isSuccess = false
5278
});
5379
}
5480
})

src/utils/axios/axiosInstance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable */
22
import axios from "axios";
3-
export const URL = "https://e-commerce-ninjas-platform-backend.onrender.com";
3+
export const URL = "http://localhost:5001" //https://e-commerce-ninjas-platform-backend.onrender.com";
44
const axiosInstance = axios.create({
55
baseURL: `${URL}`,
66
headers: {

0 commit comments

Comments
 (0)