@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,465 @@
|
|
|
1
|
+
import { jsx, jsxs } 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 { toast, Heading, Text, Divider, Input, Button, Select, Label, Hint } from "@medusajs/ui";
|
|
4
|
+
import { matchSorter } from "match-sorter";
|
|
5
|
+
import { useState, useEffect, useMemo } from "react";
|
|
6
|
+
import { useForm, useWatch } from "react-hook-form";
|
|
7
|
+
import { useParams, useSearchParams, useNavigate } from "react-router-dom";
|
|
8
|
+
import { z } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/zod/lib/index.mjs";
|
|
9
|
+
import { ConditionalTooltip } from "../../../../components/common/conditional-tooltip.js";
|
|
10
|
+
import { Form } from "../../../../components/common/form.js";
|
|
11
|
+
import { KeyboundForm } from "../../../../components/common/keybound-form.js";
|
|
12
|
+
import { Thumbnail } from "../../../../components/common/thumbnail.js";
|
|
13
|
+
import { Combobox } from "../../../../components/inputs/combobox.js";
|
|
14
|
+
import "../../../../components/modals/route-drawer/route-drawer.js";
|
|
15
|
+
import { RouteFocusModal } from "../../../../components/modals/route-focus-modal/route-focus-modal.js";
|
|
16
|
+
import "../../../../components/modals/route-modal-provider/route-modal-context.js";
|
|
17
|
+
import { useRouteModal } from "../../../../components/modals/route-modal-provider/use-route-modal.js";
|
|
18
|
+
import "../../../../components/modals/stacked-drawer/stacked-drawer.js";
|
|
19
|
+
import "../../../../components/modals/stacked-focus-modal/stacked-focus-modal.js";
|
|
20
|
+
import "../../../../components/modals/stacked-modal-provider/stacked-modal-context.js";
|
|
21
|
+
import { useOrder, useOrderPreview, useOrderEditConfirm, useOrderEditRequest, useOrderEditAddShippingMethod } from "../../../../hooks/api/orders.js";
|
|
22
|
+
import { useComboboxData } from "../../../../hooks/common/use-combobox-data.js";
|
|
23
|
+
import { useDebouncedSearch } from "../../../../hooks/common/use-debounced-search.js";
|
|
24
|
+
import { useCancelOrderEdit } from "../../../../hooks/order-edits/use-cancel-order-edit.js";
|
|
25
|
+
import { useInitiateOrderEdit } from "../../../../hooks/order-edits/use-initiate-order-edit.js";
|
|
26
|
+
import { sdk } from "../../../../lib/queries/sdk.js";
|
|
27
|
+
import { getUniqueShippingProfiles } from "../../../../lib/utils/order-utils.js";
|
|
28
|
+
const Shipping = () => {
|
|
29
|
+
const { id } = useParams();
|
|
30
|
+
const [searchParams] = useSearchParams();
|
|
31
|
+
const shippingProfileId = searchParams.get("shipping_profile_id");
|
|
32
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
33
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+items.variant.options.*,+currency_code"
|
|
34
|
+
});
|
|
35
|
+
const {
|
|
36
|
+
order: preview,
|
|
37
|
+
isPending: isPreviewPending,
|
|
38
|
+
isError: isPreviewError,
|
|
39
|
+
error: previewError
|
|
40
|
+
} = useOrderPreview(id);
|
|
41
|
+
useInitiateOrderEdit({ preview });
|
|
42
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
43
|
+
const onClose = async () => {
|
|
44
|
+
const res = await onCancel();
|
|
45
|
+
if (res) {
|
|
46
|
+
clearLocalStorageShippingInformation();
|
|
47
|
+
}
|
|
48
|
+
return res;
|
|
49
|
+
};
|
|
50
|
+
if (isError) {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
if (isPreviewError) {
|
|
54
|
+
throw previewError;
|
|
55
|
+
}
|
|
56
|
+
const ready = order && !isPending && preview && !isPreviewPending;
|
|
57
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose, children: ready && /* @__PURE__ */ jsx(
|
|
58
|
+
ShippingForm,
|
|
59
|
+
{
|
|
60
|
+
order,
|
|
61
|
+
preview,
|
|
62
|
+
selectedShippingProfileId: shippingProfileId
|
|
63
|
+
}
|
|
64
|
+
) });
|
|
65
|
+
};
|
|
66
|
+
const ShippingForm = ({
|
|
67
|
+
order,
|
|
68
|
+
preview,
|
|
69
|
+
selectedShippingProfileId
|
|
70
|
+
}) => {
|
|
71
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
72
|
+
const { searchValue, onSearchValueChange, query } = useDebouncedSearch();
|
|
73
|
+
const uniqueShippingProfiles = getUniqueShippingProfiles(order.items);
|
|
74
|
+
const navigate = useNavigate();
|
|
75
|
+
const { handleSuccess } = useRouteModal();
|
|
76
|
+
const { mutateAsync: confirmOrderEdit } = useOrderEditConfirm(preview.id);
|
|
77
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
78
|
+
const shippingInformation = getLocalStorageShippingInformation();
|
|
79
|
+
const form = useForm({
|
|
80
|
+
defaultValues: {
|
|
81
|
+
shipping_profile_id: selectedShippingProfileId ? selectedShippingProfileId : uniqueShippingProfiles.length <= 1 ? uniqueShippingProfiles[0].id : (shippingInformation == null ? void 0 : shippingInformation.shipping_profile_id) || "",
|
|
82
|
+
location_id: (shippingInformation == null ? void 0 : shippingInformation.location_id) || ""
|
|
83
|
+
},
|
|
84
|
+
resolver: zodResolver(schema)
|
|
85
|
+
});
|
|
86
|
+
const shippingProfileId = useWatch({
|
|
87
|
+
control: form.control,
|
|
88
|
+
name: "shipping_profile_id"
|
|
89
|
+
});
|
|
90
|
+
const locationId = useWatch({
|
|
91
|
+
control: form.control,
|
|
92
|
+
name: "location_id"
|
|
93
|
+
});
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
updateLocalStorageShippingInformation({
|
|
96
|
+
shipping_profile_id: shippingProfileId,
|
|
97
|
+
location_id: locationId
|
|
98
|
+
});
|
|
99
|
+
}, [shippingProfileId, locationId]);
|
|
100
|
+
const items = useMemo(() => {
|
|
101
|
+
var _a;
|
|
102
|
+
return (_a = order.items) == null ? void 0 : _a.filter(
|
|
103
|
+
(item) => {
|
|
104
|
+
var _a2, _b, _c;
|
|
105
|
+
return ((_c = (_b = (_a2 = item.variant) == null ? void 0 : _a2.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}, [order.items, shippingProfileId]);
|
|
109
|
+
const itemCount = (items == null ? void 0 : items.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
110
|
+
const matches = useMemo(() => {
|
|
111
|
+
return matchSorter(items, query, {
|
|
112
|
+
keys: ["product_title", "variant_title", "variant_sku"]
|
|
113
|
+
});
|
|
114
|
+
}, [items, query]);
|
|
115
|
+
if (selectedShippingProfileId && !uniqueShippingProfiles.find(
|
|
116
|
+
(profile) => profile.id === selectedShippingProfileId
|
|
117
|
+
)) {
|
|
118
|
+
toast.error(
|
|
119
|
+
`Unable to find a shipping profile with the provided ID: ${selectedShippingProfileId}`
|
|
120
|
+
);
|
|
121
|
+
navigate("..");
|
|
122
|
+
}
|
|
123
|
+
const onSubmit = form.handleSubmit(async (_data) => {
|
|
124
|
+
setIsSubmitting(true);
|
|
125
|
+
let requestSucceeded = false;
|
|
126
|
+
await requestOrderEdit(void 0, {
|
|
127
|
+
onError: (e) => {
|
|
128
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
129
|
+
},
|
|
130
|
+
onSuccess: () => {
|
|
131
|
+
requestSucceeded = true;
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
if (!requestSucceeded) {
|
|
135
|
+
setIsSubmitting(false);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
await confirmOrderEdit(void 0, {
|
|
139
|
+
onError: (e) => {
|
|
140
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
141
|
+
},
|
|
142
|
+
onSuccess: () => {
|
|
143
|
+
handleSuccess();
|
|
144
|
+
},
|
|
145
|
+
onSettled: () => {
|
|
146
|
+
setIsSubmitting(false);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
return /* @__PURE__ */ jsx(RouteFocusModal.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
151
|
+
KeyboundForm,
|
|
152
|
+
{
|
|
153
|
+
className: "flex h-full flex-col overflow-hidden",
|
|
154
|
+
onSubmit,
|
|
155
|
+
children: [
|
|
156
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
157
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
158
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
159
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
160
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for this order." }) })
|
|
161
|
+
] }),
|
|
162
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
163
|
+
/* @__PURE__ */ jsx(
|
|
164
|
+
ShippingProfileField,
|
|
165
|
+
{
|
|
166
|
+
control: form.control,
|
|
167
|
+
shippingProfiles: uniqueShippingProfiles
|
|
168
|
+
}
|
|
169
|
+
),
|
|
170
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
171
|
+
/* @__PURE__ */ jsx(LocationField, { control: form.control }),
|
|
172
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
173
|
+
/* @__PURE__ */ jsx(
|
|
174
|
+
ShippingOptionField,
|
|
175
|
+
{
|
|
176
|
+
control: form.control,
|
|
177
|
+
orderId: preview.id,
|
|
178
|
+
preview
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
182
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
183
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
184
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
185
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
|
|
186
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
|
|
187
|
+
] }),
|
|
188
|
+
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-2", children: /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
189
|
+
Input,
|
|
190
|
+
{
|
|
191
|
+
type: "search",
|
|
192
|
+
placeholder: "Search items",
|
|
193
|
+
value: searchValue,
|
|
194
|
+
onChange: (e) => onSearchValueChange(e.target.value)
|
|
195
|
+
}
|
|
196
|
+
) }) })
|
|
197
|
+
] }),
|
|
198
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
199
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
|
|
200
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
201
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
|
|
202
|
+
] }),
|
|
203
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
|
|
204
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Choose a shipping profile" }),
|
|
205
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile will be shown here." })
|
|
206
|
+
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
|
|
207
|
+
"div",
|
|
208
|
+
{
|
|
209
|
+
className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
|
|
210
|
+
children: [
|
|
211
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
212
|
+
/* @__PURE__ */ jsx(
|
|
213
|
+
Thumbnail,
|
|
214
|
+
{
|
|
215
|
+
thumbnail: item.thumbnail,
|
|
216
|
+
alt: item.product_title ?? void 0
|
|
217
|
+
}
|
|
218
|
+
),
|
|
219
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
220
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
221
|
+
/* @__PURE__ */ jsx(
|
|
222
|
+
Text,
|
|
223
|
+
{
|
|
224
|
+
size: "small",
|
|
225
|
+
weight: "plus",
|
|
226
|
+
leading: "compact",
|
|
227
|
+
children: item.product_title
|
|
228
|
+
}
|
|
229
|
+
),
|
|
230
|
+
/* @__PURE__ */ jsxs(
|
|
231
|
+
Text,
|
|
232
|
+
{
|
|
233
|
+
size: "small",
|
|
234
|
+
leading: "compact",
|
|
235
|
+
className: "text-ui-fg-subtle",
|
|
236
|
+
children: [
|
|
237
|
+
"(",
|
|
238
|
+
item.variant_title,
|
|
239
|
+
")"
|
|
240
|
+
]
|
|
241
|
+
}
|
|
242
|
+
)
|
|
243
|
+
] }),
|
|
244
|
+
/* @__PURE__ */ jsx(
|
|
245
|
+
Text,
|
|
246
|
+
{
|
|
247
|
+
size: "small",
|
|
248
|
+
leading: "compact",
|
|
249
|
+
className: "text-ui-fg-subtle",
|
|
250
|
+
children: item.variant_sku
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
] })
|
|
254
|
+
] }),
|
|
255
|
+
/* @__PURE__ */ jsxs(
|
|
256
|
+
Text,
|
|
257
|
+
{
|
|
258
|
+
size: "small",
|
|
259
|
+
leading: "compact",
|
|
260
|
+
className: "text-ui-fg-subtle",
|
|
261
|
+
children: [
|
|
262
|
+
item.quantity,
|
|
263
|
+
"x"
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
)
|
|
267
|
+
]
|
|
268
|
+
},
|
|
269
|
+
item.id
|
|
270
|
+
)) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
|
|
271
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
272
|
+
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
273
|
+
'No items found for "',
|
|
274
|
+
query,
|
|
275
|
+
'".'
|
|
276
|
+
] })
|
|
277
|
+
] }) })
|
|
278
|
+
] })
|
|
279
|
+
] })
|
|
280
|
+
] }) }) }),
|
|
281
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
|
|
282
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
283
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isSubmitting, children: "Save" })
|
|
284
|
+
] }) })
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
) });
|
|
288
|
+
};
|
|
289
|
+
const ShippingProfileField = ({
|
|
290
|
+
control,
|
|
291
|
+
shippingProfiles
|
|
292
|
+
}) => {
|
|
293
|
+
const shippingProfileOptions = shippingProfiles.map((profile) => ({
|
|
294
|
+
label: profile.name,
|
|
295
|
+
value: profile.id
|
|
296
|
+
}));
|
|
297
|
+
return /* @__PURE__ */ jsx(
|
|
298
|
+
Form.Field,
|
|
299
|
+
{
|
|
300
|
+
control,
|
|
301
|
+
name: "shipping_profile_id",
|
|
302
|
+
render: ({ field: { onChange, ref, ...field } }) => {
|
|
303
|
+
return /* @__PURE__ */ jsx(Form.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
304
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
305
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "Shipping Profile" }),
|
|
306
|
+
/* @__PURE__ */ jsx(Form.Hint, { children: "Choose the shipping profile to add shipping for." })
|
|
307
|
+
] }),
|
|
308
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsxs(
|
|
309
|
+
Select,
|
|
310
|
+
{
|
|
311
|
+
...field,
|
|
312
|
+
onValueChange: onChange,
|
|
313
|
+
disabled: shippingProfileOptions.length <= 1,
|
|
314
|
+
children: [
|
|
315
|
+
/* @__PURE__ */ jsx(Select.Trigger, { ref, children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select a shipping profile" }) }),
|
|
316
|
+
/* @__PURE__ */ jsx(Select.Content, { children: shippingProfileOptions.map((option) => /* @__PURE__ */ jsx(Select.Item, { value: option.value, children: option.label }, option.value)) })
|
|
317
|
+
]
|
|
318
|
+
}
|
|
319
|
+
) })
|
|
320
|
+
] }) });
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
const LocationField = ({ control }) => {
|
|
326
|
+
const locations = useComboboxData({
|
|
327
|
+
queryKey: ["locations"],
|
|
328
|
+
queryFn: async (params) => {
|
|
329
|
+
return await sdk.admin.stockLocation.list(params);
|
|
330
|
+
},
|
|
331
|
+
getOptions: (data) => {
|
|
332
|
+
return data.stock_locations.map((location) => ({
|
|
333
|
+
label: location.name,
|
|
334
|
+
value: location.id
|
|
335
|
+
}));
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
return /* @__PURE__ */ jsx(
|
|
339
|
+
Form.Field,
|
|
340
|
+
{
|
|
341
|
+
control,
|
|
342
|
+
name: "location_id",
|
|
343
|
+
render: ({ field }) => {
|
|
344
|
+
return /* @__PURE__ */ jsx(Form.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
345
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
346
|
+
/* @__PURE__ */ jsx(Form.Label, { children: "Location" }),
|
|
347
|
+
/* @__PURE__ */ jsx(Form.Hint, { children: "Choose where you want to ship the items from." })
|
|
348
|
+
] }),
|
|
349
|
+
/* @__PURE__ */ jsx(Form.Control, { children: /* @__PURE__ */ jsx(
|
|
350
|
+
Combobox,
|
|
351
|
+
{
|
|
352
|
+
options: locations.options,
|
|
353
|
+
fetchNextPage: locations.fetchNextPage,
|
|
354
|
+
isFetchingNextPage: locations.isFetchingNextPage,
|
|
355
|
+
searchValue: locations.searchValue,
|
|
356
|
+
onSearchValueChange: locations.onSearchValueChange,
|
|
357
|
+
placeholder: "Select location",
|
|
358
|
+
...field
|
|
359
|
+
}
|
|
360
|
+
) })
|
|
361
|
+
] }) });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
};
|
|
366
|
+
const ShippingOptionField = ({
|
|
367
|
+
orderId,
|
|
368
|
+
preview,
|
|
369
|
+
control
|
|
370
|
+
}) => {
|
|
371
|
+
var _a, _b;
|
|
372
|
+
const locationId = useWatch({ control, name: "location_id" });
|
|
373
|
+
const shippingProfileId = useWatch({ control, name: "shipping_profile_id" });
|
|
374
|
+
const shippingOptions = useComboboxData({
|
|
375
|
+
queryKey: ["shipping_options"],
|
|
376
|
+
queryFn: async (params) => {
|
|
377
|
+
return await sdk.admin.shippingOption.list({
|
|
378
|
+
...params,
|
|
379
|
+
stock_location_id: locationId,
|
|
380
|
+
shipping_profile_id: shippingProfileId
|
|
381
|
+
});
|
|
382
|
+
},
|
|
383
|
+
getOptions: (data) => {
|
|
384
|
+
return data.shipping_options.map((option) => ({
|
|
385
|
+
label: option.name,
|
|
386
|
+
value: option.id
|
|
387
|
+
}));
|
|
388
|
+
},
|
|
389
|
+
enabled: !!locationId && !!shippingProfileId,
|
|
390
|
+
defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
|
|
391
|
+
});
|
|
392
|
+
const { mutateAsync: addShippingMethod, isPending } = useOrderEditAddShippingMethod(orderId);
|
|
393
|
+
const onShippingOptionChange = async (value) => {
|
|
394
|
+
if (!value) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
await addShippingMethod(
|
|
398
|
+
{
|
|
399
|
+
shipping_option_id: value
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
onError: (e) => {
|
|
403
|
+
toast.error(e.message);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
);
|
|
407
|
+
};
|
|
408
|
+
const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
|
|
409
|
+
return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
410
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
411
|
+
/* @__PURE__ */ jsx(Label, { size: "small", weight: "plus", children: "Shipping option" }),
|
|
412
|
+
/* @__PURE__ */ jsx(Hint, { children: "Choose the shipping option to use." })
|
|
413
|
+
] }),
|
|
414
|
+
/* @__PURE__ */ jsx(
|
|
415
|
+
ConditionalTooltip,
|
|
416
|
+
{
|
|
417
|
+
content: tooltipContent,
|
|
418
|
+
showTooltip: !locationId || !shippingProfileId,
|
|
419
|
+
children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
|
|
420
|
+
Combobox,
|
|
421
|
+
{
|
|
422
|
+
options: shippingOptions.options,
|
|
423
|
+
fetchNextPage: shippingOptions.fetchNextPage,
|
|
424
|
+
isFetchingNextPage: shippingOptions.isFetchingNextPage,
|
|
425
|
+
searchValue: shippingOptions.searchValue,
|
|
426
|
+
onSearchValueChange: shippingOptions.onSearchValueChange,
|
|
427
|
+
placeholder: "Select shipping option",
|
|
428
|
+
onChange: onShippingOptionChange,
|
|
429
|
+
value: ((_b = preview.shipping_methods[0]) == null ? void 0 : _b.shipping_option_id) || void 0,
|
|
430
|
+
disabled: !locationId || !shippingProfileId || isPending
|
|
431
|
+
}
|
|
432
|
+
) })
|
|
433
|
+
}
|
|
434
|
+
)
|
|
435
|
+
] });
|
|
436
|
+
};
|
|
437
|
+
const LOCAL_STORAGE_KEY = "draft_order_shipping";
|
|
438
|
+
const getLocalStorageShippingInformation = () => {
|
|
439
|
+
const shippingInformation = localStorage.getItem(LOCAL_STORAGE_KEY);
|
|
440
|
+
return shippingInformation ? JSON.parse(shippingInformation) : null;
|
|
441
|
+
};
|
|
442
|
+
const updateLocalStorageShippingInformation = (shipping) => {
|
|
443
|
+
const shippingInformation = getLocalStorageShippingInformation();
|
|
444
|
+
if (!shippingInformation) {
|
|
445
|
+
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(shipping));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
localStorage.setItem(
|
|
449
|
+
LOCAL_STORAGE_KEY,
|
|
450
|
+
JSON.stringify({
|
|
451
|
+
...shippingInformation,
|
|
452
|
+
...shipping
|
|
453
|
+
})
|
|
454
|
+
);
|
|
455
|
+
};
|
|
456
|
+
function clearLocalStorageShippingInformation() {
|
|
457
|
+
localStorage.removeItem(LOCAL_STORAGE_KEY);
|
|
458
|
+
}
|
|
459
|
+
const schema = z.object({
|
|
460
|
+
shipping_profile_id: z.string(),
|
|
461
|
+
location_id: z.string()
|
|
462
|
+
});
|
|
463
|
+
export {
|
|
464
|
+
Shipping as default
|
|
465
|
+
};
|