updating work
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 774 KiB After Width: | Height: | Size: 774 KiB |
|
Before Width: | Height: | Size: 46 KiB After Width: | Height: | Size: 46 KiB |
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 9.4 KiB |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
Before Width: | Height: | Size: 301 KiB After Width: | Height: | Size: 301 KiB |
|
Before Width: | Height: | Size: 421 KiB After Width: | Height: | Size: 421 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 74 KiB After Width: | Height: | Size: 74 KiB |
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 41 KiB |
|
Before Width: | Height: | Size: 236 KiB After Width: | Height: | Size: 236 KiB |
|
Before Width: | Height: | Size: 197 KiB After Width: | Height: | Size: 197 KiB |
|
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 83 KiB |
|
Before Width: | Height: | Size: 128 KiB After Width: | Height: | Size: 128 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 201 KiB After Width: | Height: | Size: 201 KiB |
|
Before Width: | Height: | Size: 577 KiB After Width: | Height: | Size: 577 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 39 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 22 KiB |
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 123 KiB After Width: | Height: | Size: 123 KiB |
|
Before Width: | Height: | Size: 923 KiB |
|
Before Width: | Height: | Size: 413 KiB |
@@ -9,6 +9,7 @@ const Selling = () => {
|
|||||||
const [categories, setCategories] = useState([]);
|
const [categories, setCategories] = useState([]);
|
||||||
const [categoryMapping, setCategoryMapping] = useState({});
|
const [categoryMapping, setCategoryMapping] = useState({});
|
||||||
const [selectedCategory, setSelectedCategory] = useState("");
|
const [selectedCategory, setSelectedCategory] = useState("");
|
||||||
|
const [originalProduct, setOriginalProduct] = useState(null);
|
||||||
|
|
||||||
const [editingProduct, setEditingProduct] = useState({
|
const [editingProduct, setEditingProduct] = useState({
|
||||||
name: "",
|
name: "",
|
||||||
@@ -92,7 +93,6 @@ const Selling = () => {
|
|||||||
fetchProducts();
|
fetchProducts();
|
||||||
}, []); // Add userId to dependency array if it might change
|
}, []); // Add userId to dependency array if it might change
|
||||||
|
|
||||||
// Handle creating or updating a product
|
|
||||||
const handleSaveProduct = async () => {
|
const handleSaveProduct = async () => {
|
||||||
if (!(editingProduct.categories || []).length) {
|
if (!(editingProduct.categories || []).length) {
|
||||||
alert("Please select at least one category");
|
alert("Please select at least one category");
|
||||||
@@ -107,17 +107,24 @@ const Selling = () => {
|
|||||||
const simulatedPath = `/public/uploads/${file.name}`;
|
const simulatedPath = `/public/uploads/${file.name}`;
|
||||||
imagePaths.push(simulatedPath);
|
imagePaths.push(simulatedPath);
|
||||||
});
|
});
|
||||||
|
} else if (originalProduct?.images?.length > 0) {
|
||||||
|
imagePaths.push(...originalProduct.images);
|
||||||
}
|
}
|
||||||
|
|
||||||
const categoryName = (editingProduct.categories || [])[0];
|
const categoryName = (editingProduct.categories || [])[0];
|
||||||
const categoryID = categoryMapping[categoryName] || 1;
|
const categoryID =
|
||||||
|
categoryMapping[categoryName] || originalProduct?.category || 1;
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
name: editingProduct.name || "",
|
name: editingProduct.name || originalProduct?.name || "",
|
||||||
price: parseFloat(editingProduct.price) || 0,
|
price:
|
||||||
|
parseFloat(editingProduct.price) ||
|
||||||
|
parseFloat(originalProduct?.price) ||
|
||||||
|
0,
|
||||||
qty: 1,
|
qty: 1,
|
||||||
userID: storedUser.ID,
|
userID: storedUser.ID,
|
||||||
description: editingProduct.description || "",
|
description:
|
||||||
|
editingProduct.description || originalProduct?.description || "",
|
||||||
category: categoryID,
|
category: categoryID,
|
||||||
images: imagePaths,
|
images: imagePaths,
|
||||||
};
|
};
|
||||||
@@ -160,7 +167,8 @@ const Selling = () => {
|
|||||||
images: [],
|
images: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reload products
|
setOriginalProduct(null); // reset original as well
|
||||||
|
|
||||||
reloadPage();
|
reloadPage();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error saving product:", error);
|
console.error("Error saving product:", error);
|
||||||
|
|||||||