@medusajs/draft-order 2.14.1 → 2.14.2-preview-20260426091727

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.
@@ -12088,584 +12088,108 @@ const ShippingAddressForm = ({ order }) => {
12088
12088
  ) });
12089
12089
  };
12090
12090
  const schema$1 = addressSchema;
12091
- const TransferOwnership = () => {
12091
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
12092
+ const Shipping = () => {
12093
+ var _a2;
12092
12094
  const { id } = reactRouterDom.useParams();
12093
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12094
- fields: "id,customer_id,customer.*"
12095
+ const { order, isPending, isError, error } = useOrder(id, {
12096
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12095
12097
  });
12098
+ const {
12099
+ order: preview,
12100
+ isPending: isPreviewPending,
12101
+ isError: isPreviewError,
12102
+ error: previewError
12103
+ } = useOrderPreview(id);
12104
+ useInitiateOrderEdit({ preview });
12105
+ const { onCancel } = useCancelOrderEdit({ preview });
12096
12106
  if (isError) {
12097
12107
  throw error;
12098
12108
  }
12099
- const isReady = !isPending && !!draft_order;
12100
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12101
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12102
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12103
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12104
- ] }),
12105
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12106
- ] });
12109
+ if (isPreviewError) {
12110
+ throw previewError;
12111
+ }
12112
+ const orderHasItems = (((_a2 = order == null ? void 0 : order.items) == null ? void 0 : _a2.length) || 0) > 0;
12113
+ const isReady = preview && !isPreviewPending && order && !isPending;
12114
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12115
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12116
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12117
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12118
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12119
+ ] }) }) }),
12120
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12121
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12122
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12123
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12124
+ ] }) });
12107
12125
  };
12108
- const TransferOwnershipForm = ({ order }) => {
12109
- var _a2, _b;
12110
- const form = reactHookForm.useForm({
12111
- defaultValues: {
12112
- customer_id: order.customer_id || ""
12126
+ const ShippingForm = ({ preview, order }) => {
12127
+ var _a2;
12128
+ const { setIsOpen } = useStackedModal();
12129
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12130
+ const [data, setData] = React.useState(null);
12131
+ const appliedShippingOptionIds = (_a2 = preview.shipping_methods) == null ? void 0 : _a2.map((method) => method.shipping_option_id).filter(Boolean);
12132
+ const { shipping_options } = useShippingOptions(
12133
+ {
12134
+ id: appliedShippingOptionIds,
12135
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12113
12136
  },
12114
- resolver: zod.zodResolver(schema)
12115
- });
12116
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12137
+ {
12138
+ enabled: appliedShippingOptionIds.length > 0
12139
+ }
12140
+ );
12141
+ const uniqueShippingProfiles = React.useMemo(() => {
12142
+ const profiles = /* @__PURE__ */ new Map();
12143
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12144
+ profiles.set(profile.id, profile);
12145
+ });
12146
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12147
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12148
+ });
12149
+ return Array.from(profiles.values());
12150
+ }, [order.items, shipping_options]);
12117
12151
  const { handleSuccess } = useRouteModal();
12118
- const name = [(_a2 = order.customer) == null ? void 0 : _a2.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12119
- const currentCustomer = order.customer ? {
12120
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12121
- value: order.customer.id
12122
- } : null;
12123
- const onSubmit = form.handleSubmit(async (data) => {
12124
- await mutateAsync(
12125
- { customer_id: data.customer_id },
12126
- {
12127
- onSuccess: () => {
12128
- ui.toast.success("Customer updated");
12129
- handleSuccess();
12130
- },
12131
- onError: (error) => {
12132
- ui.toast.error(error.message);
12133
- }
12152
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12153
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12154
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12155
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12156
+ const onSubmit = async () => {
12157
+ setIsSubmitting(true);
12158
+ let requestSucceeded = false;
12159
+ await requestOrderEdit(void 0, {
12160
+ onError: (e) => {
12161
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12162
+ },
12163
+ onSuccess: () => {
12164
+ requestSucceeded = true;
12134
12165
  }
12135
- );
12136
- });
12137
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12138
- KeyboundForm,
12139
- {
12140
- className: "flex flex-1 flex-col overflow-hidden",
12141
- onSubmit,
12142
- children: [
12143
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12144
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12145
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12146
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12147
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12148
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12149
- ] }),
12150
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12151
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12152
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12153
- ] })
12154
- ] }),
12155
- /* @__PURE__ */ jsxRuntime.jsx(
12156
- CustomerField,
12157
- {
12158
- control: form.control,
12159
- currentCustomerId: order.customer_id
12160
- }
12161
- )
12162
- ] }),
12163
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12164
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12165
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12166
- ] }) })
12167
- ]
12166
+ });
12167
+ if (!requestSucceeded) {
12168
+ setIsSubmitting(false);
12169
+ return;
12168
12170
  }
12169
- ) });
12170
- };
12171
- const CustomerField = ({ control, currentCustomerId }) => {
12172
- const customers = useComboboxData({
12173
- queryFn: async (params) => {
12174
- return await sdk.admin.customer.list({
12175
- ...params,
12176
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12177
- });
12171
+ await confirmOrderEdit(void 0, {
12172
+ onError: (e) => {
12173
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12174
+ },
12175
+ onSuccess: () => {
12176
+ handleSuccess();
12177
+ },
12178
+ onSettled: () => {
12179
+ setIsSubmitting(false);
12180
+ }
12181
+ });
12182
+ };
12183
+ const onKeydown = React.useCallback(
12184
+ (e) => {
12185
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12186
+ if (data || isSubmitting) {
12187
+ return;
12188
+ }
12189
+ onSubmit();
12190
+ }
12178
12191
  },
12179
- queryKey: ["customers"],
12180
- getOptions: (data) => {
12181
- return data.customers.map((customer) => {
12182
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12183
- return {
12184
- label: name ? `${name} (${customer.email})` : customer.email,
12185
- value: customer.id
12186
- };
12187
- });
12188
- }
12189
- });
12190
- return /* @__PURE__ */ jsxRuntime.jsx(
12191
- Form$2.Field,
12192
- {
12193
- name: "customer_id",
12194
- control,
12195
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12196
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12197
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12198
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12199
- ] }),
12200
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12201
- Combobox,
12202
- {
12203
- options: customers.options,
12204
- fetchNextPage: customers.fetchNextPage,
12205
- isFetchingNextPage: customers.isFetchingNextPage,
12206
- searchValue: customers.searchValue,
12207
- onSearchValueChange: customers.onSearchValueChange,
12208
- placeholder: "Select customer",
12209
- ...field
12210
- }
12211
- ) }),
12212
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12213
- ] })
12214
- }
12215
- );
12216
- };
12217
- const Illustration = () => {
12218
- return /* @__PURE__ */ jsxRuntime.jsxs(
12219
- "svg",
12220
- {
12221
- width: "280",
12222
- height: "180",
12223
- viewBox: "0 0 280 180",
12224
- fill: "none",
12225
- xmlns: "http://www.w3.org/2000/svg",
12226
- children: [
12227
- /* @__PURE__ */ jsxRuntime.jsx(
12228
- "rect",
12229
- {
12230
- x: "0.00428286",
12231
- y: "-0.742904",
12232
- width: "33.5",
12233
- height: "65.5",
12234
- rx: "6.75",
12235
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12236
- fill: "#D4D4D8",
12237
- stroke: "#52525B",
12238
- strokeWidth: "1.5"
12239
- }
12240
- ),
12241
- /* @__PURE__ */ jsxRuntime.jsx(
12242
- "rect",
12243
- {
12244
- x: "0.00428286",
12245
- y: "-0.742904",
12246
- width: "33.5",
12247
- height: "65.5",
12248
- rx: "6.75",
12249
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12250
- fill: "white",
12251
- stroke: "#52525B",
12252
- strokeWidth: "1.5"
12253
- }
12254
- ),
12255
- /* @__PURE__ */ jsxRuntime.jsx(
12256
- "path",
12257
- {
12258
- d: "M180.579 107.142L179.126 107.959",
12259
- stroke: "#52525B",
12260
- strokeWidth: "1.5",
12261
- strokeLinecap: "round",
12262
- strokeLinejoin: "round"
12263
- }
12264
- ),
12265
- /* @__PURE__ */ jsxRuntime.jsx(
12266
- "path",
12267
- {
12268
- opacity: "0.88",
12269
- d: "M182.305 109.546L180.257 109.534",
12270
- stroke: "#52525B",
12271
- strokeWidth: "1.5",
12272
- strokeLinecap: "round",
12273
- strokeLinejoin: "round"
12274
- }
12275
- ),
12276
- /* @__PURE__ */ jsxRuntime.jsx(
12277
- "path",
12278
- {
12279
- opacity: "0.75",
12280
- d: "M180.551 111.93L179.108 111.096",
12281
- stroke: "#52525B",
12282
- strokeWidth: "1.5",
12283
- strokeLinecap: "round",
12284
- strokeLinejoin: "round"
12285
- }
12286
- ),
12287
- /* @__PURE__ */ jsxRuntime.jsx(
12288
- "path",
12289
- {
12290
- opacity: "0.63",
12291
- d: "M176.347 112.897L176.354 111.73",
12292
- stroke: "#52525B",
12293
- strokeWidth: "1.5",
12294
- strokeLinecap: "round",
12295
- strokeLinejoin: "round"
12296
- }
12297
- ),
12298
- /* @__PURE__ */ jsxRuntime.jsx(
12299
- "path",
12300
- {
12301
- opacity: "0.5",
12302
- d: "M172.153 111.881L173.606 111.064",
12303
- stroke: "#52525B",
12304
- strokeWidth: "1.5",
12305
- strokeLinecap: "round",
12306
- strokeLinejoin: "round"
12307
- }
12308
- ),
12309
- /* @__PURE__ */ jsxRuntime.jsx(
12310
- "path",
12311
- {
12312
- opacity: "0.38",
12313
- d: "M170.428 109.478L172.476 109.489",
12314
- stroke: "#52525B",
12315
- strokeWidth: "1.5",
12316
- strokeLinecap: "round",
12317
- strokeLinejoin: "round"
12318
- }
12319
- ),
12320
- /* @__PURE__ */ jsxRuntime.jsx(
12321
- "path",
12322
- {
12323
- opacity: "0.25",
12324
- d: "M172.181 107.094L173.624 107.928",
12325
- stroke: "#52525B",
12326
- strokeWidth: "1.5",
12327
- strokeLinecap: "round",
12328
- strokeLinejoin: "round"
12329
- }
12330
- ),
12331
- /* @__PURE__ */ jsxRuntime.jsx(
12332
- "path",
12333
- {
12334
- opacity: "0.13",
12335
- d: "M176.386 106.126L176.379 107.294",
12336
- stroke: "#52525B",
12337
- strokeWidth: "1.5",
12338
- strokeLinecap: "round",
12339
- strokeLinejoin: "round"
12340
- }
12341
- ),
12342
- /* @__PURE__ */ jsxRuntime.jsx(
12343
- "rect",
12344
- {
12345
- width: "12",
12346
- height: "3",
12347
- rx: "1.5",
12348
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12349
- fill: "#D4D4D8"
12350
- }
12351
- ),
12352
- /* @__PURE__ */ jsxRuntime.jsx(
12353
- "rect",
12354
- {
12355
- x: "0.00428286",
12356
- y: "-0.742904",
12357
- width: "33.5",
12358
- height: "65.5",
12359
- rx: "6.75",
12360
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12361
- fill: "#D4D4D8",
12362
- stroke: "#52525B",
12363
- strokeWidth: "1.5"
12364
- }
12365
- ),
12366
- /* @__PURE__ */ jsxRuntime.jsx(
12367
- "rect",
12368
- {
12369
- x: "0.00428286",
12370
- y: "-0.742904",
12371
- width: "33.5",
12372
- height: "65.5",
12373
- rx: "6.75",
12374
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12375
- fill: "white",
12376
- stroke: "#52525B",
12377
- strokeWidth: "1.5"
12378
- }
12379
- ),
12380
- /* @__PURE__ */ jsxRuntime.jsx(
12381
- "rect",
12382
- {
12383
- width: "12",
12384
- height: "3",
12385
- rx: "1.5",
12386
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12387
- fill: "#D4D4D8"
12388
- }
12389
- ),
12390
- /* @__PURE__ */ jsxRuntime.jsx(
12391
- "rect",
12392
- {
12393
- width: "17",
12394
- height: "3",
12395
- rx: "1.5",
12396
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12397
- fill: "#D4D4D8"
12398
- }
12399
- ),
12400
- /* @__PURE__ */ jsxRuntime.jsx(
12401
- "rect",
12402
- {
12403
- width: "12",
12404
- height: "3",
12405
- rx: "1.5",
12406
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12407
- fill: "#D4D4D8"
12408
- }
12409
- ),
12410
- /* @__PURE__ */ jsxRuntime.jsx(
12411
- "path",
12412
- {
12413
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12414
- fill: "#A1A1AA"
12415
- }
12416
- ),
12417
- /* @__PURE__ */ jsxRuntime.jsx(
12418
- "rect",
12419
- {
12420
- width: "17",
12421
- height: "3",
12422
- rx: "1.5",
12423
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12424
- fill: "#A1A1AA"
12425
- }
12426
- ),
12427
- /* @__PURE__ */ jsxRuntime.jsx(
12428
- "rect",
12429
- {
12430
- width: "12",
12431
- height: "3",
12432
- rx: "1.5",
12433
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12434
- fill: "#A1A1AA"
12435
- }
12436
- ),
12437
- /* @__PURE__ */ jsxRuntime.jsx(
12438
- "path",
12439
- {
12440
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12441
- fill: "#52525B"
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12445
- "path",
12446
- {
12447
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12448
- stroke: "#A1A1AA",
12449
- strokeWidth: "1.5",
12450
- strokeLinecap: "round",
12451
- strokeLinejoin: "round"
12452
- }
12453
- ) }),
12454
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12455
- "path",
12456
- {
12457
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12458
- stroke: "#A1A1AA",
12459
- strokeWidth: "1.5",
12460
- strokeLinecap: "round",
12461
- strokeLinejoin: "round"
12462
- }
12463
- ) }),
12464
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12465
- "path",
12466
- {
12467
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12468
- stroke: "#A1A1AA",
12469
- strokeWidth: "1.5",
12470
- strokeLinecap: "round",
12471
- strokeLinejoin: "round"
12472
- }
12473
- ) }),
12474
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12475
- "path",
12476
- {
12477
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12478
- stroke: "#A1A1AA",
12479
- strokeWidth: "1.5",
12480
- strokeLinecap: "round",
12481
- strokeLinejoin: "round"
12482
- }
12483
- ) }),
12484
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12485
- "path",
12486
- {
12487
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12488
- stroke: "#A1A1AA",
12489
- strokeWidth: "1.5",
12490
- strokeLinecap: "round",
12491
- strokeLinejoin: "round"
12492
- }
12493
- ) }),
12494
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12495
- "path",
12496
- {
12497
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12498
- stroke: "#A1A1AA",
12499
- strokeWidth: "1.5",
12500
- strokeLinecap: "round",
12501
- strokeLinejoin: "round"
12502
- }
12503
- ) }),
12504
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12505
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12506
- "rect",
12507
- {
12508
- width: "12",
12509
- height: "12",
12510
- fill: "white",
12511
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12512
- }
12513
- ) }),
12514
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12515
- "rect",
12516
- {
12517
- width: "12",
12518
- height: "12",
12519
- fill: "white",
12520
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12521
- }
12522
- ) }),
12523
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12524
- "rect",
12525
- {
12526
- width: "12",
12527
- height: "12",
12528
- fill: "white",
12529
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12530
- }
12531
- ) }),
12532
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12533
- "rect",
12534
- {
12535
- width: "12",
12536
- height: "12",
12537
- fill: "white",
12538
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12539
- }
12540
- ) }),
12541
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12542
- "rect",
12543
- {
12544
- width: "12",
12545
- height: "12",
12546
- fill: "white",
12547
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12548
- }
12549
- ) }),
12550
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12551
- "rect",
12552
- {
12553
- width: "12",
12554
- height: "12",
12555
- fill: "white",
12556
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12557
- }
12558
- ) })
12559
- ] })
12560
- ]
12561
- }
12562
- );
12563
- };
12564
- const schema = object({
12565
- customer_id: string().min(1)
12566
- });
12567
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12568
- const Shipping = () => {
12569
- var _a2;
12570
- const { id } = reactRouterDom.useParams();
12571
- const { order, isPending, isError, error } = useOrder(id, {
12572
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12573
- });
12574
- const {
12575
- order: preview,
12576
- isPending: isPreviewPending,
12577
- isError: isPreviewError,
12578
- error: previewError
12579
- } = useOrderPreview(id);
12580
- useInitiateOrderEdit({ preview });
12581
- const { onCancel } = useCancelOrderEdit({ preview });
12582
- if (isError) {
12583
- throw error;
12584
- }
12585
- if (isPreviewError) {
12586
- throw previewError;
12587
- }
12588
- const orderHasItems = (((_a2 = order == null ? void 0 : order.items) == null ? void 0 : _a2.length) || 0) > 0;
12589
- const isReady = preview && !isPreviewPending && order && !isPending;
12590
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12591
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12592
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12593
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12594
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12595
- ] }) }) }),
12596
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12597
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12598
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12599
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12600
- ] }) });
12601
- };
12602
- const ShippingForm = ({ preview, order }) => {
12603
- var _a2;
12604
- const { setIsOpen } = useStackedModal();
12605
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12606
- const [data, setData] = React.useState(null);
12607
- const appliedShippingOptionIds = (_a2 = preview.shipping_methods) == null ? void 0 : _a2.map((method) => method.shipping_option_id).filter(Boolean);
12608
- const { shipping_options } = useShippingOptions(
12609
- {
12610
- id: appliedShippingOptionIds,
12611
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12612
- },
12613
- {
12614
- enabled: appliedShippingOptionIds.length > 0
12615
- }
12616
- );
12617
- const uniqueShippingProfiles = React.useMemo(() => {
12618
- const profiles = /* @__PURE__ */ new Map();
12619
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12620
- profiles.set(profile.id, profile);
12621
- });
12622
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12623
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12624
- });
12625
- return Array.from(profiles.values());
12626
- }, [order.items, shipping_options]);
12627
- const { handleSuccess } = useRouteModal();
12628
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12629
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12630
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12631
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12632
- const onSubmit = async () => {
12633
- setIsSubmitting(true);
12634
- let requestSucceeded = false;
12635
- await requestOrderEdit(void 0, {
12636
- onError: (e) => {
12637
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12638
- },
12639
- onSuccess: () => {
12640
- requestSucceeded = true;
12641
- }
12642
- });
12643
- if (!requestSucceeded) {
12644
- setIsSubmitting(false);
12645
- return;
12646
- }
12647
- await confirmOrderEdit(void 0, {
12648
- onError: (e) => {
12649
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12650
- },
12651
- onSuccess: () => {
12652
- handleSuccess();
12653
- },
12654
- onSettled: () => {
12655
- setIsSubmitting(false);
12656
- }
12657
- });
12658
- };
12659
- const onKeydown = React.useCallback(
12660
- (e) => {
12661
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12662
- if (data || isSubmitting) {
12663
- return;
12664
- }
12665
- onSubmit();
12666
- }
12667
- },
12668
- [data, isSubmitting, onSubmit]
12192
+ [data, isSubmitting, onSubmit]
12669
12193
  );
12670
12194
  React.useEffect(() => {
12671
12195
  document.addEventListener("keydown", onKeydown);
@@ -13228,149 +12752,625 @@ const LocationField = ({ control, setValue }) => {
13228
12752
  const locations = useComboboxData({
13229
12753
  queryKey: ["locations"],
13230
12754
  queryFn: async (params) => {
13231
- return await sdk.admin.stockLocation.list(params);
12755
+ return await sdk.admin.stockLocation.list(params);
12756
+ },
12757
+ getOptions: (data) => {
12758
+ return data.stock_locations.map((location) => ({
12759
+ label: location.name,
12760
+ value: location.id
12761
+ }));
12762
+ }
12763
+ });
12764
+ return /* @__PURE__ */ jsxRuntime.jsx(
12765
+ Form$2.Field,
12766
+ {
12767
+ control,
12768
+ name: "location_id",
12769
+ render: ({ field: { onChange, ...field } }) => {
12770
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12771
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12772
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12773
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12774
+ ] }),
12775
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12776
+ Combobox,
12777
+ {
12778
+ options: locations.options,
12779
+ fetchNextPage: locations.fetchNextPage,
12780
+ isFetchingNextPage: locations.isFetchingNextPage,
12781
+ searchValue: locations.searchValue,
12782
+ onSearchValueChange: locations.onSearchValueChange,
12783
+ placeholder: "Select location",
12784
+ onChange: (value) => {
12785
+ setValue("shipping_option_id", "", {
12786
+ shouldDirty: true,
12787
+ shouldTouch: true
12788
+ });
12789
+ onChange(value);
12790
+ },
12791
+ ...field
12792
+ }
12793
+ ) })
12794
+ ] }) });
12795
+ }
12796
+ }
12797
+ );
12798
+ };
12799
+ const ShippingOptionField = ({
12800
+ shippingProfileId,
12801
+ preview,
12802
+ control
12803
+ }) => {
12804
+ var _a2;
12805
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12806
+ const shippingOptions = useComboboxData({
12807
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12808
+ queryFn: async (params) => {
12809
+ return await sdk.admin.shippingOption.list({
12810
+ ...params,
12811
+ stock_location_id: locationId,
12812
+ shipping_profile_id: shippingProfileId
12813
+ });
12814
+ },
12815
+ getOptions: (data) => {
12816
+ return data.shipping_options.map((option) => {
12817
+ var _a3;
12818
+ if ((_a3 = option.rules) == null ? void 0 : _a3.find(
12819
+ (r) => r.attribute === "is_return" && r.value === "true"
12820
+ )) {
12821
+ return void 0;
12822
+ }
12823
+ return {
12824
+ label: option.name,
12825
+ value: option.id
12826
+ };
12827
+ }).filter(Boolean);
12828
+ },
12829
+ enabled: !!locationId && !!shippingProfileId,
12830
+ defaultValue: ((_a2 = preview.shipping_methods[0]) == null ? void 0 : _a2.shipping_option_id) || void 0
12831
+ });
12832
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12833
+ return /* @__PURE__ */ jsxRuntime.jsx(
12834
+ Form$2.Field,
12835
+ {
12836
+ control,
12837
+ name: "shipping_option_id",
12838
+ render: ({ field }) => {
12839
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12840
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12841
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12842
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12843
+ ] }),
12844
+ /* @__PURE__ */ jsxRuntime.jsx(
12845
+ ConditionalTooltip,
12846
+ {
12847
+ content: tooltipContent,
12848
+ showTooltip: !locationId || !shippingProfileId,
12849
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12850
+ Combobox,
12851
+ {
12852
+ options: shippingOptions.options,
12853
+ fetchNextPage: shippingOptions.fetchNextPage,
12854
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12855
+ searchValue: shippingOptions.searchValue,
12856
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12857
+ placeholder: "Select shipping option",
12858
+ ...field,
12859
+ disabled: !locationId || !shippingProfileId
12860
+ }
12861
+ ) }) })
12862
+ }
12863
+ )
12864
+ ] }) });
12865
+ }
12866
+ }
12867
+ );
12868
+ };
12869
+ const CustomAmountField = ({
12870
+ control,
12871
+ currencyCode
12872
+ }) => {
12873
+ return /* @__PURE__ */ jsxRuntime.jsx(
12874
+ Form$2.Field,
12875
+ {
12876
+ control,
12877
+ name: "custom_amount",
12878
+ render: ({ field: { onChange, ...field } }) => {
12879
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12880
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12881
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12882
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12883
+ ] }),
12884
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12885
+ ui.CurrencyInput,
12886
+ {
12887
+ ...field,
12888
+ onValueChange: (value) => onChange(value),
12889
+ symbol: getNativeSymbol(currencyCode),
12890
+ code: currencyCode
12891
+ }
12892
+ ) })
12893
+ ] });
12894
+ }
12895
+ }
12896
+ );
12897
+ };
12898
+ const TransferOwnership = () => {
12899
+ const { id } = reactRouterDom.useParams();
12900
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12901
+ fields: "id,customer_id,customer.*"
12902
+ });
12903
+ if (isError) {
12904
+ throw error;
12905
+ }
12906
+ const isReady = !isPending && !!draft_order;
12907
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12908
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12909
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12910
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12911
+ ] }),
12912
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12913
+ ] });
12914
+ };
12915
+ const TransferOwnershipForm = ({ order }) => {
12916
+ var _a2, _b;
12917
+ const form = reactHookForm.useForm({
12918
+ defaultValues: {
12919
+ customer_id: order.customer_id || ""
12920
+ },
12921
+ resolver: zod.zodResolver(schema)
12922
+ });
12923
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12924
+ const { handleSuccess } = useRouteModal();
12925
+ const name = [(_a2 = order.customer) == null ? void 0 : _a2.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12926
+ const currentCustomer = order.customer ? {
12927
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12928
+ value: order.customer.id
12929
+ } : null;
12930
+ const onSubmit = form.handleSubmit(async (data) => {
12931
+ await mutateAsync(
12932
+ { customer_id: data.customer_id },
12933
+ {
12934
+ onSuccess: () => {
12935
+ ui.toast.success("Customer updated");
12936
+ handleSuccess();
12937
+ },
12938
+ onError: (error) => {
12939
+ ui.toast.error(error.message);
12940
+ }
12941
+ }
12942
+ );
12943
+ });
12944
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12945
+ KeyboundForm,
12946
+ {
12947
+ className: "flex flex-1 flex-col overflow-hidden",
12948
+ onSubmit,
12949
+ children: [
12950
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12951
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12952
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12953
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12954
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12955
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12956
+ ] }),
12957
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12960
+ ] })
12961
+ ] }),
12962
+ /* @__PURE__ */ jsxRuntime.jsx(
12963
+ CustomerField,
12964
+ {
12965
+ control: form.control,
12966
+ currentCustomerId: order.customer_id
12967
+ }
12968
+ )
12969
+ ] }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12971
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12973
+ ] }) })
12974
+ ]
12975
+ }
12976
+ ) });
12977
+ };
12978
+ const CustomerField = ({ control, currentCustomerId }) => {
12979
+ const customers = useComboboxData({
12980
+ queryFn: async (params) => {
12981
+ return await sdk.admin.customer.list({
12982
+ ...params,
12983
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12984
+ });
13232
12985
  },
12986
+ queryKey: ["customers"],
13233
12987
  getOptions: (data) => {
13234
- return data.stock_locations.map((location) => ({
13235
- label: location.name,
13236
- value: location.id
13237
- }));
12988
+ return data.customers.map((customer) => {
12989
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12990
+ return {
12991
+ label: name ? `${name} (${customer.email})` : customer.email,
12992
+ value: customer.id
12993
+ };
12994
+ });
13238
12995
  }
13239
12996
  });
13240
12997
  return /* @__PURE__ */ jsxRuntime.jsx(
13241
12998
  Form$2.Field,
13242
12999
  {
13000
+ name: "customer_id",
13243
13001
  control,
13244
- name: "location_id",
13245
- render: ({ field: { onChange, ...field } }) => {
13246
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13247
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13248
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
13249
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
13250
- ] }),
13251
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13252
- Combobox,
13002
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
13003
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13004
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
13005
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
13006
+ ] }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13008
+ Combobox,
13009
+ {
13010
+ options: customers.options,
13011
+ fetchNextPage: customers.fetchNextPage,
13012
+ isFetchingNextPage: customers.isFetchingNextPage,
13013
+ searchValue: customers.searchValue,
13014
+ onSearchValueChange: customers.onSearchValueChange,
13015
+ placeholder: "Select customer",
13016
+ ...field
13017
+ }
13018
+ ) }),
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13020
+ ] })
13021
+ }
13022
+ );
13023
+ };
13024
+ const Illustration = () => {
13025
+ return /* @__PURE__ */ jsxRuntime.jsxs(
13026
+ "svg",
13027
+ {
13028
+ width: "280",
13029
+ height: "180",
13030
+ viewBox: "0 0 280 180",
13031
+ fill: "none",
13032
+ xmlns: "http://www.w3.org/2000/svg",
13033
+ children: [
13034
+ /* @__PURE__ */ jsxRuntime.jsx(
13035
+ "rect",
13036
+ {
13037
+ x: "0.00428286",
13038
+ y: "-0.742904",
13039
+ width: "33.5",
13040
+ height: "65.5",
13041
+ rx: "6.75",
13042
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
13043
+ fill: "#D4D4D8",
13044
+ stroke: "#52525B",
13045
+ strokeWidth: "1.5"
13046
+ }
13047
+ ),
13048
+ /* @__PURE__ */ jsxRuntime.jsx(
13049
+ "rect",
13050
+ {
13051
+ x: "0.00428286",
13052
+ y: "-0.742904",
13053
+ width: "33.5",
13054
+ height: "65.5",
13055
+ rx: "6.75",
13056
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
13057
+ fill: "white",
13058
+ stroke: "#52525B",
13059
+ strokeWidth: "1.5"
13060
+ }
13061
+ ),
13062
+ /* @__PURE__ */ jsxRuntime.jsx(
13063
+ "path",
13064
+ {
13065
+ d: "M180.579 107.142L179.126 107.959",
13066
+ stroke: "#52525B",
13067
+ strokeWidth: "1.5",
13068
+ strokeLinecap: "round",
13069
+ strokeLinejoin: "round"
13070
+ }
13071
+ ),
13072
+ /* @__PURE__ */ jsxRuntime.jsx(
13073
+ "path",
13074
+ {
13075
+ opacity: "0.88",
13076
+ d: "M182.305 109.546L180.257 109.534",
13077
+ stroke: "#52525B",
13078
+ strokeWidth: "1.5",
13079
+ strokeLinecap: "round",
13080
+ strokeLinejoin: "round"
13081
+ }
13082
+ ),
13083
+ /* @__PURE__ */ jsxRuntime.jsx(
13084
+ "path",
13085
+ {
13086
+ opacity: "0.75",
13087
+ d: "M180.551 111.93L179.108 111.096",
13088
+ stroke: "#52525B",
13089
+ strokeWidth: "1.5",
13090
+ strokeLinecap: "round",
13091
+ strokeLinejoin: "round"
13092
+ }
13093
+ ),
13094
+ /* @__PURE__ */ jsxRuntime.jsx(
13095
+ "path",
13096
+ {
13097
+ opacity: "0.63",
13098
+ d: "M176.347 112.897L176.354 111.73",
13099
+ stroke: "#52525B",
13100
+ strokeWidth: "1.5",
13101
+ strokeLinecap: "round",
13102
+ strokeLinejoin: "round"
13103
+ }
13104
+ ),
13105
+ /* @__PURE__ */ jsxRuntime.jsx(
13106
+ "path",
13107
+ {
13108
+ opacity: "0.5",
13109
+ d: "M172.153 111.881L173.606 111.064",
13110
+ stroke: "#52525B",
13111
+ strokeWidth: "1.5",
13112
+ strokeLinecap: "round",
13113
+ strokeLinejoin: "round"
13114
+ }
13115
+ ),
13116
+ /* @__PURE__ */ jsxRuntime.jsx(
13117
+ "path",
13118
+ {
13119
+ opacity: "0.38",
13120
+ d: "M170.428 109.478L172.476 109.489",
13121
+ stroke: "#52525B",
13122
+ strokeWidth: "1.5",
13123
+ strokeLinecap: "round",
13124
+ strokeLinejoin: "round"
13125
+ }
13126
+ ),
13127
+ /* @__PURE__ */ jsxRuntime.jsx(
13128
+ "path",
13129
+ {
13130
+ opacity: "0.25",
13131
+ d: "M172.181 107.094L173.624 107.928",
13132
+ stroke: "#52525B",
13133
+ strokeWidth: "1.5",
13134
+ strokeLinecap: "round",
13135
+ strokeLinejoin: "round"
13136
+ }
13137
+ ),
13138
+ /* @__PURE__ */ jsxRuntime.jsx(
13139
+ "path",
13140
+ {
13141
+ opacity: "0.13",
13142
+ d: "M176.386 106.126L176.379 107.294",
13143
+ stroke: "#52525B",
13144
+ strokeWidth: "1.5",
13145
+ strokeLinecap: "round",
13146
+ strokeLinejoin: "round"
13147
+ }
13148
+ ),
13149
+ /* @__PURE__ */ jsxRuntime.jsx(
13150
+ "rect",
13151
+ {
13152
+ width: "12",
13153
+ height: "3",
13154
+ rx: "1.5",
13155
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
13156
+ fill: "#D4D4D8"
13157
+ }
13158
+ ),
13159
+ /* @__PURE__ */ jsxRuntime.jsx(
13160
+ "rect",
13161
+ {
13162
+ x: "0.00428286",
13163
+ y: "-0.742904",
13164
+ width: "33.5",
13165
+ height: "65.5",
13166
+ rx: "6.75",
13167
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
13168
+ fill: "#D4D4D8",
13169
+ stroke: "#52525B",
13170
+ strokeWidth: "1.5"
13171
+ }
13172
+ ),
13173
+ /* @__PURE__ */ jsxRuntime.jsx(
13174
+ "rect",
13175
+ {
13176
+ x: "0.00428286",
13177
+ y: "-0.742904",
13178
+ width: "33.5",
13179
+ height: "65.5",
13180
+ rx: "6.75",
13181
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
13182
+ fill: "white",
13183
+ stroke: "#52525B",
13184
+ strokeWidth: "1.5"
13185
+ }
13186
+ ),
13187
+ /* @__PURE__ */ jsxRuntime.jsx(
13188
+ "rect",
13189
+ {
13190
+ width: "12",
13191
+ height: "3",
13192
+ rx: "1.5",
13193
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
13194
+ fill: "#D4D4D8"
13195
+ }
13196
+ ),
13197
+ /* @__PURE__ */ jsxRuntime.jsx(
13198
+ "rect",
13199
+ {
13200
+ width: "17",
13201
+ height: "3",
13202
+ rx: "1.5",
13203
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
13204
+ fill: "#D4D4D8"
13205
+ }
13206
+ ),
13207
+ /* @__PURE__ */ jsxRuntime.jsx(
13208
+ "rect",
13209
+ {
13210
+ width: "12",
13211
+ height: "3",
13212
+ rx: "1.5",
13213
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
13214
+ fill: "#D4D4D8"
13215
+ }
13216
+ ),
13217
+ /* @__PURE__ */ jsxRuntime.jsx(
13218
+ "path",
13219
+ {
13220
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
13221
+ fill: "#A1A1AA"
13222
+ }
13223
+ ),
13224
+ /* @__PURE__ */ jsxRuntime.jsx(
13225
+ "rect",
13226
+ {
13227
+ width: "17",
13228
+ height: "3",
13229
+ rx: "1.5",
13230
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
13231
+ fill: "#A1A1AA"
13232
+ }
13233
+ ),
13234
+ /* @__PURE__ */ jsxRuntime.jsx(
13235
+ "rect",
13236
+ {
13237
+ width: "12",
13238
+ height: "3",
13239
+ rx: "1.5",
13240
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
13241
+ fill: "#A1A1AA"
13242
+ }
13243
+ ),
13244
+ /* @__PURE__ */ jsxRuntime.jsx(
13245
+ "path",
13246
+ {
13247
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
13248
+ fill: "#52525B"
13249
+ }
13250
+ ),
13251
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13252
+ "path",
13253
+ {
13254
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
13255
+ stroke: "#A1A1AA",
13256
+ strokeWidth: "1.5",
13257
+ strokeLinecap: "round",
13258
+ strokeLinejoin: "round"
13259
+ }
13260
+ ) }),
13261
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13262
+ "path",
13263
+ {
13264
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
13265
+ stroke: "#A1A1AA",
13266
+ strokeWidth: "1.5",
13267
+ strokeLinecap: "round",
13268
+ strokeLinejoin: "round"
13269
+ }
13270
+ ) }),
13271
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13272
+ "path",
13273
+ {
13274
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
13275
+ stroke: "#A1A1AA",
13276
+ strokeWidth: "1.5",
13277
+ strokeLinecap: "round",
13278
+ strokeLinejoin: "round"
13279
+ }
13280
+ ) }),
13281
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13282
+ "path",
13283
+ {
13284
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
13285
+ stroke: "#A1A1AA",
13286
+ strokeWidth: "1.5",
13287
+ strokeLinecap: "round",
13288
+ strokeLinejoin: "round"
13289
+ }
13290
+ ) }),
13291
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13292
+ "path",
13293
+ {
13294
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
13295
+ stroke: "#A1A1AA",
13296
+ strokeWidth: "1.5",
13297
+ strokeLinecap: "round",
13298
+ strokeLinejoin: "round"
13299
+ }
13300
+ ) }),
13301
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13302
+ "path",
13303
+ {
13304
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
13305
+ stroke: "#A1A1AA",
13306
+ strokeWidth: "1.5",
13307
+ strokeLinecap: "round",
13308
+ strokeLinejoin: "round"
13309
+ }
13310
+ ) }),
13311
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
13312
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13313
+ "rect",
13253
13314
  {
13254
- options: locations.options,
13255
- fetchNextPage: locations.fetchNextPage,
13256
- isFetchingNextPage: locations.isFetchingNextPage,
13257
- searchValue: locations.searchValue,
13258
- onSearchValueChange: locations.onSearchValueChange,
13259
- placeholder: "Select location",
13260
- onChange: (value) => {
13261
- setValue("shipping_option_id", "", {
13262
- shouldDirty: true,
13263
- shouldTouch: true
13264
- });
13265
- onChange(value);
13266
- },
13267
- ...field
13315
+ width: "12",
13316
+ height: "12",
13317
+ fill: "white",
13318
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
13268
13319
  }
13269
- ) })
13270
- ] }) });
13271
- }
13272
- }
13273
- );
13274
- };
13275
- const ShippingOptionField = ({
13276
- shippingProfileId,
13277
- preview,
13278
- control
13279
- }) => {
13280
- var _a2;
13281
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
13282
- const shippingOptions = useComboboxData({
13283
- queryKey: ["shipping_options", locationId, shippingProfileId],
13284
- queryFn: async (params) => {
13285
- return await sdk.admin.shippingOption.list({
13286
- ...params,
13287
- stock_location_id: locationId,
13288
- shipping_profile_id: shippingProfileId
13289
- });
13290
- },
13291
- getOptions: (data) => {
13292
- return data.shipping_options.map((option) => {
13293
- var _a3;
13294
- if ((_a3 = option.rules) == null ? void 0 : _a3.find(
13295
- (r) => r.attribute === "is_return" && r.value === "true"
13296
- )) {
13297
- return void 0;
13298
- }
13299
- return {
13300
- label: option.name,
13301
- value: option.id
13302
- };
13303
- }).filter(Boolean);
13304
- },
13305
- enabled: !!locationId && !!shippingProfileId,
13306
- defaultValue: ((_a2 = preview.shipping_methods[0]) == null ? void 0 : _a2.shipping_option_id) || void 0
13307
- });
13308
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
13309
- return /* @__PURE__ */ jsxRuntime.jsx(
13310
- Form$2.Field,
13311
- {
13312
- control,
13313
- name: "shipping_option_id",
13314
- render: ({ field }) => {
13315
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13316
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13317
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
13318
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
13319
- ] }),
13320
- /* @__PURE__ */ jsxRuntime.jsx(
13321
- ConditionalTooltip,
13320
+ ) }),
13321
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13322
+ "rect",
13322
13323
  {
13323
- content: tooltipContent,
13324
- showTooltip: !locationId || !shippingProfileId,
13325
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13326
- Combobox,
13327
- {
13328
- options: shippingOptions.options,
13329
- fetchNextPage: shippingOptions.fetchNextPage,
13330
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
13331
- searchValue: shippingOptions.searchValue,
13332
- onSearchValueChange: shippingOptions.onSearchValueChange,
13333
- placeholder: "Select shipping option",
13334
- ...field,
13335
- disabled: !locationId || !shippingProfileId
13336
- }
13337
- ) }) })
13324
+ width: "12",
13325
+ height: "12",
13326
+ fill: "white",
13327
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13338
13328
  }
13339
- )
13340
- ] }) });
13341
- }
13342
- }
13343
- );
13344
- };
13345
- const CustomAmountField = ({
13346
- control,
13347
- currencyCode
13348
- }) => {
13349
- return /* @__PURE__ */ jsxRuntime.jsx(
13350
- Form$2.Field,
13351
- {
13352
- control,
13353
- name: "custom_amount",
13354
- render: ({ field: { onChange, ...field } }) => {
13355
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13356
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13357
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13358
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
13359
- ] }),
13360
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13361
- ui.CurrencyInput,
13329
+ ) }),
13330
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13331
+ "rect",
13362
13332
  {
13363
- ...field,
13364
- onValueChange: (value) => onChange(value),
13365
- symbol: getNativeSymbol(currencyCode),
13366
- code: currencyCode
13333
+ width: "12",
13334
+ height: "12",
13335
+ fill: "white",
13336
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13337
+ }
13338
+ ) }),
13339
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13340
+ "rect",
13341
+ {
13342
+ width: "12",
13343
+ height: "12",
13344
+ fill: "white",
13345
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13346
+ }
13347
+ ) }),
13348
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13349
+ "rect",
13350
+ {
13351
+ width: "12",
13352
+ height: "12",
13353
+ fill: "white",
13354
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13355
+ }
13356
+ ) }),
13357
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13358
+ "rect",
13359
+ {
13360
+ width: "12",
13361
+ height: "12",
13362
+ fill: "white",
13363
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13367
13364
  }
13368
13365
  ) })
13369
- ] });
13370
- }
13366
+ ] })
13367
+ ]
13371
13368
  }
13372
13369
  );
13373
13370
  };
13371
+ const schema = object({
13372
+ customer_id: string().min(1)
13373
+ });
13374
13374
  const widgetModule = { widgets: [] };
13375
13375
  const routeModule = {
13376
13376
  routes: [
@@ -13423,13 +13423,13 @@ const routeModule = {
13423
13423
  Component: ShippingAddress,
13424
13424
  path: "/draft-orders/:id/shipping-address"
13425
13425
  },
13426
- {
13427
- Component: TransferOwnership,
13428
- path: "/draft-orders/:id/transfer-ownership"
13429
- },
13430
13426
  {
13431
13427
  Component: Shipping,
13432
13428
  path: "/draft-orders/:id/shipping"
13429
+ },
13430
+ {
13431
+ Component: TransferOwnership,
13432
+ path: "/draft-orders/:id/transfer-ownership"
13433
13433
  }
13434
13434
  ]
13435
13435
  }