weewoo
This commit is contained in:
@@ -35,8 +35,6 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
categories,
|
||||
editing,
|
||||
handleChange,
|
||||
handleTieredPricingChange,
|
||||
handleAddTier,
|
||||
handleRemoveTier,
|
||||
setProductData,
|
||||
}) => {
|
||||
@@ -59,9 +57,7 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
setLocalCategories(categories);
|
||||
}, [categories]);
|
||||
|
||||
/**
|
||||
* 2) When user selects a file, store it and create an objectURL for preview
|
||||
*/
|
||||
|
||||
const handleImageChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (!file) {
|
||||
@@ -72,12 +68,10 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
}
|
||||
|
||||
// For preview
|
||||
console.log(file)
|
||||
const objectUrl = URL.createObjectURL(file);
|
||||
setSelectedFile(file);
|
||||
setImagePreview(objectUrl);
|
||||
|
||||
// Optionally, load the image to calculate dimensions
|
||||
const image = new Image();
|
||||
image.onload = () => {
|
||||
const aspectRatio = image.naturalWidth / image.naturalHeight;
|
||||
@@ -88,9 +82,13 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
image.src = objectUrl;
|
||||
};
|
||||
|
||||
/**
|
||||
* 3) On 'Save', call the parent onSave(productData, selectedFile)
|
||||
*/
|
||||
const handleAddTier = () => {
|
||||
setProductData((prev) => ({
|
||||
...prev,
|
||||
pricing: [...prev.pricing, { minQuantity: 0, pricePerUnit: 0 }],
|
||||
}));
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!productData.category) {
|
||||
toast.error("Please select or add a category");
|
||||
@@ -107,6 +105,19 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
setLocalCategories((prev) => [...prev, newCategory]);
|
||||
};
|
||||
|
||||
const handleTierChange = (e: React.ChangeEvent<HTMLInputElement>, index: number) => {
|
||||
const { name, value } = e.target;
|
||||
|
||||
setProductData((prev) => ({
|
||||
...prev,
|
||||
pricing: prev.pricing.map((tier, i) =>
|
||||
i === index
|
||||
? { ...tier, [name]: value === "" ? 0 : Number(value) }
|
||||
: tier
|
||||
),
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onClose}>
|
||||
<DialogContent className="max-w-6xl">
|
||||
@@ -133,7 +144,7 @@ export const ProductModal: React.FC<ProductModalProps> = ({
|
||||
/>
|
||||
<PricingTiers
|
||||
pricing={productData.pricing}
|
||||
handleTierChange={handleTieredPricingChange}
|
||||
handleTierChange={handleTierChange}
|
||||
handleRemoveTier={handleRemoveTier}
|
||||
handleAddTier={handleAddTier}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user