@medusajs/draft-order 0.0.1 → 0.0.2

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 (76) hide show
  1. package/.medusa/server/src/admin/index.js +11326 -0
  2. package/.medusa/server/src/admin/index.mjs +11322 -0
  3. package/package.json +16 -16
  4. package/.medusa/server/src/admin/components/common/action-menu.js +0 -77
  5. package/.medusa/server/src/admin/components/common/conditional-tooltip.js +0 -15
  6. package/.medusa/server/src/admin/components/common/data-table.js +0 -249
  7. package/.medusa/server/src/admin/components/common/form.js +0 -151
  8. package/.medusa/server/src/admin/components/common/inline-tip.js +0 -42
  9. package/.medusa/server/src/admin/components/common/keybound-form.js +0 -32
  10. package/.medusa/server/src/admin/components/common/page-skeleton.js +0 -51
  11. package/.medusa/server/src/admin/components/common/thumbnail.js +0 -15
  12. package/.medusa/server/src/admin/components/draft-orders/activity-section.js +0 -205
  13. package/.medusa/server/src/admin/components/draft-orders/customer-section.js +0 -165
  14. package/.medusa/server/src/admin/components/draft-orders/general-section.js +0 -36
  15. package/.medusa/server/src/admin/components/draft-orders/json-view-section.js +0 -140
  16. package/.medusa/server/src/admin/components/draft-orders/metadata-section.js +0 -28
  17. package/.medusa/server/src/admin/components/draft-orders/shipping-section.js +0 -211
  18. package/.medusa/server/src/admin/components/draft-orders/summary-section.js +0 -148
  19. package/.medusa/server/src/admin/components/inputs/combobox.js +0 -311
  20. package/.medusa/server/src/admin/components/inputs/country-select.js +0 -59
  21. package/.medusa/server/src/admin/components/inputs/number-input.js +0 -100
  22. package/.medusa/server/src/admin/components/inputs/switch-block.js +0 -30
  23. package/.medusa/server/src/admin/components/modals/index.js +0 -19
  24. package/.medusa/server/src/admin/components/modals/route-drawer/index.js +0 -4
  25. package/.medusa/server/src/admin/components/modals/route-drawer/route-drawer.js +0 -57
  26. package/.medusa/server/src/admin/components/modals/route-focus-modal/index.js +0 -4
  27. package/.medusa/server/src/admin/components/modals/route-focus-modal/route-focus-modal.js +0 -71
  28. package/.medusa/server/src/admin/components/modals/route-modal-form/index.js +0 -4
  29. package/.medusa/server/src/admin/components/modals/route-modal-form/route-modal-form.js +0 -60
  30. package/.medusa/server/src/admin/components/modals/route-modal-provider/index.js +0 -6
  31. package/.medusa/server/src/admin/components/modals/route-modal-provider/route-modal-context.js +0 -5
  32. package/.medusa/server/src/admin/components/modals/route-modal-provider/route-provider.js +0 -30
  33. package/.medusa/server/src/admin/components/modals/route-modal-provider/use-route-modal.js +0 -12
  34. package/.medusa/server/src/admin/components/modals/stacked-drawer/index.js +0 -5
  35. package/.medusa/server/src/admin/components/modals/stacked-drawer/stacked-drawer.js +0 -55
  36. package/.medusa/server/src/admin/components/modals/stacked-focus-modal/index.js +0 -5
  37. package/.medusa/server/src/admin/components/modals/stacked-focus-modal/stacked-focus-modal.js +0 -63
  38. package/.medusa/server/src/admin/components/modals/stacked-modal-provider/index.js +0 -6
  39. package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-context.js +0 -5
  40. package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-provider.js +0 -47
  41. package/.medusa/server/src/admin/components/modals/stacked-modal-provider/use-stacked-modal.js +0 -14
  42. package/.medusa/server/src/admin/components/utilities/generic-forward-ref.js +0 -7
  43. package/.medusa/server/src/admin/hooks/api/customers.js +0 -53
  44. package/.medusa/server/src/admin/hooks/api/draft-orders.js +0 -161
  45. package/.medusa/server/src/admin/hooks/api/orders.js +0 -274
  46. package/.medusa/server/src/admin/hooks/api/product-variants.js +0 -21
  47. package/.medusa/server/src/admin/hooks/api/regions.js +0 -35
  48. package/.medusa/server/src/admin/hooks/api/sales-channels.js +0 -35
  49. package/.medusa/server/src/admin/hooks/api/shipping-options.js +0 -35
  50. package/.medusa/server/src/admin/hooks/api/users.js +0 -26
  51. package/.medusa/server/src/admin/hooks/common/use-combobox-data.js +0 -61
  52. package/.medusa/server/src/admin/hooks/common/use-data-table-date-filters.js +0 -89
  53. package/.medusa/server/src/admin/hooks/common/use-debounced-search.js +0 -22
  54. package/.medusa/server/src/admin/hooks/common/use-query-params.js +0 -14
  55. package/.medusa/server/src/admin/hooks/order-edits/use-cancel-order-edit.js +0 -25
  56. package/.medusa/server/src/admin/hooks/order-edits/use-initiate-order-edit.js +0 -39
  57. package/.medusa/server/src/admin/lib/data/countries.js +0 -1762
  58. package/.medusa/server/src/admin/lib/data/currencies.js +0 -36
  59. package/.medusa/server/src/admin/lib/queries/draft-order-details.js +0 -1
  60. package/.medusa/server/src/admin/lib/queries/sdk.js +0 -10
  61. package/.medusa/server/src/admin/lib/schemas/address.js +0 -16
  62. package/.medusa/server/src/admin/lib/utils/address-utils.js +0 -57
  63. package/.medusa/server/src/admin/lib/utils/date-utils.js +0 -27
  64. package/.medusa/server/src/admin/lib/utils/order-utils.js +0 -13
  65. package/.medusa/server/src/admin/routes/draft-orders/@create/page.js +0 -659
  66. package/.medusa/server/src/admin/routes/draft-orders/_id_/@billing-address/page.js +0 -228
  67. package/.medusa/server/src/admin/routes/draft-orders/_id_/@custom-items/page.js +0 -38
  68. package/.medusa/server/src/admin/routes/draft-orders/_id_/@email/page.js +0 -89
  69. package/.medusa/server/src/admin/routes/draft-orders/_id_/@items/page.js +0 -576
  70. package/.medusa/server/src/admin/routes/draft-orders/_id_/@metadata/page.js +0 -338
  71. package/.medusa/server/src/admin/routes/draft-orders/_id_/@promotions/page.js +0 -70
  72. package/.medusa/server/src/admin/routes/draft-orders/_id_/@sales-channel/page.js +0 -113
  73. package/.medusa/server/src/admin/routes/draft-orders/_id_/@shipping/page.js +0 -465
  74. package/.medusa/server/src/admin/routes/draft-orders/_id_/@shipping-address/page.js +0 -241
  75. package/.medusa/server/src/admin/routes/draft-orders/_id_/page.js +0 -70
  76. package/.medusa/server/src/admin/routes/draft-orders/page.js +0 -148
@@ -1,241 +0,0 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { zodResolver } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/@hookform/resolvers/zod/dist/zod.mjs";
3
- import { Heading, toast, Input, Button } from "@medusajs/ui";
4
- import { useForm } from "react-hook-form";
5
- import { useParams } from "react-router-dom";
6
- import { z } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/zod/lib/index.mjs";
7
- import { Form } from "../../../../components/common/form.js";
8
- import { KeyboundForm } from "../../../../components/common/keybound-form.js";
9
- import { CountrySelect } from "../../../../components/inputs/country-select.js";
10
- import { SwitchBlock } from "../../../../components/inputs/switch-block.js";
11
- import { RouteDrawer } from "../../../../components/modals/route-drawer/route-drawer.js";
12
- import "../../../../components/modals/route-focus-modal/route-focus-modal.js";
13
- import "react";
14
- import "../../../../components/modals/route-modal-provider/route-modal-context.js";
15
- import { useRouteModal } from "../../../../components/modals/route-modal-provider/use-route-modal.js";
16
- import "../../../../components/modals/stacked-drawer/stacked-drawer.js";
17
- import "../../../../components/modals/stacked-focus-modal/stacked-focus-modal.js";
18
- import "../../../../components/modals/stacked-modal-provider/stacked-modal-context.js";
19
- import { useUpdateDraftOrder } from "../../../../hooks/api/draft-orders.js";
20
- import { useOrder } from "../../../../hooks/api/orders.js";
21
- import { addressSchema } from "../../../../lib/schemas/address.js";
22
- const ShippingAddress = () => {
23
- const { id } = useParams();
24
- const { order, isPending, isError, error } = useOrder(id, {
25
- fields: "+shipping_address"
26
- });
27
- if (isError) {
28
- throw error;
29
- }
30
- const isReady = !isPending && !!order;
31
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
32
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
33
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
34
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
35
- ] }),
36
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
37
- ] });
38
- };
39
- const ShippingAddressForm = ({ order }) => {
40
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
41
- const form = useForm({
42
- defaultValues: {
43
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
44
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
45
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
46
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
47
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
48
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
49
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
50
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
51
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
52
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? "",
53
- notify: false
54
- },
55
- resolver: zodResolver(schema)
56
- });
57
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
58
- const { handleSuccess } = useRouteModal();
59
- const onSubmit = form.handleSubmit(async (data) => {
60
- await mutateAsync(
61
- {
62
- shipping_address: {
63
- first_name: data.first_name,
64
- last_name: data.last_name,
65
- company: data.company,
66
- address_1: data.address_1,
67
- address_2: data.address_2,
68
- city: data.city,
69
- province: data.province,
70
- country_code: data.country_code,
71
- postal_code: data.postal_code,
72
- phone: data.phone
73
- }
74
- },
75
- {
76
- onSuccess: () => {
77
- handleSuccess();
78
- },
79
- onError: (error) => {
80
- toast.error(error.message);
81
- }
82
- }
83
- );
84
- });
85
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
86
- KeyboundForm,
87
- {
88
- className: "flex flex-1 flex-col overflow-hidden",
89
- onSubmit,
90
- children: [
91
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
92
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
93
- /* @__PURE__ */ jsx(
94
- Form.Field,
95
- {
96
- control: form.control,
97
- name: "country_code",
98
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
99
- /* @__PURE__ */ jsx(Form.Label, { children: "Country" }),
100
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
101
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
102
- ] })
103
- }
104
- ),
105
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
106
- /* @__PURE__ */ jsx(
107
- Form.Field,
108
- {
109
- control: form.control,
110
- name: "first_name",
111
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
112
- /* @__PURE__ */ jsx(Form.Label, { children: "First name" }),
113
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
114
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
115
- ] })
116
- }
117
- ),
118
- /* @__PURE__ */ jsx(
119
- Form.Field,
120
- {
121
- control: form.control,
122
- name: "last_name",
123
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
124
- /* @__PURE__ */ jsx(Form.Label, { children: "Last name" }),
125
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
126
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
127
- ] })
128
- }
129
- )
130
- ] }),
131
- /* @__PURE__ */ jsx(
132
- Form.Field,
133
- {
134
- control: form.control,
135
- name: "company",
136
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
137
- /* @__PURE__ */ jsx(Form.Label, { optional: true, children: "Company" }),
138
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
139
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
140
- ] })
141
- }
142
- ),
143
- /* @__PURE__ */ jsx(
144
- Form.Field,
145
- {
146
- control: form.control,
147
- name: "address_1",
148
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
149
- /* @__PURE__ */ jsx(Form.Label, { children: "Address" }),
150
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
151
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
152
- ] })
153
- }
154
- ),
155
- /* @__PURE__ */ jsx(
156
- Form.Field,
157
- {
158
- control: form.control,
159
- name: "address_2",
160
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
161
- /* @__PURE__ */ jsx(Form.Label, { optional: true, children: "Apartment, suite, etc." }),
162
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
163
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
164
- ] })
165
- }
166
- ),
167
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
168
- /* @__PURE__ */ jsx(
169
- Form.Field,
170
- {
171
- control: form.control,
172
- name: "postal_code",
173
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
174
- /* @__PURE__ */ jsx(Form.Label, { children: "Postal code" }),
175
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
176
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
177
- ] })
178
- }
179
- ),
180
- /* @__PURE__ */ jsx(
181
- Form.Field,
182
- {
183
- control: form.control,
184
- name: "city",
185
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
186
- /* @__PURE__ */ jsx(Form.Label, { children: "City" }),
187
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
188
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
189
- ] })
190
- }
191
- )
192
- ] }),
193
- /* @__PURE__ */ jsx(
194
- Form.Field,
195
- {
196
- control: form.control,
197
- name: "province",
198
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
199
- /* @__PURE__ */ jsx(Form.Label, { optional: true, children: "Province / State" }),
200
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
201
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
202
- ] })
203
- }
204
- ),
205
- /* @__PURE__ */ jsx(
206
- Form.Field,
207
- {
208
- control: form.control,
209
- name: "phone",
210
- render: ({ field }) => /* @__PURE__ */ jsxs(Form.Item, { children: [
211
- /* @__PURE__ */ jsx(Form.Label, { optional: true, children: "Phone" }),
212
- /* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
213
- /* @__PURE__ */ jsx(Form.ErrorMessage, {})
214
- ] })
215
- }
216
- )
217
- ] }),
218
- /* @__PURE__ */ jsx(
219
- SwitchBlock,
220
- {
221
- control: form.control,
222
- name: "notify",
223
- label: "Notify customer",
224
- description: "Notify the customer of the new shipping address."
225
- }
226
- )
227
- ] }),
228
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
229
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
230
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
231
- ] }) })
232
- ]
233
- }
234
- ) });
235
- };
236
- const schema = addressSchema.extend({
237
- notify: z.boolean().optional()
238
- });
239
- export {
240
- ShippingAddress as default
241
- };
@@ -1,70 +0,0 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
2
- import { Fragment } from "react";
3
- import { useParams, Outlet } from "react-router-dom";
4
- import { PageSkeleton } from "../../../components/common/page-skeleton.js";
5
- import { ActivitySection } from "../../../components/draft-orders/activity-section.js";
6
- import { CustomerSection } from "../../../components/draft-orders/customer-section.js";
7
- import { GeneralSection } from "../../../components/draft-orders/general-section.js";
8
- import { JsonViewSection } from "../../../components/draft-orders/json-view-section.js";
9
- import { MetadataSection } from "../../../components/draft-orders/metadata-section.js";
10
- import { ShippingSection } from "../../../components/draft-orders/shipping-section.js";
11
- import { SummarySection } from "../../../components/draft-orders/summary-section.js";
12
- import { useOrder, useOrderChanges } from "../../../hooks/api/orders.js";
13
- const ID = () => {
14
- const { id } = useParams();
15
- const { order, isPending, isError, error } = useOrder(id, {
16
- fields: "+customer.*,+sales_channel.*,+region.*,+email,+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+items.variant.options.*,+currency_code"
17
- });
18
- const {
19
- order_changes,
20
- isPending: isOrderChangesPending,
21
- isError: isOrderChangesError,
22
- error: orderChangesError
23
- } = useOrderChanges(id, {
24
- change_type: ["edit", "transfer", "update_order"]
25
- });
26
- if (isError) {
27
- throw error;
28
- }
29
- if (isOrderChangesError) {
30
- throw orderChangesError;
31
- }
32
- const isReady = !isPending && !isOrderChangesPending && !!order && !!order_changes;
33
- if (!isReady) {
34
- return /* @__PURE__ */ jsx(
35
- PageSkeleton,
36
- {
37
- mainSections: 3,
38
- sidebarSections: 2,
39
- showJSON: true,
40
- showMetadata: true
41
- }
42
- );
43
- }
44
- const orderHasItems = order.items.length > 0;
45
- return /* @__PURE__ */ jsxs(Fragment, { children: [
46
- /* @__PURE__ */ jsx("div", { className: "flex w-full flex-col gap-y-3", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col items-start gap-x-4 gap-y-3 xl:grid xl:grid-cols-[minmax(0,_1fr)_440px]", children: [
47
- /* @__PURE__ */ jsxs("div", { className: "flex w-full min-w-0 flex-col gap-y-3", children: [
48
- /* @__PURE__ */ jsx(GeneralSection, { order }),
49
- /* @__PURE__ */ jsx(SummarySection, { order }),
50
- orderHasItems && /* @__PURE__ */ jsx(ShippingSection, { order }),
51
- /* @__PURE__ */ jsxs("div", { className: "hidden flex-col gap-y-3 xl:flex", children: [
52
- /* @__PURE__ */ jsx(MetadataSection, { order }),
53
- /* @__PURE__ */ jsx(JsonViewSection, { data: order })
54
- ] })
55
- ] }),
56
- /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-y-3 xl:mt-0", children: [
57
- /* @__PURE__ */ jsx(CustomerSection, { order }),
58
- /* @__PURE__ */ jsx(ActivitySection, { order, changes: order_changes }),
59
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-3 xl:hidden", children: [
60
- /* @__PURE__ */ jsx(MetadataSection, { order }),
61
- /* @__PURE__ */ jsx(JsonViewSection, { data: order })
62
- ] })
63
- ] })
64
- ] }) }),
65
- /* @__PURE__ */ jsx(Outlet, {})
66
- ] });
67
- };
68
- export {
69
- ID as default
70
- };
@@ -1,148 +0,0 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { defineRouteConfig } from "@medusajs/admin-sdk";
3
- import { createDataTableColumnHelper, Container, Tooltip } from "@medusajs/ui";
4
- import { keepPreviousData } from "@tanstack/react-query";
5
- import { Fragment, useMemo } from "react";
6
- import { Outlet } from "react-router-dom";
7
- import { DataTable } from "../../components/common/data-table.js";
8
- import { useDraftOrders } from "../../hooks/api/draft-orders.js";
9
- import { useDataTableDateFilters } from "../../hooks/common/use-data-table-date-filters.js";
10
- import { useQueryParams } from "../../hooks/common/use-query-params.js";
11
- import { getFullDate } from "../../lib/utils/date-utils.js";
12
- const PAGE_SIZE = 20;
13
- const List = () => {
14
- const queryParams = useDraftOrderTableQuery({
15
- pageSize: PAGE_SIZE
16
- });
17
- const { draft_orders, count, isPending, isError, error } = useDraftOrders(
18
- {
19
- ...queryParams,
20
- order: queryParams.order ?? "-created_at",
21
- fields: "+customer.*,+sales_channel.*,+email,+display_id,+total,+currency_code,+shipping_total,+tax_total,+discount_total,+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+items.variant.options.*"
22
- },
23
- {
24
- placeholderData: keepPreviousData
25
- }
26
- );
27
- const columns = useColumns();
28
- const filters = useFilters();
29
- if (isError) {
30
- throw error;
31
- }
32
- return /* @__PURE__ */ jsxs(Fragment, { children: [
33
- /* @__PURE__ */ jsx(Container, { className: "p-0", children: /* @__PURE__ */ jsx(
34
- DataTable,
35
- {
36
- data: draft_orders,
37
- getRowId: (row) => row.id,
38
- columns,
39
- filters,
40
- isLoading: isPending,
41
- pageSize: PAGE_SIZE,
42
- rowCount: count,
43
- heading: "Draft Orders",
44
- action: {
45
- label: "Create",
46
- to: "create"
47
- },
48
- rowHref: (row) => `${row.id}`,
49
- emptyState: {
50
- empty: {
51
- heading: "No draft orders found",
52
- description: "Create a new draft order to get started."
53
- },
54
- filtered: {
55
- heading: "No results found",
56
- description: "No draft orders match your filter criteria."
57
- }
58
- }
59
- }
60
- ) }),
61
- /* @__PURE__ */ jsx(Outlet, {})
62
- ] });
63
- };
64
- const config = defineRouteConfig({
65
- label: "Drafts",
66
- nested: "/orders"
67
- });
68
- const columnHelper = createDataTableColumnHelper();
69
- const useColumns = () => {
70
- return useMemo(
71
- () => [
72
- columnHelper.accessor("display_id", {
73
- header: "Display ID",
74
- cell: ({ getValue }) => {
75
- return `#${getValue()}`;
76
- },
77
- enableSorting: true
78
- }),
79
- columnHelper.accessor("created_at", {
80
- header: "Date",
81
- cell: ({ getValue }) => {
82
- return /* @__PURE__ */ jsx(
83
- Tooltip,
84
- {
85
- content: getFullDate({ date: getValue(), includeTime: true }),
86
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
87
- }
88
- );
89
- },
90
- enableSorting: true
91
- }),
92
- columnHelper.accessor("customer", {
93
- header: "Customer",
94
- cell: ({ getValue }) => {
95
- var _a;
96
- return (_a = getValue()) == null ? void 0 : _a.email;
97
- },
98
- enableSorting: true
99
- }),
100
- columnHelper.accessor("sales_channel.name", {
101
- header: "Sales Channel",
102
- cell: ({ getValue }) => {
103
- return getValue() || "-";
104
- },
105
- enableSorting: true
106
- })
107
- ],
108
- []
109
- );
110
- };
111
- const useFilters = () => {
112
- const dateFilterOptions = useDataTableDateFilters();
113
- return useMemo(() => {
114
- return dateFilterOptions;
115
- }, [dateFilterOptions]);
116
- };
117
- const useDraftOrderTableQuery = ({
118
- prefix,
119
- pageSize = 20
120
- }) => {
121
- const queryObject = useQueryParams(
122
- [
123
- "offset",
124
- "q",
125
- "order",
126
- "status",
127
- "customer_id",
128
- "created_at",
129
- "updated_at"
130
- ],
131
- prefix
132
- );
133
- const { offset, created_at, updated_at, status, ...rest } = queryObject;
134
- const searchParams = {
135
- limit: pageSize,
136
- offset: offset ? Number(offset) : 0,
137
- created_at: created_at ? JSON.parse(created_at) : void 0,
138
- updated_at: updated_at ? JSON.parse(updated_at) : void 0,
139
- status: status ? JSON.parse(status) : void 0,
140
- ...rest
141
- };
142
- return searchParams;
143
- };
144
- export {
145
- config,
146
- List as default,
147
- useDraftOrderTableQuery
148
- };