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:
Kasper Fabricius Kristensen
2024-04-01 16:38:49 +00:00
committed by GitHub
parent 8363dbec4f
commit b2763647f7
10 changed files with 632 additions and 8 deletions
@@ -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"),
}
)