feat(dashboard): Variant edit form (#6870)
**What** - Adds form to edit variant details. - If stock and inventory modules are installed we omit inputs for stock and inventory as they should be managed in a separate form in that case. (Still a bit unsure about this, but its what we have in the current admin)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import i18next from "i18next"
|
||||
import { z } from "zod"
|
||||
import { castNumber } from "./cast-number"
|
||||
|
||||
/**
|
||||
* Validates that an optional value is an integer.
|
||||
*/
|
||||
export const optionalInt = z
|
||||
.union([z.string(), z.number()])
|
||||
.optional()
|
||||
.refine(
|
||||
(value) => {
|
||||
if (value === "" || value === undefined) {
|
||||
return true
|
||||
}
|
||||
|
||||
return Number.isInteger(castNumber(value))
|
||||
},
|
||||
{
|
||||
message: i18next.t("validation.mustBeInt"),
|
||||
}
|
||||
)
|
||||
.refine(
|
||||
(value) => {
|
||||
if (value === "" || value === undefined) {
|
||||
return true
|
||||
}
|
||||
|
||||
return castNumber(value) >= 0
|
||||
},
|
||||
{
|
||||
message: i18next.t("validation.mustBePositive"),
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user