File tree 3 files changed +16
-2
lines changed
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';
12
12
import { Meta } from '../Meta' ;
13
13
import { deleteItem } from '../../store/features/product/sellerCollectionProductsSlice' ;
14
14
import ConfirmModal from './ConfirmModal' ;
15
+ import { useNavigate } from 'react-router-dom' ;
15
16
16
17
const SellerProduct = ( { productId } : { productId : string } ) => {
17
18
const dispatch = useAppDispatch ( ) ;
@@ -20,6 +21,7 @@ const SellerProduct = ({ productId }: { productId: string }) => {
20
21
const [ updatedProduct , setUpdatedProduct ] = useState < ISingleProduct | null > ( null ) ;
21
22
const [ showConfirm , setShowConfirm ] = useState ( false ) ;
22
23
const [ itemToDelete , setItemToDelete ] = useState < string | null > ( null ) ;
24
+ const navigate = useNavigate ( )
23
25
24
26
useEffect ( ( ) => {
25
27
dispatch ( fetchSingleSellerProduct ( productId ) ) ;
@@ -47,7 +49,8 @@ const SellerProduct = ({ productId }: { productId: string }) => {
47
49
const handleDelete = async ( ) => {
48
50
if ( updatedProduct ) {
49
51
await dispatch ( deleteItem ( itemToDelete ) ) ;
50
- setShowConfirm ( false ) ;
52
+ setShowConfirm ( false ) ;
53
+ navigate ( '/seller/products' ) ;
51
54
}
52
55
} ;
53
56
Original file line number Diff line number Diff line change @@ -27,12 +27,23 @@ export default function SellerCollection() {
27
27
28
28
const [ showConfirm , setShowConfirm ] = useState ( false ) ;
29
29
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 ] ) ;
30
37
31
38
32
39
const handleDelete = async ( ) => {
33
40
try {
34
41
if ( itemToDelete !== null ) {
35
42
await dispatch ( deleteItem ( itemToDelete . id ) ) ;
43
+ if ( data ?. products ) {
44
+ const updatedProducts = data . products . filter ( product => product . id !== itemToDelete . id ) ;
45
+ dispatch ( fetchSellerCollectionProduct ( ) ) ;
46
+ }
36
47
setShowConfirm ( false ) ;
37
48
setItemToDelete ( null )
38
49
}
Original file line number Diff line number Diff line change 1
1
/* eslint-disable */
2
2
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" ;
4
4
const axiosInstance = axios . create ( {
5
5
baseURL : `${ URL } ` ,
6
6
headers : {
You can’t perform that action at this time.
0 commit comments