fix(dashboard): Allow float values for product prices (#9859)
This commit is contained in:
1 parent
7b51204ef3
commit
a0034a0fef
3 files changed
+27
-5
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
import i18next from "i18next"
|
import i18next from "i18next"
|
||||||
|
import { FieldPath, FieldValues, UseFormReturn } from "react-hook-form"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { castNumber } from "./cast-number"
|
import { castNumber } from "./cast-number"
|
||||||
import { FieldPath, FieldValues, UseFormReturn } from "react-hook-form"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates that an optional value is an integer.
|
* 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.
|
* Schema for metadata form.
|
||||||
*/
|
*/
|
||||||
|
|||||||
+5
-2
@@ -80,10 +80,13 @@ export const ProductCreateForm = ({
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return regions.reduce((acc, reg) => {
|
return regions.reduce(
|
||||||
|
(acc, reg) => {
|
||||||
acc[reg.id] = reg.currency_code
|
acc[reg.id] = reg.currency_code
|
||||||
return acc
|
return acc
|
||||||
}, {} as Record<string, string>)
|
},
|
||||||
|
{} as Record<string, string>
|
||||||
|
)
|
||||||
}, [regions])
|
}, [regions])
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
import { i18n } from "../../../components/utilities/i18n/i18n.tsx"
|
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"
|
import { decorateVariantsWithDefaultValues } from "./utils.ts"
|
||||||
|
|
||||||
export const MediaSchema = z.object({
|
export const MediaSchema = z.object({
|
||||||
@@ -32,7 +32,7 @@ const ProductCreateVariantSchema = z.object({
|
|||||||
inventory_kit: z.boolean().optional(),
|
inventory_kit: z.boolean().optional(),
|
||||||
options: z.record(z.string(), z.string()),
|
options: z.record(z.string(), z.string()),
|
||||||
variant_rank: z.number(),
|
variant_rank: z.number(),
|
||||||
prices: z.record(z.string(), optionalInt).optional(),
|
prices: z.record(z.string(), optionalFloat).optional(),
|
||||||
inventory: z
|
inventory: z
|
||||||
.array(
|
.array(
|
||||||
z.object({
|
z.object({
|
||||||
|
|||||||
Reference in new issue
Block a user