This commit is contained in:
shafi54 2026-09-06 19:27:52 +05:30
parent 7537780caa
commit 5d7648c6b0

View file

@ -212,15 +212,20 @@ const ProductForm = forwardRef<ProductFormRef, ProductFormProps>(({
// 'quantity' feature must always go out lowercase (case-insensitive // 'quantity' feature must always go out lowercase (case-insensitive
// matching means 'Quantity'/'QUANTITY' are treated the same), and // matching means 'Quantity'/'QUANTITY' are treated the same), and
// names are trimmed like the backend does. // names are trimmed like the backend does.
// TextInputs emit strings — coerce price fields to the numeric types
// the backend zod schema requires (price required; market/flash nullable).
const toNumber = (value: unknown): number | null => {
if (value == null || value === '') return null
const n = Number(value)
return Number.isFinite(n) ? n : null
}
const normalizedValues: ProductFormData = { const normalizedValues: ProductFormData = {
...values, ...values,
variants: values.variants.map((v) => ({ variants: values.variants.map((v) => ({
...v, ...v,
// TextInputs emit strings — coerce to the numeric types the price: toNumber(v.price) ?? undefined,
// backend zod schema requires (price required; market/flash nullable). marketPrice: toNumber(v.marketPrice),
price: v.price == null || v.price === '' ? undefined : Number(v.price), flashPrice: toNumber(v.flashPrice),
marketPrice: v.marketPrice == null || v.marketPrice === '' ? null : Number(v.marketPrice),
flashPrice: v.flashPrice == null || v.flashPrice === '' ? null : Number(v.flashPrice),
features: v.features.map((a) => ({ features: v.features.map((a) => ({
...a, ...a,
featureName: isQuantityFeature(a) ? 'quantity' : (a.featureName ?? '').trim() || null, featureName: isQuantityFeature(a) ? 'quantity' : (a.featureName ?? '').trim() || null,