fix(dashboard): Allow float values for product prices (#9859)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import i18next from "i18next"
|
||||
import { FieldPath, FieldValues, UseFormReturn } from "react-hook-form"
|
||||
import { z } from "zod"
|
||||
import { castNumber } from "./cast-number"
|
||||
import { FieldPath, FieldValues, UseFormReturn } from "react-hook-form"
|
||||
|
||||
/**
|
||||
* Validates that an optional value is an integer.
|
||||
@@ -34,6 +34,25 @@ export const optionalInt = z
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Validates that an optional value is an number.
|
||||
*/
|
||||
export const optionalFloat = z
|
||||
.union([z.string(), z.number()])
|
||||
.optional()
|
||||
.refine(
|
||||
(value) => {
|
||||
if (value === "" || value === undefined) {
|
||||
return true
|
||||
}
|
||||
|
||||
return castNumber(value) >= 0
|
||||
},
|
||||
{
|
||||
message: i18next.t("validation.mustBePositive"),
|
||||
}
|
||||
)
|
||||
|
||||
/**
|
||||
* Schema for metadata form.
|
||||
*/
|
||||
|
||||
+7
-4
@@ -80,10 +80,13 @@ export const ProductCreateForm = ({
|
||||
return {}
|
||||
}
|
||||
|
||||
return regions.reduce((acc, reg) => {
|
||||
acc[reg.id] = reg.currency_code
|
||||
return acc
|
||||
}, {} as Record<string, string>)
|
||||
return regions.reduce(
|
||||
(acc, reg) => {
|
||||
acc[reg.id] = reg.currency_code
|
||||
return acc
|
||||
},
|
||||
{} as Record<string, string>
|
||||
)
|
||||
}, [regions])
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod"
|
||||
import { i18n } from "../../../components/utilities/i18n/i18n.tsx"
|
||||
import { optionalInt } from "../../../lib/validation.ts"
|
||||
import { optionalFloat, optionalInt } from "../../../lib/validation.ts"
|
||||
import { decorateVariantsWithDefaultValues } from "./utils.ts"
|
||||
|
||||
export const MediaSchema = z.object({
|
||||
@@ -32,7 +32,7 @@ const ProductCreateVariantSchema = z.object({
|
||||
inventory_kit: z.boolean().optional(),
|
||||
options: z.record(z.string(), z.string()),
|
||||
variant_rank: z.number(),
|
||||
prices: z.record(z.string(), optionalInt).optional(),
|
||||
prices: z.record(z.string(), optionalFloat).optional(),
|
||||
inventory: z
|
||||
.array(
|
||||
z.object({
|
||||
|
||||
Reference in New Issue
Block a user