@voyantjs/products-ui 0.15.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.
- package/README.md +11 -0
- package/dist/components/option-unit-dialog.d.ts.map +1 -1
- package/dist/components/option-unit-dialog.js +7 -3
- package/dist/components/option-unit-form.d.ts.map +1 -1
- package/dist/components/option-unit-form.js +16 -9
- package/dist/components/product-category-combobox.d.ts.map +1 -1
- package/dist/components/product-category-combobox.js +6 -4
- package/dist/components/product-category-dialog.d.ts.map +1 -1
- package/dist/components/product-category-dialog.js +7 -3
- package/dist/components/product-category-form.d.ts.map +1 -1
- package/dist/components/product-category-form.js +8 -4
- package/dist/components/product-category-list.d.ts.map +1 -1
- package/dist/components/product-category-list.js +11 -5
- package/dist/components/product-day-dialog.d.ts.map +1 -1
- package/dist/components/product-day-dialog.js +7 -3
- package/dist/components/product-day-form.d.ts.map +1 -1
- package/dist/components/product-day-form.js +9 -3
- package/dist/components/product-itinerary-dialog.d.ts.map +1 -1
- package/dist/components/product-itinerary-dialog.js +13 -5
- package/dist/components/product-media-dialog.d.ts.map +1 -1
- package/dist/components/product-media-dialog.js +7 -3
- package/dist/components/product-media-form.d.ts.map +1 -1
- package/dist/components/product-media-form.js +16 -7
- package/dist/components/product-media-section.d.ts.map +1 -1
- package/dist/components/product-media-section.js +19 -11
- package/dist/components/product-option-dialog.d.ts.map +1 -1
- package/dist/components/product-option-dialog.js +7 -3
- package/dist/components/product-option-form.d.ts.map +1 -1
- package/dist/components/product-option-form.js +11 -8
- package/dist/components/product-options-section.d.ts.map +1 -1
- package/dist/components/product-options-section.js +17 -13
- package/dist/components/product-tag-dialog.d.ts.map +1 -1
- package/dist/components/product-tag-dialog.js +7 -3
- package/dist/components/product-tag-form.d.ts.map +1 -1
- package/dist/components/product-tag-form.js +7 -3
- package/dist/components/product-tag-list.d.ts.map +1 -1
- package/dist/components/product-tag-list.js +9 -5
- package/dist/components/product-type-combobox.d.ts +1 -1
- package/dist/components/product-type-combobox.d.ts.map +1 -1
- package/dist/components/product-type-combobox.js +6 -2
- package/dist/components/product-version-dialog.d.ts.map +1 -1
- package/dist/components/product-version-dialog.js +5 -3
- package/dist/components/product-versions-section.d.ts.map +1 -1
- package/dist/components/product-versions-section.js +7 -2
- package/dist/i18n/en.d.ts +402 -0
- package/dist/i18n/en.d.ts.map +1 -0
- package/dist/i18n/en.js +401 -0
- package/dist/i18n/index.d.ts +5 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/index.js +3 -0
- package/dist/i18n/messages.d.ts +402 -0
- package/dist/i18n/messages.d.ts.map +1 -0
- package/dist/i18n/messages.js +1 -0
- package/dist/i18n/provider.d.ts +826 -0
- package/dist/i18n/provider.d.ts.map +1 -0
- package/dist/i18n/provider.js +44 -0
- package/dist/i18n/ro.d.ts +402 -0
- package/dist/i18n/ro.d.ts.map +1 -0
- package/dist/i18n/ro.js +401 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +27 -11
package/README.md
CHANGED
|
@@ -11,3 +11,14 @@ pnpm add @voyantjs/products-ui @voyantjs/products-react @voyantjs/ui @tanstack/r
|
|
|
11
11
|
`@voyantjs/ui` provides the design-system primitives. `@voyantjs/products-react` provides the data-layer hooks. Both are required peers.
|
|
12
12
|
|
|
13
13
|
All components accept a `className` prop and merge it with `cn()`. Wrap or compose to extend; use the registry copy-paste path (`npx shadcn add @voyant/...`) for components you want to fork outright.
|
|
14
|
+
|
|
15
|
+
## I18n
|
|
16
|
+
|
|
17
|
+
Components render English by default. To localize them, wrap your UI in
|
|
18
|
+
`ProductsUiMessagesProvider` and import only the locales your app supports.
|
|
19
|
+
|
|
20
|
+
```tsx
|
|
21
|
+
import { ProductsUiMessagesProvider } from "@voyantjs/products-ui"
|
|
22
|
+
import { productsUiEn } from "@voyantjs/products-ui/i18n/en"
|
|
23
|
+
import { productsUiRo } from "@voyantjs/products-ui/i18n/ro"
|
|
24
|
+
```
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-unit-dialog.d.ts","sourceRoot":"","sources":["../../src/components/option-unit-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"option-unit-dialog.d.ts","sourceRoot":"","sources":["../../src/components/option-unit-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAahE,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,gBAAgB,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAC7C;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,YAAY,EACZ,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,SAAS,GACV,EAAE,qBAAqB,2CA8BvB"}
|
|
@@ -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 { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
4
5
|
import { OptionUnitForm } from "./option-unit-form";
|
|
5
6
|
export function OptionUnitDialog({ open, onOpenChange, optionId, unit, sortOrder, onSuccess, }) {
|
|
6
7
|
const isEdit = Boolean(unit);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
9
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "option-unit-dialog", className: "sm:max-w-[680px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEdit
|
|
10
|
+
? messages.optionUnitDialog.titles.edit
|
|
11
|
+
: messages.optionUnitDialog.titles.create }), _jsx(DialogDescription, { children: isEdit
|
|
12
|
+
? messages.optionUnitDialog.descriptions.edit
|
|
13
|
+
: messages.optionUnitDialog.descriptions.create })] }), _jsx(OptionUnitForm, { mode: unit ? { kind: "edit", unit } : { kind: "create", optionId, sortOrder }, onSuccess: (saved) => {
|
|
10
14
|
onSuccess?.(saved);
|
|
11
15
|
onOpenChange(false);
|
|
12
16
|
}, onCancel: () => onOpenChange(false) })] }) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"option-unit-form.d.ts","sourceRoot":"","sources":["../../src/components/option-unit-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"option-unit-form.d.ts","sourceRoot":"","sources":["../../src/components/option-unit-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,gBAAgB,EAEtB,MAAM,0BAA0B,CAAA;AAkBjC,KAAK,IAAI,GACL;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAE5C,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,IAAI,CAAA;IACV,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC5C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AA6FD,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CAuOhF"}
|
|
@@ -9,13 +9,14 @@ 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 { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
12
13
|
const UNIT_TYPES = [
|
|
13
|
-
{ value: "person"
|
|
14
|
-
{ value: "group"
|
|
15
|
-
{ value: "room"
|
|
16
|
-
{ value: "vehicle"
|
|
17
|
-
{ value: "service"
|
|
18
|
-
{ value: "other"
|
|
14
|
+
{ value: "person" },
|
|
15
|
+
{ value: "group" },
|
|
16
|
+
{ value: "room" },
|
|
17
|
+
{ value: "vehicle" },
|
|
18
|
+
{ value: "service" },
|
|
19
|
+
{ value: "other" },
|
|
19
20
|
];
|
|
20
21
|
function initialState(mode) {
|
|
21
22
|
if (mode.kind === "edit") {
|
|
@@ -83,6 +84,7 @@ export function OptionUnitForm({ mode, onSuccess, onCancel }) {
|
|
|
83
84
|
const [state, setState] = React.useState(() => initialState(mode));
|
|
84
85
|
const [error, setError] = React.useState(null);
|
|
85
86
|
const { create, update } = useOptionUnitMutation();
|
|
87
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
86
88
|
React.useEffect(() => {
|
|
87
89
|
setState(initialState(mode));
|
|
88
90
|
setError(null);
|
|
@@ -95,7 +97,7 @@ export function OptionUnitForm({ mode, onSuccess, onCancel }) {
|
|
|
95
97
|
event.preventDefault();
|
|
96
98
|
setError(null);
|
|
97
99
|
if (!state.name.trim()) {
|
|
98
|
-
setError(
|
|
100
|
+
setError(messages.optionUnitForm.validation.nameRequired);
|
|
99
101
|
return;
|
|
100
102
|
}
|
|
101
103
|
try {
|
|
@@ -105,10 +107,15 @@ export function OptionUnitForm({ mode, onSuccess, onCancel }) {
|
|
|
105
107
|
onSuccess?.(unit);
|
|
106
108
|
}
|
|
107
109
|
catch (err) {
|
|
108
|
-
setError(err instanceof Error ? err.message :
|
|
110
|
+
setError(err instanceof Error ? err.message : messages.optionUnitForm.validation.saveFailed);
|
|
109
111
|
}
|
|
110
112
|
};
|
|
111
113
|
const showAgeRange = state.unitType === "person";
|
|
112
114
|
const showOccupancy = state.unitType === "group" || state.unitType === "room" || state.unitType === "vehicle";
|
|
113
|
-
return (_jsxs("form", { "data-slot": "option-unit-form", onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-name", children:
|
|
115
|
+
return (_jsxs("form", { "data-slot": "option-unit-form", onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-name", children: messages.optionUnitForm.fields.name }), _jsx(Input, { id: "option-unit-name", required: true, autoFocus: true, value: state.name, onChange: (event) => field("name")(event.target.value), placeholder: messages.optionUnitForm.placeholders.name })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-code", children: messages.optionUnitForm.fields.code }), _jsx(Input, { id: "option-unit-code", value: state.code, onChange: (event) => field("code")(event.target.value), placeholder: messages.optionUnitForm.placeholders.code })] })] }), _jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: messages.optionUnitForm.fields.unitType }), _jsxs(Select, { items: UNIT_TYPES.map((type) => ({
|
|
116
|
+
label: messages.common.optionUnitTypeLabels[type.value],
|
|
117
|
+
value: type.value,
|
|
118
|
+
})), value: state.unitType, onValueChange: (value) => value && field("unitType")(value), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: UNIT_TYPES.map((type) => (_jsx(SelectItem, { value: type.value, children: messages.common.optionUnitTypeLabels[type.value] }, type.value))) })] })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-sort-order", children: messages.optionUnitForm.fields.sortOrder }), _jsx(Input, { id: "option-unit-sort-order", type: "number", value: state.sortOrder, onChange: (event) => field("sortOrder")(event.target.value) })] })] }), _jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-min-quantity", children: messages.optionUnitForm.fields.minQuantity }), _jsx(Input, { id: "option-unit-min-quantity", type: "number", min: "0", value: state.minQuantity, onChange: (event) => field("minQuantity")(event.target.value) })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-max-quantity", children: messages.optionUnitForm.fields.maxQuantity }), _jsx(Input, { id: "option-unit-max-quantity", type: "number", min: "0", value: state.maxQuantity, onChange: (event) => field("maxQuantity")(event.target.value) })] })] }), showAgeRange ? (_jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-min-age", children: messages.optionUnitForm.fields.minAge }), _jsx(Input, { id: "option-unit-min-age", type: "number", min: "0", value: state.minAge, onChange: (event) => field("minAge")(event.target.value) })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-max-age", children: messages.optionUnitForm.fields.maxAge }), _jsx(Input, { id: "option-unit-max-age", type: "number", min: "0", value: state.maxAge, onChange: (event) => field("maxAge")(event.target.value) })] })] })) : null, showOccupancy ? (_jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-occupancy-min", children: messages.optionUnitForm.fields.occupancyMin }), _jsx(Input, { id: "option-unit-occupancy-min", type: "number", min: "0", value: state.occupancyMin, onChange: (event) => field("occupancyMin")(event.target.value) })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-occupancy-max", children: messages.optionUnitForm.fields.occupancyMax }), _jsx(Input, { id: "option-unit-occupancy-max", type: "number", min: "0", value: state.occupancyMax, onChange: (event) => field("occupancyMax")(event.target.value) })] })] })) : null, _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "option-unit-description", children: messages.optionUnitForm.fields.description }), _jsx(Textarea, { id: "option-unit-description", value: state.description, onChange: (event) => field("description")(event.target.value), placeholder: messages.optionUnitForm.placeholders.description })] }), _jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Switch, { checked: state.isRequired, onCheckedChange: (checked) => field("isRequired")(checked) }), _jsx(Label, { children: messages.optionUnitForm.fields.required })] }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Switch, { checked: state.isHidden, onCheckedChange: (checked) => field("isHidden")(checked) }), _jsx(Label, { children: messages.optionUnitForm.fields.hidden })] })] }), 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, disabled: isSubmitting, 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 === "create"
|
|
119
|
+
? messages.optionUnitForm.actions.createUnit
|
|
120
|
+
: messages.common.saveChanges] })] })] }));
|
|
114
121
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-category-combobox.d.ts","sourceRoot":"","sources":["../../src/components/product-category-combobox.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"product-category-combobox.d.ts","sourceRoot":"","sources":["../../src/components/product-category-combobox.tsx"],"names":[],"mappings":"AAkBA,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;IAClB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1B,CAAA;AAID,wBAAgB,uBAAuB,CAAC,EACtC,KAAK,EACL,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,SAAS,GACV,EAAE,KAAK,2CA0EP"}
|
|
@@ -2,8 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useProductCategories, useProductCategory, } from "@voyantjs/products-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 { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
5
6
|
const PAGE_SIZE = 25;
|
|
6
|
-
export function ProductCategoryCombobox({ value, onChange, placeholder
|
|
7
|
+
export function ProductCategoryCombobox({ value, onChange, placeholder, disabled, excludeId, }) {
|
|
8
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
7
9
|
const [search, setSearch] = React.useState("");
|
|
8
10
|
const listQuery = useProductCategories({ search: search || undefined, limit: PAGE_SIZE });
|
|
9
11
|
const selectedQuery = useProductCategory(value, { enabled: !!value });
|
|
@@ -34,9 +36,9 @@ export function ProductCategoryCombobox({ value, onChange, placeholder = "Search
|
|
|
34
36
|
const id = next ?? null;
|
|
35
37
|
onChange(id);
|
|
36
38
|
setInputValue(id ? (itemMap.get(id)?.name ?? "") : "");
|
|
37
|
-
}, children: [_jsx(ComboboxInput, { placeholder: placeholder, showClear: !!value }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: listQuery.isPending || selectedQuery.isPending
|
|
38
|
-
?
|
|
39
|
-
:
|
|
39
|
+
}, children: [_jsx(ComboboxInput, { placeholder: placeholder ?? messages.comboboxes.productCategory.placeholder, showClear: !!value }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: listQuery.isPending || selectedQuery.isPending
|
|
40
|
+
? messages.common.loading
|
|
41
|
+
: messages.comboboxes.productCategory.empty }), _jsx(ComboboxList, { children: _jsx(ComboboxCollection, { children: (id) => {
|
|
40
42
|
const item = itemMap.get(id);
|
|
41
43
|
if (!item)
|
|
42
44
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-category-dialog.d.ts","sourceRoot":"","sources":["../../src/components/product-category-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"product-category-dialog.d.ts","sourceRoot":"","sources":["../../src/components/product-category-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AAarE,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 { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
4
5
|
import { ProductCategoryForm } from "./product-category-form";
|
|
5
6
|
export function ProductCategoryDialog({ open, onOpenChange, category, onSuccess, }) {
|
|
6
7
|
const isEdit = Boolean(category);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
9
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "product-category-dialog", className: "sm:max-w-[640px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEdit
|
|
10
|
+
? messages.productCategoryDialog.titles.edit
|
|
11
|
+
: messages.productCategoryDialog.titles.create }), _jsx(DialogDescription, { children: isEdit
|
|
12
|
+
? messages.productCategoryDialog.descriptions.edit
|
|
13
|
+
: messages.productCategoryDialog.descriptions.create })] }), _jsx(ProductCategoryForm, { 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":"product-category-form.d.ts","sourceRoot":"","sources":["../../src/components/product-category-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,qBAAqB,EAE3B,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"product-category-form.d.ts","sourceRoot":"","sources":["../../src/components/product-category-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,qBAAqB,EAE3B,MAAM,0BAA0B,CAAA;AAYjC,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;AA6CD,wBAAgB,mBAAmB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,wBAAwB,2CAkI1F"}
|
|
@@ -8,6 +8,7 @@ import { Switch } from "@voyantjs/ui/components/switch";
|
|
|
8
8
|
import { Textarea } from "@voyantjs/ui/components/textarea";
|
|
9
9
|
import { Loader2 } from "lucide-react";
|
|
10
10
|
import * as React from "react";
|
|
11
|
+
import { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
11
12
|
import { ProductCategoryCombobox } from "./product-category-combobox";
|
|
12
13
|
function initialState(mode) {
|
|
13
14
|
if (mode.kind === "edit") {
|
|
@@ -44,6 +45,7 @@ export function ProductCategoryForm({ mode, onSuccess, onCancel }) {
|
|
|
44
45
|
const [state, setState] = React.useState(() => initialState(mode));
|
|
45
46
|
const [error, setError] = React.useState(null);
|
|
46
47
|
const { create, update } = useProductCategoryMutation();
|
|
48
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
47
49
|
React.useEffect(() => {
|
|
48
50
|
setState(initialState(mode));
|
|
49
51
|
setError(null);
|
|
@@ -53,11 +55,11 @@ export function ProductCategoryForm({ mode, onSuccess, onCancel }) {
|
|
|
53
55
|
event.preventDefault();
|
|
54
56
|
setError(null);
|
|
55
57
|
if (!state.name.trim()) {
|
|
56
|
-
setError(
|
|
58
|
+
setError(messages.productCategoryForm.validation.nameRequired);
|
|
57
59
|
return;
|
|
58
60
|
}
|
|
59
61
|
if (!state.slug.trim()) {
|
|
60
|
-
setError(
|
|
62
|
+
setError(messages.productCategoryForm.validation.slugRequired);
|
|
61
63
|
return;
|
|
62
64
|
}
|
|
63
65
|
try {
|
|
@@ -67,8 +69,10 @@ export function ProductCategoryForm({ mode, onSuccess, onCancel }) {
|
|
|
67
69
|
onSuccess?.(category);
|
|
68
70
|
}
|
|
69
71
|
catch (err) {
|
|
70
|
-
setError(err instanceof Error ? err.message :
|
|
72
|
+
setError(err instanceof Error ? err.message : messages.productCategoryForm.validation.saveFailed);
|
|
71
73
|
}
|
|
72
74
|
};
|
|
73
|
-
return (_jsxs("form", { "data-slot": "product-category-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, { htmlFor: "product-category-name", children:
|
|
75
|
+
return (_jsxs("form", { "data-slot": "product-category-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, { htmlFor: "product-category-name", children: messages.productCategoryForm.fields.name }), _jsx(Input, { id: "product-category-name", required: true, autoFocus: true, value: state.name, onChange: (event) => setState((prev) => ({ ...prev, name: event.target.value })), placeholder: messages.productCategoryForm.placeholders.name })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-category-slug", children: messages.productCategoryForm.fields.slug }), _jsx(Input, { id: "product-category-slug", required: true, value: state.slug, onChange: (event) => setState((prev) => ({ ...prev, slug: event.target.value })), placeholder: messages.productCategoryForm.placeholders.slug })] })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: messages.productCategoryForm.fields.parentCategory }), _jsx(ProductCategoryCombobox, { value: state.parentId === "__none__" ? null : state.parentId, onChange: (value) => setState((prev) => ({ ...prev, parentId: value ?? "__none__" })), excludeId: mode.kind === "edit" ? mode.category.id : null, placeholder: messages.productCategoryForm.placeholders.parentCategory })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-category-description", children: messages.productCategoryForm.fields.description }), _jsx(Textarea, { id: "product-category-description", value: state.description, onChange: (event) => setState((prev) => ({ ...prev, description: event.target.value })), placeholder: messages.productCategoryForm.placeholders.description })] }), _jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-category-sort-order", children: messages.productCategoryForm.fields.sortOrder }), _jsx(Input, { id: "product-category-sort-order", type: "number", value: state.sortOrder, onChange: (event) => setState((prev) => ({ ...prev, sortOrder: event.target.value })) })] }), _jsxs("div", { className: "flex items-center gap-2 pt-7", children: [_jsx(Switch, { checked: state.active, onCheckedChange: (active) => setState((prev) => ({ ...prev, active })) }), _jsx(Label, { children: messages.productCategoryForm.fields.active })] })] }), 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"
|
|
76
|
+
? messages.common.saveChanges
|
|
77
|
+
: messages.productCategoryForm.actions.createCategory] })] })] }));
|
|
74
78
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-category-list.d.ts","sourceRoot":"","sources":["../../src/components/product-category-list.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"product-category-list.d.ts","sourceRoot":"","sources":["../../src/components/product-category-list.tsx"],"names":[],"mappings":"AA+BA,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,wBAAgB,mBAAmB,CAAC,EAAE,QAAc,EAAE,GAAE,wBAA6B,2CAsKpF"}
|
|
@@ -8,6 +8,7 @@ import { Input } from "@voyantjs/ui/components/input";
|
|
|
8
8
|
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@voyantjs/ui/components/table";
|
|
9
9
|
import { CheckCircle2, Loader2, MoreHorizontal, Pencil, Plus, Search, Trash2 } from "lucide-react";
|
|
10
10
|
import * as React from "react";
|
|
11
|
+
import { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
11
12
|
import { ProductCategoryDialog } from "./product-category-dialog";
|
|
12
13
|
export function ProductCategoryList({ pageSize = 200 } = {}) {
|
|
13
14
|
const [search, setSearch] = React.useState("");
|
|
@@ -20,23 +21,28 @@ export function ProductCategoryList({ pageSize = 200 } = {}) {
|
|
|
20
21
|
offset,
|
|
21
22
|
});
|
|
22
23
|
const { remove } = useProductCategoryMutation();
|
|
24
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
23
25
|
const categories = data?.data ?? [];
|
|
24
26
|
const total = data?.total ?? 0;
|
|
25
27
|
const page = Math.floor(offset / pageSize) + 1;
|
|
26
28
|
const pageCount = Math.max(1, Math.ceil(total / pageSize));
|
|
27
29
|
const categoryById = new Map(categories.map((category) => [category.id, category]));
|
|
28
|
-
return (_jsxs("div", { "data-slot": "product-category-list", className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsxs("div", { className: "relative w-full max-w-sm", children: [_jsx(Search, { className: "absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" }), _jsx(Input, { placeholder:
|
|
30
|
+
return (_jsxs("div", { "data-slot": "product-category-list", className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-3", children: [_jsxs("div", { className: "relative w-full max-w-sm", children: [_jsx(Search, { className: "absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" }), _jsx(Input, { placeholder: messages.productCategoryList.searchPlaceholder, value: search, onChange: (event) => {
|
|
29
31
|
setSearch(event.target.value);
|
|
30
32
|
setOffset(0);
|
|
31
33
|
}, className: "pl-9" })] }), _jsxs(Button, { onClick: () => {
|
|
32
34
|
setEditing(undefined);
|
|
33
35
|
setDialogOpen(true);
|
|
34
|
-
}, children: [_jsx(Plus, { className: "mr-2 size-4", "aria-hidden": "true" }),
|
|
36
|
+
}, children: [_jsx(Plus, { className: "mr-2 size-4", "aria-hidden": "true" }), messages.productCategoryList.addCategory] })] }), _jsx("div", { className: "rounded-md border", children: _jsxs(Table, { children: [_jsx(TableHeader, { children: _jsxs(TableRow, { children: [_jsx(TableHead, { children: messages.productCategoryList.columns.name }), _jsx(TableHead, { children: messages.productCategoryList.columns.slug }), _jsx(TableHead, { children: messages.productCategoryList.columns.parent }), _jsx(TableHead, { children: messages.productCategoryList.columns.status }), _jsx(TableHead, { className: "w-[80px] text-right", children: messages.productCategoryList.columns.actions })] }) }), _jsx(TableBody, { children: isPending ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 5, className: "h-24 text-center", children: _jsx(Loader2, { className: "mx-auto size-4 animate-spin text-muted-foreground" }) }) })) : isError ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 5, className: "h-24 text-center text-sm text-destructive", children: messages.productCategoryList.loadingError }) })) : categories.length === 0 ? (_jsx(TableRow, { children: _jsx(TableCell, { colSpan: 5, className: "h-24 text-center text-sm text-muted-foreground", children: messages.productCategoryList.empty }) })) : (categories.map((category) => (_jsxs(TableRow, { children: [_jsx(TableCell, { className: "font-medium", children: category.name }), _jsx(TableCell, { children: category.slug }), _jsx(TableCell, { children: category.parentId
|
|
37
|
+
? (categoryById.get(category.parentId)?.name ?? messages.common.none)
|
|
38
|
+
: messages.common.none }), _jsx(TableCell, { children: category.active ? (_jsxs(Badge, { variant: "default", className: "gap-1", children: [_jsx(CheckCircle2, { className: "size-3.5" }), messages.common.active] })) : (_jsx(Badge, { variant: "secondary", children: messages.common.inactive })) }), _jsx(TableCell, { className: "text-right", children: _jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { className: "inline-flex size-8 items-center justify-center rounded-md text-muted-foreground outline-hidden hover:bg-accent hover:text-accent-foreground", children: _jsx(MoreHorizontal, { className: "size-4" }) }), _jsxs(DropdownMenuContent, { align: "end", children: [_jsxs(DropdownMenuItem, { onClick: () => {
|
|
35
39
|
setEditing(category);
|
|
36
40
|
setDialogOpen(true);
|
|
37
|
-
}, children: [_jsx(Pencil, { className: "size-4" }),
|
|
38
|
-
if (confirm(
|
|
41
|
+
}, children: [_jsx(Pencil, { className: "size-4" }), messages.productCategoryList.edit] }), _jsx(DropdownMenuSeparator, {}), _jsxs(DropdownMenuItem, { variant: "destructive", onClick: () => {
|
|
42
|
+
if (confirm(messages.productCategoryList.deleteConfirm)) {
|
|
39
43
|
remove.mutate(category.id);
|
|
40
44
|
}
|
|
41
|
-
}, children: [_jsx(Trash2, { className: "size-4" }),
|
|
45
|
+
}, children: [_jsx(Trash2, { className: "size-4" }), messages.productCategoryList.delete] })] })] }) })] }, category.id)))) })] }) }), _jsxs("div", { className: "flex items-center justify-between text-sm text-muted-foreground", children: [_jsx("span", { children: messages.productCategoryList.showingSummary
|
|
46
|
+
.replace("{count}", String(categories.length))
|
|
47
|
+
.replace("{total}", String(total)) }), _jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Button, { variant: "outline", size: "sm", disabled: offset === 0, onClick: () => setOffset((prev) => Math.max(0, prev - pageSize)), children: messages.common.previous }), _jsxs("span", { children: [messages.common.page, " ", page, " / ", pageCount] }), _jsx(Button, { variant: "outline", size: "sm", disabled: offset + pageSize >= total, onClick: () => setOffset((prev) => prev + pageSize), children: messages.common.next })] })] }), _jsx(ProductCategoryDialog, { open: dialogOpen, onOpenChange: setDialogOpen, category: editing })] }));
|
|
42
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-day-dialog.d.ts","sourceRoot":"","sources":["../../src/components/product-day-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"product-day-dialog.d.ts","sourceRoot":"","sources":["../../src/components/product-day-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAahE,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,gBAAgB,CAAA;IACtB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAA;CAC5C;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,GAAG,EACH,aAAa,EACb,SAAS,GACV,EAAE,qBAAqB,2CAgCvB"}
|
|
@@ -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 { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
4
5
|
import { ProductDayForm } from "./product-day-form";
|
|
5
6
|
export function ProductDayDialog({ open, onOpenChange, productId, day, nextDayNumber, onSuccess, }) {
|
|
6
7
|
const isEdit = Boolean(day);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
9
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "product-day-dialog", className: "sm:max-w-[640px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEdit
|
|
10
|
+
? messages.productDayDialog.titles.edit
|
|
11
|
+
: messages.productDayDialog.titles.create }), _jsx(DialogDescription, { children: isEdit
|
|
12
|
+
? messages.productDayDialog.descriptions.edit
|
|
13
|
+
: messages.productDayDialog.descriptions.create })] }), _jsx(ProductDayForm, { mode: day ? { kind: "edit", productId, day } : { kind: "create", productId, nextDayNumber }, onSuccess: (savedDay) => {
|
|
10
14
|
onSuccess?.(savedDay);
|
|
11
15
|
onOpenChange(false);
|
|
12
16
|
}, onCancel: () => onOpenChange(false) })] }) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-day-form.d.ts","sourceRoot":"","sources":["../../src/components/product-day-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAyB,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"product-day-form.d.ts","sourceRoot":"","sources":["../../src/components/product-day-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gBAAgB,EAAyB,MAAM,0BAA0B,CAAA;AAUvF,KAAK,IAAI,GACL;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAE9D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,IAAI,CAAA;IACV,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAA;IAC3C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AA2BD,wBAAgB,cAAc,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,mBAAmB,2CA0HhF"}
|
|
@@ -7,6 +7,7 @@ import { Label } from "@voyantjs/ui/components/label";
|
|
|
7
7
|
import { Textarea } from "@voyantjs/ui/components/textarea";
|
|
8
8
|
import { Loader2 } from "lucide-react";
|
|
9
9
|
import * as React from "react";
|
|
10
|
+
import { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
10
11
|
function initialState(mode) {
|
|
11
12
|
if (mode.kind === "edit") {
|
|
12
13
|
return {
|
|
@@ -27,6 +28,7 @@ export function ProductDayForm({ mode, onSuccess, onCancel }) {
|
|
|
27
28
|
const [state, setState] = React.useState(() => initialState(mode));
|
|
28
29
|
const [error, setError] = React.useState(null);
|
|
29
30
|
const { create, update } = useProductDayMutation();
|
|
31
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
30
32
|
React.useEffect(() => {
|
|
31
33
|
setState(initialState(mode));
|
|
32
34
|
setError(null);
|
|
@@ -40,7 +42,7 @@ export function ProductDayForm({ mode, onSuccess, onCancel }) {
|
|
|
40
42
|
setError(null);
|
|
41
43
|
const dayNumber = Number.parseInt(state.dayNumber || "0", 10);
|
|
42
44
|
if (!Number.isFinite(dayNumber) || dayNumber < 1) {
|
|
43
|
-
setError(
|
|
45
|
+
setError(messages.productDayForm.validation.dayNumberMin);
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
48
|
const payload = {
|
|
@@ -60,8 +62,12 @@ export function ProductDayForm({ mode, onSuccess, onCancel }) {
|
|
|
60
62
|
onSuccess?.(day);
|
|
61
63
|
}
|
|
62
64
|
catch (submissionError) {
|
|
63
|
-
setError(submissionError instanceof Error
|
|
65
|
+
setError(submissionError instanceof Error
|
|
66
|
+
? submissionError.message
|
|
67
|
+
: messages.productDayForm.validation.saveFailed);
|
|
64
68
|
}
|
|
65
69
|
};
|
|
66
|
-
return (_jsxs("form", { "data-slot": "product-day-form", onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-day-number", children:
|
|
70
|
+
return (_jsxs("form", { "data-slot": "product-day-form", onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-day-number", children: messages.productDayForm.fields.dayNumber }), _jsx(Input, { id: "product-day-number", type: "number", min: "1", autoFocus: true, required: true, value: state.dayNumber, onChange: (event) => field("dayNumber")(event.target.value) })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-day-location", children: messages.productDayForm.fields.location }), _jsx(Input, { id: "product-day-location", value: state.location, onChange: (event) => field("location")(event.target.value), placeholder: messages.productDayForm.placeholders.location })] })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-day-title", children: messages.productDayForm.fields.title }), _jsx(Input, { id: "product-day-title", value: state.title, onChange: (event) => field("title")(event.target.value), placeholder: messages.productDayForm.placeholders.title })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-day-description", children: messages.productDayForm.fields.description }), _jsx(Textarea, { id: "product-day-description", value: state.description, onChange: (event) => field("description")(event.target.value), placeholder: messages.productDayForm.placeholders.description })] }), 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, disabled: isSubmitting, 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 === "create"
|
|
71
|
+
? messages.productDayForm.actions.addDay
|
|
72
|
+
: messages.productDayForm.actions.saveDay] })] })] }));
|
|
67
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-itinerary-dialog.d.ts","sourceRoot":"","sources":["../../src/components/product-itinerary-dialog.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"product-itinerary-dialog.d.ts","sourceRoot":"","sources":["../../src/components/product-itinerary-dialog.tsx"],"names":[],"mappings":"AAmBA,KAAK,aAAa,GAAG;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAA;CAC1C;AAED,wBAAgB,sBAAsB,CAAC,EACrC,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,SAAS,EACT,cAAc,EACd,SAAS,GACV,EAAE,2BAA2B,2CAuI7B"}
|
|
@@ -8,6 +8,7 @@ import { Input } from "@voyantjs/ui/components/input";
|
|
|
8
8
|
import { Label } from "@voyantjs/ui/components/label";
|
|
9
9
|
import { Loader2 } from "lucide-react";
|
|
10
10
|
import * as React from "react";
|
|
11
|
+
import { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
11
12
|
export function ProductItineraryDialog({ open, onOpenChange, productId, itinerary, itineraryCount, onSuccess, }) {
|
|
12
13
|
const isEditing = !!itinerary;
|
|
13
14
|
const isFirstItinerary = !isEditing && itineraryCount === 0;
|
|
@@ -15,6 +16,7 @@ export function ProductItineraryDialog({ open, onOpenChange, productId, itinerar
|
|
|
15
16
|
const [name, setName] = React.useState("");
|
|
16
17
|
const [isDefault, setIsDefault] = React.useState(false);
|
|
17
18
|
const [error, setError] = React.useState(null);
|
|
19
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
18
20
|
const { create, update } = useProductItineraryMutation();
|
|
19
21
|
const pending = create.isPending || update.isPending;
|
|
20
22
|
React.useEffect(() => {
|
|
@@ -35,7 +37,7 @@ export function ProductItineraryDialog({ open, onOpenChange, productId, itinerar
|
|
|
35
37
|
setError(null);
|
|
36
38
|
const trimmed = name.trim();
|
|
37
39
|
if (!trimmed) {
|
|
38
|
-
setError(
|
|
40
|
+
setError(messages.productItineraryDialog.validation.nameRequired);
|
|
39
41
|
return;
|
|
40
42
|
}
|
|
41
43
|
try {
|
|
@@ -68,10 +70,16 @@ export function ProductItineraryDialog({ open, onOpenChange, productId, itinerar
|
|
|
68
70
|
onOpenChange(false);
|
|
69
71
|
}
|
|
70
72
|
catch (submissionError) {
|
|
71
|
-
setError(submissionError instanceof Error
|
|
73
|
+
setError(submissionError instanceof Error
|
|
74
|
+
? submissionError.message
|
|
75
|
+
: messages.productItineraryDialog.validation.saveFailed);
|
|
72
76
|
}
|
|
73
77
|
};
|
|
74
|
-
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "product-itinerary-dialog", className: "sm:max-w-md", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEditing
|
|
75
|
-
?
|
|
76
|
-
:
|
|
78
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "product-itinerary-dialog", className: "sm:max-w-md", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEditing
|
|
79
|
+
? messages.productItineraryDialog.titles.edit
|
|
80
|
+
: messages.productItineraryDialog.titles.create }), _jsx(DialogDescription, { children: isEditing
|
|
81
|
+
? messages.productItineraryDialog.descriptions.edit
|
|
82
|
+
: messages.productItineraryDialog.descriptions.create })] }), _jsxs("form", { className: "flex flex-col gap-4", onSubmit: handleSubmit, children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-itinerary-name", children: messages.productItineraryDialog.fields.name }), _jsx(Input, { id: "product-itinerary-name", autoFocus: true, value: name, onChange: (event) => setName(event.target.value), placeholder: messages.productItineraryDialog.placeholders.name })] }), _jsxs("div", { className: "flex items-start gap-2", children: [_jsx(Checkbox, { id: "product-itinerary-default", checked: isDefault, disabled: defaultLocked || isFirstItinerary, onCheckedChange: (checked) => setIsDefault(checked === true) }), _jsxs("div", { className: "flex flex-col gap-1", children: [_jsx(Label, { htmlFor: "product-itinerary-default", className: "text-sm font-normal", children: messages.productItineraryDialog.fields.defaultItinerary }), defaultLocked ? (_jsx("p", { className: "text-xs text-muted-foreground", children: messages.productItineraryDialog.fields.notesDefaultLocked })) : isFirstItinerary ? (_jsx("p", { className: "text-xs text-muted-foreground", children: messages.productItineraryDialog.fields.notesFirstDefault })) : null] })] }), error ? _jsx("p", { className: "text-sm text-destructive", children: error }) : null, _jsxs("div", { className: "flex items-center justify-end gap-2", children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: messages.common.cancel }), _jsxs(Button, { type: "submit", disabled: pending, children: [pending ? _jsx(Loader2, { className: "mr-2 size-4 animate-spin", "aria-hidden": "true" }) : null, isEditing
|
|
83
|
+
? messages.common.saveChanges
|
|
84
|
+
: messages.productItineraryDialog.actions.createItinerary] })] })] })] }) }));
|
|
77
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-media-dialog.d.ts","sourceRoot":"","sources":["../../src/components/product-media-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"product-media-dialog.d.ts","sourceRoot":"","sources":["../../src/components/product-media-dialog.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAA;AAalE,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,OAAO,CAAA;IACb,YAAY,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,kBAAkB,CAAA;IAC1B,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAA;CAChD;AAED,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,KAAK,EACL,KAAK,EACL,SAAS,GACV,EAAE,uBAAuB,2CA8BzB"}
|
|
@@ -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 { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
4
5
|
import { ProductMediaForm } from "./product-media-form";
|
|
5
6
|
export function ProductMediaDialog({ open, onOpenChange, productId, dayId, media, onSuccess, }) {
|
|
6
7
|
const isEdit = Boolean(media);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
9
|
+
return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-slot": "product-media-dialog", className: "sm:max-w-[720px]", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isEdit
|
|
10
|
+
? messages.productMediaDialog.titles.edit
|
|
11
|
+
: messages.productMediaDialog.titles.create }), _jsx(DialogDescription, { children: isEdit
|
|
12
|
+
? messages.productMediaDialog.descriptions.edit
|
|
13
|
+
: messages.productMediaDialog.descriptions.create })] }), _jsx(ProductMediaForm, { mode: media ? { kind: "edit", media } : { kind: "create", productId, dayId }, onSuccess: (savedMedia) => {
|
|
10
14
|
onSuccess?.(savedMedia);
|
|
11
15
|
onOpenChange(false);
|
|
12
16
|
}, onCancel: () => onOpenChange(false) })] }) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-media-form.d.ts","sourceRoot":"","sources":["../../src/components/product-media-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,kBAAkB,EAA2B,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"product-media-form.d.ts","sourceRoot":"","sources":["../../src/components/product-media-form.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,kBAAkB,EAA2B,MAAM,0BAA0B,CAAA;AAoB3F,KAAK,IAAI,GACL;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,kBAAkB,CAAA;CAAE,CAAA;AAE/C,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,IAAI,CAAA;IACV,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAA;IAC/C,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;CACtB;AAgDD,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,qBAAqB,2CAuMpF"}
|
|
@@ -9,10 +9,11 @@ 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 { useProductsUiMessagesOrDefault } from "../i18n/provider";
|
|
12
13
|
const MEDIA_TYPES = [
|
|
13
|
-
{ value: "image"
|
|
14
|
-
{ value: "video"
|
|
15
|
-
{ value: "document"
|
|
14
|
+
{ value: "image" },
|
|
15
|
+
{ value: "video" },
|
|
16
|
+
{ value: "document" },
|
|
16
17
|
];
|
|
17
18
|
function initialState(mode) {
|
|
18
19
|
if (mode.kind === "edit") {
|
|
@@ -44,6 +45,7 @@ export function ProductMediaForm({ mode, onSuccess, onCancel }) {
|
|
|
44
45
|
const [state, setState] = React.useState(() => initialState(mode));
|
|
45
46
|
const [error, setError] = React.useState(null);
|
|
46
47
|
const { create, update } = useProductMediaMutation();
|
|
48
|
+
const messages = useProductsUiMessagesOrDefault();
|
|
47
49
|
React.useEffect(() => {
|
|
48
50
|
setState(initialState(mode));
|
|
49
51
|
setError(null);
|
|
@@ -56,11 +58,11 @@ export function ProductMediaForm({ mode, onSuccess, onCancel }) {
|
|
|
56
58
|
event.preventDefault();
|
|
57
59
|
setError(null);
|
|
58
60
|
if (!state.name.trim()) {
|
|
59
|
-
setError(
|
|
61
|
+
setError(messages.productMediaForm.validation.nameRequired);
|
|
60
62
|
return;
|
|
61
63
|
}
|
|
62
64
|
if (!state.url.trim()) {
|
|
63
|
-
setError(
|
|
65
|
+
setError(messages.productMediaForm.validation.urlRequired);
|
|
64
66
|
return;
|
|
65
67
|
}
|
|
66
68
|
const payload = {
|
|
@@ -85,8 +87,15 @@ export function ProductMediaForm({ mode, onSuccess, onCancel }) {
|
|
|
85
87
|
onSuccess?.(media);
|
|
86
88
|
}
|
|
87
89
|
catch (submissionError) {
|
|
88
|
-
setError(submissionError instanceof Error
|
|
90
|
+
setError(submissionError instanceof Error
|
|
91
|
+
? submissionError.message
|
|
92
|
+
: messages.productMediaForm.validation.saveFailed);
|
|
89
93
|
}
|
|
90
94
|
};
|
|
91
|
-
return (_jsxs("form", { "data-slot": "product-media-form", onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children:
|
|
95
|
+
return (_jsxs("form", { "data-slot": "product-media-form", onSubmit: handleSubmit, className: "flex flex-col gap-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { children: messages.productMediaForm.fields.mediaType }), _jsxs(Select, { items: MEDIA_TYPES.map((type) => ({
|
|
96
|
+
label: messages.common.mediaTypeLabels[type.value],
|
|
97
|
+
value: type.value,
|
|
98
|
+
})), value: state.mediaType, onValueChange: (value) => field("mediaType")(value), children: [_jsx(SelectTrigger, { className: "w-full", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: MEDIA_TYPES.map((type) => (_jsx(SelectItem, { value: type.value, children: messages.common.mediaTypeLabels[type.value] }, type.value))) })] })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-media-name", children: messages.productMediaForm.fields.name }), _jsx(Input, { id: "product-media-name", autoFocus: true, required: true, value: state.name, onChange: (event) => field("name")(event.target.value), placeholder: messages.productMediaForm.placeholders.name })] })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-media-url", children: messages.productMediaForm.fields.url }), _jsx(Input, { id: "product-media-url", type: "url", required: true, value: state.url, onChange: (event) => field("url")(event.target.value), placeholder: messages.productMediaForm.placeholders.url })] }), _jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-media-storage-key", children: messages.productMediaForm.fields.storageKey }), _jsx(Input, { id: "product-media-storage-key", value: state.storageKey, onChange: (event) => field("storageKey")(event.target.value) })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-media-mime-type", children: messages.productMediaForm.fields.mimeType }), _jsx(Input, { id: "product-media-mime-type", value: state.mimeType, onChange: (event) => field("mimeType")(event.target.value), placeholder: messages.productMediaForm.placeholders.mimeType })] })] }), _jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-3", children: [_jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-media-file-size", children: messages.productMediaForm.fields.fileSize }), _jsx(Input, { id: "product-media-file-size", type: "number", min: "0", value: state.fileSize, onChange: (event) => field("fileSize")(event.target.value) })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-media-sort-order", children: messages.productMediaForm.fields.sortOrder }), _jsx(Input, { id: "product-media-sort-order", type: "number", value: state.sortOrder, onChange: (event) => field("sortOrder")(event.target.value) })] }), _jsxs("div", { className: "flex items-end gap-2 pb-2", children: [_jsx(Switch, { checked: state.isCover, onCheckedChange: (checked) => field("isCover")(checked) }), _jsx(Label, { children: messages.productMediaForm.fields.coverMedia })] })] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx(Label, { htmlFor: "product-media-alt-text", children: messages.productMediaForm.fields.altText }), _jsx(Textarea, { id: "product-media-alt-text", value: state.altText, onChange: (event) => field("altText")(event.target.value), placeholder: messages.productMediaForm.placeholders.altText })] }), 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, disabled: isSubmitting, 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 === "create"
|
|
99
|
+
? messages.productMediaForm.actions.addMedia
|
|
100
|
+
: messages.productMediaForm.actions.saveMedia] })] })] }));
|
|
92
101
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-media-section.d.ts","sourceRoot":"","sources":["../../src/components/product-media-section.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"product-media-section.d.ts","sourceRoot":"","sources":["../../src/components/product-media-section.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,0BAA0B,CAAA;AAwBjC,MAAM,WAAW,wBAAwB;IACvC,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,SAAS,CAAC,EAAE,kBAAkB,CAAC,WAAW,CAAC,CAAA;IAC3C,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,MAAM,yBAAyB,GAAG,CACtC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,KAC3C,OAAO,CAAC,wBAAwB,CAAC,CAAA;AAEtC,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,WAAW,CAAC,EAAE,yBAAyB,CAAA;IACvC,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,wBAAgB,mBAAmB,CAAC,EAClC,SAAS,EACT,KAAK,EACL,KAAK,EACL,WAAW,EACX,OAAe,EACf,WAAW,EACX,YAAgD,GACjD,EAAE,wBAAwB,2CAgQ1B"}
|