diff --git a/src/components/ProductsList.jsx b/src/components/ProductsList.jsx index d65c7cc..d57b3aa 100644 --- a/src/components/ProductsList.jsx +++ b/src/components/ProductsList.jsx @@ -1,15 +1,20 @@ import React, { useEffect, useState } from 'react'; -import { Table, Form } from 'react-bootstrap'; +import { Table, Form, Button, Modal } from 'react-bootstrap'; import { useSelector, useDispatch } from 'react-redux'; import '../styles/Products.scss'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import Spinning from './Spinning'; +import { Plus } from 'lucide-react'; +import SpinningComponent from './Spinning'; +import { addProductToCampaign } from '../store/slices/productSlice'; -export default function ProductsList({ products, setSelectedProduct, onShowProductDetail }) { - const { selectedBrand } = useSelector((state) => state.brands); +export default function ProductsList({ products, onShowProductDetail, type = 'default' }) { + const { selectedBrand, status } = useSelector((state) => state.brands); const [sortField, setSortField] = useState(null); const [sortDirection, setSortDirection] = useState('asc'); const [selectedProducts, setSelectedProducts] = useState([]); + const [showAddProductToCampaignModal, setShowAddProductToCampaignModal] = useState(false); + const [selectedProduct, setSelectedProduct] = useState(null); const handleSort = (field) => { return; @@ -44,10 +49,9 @@ export default function ProductsList({ products, setSelectedProduct, onShowProdu }; if (status === 'loading') { - return ; + return ; } - return (
@@ -87,6 +91,7 @@ export default function ProductsList({ products, setSelectedProduct, onShowProdu + {type === 'brand' && } @@ -107,18 +112,24 @@ export default function ProductsList({ products, setSelectedProduct, onShowProdu /> - - + - + + {type === 'brand' && ( + + )} )) )}
handleSort('tiktokShop')}> TikTok Shop {renderSortIcon('tiktokShop')} Add To Campaign
-
onShowProductDetail(product)} style={{cursor: 'pointer'}}> +
onShowProductDetail(product)} + style={{ cursor: 'pointer' }} + > {product.name} {/*
{product.name.slice(0, 1)}
*/}
{product.name}
+
{product.commission_rate}
Open collab. {product.open_collab}
{product.available_samples}{product.sales_price_min} - {product.sales_price_max} + {product.sales_price_min} - {product.sales_price_max} + {product.stock} {product.items_sold} @@ -126,12 +137,74 @@ export default function ProductsList({ products, setSelectedProduct, onShowProdu
{product.reviews_count} Reviews
{product.collab_creators}{product.tiktok_shop && } + {product.tiktok_shop && } + + +
+ setShowAddProductToCampaignModal(false)} productId={selectedProduct} />
); } + +function AddProductToCampaignModal({ show, onHide, productId }) { + const [campaignId, setCampaignId] = useState(null); + const { selectedBrand } = useSelector((state) => state.brands); + const dispatch = useDispatch(); + + const handleSubmit = async (e) => { + e.preventDefault(); + console.log(campaignId, productId); + await dispatch(addProductToCampaign({ campaignId, productId })).unwrap(); + handleCancel(); + }; + + const handleCancel = () => { + setCampaignId(null); + onHide(); + }; + + return ( + + + Add Product + +
+ + + Campaign Name + setCampaignId(e.target.value)}> + + {selectedBrand?.campaigns?.map((campaign) => ( + + ))} + + + + + + + +
+
+ ); +} diff --git a/src/pages/BrandsDetail.jsx b/src/pages/BrandsDetail.jsx index 692ff2b..8af5b86 100644 --- a/src/pages/BrandsDetail.jsx +++ b/src/pages/BrandsDetail.jsx @@ -139,6 +139,7 @@ export default function BrandsDetail() { + Add Product diff --git a/src/store/slices/productSlice.js b/src/store/slices/productSlice.js index 0fe4c14..fa4b116 100644 --- a/src/store/slices/productSlice.js +++ b/src/store/slices/productSlice.js @@ -21,8 +21,7 @@ export const addProductToCampaign = createAsyncThunk('products/addProductToCampa if (response.code !== 201 && response.code !== 200) { throw new Error(response.message); } - console.log(response); - + dispatch(setNotificationBarMessage({ message: response.message, type: 'success' })); return response.data; } catch (error) { dispatch(setNotificationBarMessage({ message: error.message, type: 'error' })); diff --git a/src/styles/custom-theme.scss b/src/styles/custom-theme.scss index d8ec45d..301853c 100644 --- a/src/styles/custom-theme.scss +++ b/src/styles/custom-theme.scss @@ -134,8 +134,3 @@ a { box-shadow: 0px 0px 1px #171a1f12, 0px 0px 2px #171a1f1f; /* shadow-xs */ padding: 1rem; } - -.modal-content { - width: max-content; - max-width: 60vw; -} \ No newline at end of file