mirror of
https://github.com/Funkoala14/CreatorCenter_OOIN.git
synced 2025-06-08 05:28:14 +08:00
[dev]add product
This commit is contained in:
parent
ce1b944103
commit
10f3420890
@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import SearchBar from '../components/SearchBar';
|
import SearchBar from '../components/SearchBar';
|
||||||
import { Alert, Button, Form, Modal } from 'react-bootstrap';
|
import { Alert, Button, Form, Modal } from 'react-bootstrap';
|
||||||
import { Folders, Hash, LinkIcon, Plus, Users } from 'lucide-react';
|
import { Folders, Hash, LinkIcon, Plus, Users, X } from 'lucide-react';
|
||||||
import { useDispatch, useSelector } from 'react-redux';
|
import { useDispatch, useSelector } from 'react-redux';
|
||||||
import { Link, useParams } from 'react-router-dom';
|
import { Link, useParams } from 'react-router-dom';
|
||||||
import CampaignList from '../components/CampaignList';
|
import CampaignList from '../components/CampaignList';
|
||||||
@ -18,6 +18,7 @@ import ProductDetail from '../components/ProductDetail';
|
|||||||
import { CAMPAIGN_SERVICES, CREATOR_CATEGORIES, CREATOR_LEVELS, CREATOR_TYPES, GMV_RANGES } from '../lib/constant';
|
import { CAMPAIGN_SERVICES, CREATOR_CATEGORIES, CREATOR_LEVELS, CREATOR_TYPES, GMV_RANGES } from '../lib/constant';
|
||||||
import RangeSlider from '../components/RangeSlider';
|
import RangeSlider from '../components/RangeSlider';
|
||||||
import SpinningComponent from '../components/Spinning';
|
import SpinningComponent from '../components/Spinning';
|
||||||
|
import { setNotificationBarMessage } from '../store/slices/notificationBarSlice';
|
||||||
|
|
||||||
export default function BrandsDetail() {
|
export default function BrandsDetail() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
@ -26,6 +27,7 @@ export default function BrandsDetail() {
|
|||||||
const { selectedBrand } = useSelector((state) => state.brands);
|
const { selectedBrand } = useSelector((state) => state.brands);
|
||||||
const [showProductDetail, setShowProductDetail] = useState(false);
|
const [showProductDetail, setShowProductDetail] = useState(false);
|
||||||
const [showAddCampaignModal, setShowAddCampaignModal] = useState(false);
|
const [showAddCampaignModal, setShowAddCampaignModal] = useState(false);
|
||||||
|
const [showAddProductModal, setShowAddProductModal] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -52,7 +54,7 @@ export default function BrandsDetail() {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{activeTab === 'products' && (
|
{activeTab === 'products' && (
|
||||||
<Button>
|
<Button onClick={() => setShowAddProductModal(true)}>
|
||||||
<Plus />
|
<Plus />
|
||||||
Add Product
|
Add Product
|
||||||
</Button>
|
</Button>
|
||||||
@ -149,6 +151,7 @@ export default function BrandsDetail() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<AddCampaignModal show={showAddCampaignModal} onHide={() => setShowAddCampaignModal(false)} />
|
<AddCampaignModal show={showAddCampaignModal} onHide={() => setShowAddCampaignModal(false)} />
|
||||||
|
<AddProductModal show={showAddProductModal} onHide={() => setShowAddProductModal(false)} />
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
@ -368,3 +371,111 @@ export function AddCampaignModal({ show, onHide }) {
|
|||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function AddProductModal({ show, onHide }) {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const [productIds, setProductIds] = useState({
|
||||||
|
0: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
const addProduct = () => {
|
||||||
|
const newIndex = Object.keys(productIds).length;
|
||||||
|
console.log(newIndex);
|
||||||
|
|
||||||
|
setProductIds((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[newIndex]: '',
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (e) => {
|
||||||
|
const { name, value } = e.target;
|
||||||
|
setProductIds((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[name]: value,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleClose = () => {
|
||||||
|
setProductIds([]);
|
||||||
|
onHide();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
dispatch(
|
||||||
|
setNotificationBarMessage({
|
||||||
|
message: '这个接口是哪一个?',
|
||||||
|
variant: 'info',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
const form = document.getElementById('addProductForm');
|
||||||
|
if (form.checkValidity() === false) {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
setValidated(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.log(productIds);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeProduct = (index) => {
|
||||||
|
if (Object.keys(productIds).length === 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setProductIds((prev) => {
|
||||||
|
const updated = { ...prev };
|
||||||
|
delete updated[index];
|
||||||
|
return updated;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (show) {
|
||||||
|
setProductIds({
|
||||||
|
0: '',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [show]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal show={show} onHide={handleClose}>
|
||||||
|
<Modal.Header>
|
||||||
|
<Modal.Title>Add Product</Modal.Title>
|
||||||
|
</Modal.Header>
|
||||||
|
<Form id='addProductForm' onSubmit={handleSubmit}>
|
||||||
|
<Modal.Body>
|
||||||
|
{Object.entries(productIds).map(([index, productId]) => (
|
||||||
|
<Form.Group key={Number(index)}>
|
||||||
|
<Form.Label>Product {Number(index) + 1} PID</Form.Label>
|
||||||
|
<div className='d-flex flex-row align-items-center justify-content-between'>
|
||||||
|
<Form.Control
|
||||||
|
type='text'
|
||||||
|
name={index}
|
||||||
|
value={productId}
|
||||||
|
onChange={handleChange}
|
||||||
|
placeholder='Enter Product ID'
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<Button variant='link' className='border-0' onClick={() => removeProduct(index)}>
|
||||||
|
<X />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</Form.Group>
|
||||||
|
))}
|
||||||
|
<Button variant='outline-primary' className='mt-3' onClick={addProduct}>
|
||||||
|
Add Product
|
||||||
|
</Button>
|
||||||
|
</Modal.Body>
|
||||||
|
<Modal.Footer>
|
||||||
|
<Button variant='outline-primary' className='border-0' onClick={onHide}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button variant='primary' type='submit'>
|
||||||
|
Submit
|
||||||
|
</Button>
|
||||||
|
</Modal.Footer>
|
||||||
|
</Form>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -411,3 +411,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#addProductForm {
|
||||||
|
.modal-body {
|
||||||
|
width: 400px;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: column nowrap;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user