Skip to content

Commit

Permalink
[finished 187584874] seller delete item
Browse files Browse the repository at this point in the history
  • Loading branch information
solangeihirwe03 committed Jul 25, 2024
1 parent 5444bce commit 89cc748
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/components/product/SellerProduct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { PuffLoader } from 'react-spinners';
import { Meta } from '../Meta';
import { deleteItem } from '../../store/features/product/sellerCollectionProductsSlice';
import ConfirmModal from './ConfirmModal';
import { useNavigate } from 'react-router-dom';

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

useEffect(() => {
dispatch(fetchSingleSellerProduct(productId));
Expand Down Expand Up @@ -47,7 +49,8 @@ const SellerProduct = ({ productId }: { productId: string }) => {
const handleDelete = async () => {
if (updatedProduct) {
await dispatch(deleteItem(itemToDelete));
setShowConfirm(false);
setShowConfirm(false);
navigate('/seller/products');
}
};

Expand Down
11 changes: 11 additions & 0 deletions src/pages/seller/SellerCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@ export default function SellerCollection() {

const [showConfirm, setShowConfirm] = useState(false);
const [itemToDelete, setItemToDelete] = useState<{ id: string; name: string } | null>(null);
const [products, setProducts] = useState(data?.products || []);

useEffect(() => {
if (data?.products) {
setProducts(data.products);
}
}, [data]);


const handleDelete = async () => {
try {
if (itemToDelete !== null) {
await dispatch(deleteItem(itemToDelete.id));
if (data?.products) {
const updatedProducts = data.products.filter(product => product.id !== itemToDelete.id);
dispatch(fetchSellerCollectionProduct());
}
setShowConfirm(false);
setItemToDelete(null)
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/axios/axiosInstance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import axios from "axios";
export const URL = "http://localhost:5001" //https://e-commerce-ninjas-platform-backend.onrender.com";
export const URL = "https://e-commerce-ninjas-platform-backend.onrender.com";
const axiosInstance = axios.create({
baseURL: `${URL}`,
headers: {
Expand Down

0 comments on commit 89cc748

Please sign in to comment.