@voyantjs/products-ui 0.101.2 → 0.103.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 (40) hide show
  1. package/dist/components/product-detail/product-departure-form.d.ts.map +1 -1
  2. package/dist/components/product-detail/product-departure-form.js +22 -2
  3. package/dist/components/product-detail/product-detail-form.d.ts +3 -0
  4. package/dist/components/product-detail/product-detail-form.d.ts.map +1 -1
  5. package/dist/components/product-detail/product-detail-form.js +31 -4
  6. package/dist/components/product-detail/product-detail-page.d.ts.map +1 -1
  7. package/dist/components/product-detail/product-detail-page.js +2 -3
  8. package/dist/components/product-detail/product-extra-dialog.d.ts +21 -0
  9. package/dist/components/product-detail/product-extra-dialog.d.ts.map +1 -0
  10. package/dist/components/product-detail/product-extra-dialog.js +131 -0
  11. package/dist/components/product-detail/product-option-pricing-grid.d.ts +16 -0
  12. package/dist/components/product-detail/product-option-pricing-grid.d.ts.map +1 -0
  13. package/dist/components/product-detail/product-option-pricing-grid.js +233 -0
  14. package/dist/components/product-detail/product-options-pricing.d.ts +38 -1
  15. package/dist/components/product-detail/product-options-pricing.d.ts.map +1 -1
  16. package/dist/components/product-detail/product-options-pricing.js +136 -46
  17. package/dist/components/product-detail/product-options-shared.d.ts +14 -0
  18. package/dist/components/product-detail/product-options-shared.d.ts.map +1 -1
  19. package/dist/components/product-detail/product-options-shared.js +20 -0
  20. package/dist/components/product-detail/product-translation-popover.d.ts +4 -1
  21. package/dist/components/product-detail/product-translation-popover.d.ts.map +1 -1
  22. package/dist/components/product-detail/product-translation-popover.js +28 -8
  23. package/dist/components/product-detail/product-unit-dialog.d.ts +3 -1
  24. package/dist/components/product-detail/product-unit-dialog.d.ts.map +1 -1
  25. package/dist/components/product-detail/product-unit-dialog.js +2 -2
  26. package/dist/components/product-detail/product-unit-form.d.ts +9 -1
  27. package/dist/components/product-detail/product-unit-form.d.ts.map +1 -1
  28. package/dist/components/product-detail/product-unit-form.js +37 -7
  29. package/dist/components/product-detail/product-unit-price-rule-dialog.d.ts +2 -1
  30. package/dist/components/product-detail/product-unit-price-rule-dialog.d.ts.map +1 -1
  31. package/dist/components/product-detail/product-unit-price-rule-dialog.js +2 -2
  32. package/dist/components/product-detail/product-unit-price-rule-form.d.ts +2 -1
  33. package/dist/components/product-detail/product-unit-price-rule-form.d.ts.map +1 -1
  34. package/dist/components/product-detail/product-unit-price-rule-form.js +28 -9
  35. package/dist/components/product-options-section.d.ts.map +1 -1
  36. package/dist/components/product-options-section.js +31 -20
  37. package/package.json +29 -29
  38. package/dist/components/product-detail/product-extras-section.d.ts +0 -4
  39. package/dist/components/product-detail/product-extras-section.d.ts.map +0 -1
  40. package/dist/components/product-detail/product-extras-section.js +0 -141
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyantjs/products-ui",
3
- "version": "0.101.2",
3
+ "version": "0.103.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -50,26 +50,26 @@
50
50
  "react-dom": "^19.0.0",
51
51
  "react-hook-form": "^7.60.0",
52
52
  "zod": "^4.3.6",
53
- "@voyantjs/availability": "0.101.2",
54
- "@voyantjs/availability-react": "0.101.2",
55
- "@voyantjs/catalog-react": "0.101.2",
56
- "@voyantjs/extras-react": "0.101.2",
57
- "@voyantjs/finance": "0.101.2",
58
- "@voyantjs/finance-ui": "0.101.2",
59
- "@voyantjs/markets-react": "0.101.2",
60
- "@voyantjs/pricing-react": "0.101.2",
61
- "@voyantjs/pricing-ui": "0.101.2",
62
- "@voyantjs/products-react": "0.101.2",
63
- "@voyantjs/suppliers-react": "0.101.2",
64
- "@voyantjs/ui": "0.101.2",
65
- "@voyantjs/utils": "0.101.2"
53
+ "@voyantjs/availability": "0.103.0",
54
+ "@voyantjs/availability-react": "0.103.0",
55
+ "@voyantjs/catalog-react": "0.103.0",
56
+ "@voyantjs/extras-react": "0.103.0",
57
+ "@voyantjs/finance": "0.103.0",
58
+ "@voyantjs/finance-ui": "0.103.0",
59
+ "@voyantjs/markets-react": "0.103.0",
60
+ "@voyantjs/pricing-react": "0.103.0",
61
+ "@voyantjs/pricing-ui": "0.103.0",
62
+ "@voyantjs/products-react": "0.103.0",
63
+ "@voyantjs/suppliers-react": "0.103.0",
64
+ "@voyantjs/ui": "0.103.0",
65
+ "@voyantjs/utils": "0.103.0"
66
66
  },
67
67
  "dependencies": {
68
68
  "date-fns": "^4.1.0",
69
69
  "motion": "^12.38.0",
70
70
  "react-day-picker": "^9.8.0",
71
71
  "sonner": "^2.0.7",
72
- "@voyantjs/i18n": "0.101.2"
72
+ "@voyantjs/i18n": "0.103.0"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@tanstack/react-query": "^5.100.11",
@@ -82,20 +82,20 @@
82
82
  "typescript": "^6.0.2",
83
83
  "vitest": "^4.1.2",
84
84
  "zod": "^4.3.6",
85
- "@voyantjs/availability": "0.101.2",
86
- "@voyantjs/availability-react": "0.101.2",
87
- "@voyantjs/catalog-react": "0.101.2",
88
- "@voyantjs/extras-react": "0.101.2",
89
- "@voyantjs/finance": "0.101.2",
90
- "@voyantjs/finance-ui": "0.101.2",
91
- "@voyantjs/i18n": "0.101.2",
92
- "@voyantjs/markets-react": "0.101.2",
93
- "@voyantjs/pricing-react": "0.101.2",
94
- "@voyantjs/pricing-ui": "0.101.2",
95
- "@voyantjs/products-react": "0.101.2",
96
- "@voyantjs/suppliers-react": "0.101.2",
97
- "@voyantjs/ui": "0.101.2",
98
- "@voyantjs/utils": "0.101.2",
85
+ "@voyantjs/availability": "0.103.0",
86
+ "@voyantjs/availability-react": "0.103.0",
87
+ "@voyantjs/catalog-react": "0.103.0",
88
+ "@voyantjs/extras-react": "0.103.0",
89
+ "@voyantjs/finance": "0.103.0",
90
+ "@voyantjs/finance-ui": "0.103.0",
91
+ "@voyantjs/i18n": "0.103.0",
92
+ "@voyantjs/markets-react": "0.103.0",
93
+ "@voyantjs/pricing-react": "0.103.0",
94
+ "@voyantjs/pricing-ui": "0.103.0",
95
+ "@voyantjs/products-react": "0.103.0",
96
+ "@voyantjs/suppliers-react": "0.103.0",
97
+ "@voyantjs/ui": "0.103.0",
98
+ "@voyantjs/utils": "0.103.0",
99
99
  "@voyantjs/voyant-typescript-config": "0.1.0"
100
100
  },
101
101
  "files": [
@@ -1,4 +0,0 @@
1
- export declare function ProductExtrasSection({ productId }: {
2
- productId: string;
3
- }): import("react/jsx-runtime").JSX.Element;
4
- //# sourceMappingURL=product-extras-section.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"product-extras-section.d.ts","sourceRoot":"","sources":["../../../src/components/product-detail/product-extras-section.tsx"],"names":[],"mappings":"AAmEA,wBAAgB,oBAAoB,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,2CAiQxE"}
@@ -1,141 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useProductExtraMutation, useProductExtras, } from "@voyantjs/extras-react";
3
- import { formatMessage } from "@voyantjs/i18n";
4
- import { Badge, Button, Checkbox, Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, Textarea, } from "@voyantjs/ui/components";
5
- import { Pencil, Plus, Trash2 } from "lucide-react";
6
- import * as React from "react";
7
- import { useProductDetailMessages } from "./host.js";
8
- import { ActionMenu, EmptyState, Section } from "./product-detail-sections.js";
9
- const selectionTypes = ["optional", "required", "default_selected", "unavailable"];
10
- const pricingModes = [
11
- "included",
12
- "per_person",
13
- "per_booking",
14
- "quantity_based",
15
- "on_request",
16
- "free",
17
- ];
18
- const emptyForm = {
19
- name: "",
20
- code: "",
21
- description: "",
22
- selectionType: "optional",
23
- pricingMode: "per_booking",
24
- pricedPerPerson: false,
25
- minQuantity: "",
26
- maxQuantity: "",
27
- defaultQuantity: "",
28
- active: true,
29
- };
30
- export function ProductExtrasSection({ productId }) {
31
- const messages = useProductDetailMessages();
32
- const extraMessages = messages.products.operations.extras;
33
- const [open, setOpen] = React.useState(false);
34
- const [editing, setEditing] = React.useState(null);
35
- const [form, setForm] = React.useState(emptyForm);
36
- const { data, isPending, refetch } = useProductExtras({ productId, limit: 100 });
37
- const { create, update, remove } = useProductExtraMutation();
38
- const rows = data?.data ?? [];
39
- const startCreate = () => {
40
- setEditing(null);
41
- setForm(emptyForm);
42
- setOpen(true);
43
- };
44
- const startEdit = (extra) => {
45
- setEditing(extra);
46
- setForm({
47
- name: extra.name,
48
- code: extra.code ?? "",
49
- description: extra.description ?? "",
50
- selectionType: extra.selectionType,
51
- pricingMode: extra.pricingMode,
52
- pricedPerPerson: extra.pricedPerPerson,
53
- minQuantity: extra.minQuantity == null ? "" : String(extra.minQuantity),
54
- maxQuantity: extra.maxQuantity == null ? "" : String(extra.maxQuantity),
55
- defaultQuantity: extra.defaultQuantity == null ? "" : String(extra.defaultQuantity),
56
- active: extra.active,
57
- });
58
- setOpen(true);
59
- };
60
- const save = async () => {
61
- const payload = {
62
- productId,
63
- name: form.name.trim(),
64
- code: form.code.trim() || null,
65
- description: form.description.trim() || null,
66
- selectionType: form.selectionType,
67
- pricingMode: form.pricingMode,
68
- pricedPerPerson: form.pricedPerPerson,
69
- minQuantity: parseNullableInt(form.minQuantity),
70
- maxQuantity: parseNullableInt(form.maxQuantity),
71
- defaultQuantity: parseNullableInt(form.defaultQuantity),
72
- active: form.active,
73
- sortOrder: editing?.sortOrder ?? rows.length,
74
- };
75
- if (!payload.name)
76
- return;
77
- if (editing)
78
- await update.mutateAsync({ id: editing.id, input: payload });
79
- else
80
- await create.mutateAsync(payload);
81
- setOpen(false);
82
- setEditing(null);
83
- setForm(emptyForm);
84
- void refetch();
85
- };
86
- return (_jsxs(Section, { title: extraMessages.sectionTitle, actions: _jsxs(Button, { variant: "outline", size: "sm", onClick: startCreate, children: [_jsx(Plus, { className: "mr-1 h-3.5 w-3.5" }), extraMessages.addAction] }), contentClassName: "px-6 py-4", children: [rows.length === 0 ? (_jsx(EmptyState, { message: isPending ? extraMessages.loading : extraMessages.empty })) : (_jsx("div", { className: "flex flex-col gap-2", children: rows.map((extra) => (_jsxs("div", { className: "flex items-start justify-between gap-3 rounded-md border px-3 py-2", children: [_jsxs("div", { className: "min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "font-medium text-sm", children: extra.name }), _jsx(Badge, { variant: extra.active ? "default" : "outline", children: extra.active ? extraMessages.activeBadge : extraMessages.inactiveBadge }), _jsx(Badge, { variant: "secondary", children: getPricingModeLabel(extra.pricingMode, extraMessages) }), extra.pricedPerPerson ? (_jsx(Badge, { variant: "outline", children: extraMessages.perTravelerBadge })) : null] }), extra.description ? (_jsx("p", { className: "text-muted-foreground text-xs", children: extra.description })) : null] }), _jsxs(ActionMenu, { children: [_jsxs("button", { type: "button", className: "flex w-full items-center gap-2 px-2 py-1.5 text-sm", onClick: () => startEdit(extra), children: [_jsx(Pencil, { className: "h-4 w-4" }), extraMessages.editAction] }), _jsxs("button", { type: "button", className: "flex w-full items-center gap-2 px-2 py-1.5 text-destructive text-sm", onClick: () => {
87
- if (confirm(formatMessage(extraMessages.deleteConfirm, { name: extra.name })))
88
- remove.mutate(extra.id, { onSuccess: () => void refetch() });
89
- }, children: [_jsx(Trash2, { className: "h-4 w-4" }), extraMessages.deleteAction] })] })] }, extra.id))) })), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: _jsxs(DialogContent, { size: "lg", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: editing ? extraMessages.editTitle : extraMessages.newTitle }), _jsx(DialogDescription, { children: extraMessages.dialogDescription })] }), _jsxs(DialogBody, { className: "grid gap-4", children: [_jsxs("div", { className: "grid gap-3 md:grid-cols-2", children: [_jsx(Field, { label: extraMessages.nameLabel, children: _jsx(Input, { value: form.name, onChange: (event) => setForm({ ...form, name: event.target.value }) }) }), _jsx(Field, { label: extraMessages.codeLabel, children: _jsx(Input, { value: form.code, onChange: (event) => setForm({ ...form, code: event.target.value }) }) })] }), _jsx(Field, { label: extraMessages.descriptionLabel, children: _jsx(Textarea, { value: form.description, onChange: (event) => setForm({ ...form, description: event.target.value }) }) }), _jsxs("div", { className: "grid gap-3 md:grid-cols-3", children: [_jsx(Field, { label: extraMessages.selectionLabel, children: _jsxs(Select, { value: form.selectionType, onValueChange: (value) => setForm({
90
- ...form,
91
- selectionType: (value ?? "optional"),
92
- }), items: selectionTypes.map((type) => ({
93
- value: type,
94
- label: getSelectionTypeLabel(type, extraMessages),
95
- })), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: selectionTypes.map((type) => (_jsx(SelectItem, { value: type, children: getSelectionTypeLabel(type, extraMessages) }, type))) })] }) }), _jsx(Field, { label: extraMessages.pricingLabel, children: _jsxs(Select, { value: form.pricingMode, onValueChange: (value) => setForm({
96
- ...form,
97
- pricingMode: (value ?? "per_booking"),
98
- }), items: pricingModes.map((mode) => ({
99
- value: mode,
100
- label: getPricingModeLabel(mode, extraMessages),
101
- })), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: pricingModes.map((mode) => (_jsx(SelectItem, { value: mode, children: getPricingModeLabel(mode, extraMessages) }, mode))) })] }) }), _jsx(Field, { label: extraMessages.defaultQuantityLabel, children: _jsx(Input, { value: form.defaultQuantity, type: "number", min: "0", onChange: (event) => setForm({ ...form, defaultQuantity: event.target.value }) }) }), _jsx(Field, { label: extraMessages.minQuantityLabel, children: _jsx(Input, { value: form.minQuantity, type: "number", min: "0", onChange: (event) => setForm({ ...form, minQuantity: event.target.value }) }) }), _jsx(Field, { label: extraMessages.maxQuantityLabel, children: _jsx(Input, { value: form.maxQuantity, type: "number", min: "0", onChange: (event) => setForm({ ...form, maxQuantity: event.target.value }) }) })] }), _jsxs("div", { className: "flex flex-wrap items-center gap-6", children: [_jsxs("div", { className: "flex items-center gap-2 text-sm", children: [_jsx(Checkbox, { id: "product-extra-priced-per-person", checked: form.pricedPerPerson, onCheckedChange: (checked) => setForm({ ...form, pricedPerPerson: checked === true }) }), _jsx(Label, { htmlFor: "product-extra-priced-per-person", children: extraMessages.perTravelerLabel })] }), _jsxs("div", { className: "flex items-center gap-2 text-sm", children: [_jsx(Checkbox, { id: "product-extra-active", checked: form.active, onCheckedChange: (checked) => setForm({ ...form, active: checked === true }) }), _jsx(Label, { htmlFor: "product-extra-active", children: extraMessages.activeLabel })] })] })] }), _jsxs(DialogFooter, { className: "-mx-6 -mb-6", children: [_jsx(Button, { variant: "ghost", onClick: () => setOpen(false), children: extraMessages.cancel }), _jsx(Button, { onClick: () => void save(), disabled: !form.name.trim(), children: editing ? extraMessages.saveChanges : extraMessages.create })] })] }) })] }));
102
- }
103
- function Field({ label, children }) {
104
- return (_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: label }), children] }));
105
- }
106
- function parseNullableInt(value) {
107
- const parsed = Number.parseInt(value, 10);
108
- return Number.isFinite(parsed) ? parsed : null;
109
- }
110
- function getSelectionTypeLabel(value, messages) {
111
- switch (value) {
112
- case "optional":
113
- return messages.selectionOptional;
114
- case "required":
115
- return messages.selectionRequired;
116
- case "default_selected":
117
- return messages.selectionDefaultSelected;
118
- case "unavailable":
119
- return messages.selectionUnavailable;
120
- default:
121
- return value;
122
- }
123
- }
124
- function getPricingModeLabel(value, messages) {
125
- switch (value) {
126
- case "included":
127
- return messages.pricingIncluded;
128
- case "per_person":
129
- return messages.pricingPerPerson;
130
- case "per_booking":
131
- return messages.pricingPerBooking;
132
- case "quantity_based":
133
- return messages.pricingQuantityBased;
134
- case "on_request":
135
- return messages.pricingOnRequest;
136
- case "free":
137
- return messages.pricingFree;
138
- default:
139
- return value;
140
- }
141
- }