Skip to content

Commit 89cc748

Browse files
[finished 187584874] seller delete item
1 parent 5444bce commit 89cc748

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Diff for: src/components/product/SellerProduct.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PuffLoader } from 'react-spinners';
1212
import { Meta } from '../Meta';
1313
import { deleteItem } from '../../store/features/product/sellerCollectionProductsSlice';
1414
import ConfirmModal from './ConfirmModal';
15+
import { useNavigate } from 'react-router-dom';
1516

1617
const SellerProduct = ({ productId }: { productId: string }) => {
1718
const dispatch = useAppDispatch();
@@ -20,6 +21,7 @@ const SellerProduct = ({ productId }: { productId: string }) => {
2021
const [updatedProduct, setUpdatedProduct] = useState<ISingleProduct | null>(null);
2122
const [showConfirm, setShowConfirm] = useState(false);
2223
const [itemToDelete, setItemToDelete] = useState<string | null>(null);
24+
const navigate = useNavigate()
2325

2426
useEffect(() => {
2527
dispatch(fetchSingleSellerProduct(productId));
@@ -47,7 +49,8 @@ const SellerProduct = ({ productId }: { productId: string }) => {
4749
const handleDelete = async () => {
4850
if (updatedProduct) {
4951
await dispatch(deleteItem(itemToDelete));
50-
setShowConfirm(false);
52+
setShowConfirm(false);
53+
navigate('/seller/products');
5154
}
5255
};
5356

Diff for: src/pages/seller/SellerCollection.tsx

+11
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ export default function SellerCollection() {
2727

2828
const [showConfirm, setShowConfirm] = useState(false);
2929
const [itemToDelete, setItemToDelete] = useState<{ id: string; name: string } | null>(null);
30+
const [products, setProducts] = useState(data?.products || []);
31+
32+
useEffect(() => {
33+
if (data?.products) {
34+
setProducts(data.products);
35+
}
36+
}, [data]);
3037

3138

3239
const handleDelete = async () => {
3340
try {
3441
if (itemToDelete !== null) {
3542
await dispatch(deleteItem(itemToDelete.id));
43+
if (data?.products) {
44+
const updatedProducts = data.products.filter(product => product.id !== itemToDelete.id);
45+
dispatch(fetchSellerCollectionProduct());
46+
}
3647
setShowConfirm(false);
3748
setItemToDelete(null)
3849
}

Diff for: src/utils/axios/axiosInstance.ts

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

0 commit comments

Comments
 (0)