DEAD_CODE_CLEAN #7
1 changed files with 10 additions and 5 deletions
|
|
@ -212,15 +212,20 @@ const ProductForm = forwardRef<ProductFormRef, ProductFormProps>(({
|
|||
// 'quantity' feature must always go out lowercase (case-insensitive
|
||||
// matching means 'Quantity'/'QUANTITY' are treated the same), and
|
||||
// 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 = {
|
||||
...values,
|
||||
variants: values.variants.map((v) => ({
|
||||
...v,
|
||||
// TextInputs emit strings — coerce to the numeric types the
|
||||
// backend zod schema requires (price required; market/flash nullable).
|
||||
price: v.price == null || v.price === '' ? undefined : Number(v.price),
|
||||
marketPrice: v.marketPrice == null || v.marketPrice === '' ? null : Number(v.marketPrice),
|
||||
flashPrice: v.flashPrice == null || v.flashPrice === '' ? null : Number(v.flashPrice),
|
||||
price: toNumber(v.price) ?? undefined,
|
||||
marketPrice: toNumber(v.marketPrice),
|
||||
flashPrice: toNumber(v.flashPrice),
|
||||
features: v.features.map((a) => ({
|
||||
...a,
|
||||
featureName: isQuantityFeature(a) ? 'quantity' : (a.featureName ?? '').trim() || null,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue