Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

fix(dashboard): unwrap zod wrappers when picking custom-field input control (#1188)

Viktor Holik882bca6eb8c4
diff --git a/packages/dashboard-shared/src/extensions/form-extension-zone.tsx b/packages/dashboard-shared/src/extensions/form-extension-zone.tsx
index bf82d1c36..89fbec0d3 100644
--- a/packages/dashboard-shared/src/extensions/form-extension-zone.tsx
+++ b/packages/dashboard-shared/src/extensions/form-extension-zone.tsx
@@ -4,9 +4,37 @@ import type { CustomFormField } from "@mercurjs/dashboard-sdk"
import { Form } from "../components/common/form"
import { useExtension } from "./context"
-function zodType(field: CustomFormField): string {
- const def = (field.validation as unknown as { def?: { type?: string } })?.def
- return def?.type ?? "string"
+type FieldControlType = "boolean" | "number" | "string" | "textarea"
+
+// Zod wrappers that carry the base schema on `def.innerType` — unwrap them so an
+// `optional()`/`nullable()`/`default()` field maps to its underlying control.
+const ZOD_WRAPPER_TYPES = new Set([
+ "optional",
+ "nullable",
+ "default",
+ "prefault",
+ "nonoptional",
+ "readonly",
+ "catch",
+])
+
+type ZodDef = { type?: string; innerType?: { def?: ZodDef } }
+
+function zodType(field: CustomFormField): FieldControlType {
+ let def = (field.validation as unknown as { def?: ZodDef })?.def
+
+ while (def && ZOD_WRAPPER_TYPES.has(def.type ?? "")) {
+ def = def.innerType?.def
+ }
+
+ switch (def?.type) {
+ case "boolean":
+ case "number":
+ case "string":
+ return def.type
+ default:
+ return "textarea"
+ }
}
type FieldProps = {