@medusajs/draft-order 0.0.1
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/.medusa/server/src/admin/components/common/action-menu.js +77 -0
- package/.medusa/server/src/admin/components/common/conditional-tooltip.js +15 -0
- package/.medusa/server/src/admin/components/common/data-table.js +249 -0
- package/.medusa/server/src/admin/components/common/form.js +151 -0
- package/.medusa/server/src/admin/components/common/inline-tip.js +42 -0
- package/.medusa/server/src/admin/components/common/keybound-form.js +32 -0
- package/.medusa/server/src/admin/components/common/page-skeleton.js +51 -0
- package/.medusa/server/src/admin/components/common/thumbnail.js +15 -0
- package/.medusa/server/src/admin/components/draft-orders/activity-section.js +205 -0
- package/.medusa/server/src/admin/components/draft-orders/customer-section.js +165 -0
- package/.medusa/server/src/admin/components/draft-orders/general-section.js +36 -0
- package/.medusa/server/src/admin/components/draft-orders/json-view-section.js +140 -0
- package/.medusa/server/src/admin/components/draft-orders/metadata-section.js +28 -0
- package/.medusa/server/src/admin/components/draft-orders/shipping-section.js +211 -0
- package/.medusa/server/src/admin/components/draft-orders/summary-section.js +148 -0
- package/.medusa/server/src/admin/components/inputs/combobox.js +311 -0
- package/.medusa/server/src/admin/components/inputs/country-select.js +59 -0
- package/.medusa/server/src/admin/components/inputs/number-input.js +100 -0
- package/.medusa/server/src/admin/components/inputs/switch-block.js +30 -0
- package/.medusa/server/src/admin/components/modals/index.js +19 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/route-drawer.js +57 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/route-focus-modal.js +71 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/route-modal-form.js +60 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-provider.js +30 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/use-route-modal.js +12 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/stacked-drawer.js +55 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/stacked-focus-modal.js +63 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-provider.js +47 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/use-stacked-modal.js +14 -0
- package/.medusa/server/src/admin/components/utilities/generic-forward-ref.js +7 -0
- package/.medusa/server/src/admin/hooks/api/customers.js +53 -0
- package/.medusa/server/src/admin/hooks/api/draft-orders.js +161 -0
- package/.medusa/server/src/admin/hooks/api/orders.js +274 -0
- package/.medusa/server/src/admin/hooks/api/product-variants.js +21 -0
- package/.medusa/server/src/admin/hooks/api/regions.js +35 -0
- package/.medusa/server/src/admin/hooks/api/sales-channels.js +35 -0
- package/.medusa/server/src/admin/hooks/api/shipping-options.js +35 -0
- package/.medusa/server/src/admin/hooks/api/users.js +26 -0
- package/.medusa/server/src/admin/hooks/common/use-combobox-data.js +61 -0
- package/.medusa/server/src/admin/hooks/common/use-data-table-date-filters.js +89 -0
- package/.medusa/server/src/admin/hooks/common/use-debounced-search.js +22 -0
- package/.medusa/server/src/admin/hooks/common/use-query-params.js +14 -0
- package/.medusa/server/src/admin/hooks/order-edits/use-cancel-order-edit.js +25 -0
- package/.medusa/server/src/admin/hooks/order-edits/use-initiate-order-edit.js +39 -0
- package/.medusa/server/src/admin/lib/data/countries.js +1762 -0
- package/.medusa/server/src/admin/lib/data/currencies.js +36 -0
- package/.medusa/server/src/admin/lib/queries/draft-order-details.js +1 -0
- package/.medusa/server/src/admin/lib/queries/sdk.js +10 -0
- package/.medusa/server/src/admin/lib/schemas/address.js +16 -0
- package/.medusa/server/src/admin/lib/utils/address-utils.js +57 -0
- package/.medusa/server/src/admin/lib/utils/date-utils.js +27 -0
- package/.medusa/server/src/admin/lib/utils/order-utils.js +13 -0
- package/.medusa/server/src/admin/routes/draft-orders/@create/page.js +659 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@billing-address/page.js +228 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@custom-items/page.js +38 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@email/page.js +89 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@items/page.js +576 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@metadata/page.js +338 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@promotions/page.js +70 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@sales-channel/page.js +113 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@shipping/page.js +465 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@shipping-address/page.js +241 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/page.js +70 -0
- package/.medusa/server/src/admin/routes/draft-orders/page.js +148 -0
- package/.medusa/server/src/api/admin/draft-orders/[id]/convert/route.js +18 -0
- package/.medusa/server/src/types/http/draft-orders/payloads.js +3 -0
- package/.medusa/server/src/types/http/draft-orders/responses.js +3 -0
- package/.medusa/server/src/types/http/orders/entity.js +3 -0
- package/.medusa/server/src/types/http/orders/requests.js +3 -0
- package/.medusa/server/src/workflows/draft-orders/convert-draft-order-workflow.js +54 -0
- package/.medusa/server/tailwind.config.js +12 -0
- package/README.md +64 -0
- package/package.json +104 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { DropdownMenu, clx, IconButton } from "@medusajs/ui";
|
|
3
|
+
import { EllipsisHorizontal } from "@medusajs/icons";
|
|
4
|
+
import { Link } from "react-router-dom";
|
|
5
|
+
import { ConditionalTooltip } from "./conditional-tooltip.js";
|
|
6
|
+
const ActionMenu = ({
|
|
7
|
+
groups,
|
|
8
|
+
variant = "transparent",
|
|
9
|
+
children
|
|
10
|
+
}) => {
|
|
11
|
+
const inner = children ?? /* @__PURE__ */ jsx(IconButton, { size: "small", variant, children: /* @__PURE__ */ jsx(EllipsisHorizontal, {}) });
|
|
12
|
+
return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
13
|
+
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: inner }),
|
|
14
|
+
/* @__PURE__ */ jsx(DropdownMenu.Content, { children: groups.map((group, index) => {
|
|
15
|
+
if (!group.actions.length) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const isLast = index === groups.length - 1;
|
|
19
|
+
return /* @__PURE__ */ jsxs(DropdownMenu.Group, { children: [
|
|
20
|
+
group.actions.map((action, index2) => {
|
|
21
|
+
const Wrapper = action.disabledTooltip ? ({ children: children2 }) => /* @__PURE__ */ jsx(
|
|
22
|
+
ConditionalTooltip,
|
|
23
|
+
{
|
|
24
|
+
showTooltip: action.disabled,
|
|
25
|
+
content: action.disabledTooltip,
|
|
26
|
+
side: "right",
|
|
27
|
+
children: /* @__PURE__ */ jsx("div", { children: children2 })
|
|
28
|
+
}
|
|
29
|
+
) : "div";
|
|
30
|
+
if (action.onClick) {
|
|
31
|
+
return /* @__PURE__ */ jsx(Wrapper, { children: /* @__PURE__ */ jsxs(
|
|
32
|
+
DropdownMenu.Item,
|
|
33
|
+
{
|
|
34
|
+
disabled: action.disabled,
|
|
35
|
+
onClick: (e) => {
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
action.onClick();
|
|
38
|
+
},
|
|
39
|
+
className: clx(
|
|
40
|
+
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
|
|
41
|
+
{
|
|
42
|
+
"[&_svg]:text-ui-fg-disabled": action.disabled
|
|
43
|
+
}
|
|
44
|
+
),
|
|
45
|
+
children: [
|
|
46
|
+
action.icon,
|
|
47
|
+
/* @__PURE__ */ jsx("span", { children: action.label })
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
) }, index2);
|
|
51
|
+
}
|
|
52
|
+
return /* @__PURE__ */ jsx(Wrapper, { children: /* @__PURE__ */ jsx(
|
|
53
|
+
DropdownMenu.Item,
|
|
54
|
+
{
|
|
55
|
+
className: clx(
|
|
56
|
+
"[&_svg]:text-ui-fg-subtle flex items-center gap-x-2",
|
|
57
|
+
{
|
|
58
|
+
"[&_svg]:text-ui-fg-disabled": action.disabled
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
asChild: true,
|
|
62
|
+
disabled: action.disabled,
|
|
63
|
+
children: /* @__PURE__ */ jsxs(Link, { to: action.to, onClick: (e) => e.stopPropagation(), children: [
|
|
64
|
+
action.icon,
|
|
65
|
+
/* @__PURE__ */ jsx("span", { children: action.label })
|
|
66
|
+
] })
|
|
67
|
+
}
|
|
68
|
+
) }, index2);
|
|
69
|
+
}),
|
|
70
|
+
!isLast && /* @__PURE__ */ jsx(DropdownMenu.Separator, {})
|
|
71
|
+
] }, index);
|
|
72
|
+
}) })
|
|
73
|
+
] });
|
|
74
|
+
};
|
|
75
|
+
export {
|
|
76
|
+
ActionMenu
|
|
77
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Tooltip } from "@medusajs/ui";
|
|
3
|
+
const ConditionalTooltip = ({
|
|
4
|
+
children,
|
|
5
|
+
showTooltip = false,
|
|
6
|
+
...props
|
|
7
|
+
}) => {
|
|
8
|
+
if (showTooltip) {
|
|
9
|
+
return /* @__PURE__ */ jsx(Tooltip, { ...props, children });
|
|
10
|
+
}
|
|
11
|
+
return children;
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
ConditionalTooltip
|
|
15
|
+
};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useDataTable, DataTable as DataTable$1, clx, Heading, Text, Button } from "@medusajs/ui";
|
|
3
|
+
import { useState, useCallback } from "react";
|
|
4
|
+
import { useSearchParams, useNavigate, Link } from "react-router-dom";
|
|
5
|
+
import { useQueryParams } from "../../hooks/common/use-query-params.js";
|
|
6
|
+
import { ActionMenu } from "./action-menu.js";
|
|
7
|
+
const DataTable = ({
|
|
8
|
+
data = [],
|
|
9
|
+
columns,
|
|
10
|
+
filters,
|
|
11
|
+
commands,
|
|
12
|
+
action,
|
|
13
|
+
actionMenu,
|
|
14
|
+
getRowId,
|
|
15
|
+
rowCount = 0,
|
|
16
|
+
enablePagination = true,
|
|
17
|
+
enableSearch = true,
|
|
18
|
+
autoFocusSearch = false,
|
|
19
|
+
rowHref,
|
|
20
|
+
heading,
|
|
21
|
+
subHeading,
|
|
22
|
+
prefix,
|
|
23
|
+
pageSize = 10,
|
|
24
|
+
emptyState,
|
|
25
|
+
rowSelection,
|
|
26
|
+
isLoading = false,
|
|
27
|
+
layout = "auto"
|
|
28
|
+
}) => {
|
|
29
|
+
const enableFiltering = filters && filters.length > 0;
|
|
30
|
+
const enableCommands = commands && commands.length > 0;
|
|
31
|
+
const enableSorting = columns.some((column) => column.enableSorting);
|
|
32
|
+
const filterIds = (filters == null ? void 0 : filters.map((f) => f.id)) ?? [];
|
|
33
|
+
const prefixedFilterIds = filterIds.map((id) => getQueryParamKey(id, prefix));
|
|
34
|
+
const { offset, order, q, ...filterParams } = useQueryParams(
|
|
35
|
+
[
|
|
36
|
+
...filterIds,
|
|
37
|
+
...enableSorting ? ["order"] : [],
|
|
38
|
+
...enableSearch ? ["q"] : [],
|
|
39
|
+
...enablePagination ? ["offset"] : []
|
|
40
|
+
],
|
|
41
|
+
prefix
|
|
42
|
+
);
|
|
43
|
+
const [_, setSearchParams] = useSearchParams();
|
|
44
|
+
const [search, setSearch] = useState(q ?? "");
|
|
45
|
+
const handleSearchChange = (value) => {
|
|
46
|
+
setSearch(value);
|
|
47
|
+
setSearchParams((prev) => {
|
|
48
|
+
if (value) {
|
|
49
|
+
prev.set(getQueryParamKey("q", prefix), value);
|
|
50
|
+
} else {
|
|
51
|
+
prev.delete(getQueryParamKey("q", prefix));
|
|
52
|
+
}
|
|
53
|
+
return prev;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
const [pagination, setPagination] = useState(
|
|
57
|
+
offset ? parsePaginationState(offset, pageSize) : { pageIndex: 0, pageSize }
|
|
58
|
+
);
|
|
59
|
+
const handlePaginationChange = (value) => {
|
|
60
|
+
setPagination(value);
|
|
61
|
+
setSearchParams((prev) => {
|
|
62
|
+
if (value.pageIndex === 0) {
|
|
63
|
+
prev.delete(getQueryParamKey("offset", prefix));
|
|
64
|
+
} else {
|
|
65
|
+
prev.set(
|
|
66
|
+
getQueryParamKey("offset", prefix),
|
|
67
|
+
transformPaginationState(value).toString()
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return prev;
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const [filtering, setFiltering] = useState(
|
|
74
|
+
parseFilterState(filterIds, filterParams)
|
|
75
|
+
);
|
|
76
|
+
const handleFilteringChange = (value) => {
|
|
77
|
+
setFiltering(value);
|
|
78
|
+
setSearchParams((prev) => {
|
|
79
|
+
Array.from(prev.keys()).forEach((key) => {
|
|
80
|
+
if (prefixedFilterIds.includes(key) && !(key in value)) {
|
|
81
|
+
prev.delete(key);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.entries(value).forEach(([key, filter]) => {
|
|
85
|
+
if (prefixedFilterIds.includes(getQueryParamKey(key, prefix)) && filter) {
|
|
86
|
+
prev.set(getQueryParamKey(key, prefix), JSON.stringify(filter));
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return prev;
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
const [sorting, setSorting] = useState(
|
|
93
|
+
order ? parseSortingState(order) : null
|
|
94
|
+
);
|
|
95
|
+
const handleSortingChange = (value) => {
|
|
96
|
+
setSorting(value);
|
|
97
|
+
setSearchParams((prev) => {
|
|
98
|
+
if (value) {
|
|
99
|
+
const valueToStore = transformSortingState(value);
|
|
100
|
+
prev.set(getQueryParamKey("order", prefix), valueToStore);
|
|
101
|
+
} else {
|
|
102
|
+
prev.delete(getQueryParamKey("order", prefix));
|
|
103
|
+
}
|
|
104
|
+
return prev;
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
const navigate = useNavigate();
|
|
108
|
+
const onRowClick = useCallback(
|
|
109
|
+
(event, row) => {
|
|
110
|
+
if (!rowHref) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const href = rowHref(row);
|
|
114
|
+
if (event.metaKey || event.ctrlKey || event.button === 1) {
|
|
115
|
+
window.open(href, "_blank", "noreferrer");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (event.shiftKey) {
|
|
119
|
+
window.open(href, void 0, "noreferrer");
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
navigate(href);
|
|
123
|
+
},
|
|
124
|
+
[navigate, rowHref]
|
|
125
|
+
);
|
|
126
|
+
const instance = useDataTable({
|
|
127
|
+
data,
|
|
128
|
+
columns,
|
|
129
|
+
filters,
|
|
130
|
+
commands,
|
|
131
|
+
rowCount,
|
|
132
|
+
getRowId,
|
|
133
|
+
onRowClick: rowHref ? onRowClick : void 0,
|
|
134
|
+
pagination: enablePagination ? {
|
|
135
|
+
state: pagination,
|
|
136
|
+
onPaginationChange: handlePaginationChange
|
|
137
|
+
} : void 0,
|
|
138
|
+
filtering: enableFiltering ? {
|
|
139
|
+
state: filtering,
|
|
140
|
+
onFilteringChange: handleFilteringChange
|
|
141
|
+
} : void 0,
|
|
142
|
+
sorting: enableSorting ? {
|
|
143
|
+
state: sorting,
|
|
144
|
+
onSortingChange: handleSortingChange
|
|
145
|
+
} : void 0,
|
|
146
|
+
search: enableSearch ? {
|
|
147
|
+
state: search,
|
|
148
|
+
onSearchChange: handleSearchChange
|
|
149
|
+
} : void 0,
|
|
150
|
+
rowSelection,
|
|
151
|
+
isLoading
|
|
152
|
+
});
|
|
153
|
+
const shouldRenderHeading = heading || subHeading;
|
|
154
|
+
return /* @__PURE__ */ jsxs(
|
|
155
|
+
DataTable$1,
|
|
156
|
+
{
|
|
157
|
+
instance,
|
|
158
|
+
className: clx({
|
|
159
|
+
"h-full [&_tr]:last-of-type:!border-b": layout === "fill"
|
|
160
|
+
}),
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ jsxs(DataTable$1.Toolbar, { className: "flex flex-col items-start justify-between gap-2 md:flex-row md:items-center", children: [
|
|
163
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full items-center justify-between gap-2", children: [
|
|
164
|
+
shouldRenderHeading && /* @__PURE__ */ jsxs("div", { children: [
|
|
165
|
+
heading && /* @__PURE__ */ jsx(Heading, { children: heading }),
|
|
166
|
+
subHeading && /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: subHeading })
|
|
167
|
+
] }),
|
|
168
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2 md:hidden", children: [
|
|
169
|
+
enableFiltering && /* @__PURE__ */ jsx(DataTable$1.FilterMenu, { tooltip: "Filter" }),
|
|
170
|
+
/* @__PURE__ */ jsx(DataTable$1.SortingMenu, { tooltip: "Sort" }),
|
|
171
|
+
actionMenu && /* @__PURE__ */ jsx(ActionMenu, { variant: "primary", ...actionMenu }),
|
|
172
|
+
action && /* @__PURE__ */ jsx(DataTableAction, { ...action })
|
|
173
|
+
] })
|
|
174
|
+
] }),
|
|
175
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-2 md:justify-end", children: [
|
|
176
|
+
enableSearch && /* @__PURE__ */ jsx("div", { className: "w-full md:w-auto", children: /* @__PURE__ */ jsx(
|
|
177
|
+
DataTable$1.Search,
|
|
178
|
+
{
|
|
179
|
+
"data-modal-id": "modal-search-input",
|
|
180
|
+
placeholder: "Search",
|
|
181
|
+
autoFocus: autoFocusSearch
|
|
182
|
+
}
|
|
183
|
+
) }),
|
|
184
|
+
/* @__PURE__ */ jsxs("div", { className: "hidden items-center gap-x-2 md:flex", children: [
|
|
185
|
+
enableFiltering && /* @__PURE__ */ jsx(DataTable$1.FilterMenu, { tooltip: "Filter" }),
|
|
186
|
+
/* @__PURE__ */ jsx(DataTable$1.SortingMenu, { tooltip: "Sort" }),
|
|
187
|
+
actionMenu && /* @__PURE__ */ jsx(ActionMenu, { variant: "primary", ...actionMenu }),
|
|
188
|
+
action && /* @__PURE__ */ jsx(DataTableAction, { ...action })
|
|
189
|
+
] })
|
|
190
|
+
] })
|
|
191
|
+
] }),
|
|
192
|
+
/* @__PURE__ */ jsx(DataTable$1.Table, { emptyState }),
|
|
193
|
+
enablePagination && /* @__PURE__ */ jsx(DataTable$1.Pagination, {}),
|
|
194
|
+
enableCommands && /* @__PURE__ */ jsx(DataTable$1.CommandBar, { selectedLabel: (count) => `${count} selected` })
|
|
195
|
+
]
|
|
196
|
+
}
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
function transformSortingState(value) {
|
|
200
|
+
return value.desc ? `-${value.id}` : value.id;
|
|
201
|
+
}
|
|
202
|
+
function parseSortingState(value) {
|
|
203
|
+
return value.startsWith("-") ? { id: value.slice(1), desc: true } : { id: value, desc: false };
|
|
204
|
+
}
|
|
205
|
+
function transformPaginationState(value) {
|
|
206
|
+
return value.pageIndex * value.pageSize;
|
|
207
|
+
}
|
|
208
|
+
function parsePaginationState(value, pageSize) {
|
|
209
|
+
const offset = parseInt(value);
|
|
210
|
+
return {
|
|
211
|
+
pageIndex: Math.floor(offset / pageSize),
|
|
212
|
+
pageSize
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function parseFilterState(filterIds, value) {
|
|
216
|
+
if (!value) {
|
|
217
|
+
return {};
|
|
218
|
+
}
|
|
219
|
+
const filters = {};
|
|
220
|
+
for (const id of filterIds) {
|
|
221
|
+
const filterValue = value[id];
|
|
222
|
+
if (filterValue) {
|
|
223
|
+
filters[id] = JSON.parse(filterValue);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return filters;
|
|
227
|
+
}
|
|
228
|
+
function getQueryParamKey(key, prefix) {
|
|
229
|
+
return prefix ? `${prefix}_${key}` : key;
|
|
230
|
+
}
|
|
231
|
+
const DataTableAction = ({
|
|
232
|
+
label,
|
|
233
|
+
disabled,
|
|
234
|
+
...props
|
|
235
|
+
}) => {
|
|
236
|
+
const buttonProps = {
|
|
237
|
+
size: "small",
|
|
238
|
+
disabled: disabled ?? false,
|
|
239
|
+
type: "button",
|
|
240
|
+
variant: "secondary"
|
|
241
|
+
};
|
|
242
|
+
if ("to" in props) {
|
|
243
|
+
return /* @__PURE__ */ jsx(Button, { ...buttonProps, asChild: true, children: /* @__PURE__ */ jsx(Link, { to: props.to, children: label }) });
|
|
244
|
+
}
|
|
245
|
+
return /* @__PURE__ */ jsx(Button, { ...buttonProps, onClick: props.onClick, children: label });
|
|
246
|
+
};
|
|
247
|
+
export {
|
|
248
|
+
DataTable
|
|
249
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { InformationCircleSolid } from "@medusajs/icons";
|
|
3
|
+
import { clx, Label as Label$1, Tooltip, Text, Hint as Hint$1 } from "@medusajs/ui";
|
|
4
|
+
import { Slot } from "radix-ui";
|
|
5
|
+
import { createContext, forwardRef, useId, useContext } from "react";
|
|
6
|
+
import { FormProvider, Controller, useFormContext, useFormState } from "react-hook-form";
|
|
7
|
+
const Provider = FormProvider;
|
|
8
|
+
const FormFieldContext = createContext(
|
|
9
|
+
{}
|
|
10
|
+
);
|
|
11
|
+
const Field = ({
|
|
12
|
+
...props
|
|
13
|
+
}) => {
|
|
14
|
+
return /* @__PURE__ */ jsx(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsx(Controller, { ...props }) });
|
|
15
|
+
};
|
|
16
|
+
const FormItemContext = createContext(
|
|
17
|
+
{}
|
|
18
|
+
);
|
|
19
|
+
const useFormField = () => {
|
|
20
|
+
const fieldContext = useContext(FormFieldContext);
|
|
21
|
+
const itemContext = useContext(FormItemContext);
|
|
22
|
+
const { getFieldState } = useFormContext();
|
|
23
|
+
const formState = useFormState({ name: fieldContext.name });
|
|
24
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
25
|
+
if (!fieldContext) {
|
|
26
|
+
throw new Error("useFormField should be used within a FormField");
|
|
27
|
+
}
|
|
28
|
+
const { id } = itemContext;
|
|
29
|
+
return {
|
|
30
|
+
id,
|
|
31
|
+
name: fieldContext.name,
|
|
32
|
+
formItemId: `${id}-form-item`,
|
|
33
|
+
formLabelId: `${id}-form-item-label`,
|
|
34
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
35
|
+
formErrorMessageId: `${id}-form-item-message`,
|
|
36
|
+
...fieldState
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const Item = forwardRef(
|
|
40
|
+
({ className, ...props }, ref) => {
|
|
41
|
+
const id = useId();
|
|
42
|
+
return /* @__PURE__ */ jsx(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsx(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
ref,
|
|
46
|
+
className: clx("flex flex-col space-y-2", className),
|
|
47
|
+
...props
|
|
48
|
+
}
|
|
49
|
+
) });
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
Item.displayName = "Form.Item";
|
|
53
|
+
const Label = forwardRef(
|
|
54
|
+
({
|
|
55
|
+
className,
|
|
56
|
+
optional = false,
|
|
57
|
+
tooltip,
|
|
58
|
+
icon,
|
|
59
|
+
variant = "default",
|
|
60
|
+
...props
|
|
61
|
+
}, ref) => {
|
|
62
|
+
const { formLabelId, formItemId } = useFormField();
|
|
63
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
64
|
+
/* @__PURE__ */ jsx(
|
|
65
|
+
Label$1,
|
|
66
|
+
{
|
|
67
|
+
id: formLabelId,
|
|
68
|
+
ref,
|
|
69
|
+
className: clx(
|
|
70
|
+
{
|
|
71
|
+
"text-ui-fg-subtle": variant === "subtle"
|
|
72
|
+
},
|
|
73
|
+
className
|
|
74
|
+
),
|
|
75
|
+
htmlFor: formItemId,
|
|
76
|
+
size: "small",
|
|
77
|
+
weight: variant === "default" ? "plus" : "regular",
|
|
78
|
+
...props
|
|
79
|
+
}
|
|
80
|
+
),
|
|
81
|
+
tooltip && /* @__PURE__ */ jsx(Tooltip, { content: tooltip, children: /* @__PURE__ */ jsx(InformationCircleSolid, { className: "text-ui-fg-muted" }) }),
|
|
82
|
+
icon,
|
|
83
|
+
optional && /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "text-ui-fg-muted", children: "(Optional)" })
|
|
84
|
+
] });
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
Label.displayName = "Form.Label";
|
|
88
|
+
const Control = forwardRef(({ ...props }, ref) => {
|
|
89
|
+
const {
|
|
90
|
+
error,
|
|
91
|
+
formItemId,
|
|
92
|
+
formDescriptionId,
|
|
93
|
+
formErrorMessageId,
|
|
94
|
+
formLabelId
|
|
95
|
+
} = useFormField();
|
|
96
|
+
return /* @__PURE__ */ jsx(
|
|
97
|
+
Slot.Root,
|
|
98
|
+
{
|
|
99
|
+
ref,
|
|
100
|
+
id: formItemId,
|
|
101
|
+
"aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formErrorMessageId}`,
|
|
102
|
+
"aria-invalid": !!error,
|
|
103
|
+
"aria-labelledby": formLabelId,
|
|
104
|
+
...props
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
Control.displayName = "Form.Control";
|
|
109
|
+
const Hint = forwardRef(({ className, ...props }, ref) => {
|
|
110
|
+
const { formDescriptionId } = useFormField();
|
|
111
|
+
return /* @__PURE__ */ jsx(
|
|
112
|
+
Hint$1,
|
|
113
|
+
{
|
|
114
|
+
ref,
|
|
115
|
+
id: formDescriptionId,
|
|
116
|
+
className,
|
|
117
|
+
...props
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
Hint.displayName = "Form.Hint";
|
|
122
|
+
const ErrorMessage = forwardRef(({ className, children, ...props }, ref) => {
|
|
123
|
+
const { error, formErrorMessageId } = useFormField();
|
|
124
|
+
const msg = error ? String(error == null ? void 0 : error.message) : children;
|
|
125
|
+
if (!msg || msg === "undefined") {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return /* @__PURE__ */ jsx(
|
|
129
|
+
Hint$1,
|
|
130
|
+
{
|
|
131
|
+
ref,
|
|
132
|
+
id: formErrorMessageId,
|
|
133
|
+
className,
|
|
134
|
+
variant: error ? "error" : "info",
|
|
135
|
+
...props,
|
|
136
|
+
children: msg
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
ErrorMessage.displayName = "Form.ErrorMessage";
|
|
141
|
+
const Form = Object.assign(Provider, {
|
|
142
|
+
Item,
|
|
143
|
+
Label,
|
|
144
|
+
Control,
|
|
145
|
+
Hint,
|
|
146
|
+
ErrorMessage,
|
|
147
|
+
Field
|
|
148
|
+
});
|
|
149
|
+
export {
|
|
150
|
+
Form
|
|
151
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import { clx } from "@medusajs/ui";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
const InlineTip = forwardRef(
|
|
5
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
6
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
7
|
+
return /* @__PURE__ */ jsxs(
|
|
8
|
+
"div",
|
|
9
|
+
{
|
|
10
|
+
ref,
|
|
11
|
+
className: clx(
|
|
12
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
13
|
+
className
|
|
14
|
+
),
|
|
15
|
+
...props,
|
|
16
|
+
children: [
|
|
17
|
+
/* @__PURE__ */ jsx(
|
|
18
|
+
"div",
|
|
19
|
+
{
|
|
20
|
+
role: "presentation",
|
|
21
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
22
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
),
|
|
26
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
27
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
28
|
+
labelValue,
|
|
29
|
+
":"
|
|
30
|
+
] }),
|
|
31
|
+
" ",
|
|
32
|
+
children
|
|
33
|
+
] })
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
InlineTip.displayName = "InlineTip";
|
|
40
|
+
export {
|
|
41
|
+
InlineTip
|
|
42
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from "react";
|
|
3
|
+
const KeyboundForm = React.forwardRef(({ onSubmit, onKeyDown, ...rest }, ref) => {
|
|
4
|
+
const handleSubmit = (event) => {
|
|
5
|
+
event.preventDefault();
|
|
6
|
+
onSubmit == null ? void 0 : onSubmit(event);
|
|
7
|
+
};
|
|
8
|
+
const handleKeyDown = (event) => {
|
|
9
|
+
if (event.key === "Enter") {
|
|
10
|
+
if (event.target instanceof HTMLTextAreaElement && !(event.metaKey || event.ctrlKey)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
event.preventDefault();
|
|
14
|
+
if (event.metaKey || event.ctrlKey) {
|
|
15
|
+
handleSubmit(event);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
return /* @__PURE__ */ jsx(
|
|
20
|
+
"form",
|
|
21
|
+
{
|
|
22
|
+
...rest,
|
|
23
|
+
onSubmit: handleSubmit,
|
|
24
|
+
onKeyDown: onKeyDown ?? handleKeyDown,
|
|
25
|
+
ref
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
KeyboundForm.displayName = "KeyboundForm";
|
|
30
|
+
export {
|
|
31
|
+
KeyboundForm
|
|
32
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Skeleton, clx } from "@medusajs/ui";
|
|
3
|
+
const PageSkeleton = ({
|
|
4
|
+
mainSections = 2,
|
|
5
|
+
sidebarSections = 1,
|
|
6
|
+
showJSON = false,
|
|
7
|
+
showMetadata = true
|
|
8
|
+
}) => {
|
|
9
|
+
const showExtraData = showJSON || showMetadata;
|
|
10
|
+
return /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-x-4 gap-y-3 xl:flex-row xl:items-start", children: [
|
|
11
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-y-3", children: [
|
|
12
|
+
Array.from({ length: mainSections }, (_, i) => i).map((section) => {
|
|
13
|
+
return /* @__PURE__ */ jsx(
|
|
14
|
+
Skeleton,
|
|
15
|
+
{
|
|
16
|
+
className: clx("h-full max-h-[460px] w-full rounded-lg", {
|
|
17
|
+
"max-h-[219px]": section === 0
|
|
18
|
+
})
|
|
19
|
+
},
|
|
20
|
+
section
|
|
21
|
+
);
|
|
22
|
+
}),
|
|
23
|
+
showExtraData && /* @__PURE__ */ jsxs("div", { className: "hidden flex-col gap-y-3 xl:flex", children: [
|
|
24
|
+
showMetadata && /* @__PURE__ */ jsx(Skeleton, { className: "h-[60px] w-full rounded-lg" }),
|
|
25
|
+
showJSON && /* @__PURE__ */ jsx(Skeleton, { className: "h-[60px] w-full rounded-lg" })
|
|
26
|
+
] })
|
|
27
|
+
] }),
|
|
28
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[100%] flex-col gap-y-3 xl:mt-0 xl:max-w-[440px]", children: [
|
|
29
|
+
Array.from({ length: sidebarSections }, (_, i) => i).map(
|
|
30
|
+
(section) => {
|
|
31
|
+
return /* @__PURE__ */ jsx(
|
|
32
|
+
Skeleton,
|
|
33
|
+
{
|
|
34
|
+
className: clx("h-full max-h-[320px] w-full rounded-lg", {
|
|
35
|
+
"max-h-[140px]": section === 0
|
|
36
|
+
})
|
|
37
|
+
},
|
|
38
|
+
section
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
),
|
|
42
|
+
showExtraData && /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-3 xl:hidden", children: [
|
|
43
|
+
showMetadata && /* @__PURE__ */ jsx(Skeleton, { className: "h-[60px] w-full rounded-lg" }),
|
|
44
|
+
showJSON && /* @__PURE__ */ jsx(Skeleton, { className: "h-[60px] w-full rounded-lg" })
|
|
45
|
+
] })
|
|
46
|
+
] })
|
|
47
|
+
] }) });
|
|
48
|
+
};
|
|
49
|
+
export {
|
|
50
|
+
PageSkeleton
|
|
51
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Photo } from "@medusajs/icons";
|
|
3
|
+
const Thumbnail = ({ thumbnail, alt = "" }) => {
|
|
4
|
+
return /* @__PURE__ */ jsx("div", { className: "relative w-6 h-8 rounded overflow-hidden flex items-center justify-center bg-ui-bg-component", children: thumbnail ? /* @__PURE__ */ jsx(
|
|
5
|
+
"img",
|
|
6
|
+
{
|
|
7
|
+
src: thumbnail,
|
|
8
|
+
className: "w-full h-full object-cover",
|
|
9
|
+
alt: alt ?? void 0
|
|
10
|
+
}
|
|
11
|
+
) : /* @__PURE__ */ jsx(Photo, {}) });
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
Thumbnail
|
|
15
|
+
};
|