@voyantjs/pricing-ui 0.16.0 → 0.17.0

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.
Files changed (66) hide show
  1. package/README.md +11 -0
  2. package/dist/components/cancellation-policy-combobox.d.ts +1 -1
  3. package/dist/components/cancellation-policy-combobox.d.ts.map +1 -1
  4. package/dist/components/cancellation-policy-combobox.js +6 -4
  5. package/dist/components/cancellation-policy-rule-dialog.d.ts.map +1 -1
  6. package/dist/components/cancellation-policy-rule-dialog.js +23 -15
  7. package/dist/components/dropoff-price-rule-dialog.d.ts.map +1 -1
  8. package/dist/components/dropoff-price-rule-dialog.js +32 -15
  9. package/dist/components/extra-price-rule-dialog.d.ts.map +1 -1
  10. package/dist/components/extra-price-rule-dialog.js +28 -14
  11. package/dist/components/option-price-rule-combobox.d.ts +1 -1
  12. package/dist/components/option-price-rule-combobox.d.ts.map +1 -1
  13. package/dist/components/option-price-rule-combobox.js +6 -4
  14. package/dist/components/option-price-rule-dialog.d.ts.map +1 -1
  15. package/dist/components/option-price-rule-dialog.js +35 -23
  16. package/dist/components/option-start-time-rule-dialog.d.ts.map +1 -1
  17. package/dist/components/option-start-time-rule-dialog.js +33 -14
  18. package/dist/components/option-unit-price-rule-dialog.d.ts.map +1 -1
  19. package/dist/components/option-unit-price-rule-dialog.js +30 -16
  20. package/dist/components/option-unit-tier-dialog.d.ts.map +1 -1
  21. package/dist/components/option-unit-tier-dialog.js +24 -10
  22. package/dist/components/pickup-price-rule-dialog.d.ts.map +1 -1
  23. package/dist/components/pickup-price-rule-dialog.js +29 -13
  24. package/dist/components/price-catalog-combobox.d.ts +1 -1
  25. package/dist/components/price-catalog-combobox.d.ts.map +1 -1
  26. package/dist/components/price-catalog-combobox.js +6 -2
  27. package/dist/components/price-schedule-combobox.d.ts.map +1 -1
  28. package/dist/components/price-schedule-combobox.js +6 -4
  29. package/dist/components/price-schedule-dialog.d.ts.map +1 -1
  30. package/dist/components/price-schedule-dialog.js +26 -15
  31. package/dist/components/pricing-category-combobox.d.ts.map +1 -1
  32. package/dist/components/pricing-category-combobox.js +4 -2
  33. package/dist/components/pricing-category-dependency-dialog.d.ts.map +1 -1
  34. package/dist/components/pricing-category-dependency-dialog.js +5 -1
  35. package/dist/components/pricing-category-dependency-form.d.ts.map +1 -1
  36. package/dist/components/pricing-category-dependency-form.js +17 -8
  37. package/dist/components/pricing-category-dialog.d.ts.map +1 -1
  38. package/dist/components/pricing-category-dialog.js +7 -3
  39. package/dist/components/pricing-category-form.d.ts.map +1 -1
  40. package/dist/components/pricing-category-form.js +20 -13
  41. package/dist/components/pricing-category-list.d.ts.map +1 -1
  42. package/dist/components/pricing-category-list.js +10 -6
  43. package/dist/components/product-combobox.d.ts +1 -1
  44. package/dist/components/product-combobox.d.ts.map +1 -1
  45. package/dist/components/product-combobox.js +6 -2
  46. package/dist/components/product-option-combobox.d.ts.map +1 -1
  47. package/dist/components/product-option-combobox.js +7 -5
  48. package/dist/i18n/en.d.ts +426 -0
  49. package/dist/i18n/en.d.ts.map +1 -0
  50. package/dist/i18n/en.js +425 -0
  51. package/dist/i18n/index.d.ts +5 -0
  52. package/dist/i18n/index.d.ts.map +1 -0
  53. package/dist/i18n/index.js +3 -0
  54. package/dist/i18n/messages.d.ts +391 -0
  55. package/dist/i18n/messages.d.ts.map +1 -0
  56. package/dist/i18n/messages.js +17 -0
  57. package/dist/i18n/provider.d.ts +874 -0
  58. package/dist/i18n/provider.d.ts.map +1 -0
  59. package/dist/i18n/provider.js +44 -0
  60. package/dist/i18n/ro.d.ts +426 -0
  61. package/dist/i18n/ro.d.ts.map +1 -0
  62. package/dist/i18n/ro.js +425 -0
  63. package/dist/index.d.ts +2 -0
  64. package/dist/index.d.ts.map +1 -1
  65. package/dist/index.js +1 -0
  66. package/package.json +25 -9
@@ -7,6 +7,7 @@ import { Loader2 } from "lucide-react";
7
7
  import { useEffect } from "react";
8
8
  import { useForm } from "react-hook-form";
9
9
  import { z } from "zod/v4";
10
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
10
11
  import { OptionPriceRuleCombobox } from "./option-price-rule-combobox";
11
12
  import { PricingCategoryCombobox } from "./pricing-category-combobox";
12
13
  const PRICING_MODES = [
@@ -17,25 +18,31 @@ const PRICING_MODES = [
17
18
  "free",
18
19
  "on_request",
19
20
  ];
20
- const formSchema = z.object({
21
- optionPriceRuleId: z.string().min(1, "Option price rule is required"),
22
- optionId: z.string().min(1, "Option ID is required"),
23
- unitId: z.string().min(1, "Unit ID is required"),
24
- pricingCategoryId: z.string().optional().nullable(),
25
- pricingMode: z.enum(PRICING_MODES),
26
- sellAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
27
- costAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
28
- minQuantity: z.coerce.number().int().min(0).optional().or(z.literal("")).nullable(),
29
- maxQuantity: z.coerce.number().int().min(0).optional().or(z.literal("")).nullable(),
30
- sortOrder: z.coerce.number().int(),
31
- active: z.boolean(),
32
- notes: z.string().optional().nullable(),
33
- });
21
+ function createFormSchema(messages) {
22
+ return z.object({
23
+ optionPriceRuleId: z
24
+ .string()
25
+ .min(1, messages.optionUnitPriceRuleDialog.validation.optionPriceRuleRequired),
26
+ optionId: z.string().min(1, messages.optionUnitPriceRuleDialog.validation.optionIdRequired),
27
+ unitId: z.string().min(1, messages.optionUnitPriceRuleDialog.validation.unitIdRequired),
28
+ pricingCategoryId: z.string().optional().nullable(),
29
+ pricingMode: z.enum(PRICING_MODES),
30
+ sellAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
31
+ costAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
32
+ minQuantity: z.coerce.number().int().min(0).optional().or(z.literal("")).nullable(),
33
+ maxQuantity: z.coerce.number().int().min(0).optional().or(z.literal("")).nullable(),
34
+ sortOrder: z.coerce.number().int(),
35
+ active: z.boolean(),
36
+ notes: z.string().optional().nullable(),
37
+ });
38
+ }
34
39
  const toInt = (value) => typeof value === "number" ? value : null;
35
40
  const toCents = (value) => typeof value === "number" ? Math.round(value * 100) : null;
36
41
  export function OptionUnitPriceRuleDialog({ open, onOpenChange, rule, onSuccess }) {
37
42
  const isEditing = !!rule;
38
43
  const { create, update } = useOptionUnitPriceRuleMutation();
44
+ const messages = usePricingUiMessagesOrDefault();
45
+ const formSchema = createFormSchema(messages);
39
46
  const form = useForm({
40
47
  resolver: zodResolver(formSchema),
41
48
  defaultValues: {
@@ -96,8 +103,15 @@ export function OptionUnitPriceRuleDialog({ open, onOpenChange, rule, onSuccess
96
103
  onOpenChange(false);
97
104
  };
98
105
  const isSubmitting = create.isPending || update.isPending;
99
- return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { size: "lg", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: isEditing ? "Edit Option Unit Price Rule" : "Add Option Unit Price Rule" }) }), _jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [_jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Option price rule" }), _jsx(OptionPriceRuleCombobox, { value: form.watch("optionPriceRuleId"), onChange: (value) => form.setValue("optionPriceRuleId", value ?? "", {
106
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { size: "lg", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: isEditing
107
+ ? messages.optionUnitPriceRuleDialog.titles.edit
108
+ : messages.optionUnitPriceRuleDialog.titles.create }) }), _jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [_jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.optionPriceRule }), _jsx(OptionPriceRuleCombobox, { value: form.watch("optionPriceRuleId"), onChange: (value) => form.setValue("optionPriceRuleId", value ?? "", {
100
109
  shouldDirty: true,
101
110
  shouldValidate: true,
102
- }), disabled: isEditing }), form.formState.errors.optionPriceRuleId ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.optionPriceRuleId.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Option ID" }), _jsx(Input, { ...form.register("optionId"), placeholder: "popt_\u2026" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Unit ID" }), _jsx(Input, { ...form.register("unitId"), placeholder: "punit_\u2026" })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Pricing category (optional)" }), _jsx(PricingCategoryCombobox, { value: form.watch("pricingCategoryId"), onChange: (value) => form.setValue("pricingCategoryId", value ?? "", { shouldDirty: true }) })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Pricing mode" }), _jsxs(Select, { items: PRICING_MODES.map((x) => ({ label: x.replace(/_/g, " "), value: x })), value: form.watch("pricingMode"), onValueChange: (value) => form.setValue("pricingMode", value), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: PRICING_MODES.map((mode) => (_jsx(SelectItem, { value: mode, className: "capitalize", children: mode.replace(/_/g, " ") }, mode))) })] })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Sell amount" }), _jsx(Input, { ...form.register("sellAmount"), type: "number", step: "0.01", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Cost amount" }), _jsx(Input, { ...form.register("costAmount"), type: "number", step: "0.01", min: "0" })] })] }), _jsxs("div", { className: "grid grid-cols-3 gap-3", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Min quantity" }), _jsx(Input, { ...form.register("minQuantity"), type: "number", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Max quantity" }), _jsx(Input, { ...form.register("maxQuantity"), type: "number", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Sort order" }), _jsx(Input, { ...form.register("sortOrder"), type: "number" })] })] }), _jsxs("div", { className: "flex items-center gap-3", children: [_jsx(Switch, { checked: form.watch("active"), onCheckedChange: (checked) => form.setValue("active", checked) }), _jsx(Label, { children: "Active" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Notes" }), _jsx(Textarea, { ...form.register("notes") })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing ? "Save Changes" : "Add Rule"] })] })] })] }) }));
111
+ }), disabled: isEditing }), form.formState.errors.optionPriceRuleId ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.optionPriceRuleId.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.optionId }), _jsx(Input, { ...form.register("optionId"), placeholder: messages.optionUnitPriceRuleDialog.placeholders.optionId })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.unitId }), _jsx(Input, { ...form.register("unitId"), placeholder: messages.optionUnitPriceRuleDialog.placeholders.unitId })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.pricingCategory }), _jsx(PricingCategoryCombobox, { value: form.watch("pricingCategoryId"), onChange: (value) => form.setValue("pricingCategoryId", value ?? "", { shouldDirty: true }), placeholder: messages.optionUnitPriceRuleDialog.placeholders.pricingCategory })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.pricingMode }), _jsxs(Select, { items: PRICING_MODES.map((mode) => ({
112
+ label: messages.common.unitPricingModeLabels[mode],
113
+ value: mode,
114
+ })), value: form.watch("pricingMode"), onValueChange: (value) => form.setValue("pricingMode", value), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: PRICING_MODES.map((mode) => (_jsx(SelectItem, { value: mode, children: messages.common.unitPricingModeLabels[mode] }, mode))) })] })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.sellAmount }), _jsx(Input, { ...form.register("sellAmount"), type: "number", step: "0.01", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.costAmount }), _jsx(Input, { ...form.register("costAmount"), type: "number", step: "0.01", min: "0" })] })] }), _jsxs("div", { className: "grid grid-cols-3 gap-3", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.minQuantity }), _jsx(Input, { ...form.register("minQuantity"), type: "number", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.maxQuantity }), _jsx(Input, { ...form.register("maxQuantity"), type: "number", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.sortOrder }), _jsx(Input, { ...form.register("sortOrder"), type: "number" })] })] }), _jsxs("div", { className: "flex items-center gap-3", children: [_jsx(Switch, { checked: form.watch("active"), onCheckedChange: (checked) => form.setValue("active", checked) }), _jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.active })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitPriceRuleDialog.fields.notes }), _jsx(Textarea, { ...form.register("notes") })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: messages.common.cancel }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing
115
+ ? messages.common.saveChanges
116
+ : messages.optionUnitPriceRuleDialog.actions.create] })] })] })] }) }));
103
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"option-unit-tier-dialog.d.ts","sourceRoot":"","sources":["../../src/components/option-unit-tier-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,oBAAoB,EAA6B,MAAM,yBAAyB,CAAA;AAgC9F,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,IAAI,CAAC,EAAE,oBAAoB,CAAA;IAC3B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,IAAI,CAAA;CACjD,CAAA;AAOD,wBAAgB,oBAAoB,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,2CA0IlF"}
1
+ {"version":3,"file":"option-unit-tier-dialog.d.ts","sourceRoot":"","sources":["../../src/components/option-unit-tier-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,oBAAoB,EAA6B,MAAM,yBAAyB,CAAA;AA0C9F,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,IAAI,CAAC,EAAE,oBAAoB,CAAA;IAC3B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,oBAAoB,KAAK,IAAI,CAAA;CACjD,CAAA;AAOD,wBAAgB,oBAAoB,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,2CAkJlF"}
@@ -7,20 +7,30 @@ import { Loader2 } from "lucide-react";
7
7
  import { useEffect } from "react";
8
8
  import { useForm } from "react-hook-form";
9
9
  import { z } from "zod/v4";
10
- const formSchema = z.object({
11
- optionUnitPriceRuleId: z.string().min(1, "Option unit price rule is required"),
12
- minQuantity: z.coerce.number().int().min(1, "Min quantity must be at least 1"),
13
- maxQuantity: z.coerce.number().int().min(1).optional().or(z.literal("")).nullable(),
14
- sellAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
15
- costAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
16
- active: z.boolean(),
17
- sortOrder: z.coerce.number().int(),
18
- });
10
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
11
+ function createFormSchema(messages) {
12
+ return z.object({
13
+ optionUnitPriceRuleId: z
14
+ .string()
15
+ .min(1, messages.optionUnitTierDialog.validation.optionUnitPriceRuleIdRequired),
16
+ minQuantity: z.coerce
17
+ .number()
18
+ .int()
19
+ .min(1, messages.optionUnitTierDialog.validation.minQuantityMin),
20
+ maxQuantity: z.coerce.number().int().min(1).optional().or(z.literal("")).nullable(),
21
+ sellAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
22
+ costAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
23
+ active: z.boolean(),
24
+ sortOrder: z.coerce.number().int(),
25
+ });
26
+ }
19
27
  const toCents = (value) => typeof value === "number" ? Math.round(value * 100) : null;
20
28
  const toInt = (value) => typeof value === "number" ? value : null;
21
29
  export function OptionUnitTierDialog({ open, onOpenChange, tier, onSuccess }) {
22
30
  const isEditing = !!tier;
23
31
  const { create, update } = useOptionUnitTierMutation();
32
+ const messages = usePricingUiMessagesOrDefault();
33
+ const formSchema = createFormSchema(messages);
24
34
  const form = useForm({
25
35
  resolver: zodResolver(formSchema),
26
36
  defaultValues: {
@@ -74,5 +84,9 @@ export function OptionUnitTierDialog({ open, onOpenChange, tier, onSuccess }) {
74
84
  onOpenChange(false);
75
85
  };
76
86
  const isSubmitting = create.isPending || update.isPending;
77
- return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: isEditing ? "Edit Unit Tier" : "Add Unit Tier" }) }), _jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [_jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Option unit price rule ID" }), _jsx(Input, { ...form.register("optionUnitPriceRuleId"), placeholder: "oupr_\u2026", disabled: isEditing }), form.formState.errors.optionUnitPriceRuleId ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.optionUnitPriceRuleId.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Min quantity" }), _jsx(Input, { ...form.register("minQuantity"), type: "number", min: "1" }), form.formState.errors.minQuantity ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.minQuantity.message })) : null] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Max quantity" }), _jsx(Input, { ...form.register("maxQuantity"), type: "number", min: "1" })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Sell amount" }), _jsx(Input, { ...form.register("sellAmount"), type: "number", step: "0.01", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Cost amount" }), _jsx(Input, { ...form.register("costAmount"), type: "number", step: "0.01", min: "0" })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Sort order" }), _jsx(Input, { ...form.register("sortOrder"), type: "number" })] }), _jsxs("div", { className: "flex items-center gap-3 pt-6", children: [_jsx(Switch, { checked: form.watch("active"), onCheckedChange: (checked) => form.setValue("active", checked) }), _jsx(Label, { children: "Active" })] })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing ? "Save Changes" : "Add Tier"] })] })] })] }) }));
87
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: isEditing
88
+ ? messages.optionUnitTierDialog.titles.edit
89
+ : messages.optionUnitTierDialog.titles.create }) }), _jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [_jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitTierDialog.fields.optionUnitPriceRuleId }), _jsx(Input, { ...form.register("optionUnitPriceRuleId"), placeholder: messages.optionUnitTierDialog.placeholders.optionUnitPriceRuleId, disabled: isEditing }), form.formState.errors.optionUnitPriceRuleId ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.optionUnitPriceRuleId.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitTierDialog.fields.minQuantity }), _jsx(Input, { ...form.register("minQuantity"), type: "number", min: "1" }), form.formState.errors.minQuantity ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.minQuantity.message })) : null] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitTierDialog.fields.maxQuantity }), _jsx(Input, { ...form.register("maxQuantity"), type: "number", min: "1" })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitTierDialog.fields.sellAmount }), _jsx(Input, { ...form.register("sellAmount"), type: "number", step: "0.01", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitTierDialog.fields.costAmount }), _jsx(Input, { ...form.register("costAmount"), type: "number", step: "0.01", min: "0" })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.optionUnitTierDialog.fields.sortOrder }), _jsx(Input, { ...form.register("sortOrder"), type: "number" })] }), _jsxs("div", { className: "flex items-center gap-3 pt-6", children: [_jsx(Switch, { checked: form.watch("active"), onCheckedChange: (checked) => form.setValue("active", checked) }), _jsx(Label, { children: messages.optionUnitTierDialog.fields.active })] })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: messages.common.cancel }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing
90
+ ? messages.common.saveChanges
91
+ : messages.optionUnitTierDialog.actions.create] })] })] })] }) }));
78
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pickup-price-rule-dialog.d.ts","sourceRoot":"","sources":["../../src/components/pickup-price-rule-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAA8B,MAAM,yBAAyB,CAAA;AAmDhG,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,IAAI,CAAC,EAAE,qBAAqB,CAAA;IAC5B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAA;CAClD,CAAA;AAKD,wBAAgB,qBAAqB,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,2CAmKnF"}
1
+ {"version":3,"file":"pickup-price-rule-dialog.d.ts","sourceRoot":"","sources":["../../src/components/pickup-price-rule-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,qBAAqB,EAA8B,MAAM,yBAAyB,CAAA;AAyDhG,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,IAAI,CAAC,EAAE,qBAAqB,CAAA;IAC5B,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAA;CAClD,CAAA;AAKD,wBAAgB,qBAAqB,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,2CAoLnF"}
@@ -7,6 +7,7 @@ import { Loader2 } from "lucide-react";
7
7
  import { useEffect } from "react";
8
8
  import { useForm } from "react-hook-form";
9
9
  import { z } from "zod/v4";
10
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
10
11
  import { OptionPriceRuleCombobox } from "./option-price-rule-combobox";
11
12
  const ADDON_PRICING_MODES = [
12
13
  "included",
@@ -15,21 +16,29 @@ const ADDON_PRICING_MODES = [
15
16
  "on_request",
16
17
  "unavailable",
17
18
  ];
18
- const formSchema = z.object({
19
- optionPriceRuleId: z.string().min(1, "Option price rule is required"),
20
- optionId: z.string().min(1, "Option ID is required"),
21
- pickupPointId: z.string().min(1, "Pickup point is required"),
22
- pricingMode: z.enum(ADDON_PRICING_MODES),
23
- sellAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
24
- costAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
25
- active: z.boolean(),
26
- sortOrder: z.coerce.number().int(),
27
- notes: z.string().optional().nullable(),
28
- });
19
+ function createFormSchema(messages) {
20
+ return z.object({
21
+ optionPriceRuleId: z
22
+ .string()
23
+ .min(1, messages.locationPriceRuleDialog.validation.optionPriceRuleRequired),
24
+ optionId: z.string().min(1, messages.locationPriceRuleDialog.validation.optionIdRequired),
25
+ pickupPointId: z
26
+ .string()
27
+ .min(1, messages.locationPriceRuleDialog.validation.pickupPointIdRequired),
28
+ pricingMode: z.enum(ADDON_PRICING_MODES),
29
+ sellAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
30
+ costAmount: z.coerce.number().min(0).optional().or(z.literal("")).nullable(),
31
+ active: z.boolean(),
32
+ sortOrder: z.coerce.number().int(),
33
+ notes: z.string().optional().nullable(),
34
+ });
35
+ }
29
36
  const toCents = (value) => typeof value === "number" ? Math.round(value * 100) : null;
30
37
  export function PickupPriceRuleDialog({ open, onOpenChange, rule, onSuccess }) {
31
38
  const isEditing = !!rule;
32
39
  const { create, update } = usePickupPriceRuleMutation();
40
+ const messages = usePricingUiMessagesOrDefault();
41
+ const formSchema = createFormSchema(messages);
33
42
  const form = useForm({
34
43
  resolver: zodResolver(formSchema),
35
44
  defaultValues: {
@@ -81,8 +90,15 @@ export function PickupPriceRuleDialog({ open, onOpenChange, rule, onSuccess }) {
81
90
  onOpenChange(false);
82
91
  };
83
92
  const isSubmitting = create.isPending || update.isPending;
84
- return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { size: "lg", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: isEditing ? "Edit Pickup Price Rule" : "Add Pickup Price Rule" }) }), _jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [_jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Option price rule" }), _jsx(OptionPriceRuleCombobox, { value: form.watch("optionPriceRuleId"), onChange: (value) => form.setValue("optionPriceRuleId", value ?? "", {
93
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { size: "lg", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: isEditing
94
+ ? messages.locationPriceRuleDialog.pickup.titles.edit
95
+ : messages.locationPriceRuleDialog.pickup.titles.create }) }), _jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [_jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.locationPriceRuleDialog.fields.optionPriceRule }), _jsx(OptionPriceRuleCombobox, { value: form.watch("optionPriceRuleId"), onChange: (value) => form.setValue("optionPriceRuleId", value ?? "", {
85
96
  shouldDirty: true,
86
97
  shouldValidate: true,
87
- }), disabled: isEditing }), form.formState.errors.optionPriceRuleId ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.optionPriceRuleId.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Option ID" }), _jsx(Input, { ...form.register("optionId"), placeholder: "popt_\u2026" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Pickup point ID" }), _jsx(Input, { ...form.register("pickupPointId"), placeholder: "ppnt_\u2026" })] })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Pricing mode" }), _jsxs(Select, { items: ADDON_PRICING_MODES.map((x) => ({ label: x.replace(/_/g, " "), value: x })), value: form.watch("pricingMode"), onValueChange: (value) => form.setValue("pricingMode", value), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: ADDON_PRICING_MODES.map((mode) => (_jsx(SelectItem, { value: mode, className: "capitalize", children: mode.replace(/_/g, " ") }, mode))) })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Sell amount" }), _jsx(Input, { ...form.register("sellAmount"), type: "number", step: "0.01", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Cost amount" }), _jsx(Input, { ...form.register("costAmount"), type: "number", step: "0.01", min: "0" })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Sort order" }), _jsx(Input, { ...form.register("sortOrder"), type: "number" })] }), _jsxs("div", { className: "flex items-center gap-3 pt-6", children: [_jsx(Switch, { checked: form.watch("active"), onCheckedChange: (checked) => form.setValue("active", checked) }), _jsx(Label, { children: "Active" })] })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Notes" }), _jsx(Textarea, { ...form.register("notes") })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing ? "Save Changes" : "Add Rule"] })] })] })] }) }));
98
+ }), disabled: isEditing }), form.formState.errors.optionPriceRuleId ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.optionPriceRuleId.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.locationPriceRuleDialog.fields.optionId }), _jsx(Input, { ...form.register("optionId"), placeholder: messages.locationPriceRuleDialog.placeholders.optionId })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.locationPriceRuleDialog.fields.pickupPointId }), _jsx(Input, { ...form.register("pickupPointId"), placeholder: messages.locationPriceRuleDialog.placeholders.pickupPointId })] })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.locationPriceRuleDialog.fields.pricingMode }), _jsxs(Select, { items: ADDON_PRICING_MODES.map((mode) => ({
99
+ label: messages.common.addonPricingModeLabels[mode],
100
+ value: mode,
101
+ })), value: form.watch("pricingMode"), onValueChange: (value) => form.setValue("pricingMode", value), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: ADDON_PRICING_MODES.map((mode) => (_jsx(SelectItem, { value: mode, children: messages.common.addonPricingModeLabels[mode] }, mode))) })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.locationPriceRuleDialog.fields.sellAmount }), _jsx(Input, { ...form.register("sellAmount"), type: "number", step: "0.01", min: "0" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.locationPriceRuleDialog.fields.costAmount }), _jsx(Input, { ...form.register("costAmount"), type: "number", step: "0.01", min: "0" })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.locationPriceRuleDialog.fields.sortOrder }), _jsx(Input, { ...form.register("sortOrder"), type: "number" })] }), _jsxs("div", { className: "flex items-center gap-3 pt-6", children: [_jsx(Switch, { checked: form.watch("active"), onCheckedChange: (checked) => form.setValue("active", checked) }), _jsx(Label, { children: messages.locationPriceRuleDialog.fields.active })] })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.locationPriceRuleDialog.fields.notes }), _jsx(Textarea, { ...form.register("notes") })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: messages.common.cancel }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing
102
+ ? messages.locationPriceRuleDialog.actions.saveRule
103
+ : messages.locationPriceRuleDialog.actions.createRule] })] })] })] }) }));
88
104
  }
@@ -4,6 +4,6 @@ type Props = {
4
4
  placeholder?: string;
5
5
  disabled?: boolean;
6
6
  };
7
- export declare function PriceCatalogCombobox({ value, onChange, placeholder, disabled, }: Props): import("react/jsx-runtime").JSX.Element;
7
+ export declare function PriceCatalogCombobox({ value, onChange, placeholder, disabled }: Props): import("react/jsx-runtime").JSX.Element;
8
8
  export {};
9
9
  //# sourceMappingURL=price-catalog-combobox.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"price-catalog-combobox.d.ts","sourceRoot":"","sources":["../../src/components/price-catalog-combobox.tsx"],"names":[],"mappings":"AAYA,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACxC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAID,wBAAgB,oBAAoB,CAAC,EACnC,KAAK,EACL,QAAQ,EACR,WAAsC,EACtC,QAAQ,GACT,EAAE,KAAK,2CAsEP"}
1
+ {"version":3,"file":"price-catalog-combobox.d.ts","sourceRoot":"","sources":["../../src/components/price-catalog-combobox.tsx"],"names":[],"mappings":"AAcA,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACxC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAID,wBAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,KAAK,2CA4ErF"}
@@ -2,8 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { usePriceCatalog, usePriceCatalogs } from "@voyantjs/pricing-react";
3
3
  import { Combobox, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, } from "@voyantjs/ui/components/combobox";
4
4
  import * as React from "react";
5
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
5
6
  const PAGE_SIZE = 25;
6
- export function PriceCatalogCombobox({ value, onChange, placeholder = "Search price catalogs…", disabled, }) {
7
+ export function PriceCatalogCombobox({ value, onChange, placeholder, disabled }) {
8
+ const messages = usePricingUiMessagesOrDefault();
7
9
  const [search, setSearch] = React.useState("");
8
10
  const listQuery = usePriceCatalogs({ search: search || undefined, limit: PAGE_SIZE });
9
11
  const selectedQuery = usePriceCatalog(value, { enabled: !!value });
@@ -36,7 +38,9 @@ export function PriceCatalogCombobox({ value, onChange, placeholder = "Search pr
36
38
  onChange(id);
37
39
  const item = id ? itemMap.get(id) : null;
38
40
  setInputValue(item ? `${item.name} · ${item.code}` : "");
39
- }, children: [_jsx(ComboboxInput, { placeholder: placeholder, showClear: !!value }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: listQuery.isPending || selectedQuery.isPending ? "Loading…" : "No price catalogs found." }), _jsx(ComboboxList, { children: _jsx(ComboboxCollection, { children: (id) => {
41
+ }, children: [_jsx(ComboboxInput, { placeholder: placeholder ?? messages.comboboxes.priceCatalog.placeholder, showClear: !!value }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: listQuery.isPending || selectedQuery.isPending
42
+ ? messages.common.loading
43
+ : messages.comboboxes.priceCatalog.empty }), _jsx(ComboboxList, { children: _jsx(ComboboxCollection, { children: (id) => {
40
44
  const item = itemMap.get(id);
41
45
  if (!item)
42
46
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"price-schedule-combobox.d.ts","sourceRoot":"","sources":["../../src/components/price-schedule-combobox.tsx"],"names":[],"mappings":"AAgBA,KAAK,KAAK,GAAG;IACX,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACxC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAID,wBAAgB,qBAAqB,CAAC,EACpC,cAAc,EACd,KAAK,EACL,QAAQ,EACR,WAAuC,EACvC,QAAQ,GACT,EAAE,KAAK,2CAyEP"}
1
+ {"version":3,"file":"price-schedule-combobox.d.ts","sourceRoot":"","sources":["../../src/components/price-schedule-combobox.tsx"],"names":[],"mappings":"AAkBA,KAAK,KAAK,GAAG;IACX,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACxC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAID,wBAAgB,qBAAqB,CAAC,EACpC,cAAc,EACd,KAAK,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,GACT,EAAE,KAAK,2CA6EP"}
@@ -2,8 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { usePriceSchedule, usePriceSchedules, } from "@voyantjs/pricing-react";
3
3
  import { Combobox, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, } from "@voyantjs/ui/components/combobox";
4
4
  import * as React from "react";
5
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
5
6
  const PAGE_SIZE = 25;
6
- export function PriceScheduleCombobox({ priceCatalogId, value, onChange, placeholder = "Search price schedules…", disabled, }) {
7
+ export function PriceScheduleCombobox({ priceCatalogId, value, onChange, placeholder, disabled, }) {
8
+ const messages = usePricingUiMessagesOrDefault();
7
9
  const [search, setSearch] = React.useState("");
8
10
  const listQuery = usePriceSchedules({
9
11
  priceCatalogId: priceCatalogId || undefined,
@@ -37,9 +39,9 @@ export function PriceScheduleCombobox({ priceCatalogId, value, onChange, placeho
37
39
  const id = next ?? null;
38
40
  onChange(id);
39
41
  setInputValue(id ? (itemMap.get(id)?.name ?? "") : "");
40
- }, children: [_jsx(ComboboxInput, { placeholder: placeholder, showClear: !!value }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: listQuery.isPending || selectedQuery.isPending
41
- ? "Loading…"
42
- : "No price schedules found." }), _jsx(ComboboxList, { children: _jsx(ComboboxCollection, { children: (id) => {
42
+ }, children: [_jsx(ComboboxInput, { placeholder: placeholder ?? messages.comboboxes.priceSchedule.placeholder, showClear: !!value }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: listQuery.isPending || selectedQuery.isPending
43
+ ? messages.common.loading
44
+ : messages.comboboxes.priceSchedule.empty }), _jsx(ComboboxList, { children: _jsx(ComboboxCollection, { children: (id) => {
43
45
  const item = itemMap.get(id);
44
46
  if (!item)
45
47
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"price-schedule-dialog.d.ts","sourceRoot":"","sources":["../../src/components/price-schedule-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,mBAAmB,EAA4B,MAAM,yBAAyB,CAAA;AAuC5F,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,KAAK,IAAI,CAAA;CACpD;AAED,wBAAgB,mBAAmB,CAAC,EAClC,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,SAAS,GACV,EAAE,wBAAwB,2CAqL1B"}
1
+ {"version":3,"file":"price-schedule-dialog.d.ts","sourceRoot":"","sources":["../../src/components/price-schedule-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,mBAAmB,EAA4B,MAAM,yBAAyB,CAAA;AA6C5F,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,QAAQ,CAAC,EAAE,mBAAmB,CAAA;IAC9B,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,mBAAmB,KAAK,IAAI,CAAA;CACpD;AAED,wBAAgB,mBAAmB,CAAC,EAClC,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,SAAS,GACV,EAAE,wBAAwB,2CAuM1B"}
@@ -8,29 +8,36 @@ import { Loader2 } from "lucide-react";
8
8
  import { useEffect } from "react";
9
9
  import { useForm } from "react-hook-form";
10
10
  import { z } from "zod/v4";
11
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
11
12
  import { PriceCatalogCombobox } from "./price-catalog-combobox";
12
- const scheduleFormSchema = z.object({
13
- priceCatalogId: z.string().min(1, "Catalog is required"),
14
- name: z.string().min(1, "Name is required").max(255),
15
- code: z.string().max(100).optional().nullable(),
16
- recurrenceRule: z.string().min(1, "RRULE is required"),
17
- timezone: z.string().max(100).optional().nullable(),
18
- validFrom: z.string().optional().nullable(),
19
- validTo: z.string().optional().nullable(),
20
- priority: z.coerce.number().int(),
21
- active: z.boolean(),
22
- notes: z.string().optional().nullable(),
23
- });
13
+ function createScheduleFormSchema(messages) {
14
+ return z.object({
15
+ priceCatalogId: z.string().min(1, messages.priceScheduleDialog.validation.catalogRequired),
16
+ name: z.string().min(1, messages.priceScheduleDialog.validation.nameRequired).max(255),
17
+ code: z.string().max(100).optional().nullable(),
18
+ recurrenceRule: z
19
+ .string()
20
+ .min(1, messages.priceScheduleDialog.validation.recurrenceRuleRequired),
21
+ timezone: z.string().max(100).optional().nullable(),
22
+ validFrom: z.string().optional().nullable(),
23
+ validTo: z.string().optional().nullable(),
24
+ priority: z.coerce.number().int(),
25
+ active: z.boolean(),
26
+ notes: z.string().optional().nullable(),
27
+ });
28
+ }
24
29
  export function PriceScheduleDialog({ open, onOpenChange, schedule, onSuccess, }) {
25
30
  const isEditing = !!schedule;
26
31
  const { create, update } = usePriceScheduleMutation();
32
+ const messages = usePricingUiMessagesOrDefault();
33
+ const scheduleFormSchema = createScheduleFormSchema(messages);
27
34
  const form = useForm({
28
35
  resolver: zodResolver(scheduleFormSchema),
29
36
  defaultValues: {
30
37
  priceCatalogId: "",
31
38
  name: "",
32
39
  code: "",
33
- recurrenceRule: "FREQ=YEARLY;BYMONTH=6,7,8",
40
+ recurrenceRule: messages.priceScheduleDialog.placeholders.recurrenceRule,
34
41
  timezone: "",
35
42
  validFrom: "",
36
43
  validTo: "",
@@ -80,8 +87,12 @@ export function PriceScheduleDialog({ open, onOpenChange, schedule, onSuccess, }
80
87
  const validFrom = form.watch("validFrom");
81
88
  const validTo = form.watch("validTo");
82
89
  const isSubmitting = create.isPending || update.isPending;
83
- return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { size: "lg", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: isEditing ? "Edit Price Schedule" : "New Price Schedule" }) }), _jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [_jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Catalog" }), _jsx(PriceCatalogCombobox, { value: form.watch("priceCatalogId"), onChange: (value) => form.setValue("priceCatalogId", value ?? "", {
90
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { size: "lg", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: isEditing
91
+ ? messages.priceScheduleDialog.titles.edit
92
+ : messages.priceScheduleDialog.titles.create }) }), _jsxs("form", { onSubmit: form.handleSubmit(onSubmit), children: [_jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.catalog }), _jsx(PriceCatalogCombobox, { value: form.watch("priceCatalogId"), onChange: (value) => form.setValue("priceCatalogId", value ?? "", {
84
93
  shouldDirty: true,
85
94
  shouldValidate: true,
86
- }) }), form.formState.errors.priceCatalogId ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.priceCatalogId.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Name" }), _jsx(Input, { ...form.register("name"), placeholder: "High Season" }), form.formState.errors.name ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.name.message })) : null] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Code" }), _jsx(Input, { ...form.register("code"), placeholder: "high-season" })] })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Recurrence rule (RRULE)" }), _jsx(Textarea, { ...form.register("recurrenceRule"), placeholder: "FREQ=YEARLY;BYMONTH=6,7,8", rows: 2, className: "font-mono text-xs" }), _jsxs("p", { className: "text-xs text-muted-foreground", children: ["e.g. ", _jsx("code", { children: "FREQ=YEARLY;BYMONTH=6,7,8" }), " for June-August."] }), form.formState.errors.recurrenceRule ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.recurrenceRule.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Valid from" }), _jsx(DatePicker, { value: typeof validFrom === "string" && validFrom.length > 0 ? validFrom : null, onChange: (value) => form.setValue("validFrom", value ?? "", { shouldDirty: true }), placeholder: "Optional" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Valid to" }), _jsx(DatePicker, { value: typeof validTo === "string" && validTo.length > 0 ? validTo : null, onChange: (value) => form.setValue("validTo", value ?? "", { shouldDirty: true }), placeholder: "Optional" })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Timezone" }), _jsx(Input, { ...form.register("timezone"), placeholder: "Europe/Istanbul" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Priority" }), _jsx(Input, { ...form.register("priority"), type: "number" })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Switch, { checked: form.watch("active"), onCheckedChange: (checked) => form.setValue("active", checked) }), _jsx(Label, { children: "Active" })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: "Notes" }), _jsx(Textarea, { ...form.register("notes") })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing ? "Save Changes" : "Create Schedule"] })] })] })] }) }));
95
+ }), placeholder: messages.priceScheduleDialog.placeholders.catalog }), form.formState.errors.priceCatalogId ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.priceCatalogId.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.name }), _jsx(Input, { ...form.register("name"), placeholder: messages.priceScheduleDialog.placeholders.name }), form.formState.errors.name ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.name.message })) : null] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.code }), _jsx(Input, { ...form.register("code"), placeholder: messages.priceScheduleDialog.placeholders.code })] })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.recurrenceRule }), _jsx(Textarea, { ...form.register("recurrenceRule"), placeholder: messages.priceScheduleDialog.placeholders.recurrenceRule, rows: 2, className: "font-mono text-xs" }), _jsx("p", { className: "text-xs text-muted-foreground", children: messages.priceScheduleDialog.helpText.recurrenceRuleExample }), form.formState.errors.recurrenceRule ? (_jsx("p", { className: "text-xs text-destructive", children: form.formState.errors.recurrenceRule.message })) : null] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.validFrom }), _jsx(DatePicker, { value: typeof validFrom === "string" && validFrom.length > 0 ? validFrom : null, onChange: (value) => form.setValue("validFrom", value ?? "", { shouldDirty: true }), placeholder: messages.priceScheduleDialog.placeholders.validFrom })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.validTo }), _jsx(DatePicker, { value: typeof validTo === "string" && validTo.length > 0 ? validTo : null, onChange: (value) => form.setValue("validTo", value ?? "", { shouldDirty: true }), placeholder: messages.priceScheduleDialog.placeholders.validTo })] })] }), _jsxs("div", { className: "grid grid-cols-2 gap-4", children: [_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.timezone }), _jsx(Input, { ...form.register("timezone"), placeholder: messages.priceScheduleDialog.placeholders.timezone })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.priority }), _jsx(Input, { ...form.register("priority"), type: "number" })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Switch, { checked: form.watch("active"), onCheckedChange: (checked) => form.setValue("active", checked) }), _jsx(Label, { children: messages.priceScheduleDialog.fields.active })] }), _jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(Label, { children: messages.priceScheduleDialog.fields.notes }), _jsx(Textarea, { ...form.register("notes") })] })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: messages.common.cancel }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? _jsx(Loader2, { className: "mr-2 h-4 w-4 animate-spin" }) : null, isEditing
96
+ ? messages.common.saveChanges
97
+ : messages.priceScheduleDialog.actions.create] })] })] })] }) }));
87
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pricing-category-combobox.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-combobox.tsx"],"names":[],"mappings":"AAcA,KAAK,4BAA4B,GAAG;IAClC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACxC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAID,wBAAgB,uBAAuB,CAAC,EACtC,KAAK,EACL,QAAQ,EACR,WAA0C,EAC1C,QAAQ,GACT,EAAE,4BAA4B,2CA4E9B"}
1
+ {"version":3,"file":"pricing-category-combobox.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-combobox.tsx"],"names":[],"mappings":"AAgBA,KAAK,4BAA4B,GAAG;IAClC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IACxC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAID,wBAAgB,uBAAuB,CAAC,EACtC,KAAK,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,GACT,EAAE,4BAA4B,2CAkF9B"}
@@ -3,8 +3,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { usePricingCategories } from "@voyantjs/pricing-react";
4
4
  import { Combobox, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList, } from "@voyantjs/ui/components/combobox";
5
5
  import * as React from "react";
6
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
6
7
  const PAGE_SIZE = 25;
7
- export function PricingCategoryCombobox({ value, onChange, placeholder = "Search pricing categories…", disabled, }) {
8
+ export function PricingCategoryCombobox({ value, onChange, placeholder, disabled, }) {
9
+ const messages = usePricingUiMessagesOrDefault();
8
10
  const [search, setSearch] = React.useState("");
9
11
  const { data, isPending } = usePricingCategories({
10
12
  search: search || undefined,
@@ -45,7 +47,7 @@ export function PricingCategoryCombobox({ value, onChange, placeholder = "Search
45
47
  const item = itemMap.get(id);
46
48
  const label = item ? `${item.name}${item.code ? ` (${item.code})` : ""}` : "";
47
49
  setInputValue(label);
48
- }, children: [_jsx(ComboboxInput, { placeholder: placeholder, showClear: !!value }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: isPending ? "Loading…" : "No pricing categories found." }), _jsx(ComboboxList, { children: _jsx(ComboboxCollection, { children: (id) => {
50
+ }, children: [_jsx(ComboboxInput, { placeholder: placeholder ?? messages.comboboxes.pricingCategory.placeholder, showClear: !!value }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: isPending ? messages.common.loading : messages.comboboxes.pricingCategory.empty }), _jsx(ComboboxList, { children: _jsx(ComboboxCollection, { children: (id) => {
49
51
  const item = itemMap.get(id);
50
52
  if (!item)
51
53
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"pricing-category-dependency-dialog.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-dependency-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAA;AAY9E,MAAM,WAAW,oCAAoC;IACnD,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,UAAU,CAAC,EAAE,+BAA+B,CAAA;IAC5C,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,+BAA+B,KAAK,IAAI,CAAA;CAClE;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,SAAS,GACV,EAAE,oCAAoC,2CAyBtC"}
1
+ {"version":3,"file":"pricing-category-dependency-dialog.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-dependency-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAA;AAa9E,MAAM,WAAW,oCAAoC;IACnD,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,UAAU,CAAC,EAAE,+BAA+B,CAAA;IAC5C,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,+BAA+B,KAAK,IAAI,CAAA;CAClE;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,SAAS,GACV,EAAE,oCAAoC,2CA4BtC"}
@@ -1,10 +1,14 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@voyantjs/ui/components/dialog";
4
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
4
5
  import { PricingCategoryDependencyForm } from "./pricing-category-dependency-form";
5
6
  export function PricingCategoryDependencyDialog({ open, onOpenChange, dependency, onSuccess, }) {
6
7
  const isEdit = Boolean(dependency);
7
- return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "pricing-category-dependency-dialog", className: "sm:max-w-[720px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEdit ? "Edit category dependency" : "Add category dependency" }), _jsx(DialogDescription, { children: "Rules between pricing categories such as requires, excludes, and quantity limits." })] }), _jsx(PricingCategoryDependencyForm, { mode: dependency ? { kind: "edit", dependency } : { kind: "create" }, onSuccess: (saved) => {
8
+ const messages = usePricingUiMessagesOrDefault();
9
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "pricing-category-dependency-dialog", className: "sm:max-w-[720px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEdit
10
+ ? messages.pricingCategoryDependencyDialog.titles.edit
11
+ : messages.pricingCategoryDependencyDialog.titles.create }), _jsx(DialogDescription, { children: messages.pricingCategoryDependencyDialog.description })] }), _jsx(PricingCategoryDependencyForm, { mode: dependency ? { kind: "edit", dependency } : { kind: "create" }, onSuccess: (saved) => {
8
12
  onSuccess?.(saved);
9
13
  onOpenChange(false);
10
14
  }, onCancel: () => onOpenChange(false) })] }) }));
@@ -1 +1 @@
1
- {"version":3,"file":"pricing-category-dependency-form.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-dependency-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,+BAA+B,EAErC,MAAM,yBAAyB,CAAA;AAiBhC,KAAK,IAAI,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,+BAA+B,CAAA;CAAE,CAAA;AAE9F,MAAM,WAAW,kCAAkC;IACjD,IAAI,EAAE,IAAI,CAAA;IACV,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,+BAA+B,KAAK,IAAI,CAAA;IACjE,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AA+DD,wBAAgB,6BAA6B,CAAC,EAC5C,IAAI,EACJ,SAAS,EACT,QAAQ,GACT,EAAE,kCAAkC,2CAmJpC"}
1
+ {"version":3,"file":"pricing-category-dependency-form.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-dependency-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,+BAA+B,EAErC,MAAM,yBAAyB,CAAA;AAmBhC,KAAK,IAAI,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,+BAA+B,CAAA;CAAE,CAAA;AAE9F,MAAM,WAAW,kCAAkC;IACjD,IAAI,EAAE,IAAI,CAAA;IACV,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,+BAA+B,KAAK,IAAI,CAAA;IACjE,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AA+DD,wBAAgB,6BAA6B,CAAC,EAC5C,IAAI,EACJ,SAAS,EACT,QAAQ,GACT,EAAE,kCAAkC,2CAmKpC"}
@@ -9,12 +9,13 @@ import { Switch } from "@voyantjs/ui/components/switch";
9
9
  import { Textarea } from "@voyantjs/ui/components/textarea";
10
10
  import { Loader2 } from "lucide-react";
11
11
  import * as React from "react";
12
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
12
13
  import { PricingCategoryCombobox } from "./pricing-category-combobox";
13
14
  const DEPENDENCY_TYPES = [
14
- { value: "requires", label: "Requires" },
15
- { value: "limits_per_master", label: "Limits per master" },
16
- { value: "limits_sum", label: "Limits sum" },
17
- { value: "excludes", label: "Excludes" },
15
+ { value: "requires" },
16
+ { value: "limits_per_master" },
17
+ { value: "limits_sum" },
18
+ { value: "excludes" },
18
19
  ];
19
20
  function initialState(mode) {
20
21
  if (mode.kind === "edit") {
@@ -61,6 +62,7 @@ export function PricingCategoryDependencyForm({ mode, onSuccess, onCancel, }) {
61
62
  const [state, setState] = React.useState(() => initialState(mode));
62
63
  const [error, setError] = React.useState(null);
63
64
  const { create, update } = usePricingCategoryDependencyMutation();
65
+ const messages = usePricingUiMessagesOrDefault();
64
66
  React.useEffect(() => {
65
67
  setState(initialState(mode));
66
68
  setError(null);
@@ -70,7 +72,7 @@ export function PricingCategoryDependencyForm({ mode, onSuccess, onCancel, }) {
70
72
  event.preventDefault();
71
73
  setError(null);
72
74
  if (!state.masterPricingCategoryId || !state.pricingCategoryId) {
73
- setError("Both master and dependent categories are required.");
75
+ setError(messages.pricingCategoryDependencyForm.validation.categoriesRequired);
74
76
  return;
75
77
  }
76
78
  try {
@@ -80,11 +82,18 @@ export function PricingCategoryDependencyForm({ mode, onSuccess, onCancel, }) {
80
82
  onSuccess?.(dependency);
81
83
  }
82
84
  catch (err) {
83
- setError(err instanceof Error ? err.message : "Failed to save category dependency.");
85
+ setError(err instanceof Error
86
+ ? err.message
87
+ : messages.pricingCategoryDependencyForm.validation.saveFailed);
84
88
  }
85
89
  };
86
- return (_jsxs("form", { "data-slot": "pricing-category-dependency-form", onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: "Master category" }), _jsx(PricingCategoryCombobox, { value: state.masterPricingCategoryId, onChange: (value) => setState((prev) => ({ ...prev, masterPricingCategoryId: value ?? "" })), placeholder: "Search category" })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: "Dependent category" }), _jsx(PricingCategoryCombobox, { value: state.pricingCategoryId, onChange: (value) => setState((prev) => ({ ...prev, pricingCategoryId: value ?? "" })), placeholder: "Search category" })] })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: "Dependency type" }), _jsxs(Select, { items: DEPENDENCY_TYPES, value: state.dependencyType, onValueChange: (value) => setState((prev) => ({
90
+ return (_jsxs("form", { "data-slot": "pricing-category-dependency-form", onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: messages.pricingCategoryDependencyForm.fields.masterCategory }), _jsx(PricingCategoryCombobox, { value: state.masterPricingCategoryId, onChange: (value) => setState((prev) => ({ ...prev, masterPricingCategoryId: value ?? "" })), placeholder: messages.pricingCategoryDependencyForm.placeholders.categorySearch })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: messages.pricingCategoryDependencyForm.fields.dependentCategory }), _jsx(PricingCategoryCombobox, { value: state.pricingCategoryId, onChange: (value) => setState((prev) => ({ ...prev, pricingCategoryId: value ?? "" })), placeholder: messages.pricingCategoryDependencyForm.placeholders.categorySearch })] })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: messages.pricingCategoryDependencyForm.fields.dependencyType }), _jsxs(Select, { items: DEPENDENCY_TYPES.map((type) => ({
91
+ label: messages.common.dependencyTypeLabels[type.value],
92
+ value: type.value,
93
+ })), value: state.dependencyType, onValueChange: (value) => setState((prev) => ({
87
94
  ...prev,
88
95
  dependencyType: value,
89
- })), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: DEPENDENCY_TYPES.map((type) => (_jsx(SelectItem, { value: type.value, children: type.label }, type.value))) })] })] }), _jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "pricing-category-dependency-max-per-master", children: "Max per master" }), _jsx(Input, { id: "pricing-category-dependency-max-per-master", type: "number", min: "0", value: state.maxPerMaster, onChange: (event) => setState((prev) => ({ ...prev, maxPerMaster: event.target.value })) })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "pricing-category-dependency-max-dependent-sum", children: "Max dependent sum" }), _jsx(Input, { id: "pricing-category-dependency-max-dependent-sum", type: "number", min: "0", value: state.maxDependentSum, onChange: (event) => setState((prev) => ({ ...prev, maxDependentSum: event.target.value })) })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Switch, { checked: state.active, onCheckedChange: (active) => setState((prev) => ({ ...prev, active })) }), _jsx(Label, { children: "Active" })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "pricing-category-dependency-notes", children: "Notes" }), _jsx(Textarea, { id: "pricing-category-dependency-notes", value: state.notes, onChange: (event) => setState((prev) => ({ ...prev, notes: event.target.value })) })] }), error ? _jsx("p", { className: "text-sm text-destructive", children: error }) : null, _jsxs("div", { className: "flex items-center justify-end gap-2", children: [onCancel ? (_jsx(Button, { type: "button", variant: "ghost", onClick: onCancel, children: "Cancel" })) : null, _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? (_jsx(Loader2, { className: "mr-2 size-4 animate-spin", "aria-hidden": "true" })) : null, mode.kind === "edit" ? "Save changes" : "Add dependency"] })] })] }));
96
+ })), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: DEPENDENCY_TYPES.map((type) => (_jsx(SelectItem, { value: type.value, children: messages.common.dependencyTypeLabels[type.value] }, type.value))) })] })] }), _jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "pricing-category-dependency-max-per-master", children: messages.pricingCategoryDependencyForm.fields.maxPerMaster }), _jsx(Input, { id: "pricing-category-dependency-max-per-master", type: "number", min: "0", value: state.maxPerMaster, onChange: (event) => setState((prev) => ({ ...prev, maxPerMaster: event.target.value })) })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "pricing-category-dependency-max-dependent-sum", children: messages.pricingCategoryDependencyForm.fields.maxDependentSum }), _jsx(Input, { id: "pricing-category-dependency-max-dependent-sum", type: "number", min: "0", value: state.maxDependentSum, onChange: (event) => setState((prev) => ({ ...prev, maxDependentSum: event.target.value })) })] })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Switch, { checked: state.active, onCheckedChange: (active) => setState((prev) => ({ ...prev, active })) }), _jsx(Label, { children: messages.pricingCategoryDependencyForm.fields.active })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "pricing-category-dependency-notes", children: messages.pricingCategoryDependencyForm.fields.notes }), _jsx(Textarea, { id: "pricing-category-dependency-notes", value: state.notes, onChange: (event) => setState((prev) => ({ ...prev, notes: event.target.value })) })] }), error ? _jsx("p", { className: "text-sm text-destructive", children: error }) : null, _jsxs("div", { className: "flex items-center justify-end gap-2", children: [onCancel ? (_jsx(Button, { type: "button", variant: "ghost", onClick: onCancel, children: messages.common.cancel })) : null, _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting ? (_jsx(Loader2, { className: "mr-2 size-4 animate-spin", "aria-hidden": "true" })) : null, mode.kind === "edit"
97
+ ? messages.common.saveChanges
98
+ : messages.pricingCategoryDependencyForm.actions.create] })] })] }));
90
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"pricing-category-dialog.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAYpE,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,QAAQ,CAAC,EAAE,qBAAqB,CAAA;IAChC,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,CAAA;CACtD;AAED,wBAAgB,qBAAqB,CAAC,EACpC,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,SAAS,GACV,EAAE,0BAA0B,2CAyB5B"}
1
+ {"version":3,"file":"pricing-category-dialog.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAapE,MAAM,WAAW,0BAA0B;IACzC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,QAAQ,CAAC,EAAE,qBAAqB,CAAA;IAChC,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,CAAA;CACtD;AAED,wBAAgB,qBAAqB,CAAC,EACpC,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,SAAS,GACV,EAAE,0BAA0B,2CA8B5B"}
@@ -1,12 +1,16 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, } from "@voyantjs/ui/components/dialog";
4
+ import { usePricingUiMessagesOrDefault } from "../i18n/provider";
4
5
  import { PricingCategoryForm } from "./pricing-category-form";
5
6
  export function PricingCategoryDialog({ open, onOpenChange, category, onSuccess, }) {
6
7
  const isEdit = Boolean(category);
7
- return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "pricing-category-dialog", className: "sm:max-w-[720px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEdit ? "Edit pricing category" : "New pricing category" }), _jsx(DialogDescription, { children: isEdit
8
- ? "Update reusable pricing category rules and eligibility."
9
- : "Create a reusable pricing category for products and options." })] }), _jsx(PricingCategoryForm, { mode: category ? { kind: "edit", category } : { kind: "create" }, onSuccess: (saved) => {
8
+ const messages = usePricingUiMessagesOrDefault();
9
+ return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "pricing-category-dialog", className: "sm:max-w-[720px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEdit
10
+ ? messages.pricingCategoryDialog.titles.edit
11
+ : messages.pricingCategoryDialog.titles.create }), _jsx(DialogDescription, { children: isEdit
12
+ ? messages.pricingCategoryDialog.descriptions.edit
13
+ : messages.pricingCategoryDialog.descriptions.create })] }), _jsx(PricingCategoryForm, { mode: category ? { kind: "edit", category } : { kind: "create" }, onSuccess: (saved) => {
10
14
  onSuccess?.(saved);
11
15
  onOpenChange(false);
12
16
  }, onCancel: () => onOpenChange(false) })] }) }));
@@ -1 +1 @@
1
- {"version":3,"file":"pricing-category-form.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,qBAAqB,EAE3B,MAAM,yBAAyB,CAAA;AAehC,KAAK,IAAI,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,qBAAqB,CAAA;CAAE,CAAA;AAElF,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,IAAI,CAAA;IACV,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,CAAA;IACrD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AAqFD,wBAAgB,mBAAmB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,wBAAwB,2CAyK1F"}
1
+ {"version":3,"file":"pricing-category-form.d.ts","sourceRoot":"","sources":["../../src/components/pricing-category-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,qBAAqB,EAE3B,MAAM,yBAAyB,CAAA;AAiBhC,KAAK,IAAI,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,qBAAqB,CAAA;CAAE,CAAA;AAElF,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,IAAI,CAAA;IACV,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI,CAAA;IACrD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AAqFD,wBAAgB,mBAAmB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,wBAAwB,2CAyL1F"}