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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user