Fix
This commit is contained in:
@@ -18,9 +18,9 @@ import {
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import { Product } from "@/models/products";
|
||||
import { Trash, PlusCircle } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { Product } from "@/models/products";
|
||||
|
||||
interface Category {
|
||||
_id: string;
|
||||
@@ -39,7 +39,7 @@ interface ProductData {
|
||||
unitType: string;
|
||||
category: string;
|
||||
pricing: PricingTier[];
|
||||
image: string | File | null;
|
||||
image?: string | File | null | undefined;
|
||||
}
|
||||
|
||||
interface ProductModalProps {
|
||||
@@ -47,11 +47,10 @@ interface ProductModalProps {
|
||||
onClose: () => void;
|
||||
onSave: (productData: ProductData) => void;
|
||||
productData: ProductData;
|
||||
categories: Category[];
|
||||
categories: any[];
|
||||
editing: boolean;
|
||||
handleChange: (
|
||||
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
|
||||
) => void;
|
||||
handleChange: (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
||||
handleTieredPricingChange: (e: ChangeEvent<HTMLInputElement>, index: number) => void; // ✅ Added this
|
||||
setProductData: React.Dispatch<React.SetStateAction<ProductData>>;
|
||||
}
|
||||
|
||||
@@ -72,15 +71,6 @@ export const ProductModal = ({
|
||||
height: 200,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (productData?.pricing) {
|
||||
setProductData((prev) => ({
|
||||
...prev,
|
||||
tieredPricing: productData.pricing,
|
||||
}));
|
||||
}
|
||||
}, [productData.pricing]);
|
||||
|
||||
useEffect(() => {
|
||||
if (productData.image && typeof productData.image === "string") {
|
||||
setImagePreview(productData.image);
|
||||
@@ -137,13 +127,19 @@ export const ProductModal = ({
|
||||
|
||||
updatedPricing[index] = {
|
||||
...updatedPricing[index],
|
||||
[name]: isNaN(valueAsNumber) ? 0 : valueAsNumber, // Ensure valid numbers
|
||||
[name]: isNaN(valueAsNumber) ? 0 : valueAsNumber,
|
||||
};
|
||||
|
||||
setProductData((prev) => ({
|
||||
...prev,
|
||||
tieredPricing: updatedPricing,
|
||||
image: prev.image ?? null,
|
||||
}));
|
||||
|
||||
const convertToProductData = (product: Product): ProductData => ({
|
||||
...product,
|
||||
image: product.image ?? null, // ✅ Ensures the type is correct
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user