File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { PuffLoader } from 'react-spinners';
1212import { Meta } from '../Meta' ;
1313import { deleteItem } from '../../store/features/product/sellerCollectionProductsSlice' ;
1414import ConfirmModal from './ConfirmModal' ;
15+ import { useNavigate } from 'react-router-dom' ;
1516
1617const 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
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 11/* eslint-disable */
22import 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" ;
44const axiosInstance = axios . create ( {
55 baseURL : `${ URL } ` ,
66 headers : {
You can’t perform that action at this time.
0 commit comments