sku and item fix

This commit is contained in:
2026-08-11 21:55:04 +05:30
parent 15ddac178c
commit a7ba3d3e04
15 changed files with 557 additions and 96 deletions
@@ -81,10 +81,14 @@ export function validateItemTypeName(name: string): Record<string, string> {
}
export function validateVariantItemForm(input: {
productName: string
categoryId: number | null
hasVariants: boolean
}): Record<string, string> {
const errors: Record<string, string> = {}
// Required: it names every generated item and leads its SKU, and neither reads sensibly
// when derived from the category instead ("Beverages - 500ml").
if (!input.productName.trim()) errors.productName = "Enter a product name"
if (!input.categoryId) errors.categoryId = "Select a category"
if (!input.hasVariants) errors.variants = "Check at least one variant category and add its values"
return errors
@@ -95,6 +99,29 @@ export function validateVariantItemForm(input: {
* (docs/20 §3.1). Returns a map keyed by variant key → message; empty when valid.
* In "stock" mode there is nothing to validate (prices are sent as null).
*/
/**
* Belt-and-braces sweep over the generated variants: each one's resolved content pair must be
* whole or wholly absent. It should never fire — `addValue` rejects a half or duplicate pair at
* entry — so it exists to catch stale state, not to guide the user.
*
* Keyed by variant key to mirror {@link validateVariantPrices}, but surfaced as ONE form-level
* message: content is *derived*, so unlike a price there is no per-row control to attach an
* error to.
*/
export function validateVariantContent(
variantKeys: string[],
contentFor: (key: string) => { qty: string; unit: string | null },
): Record<string, string> {
const errors: Record<string, string> = {}
for (const key of variantKeys) {
const { qty, unit } = contentFor(key)
const pair = contentPairErrors(qty, unit)
const message = pair.contentQty ?? pair.contentUnit
if (message) errors[key] = message
}
return errors
}
export function validateVariantPrices(
variantKeys: string[],
priceFor: (key: string) => string,