@open-mercato/core 0.4.9-develop-b2b88cde69 → 0.4.9-develop-d1d38e26fb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/modules/catalog/backend/catalog/products/[id]/page.js +72 -2
- package/dist/modules/catalog/backend/catalog/products/[id]/page.js.map +2 -2
- package/dist/modules/catalog/backend/catalog/products/create/page.js +82 -3
- package/dist/modules/catalog/backend/catalog/products/create/page.js.map +2 -2
- package/dist/modules/catalog/components/products/productForm.js +12 -0
- package/dist/modules/catalog/components/products/productForm.js.map +2 -2
- package/dist/modules/catalog/data/validators.js +1 -1
- package/dist/modules/catalog/data/validators.js.map +2 -2
- package/dist/modules/currencies/lib/exchangeRateFormConfig.js +0 -1
- package/dist/modules/currencies/lib/exchangeRateFormConfig.js.map +2 -2
- package/package.json +3 -3
- package/src/modules/catalog/backend/catalog/products/[id]/page.tsx +91 -2
- package/src/modules/catalog/backend/catalog/products/create/page.tsx +99 -4
- package/src/modules/catalog/components/products/productForm.ts +22 -1
- package/src/modules/catalog/data/validators.ts +1 -1
- package/src/modules/catalog/i18n/de.json +3 -0
- package/src/modules/catalog/i18n/en.json +3 -0
- package/src/modules/catalog/i18n/es.json +3 -0
- package/src/modules/catalog/i18n/pl.json +3 -0
- package/src/modules/currencies/lib/exchangeRateFormConfig.ts +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/modules/catalog/components/products/productForm.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from \"zod\";\nimport { slugify } from \"@open-mercato/shared/lib/slugify\";\nimport { parseObjectLike } from \"@open-mercato/shared/lib/json/parseObjectLike\";\nimport type { ReferenceUnitCode } from \"@open-mercato/shared/lib/units/unitCodes\";\nimport type { CatalogProductOptionSchema } from \"../../data/types\";\nimport type { ProductMediaItem } from \"./ProductMediaManager\";\n\nexport { slugify };\n\nexport type PriceKindSummary = {\n id: string;\n code: string;\n title: string;\n currencyCode: string | null;\n displayMode: \"including-tax\" | \"excluding-tax\";\n};\n\nexport type PriceKindApiPayload = {\n id?: string | number;\n code?: string;\n title?: string;\n currencyCode?: string | null;\n currency_code?: string | null;\n displayMode?: string | null;\n display_mode?: string | null;\n};\n\nexport type TaxRateSummary = {\n id: string;\n name: string;\n code: string | null;\n rate: number | null;\n isDefault: boolean;\n};\n\nexport type ProductOptionInput = {\n id: string;\n title: string;\n values: Array<{ id: string; label: string }>;\n};\n\nexport type ProductDimensions = {\n width?: number;\n height?: number;\n depth?: number;\n unit?: string | null;\n} | null;\n\nexport type ProductWeight = {\n value?: number;\n unit?: string | null;\n} | null;\n\nexport type VariantPriceValue = {\n amount: string;\n};\n\nexport type ProductUnitRoundingMode = \"half_up\" | \"down\" | \"up\";\nexport type ProductUnitPriceReferenceUnit = ReferenceUnitCode;\n\nexport type ProductUnitConversionDraft = {\n id: string | null;\n unitCode: string;\n toBaseFactor: string;\n sortOrder: string;\n isActive: boolean;\n};\n\nexport type VariantDraft = {\n id: string;\n title: string;\n sku: string;\n isDefault: boolean;\n taxRateId: string | null;\n manageInventory: boolean;\n allowBackorder: boolean;\n hasInventoryKit: boolean;\n optionValues: Record<string, string>;\n prices: Record<string, VariantPriceValue>;\n};\n\nexport type ProductFormValues = {\n title: string;\n subtitle: string;\n handle: string;\n description: string;\n useMarkdown: boolean;\n taxRateId: string | null;\n mediaDraftId: string;\n mediaItems: ProductMediaItem[];\n defaultMediaId: string | null;\n defaultMediaUrl: string;\n hasVariants: boolean;\n options: ProductOptionInput[];\n variants: VariantDraft[];\n metadata?: Record<string, unknown> | null;\n dimensions?: ProductDimensions;\n weight?: ProductWeight;\n defaultUnit: string | null;\n defaultSalesUnit: string | null;\n defaultSalesUnitQuantity: string;\n uomRoundingScale: string;\n uomRoundingMode: ProductUnitRoundingMode;\n unitPriceEnabled: boolean;\n unitPriceReferenceUnit: string | null;\n unitPriceBaseQuantity: string;\n unitConversions: ProductUnitConversionDraft[];\n customFieldsetCode?: string | null;\n categoryIds: string[];\n channelIds: string[];\n tags: string[];\n optionSchemaId?: string | null;\n};\n\nconst optionalPositiveNumberInput = z.preprocess((value) => {\n if (value === null || value === undefined) return undefined;\n if (typeof value === \"string\" && value.trim().length === 0) return undefined;\n return value;\n}, z.coerce.number().positive().optional());\n\nconst optionalBoundedIntegerInput = (min: number, max: number) =>\n z.preprocess((value) => {\n if (value === null || value === undefined) return undefined;\n if (typeof value === \"string\" && value.trim().length === 0)\n return undefined;\n return value;\n }, z.coerce.number().int().min(min).max(max).optional());\n\nexport const productFormSchema = z\n .object({\n title: z.string().trim().min(1, \"catalog.products.validation.titleRequired\"),\n subtitle: z.string().optional(),\n handle: z\n .string()\n .trim()\n .regex(\n /^[a-z0-9\\-_]*$/,\n \"catalog.products.validation.handleFormat\",\n )\n .max(150)\n .optional(),\n description: z.string().optional(),\n useMarkdown: z.boolean().optional(),\n taxRateId: z.string().uuid().nullable().optional(),\n hasVariants: z.boolean().optional(),\n mediaDraftId: z.string().optional(),\n mediaItems: z.any().optional(),\n defaultMediaId: z.string().uuid().nullable().optional(),\n defaultMediaUrl: z.string().trim().max(500).nullable().optional(),\n options: z.any().optional(),\n variants: z.any().optional(),\n // Use a permissive schema to avoid zod classic `_zod` runtime crashes on records in edge builds.\n metadata: z\n .custom<Record<string, unknown>>(() => true)\n .nullable()\n .optional(),\n dimensions: z\n .object({\n width: z.coerce.number().min(0).optional(),\n height: z.coerce.number().min(0).optional(),\n depth: z.coerce.number().min(0).optional(),\n unit: z.string().trim().max(25).optional(),\n })\n .nullable()\n .optional(),\n weight: z\n .object({\n value: z.coerce.number().min(0).optional(),\n unit: z.string().trim().max(25).optional(),\n })\n .nullable()\n .optional(),\n defaultUnit: z.string().trim().max(50).nullable().optional(),\n defaultSalesUnit: z.string().trim().max(50).nullable().optional(),\n defaultSalesUnitQuantity: optionalPositiveNumberInput,\n uomRoundingScale: optionalBoundedIntegerInput(0, 6),\n uomRoundingMode: z.enum([\"half_up\", \"down\", \"up\"]).optional(),\n unitPriceEnabled: z.boolean().optional(),\n unitPriceReferenceUnit: z.string().trim().max(50).nullable().optional(),\n unitPriceBaseQuantity: optionalPositiveNumberInput,\n unitConversions: z\n .array(\n z.object({\n id: z.string().nullable().optional(),\n unitCode: z.string().trim().max(50),\n toBaseFactor: z.coerce.number().positive(),\n sortOrder: z.coerce.number().int().min(0).max(100000).optional(),\n isActive: z.boolean().optional(),\n }),\n )\n .optional(),\n customFieldsetCode: z.string().optional().nullable(),\n categoryIds: z.array(z.string().uuid()).optional(),\n channelIds: z.array(z.string().uuid()).optional(),\n tags: z.array(z.string().trim().min(1).max(100)).optional(),\n optionSchemaId: z.string().uuid().nullable().optional(),\n })\n .passthrough()\n .refine(\n (data) => !data.unitPriceEnabled || (data.unitPriceReferenceUnit != null && data.unitPriceReferenceUnit.length > 0),\n { message: 'catalog.products.validation.referenceUnitRequired', path: ['unitPriceReferenceUnit'] }\n )\n .refine(\n (data) => !data.defaultSalesUnit || (data.defaultUnit != null && data.defaultUnit.length > 0),\n { message: 'catalog.products.validation.baseUnitRequired', path: ['defaultUnit'] }\n );\n\nexport const PRODUCT_FORM_STEPS = [\n \"general\",\n \"organize\",\n \"uom\",\n \"variants\",\n] as const;\n\nexport const BASE_INITIAL_VALUES: ProductFormValues = {\n title: \"\",\n subtitle: \"\",\n handle: \"\",\n description: \"\",\n useMarkdown: false,\n mediaDraftId: \"\",\n mediaItems: [],\n defaultMediaId: null,\n defaultMediaUrl: \"\",\n taxRateId: null,\n hasVariants: false,\n options: [],\n variants: [],\n metadata: {},\n dimensions: null,\n weight: null,\n defaultUnit: null,\n defaultSalesUnit: null,\n defaultSalesUnitQuantity: \"1\",\n uomRoundingScale: \"4\",\n uomRoundingMode: \"half_up\",\n unitPriceEnabled: false,\n unitPriceReferenceUnit: null,\n unitPriceBaseQuantity: \"\",\n unitConversions: [],\n customFieldsetCode: null,\n categoryIds: [],\n channelIds: [],\n tags: [],\n optionSchemaId: null,\n};\n\nexport const createInitialProductFormValues = (): ProductFormValues => ({\n ...BASE_INITIAL_VALUES,\n mediaDraftId: createLocalId(),\n variants: [createVariantDraft(null, { isDefault: true })],\n});\n\nexport const createVariantDraft = (\n productTaxRateId: string | null,\n overrides: Partial<VariantDraft> = {},\n): VariantDraft => ({\n id: createLocalId(),\n title: \"Default variant\",\n sku: \"\",\n isDefault: false,\n taxRateId: productTaxRateId ?? null,\n manageInventory: false,\n allowBackorder: false,\n hasInventoryKit: false,\n optionValues: {},\n prices: {},\n ...overrides,\n});\n\nexport const createProductUnitConversionDraft = (\n overrides: Partial<ProductUnitConversionDraft> = {},\n): ProductUnitConversionDraft => ({\n id: null,\n unitCode: \"\",\n toBaseFactor: \"\",\n sortOrder: \"\",\n isActive: true,\n ...overrides,\n});\n\nexport const buildOptionValuesKey = (\n optionValues?: Record<string, string>,\n): string => {\n if (!optionValues) return \"\";\n return Object.keys(optionValues)\n .sort((a, b) => a.localeCompare(b))\n .map((key) => `${key}:${optionValues[key] ?? \"\"}`)\n .join(\"|\");\n};\n\nexport const haveSameOptionValues = (\n current: Record<string, string> | undefined,\n next: Record<string, string>,\n): boolean => {\n const a = current ?? {};\n const keys = new Set([...Object.keys(a), ...Object.keys(next)]);\n for (const key of keys) {\n if ((a[key] ?? \"\") !== (next[key] ?? \"\")) return false;\n }\n return true;\n};\n\nconst parseNumeric = (input: unknown): number | null => {\n const numeric = typeof input === \"number\" ? input : Number(input);\n if (!Number.isFinite(numeric) || numeric < 0) return null;\n return numeric;\n};\n\nexport const normalizeProductDimensions = (raw: unknown): ProductDimensions => {\n const source = parseObjectLike(raw);\n if (!source) return null;\n const width = parseNumeric(source.width);\n const height = parseNumeric(source.height);\n const depth = parseNumeric(source.depth);\n const unit =\n typeof source.unit === \"string\" && source.unit.trim().length\n ? source.unit.trim()\n : null;\n const clean: Record<string, unknown> = {};\n if (width !== null) clean.width = width;\n if (height !== null) clean.height = height;\n if (depth !== null) clean.depth = depth;\n if (unit) clean.unit = unit;\n return Object.keys(clean).length ? (clean as ProductDimensions) : null;\n};\n\nexport const normalizeProductWeight = (raw: unknown): ProductWeight => {\n const source = parseObjectLike(raw);\n if (!source) return null;\n const value = parseNumeric(source.value);\n const unit =\n typeof source.unit === \"string\" && source.unit.trim().length\n ? source.unit.trim()\n : null;\n if (value === null && !unit) return null;\n const clean: Record<string, unknown> = {};\n if (value !== null) clean.value = value;\n if (unit) clean.unit = unit;\n return clean as ProductWeight;\n};\n\nexport const sanitizeProductDimensions = (\n raw: ProductDimensions,\n): ProductDimensions => {\n return normalizeProductDimensions(raw ?? null);\n};\n\nexport const sanitizeProductWeight = (raw: ProductWeight): ProductWeight => {\n return normalizeProductWeight(raw ?? null);\n};\n\nexport const updateDimensionValue = (\n current: ProductDimensions,\n field: \"width\" | \"height\" | \"depth\" | \"unit\",\n raw: string,\n): ProductDimensions => {\n const base = normalizeProductDimensions(current) ?? {};\n if (field === \"unit\") {\n base.unit = raw;\n } else {\n const numeric = parseNumeric(raw);\n if (numeric === null) {\n delete base[field];\n } else {\n base[field] = numeric;\n }\n }\n return sanitizeProductDimensions(base);\n};\n\nexport const updateWeightValue = (\n current: ProductWeight,\n field: \"value\" | \"unit\",\n raw: string,\n): ProductWeight => {\n const base = normalizeProductWeight(current) ?? {};\n if (field === \"unit\") {\n base.unit = raw;\n } else {\n const numeric = parseNumeric(raw);\n if (numeric === null) {\n delete (base as Record<string, unknown>).value;\n } else {\n base.value = numeric;\n }\n }\n return sanitizeProductWeight(base);\n};\n\nexport const normalizePriceKindSummary = (\n input: PriceKindApiPayload | undefined | null,\n): PriceKindSummary | null => {\n if (!input) return null;\n const getString = (value: unknown): string | null => {\n if (typeof value === \"string\" && value.trim().length) return value.trim();\n if (typeof value === \"number\" || typeof value === \"bigint\")\n return String(value);\n return null;\n };\n const id = getString(input.id);\n const code = getString(input.code);\n const title = getString(input.title);\n if (!id || !code || !title) return null;\n const currency =\n getString(input.currencyCode) ?? getString(input.currency_code);\n const displayRaw =\n getString(input.displayMode) ?? getString(input.display_mode);\n const displayMode: PriceKindSummary[\"displayMode\"] =\n displayRaw === \"including-tax\" ? \"including-tax\" : \"excluding-tax\";\n return {\n id,\n code,\n title,\n currencyCode: currency,\n displayMode,\n };\n};\n\nexport const formatTaxRateLabel = (rate: TaxRateSummary): string => {\n const extras: string[] = [];\n if (typeof rate.rate === \"number\" && Number.isFinite(rate.rate)) {\n extras.push(`${rate.rate}%`);\n }\n if (rate.code) {\n extras.push(rate.code.toUpperCase());\n }\n if (!extras.length) return rate.name;\n return `${rate.name} \u2022 ${extras.join(\" \u00B7 \")}`;\n};\n\nexport function createLocalId(): string {\n return Math.random().toString(36).slice(2, 10);\n}\n\nexport function buildOptionSchemaDefinition(\n options: ProductOptionInput[] | undefined,\n name: string,\n): CatalogProductOptionSchema | null {\n const list = Array.isArray(options) ? options : [];\n if (!list.length) return null;\n const normalizedName =\n name && name.trim().length ? name.trim() : \"Product options\";\n const schemaOptions = list\n .map((option) => {\n const title = option.title?.trim() || \"\";\n const code = resolveOptionCode(option);\n const values = Array.isArray(option.values) ? option.values : [];\n return {\n code: code || slugify(createLocalId()),\n label: title || code || \"Option\",\n inputType: \"select\" as const,\n choices: values\n .map((value) => {\n const label = value.label?.trim() || \"\";\n const valueCode = slugify(label || value.id || createLocalId());\n if (!label && !valueCode) return null;\n return {\n code: valueCode || slugify(createLocalId()),\n label: label || valueCode || \"Choice\",\n };\n })\n .filter((entry): entry is { code: string; label: string } => !!entry),\n };\n })\n .filter((entry) => entry.label.trim().length);\n if (!schemaOptions.length) return null;\n return {\n version: 1,\n name: normalizedName,\n options: schemaOptions,\n };\n}\n\nexport function convertSchemaToProductOptions(\n schema: CatalogProductOptionSchema | null | undefined,\n): ProductOptionInput[] {\n if (!schema || !Array.isArray(schema.options)) return [];\n return schema.options.map((option) => ({\n id: createLocalId(),\n title: option.label ?? option.code ?? \"Option\",\n values: Array.isArray(option.choices)\n ? option.choices.map((choice) => ({\n id: createLocalId(),\n label: choice.label ?? choice.code ?? \"\",\n }))\n : [],\n }));\n}\n\nfunction resolveOptionCode(option: ProductOptionInput): string {\n const base = option.title?.trim() || option.id?.trim() || \"\";\n const slugged = slugify(base);\n if (slugged.length) return slugged;\n if (base.length) return base;\n return createLocalId();\n}\n\nexport function buildVariantCombinations(\n options: ProductOptionInput[],\n): Record<string, string>[] {\n if (!options.length) return [];\n const [first, ...rest] = options;\n if (!first || !Array.isArray(first.values) || !first.values.length) return [];\n const firstKey = resolveOptionCode(first);\n const initial = first.values.map((value) => ({ [firstKey]: value.label }));\n return rest.reduce<Record<string, string>[]>((acc, option) => {\n if (!Array.isArray(option.values) || !option.values.length) return [];\n const optionKey = resolveOptionCode(option);\n const combos: Record<string, string>[] = [];\n acc.forEach((partial) => {\n option.values.forEach((value) => {\n combos.push({ ...partial, [optionKey]: value.label });\n });\n });\n return combos;\n }, initial);\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,eAAe;AACxB,SAAS,uBAAuB;
|
|
4
|
+
"sourcesContent": ["import { z } from \"zod\";\nimport { slugify } from \"@open-mercato/shared/lib/slugify\";\nimport { parseObjectLike } from \"@open-mercato/shared/lib/json/parseObjectLike\";\nimport type { ReferenceUnitCode } from \"@open-mercato/shared/lib/units/unitCodes\";\nimport {\n CATALOG_CONFIGURABLE_PRODUCT_TYPES,\n type CatalogProductOptionSchema,\n type CatalogProductType,\n} from \"../../data/types\";\nimport type { ProductMediaItem } from \"./ProductMediaManager\";\n\nexport { slugify };\n\nexport type PriceKindSummary = {\n id: string;\n code: string;\n title: string;\n currencyCode: string | null;\n displayMode: \"including-tax\" | \"excluding-tax\";\n};\n\nexport type PriceKindApiPayload = {\n id?: string | number;\n code?: string;\n title?: string;\n currencyCode?: string | null;\n currency_code?: string | null;\n displayMode?: string | null;\n display_mode?: string | null;\n};\n\nexport type TaxRateSummary = {\n id: string;\n name: string;\n code: string | null;\n rate: number | null;\n isDefault: boolean;\n};\n\nexport type ProductOptionInput = {\n id: string;\n title: string;\n values: Array<{ id: string; label: string }>;\n};\n\nexport type ProductDimensions = {\n width?: number;\n height?: number;\n depth?: number;\n unit?: string | null;\n} | null;\n\nexport type ProductWeight = {\n value?: number;\n unit?: string | null;\n} | null;\n\nexport type VariantPriceValue = {\n amount: string;\n};\n\nexport type ProductUnitRoundingMode = \"half_up\" | \"down\" | \"up\";\nexport type ProductUnitPriceReferenceUnit = ReferenceUnitCode;\n\nexport type ProductUnitConversionDraft = {\n id: string | null;\n unitCode: string;\n toBaseFactor: string;\n sortOrder: string;\n isActive: boolean;\n};\n\nexport type VariantDraft = {\n id: string;\n title: string;\n sku: string;\n isDefault: boolean;\n taxRateId: string | null;\n manageInventory: boolean;\n allowBackorder: boolean;\n hasInventoryKit: boolean;\n optionValues: Record<string, string>;\n prices: Record<string, VariantPriceValue>;\n};\n\nexport type ProductFormValues = {\n title: string;\n subtitle: string;\n handle: string;\n sku: string;\n productType: CatalogProductType;\n description: string;\n useMarkdown: boolean;\n taxRateId: string | null;\n mediaDraftId: string;\n mediaItems: ProductMediaItem[];\n defaultMediaId: string | null;\n defaultMediaUrl: string;\n hasVariants: boolean;\n options: ProductOptionInput[];\n variants: VariantDraft[];\n metadata?: Record<string, unknown> | null;\n dimensions?: ProductDimensions;\n weight?: ProductWeight;\n defaultUnit: string | null;\n defaultSalesUnit: string | null;\n defaultSalesUnitQuantity: string;\n uomRoundingScale: string;\n uomRoundingMode: ProductUnitRoundingMode;\n unitPriceEnabled: boolean;\n unitPriceReferenceUnit: string | null;\n unitPriceBaseQuantity: string;\n unitConversions: ProductUnitConversionDraft[];\n customFieldsetCode?: string | null;\n categoryIds: string[];\n channelIds: string[];\n tags: string[];\n optionSchemaId?: string | null;\n};\n\nconst optionalPositiveNumberInput = z.preprocess((value) => {\n if (value === null || value === undefined) return undefined;\n if (typeof value === \"string\" && value.trim().length === 0) return undefined;\n return value;\n}, z.coerce.number().positive().optional());\n\nconst optionalBoundedIntegerInput = (min: number, max: number) =>\n z.preprocess((value) => {\n if (value === null || value === undefined) return undefined;\n if (typeof value === \"string\" && value.trim().length === 0)\n return undefined;\n return value;\n }, z.coerce.number().int().min(min).max(max).optional());\n\nexport const productFormSchema = z\n .object({\n title: z.string().trim().min(1, \"catalog.products.validation.titleRequired\"),\n subtitle: z.string().optional(),\n handle: z\n .string()\n .trim()\n .regex(\n /^[a-z0-9\\-_]*$/,\n \"catalog.products.validation.handleFormat\",\n )\n .max(150)\n .optional(),\n sku: z\n .string()\n .trim()\n .regex(\n /^[A-Za-z0-9\\-_\\.]*$/,\n \"catalog.products.validation.skuFormat\",\n )\n .max(191)\n .optional(),\n productType: z.string().optional(),\n description: z.string().optional(),\n useMarkdown: z.boolean().optional(),\n taxRateId: z.string().uuid().nullable().optional(),\n hasVariants: z.boolean().optional(),\n mediaDraftId: z.string().optional(),\n mediaItems: z.any().optional(),\n defaultMediaId: z.string().uuid().nullable().optional(),\n defaultMediaUrl: z.string().trim().max(500).nullable().optional(),\n options: z.any().optional(),\n variants: z.any().optional(),\n // Use a permissive schema to avoid zod classic `_zod` runtime crashes on records in edge builds.\n metadata: z\n .custom<Record<string, unknown>>(() => true)\n .nullable()\n .optional(),\n dimensions: z\n .object({\n width: z.coerce.number().min(0).optional(),\n height: z.coerce.number().min(0).optional(),\n depth: z.coerce.number().min(0).optional(),\n unit: z.string().trim().max(25).optional(),\n })\n .nullable()\n .optional(),\n weight: z\n .object({\n value: z.coerce.number().min(0).optional(),\n unit: z.string().trim().max(25).optional(),\n })\n .nullable()\n .optional(),\n defaultUnit: z.string().trim().max(50).nullable().optional(),\n defaultSalesUnit: z.string().trim().max(50).nullable().optional(),\n defaultSalesUnitQuantity: optionalPositiveNumberInput,\n uomRoundingScale: optionalBoundedIntegerInput(0, 6),\n uomRoundingMode: z.enum([\"half_up\", \"down\", \"up\"]).optional(),\n unitPriceEnabled: z.boolean().optional(),\n unitPriceReferenceUnit: z.string().trim().max(50).nullable().optional(),\n unitPriceBaseQuantity: optionalPositiveNumberInput,\n unitConversions: z\n .array(\n z.object({\n id: z.string().nullable().optional(),\n unitCode: z.string().trim().max(50),\n toBaseFactor: z.coerce.number().positive(),\n sortOrder: z.coerce.number().int().min(0).max(100000).optional(),\n isActive: z.boolean().optional(),\n }),\n )\n .optional(),\n customFieldsetCode: z.string().optional().nullable(),\n categoryIds: z.array(z.string().uuid()).optional(),\n channelIds: z.array(z.string().uuid()).optional(),\n tags: z.array(z.string().trim().min(1).max(100)).optional(),\n optionSchemaId: z.string().uuid().nullable().optional(),\n })\n .passthrough()\n .refine(\n (data) => !data.unitPriceEnabled || (data.unitPriceReferenceUnit != null && data.unitPriceReferenceUnit.length > 0),\n { message: 'catalog.products.validation.referenceUnitRequired', path: ['unitPriceReferenceUnit'] }\n )\n .refine(\n (data) => !data.defaultSalesUnit || (data.defaultUnit != null && data.defaultUnit.length > 0),\n { message: 'catalog.products.validation.baseUnitRequired', path: ['defaultUnit'] }\n );\n\nexport const PRODUCT_FORM_STEPS = [\n \"general\",\n \"organize\",\n \"uom\",\n \"variants\",\n] as const;\n\nexport const BASE_INITIAL_VALUES: ProductFormValues = {\n title: \"\",\n subtitle: \"\",\n handle: \"\",\n sku: \"\",\n productType: \"simple\",\n description: \"\",\n useMarkdown: false,\n mediaDraftId: \"\",\n mediaItems: [],\n defaultMediaId: null,\n defaultMediaUrl: \"\",\n taxRateId: null,\n hasVariants: false,\n options: [],\n variants: [],\n metadata: {},\n dimensions: null,\n weight: null,\n defaultUnit: null,\n defaultSalesUnit: null,\n defaultSalesUnitQuantity: \"1\",\n uomRoundingScale: \"4\",\n uomRoundingMode: \"half_up\",\n unitPriceEnabled: false,\n unitPriceReferenceUnit: null,\n unitPriceBaseQuantity: \"\",\n unitConversions: [],\n customFieldsetCode: null,\n categoryIds: [],\n channelIds: [],\n tags: [],\n optionSchemaId: null,\n};\n\nexport const isConfigurableProductType = (type: string): boolean =>\n (CATALOG_CONFIGURABLE_PRODUCT_TYPES as readonly string[]).includes(type);\n\nexport const createInitialProductFormValues = (): ProductFormValues => ({\n ...BASE_INITIAL_VALUES,\n mediaDraftId: createLocalId(),\n variants: [createVariantDraft(null, { isDefault: true })],\n});\n\nexport const createVariantDraft = (\n productTaxRateId: string | null,\n overrides: Partial<VariantDraft> = {},\n): VariantDraft => ({\n id: createLocalId(),\n title: \"Default variant\",\n sku: \"\",\n isDefault: false,\n taxRateId: productTaxRateId ?? null,\n manageInventory: false,\n allowBackorder: false,\n hasInventoryKit: false,\n optionValues: {},\n prices: {},\n ...overrides,\n});\n\nexport const createProductUnitConversionDraft = (\n overrides: Partial<ProductUnitConversionDraft> = {},\n): ProductUnitConversionDraft => ({\n id: null,\n unitCode: \"\",\n toBaseFactor: \"\",\n sortOrder: \"\",\n isActive: true,\n ...overrides,\n});\n\nexport const buildOptionValuesKey = (\n optionValues?: Record<string, string>,\n): string => {\n if (!optionValues) return \"\";\n return Object.keys(optionValues)\n .sort((a, b) => a.localeCompare(b))\n .map((key) => `${key}:${optionValues[key] ?? \"\"}`)\n .join(\"|\");\n};\n\nexport const haveSameOptionValues = (\n current: Record<string, string> | undefined,\n next: Record<string, string>,\n): boolean => {\n const a = current ?? {};\n const keys = new Set([...Object.keys(a), ...Object.keys(next)]);\n for (const key of keys) {\n if ((a[key] ?? \"\") !== (next[key] ?? \"\")) return false;\n }\n return true;\n};\n\nconst parseNumeric = (input: unknown): number | null => {\n const numeric = typeof input === \"number\" ? input : Number(input);\n if (!Number.isFinite(numeric) || numeric < 0) return null;\n return numeric;\n};\n\nexport const normalizeProductDimensions = (raw: unknown): ProductDimensions => {\n const source = parseObjectLike(raw);\n if (!source) return null;\n const width = parseNumeric(source.width);\n const height = parseNumeric(source.height);\n const depth = parseNumeric(source.depth);\n const unit =\n typeof source.unit === \"string\" && source.unit.trim().length\n ? source.unit.trim()\n : null;\n const clean: Record<string, unknown> = {};\n if (width !== null) clean.width = width;\n if (height !== null) clean.height = height;\n if (depth !== null) clean.depth = depth;\n if (unit) clean.unit = unit;\n return Object.keys(clean).length ? (clean as ProductDimensions) : null;\n};\n\nexport const normalizeProductWeight = (raw: unknown): ProductWeight => {\n const source = parseObjectLike(raw);\n if (!source) return null;\n const value = parseNumeric(source.value);\n const unit =\n typeof source.unit === \"string\" && source.unit.trim().length\n ? source.unit.trim()\n : null;\n if (value === null && !unit) return null;\n const clean: Record<string, unknown> = {};\n if (value !== null) clean.value = value;\n if (unit) clean.unit = unit;\n return clean as ProductWeight;\n};\n\nexport const sanitizeProductDimensions = (\n raw: ProductDimensions,\n): ProductDimensions => {\n return normalizeProductDimensions(raw ?? null);\n};\n\nexport const sanitizeProductWeight = (raw: ProductWeight): ProductWeight => {\n return normalizeProductWeight(raw ?? null);\n};\n\nexport const updateDimensionValue = (\n current: ProductDimensions,\n field: \"width\" | \"height\" | \"depth\" | \"unit\",\n raw: string,\n): ProductDimensions => {\n const base = normalizeProductDimensions(current) ?? {};\n if (field === \"unit\") {\n base.unit = raw;\n } else {\n const numeric = parseNumeric(raw);\n if (numeric === null) {\n delete base[field];\n } else {\n base[field] = numeric;\n }\n }\n return sanitizeProductDimensions(base);\n};\n\nexport const updateWeightValue = (\n current: ProductWeight,\n field: \"value\" | \"unit\",\n raw: string,\n): ProductWeight => {\n const base = normalizeProductWeight(current) ?? {};\n if (field === \"unit\") {\n base.unit = raw;\n } else {\n const numeric = parseNumeric(raw);\n if (numeric === null) {\n delete (base as Record<string, unknown>).value;\n } else {\n base.value = numeric;\n }\n }\n return sanitizeProductWeight(base);\n};\n\nexport const normalizePriceKindSummary = (\n input: PriceKindApiPayload | undefined | null,\n): PriceKindSummary | null => {\n if (!input) return null;\n const getString = (value: unknown): string | null => {\n if (typeof value === \"string\" && value.trim().length) return value.trim();\n if (typeof value === \"number\" || typeof value === \"bigint\")\n return String(value);\n return null;\n };\n const id = getString(input.id);\n const code = getString(input.code);\n const title = getString(input.title);\n if (!id || !code || !title) return null;\n const currency =\n getString(input.currencyCode) ?? getString(input.currency_code);\n const displayRaw =\n getString(input.displayMode) ?? getString(input.display_mode);\n const displayMode: PriceKindSummary[\"displayMode\"] =\n displayRaw === \"including-tax\" ? \"including-tax\" : \"excluding-tax\";\n return {\n id,\n code,\n title,\n currencyCode: currency,\n displayMode,\n };\n};\n\nexport const formatTaxRateLabel = (rate: TaxRateSummary): string => {\n const extras: string[] = [];\n if (typeof rate.rate === \"number\" && Number.isFinite(rate.rate)) {\n extras.push(`${rate.rate}%`);\n }\n if (rate.code) {\n extras.push(rate.code.toUpperCase());\n }\n if (!extras.length) return rate.name;\n return `${rate.name} \u2022 ${extras.join(\" \u00B7 \")}`;\n};\n\nexport function createLocalId(): string {\n return Math.random().toString(36).slice(2, 10);\n}\n\nexport function buildOptionSchemaDefinition(\n options: ProductOptionInput[] | undefined,\n name: string,\n): CatalogProductOptionSchema | null {\n const list = Array.isArray(options) ? options : [];\n if (!list.length) return null;\n const normalizedName =\n name && name.trim().length ? name.trim() : \"Product options\";\n const schemaOptions = list\n .map((option) => {\n const title = option.title?.trim() || \"\";\n const code = resolveOptionCode(option);\n const values = Array.isArray(option.values) ? option.values : [];\n return {\n code: code || slugify(createLocalId()),\n label: title || code || \"Option\",\n inputType: \"select\" as const,\n choices: values\n .map((value) => {\n const label = value.label?.trim() || \"\";\n const valueCode = slugify(label || value.id || createLocalId());\n if (!label && !valueCode) return null;\n return {\n code: valueCode || slugify(createLocalId()),\n label: label || valueCode || \"Choice\",\n };\n })\n .filter((entry): entry is { code: string; label: string } => !!entry),\n };\n })\n .filter((entry) => entry.label.trim().length);\n if (!schemaOptions.length) return null;\n return {\n version: 1,\n name: normalizedName,\n options: schemaOptions,\n };\n}\n\nexport function convertSchemaToProductOptions(\n schema: CatalogProductOptionSchema | null | undefined,\n): ProductOptionInput[] {\n if (!schema || !Array.isArray(schema.options)) return [];\n return schema.options.map((option) => ({\n id: createLocalId(),\n title: option.label ?? option.code ?? \"Option\",\n values: Array.isArray(option.choices)\n ? option.choices.map((choice) => ({\n id: createLocalId(),\n label: choice.label ?? choice.code ?? \"\",\n }))\n : [],\n }));\n}\n\nfunction resolveOptionCode(option: ProductOptionInput): string {\n const base = option.title?.trim() || option.id?.trim() || \"\";\n const slugged = slugify(base);\n if (slugged.length) return slugged;\n if (base.length) return base;\n return createLocalId();\n}\n\nexport function buildVariantCombinations(\n options: ProductOptionInput[],\n): Record<string, string>[] {\n if (!options.length) return [];\n const [first, ...rest] = options;\n if (!first || !Array.isArray(first.values) || !first.values.length) return [];\n const firstKey = resolveOptionCode(first);\n const initial = first.values.map((value) => ({ [firstKey]: value.label }));\n return rest.reduce<Record<string, string>[]>((acc, option) => {\n if (!Array.isArray(option.values) || !option.values.length) return [];\n const optionKey = resolveOptionCode(option);\n const combos: Record<string, string>[] = [];\n acc.forEach((partial) => {\n option.values.forEach((value) => {\n combos.push({ ...partial, [optionKey]: value.label });\n });\n });\n return combos;\n }, initial);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,OAGK;AAgHP,MAAM,8BAA8B,EAAE,WAAW,CAAC,UAAU;AAC1D,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,WAAW,EAAG,QAAO;AACnE,SAAO;AACT,GAAG,EAAE,OAAO,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC;AAE1C,MAAM,8BAA8B,CAAC,KAAa,QAChD,EAAE,WAAW,CAAC,UAAU;AACtB,MAAI,UAAU,QAAQ,UAAU,OAAW,QAAO;AAClD,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,WAAW;AACvD,WAAO;AACT,SAAO;AACT,GAAG,EAAE,OAAO,OAAO,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,IAAI,GAAG,EAAE,SAAS,CAAC;AAElD,MAAM,oBAAoB,EAC9B,OAAO;AAAA,EACN,OAAO,EAAE,OAAO,EAAE,K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AC,WAAW,EAAE,CAAC,QAAQ,GAAG,MAAM,MAAM,EAAE;AACzE,SAAO,KAAK,OAAiC,CAAC,KAAK,WAAW;AAC5D,QAAI,CAAC,MAAM,QAAQ,OAAO,MAAM,KAAK,CAAC,OAAO,OAAO,OAAQ,QAAO,CAAC;AACpE,UAAM,YAAY,kBAAkB,MAAM;AAC1C,UAAM,SAAmC,CAAC;AAC1C,QAAI,QAAQ,CAAC,YAAY;AACvB,aAAO,OAAO,QAAQ,CAAC,UAAU;AAC/B,eAAO,KAAK,EAAE,GAAG,SAAS,CAAC,SAAS,GAAG,MAAM,MAAM,CAAC;AAAA,MACtD,CAAC;AAAA,IACH,CAAC;AACD,WAAO;AAAA,EACT,GAAG,OAAO;AACZ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -116,7 +116,7 @@ const productBaseSchema = scoped.extend({
|
|
|
116
116
|
title: z.string().trim().min(1).max(255),
|
|
117
117
|
subtitle: z.string().trim().max(255).optional(),
|
|
118
118
|
description: z.string().trim().max(4e3).optional(),
|
|
119
|
-
sku: skuSchema.optional(),
|
|
119
|
+
sku: skuSchema.nullable().optional(),
|
|
120
120
|
handle: handleSchema.optional(),
|
|
121
121
|
taxRateId: uuid().nullable().optional(),
|
|
122
122
|
taxRate: z.coerce.number().min(0).max(100).optional().nullable(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/catalog/data/validators.ts"],
|
|
4
|
-
"sourcesContent": ["import { z } from 'zod'\nimport { CATALOG_PRICE_DISPLAY_MODES, CATALOG_PRODUCT_TYPES } from './types'\nimport { REFERENCE_UNIT_CODES } from '../lib/unitCodes'\nimport {\n getCatalogPriceAmountValidationMessage,\n validateCatalogPriceAmountInput,\n} from '../lib/priceValidation'\n\nconst uuid = () => z.string().uuid()\n\nconst scoped = z.object({\n organizationId: uuid(),\n tenantId: uuid(),\n})\n\nconst tenantScoped = z.object({\n tenantId: uuid(),\n})\n\nconst currencyCodeSchema = z\n .string()\n .trim()\n .regex(/^[A-Z]{3}$/, 'currency code must be a three-letter ISO code')\n\nconst metadataSchema = z.record(z.string(), z.unknown()).optional()\n\nconst slugSchema = z\n .string()\n .trim()\n .toLowerCase()\n .regex(/^[a-z0-9\\-_]+$/, 'code must contain lowercase letters, digits, hyphen, or underscore')\n .max(150)\n\nconst handleSchema = z\n .string()\n .trim()\n .toLowerCase()\n .regex(/^[a-z0-9\\-_]+$/, 'handle must contain lowercase letters, digits, hyphen, or underscore')\n .max(150)\n\nconst skuSchema = z\n .string()\n .trim()\n .regex(/^[A-Za-z0-9\\-_\\.]+$/, 'SKU may include letters, numbers, hyphen, underscore, or period')\n .max(191)\n\nconst variantOptionValuesSchema = z\n .record(\n z\n .string()\n .trim()\n .min(1)\n .max(191),\n z.string().trim().max(255)\n )\n .optional()\n\nconst optionChoiceSchema = z.object({\n code: slugSchema,\n label: z.string().trim().max(255).optional(),\n})\n\nconst optionDefinitionSchema = z.object({\n code: slugSchema,\n label: z.string().trim().min(1).max(255),\n description: z.string().trim().max(2000).optional(),\n inputType: z.enum(['select', 'text', 'textarea', 'number']),\n isRequired: z.boolean().optional(),\n isMultiple: z.boolean().optional(),\n choices: z.array(optionChoiceSchema).max(200).optional(),\n})\n\nconst optionSchema = z.object({\n version: z.number().int().min(1).optional(),\n name: z.string().trim().max(255).optional(),\n description: z.string().trim().max(4000).optional(),\n options: z.array(optionDefinitionSchema).max(64),\n})\n\nconst tagLabelSchema = z.string().trim().min(1).max(100)\n\nconst offerBaseSchema = z.object({\n channelId: uuid(),\n title: z.string().trim().min(1).max(255),\n description: z.string().trim().max(4000).optional(),\n defaultMediaId: uuid().optional().nullable(),\n defaultMediaUrl: z.string().trim().max(500).optional().nullable(),\n metadata: metadataSchema,\n isActive: z.boolean().optional(),\n})\n\nconst offerInputSchema = offerBaseSchema.extend({\n id: uuid().optional(),\n})\n\nexport const offerCreateSchema = scoped.merge(\n offerBaseSchema.extend({\n productId: uuid(),\n })\n)\n\nexport const offerUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(\n offerBaseSchema\n .extend({\n productId: uuid().optional(),\n })\n .partial()\n )\n\nconst productTypeSchema = z.enum(CATALOG_PRODUCT_TYPES)\nconst uomRoundingModeSchema = z.enum(['half_up', 'down', 'up'])\nconst unitPriceReferenceUnitSchema = z.enum(REFERENCE_UNIT_CODES)\nconst unitPriceConfigSchema = z.object({\n enabled: z.boolean().optional(),\n referenceUnit: unitPriceReferenceUnitSchema.nullable().optional(),\n baseQuantity: z.coerce.number().positive().optional(),\n})\n\nconst catalogPriceAmountSchema = z\n .custom<number>((value) => validateCatalogPriceAmountInput(value).ok, {\n message: getCatalogPriceAmountValidationMessage(),\n })\n .transform((value) => {\n const result = validateCatalogPriceAmountInput(value)\n if (!result.ok) {\n throw new Error('catalogPriceAmountSchema transform reached invalid state')\n }\n return result.numeric\n })\n\nfunction productUomCrossFieldRefinement(\n input: {\n defaultUnit?: string | null\n defaultSalesUnit?: string | null\n unitPriceEnabled?: boolean\n unitPriceReferenceUnit?: string | null\n unitPriceBaseQuantity?: number\n unitPrice?: { enabled?: boolean; referenceUnit?: string | null; baseQuantity?: number }\n },\n ctx: z.RefinementCtx,\n) {\n const defaultUnit = typeof input.defaultUnit === 'string' ? input.defaultUnit.trim() : ''\n const defaultSalesUnit =\n typeof input.defaultSalesUnit === 'string' ? input.defaultSalesUnit.trim() : ''\n if (defaultSalesUnit && !defaultUnit) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['defaultSalesUnit'],\n message: 'catalog.products.validation.baseUnitRequired',\n })\n }\n const unitPriceEnabled = input.unitPrice?.enabled ?? input.unitPriceEnabled ?? false\n if (!unitPriceEnabled) return\n const referenceUnit =\n input.unitPrice?.referenceUnit ?? input.unitPriceReferenceUnit ?? null\n const baseQuantity =\n input.unitPrice?.baseQuantity ?? input.unitPriceBaseQuantity ?? null\n if (!referenceUnit) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['unitPrice'],\n message: 'catalog.products.validation.referenceUnitRequired',\n })\n }\n if (baseQuantity === null || baseQuantity === undefined || Number(baseQuantity) <= 0) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['unitPrice'],\n message: 'catalog.products.unitPrice.errors.baseQuantity',\n })\n }\n}\n\n// Base schema without refinements (used for .partial() in update schema)\nconst productBaseSchema = scoped.extend({\n title: z.string().trim().min(1).max(255),\n subtitle: z.string().trim().max(255).optional(),\n description: z.string().trim().max(4000).optional(),\n sku: skuSchema.optional(),\n handle: handleSchema.optional(),\n taxRateId: uuid().nullable().optional(),\n taxRate: z.coerce.number().min(0).max(100).optional().nullable(),\n productType: productTypeSchema.default('simple'),\n statusEntryId: uuid().optional(),\n primaryCurrencyCode: currencyCodeSchema.optional(),\n defaultUnit: z.string().trim().max(50).optional().nullable(),\n defaultSalesUnit: z.string().trim().max(50).optional().nullable(),\n defaultSalesUnitQuantity: z.coerce.number().positive().optional(),\n uomRoundingScale: z.coerce.number().int().min(0).max(6).optional(),\n uomRoundingMode: uomRoundingModeSchema.optional(),\n unitPriceEnabled: z.boolean().optional(),\n unitPriceReferenceUnit: unitPriceReferenceUnitSchema.nullable().optional(),\n unitPriceBaseQuantity: z.coerce.number().positive().optional(),\n unitPrice: unitPriceConfigSchema.optional(),\n defaultMediaId: uuid().optional().nullable(),\n defaultMediaUrl: z.string().trim().max(500).optional().nullable(),\n weightValue: z.coerce.number().min(0).optional().nullable(),\n weightUnit: z.string().trim().max(25).optional().nullable(),\n dimensions: z\n .object({\n width: z.coerce.number().min(0).optional(),\n height: z.coerce.number().min(0).optional(),\n depth: z.coerce.number().min(0).optional(),\n unit: z.string().trim().max(25).optional(),\n })\n .optional()\n .nullable(),\n optionSchemaId: uuid().nullable().optional(),\n optionSchema: optionSchema.optional(),\n customFieldsetCode: slugSchema.nullable().optional(),\n isConfigurable: z.boolean().optional(),\n isActive: z.boolean().optional(),\n metadata: metadataSchema,\n offers: z.array(offerInputSchema.omit({ id: true })).optional(),\n categoryIds: z.array(uuid()).max(100).optional(),\n tags: z.array(tagLabelSchema).max(100).optional(),\n})\n\nexport const productCreateSchema = productBaseSchema\n .superRefine(productUomCrossFieldRefinement)\n\nexport const productUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(productBaseSchema.partial())\n .extend({\n productType: productTypeSchema.optional(),\n })\n .superRefine(productUomCrossFieldRefinement)\n\nexport const variantCreateSchema = scoped.extend({\n productId: uuid(),\n name: z.string().trim().max(255).optional(),\n sku: z\n .string()\n .trim()\n .regex(/^[A-Za-z0-9\\-_\\.]+$/)\n .max(191)\n .optional(),\n barcode: z.string().trim().max(191).optional(),\n statusEntryId: uuid().optional(),\n isDefault: z.boolean().optional(),\n isActive: z.boolean().optional(),\n defaultMediaId: uuid().optional().nullable(),\n defaultMediaUrl: z.string().trim().max(500).optional().nullable(),\n weightValue: z.coerce.number().min(0).optional(),\n weightUnit: z.string().trim().max(25).optional(),\n taxRateId: uuid().nullable().optional(),\n taxRate: z.coerce.number().min(0).max(100).optional().nullable(),\n dimensions: z\n .object({\n width: z.coerce.number().min(0).optional(),\n height: z.coerce.number().min(0).optional(),\n depth: z.coerce.number().min(0).optional(),\n unit: z.string().trim().max(25).optional(),\n })\n .optional(),\n metadata: metadataSchema,\n optionValues: variantOptionValuesSchema,\n customFieldsetCode: slugSchema.nullable().optional(),\n})\n\nexport const variantUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(variantCreateSchema.partial())\n\nexport const optionSchemaTemplateCreateSchema = scoped.extend({\n name: z.string().trim().min(1).max(255),\n code: slugSchema.optional(),\n description: z.string().trim().max(4000).optional(),\n schema: optionSchema,\n metadata: metadataSchema,\n isActive: z.boolean().optional(),\n})\n\nexport const optionSchemaTemplateUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(optionSchemaTemplateCreateSchema.partial())\n\nconst priceDisplayModeSchema = z.enum(CATALOG_PRICE_DISPLAY_MODES)\n\nexport const priceKindCreateSchema = tenantScoped.extend({\n code: slugSchema,\n title: z.string().trim().min(1).max(255),\n displayMode: priceDisplayModeSchema.default('excluding-tax'),\n currencyCode: currencyCodeSchema.optional(),\n isPromotion: z.boolean().optional(),\n isActive: z.boolean().optional(),\n})\n\nexport const priceKindUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(priceKindCreateSchema.partial())\n\nexport const priceCreateSchema = scoped.extend({\n variantId: uuid().optional(),\n productId: uuid().optional(),\n offerId: uuid().optional(),\n currencyCode: currencyCodeSchema,\n priceKindId: uuid(),\n minQuantity: z.coerce.number().int().min(1).optional(),\n maxQuantity: z.coerce.number().int().min(1).optional(),\n unitPriceNet: catalogPriceAmountSchema.optional(),\n unitPriceGross: catalogPriceAmountSchema.optional(),\n taxRate: z.coerce.number().min(0).max(100).optional(),\n taxRateId: uuid().nullable().optional(),\n channelId: uuid().optional(),\n userId: uuid().optional(),\n userGroupId: uuid().optional(),\n customerId: uuid().optional(),\n customerGroupId: uuid().optional(),\n metadata: metadataSchema,\n startsAt: z.coerce.date().optional(),\n endsAt: z.coerce.date().optional(),\n})\n\nexport const priceUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(priceCreateSchema.partial())\n\nexport const categoryCreateSchema = scoped.extend({\n name: z.string().trim().min(1).max(255),\n slug: slugSchema.optional().nullable(),\n description: z.string().trim().max(2000).optional(),\n parentId: uuid().optional().nullable(),\n isActive: z.boolean().optional(),\n})\n\nexport const categoryUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(categoryCreateSchema.partial())\n\nexport const productUnitConversionCreateSchema = scoped.extend({\n productId: uuid(),\n unitCode: z.string().trim().min(1).max(50),\n toBaseFactor: z.coerce.number().positive().max(1_000_000),\n sortOrder: z.coerce.number().int().optional(),\n isActive: z.boolean().optional(),\n metadata: metadataSchema,\n})\n\nexport const productUnitConversionUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(productUnitConversionCreateSchema.omit({ productId: true }).partial())\n\nexport const productUnitConversionDeleteSchema = scoped.extend({\n id: uuid(),\n})\n\nexport type ProductCreateInput = z.infer<typeof productCreateSchema>\nexport type ProductUpdateInput = z.infer<typeof productUpdateSchema>\nexport type VariantCreateInput = z.infer<typeof variantCreateSchema>\nexport type VariantUpdateInput = z.infer<typeof variantUpdateSchema>\nexport type OptionSchemaTemplateCreateInput = z.infer<typeof optionSchemaTemplateCreateSchema>\nexport type OptionSchemaTemplateUpdateInput = z.infer<typeof optionSchemaTemplateUpdateSchema>\nexport type PriceKindCreateInput = z.infer<typeof priceKindCreateSchema>\nexport type PriceKindUpdateInput = z.infer<typeof priceKindUpdateSchema>\nexport type PriceCreateInput = z.infer<typeof priceCreateSchema>\nexport type PriceUpdateInput = z.infer<typeof priceUpdateSchema>\nexport type CategoryCreateInput = z.infer<typeof categoryCreateSchema>\nexport type CategoryUpdateInput = z.infer<typeof categoryUpdateSchema>\nexport type OfferInput = z.infer<typeof offerInputSchema>\nexport type OfferCreateInput = z.infer<typeof offerCreateSchema>\nexport type OfferUpdateInput = z.infer<typeof offerUpdateSchema>\nexport type ProductUnitConversionCreateInput = z.infer<typeof productUnitConversionCreateSchema>\nexport type ProductUnitConversionUpdateInput = z.infer<typeof productUnitConversionUpdateSchema>\nexport type ProductUnitConversionDeleteInput = z.infer<typeof productUnitConversionDeleteSchema>\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,6BAA6B,6BAA6B;AACnE,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,OAAO,MAAM,EAAE,OAAO,EAAE,KAAK;AAEnC,MAAM,SAAS,EAAE,OAAO;AAAA,EACtB,gBAAgB,KAAK;AAAA,EACrB,UAAU,KAAK;AACjB,CAAC;AAED,MAAM,eAAe,EAAE,OAAO;AAAA,EAC5B,UAAU,KAAK;AACjB,CAAC;AAED,MAAM,qBAAqB,EACxB,OAAO,EACP,KAAK,EACL,MAAM,cAAc,+CAA+C;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AAS;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAGA,MAAM,oBAAoB,OAAO,OAAO;AAAA,EACtC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG;AAAA,EACvC,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,SAAS;AAAA,EAC9C,aAAa,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,GAAI,EAAE,SAAS;AAAA,EAClD,KAAK,UAAU,SAAS;AAAA,
|
|
4
|
+
"sourcesContent": ["import { z } from 'zod'\nimport { CATALOG_PRICE_DISPLAY_MODES, CATALOG_PRODUCT_TYPES } from './types'\nimport { REFERENCE_UNIT_CODES } from '../lib/unitCodes'\nimport {\n getCatalogPriceAmountValidationMessage,\n validateCatalogPriceAmountInput,\n} from '../lib/priceValidation'\n\nconst uuid = () => z.string().uuid()\n\nconst scoped = z.object({\n organizationId: uuid(),\n tenantId: uuid(),\n})\n\nconst tenantScoped = z.object({\n tenantId: uuid(),\n})\n\nconst currencyCodeSchema = z\n .string()\n .trim()\n .regex(/^[A-Z]{3}$/, 'currency code must be a three-letter ISO code')\n\nconst metadataSchema = z.record(z.string(), z.unknown()).optional()\n\nconst slugSchema = z\n .string()\n .trim()\n .toLowerCase()\n .regex(/^[a-z0-9\\-_]+$/, 'code must contain lowercase letters, digits, hyphen, or underscore')\n .max(150)\n\nconst handleSchema = z\n .string()\n .trim()\n .toLowerCase()\n .regex(/^[a-z0-9\\-_]+$/, 'handle must contain lowercase letters, digits, hyphen, or underscore')\n .max(150)\n\nconst skuSchema = z\n .string()\n .trim()\n .regex(/^[A-Za-z0-9\\-_\\.]+$/, 'SKU may include letters, numbers, hyphen, underscore, or period')\n .max(191)\n\nconst variantOptionValuesSchema = z\n .record(\n z\n .string()\n .trim()\n .min(1)\n .max(191),\n z.string().trim().max(255)\n )\n .optional()\n\nconst optionChoiceSchema = z.object({\n code: slugSchema,\n label: z.string().trim().max(255).optional(),\n})\n\nconst optionDefinitionSchema = z.object({\n code: slugSchema,\n label: z.string().trim().min(1).max(255),\n description: z.string().trim().max(2000).optional(),\n inputType: z.enum(['select', 'text', 'textarea', 'number']),\n isRequired: z.boolean().optional(),\n isMultiple: z.boolean().optional(),\n choices: z.array(optionChoiceSchema).max(200).optional(),\n})\n\nconst optionSchema = z.object({\n version: z.number().int().min(1).optional(),\n name: z.string().trim().max(255).optional(),\n description: z.string().trim().max(4000).optional(),\n options: z.array(optionDefinitionSchema).max(64),\n})\n\nconst tagLabelSchema = z.string().trim().min(1).max(100)\n\nconst offerBaseSchema = z.object({\n channelId: uuid(),\n title: z.string().trim().min(1).max(255),\n description: z.string().trim().max(4000).optional(),\n defaultMediaId: uuid().optional().nullable(),\n defaultMediaUrl: z.string().trim().max(500).optional().nullable(),\n metadata: metadataSchema,\n isActive: z.boolean().optional(),\n})\n\nconst offerInputSchema = offerBaseSchema.extend({\n id: uuid().optional(),\n})\n\nexport const offerCreateSchema = scoped.merge(\n offerBaseSchema.extend({\n productId: uuid(),\n })\n)\n\nexport const offerUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(\n offerBaseSchema\n .extend({\n productId: uuid().optional(),\n })\n .partial()\n )\n\nconst productTypeSchema = z.enum(CATALOG_PRODUCT_TYPES)\nconst uomRoundingModeSchema = z.enum(['half_up', 'down', 'up'])\nconst unitPriceReferenceUnitSchema = z.enum(REFERENCE_UNIT_CODES)\nconst unitPriceConfigSchema = z.object({\n enabled: z.boolean().optional(),\n referenceUnit: unitPriceReferenceUnitSchema.nullable().optional(),\n baseQuantity: z.coerce.number().positive().optional(),\n})\n\nconst catalogPriceAmountSchema = z\n .custom<number>((value) => validateCatalogPriceAmountInput(value).ok, {\n message: getCatalogPriceAmountValidationMessage(),\n })\n .transform((value) => {\n const result = validateCatalogPriceAmountInput(value)\n if (!result.ok) {\n throw new Error('catalogPriceAmountSchema transform reached invalid state')\n }\n return result.numeric\n })\n\nfunction productUomCrossFieldRefinement(\n input: {\n defaultUnit?: string | null\n defaultSalesUnit?: string | null\n unitPriceEnabled?: boolean\n unitPriceReferenceUnit?: string | null\n unitPriceBaseQuantity?: number\n unitPrice?: { enabled?: boolean; referenceUnit?: string | null; baseQuantity?: number }\n },\n ctx: z.RefinementCtx,\n) {\n const defaultUnit = typeof input.defaultUnit === 'string' ? input.defaultUnit.trim() : ''\n const defaultSalesUnit =\n typeof input.defaultSalesUnit === 'string' ? input.defaultSalesUnit.trim() : ''\n if (defaultSalesUnit && !defaultUnit) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['defaultSalesUnit'],\n message: 'catalog.products.validation.baseUnitRequired',\n })\n }\n const unitPriceEnabled = input.unitPrice?.enabled ?? input.unitPriceEnabled ?? false\n if (!unitPriceEnabled) return\n const referenceUnit =\n input.unitPrice?.referenceUnit ?? input.unitPriceReferenceUnit ?? null\n const baseQuantity =\n input.unitPrice?.baseQuantity ?? input.unitPriceBaseQuantity ?? null\n if (!referenceUnit) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['unitPrice'],\n message: 'catalog.products.validation.referenceUnitRequired',\n })\n }\n if (baseQuantity === null || baseQuantity === undefined || Number(baseQuantity) <= 0) {\n ctx.addIssue({\n code: z.ZodIssueCode.custom,\n path: ['unitPrice'],\n message: 'catalog.products.unitPrice.errors.baseQuantity',\n })\n }\n}\n\n// Base schema without refinements (used for .partial() in update schema)\nconst productBaseSchema = scoped.extend({\n title: z.string().trim().min(1).max(255),\n subtitle: z.string().trim().max(255).optional(),\n description: z.string().trim().max(4000).optional(),\n sku: skuSchema.nullable().optional(),\n handle: handleSchema.optional(),\n taxRateId: uuid().nullable().optional(),\n taxRate: z.coerce.number().min(0).max(100).optional().nullable(),\n productType: productTypeSchema.default('simple'),\n statusEntryId: uuid().optional(),\n primaryCurrencyCode: currencyCodeSchema.optional(),\n defaultUnit: z.string().trim().max(50).optional().nullable(),\n defaultSalesUnit: z.string().trim().max(50).optional().nullable(),\n defaultSalesUnitQuantity: z.coerce.number().positive().optional(),\n uomRoundingScale: z.coerce.number().int().min(0).max(6).optional(),\n uomRoundingMode: uomRoundingModeSchema.optional(),\n unitPriceEnabled: z.boolean().optional(),\n unitPriceReferenceUnit: unitPriceReferenceUnitSchema.nullable().optional(),\n unitPriceBaseQuantity: z.coerce.number().positive().optional(),\n unitPrice: unitPriceConfigSchema.optional(),\n defaultMediaId: uuid().optional().nullable(),\n defaultMediaUrl: z.string().trim().max(500).optional().nullable(),\n weightValue: z.coerce.number().min(0).optional().nullable(),\n weightUnit: z.string().trim().max(25).optional().nullable(),\n dimensions: z\n .object({\n width: z.coerce.number().min(0).optional(),\n height: z.coerce.number().min(0).optional(),\n depth: z.coerce.number().min(0).optional(),\n unit: z.string().trim().max(25).optional(),\n })\n .optional()\n .nullable(),\n optionSchemaId: uuid().nullable().optional(),\n optionSchema: optionSchema.optional(),\n customFieldsetCode: slugSchema.nullable().optional(),\n isConfigurable: z.boolean().optional(),\n isActive: z.boolean().optional(),\n metadata: metadataSchema,\n offers: z.array(offerInputSchema.omit({ id: true })).optional(),\n categoryIds: z.array(uuid()).max(100).optional(),\n tags: z.array(tagLabelSchema).max(100).optional(),\n})\n\nexport const productCreateSchema = productBaseSchema\n .superRefine(productUomCrossFieldRefinement)\n\nexport const productUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(productBaseSchema.partial())\n .extend({\n productType: productTypeSchema.optional(),\n })\n .superRefine(productUomCrossFieldRefinement)\n\nexport const variantCreateSchema = scoped.extend({\n productId: uuid(),\n name: z.string().trim().max(255).optional(),\n sku: z\n .string()\n .trim()\n .regex(/^[A-Za-z0-9\\-_\\.]+$/)\n .max(191)\n .optional(),\n barcode: z.string().trim().max(191).optional(),\n statusEntryId: uuid().optional(),\n isDefault: z.boolean().optional(),\n isActive: z.boolean().optional(),\n defaultMediaId: uuid().optional().nullable(),\n defaultMediaUrl: z.string().trim().max(500).optional().nullable(),\n weightValue: z.coerce.number().min(0).optional(),\n weightUnit: z.string().trim().max(25).optional(),\n taxRateId: uuid().nullable().optional(),\n taxRate: z.coerce.number().min(0).max(100).optional().nullable(),\n dimensions: z\n .object({\n width: z.coerce.number().min(0).optional(),\n height: z.coerce.number().min(0).optional(),\n depth: z.coerce.number().min(0).optional(),\n unit: z.string().trim().max(25).optional(),\n })\n .optional(),\n metadata: metadataSchema,\n optionValues: variantOptionValuesSchema,\n customFieldsetCode: slugSchema.nullable().optional(),\n})\n\nexport const variantUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(variantCreateSchema.partial())\n\nexport const optionSchemaTemplateCreateSchema = scoped.extend({\n name: z.string().trim().min(1).max(255),\n code: slugSchema.optional(),\n description: z.string().trim().max(4000).optional(),\n schema: optionSchema,\n metadata: metadataSchema,\n isActive: z.boolean().optional(),\n})\n\nexport const optionSchemaTemplateUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(optionSchemaTemplateCreateSchema.partial())\n\nconst priceDisplayModeSchema = z.enum(CATALOG_PRICE_DISPLAY_MODES)\n\nexport const priceKindCreateSchema = tenantScoped.extend({\n code: slugSchema,\n title: z.string().trim().min(1).max(255),\n displayMode: priceDisplayModeSchema.default('excluding-tax'),\n currencyCode: currencyCodeSchema.optional(),\n isPromotion: z.boolean().optional(),\n isActive: z.boolean().optional(),\n})\n\nexport const priceKindUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(priceKindCreateSchema.partial())\n\nexport const priceCreateSchema = scoped.extend({\n variantId: uuid().optional(),\n productId: uuid().optional(),\n offerId: uuid().optional(),\n currencyCode: currencyCodeSchema,\n priceKindId: uuid(),\n minQuantity: z.coerce.number().int().min(1).optional(),\n maxQuantity: z.coerce.number().int().min(1).optional(),\n unitPriceNet: catalogPriceAmountSchema.optional(),\n unitPriceGross: catalogPriceAmountSchema.optional(),\n taxRate: z.coerce.number().min(0).max(100).optional(),\n taxRateId: uuid().nullable().optional(),\n channelId: uuid().optional(),\n userId: uuid().optional(),\n userGroupId: uuid().optional(),\n customerId: uuid().optional(),\n customerGroupId: uuid().optional(),\n metadata: metadataSchema,\n startsAt: z.coerce.date().optional(),\n endsAt: z.coerce.date().optional(),\n})\n\nexport const priceUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(priceCreateSchema.partial())\n\nexport const categoryCreateSchema = scoped.extend({\n name: z.string().trim().min(1).max(255),\n slug: slugSchema.optional().nullable(),\n description: z.string().trim().max(2000).optional(),\n parentId: uuid().optional().nullable(),\n isActive: z.boolean().optional(),\n})\n\nexport const categoryUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(categoryCreateSchema.partial())\n\nexport const productUnitConversionCreateSchema = scoped.extend({\n productId: uuid(),\n unitCode: z.string().trim().min(1).max(50),\n toBaseFactor: z.coerce.number().positive().max(1_000_000),\n sortOrder: z.coerce.number().int().optional(),\n isActive: z.boolean().optional(),\n metadata: metadataSchema,\n})\n\nexport const productUnitConversionUpdateSchema = z\n .object({\n id: uuid(),\n })\n .merge(productUnitConversionCreateSchema.omit({ productId: true }).partial())\n\nexport const productUnitConversionDeleteSchema = scoped.extend({\n id: uuid(),\n})\n\nexport type ProductCreateInput = z.infer<typeof productCreateSchema>\nexport type ProductUpdateInput = z.infer<typeof productUpdateSchema>\nexport type VariantCreateInput = z.infer<typeof variantCreateSchema>\nexport type VariantUpdateInput = z.infer<typeof variantUpdateSchema>\nexport type OptionSchemaTemplateCreateInput = z.infer<typeof optionSchemaTemplateCreateSchema>\nexport type OptionSchemaTemplateUpdateInput = z.infer<typeof optionSchemaTemplateUpdateSchema>\nexport type PriceKindCreateInput = z.infer<typeof priceKindCreateSchema>\nexport type PriceKindUpdateInput = z.infer<typeof priceKindUpdateSchema>\nexport type PriceCreateInput = z.infer<typeof priceCreateSchema>\nexport type PriceUpdateInput = z.infer<typeof priceUpdateSchema>\nexport type CategoryCreateInput = z.infer<typeof categoryCreateSchema>\nexport type CategoryUpdateInput = z.infer<typeof categoryUpdateSchema>\nexport type OfferInput = z.infer<typeof offerInputSchema>\nexport type OfferCreateInput = z.infer<typeof offerCreateSchema>\nexport type OfferUpdateInput = z.infer<typeof offerUpdateSchema>\nexport type ProductUnitConversionCreateInput = z.infer<typeof productUnitConversionCreateSchema>\nexport type ProductUnitConversionUpdateInput = z.infer<typeof productUnitConversionUpdateSchema>\nexport type ProductUnitConversionDeleteInput = z.infer<typeof productUnitConversionDeleteSchema>\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS;AAClB,SAAS,6BAA6B,6BAA6B;AACnE,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,MAAM,OAAO,MAAM,EAAE,OAAO,EAAE,KAAK;AAEnC,MAAM,SAAS,EAAE,OAAO;AAAA,EACtB,gBAAgB,KAAK;AAAA,EACrB,UAAU,KAAK;AACjB,CAAC;AAED,MAAM,eAAe,EAAE,OAAO;AAAA,EAC5B,UAAU,KAAK;AACjB,CAAC;AAED,MAAM,qBAAqB,EACxB,OAAO,EACP,KAAK,EACL,MAAM,cAAc,+CAA+C;AAEtE,MAAM,iBAAiB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,SAAS;AAElE,MAAM,aAAa,EAChB,OAAO,EACP,KAAK,EACL,YAAY,EACZ,MAAM,kBAAkB,oEAAoE,EAC5F,IAAI,GAAG;AAEV,MAAM,eAAe,EAClB,OAAO,EACP,KAAK,EACL,YAAY,EACZ,MAAM,kBAAkB,sEAAsE,EAC9F,IAAI,GAAG;AAEV,MAAM,YAAY,EACf,OAAO,EACP,KAAK,EACL,MAAM,uBAAuB,iEAAiE,EAC9F,IAAI,GAAG;AAEV,MAAM,4BAA4B,EAC/B;AAAA,EACC,EACG,OAAO,EACP,KAAK,EACL,IAAI,CAAC,EACL,IAAI,GAAG;AAAA,EACV,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,GAAG;AAC3B,EACC,SAAS;AAEZ,MAAM,qBAAqB,EAAE,OAAO;AAAA,EAClC,MAAM;AAAA,EACN,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
85
85
|
required: false,
|
|
86
86
|
description: t("exchangeRates.form.field.typeHelp"),
|
|
87
87
|
options: [
|
|
88
|
-
{ value: "", label: t("exchangeRates.form.field.typeNone") },
|
|
89
88
|
{ value: "buy", label: t("exchangeRates.form.field.typeBuy") },
|
|
90
89
|
{ value: "sell", label: t("exchangeRates.form.field.typeSell") }
|
|
91
90
|
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/currencies/lib/exchangeRateFormConfig.ts"],
|
|
4
|
-
"sourcesContent": ["import type { CrudFormGroup, CrudFieldOption } from '@open-mercato/ui/backend/CrudForm'\nimport type { ApiCallResult } from '@open-mercato/ui/backend/utils/apiCall'\nimport { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'\n\nexport type CurrencyOption = {\n id: string\n code: string\n name: string\n isActive: boolean\n}\n\ntype ApiCallFn = <T>(input: RequestInfo | URL, init?: RequestInit) => Promise<ApiCallResult<T>>\n\nexport async function loadCurrencyOptions(\n apiCallFn: ApiCallFn,\n query?: string,\n): Promise<CrudFieldOption[]> {\n try {\n const params = new URLSearchParams()\n if (query) {\n params.set('search', query)\n }\n params.set('isActive', 'true')\n params.set('pageSize', '100')\n\n const call = await apiCallFn<{ items: CurrencyOption[] }>(\n `/api/currencies/currencies?${params.toString()}`\n )\n\n if (call.ok && call.result?.items) {\n return call.result.items.map((c) => ({\n value: c.code,\n label: c.code,\n }))\n }\n } catch (error) {\n console.error('Failed to load currencies:', error)\n }\n return []\n}\n\nexport function exchangeRateGroups(\n t: (key: string) => string,\n loadOptions: (query?: string) => Promise<CrudFieldOption[]>,\n): CrudFormGroup[] {\n return [\n {\n id: 'rate-details',\n column: 1,\n fields: [\n {\n id: 'fromCurrencyCode',\n type: 'combobox',\n label: t('exchangeRates.form.field.fromCurrency'),\n placeholder: t('exchangeRates.form.field.fromCurrencyPlaceholder'),\n required: true,\n loadOptions,\n allowCustomValues: false,\n description: t('exchangeRates.form.field.fromCurrencyHelp'),\n },\n {\n id: 'toCurrencyCode',\n type: 'combobox',\n label: t('exchangeRates.form.field.toCurrency'),\n placeholder: t('exchangeRates.form.field.toCurrencyPlaceholder'),\n required: true,\n loadOptions,\n allowCustomValues: false,\n description: t('exchangeRates.form.field.toCurrencyHelp'),\n },\n {\n id: 'rate',\n type: 'number',\n label: t('exchangeRates.form.field.rate'),\n placeholder: '1.00000000',\n required: true,\n description: t('exchangeRates.form.field.rateHelp'),\n },\n {\n id: 'date',\n type: 'datetime-local',\n label: t('exchangeRates.form.field.date'),\n required: true,\n description: t('exchangeRates.form.field.dateHelp'),\n },\n ],\n },\n {\n id: 'metadata',\n column: 2,\n title: t('exchangeRates.form.group.metadata'),\n fields: [\n {\n id: 'source',\n type: 'text',\n label: t('exchangeRates.form.field.source'),\n placeholder: t('exchangeRates.form.field.sourcePlaceholder'),\n required: true,\n description: t('exchangeRates.form.field.sourceHelp'),\n },\n {\n id: 'type',\n type: 'select',\n label: t('exchangeRates.form.field.type'),\n placeholder: t('exchangeRates.form.field.typePlaceholder'),\n required: false,\n description: t('exchangeRates.form.field.typeHelp'),\n options: [\n { value: '
|
|
5
|
-
"mappings": "AAEA,SAAS,2BAA2B;AAWpC,eAAsB,oBACpB,WACA,OAC4B;AAC5B,MAAI;AACF,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,OAAO;AACT,aAAO,IAAI,UAAU,KAAK;AAAA,IAC5B;AACA,WAAO,IAAI,YAAY,MAAM;AAC7B,WAAO,IAAI,YAAY,KAAK;AAE5B,UAAM,OAAO,MAAM;AAAA,MACjB,8BAA8B,OAAO,SAAS,CAAC;AAAA,IACjD;AAEA,QAAI,KAAK,MAAM,KAAK,QAAQ,OAAO;AACjC,aAAO,KAAK,OAAO,MAAM,IAAI,CAAC,OAAO;AAAA,QACnC,OAAO,EAAE;AAAA,QACT,OAAO,EAAE;AAAA,MACX,EAAE;AAAA,IACJ;AAAA,EACF,SAAS,OAA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,EAAE,+BAA+B;AAAA,UACxC,aAAa,EAAE,0CAA0C;AAAA,UACzD,UAAU;AAAA,UACV,aAAa,EAAE,mCAAmC;AAAA,UAClD,SAAS;AAAA,YACP,EAAE,OAAO,
|
|
4
|
+
"sourcesContent": ["import type { CrudFormGroup, CrudFieldOption } from '@open-mercato/ui/backend/CrudForm'\nimport type { ApiCallResult } from '@open-mercato/ui/backend/utils/apiCall'\nimport { createCrudFormError } from '@open-mercato/ui/backend/utils/serverErrors'\n\nexport type CurrencyOption = {\n id: string\n code: string\n name: string\n isActive: boolean\n}\n\ntype ApiCallFn = <T>(input: RequestInfo | URL, init?: RequestInit) => Promise<ApiCallResult<T>>\n\nexport async function loadCurrencyOptions(\n apiCallFn: ApiCallFn,\n query?: string,\n): Promise<CrudFieldOption[]> {\n try {\n const params = new URLSearchParams()\n if (query) {\n params.set('search', query)\n }\n params.set('isActive', 'true')\n params.set('pageSize', '100')\n\n const call = await apiCallFn<{ items: CurrencyOption[] }>(\n `/api/currencies/currencies?${params.toString()}`\n )\n\n if (call.ok && call.result?.items) {\n return call.result.items.map((c) => ({\n value: c.code,\n label: c.code,\n }))\n }\n } catch (error) {\n console.error('Failed to load currencies:', error)\n }\n return []\n}\n\nexport function exchangeRateGroups(\n t: (key: string) => string,\n loadOptions: (query?: string) => Promise<CrudFieldOption[]>,\n): CrudFormGroup[] {\n return [\n {\n id: 'rate-details',\n column: 1,\n fields: [\n {\n id: 'fromCurrencyCode',\n type: 'combobox',\n label: t('exchangeRates.form.field.fromCurrency'),\n placeholder: t('exchangeRates.form.field.fromCurrencyPlaceholder'),\n required: true,\n loadOptions,\n allowCustomValues: false,\n description: t('exchangeRates.form.field.fromCurrencyHelp'),\n },\n {\n id: 'toCurrencyCode',\n type: 'combobox',\n label: t('exchangeRates.form.field.toCurrency'),\n placeholder: t('exchangeRates.form.field.toCurrencyPlaceholder'),\n required: true,\n loadOptions,\n allowCustomValues: false,\n description: t('exchangeRates.form.field.toCurrencyHelp'),\n },\n {\n id: 'rate',\n type: 'number',\n label: t('exchangeRates.form.field.rate'),\n placeholder: '1.00000000',\n required: true,\n description: t('exchangeRates.form.field.rateHelp'),\n },\n {\n id: 'date',\n type: 'datetime-local',\n label: t('exchangeRates.form.field.date'),\n required: true,\n description: t('exchangeRates.form.field.dateHelp'),\n },\n ],\n },\n {\n id: 'metadata',\n column: 2,\n title: t('exchangeRates.form.group.metadata'),\n fields: [\n {\n id: 'source',\n type: 'text',\n label: t('exchangeRates.form.field.source'),\n placeholder: t('exchangeRates.form.field.sourcePlaceholder'),\n required: true,\n description: t('exchangeRates.form.field.sourceHelp'),\n },\n {\n id: 'type',\n type: 'select',\n label: t('exchangeRates.form.field.type'),\n placeholder: t('exchangeRates.form.field.typePlaceholder'),\n required: false,\n description: t('exchangeRates.form.field.typeHelp'),\n options: [\n { value: 'buy', label: t('exchangeRates.form.field.typeBuy') },\n { value: 'sell', label: t('exchangeRates.form.field.typeSell') },\n ],\n },\n {\n id: 'isActive',\n type: 'checkbox',\n label: t('exchangeRates.form.field.isActive'),\n },\n ],\n },\n ]\n}\n\nexport function validateExchangeRateForm(\n values: Record<string, unknown>,\n t: (key: string) => string,\n): { fromCode: string; toCode: string; rate: number; date: Date; source: string } {\n const fromCode = String(values.fromCurrencyCode || '').trim().toUpperCase()\n const toCode = String(values.toCurrencyCode || '').trim().toUpperCase()\n\n if (!/^[A-Z]{3}$/.test(fromCode)) {\n throw createCrudFormError(t('exchangeRates.form.errors.fromCurrencyFormat'), {\n fromCurrencyCode: t('exchangeRates.form.errors.currencyCodeFormat'),\n })\n }\n\n if (!/^[A-Z]{3}$/.test(toCode)) {\n throw createCrudFormError(t('exchangeRates.form.errors.toCurrencyFormat'), {\n toCurrencyCode: t('exchangeRates.form.errors.currencyCodeFormat'),\n })\n }\n\n if (fromCode === toCode) {\n throw createCrudFormError(t('exchangeRates.form.errors.sameCurrency'), {\n toCurrencyCode: t('exchangeRates.form.errors.sameCurrency'),\n })\n }\n\n const rate = parseFloat(String(values.rate || '0'))\n if (isNaN(rate) || rate <= 0) {\n throw createCrudFormError(t('exchangeRates.form.errors.invalidRate'), {\n rate: t('exchangeRates.form.errors.invalidRate'),\n })\n }\n\n const date = values.date ? new Date(String(values.date)) : null\n\n if (!date || isNaN(date.getTime())) {\n throw createCrudFormError(t('exchangeRates.form.errors.invalidDate'), {\n date: t('exchangeRates.form.errors.invalidDate'),\n })\n }\n\n const source = String(values.source || '').trim()\n if (!source || source.length < 2) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceTooShort'), {\n source: t('exchangeRates.form.errors.sourceTooShort'),\n })\n }\n if (source.length > 50) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceTooLong'), {\n source: t('exchangeRates.form.errors.sourceTooLong'),\n })\n }\n if (!/^[a-zA-Z0-9\\s\\-_]+$/.test(source)) {\n throw createCrudFormError(t('exchangeRates.form.errors.sourceInvalidFormat'), {\n source: t('exchangeRates.form.errors.sourceInvalidFormat'),\n })\n }\n\n return { fromCode, toCode, rate, date, source }\n}\n\nexport function buildExchangeRatePayload(values: Record<string, unknown>, validated: {\n fromCode: string\n toCode: string\n rate: number\n date: Date\n source: string\n}) {\n return {\n fromCurrencyCode: validated.fromCode,\n toCurrencyCode: validated.toCode,\n rate: validated.rate.toFixed(8),\n date: validated.date.toISOString(),\n source: validated.source,\n type: values.type && values.type !== '' ? values.type : null,\n isActive: values.isActive !== false,\n }\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,2BAA2B;AAWpC,eAAsB,oBACpB,WACA,OAC4B;AAC5B,MAAI;AACF,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,OAAO;AACT,aAAO,IAAI,UAAU,KAAK;AAAA,IAC5B;AACA,WAAO,IAAI,YAAY,MAAM;AAC7B,WAAO,IAAI,YAAY,KAAK;AAE5B,UAAM,OAAO,MAAM;AAAA,MACjB,8BAA8B,OAAO,SAAS,CAAC;AAAA,IACjD;AAEA,QAAI,KAAK,MAAM,KAAK,QA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ANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/core",
|
|
3
|
-
"version": "0.4.9-develop-
|
|
3
|
+
"version": "0.4.9-develop-d1d38e26fb",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -217,10 +217,10 @@
|
|
|
217
217
|
"semver": "^7.6.3"
|
|
218
218
|
},
|
|
219
219
|
"peerDependencies": {
|
|
220
|
-
"@open-mercato/shared": "0.4.9-develop-
|
|
220
|
+
"@open-mercato/shared": "0.4.9-develop-d1d38e26fb"
|
|
221
221
|
},
|
|
222
222
|
"devDependencies": {
|
|
223
|
-
"@open-mercato/shared": "0.4.9-develop-
|
|
223
|
+
"@open-mercato/shared": "0.4.9-develop-d1d38e26fb",
|
|
224
224
|
"@testing-library/dom": "^10.4.1",
|
|
225
225
|
"@testing-library/jest-dom": "^6.9.1",
|
|
226
226
|
"@testing-library/react": "^16.3.1",
|
|
@@ -67,8 +67,13 @@ import {
|
|
|
67
67
|
sanitizeProductWeight,
|
|
68
68
|
updateDimensionValue,
|
|
69
69
|
updateWeightValue,
|
|
70
|
+
isConfigurableProductType,
|
|
70
71
|
} from "@open-mercato/core/modules/catalog/components/products/productForm";
|
|
71
|
-
import
|
|
72
|
+
import {
|
|
73
|
+
CATALOG_PRODUCT_TYPES,
|
|
74
|
+
type CatalogProductOptionSchema,
|
|
75
|
+
type CatalogProductType,
|
|
76
|
+
} from "@open-mercato/core/modules/catalog/data/types";
|
|
72
77
|
import { MetadataEditor } from "@open-mercato/core/modules/catalog/components/products/MetadataEditor";
|
|
73
78
|
import {
|
|
74
79
|
buildAttachmentImageUrl,
|
|
@@ -571,6 +576,14 @@ export default function EditCatalogProductPage({
|
|
|
571
576
|
title: typeof record.title === "string" ? record.title : "",
|
|
572
577
|
subtitle: typeof record.subtitle === "string" ? record.subtitle : "",
|
|
573
578
|
handle: typeof record.handle === "string" ? record.handle : "",
|
|
579
|
+
sku: typeof record.sku === "string" ? record.sku : "",
|
|
580
|
+
productType: (
|
|
581
|
+
typeof record.product_type === "string"
|
|
582
|
+
? record.product_type
|
|
583
|
+
: typeof record.productType === "string"
|
|
584
|
+
? record.productType
|
|
585
|
+
: "simple"
|
|
586
|
+
) as CatalogProductType,
|
|
574
587
|
description:
|
|
575
588
|
typeof record.description === "string" ? record.description : "",
|
|
576
589
|
useMarkdown: Boolean(metadata.__useMarkdown),
|
|
@@ -855,6 +868,7 @@ export default function EditCatalogProductPage({
|
|
|
855
868
|
: [],
|
|
856
869
|
defaultMediaId: parsed.data.defaultMediaId ?? null,
|
|
857
870
|
defaultMediaUrl: parsed.data.defaultMediaUrl ?? "",
|
|
871
|
+
productType: (parsed.data.productType ?? "simple") as CatalogProductType,
|
|
858
872
|
hasVariants: parsed.data.hasVariants ?? false,
|
|
859
873
|
options: Array.isArray(parsed.data.options) ? parsed.data.options : [],
|
|
860
874
|
variants: Array.isArray(parsed.data.variants)
|
|
@@ -1025,9 +1039,13 @@ export default function EditCatalogProductPage({
|
|
|
1025
1039
|
subtitle: values.subtitle?.trim() || undefined,
|
|
1026
1040
|
description,
|
|
1027
1041
|
handle,
|
|
1042
|
+
sku: values.sku?.trim() || null,
|
|
1043
|
+
productType: values.productType || "simple",
|
|
1028
1044
|
taxRateId: values.taxRateId ?? null,
|
|
1029
1045
|
taxRate: productTaxRateValue ?? null,
|
|
1030
|
-
isConfigurable:
|
|
1046
|
+
isConfigurable: isConfigurableProductType(
|
|
1047
|
+
values.productType || "simple",
|
|
1048
|
+
),
|
|
1031
1049
|
metadata,
|
|
1032
1050
|
dimensions,
|
|
1033
1051
|
weightValue: weight?.value ?? null,
|
|
@@ -2287,6 +2305,77 @@ function ProductMetaSection({
|
|
|
2287
2305
|
) : null}
|
|
2288
2306
|
</div>
|
|
2289
2307
|
|
|
2308
|
+
<div className="space-y-2">
|
|
2309
|
+
<Label>{t("catalog.products.form.sku", "SKU")}</Label>
|
|
2310
|
+
<Input
|
|
2311
|
+
value={values.sku}
|
|
2312
|
+
onChange={(event) => setValue("sku", event.target.value)}
|
|
2313
|
+
placeholder={t(
|
|
2314
|
+
"catalog.products.create.placeholders.sku",
|
|
2315
|
+
"e.g., PROD-001",
|
|
2316
|
+
)}
|
|
2317
|
+
className="font-mono"
|
|
2318
|
+
/>
|
|
2319
|
+
<p className="text-xs text-muted-foreground">
|
|
2320
|
+
{t(
|
|
2321
|
+
"catalog.products.create.skuHelp",
|
|
2322
|
+
"Unique product identifier. Letters, numbers, hyphens, underscores, periods.",
|
|
2323
|
+
)}
|
|
2324
|
+
</p>
|
|
2325
|
+
{errors.sku ? (
|
|
2326
|
+
<p className="text-xs text-red-600">{errors.sku}</p>
|
|
2327
|
+
) : null}
|
|
2328
|
+
</div>
|
|
2329
|
+
|
|
2330
|
+
<div className="space-y-2">
|
|
2331
|
+
<Label>
|
|
2332
|
+
{t("catalog.products.form.productType", "Product type")}
|
|
2333
|
+
</Label>
|
|
2334
|
+
<select
|
|
2335
|
+
className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
2336
|
+
value={values.productType || "simple"}
|
|
2337
|
+
onChange={(event) => {
|
|
2338
|
+
const nextType = event.target.value;
|
|
2339
|
+
setValue("productType", nextType);
|
|
2340
|
+
const nextIsConfigurable =
|
|
2341
|
+
isConfigurableProductType(nextType);
|
|
2342
|
+
if (nextIsConfigurable && !values.hasVariants) {
|
|
2343
|
+
setValue("hasVariants", true);
|
|
2344
|
+
} else if (
|
|
2345
|
+
!nextIsConfigurable &&
|
|
2346
|
+
values.hasVariants
|
|
2347
|
+
) {
|
|
2348
|
+
setValue("hasVariants", false);
|
|
2349
|
+
}
|
|
2350
|
+
}}
|
|
2351
|
+
>
|
|
2352
|
+
{CATALOG_PRODUCT_TYPES.map((type) => {
|
|
2353
|
+
const isDisabled =
|
|
2354
|
+
type === "bundle" || type === "grouped";
|
|
2355
|
+
return (
|
|
2356
|
+
<option
|
|
2357
|
+
key={type}
|
|
2358
|
+
value={type}
|
|
2359
|
+
disabled={isDisabled}
|
|
2360
|
+
>
|
|
2361
|
+
{t(
|
|
2362
|
+
`catalog.products.types.${type}`,
|
|
2363
|
+
type,
|
|
2364
|
+
)}
|
|
2365
|
+
{isDisabled
|
|
2366
|
+
? ` (${t("common.comingSoon", "Coming soon")})`
|
|
2367
|
+
: ""}
|
|
2368
|
+
</option>
|
|
2369
|
+
);
|
|
2370
|
+
})}
|
|
2371
|
+
</select>
|
|
2372
|
+
{errors.productType ? (
|
|
2373
|
+
<p className="text-xs text-red-600">
|
|
2374
|
+
{errors.productType}
|
|
2375
|
+
</p>
|
|
2376
|
+
) : null}
|
|
2377
|
+
</div>
|
|
2378
|
+
|
|
2290
2379
|
<div className="space-y-2">
|
|
2291
2380
|
<div className="flex items-center justify-between gap-2">
|
|
2292
2381
|
<Label>
|
|
@@ -68,7 +68,9 @@ import {
|
|
|
68
68
|
sanitizeProductWeight,
|
|
69
69
|
updateDimensionValue,
|
|
70
70
|
updateWeightValue,
|
|
71
|
+
isConfigurableProductType,
|
|
71
72
|
} from "@open-mercato/core/modules/catalog/components/products/productForm";
|
|
73
|
+
import { CATALOG_PRODUCT_TYPES } from "@open-mercato/core/modules/catalog/data/types";
|
|
72
74
|
import {
|
|
73
75
|
buildAttachmentImageUrl,
|
|
74
76
|
slugifyAttachmentFileName,
|
|
@@ -131,6 +133,8 @@ const STEP_FIELD_MATCHERS: Record<
|
|
|
131
133
|
> = {
|
|
132
134
|
general: [
|
|
133
135
|
matchField("title"),
|
|
136
|
+
matchField("sku"),
|
|
137
|
+
matchField("productType"),
|
|
134
138
|
matchField("description"),
|
|
135
139
|
matchField("mediaItems"),
|
|
136
140
|
matchField("mediaDraftId"),
|
|
@@ -520,9 +524,13 @@ export default function CreateCatalogProductPage() {
|
|
|
520
524
|
subtitle: formValues.subtitle?.trim() || undefined,
|
|
521
525
|
description,
|
|
522
526
|
handle,
|
|
527
|
+
sku: formValues.sku?.trim() || undefined,
|
|
528
|
+
productType: formValues.productType || "simple",
|
|
523
529
|
taxRateId: formValues.taxRateId ?? null,
|
|
524
530
|
taxRate: productTaxRate ?? null,
|
|
525
|
-
isConfigurable:
|
|
531
|
+
isConfigurable: isConfigurableProductType(
|
|
532
|
+
formValues.productType || "simple",
|
|
533
|
+
),
|
|
526
534
|
defaultMediaId: defaultMediaId ?? undefined,
|
|
527
535
|
defaultMediaUrl: defaultMediaUrl ?? undefined,
|
|
528
536
|
dimensions,
|
|
@@ -1438,9 +1446,25 @@ function ProductBuilder({
|
|
|
1438
1446
|
type="checkbox"
|
|
1439
1447
|
className="h-4 w-4 rounded border"
|
|
1440
1448
|
checked={values.hasVariants}
|
|
1441
|
-
onChange={(event) =>
|
|
1442
|
-
|
|
1443
|
-
|
|
1449
|
+
onChange={(event) => {
|
|
1450
|
+
const checked = event.target.checked;
|
|
1451
|
+
setValue("hasVariants", checked);
|
|
1452
|
+
if (
|
|
1453
|
+
checked &&
|
|
1454
|
+
!isConfigurableProductType(
|
|
1455
|
+
values.productType || "simple",
|
|
1456
|
+
)
|
|
1457
|
+
) {
|
|
1458
|
+
setValue("productType", "configurable");
|
|
1459
|
+
} else if (
|
|
1460
|
+
!checked &&
|
|
1461
|
+
isConfigurableProductType(
|
|
1462
|
+
values.productType || "simple",
|
|
1463
|
+
)
|
|
1464
|
+
) {
|
|
1465
|
+
setValue("productType", "simple");
|
|
1466
|
+
}
|
|
1467
|
+
}}
|
|
1444
1468
|
/>
|
|
1445
1469
|
{t(
|
|
1446
1470
|
"catalog.products.create.variantsBuilder.toggle",
|
|
@@ -1914,6 +1938,77 @@ function ProductMetaSection({
|
|
|
1914
1938
|
) : null}
|
|
1915
1939
|
</div>
|
|
1916
1940
|
|
|
1941
|
+
<div className="space-y-2">
|
|
1942
|
+
<Label>{t("catalog.products.form.sku", "SKU")}</Label>
|
|
1943
|
+
<Input
|
|
1944
|
+
value={values.sku}
|
|
1945
|
+
onChange={(event) => setValue("sku", event.target.value)}
|
|
1946
|
+
placeholder={t(
|
|
1947
|
+
"catalog.products.create.placeholders.sku",
|
|
1948
|
+
"e.g., PROD-001",
|
|
1949
|
+
)}
|
|
1950
|
+
className="font-mono"
|
|
1951
|
+
/>
|
|
1952
|
+
<p className="text-xs text-muted-foreground">
|
|
1953
|
+
{t(
|
|
1954
|
+
"catalog.products.create.skuHelp",
|
|
1955
|
+
"Unique product identifier. Letters, numbers, hyphens, underscores, periods.",
|
|
1956
|
+
)}
|
|
1957
|
+
</p>
|
|
1958
|
+
{errors.sku ? (
|
|
1959
|
+
<p className="text-xs text-red-600">{errors.sku}</p>
|
|
1960
|
+
) : null}
|
|
1961
|
+
</div>
|
|
1962
|
+
|
|
1963
|
+
<div className="space-y-2">
|
|
1964
|
+
<Label>
|
|
1965
|
+
{t("catalog.products.form.productType", "Product type")}
|
|
1966
|
+
</Label>
|
|
1967
|
+
<select
|
|
1968
|
+
className="w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
1969
|
+
value={values.productType || "simple"}
|
|
1970
|
+
onChange={(event) => {
|
|
1971
|
+
const nextType = event.target.value;
|
|
1972
|
+
setValue("productType", nextType);
|
|
1973
|
+
const nextIsConfigurable =
|
|
1974
|
+
isConfigurableProductType(nextType);
|
|
1975
|
+
if (nextIsConfigurable && !values.hasVariants) {
|
|
1976
|
+
setValue("hasVariants", true);
|
|
1977
|
+
} else if (
|
|
1978
|
+
!nextIsConfigurable &&
|
|
1979
|
+
values.hasVariants
|
|
1980
|
+
) {
|
|
1981
|
+
setValue("hasVariants", false);
|
|
1982
|
+
}
|
|
1983
|
+
}}
|
|
1984
|
+
>
|
|
1985
|
+
{CATALOG_PRODUCT_TYPES.map((type) => {
|
|
1986
|
+
const isDisabled =
|
|
1987
|
+
type === "bundle" || type === "grouped";
|
|
1988
|
+
return (
|
|
1989
|
+
<option
|
|
1990
|
+
key={type}
|
|
1991
|
+
value={type}
|
|
1992
|
+
disabled={isDisabled}
|
|
1993
|
+
>
|
|
1994
|
+
{t(
|
|
1995
|
+
`catalog.products.types.${type}`,
|
|
1996
|
+
type,
|
|
1997
|
+
)}
|
|
1998
|
+
{isDisabled
|
|
1999
|
+
? ` (${t("common.comingSoon", "Coming soon")})`
|
|
2000
|
+
: ""}
|
|
2001
|
+
</option>
|
|
2002
|
+
);
|
|
2003
|
+
})}
|
|
2004
|
+
</select>
|
|
2005
|
+
{errors.productType ? (
|
|
2006
|
+
<p className="text-xs text-red-600">
|
|
2007
|
+
{errors.productType}
|
|
2008
|
+
</p>
|
|
2009
|
+
) : null}
|
|
2010
|
+
</div>
|
|
2011
|
+
|
|
1917
2012
|
<div className="space-y-2">
|
|
1918
2013
|
<div className="flex items-center justify-between gap-2">
|
|
1919
2014
|
<Label>
|