@medusajs/draft-order 2.10.3-snapshot-20250915125232 → 2.10.3-snapshot-20250915222840

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.
@@ -11369,821 +11369,142 @@ const SalesChannelField = ({ control, order }) => {
11369
11369
  const schema$3 = objectType({
11370
11370
  sales_channel_id: stringType().min(1)
11371
11371
  });
11372
- const ShippingAddress = () => {
11372
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11373
+ const Shipping = () => {
11374
+ var _a;
11373
11375
  const { id } = reactRouterDom.useParams();
11374
11376
  const { order, isPending, isError, error } = useOrder(id, {
11375
- fields: "+shipping_address"
11377
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11376
11378
  });
11379
+ const {
11380
+ order: preview,
11381
+ isPending: isPreviewPending,
11382
+ isError: isPreviewError,
11383
+ error: previewError
11384
+ } = useOrderPreview(id);
11385
+ useInitiateOrderEdit({ preview });
11386
+ const { onCancel } = useCancelOrderEdit({ preview });
11377
11387
  if (isError) {
11378
11388
  throw error;
11379
11389
  }
11380
- const isReady = !isPending && !!order;
11381
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11382
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11383
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11384
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11385
- ] }),
11386
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11387
- ] });
11390
+ if (isPreviewError) {
11391
+ throw previewError;
11392
+ }
11393
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11394
+ const isReady = preview && !isPreviewPending && order && !isPending;
11395
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11396
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11397
+ /* @__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 py-16 px-6", children: [
11398
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11399
+ /* @__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." }) })
11400
+ ] }) }) }),
11401
+ /* @__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" }) }) })
11402
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11403
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11404
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11405
+ ] }) });
11388
11406
  };
11389
- const ShippingAddressForm = ({ order }) => {
11390
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11391
- const form = reactHookForm.useForm({
11392
- defaultValues: {
11393
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11394
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11395
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11396
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11397
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11398
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11399
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11400
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11401
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11402
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11407
+ const ShippingForm = ({ preview, order }) => {
11408
+ var _a;
11409
+ const { setIsOpen } = useStackedModal();
11410
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11411
+ const [data, setData] = React.useState(null);
11412
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11413
+ const { shipping_options } = useShippingOptions(
11414
+ {
11415
+ id: appliedShippingOptionIds,
11416
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11403
11417
  },
11404
- resolver: zod.zodResolver(schema$2)
11405
- });
11406
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11418
+ {
11419
+ enabled: appliedShippingOptionIds.length > 0
11420
+ }
11421
+ );
11422
+ const uniqueShippingProfiles = React.useMemo(() => {
11423
+ const profiles = /* @__PURE__ */ new Map();
11424
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11425
+ profiles.set(profile.id, profile);
11426
+ });
11427
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11428
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11429
+ });
11430
+ return Array.from(profiles.values());
11431
+ }, [order.items, shipping_options]);
11407
11432
  const { handleSuccess } = useRouteModal();
11408
- const onSubmit = form.handleSubmit(async (data) => {
11409
- await mutateAsync(
11410
- {
11411
- shipping_address: {
11412
- first_name: data.first_name,
11413
- last_name: data.last_name,
11414
- company: data.company,
11415
- address_1: data.address_1,
11416
- address_2: data.address_2,
11417
- city: data.city,
11418
- province: data.province,
11419
- country_code: data.country_code,
11420
- postal_code: data.postal_code,
11421
- phone: data.phone
11422
- }
11433
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11434
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11435
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11436
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11437
+ const onSubmit = async () => {
11438
+ setIsSubmitting(true);
11439
+ let requestSucceeded = false;
11440
+ await requestOrderEdit(void 0, {
11441
+ onError: (e) => {
11442
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11423
11443
  },
11424
- {
11425
- onSuccess: () => {
11426
- handleSuccess();
11427
- },
11428
- onError: (error) => {
11429
- ui.toast.error(error.message);
11444
+ onSuccess: () => {
11445
+ requestSucceeded = true;
11446
+ }
11447
+ });
11448
+ if (!requestSucceeded) {
11449
+ setIsSubmitting(false);
11450
+ return;
11451
+ }
11452
+ await confirmOrderEdit(void 0, {
11453
+ onError: (e) => {
11454
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11455
+ },
11456
+ onSuccess: () => {
11457
+ handleSuccess();
11458
+ },
11459
+ onSettled: () => {
11460
+ setIsSubmitting(false);
11461
+ }
11462
+ });
11463
+ };
11464
+ const onKeydown = React.useCallback(
11465
+ (e) => {
11466
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11467
+ if (data || isSubmitting) {
11468
+ return;
11430
11469
  }
11470
+ onSubmit();
11431
11471
  }
11432
- );
11433
- });
11434
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11435
- KeyboundForm,
11436
- {
11437
- className: "flex flex-1 flex-col overflow-hidden",
11438
- onSubmit,
11439
- children: [
11440
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11441
- /* @__PURE__ */ jsxRuntime.jsx(
11442
- Form$2.Field,
11443
- {
11444
- control: form.control,
11445
- name: "country_code",
11446
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11450
- ] })
11451
- }
11452
- ),
11453
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11472
+ },
11473
+ [data, isSubmitting, onSubmit]
11474
+ );
11475
+ React.useEffect(() => {
11476
+ document.addEventListener("keydown", onKeydown);
11477
+ return () => {
11478
+ document.removeEventListener("keydown", onKeydown);
11479
+ };
11480
+ }, [onKeydown]);
11481
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11482
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11483
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11484
+ /* @__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 py-16 px-6", children: [
11485
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11486
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11487
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11488
+ ] }),
11489
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11490
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11491
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11454
11492
  /* @__PURE__ */ jsxRuntime.jsx(
11455
- Form$2.Field,
11493
+ ui.Text,
11456
11494
  {
11457
- control: form.control,
11458
- name: "first_name",
11459
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11461
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11462
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11463
- ] })
11495
+ size: "xsmall",
11496
+ weight: "plus",
11497
+ className: "text-ui-fg-muted",
11498
+ children: "Shipping profile"
11464
11499
  }
11465
11500
  ),
11466
11501
  /* @__PURE__ */ jsxRuntime.jsx(
11467
- Form$2.Field,
11502
+ ui.Text,
11468
11503
  {
11469
- control: form.control,
11470
- name: "last_name",
11471
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11472
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11473
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11474
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11475
- ] })
11476
- }
11477
- )
11478
- ] }),
11479
- /* @__PURE__ */ jsxRuntime.jsx(
11480
- Form$2.Field,
11481
- {
11482
- control: form.control,
11483
- name: "company",
11484
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11485
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11486
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11487
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11488
- ] })
11489
- }
11490
- ),
11491
- /* @__PURE__ */ jsxRuntime.jsx(
11492
- Form$2.Field,
11493
- {
11494
- control: form.control,
11495
- name: "address_1",
11496
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11498
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11499
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11500
- ] })
11501
- }
11502
- ),
11503
- /* @__PURE__ */ jsxRuntime.jsx(
11504
- Form$2.Field,
11505
- {
11506
- control: form.control,
11507
- name: "address_2",
11508
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11509
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11510
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11511
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11512
- ] })
11513
- }
11514
- ),
11515
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11516
- /* @__PURE__ */ jsxRuntime.jsx(
11517
- Form$2.Field,
11518
- {
11519
- control: form.control,
11520
- name: "postal_code",
11521
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11522
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11523
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11524
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11525
- ] })
11526
- }
11527
- ),
11528
- /* @__PURE__ */ jsxRuntime.jsx(
11529
- Form$2.Field,
11530
- {
11531
- control: form.control,
11532
- name: "city",
11533
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11534
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11535
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11536
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11537
- ] })
11538
- }
11539
- )
11540
- ] }),
11541
- /* @__PURE__ */ jsxRuntime.jsx(
11542
- Form$2.Field,
11543
- {
11544
- control: form.control,
11545
- name: "province",
11546
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11547
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11548
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11549
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11550
- ] })
11551
- }
11552
- ),
11553
- /* @__PURE__ */ jsxRuntime.jsx(
11554
- Form$2.Field,
11555
- {
11556
- control: form.control,
11557
- name: "phone",
11558
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11559
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11560
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11561
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11562
- ] })
11563
- }
11564
- )
11565
- ] }) }),
11566
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11567
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11568
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11569
- ] }) })
11570
- ]
11571
- }
11572
- ) });
11573
- };
11574
- const schema$2 = addressSchema;
11575
- const TransferOwnership = () => {
11576
- const { id } = reactRouterDom.useParams();
11577
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11578
- fields: "id,customer_id,customer.*"
11579
- });
11580
- if (isError) {
11581
- throw error;
11582
- }
11583
- const isReady = !isPending && !!draft_order;
11584
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11585
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11587
- /* @__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" }) })
11588
- ] }),
11589
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11590
- ] });
11591
- };
11592
- const TransferOwnershipForm = ({ order }) => {
11593
- var _a, _b;
11594
- const form = reactHookForm.useForm({
11595
- defaultValues: {
11596
- customer_id: order.customer_id || ""
11597
- },
11598
- resolver: zod.zodResolver(schema$1)
11599
- });
11600
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11601
- const { handleSuccess } = useRouteModal();
11602
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11603
- const currentCustomer = order.customer ? {
11604
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11605
- value: order.customer.id
11606
- } : null;
11607
- const onSubmit = form.handleSubmit(async (data) => {
11608
- await mutateAsync(
11609
- { customer_id: data.customer_id },
11610
- {
11611
- onSuccess: () => {
11612
- ui.toast.success("Customer updated");
11613
- handleSuccess();
11614
- },
11615
- onError: (error) => {
11616
- ui.toast.error(error.message);
11617
- }
11618
- }
11619
- );
11620
- });
11621
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11622
- KeyboundForm,
11623
- {
11624
- className: "flex flex-1 flex-col overflow-hidden",
11625
- onSubmit,
11626
- children: [
11627
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11628
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11629
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11630
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11632
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11633
- ] }),
11634
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11635
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11636
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11637
- ] })
11638
- ] }),
11639
- /* @__PURE__ */ jsxRuntime.jsx(
11640
- CustomerField,
11641
- {
11642
- control: form.control,
11643
- currentCustomerId: order.customer_id
11644
- }
11645
- )
11646
- ] }),
11647
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11648
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11649
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11650
- ] }) })
11651
- ]
11652
- }
11653
- ) });
11654
- };
11655
- const CustomerField = ({ control, currentCustomerId }) => {
11656
- const customers = useComboboxData({
11657
- queryFn: async (params) => {
11658
- return await sdk.admin.customer.list({
11659
- ...params,
11660
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11661
- });
11662
- },
11663
- queryKey: ["customers"],
11664
- getOptions: (data) => {
11665
- return data.customers.map((customer) => {
11666
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11667
- return {
11668
- label: name ? `${name} (${customer.email})` : customer.email,
11669
- value: customer.id
11670
- };
11671
- });
11672
- }
11673
- });
11674
- return /* @__PURE__ */ jsxRuntime.jsx(
11675
- Form$2.Field,
11676
- {
11677
- name: "customer_id",
11678
- control,
11679
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11680
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11681
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11682
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11683
- ] }),
11684
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11685
- Combobox,
11686
- {
11687
- options: customers.options,
11688
- fetchNextPage: customers.fetchNextPage,
11689
- isFetchingNextPage: customers.isFetchingNextPage,
11690
- searchValue: customers.searchValue,
11691
- onSearchValueChange: customers.onSearchValueChange,
11692
- placeholder: "Select customer",
11693
- ...field
11694
- }
11695
- ) }),
11696
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11697
- ] })
11698
- }
11699
- );
11700
- };
11701
- const Illustration = () => {
11702
- return /* @__PURE__ */ jsxRuntime.jsxs(
11703
- "svg",
11704
- {
11705
- width: "280",
11706
- height: "180",
11707
- viewBox: "0 0 280 180",
11708
- fill: "none",
11709
- xmlns: "http://www.w3.org/2000/svg",
11710
- children: [
11711
- /* @__PURE__ */ jsxRuntime.jsx(
11712
- "rect",
11713
- {
11714
- x: "0.00428286",
11715
- y: "-0.742904",
11716
- width: "33.5",
11717
- height: "65.5",
11718
- rx: "6.75",
11719
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11720
- fill: "#D4D4D8",
11721
- stroke: "#52525B",
11722
- strokeWidth: "1.5"
11723
- }
11724
- ),
11725
- /* @__PURE__ */ jsxRuntime.jsx(
11726
- "rect",
11727
- {
11728
- x: "0.00428286",
11729
- y: "-0.742904",
11730
- width: "33.5",
11731
- height: "65.5",
11732
- rx: "6.75",
11733
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11734
- fill: "white",
11735
- stroke: "#52525B",
11736
- strokeWidth: "1.5"
11737
- }
11738
- ),
11739
- /* @__PURE__ */ jsxRuntime.jsx(
11740
- "path",
11741
- {
11742
- d: "M180.579 107.142L179.126 107.959",
11743
- stroke: "#52525B",
11744
- strokeWidth: "1.5",
11745
- strokeLinecap: "round",
11746
- strokeLinejoin: "round"
11747
- }
11748
- ),
11749
- /* @__PURE__ */ jsxRuntime.jsx(
11750
- "path",
11751
- {
11752
- opacity: "0.88",
11753
- d: "M182.305 109.546L180.257 109.534",
11754
- stroke: "#52525B",
11755
- strokeWidth: "1.5",
11756
- strokeLinecap: "round",
11757
- strokeLinejoin: "round"
11758
- }
11759
- ),
11760
- /* @__PURE__ */ jsxRuntime.jsx(
11761
- "path",
11762
- {
11763
- opacity: "0.75",
11764
- d: "M180.551 111.93L179.108 111.096",
11765
- stroke: "#52525B",
11766
- strokeWidth: "1.5",
11767
- strokeLinecap: "round",
11768
- strokeLinejoin: "round"
11769
- }
11770
- ),
11771
- /* @__PURE__ */ jsxRuntime.jsx(
11772
- "path",
11773
- {
11774
- opacity: "0.63",
11775
- d: "M176.347 112.897L176.354 111.73",
11776
- stroke: "#52525B",
11777
- strokeWidth: "1.5",
11778
- strokeLinecap: "round",
11779
- strokeLinejoin: "round"
11780
- }
11781
- ),
11782
- /* @__PURE__ */ jsxRuntime.jsx(
11783
- "path",
11784
- {
11785
- opacity: "0.5",
11786
- d: "M172.153 111.881L173.606 111.064",
11787
- stroke: "#52525B",
11788
- strokeWidth: "1.5",
11789
- strokeLinecap: "round",
11790
- strokeLinejoin: "round"
11791
- }
11792
- ),
11793
- /* @__PURE__ */ jsxRuntime.jsx(
11794
- "path",
11795
- {
11796
- opacity: "0.38",
11797
- d: "M170.428 109.478L172.476 109.489",
11798
- stroke: "#52525B",
11799
- strokeWidth: "1.5",
11800
- strokeLinecap: "round",
11801
- strokeLinejoin: "round"
11802
- }
11803
- ),
11804
- /* @__PURE__ */ jsxRuntime.jsx(
11805
- "path",
11806
- {
11807
- opacity: "0.25",
11808
- d: "M172.181 107.094L173.624 107.928",
11809
- stroke: "#52525B",
11810
- strokeWidth: "1.5",
11811
- strokeLinecap: "round",
11812
- strokeLinejoin: "round"
11813
- }
11814
- ),
11815
- /* @__PURE__ */ jsxRuntime.jsx(
11816
- "path",
11817
- {
11818
- opacity: "0.13",
11819
- d: "M176.386 106.126L176.379 107.294",
11820
- stroke: "#52525B",
11821
- strokeWidth: "1.5",
11822
- strokeLinecap: "round",
11823
- strokeLinejoin: "round"
11824
- }
11825
- ),
11826
- /* @__PURE__ */ jsxRuntime.jsx(
11827
- "rect",
11828
- {
11829
- width: "12",
11830
- height: "3",
11831
- rx: "1.5",
11832
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11833
- fill: "#D4D4D8"
11834
- }
11835
- ),
11836
- /* @__PURE__ */ jsxRuntime.jsx(
11837
- "rect",
11838
- {
11839
- x: "0.00428286",
11840
- y: "-0.742904",
11841
- width: "33.5",
11842
- height: "65.5",
11843
- rx: "6.75",
11844
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11845
- fill: "#D4D4D8",
11846
- stroke: "#52525B",
11847
- strokeWidth: "1.5"
11848
- }
11849
- ),
11850
- /* @__PURE__ */ jsxRuntime.jsx(
11851
- "rect",
11852
- {
11853
- x: "0.00428286",
11854
- y: "-0.742904",
11855
- width: "33.5",
11856
- height: "65.5",
11857
- rx: "6.75",
11858
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11859
- fill: "white",
11860
- stroke: "#52525B",
11861
- strokeWidth: "1.5"
11862
- }
11863
- ),
11864
- /* @__PURE__ */ jsxRuntime.jsx(
11865
- "rect",
11866
- {
11867
- width: "12",
11868
- height: "3",
11869
- rx: "1.5",
11870
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11871
- fill: "#D4D4D8"
11872
- }
11873
- ),
11874
- /* @__PURE__ */ jsxRuntime.jsx(
11875
- "rect",
11876
- {
11877
- width: "17",
11878
- height: "3",
11879
- rx: "1.5",
11880
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11881
- fill: "#D4D4D8"
11882
- }
11883
- ),
11884
- /* @__PURE__ */ jsxRuntime.jsx(
11885
- "rect",
11886
- {
11887
- width: "12",
11888
- height: "3",
11889
- rx: "1.5",
11890
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11891
- fill: "#D4D4D8"
11892
- }
11893
- ),
11894
- /* @__PURE__ */ jsxRuntime.jsx(
11895
- "path",
11896
- {
11897
- 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",
11898
- fill: "#A1A1AA"
11899
- }
11900
- ),
11901
- /* @__PURE__ */ jsxRuntime.jsx(
11902
- "rect",
11903
- {
11904
- width: "17",
11905
- height: "3",
11906
- rx: "1.5",
11907
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11908
- fill: "#A1A1AA"
11909
- }
11910
- ),
11911
- /* @__PURE__ */ jsxRuntime.jsx(
11912
- "rect",
11913
- {
11914
- width: "12",
11915
- height: "3",
11916
- rx: "1.5",
11917
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11918
- fill: "#A1A1AA"
11919
- }
11920
- ),
11921
- /* @__PURE__ */ jsxRuntime.jsx(
11922
- "path",
11923
- {
11924
- 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",
11925
- fill: "#52525B"
11926
- }
11927
- ),
11928
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11929
- "path",
11930
- {
11931
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11932
- stroke: "#A1A1AA",
11933
- strokeWidth: "1.5",
11934
- strokeLinecap: "round",
11935
- strokeLinejoin: "round"
11936
- }
11937
- ) }),
11938
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11939
- "path",
11940
- {
11941
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11942
- stroke: "#A1A1AA",
11943
- strokeWidth: "1.5",
11944
- strokeLinecap: "round",
11945
- strokeLinejoin: "round"
11946
- }
11947
- ) }),
11948
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11949
- "path",
11950
- {
11951
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11952
- stroke: "#A1A1AA",
11953
- strokeWidth: "1.5",
11954
- strokeLinecap: "round",
11955
- strokeLinejoin: "round"
11956
- }
11957
- ) }),
11958
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11959
- "path",
11960
- {
11961
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11962
- stroke: "#A1A1AA",
11963
- strokeWidth: "1.5",
11964
- strokeLinecap: "round",
11965
- strokeLinejoin: "round"
11966
- }
11967
- ) }),
11968
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11969
- "path",
11970
- {
11971
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11972
- stroke: "#A1A1AA",
11973
- strokeWidth: "1.5",
11974
- strokeLinecap: "round",
11975
- strokeLinejoin: "round"
11976
- }
11977
- ) }),
11978
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11979
- "path",
11980
- {
11981
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11982
- stroke: "#A1A1AA",
11983
- strokeWidth: "1.5",
11984
- strokeLinecap: "round",
11985
- strokeLinejoin: "round"
11986
- }
11987
- ) }),
11988
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
11989
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11990
- "rect",
11991
- {
11992
- width: "12",
11993
- height: "12",
11994
- fill: "white",
11995
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11996
- }
11997
- ) }),
11998
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11999
- "rect",
12000
- {
12001
- width: "12",
12002
- height: "12",
12003
- fill: "white",
12004
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12005
- }
12006
- ) }),
12007
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12008
- "rect",
12009
- {
12010
- width: "12",
12011
- height: "12",
12012
- fill: "white",
12013
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12014
- }
12015
- ) }),
12016
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12017
- "rect",
12018
- {
12019
- width: "12",
12020
- height: "12",
12021
- fill: "white",
12022
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12023
- }
12024
- ) }),
12025
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12026
- "rect",
12027
- {
12028
- width: "12",
12029
- height: "12",
12030
- fill: "white",
12031
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12032
- }
12033
- ) }),
12034
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12035
- "rect",
12036
- {
12037
- width: "12",
12038
- height: "12",
12039
- fill: "white",
12040
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12041
- }
12042
- ) })
12043
- ] })
12044
- ]
12045
- }
12046
- );
12047
- };
12048
- const schema$1 = objectType({
12049
- customer_id: stringType().min(1)
12050
- });
12051
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12052
- const Shipping = () => {
12053
- var _a;
12054
- const { id } = reactRouterDom.useParams();
12055
- const { order, isPending, isError, error } = useOrder(id, {
12056
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12057
- });
12058
- const {
12059
- order: preview,
12060
- isPending: isPreviewPending,
12061
- isError: isPreviewError,
12062
- error: previewError
12063
- } = useOrderPreview(id);
12064
- useInitiateOrderEdit({ preview });
12065
- const { onCancel } = useCancelOrderEdit({ preview });
12066
- if (isError) {
12067
- throw error;
12068
- }
12069
- if (isPreviewError) {
12070
- throw previewError;
12071
- }
12072
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12073
- const isReady = preview && !isPreviewPending && order && !isPending;
12074
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12075
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12076
- /* @__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 py-16 px-6", children: [
12077
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12078
- /* @__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." }) })
12079
- ] }) }) }),
12080
- /* @__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" }) }) })
12081
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12082
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12083
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12084
- ] }) });
12085
- };
12086
- const ShippingForm = ({ preview, order }) => {
12087
- var _a;
12088
- const { setIsOpen } = useStackedModal();
12089
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12090
- const [data, setData] = React.useState(null);
12091
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12092
- const { shipping_options } = useShippingOptions(
12093
- {
12094
- id: appliedShippingOptionIds,
12095
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12096
- },
12097
- {
12098
- enabled: appliedShippingOptionIds.length > 0
12099
- }
12100
- );
12101
- const uniqueShippingProfiles = React.useMemo(() => {
12102
- const profiles = /* @__PURE__ */ new Map();
12103
- getUniqueShippingProfiles(order.items).forEach((profile) => {
12104
- profiles.set(profile.id, profile);
12105
- });
12106
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12107
- profiles.set(option.shipping_profile_id, option.shipping_profile);
12108
- });
12109
- return Array.from(profiles.values());
12110
- }, [order.items, shipping_options]);
12111
- const { handleSuccess } = useRouteModal();
12112
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12113
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12114
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12115
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12116
- const onSubmit = async () => {
12117
- setIsSubmitting(true);
12118
- let requestSucceeded = false;
12119
- await requestOrderEdit(void 0, {
12120
- onError: (e) => {
12121
- ui.toast.error(`Failed to request order edit: ${e.message}`);
12122
- },
12123
- onSuccess: () => {
12124
- requestSucceeded = true;
12125
- }
12126
- });
12127
- if (!requestSucceeded) {
12128
- setIsSubmitting(false);
12129
- return;
12130
- }
12131
- await confirmOrderEdit(void 0, {
12132
- onError: (e) => {
12133
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12134
- },
12135
- onSuccess: () => {
12136
- handleSuccess();
12137
- },
12138
- onSettled: () => {
12139
- setIsSubmitting(false);
12140
- }
12141
- });
12142
- };
12143
- const onKeydown = React.useCallback(
12144
- (e) => {
12145
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12146
- if (data || isSubmitting) {
12147
- return;
12148
- }
12149
- onSubmit();
12150
- }
12151
- },
12152
- [data, isSubmitting, onSubmit]
12153
- );
12154
- React.useEffect(() => {
12155
- document.addEventListener("keydown", onKeydown);
12156
- return () => {
12157
- document.removeEventListener("keydown", onKeydown);
12158
- };
12159
- }, [onKeydown]);
12160
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12161
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12162
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12163
- /* @__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 py-16 px-6", children: [
12164
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12165
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12166
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
12167
- ] }),
12168
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12169
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
12170
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12171
- /* @__PURE__ */ jsxRuntime.jsx(
12172
- ui.Text,
12173
- {
12174
- size: "xsmall",
12175
- weight: "plus",
12176
- className: "text-ui-fg-muted",
12177
- children: "Shipping profile"
12178
- }
12179
- ),
12180
- /* @__PURE__ */ jsxRuntime.jsx(
12181
- ui.Text,
12182
- {
12183
- size: "xsmall",
12184
- weight: "plus",
12185
- className: "text-ui-fg-muted",
12186
- children: "Action"
11504
+ size: "xsmall",
11505
+ weight: "plus",
11506
+ className: "text-ui-fg-muted",
11507
+ children: "Action"
12187
11508
  }
12188
11509
  )
12189
11510
  ] }),
@@ -12447,414 +11768,1093 @@ const ShippingForm = ({ preview, order }) => {
12447
11768
  }
12448
11769
  return open;
12449
11770
  },
12450
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11771
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11772
+ }
11773
+ )
11774
+ ] }),
11775
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11776
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11777
+ /* @__PURE__ */ jsxRuntime.jsx(
11778
+ ui.Button,
11779
+ {
11780
+ size: "small",
11781
+ type: "button",
11782
+ isLoading: isSubmitting,
11783
+ onClick: onSubmit,
11784
+ children: "Save"
11785
+ }
11786
+ )
11787
+ ] }) })
11788
+ ] });
11789
+ };
11790
+ const StackedModalTrigger = ({
11791
+ shippingProfileId,
11792
+ shippingOption,
11793
+ shippingMethod,
11794
+ setData,
11795
+ children
11796
+ }) => {
11797
+ const { setIsOpen, getIsOpen } = useStackedModal();
11798
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11799
+ const onToggle = () => {
11800
+ if (isOpen) {
11801
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11802
+ setData(null);
11803
+ } else {
11804
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11805
+ setData({
11806
+ shippingProfileId,
11807
+ shippingOption,
11808
+ shippingMethod
11809
+ });
11810
+ }
11811
+ };
11812
+ return /* @__PURE__ */ jsxRuntime.jsx(
11813
+ ui.Button,
11814
+ {
11815
+ size: "small",
11816
+ variant: "secondary",
11817
+ onClick: onToggle,
11818
+ className: "text-ui-fg-primary shrink-0",
11819
+ children
11820
+ }
11821
+ );
11822
+ };
11823
+ const ShippingProfileForm = ({
11824
+ data,
11825
+ order,
11826
+ preview
11827
+ }) => {
11828
+ var _a, _b, _c, _d, _e, _f;
11829
+ const { setIsOpen } = useStackedModal();
11830
+ const form = reactHookForm.useForm({
11831
+ resolver: zod.zodResolver(shippingMethodSchema),
11832
+ defaultValues: {
11833
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11834
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11835
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11836
+ }
11837
+ });
11838
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11839
+ const {
11840
+ mutateAsync: updateShippingMethod,
11841
+ isPending: isUpdatingShippingMethod
11842
+ } = useDraftOrderUpdateShippingMethod(order.id);
11843
+ const onSubmit = form.handleSubmit(async (values) => {
11844
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
11845
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11846
+ return;
11847
+ }
11848
+ if (data.shippingMethod) {
11849
+ await updateShippingMethod(
11850
+ {
11851
+ method_id: data.shippingMethod.id,
11852
+ shipping_option_id: values.shipping_option_id,
11853
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11854
+ },
11855
+ {
11856
+ onError: (e) => {
11857
+ ui.toast.error(e.message);
11858
+ },
11859
+ onSuccess: () => {
11860
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11861
+ }
12451
11862
  }
12452
- )
12453
- ] }),
12454
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12455
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12456
- /* @__PURE__ */ jsxRuntime.jsx(
12457
- ui.Button,
11863
+ );
11864
+ return;
11865
+ }
11866
+ await addShippingMethod(
11867
+ {
11868
+ shipping_option_id: values.shipping_option_id,
11869
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11870
+ },
11871
+ {
11872
+ onError: (e) => {
11873
+ ui.toast.error(e.message);
11874
+ },
11875
+ onSuccess: () => {
11876
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11877
+ }
11878
+ }
11879
+ );
11880
+ });
11881
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11882
+ KeyboundForm,
11883
+ {
11884
+ className: "flex h-full flex-col overflow-hidden",
11885
+ onSubmit,
11886
+ children: [
11887
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11888
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.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 py-16 px-6", children: [
11889
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11890
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11891
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11892
+ ] }),
11893
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11894
+ /* @__PURE__ */ jsxRuntime.jsx(
11895
+ LocationField,
11896
+ {
11897
+ control: form.control,
11898
+ setValue: form.setValue
11899
+ }
11900
+ ),
11901
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11902
+ /* @__PURE__ */ jsxRuntime.jsx(
11903
+ ShippingOptionField,
11904
+ {
11905
+ shippingProfileId: data.shippingProfileId,
11906
+ preview,
11907
+ control: form.control
11908
+ }
11909
+ ),
11910
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11911
+ /* @__PURE__ */ jsxRuntime.jsx(
11912
+ CustomAmountField,
11913
+ {
11914
+ control: form.control,
11915
+ currencyCode: order.currency_code
11916
+ }
11917
+ ),
11918
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11919
+ /* @__PURE__ */ jsxRuntime.jsx(
11920
+ ItemsPreview,
11921
+ {
11922
+ order,
11923
+ shippingProfileId: data.shippingProfileId
11924
+ }
11925
+ )
11926
+ ] }) }) }),
11927
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11928
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11929
+ /* @__PURE__ */ jsxRuntime.jsx(
11930
+ ui.Button,
11931
+ {
11932
+ size: "small",
11933
+ type: "submit",
11934
+ isLoading: isPending || isUpdatingShippingMethod,
11935
+ children: data.shippingMethod ? "Update" : "Add"
11936
+ }
11937
+ )
11938
+ ] }) })
11939
+ ]
11940
+ }
11941
+ ) }) });
11942
+ };
11943
+ const shippingMethodSchema = objectType({
11944
+ location_id: stringType(),
11945
+ shipping_option_id: stringType(),
11946
+ custom_amount: unionType([numberType(), stringType()]).optional()
11947
+ });
11948
+ const ItemsPreview = ({ order, shippingProfileId }) => {
11949
+ const matches = order.items.filter(
11950
+ (item) => {
11951
+ var _a, _b, _c;
11952
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11953
+ }
11954
+ );
11955
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11956
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11957
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11958
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11959
+ ] }) }),
11960
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11961
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11962
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11963
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11964
+ ] }),
11965
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
11966
+ "div",
12458
11967
  {
12459
- size: "small",
12460
- type: "button",
12461
- isLoading: isSubmitting,
12462
- onClick: onSubmit,
12463
- children: "Save"
11968
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11969
+ children: [
11970
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11971
+ /* @__PURE__ */ jsxRuntime.jsx(
11972
+ Thumbnail,
11973
+ {
11974
+ thumbnail: item.thumbnail,
11975
+ alt: item.product_title ?? void 0
11976
+ }
11977
+ ),
11978
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11979
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11980
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11981
+ /* @__PURE__ */ jsxRuntime.jsxs(
11982
+ ui.Text,
11983
+ {
11984
+ size: "small",
11985
+ leading: "compact",
11986
+ className: "text-ui-fg-subtle",
11987
+ children: [
11988
+ "(",
11989
+ item.variant_title,
11990
+ ")"
11991
+ ]
11992
+ }
11993
+ )
11994
+ ] }),
11995
+ /* @__PURE__ */ jsxRuntime.jsx(
11996
+ ui.Text,
11997
+ {
11998
+ size: "small",
11999
+ leading: "compact",
12000
+ className: "text-ui-fg-subtle",
12001
+ children: item.variant_sku
12002
+ }
12003
+ )
12004
+ ] })
12005
+ ] }),
12006
+ /* @__PURE__ */ jsxRuntime.jsxs(
12007
+ ui.Text,
12008
+ {
12009
+ size: "small",
12010
+ leading: "compact",
12011
+ className: "text-ui-fg-subtle",
12012
+ children: [
12013
+ item.quantity,
12014
+ "x"
12015
+ ]
12016
+ }
12017
+ )
12018
+ ]
12019
+ },
12020
+ item.id
12021
+ )) : /* @__PURE__ */ jsxRuntime.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: [
12022
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12023
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12024
+ 'No items found for "',
12025
+ query,
12026
+ '".'
12027
+ ] })
12028
+ ] }) })
12029
+ ] })
12030
+ ] });
12031
+ };
12032
+ const LocationField = ({ control, setValue }) => {
12033
+ const locations = useComboboxData({
12034
+ queryKey: ["locations"],
12035
+ queryFn: async (params) => {
12036
+ return await sdk.admin.stockLocation.list(params);
12037
+ },
12038
+ getOptions: (data) => {
12039
+ return data.stock_locations.map((location) => ({
12040
+ label: location.name,
12041
+ value: location.id
12042
+ }));
12043
+ }
12044
+ });
12045
+ return /* @__PURE__ */ jsxRuntime.jsx(
12046
+ Form$2.Field,
12047
+ {
12048
+ control,
12049
+ name: "location_id",
12050
+ render: ({ field: { onChange, ...field } }) => {
12051
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12052
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12053
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12054
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12055
+ ] }),
12056
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12057
+ Combobox,
12058
+ {
12059
+ options: locations.options,
12060
+ fetchNextPage: locations.fetchNextPage,
12061
+ isFetchingNextPage: locations.isFetchingNextPage,
12062
+ searchValue: locations.searchValue,
12063
+ onSearchValueChange: locations.onSearchValueChange,
12064
+ placeholder: "Select location",
12065
+ onChange: (value) => {
12066
+ setValue("shipping_option_id", "", {
12067
+ shouldDirty: true,
12068
+ shouldTouch: true
12069
+ });
12070
+ onChange(value);
12071
+ },
12072
+ ...field
12073
+ }
12074
+ ) })
12075
+ ] }) });
12076
+ }
12077
+ }
12078
+ );
12079
+ };
12080
+ const ShippingOptionField = ({
12081
+ shippingProfileId,
12082
+ preview,
12083
+ control
12084
+ }) => {
12085
+ var _a;
12086
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12087
+ const shippingOptions = useComboboxData({
12088
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12089
+ queryFn: async (params) => {
12090
+ return await sdk.admin.shippingOption.list({
12091
+ ...params,
12092
+ stock_location_id: locationId,
12093
+ shipping_profile_id: shippingProfileId
12094
+ });
12095
+ },
12096
+ getOptions: (data) => {
12097
+ return data.shipping_options.map((option) => {
12098
+ var _a2;
12099
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12100
+ (r) => r.attribute === "is_return" && r.value === "true"
12101
+ )) {
12102
+ return void 0;
12464
12103
  }
12465
- )
12466
- ] }) })
12467
- ] });
12104
+ return {
12105
+ label: option.name,
12106
+ value: option.id
12107
+ };
12108
+ }).filter(Boolean);
12109
+ },
12110
+ enabled: !!locationId && !!shippingProfileId,
12111
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12112
+ });
12113
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12114
+ return /* @__PURE__ */ jsxRuntime.jsx(
12115
+ Form$2.Field,
12116
+ {
12117
+ control,
12118
+ name: "shipping_option_id",
12119
+ render: ({ field }) => {
12120
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12121
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12122
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12123
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12124
+ ] }),
12125
+ /* @__PURE__ */ jsxRuntime.jsx(
12126
+ ConditionalTooltip,
12127
+ {
12128
+ content: tooltipContent,
12129
+ showTooltip: !locationId || !shippingProfileId,
12130
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12131
+ Combobox,
12132
+ {
12133
+ options: shippingOptions.options,
12134
+ fetchNextPage: shippingOptions.fetchNextPage,
12135
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12136
+ searchValue: shippingOptions.searchValue,
12137
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12138
+ placeholder: "Select shipping option",
12139
+ ...field,
12140
+ disabled: !locationId || !shippingProfileId
12141
+ }
12142
+ ) }) })
12143
+ }
12144
+ )
12145
+ ] }) });
12146
+ }
12147
+ }
12148
+ );
12468
12149
  };
12469
- const StackedModalTrigger = ({
12470
- shippingProfileId,
12471
- shippingOption,
12472
- shippingMethod,
12473
- setData,
12474
- children
12150
+ const CustomAmountField = ({
12151
+ control,
12152
+ currencyCode
12475
12153
  }) => {
12476
- const { setIsOpen, getIsOpen } = useStackedModal();
12477
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12478
- const onToggle = () => {
12479
- if (isOpen) {
12480
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12481
- setData(null);
12482
- } else {
12483
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12484
- setData({
12485
- shippingProfileId,
12486
- shippingOption,
12487
- shippingMethod
12488
- });
12489
- }
12490
- };
12491
12154
  return /* @__PURE__ */ jsxRuntime.jsx(
12492
- ui.Button,
12155
+ Form$2.Field,
12493
12156
  {
12494
- size: "small",
12495
- variant: "secondary",
12496
- onClick: onToggle,
12497
- className: "text-ui-fg-primary shrink-0",
12498
- children
12157
+ control,
12158
+ name: "custom_amount",
12159
+ render: ({ field: { onChange, ...field } }) => {
12160
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12161
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12162
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12163
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12164
+ ] }),
12165
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12166
+ ui.CurrencyInput,
12167
+ {
12168
+ ...field,
12169
+ onValueChange: (value) => onChange(value),
12170
+ symbol: getNativeSymbol(currencyCode),
12171
+ code: currencyCode
12172
+ }
12173
+ ) })
12174
+ ] });
12175
+ }
12499
12176
  }
12500
12177
  );
12501
12178
  };
12502
- const ShippingProfileForm = ({
12503
- data,
12504
- order,
12505
- preview
12506
- }) => {
12507
- var _a, _b, _c, _d, _e, _f;
12508
- const { setIsOpen } = useStackedModal();
12179
+ const ShippingAddress = () => {
12180
+ const { id } = reactRouterDom.useParams();
12181
+ const { order, isPending, isError, error } = useOrder(id, {
12182
+ fields: "+shipping_address"
12183
+ });
12184
+ if (isError) {
12185
+ throw error;
12186
+ }
12187
+ const isReady = !isPending && !!order;
12188
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12189
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12190
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12191
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12192
+ ] }),
12193
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12194
+ ] });
12195
+ };
12196
+ const ShippingAddressForm = ({ order }) => {
12197
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12509
12198
  const form = reactHookForm.useForm({
12510
- resolver: zod.zodResolver(shippingMethodSchema),
12511
12199
  defaultValues: {
12512
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12513
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12514
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12515
- }
12200
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12201
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12202
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12203
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12204
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12205
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12206
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12207
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12208
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12209
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12210
+ },
12211
+ resolver: zod.zodResolver(schema$2)
12516
12212
  });
12517
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12518
- const {
12519
- mutateAsync: updateShippingMethod,
12520
- isPending: isUpdatingShippingMethod
12521
- } = useDraftOrderUpdateShippingMethod(order.id);
12522
- const onSubmit = form.handleSubmit(async (values) => {
12523
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12524
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12525
- return;
12526
- }
12527
- if (data.shippingMethod) {
12528
- await updateShippingMethod(
12529
- {
12530
- method_id: data.shippingMethod.id,
12531
- shipping_option_id: values.shipping_option_id,
12532
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12533
- },
12534
- {
12535
- onError: (e) => {
12536
- ui.toast.error(e.message);
12537
- },
12538
- onSuccess: () => {
12539
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12540
- }
12541
- }
12542
- );
12543
- return;
12544
- }
12545
- await addShippingMethod(
12213
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12214
+ const { handleSuccess } = useRouteModal();
12215
+ const onSubmit = form.handleSubmit(async (data) => {
12216
+ await mutateAsync(
12546
12217
  {
12547
- shipping_option_id: values.shipping_option_id,
12548
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12218
+ shipping_address: {
12219
+ first_name: data.first_name,
12220
+ last_name: data.last_name,
12221
+ company: data.company,
12222
+ address_1: data.address_1,
12223
+ address_2: data.address_2,
12224
+ city: data.city,
12225
+ province: data.province,
12226
+ country_code: data.country_code,
12227
+ postal_code: data.postal_code,
12228
+ phone: data.phone
12229
+ }
12549
12230
  },
12550
12231
  {
12551
- onError: (e) => {
12552
- ui.toast.error(e.message);
12553
- },
12554
12232
  onSuccess: () => {
12555
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12233
+ handleSuccess();
12234
+ },
12235
+ onError: (error) => {
12236
+ ui.toast.error(error.message);
12556
12237
  }
12557
12238
  }
12558
12239
  );
12559
12240
  });
12560
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12241
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12561
12242
  KeyboundForm,
12562
12243
  {
12563
- className: "flex h-full flex-col overflow-hidden",
12244
+ className: "flex flex-1 flex-col overflow-hidden",
12564
12245
  onSubmit,
12565
12246
  children: [
12566
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12567
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.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 py-16 px-6", children: [
12568
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12569
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12570
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12247
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12248
+ /* @__PURE__ */ jsxRuntime.jsx(
12249
+ Form$2.Field,
12250
+ {
12251
+ control: form.control,
12252
+ name: "country_code",
12253
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12254
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12255
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12256
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12257
+ ] })
12258
+ }
12259
+ ),
12260
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12261
+ /* @__PURE__ */ jsxRuntime.jsx(
12262
+ Form$2.Field,
12263
+ {
12264
+ control: form.control,
12265
+ name: "first_name",
12266
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12267
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12268
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12269
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12270
+ ] })
12271
+ }
12272
+ ),
12273
+ /* @__PURE__ */ jsxRuntime.jsx(
12274
+ Form$2.Field,
12275
+ {
12276
+ control: form.control,
12277
+ name: "last_name",
12278
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12279
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12280
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12281
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12282
+ ] })
12283
+ }
12284
+ )
12571
12285
  ] }),
12572
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12573
12286
  /* @__PURE__ */ jsxRuntime.jsx(
12574
- LocationField,
12287
+ Form$2.Field,
12288
+ {
12289
+ control: form.control,
12290
+ name: "company",
12291
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12292
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12293
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12294
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12295
+ ] })
12296
+ }
12297
+ ),
12298
+ /* @__PURE__ */ jsxRuntime.jsx(
12299
+ Form$2.Field,
12575
12300
  {
12576
12301
  control: form.control,
12577
- setValue: form.setValue
12302
+ name: "address_1",
12303
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12304
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12305
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12306
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12307
+ ] })
12578
12308
  }
12579
12309
  ),
12580
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12581
12310
  /* @__PURE__ */ jsxRuntime.jsx(
12582
- ShippingOptionField,
12311
+ Form$2.Field,
12583
12312
  {
12584
- shippingProfileId: data.shippingProfileId,
12585
- preview,
12586
- control: form.control
12313
+ control: form.control,
12314
+ name: "address_2",
12315
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12316
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12317
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12318
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12319
+ ] })
12587
12320
  }
12588
12321
  ),
12589
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12322
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12323
+ /* @__PURE__ */ jsxRuntime.jsx(
12324
+ Form$2.Field,
12325
+ {
12326
+ control: form.control,
12327
+ name: "postal_code",
12328
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12329
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12330
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12331
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12332
+ ] })
12333
+ }
12334
+ ),
12335
+ /* @__PURE__ */ jsxRuntime.jsx(
12336
+ Form$2.Field,
12337
+ {
12338
+ control: form.control,
12339
+ name: "city",
12340
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12341
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12342
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12343
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12344
+ ] })
12345
+ }
12346
+ )
12347
+ ] }),
12590
12348
  /* @__PURE__ */ jsxRuntime.jsx(
12591
- CustomAmountField,
12349
+ Form$2.Field,
12592
12350
  {
12593
12351
  control: form.control,
12594
- currencyCode: order.currency_code
12352
+ name: "province",
12353
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12354
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12355
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12356
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12357
+ ] })
12595
12358
  }
12596
12359
  ),
12597
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12598
12360
  /* @__PURE__ */ jsxRuntime.jsx(
12599
- ItemsPreview,
12361
+ Form$2.Field,
12600
12362
  {
12601
- order,
12602
- shippingProfileId: data.shippingProfileId
12363
+ control: form.control,
12364
+ name: "phone",
12365
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12367
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12368
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12369
+ ] })
12603
12370
  }
12604
12371
  )
12605
- ] }) }) }),
12606
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12607
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12372
+ ] }) }),
12373
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12374
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12375
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12376
+ ] }) })
12377
+ ]
12378
+ }
12379
+ ) });
12380
+ };
12381
+ const schema$2 = addressSchema;
12382
+ const TransferOwnership = () => {
12383
+ const { id } = reactRouterDom.useParams();
12384
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12385
+ fields: "id,customer_id,customer.*"
12386
+ });
12387
+ if (isError) {
12388
+ throw error;
12389
+ }
12390
+ const isReady = !isPending && !!draft_order;
12391
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12392
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12393
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12394
+ /* @__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" }) })
12395
+ ] }),
12396
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12397
+ ] });
12398
+ };
12399
+ const TransferOwnershipForm = ({ order }) => {
12400
+ var _a, _b;
12401
+ const form = reactHookForm.useForm({
12402
+ defaultValues: {
12403
+ customer_id: order.customer_id || ""
12404
+ },
12405
+ resolver: zod.zodResolver(schema$1)
12406
+ });
12407
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12408
+ const { handleSuccess } = useRouteModal();
12409
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12410
+ const currentCustomer = order.customer ? {
12411
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12412
+ value: order.customer.id
12413
+ } : null;
12414
+ const onSubmit = form.handleSubmit(async (data) => {
12415
+ await mutateAsync(
12416
+ { customer_id: data.customer_id },
12417
+ {
12418
+ onSuccess: () => {
12419
+ ui.toast.success("Customer updated");
12420
+ handleSuccess();
12421
+ },
12422
+ onError: (error) => {
12423
+ ui.toast.error(error.message);
12424
+ }
12425
+ }
12426
+ );
12427
+ });
12428
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12429
+ KeyboundForm,
12430
+ {
12431
+ className: "flex flex-1 flex-col overflow-hidden",
12432
+ onSubmit,
12433
+ children: [
12434
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12435
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12436
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12437
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12439
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12440
+ ] }),
12441
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12442
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12443
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12444
+ ] })
12445
+ ] }),
12608
12446
  /* @__PURE__ */ jsxRuntime.jsx(
12609
- ui.Button,
12447
+ CustomerField,
12610
12448
  {
12611
- size: "small",
12612
- type: "submit",
12613
- isLoading: isPending || isUpdatingShippingMethod,
12614
- children: data.shippingMethod ? "Update" : "Add"
12449
+ control: form.control,
12450
+ currentCustomerId: order.customer_id
12615
12451
  }
12616
12452
  )
12453
+ ] }),
12454
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12455
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12456
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12617
12457
  ] }) })
12618
12458
  ]
12619
12459
  }
12620
- ) }) });
12621
- };
12622
- const shippingMethodSchema = objectType({
12623
- location_id: stringType(),
12624
- shipping_option_id: stringType(),
12625
- custom_amount: unionType([numberType(), stringType()]).optional()
12626
- });
12627
- const ItemsPreview = ({ order, shippingProfileId }) => {
12628
- const matches = order.items.filter(
12629
- (item) => {
12630
- var _a, _b, _c;
12631
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12632
- }
12633
- );
12634
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12635
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12636
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12637
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12638
- ] }) }),
12639
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12640
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12641
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12642
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12643
- ] }),
12644
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12645
- "div",
12646
- {
12647
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12648
- children: [
12649
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12650
- /* @__PURE__ */ jsxRuntime.jsx(
12651
- Thumbnail,
12652
- {
12653
- thumbnail: item.thumbnail,
12654
- alt: item.product_title ?? void 0
12655
- }
12656
- ),
12657
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12658
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12659
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12660
- /* @__PURE__ */ jsxRuntime.jsxs(
12661
- ui.Text,
12662
- {
12663
- size: "small",
12664
- leading: "compact",
12665
- className: "text-ui-fg-subtle",
12666
- children: [
12667
- "(",
12668
- item.variant_title,
12669
- ")"
12670
- ]
12671
- }
12672
- )
12673
- ] }),
12674
- /* @__PURE__ */ jsxRuntime.jsx(
12675
- ui.Text,
12676
- {
12677
- size: "small",
12678
- leading: "compact",
12679
- className: "text-ui-fg-subtle",
12680
- children: item.variant_sku
12681
- }
12682
- )
12683
- ] })
12684
- ] }),
12685
- /* @__PURE__ */ jsxRuntime.jsxs(
12686
- ui.Text,
12687
- {
12688
- size: "small",
12689
- leading: "compact",
12690
- className: "text-ui-fg-subtle",
12691
- children: [
12692
- item.quantity,
12693
- "x"
12694
- ]
12695
- }
12696
- )
12697
- ]
12698
- },
12699
- item.id
12700
- )) : /* @__PURE__ */ jsxRuntime.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: [
12701
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12702
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12703
- 'No items found for "',
12704
- query,
12705
- '".'
12706
- ] })
12707
- ] }) })
12708
- ] })
12709
- ] });
12710
- };
12711
- const LocationField = ({ control, setValue }) => {
12712
- const locations = useComboboxData({
12713
- queryKey: ["locations"],
12460
+ ) });
12461
+ };
12462
+ const CustomerField = ({ control, currentCustomerId }) => {
12463
+ const customers = useComboboxData({
12714
12464
  queryFn: async (params) => {
12715
- return await sdk.admin.stockLocation.list(params);
12465
+ return await sdk.admin.customer.list({
12466
+ ...params,
12467
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12468
+ });
12716
12469
  },
12470
+ queryKey: ["customers"],
12717
12471
  getOptions: (data) => {
12718
- return data.stock_locations.map((location) => ({
12719
- label: location.name,
12720
- value: location.id
12721
- }));
12472
+ return data.customers.map((customer) => {
12473
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12474
+ return {
12475
+ label: name ? `${name} (${customer.email})` : customer.email,
12476
+ value: customer.id
12477
+ };
12478
+ });
12722
12479
  }
12723
12480
  });
12724
12481
  return /* @__PURE__ */ jsxRuntime.jsx(
12725
12482
  Form$2.Field,
12726
12483
  {
12484
+ name: "customer_id",
12727
12485
  control,
12728
- name: "location_id",
12729
- render: ({ field: { onChange, ...field } }) => {
12730
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12731
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12732
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12733
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12734
- ] }),
12735
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12736
- Combobox,
12486
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12487
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12488
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12489
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12490
+ ] }),
12491
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12492
+ Combobox,
12493
+ {
12494
+ options: customers.options,
12495
+ fetchNextPage: customers.fetchNextPage,
12496
+ isFetchingNextPage: customers.isFetchingNextPage,
12497
+ searchValue: customers.searchValue,
12498
+ onSearchValueChange: customers.onSearchValueChange,
12499
+ placeholder: "Select customer",
12500
+ ...field
12501
+ }
12502
+ ) }),
12503
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12504
+ ] })
12505
+ }
12506
+ );
12507
+ };
12508
+ const Illustration = () => {
12509
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12510
+ "svg",
12511
+ {
12512
+ width: "280",
12513
+ height: "180",
12514
+ viewBox: "0 0 280 180",
12515
+ fill: "none",
12516
+ xmlns: "http://www.w3.org/2000/svg",
12517
+ children: [
12518
+ /* @__PURE__ */ jsxRuntime.jsx(
12519
+ "rect",
12520
+ {
12521
+ x: "0.00428286",
12522
+ y: "-0.742904",
12523
+ width: "33.5",
12524
+ height: "65.5",
12525
+ rx: "6.75",
12526
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12527
+ fill: "#D4D4D8",
12528
+ stroke: "#52525B",
12529
+ strokeWidth: "1.5"
12530
+ }
12531
+ ),
12532
+ /* @__PURE__ */ jsxRuntime.jsx(
12533
+ "rect",
12534
+ {
12535
+ x: "0.00428286",
12536
+ y: "-0.742904",
12537
+ width: "33.5",
12538
+ height: "65.5",
12539
+ rx: "6.75",
12540
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12541
+ fill: "white",
12542
+ stroke: "#52525B",
12543
+ strokeWidth: "1.5"
12544
+ }
12545
+ ),
12546
+ /* @__PURE__ */ jsxRuntime.jsx(
12547
+ "path",
12548
+ {
12549
+ d: "M180.579 107.142L179.126 107.959",
12550
+ stroke: "#52525B",
12551
+ strokeWidth: "1.5",
12552
+ strokeLinecap: "round",
12553
+ strokeLinejoin: "round"
12554
+ }
12555
+ ),
12556
+ /* @__PURE__ */ jsxRuntime.jsx(
12557
+ "path",
12558
+ {
12559
+ opacity: "0.88",
12560
+ d: "M182.305 109.546L180.257 109.534",
12561
+ stroke: "#52525B",
12562
+ strokeWidth: "1.5",
12563
+ strokeLinecap: "round",
12564
+ strokeLinejoin: "round"
12565
+ }
12566
+ ),
12567
+ /* @__PURE__ */ jsxRuntime.jsx(
12568
+ "path",
12569
+ {
12570
+ opacity: "0.75",
12571
+ d: "M180.551 111.93L179.108 111.096",
12572
+ stroke: "#52525B",
12573
+ strokeWidth: "1.5",
12574
+ strokeLinecap: "round",
12575
+ strokeLinejoin: "round"
12576
+ }
12577
+ ),
12578
+ /* @__PURE__ */ jsxRuntime.jsx(
12579
+ "path",
12580
+ {
12581
+ opacity: "0.63",
12582
+ d: "M176.347 112.897L176.354 111.73",
12583
+ stroke: "#52525B",
12584
+ strokeWidth: "1.5",
12585
+ strokeLinecap: "round",
12586
+ strokeLinejoin: "round"
12587
+ }
12588
+ ),
12589
+ /* @__PURE__ */ jsxRuntime.jsx(
12590
+ "path",
12591
+ {
12592
+ opacity: "0.5",
12593
+ d: "M172.153 111.881L173.606 111.064",
12594
+ stroke: "#52525B",
12595
+ strokeWidth: "1.5",
12596
+ strokeLinecap: "round",
12597
+ strokeLinejoin: "round"
12598
+ }
12599
+ ),
12600
+ /* @__PURE__ */ jsxRuntime.jsx(
12601
+ "path",
12602
+ {
12603
+ opacity: "0.38",
12604
+ d: "M170.428 109.478L172.476 109.489",
12605
+ stroke: "#52525B",
12606
+ strokeWidth: "1.5",
12607
+ strokeLinecap: "round",
12608
+ strokeLinejoin: "round"
12609
+ }
12610
+ ),
12611
+ /* @__PURE__ */ jsxRuntime.jsx(
12612
+ "path",
12613
+ {
12614
+ opacity: "0.25",
12615
+ d: "M172.181 107.094L173.624 107.928",
12616
+ stroke: "#52525B",
12617
+ strokeWidth: "1.5",
12618
+ strokeLinecap: "round",
12619
+ strokeLinejoin: "round"
12620
+ }
12621
+ ),
12622
+ /* @__PURE__ */ jsxRuntime.jsx(
12623
+ "path",
12624
+ {
12625
+ opacity: "0.13",
12626
+ d: "M176.386 106.126L176.379 107.294",
12627
+ stroke: "#52525B",
12628
+ strokeWidth: "1.5",
12629
+ strokeLinecap: "round",
12630
+ strokeLinejoin: "round"
12631
+ }
12632
+ ),
12633
+ /* @__PURE__ */ jsxRuntime.jsx(
12634
+ "rect",
12635
+ {
12636
+ width: "12",
12637
+ height: "3",
12638
+ rx: "1.5",
12639
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12640
+ fill: "#D4D4D8"
12641
+ }
12642
+ ),
12643
+ /* @__PURE__ */ jsxRuntime.jsx(
12644
+ "rect",
12645
+ {
12646
+ x: "0.00428286",
12647
+ y: "-0.742904",
12648
+ width: "33.5",
12649
+ height: "65.5",
12650
+ rx: "6.75",
12651
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12652
+ fill: "#D4D4D8",
12653
+ stroke: "#52525B",
12654
+ strokeWidth: "1.5"
12655
+ }
12656
+ ),
12657
+ /* @__PURE__ */ jsxRuntime.jsx(
12658
+ "rect",
12659
+ {
12660
+ x: "0.00428286",
12661
+ y: "-0.742904",
12662
+ width: "33.5",
12663
+ height: "65.5",
12664
+ rx: "6.75",
12665
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12666
+ fill: "white",
12667
+ stroke: "#52525B",
12668
+ strokeWidth: "1.5"
12669
+ }
12670
+ ),
12671
+ /* @__PURE__ */ jsxRuntime.jsx(
12672
+ "rect",
12673
+ {
12674
+ width: "12",
12675
+ height: "3",
12676
+ rx: "1.5",
12677
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12678
+ fill: "#D4D4D8"
12679
+ }
12680
+ ),
12681
+ /* @__PURE__ */ jsxRuntime.jsx(
12682
+ "rect",
12683
+ {
12684
+ width: "17",
12685
+ height: "3",
12686
+ rx: "1.5",
12687
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12688
+ fill: "#D4D4D8"
12689
+ }
12690
+ ),
12691
+ /* @__PURE__ */ jsxRuntime.jsx(
12692
+ "rect",
12693
+ {
12694
+ width: "12",
12695
+ height: "3",
12696
+ rx: "1.5",
12697
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12698
+ fill: "#D4D4D8"
12699
+ }
12700
+ ),
12701
+ /* @__PURE__ */ jsxRuntime.jsx(
12702
+ "path",
12703
+ {
12704
+ 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",
12705
+ fill: "#A1A1AA"
12706
+ }
12707
+ ),
12708
+ /* @__PURE__ */ jsxRuntime.jsx(
12709
+ "rect",
12710
+ {
12711
+ width: "17",
12712
+ height: "3",
12713
+ rx: "1.5",
12714
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12715
+ fill: "#A1A1AA"
12716
+ }
12717
+ ),
12718
+ /* @__PURE__ */ jsxRuntime.jsx(
12719
+ "rect",
12720
+ {
12721
+ width: "12",
12722
+ height: "3",
12723
+ rx: "1.5",
12724
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12725
+ fill: "#A1A1AA"
12726
+ }
12727
+ ),
12728
+ /* @__PURE__ */ jsxRuntime.jsx(
12729
+ "path",
12730
+ {
12731
+ 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",
12732
+ fill: "#52525B"
12733
+ }
12734
+ ),
12735
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12736
+ "path",
12737
+ {
12738
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12739
+ stroke: "#A1A1AA",
12740
+ strokeWidth: "1.5",
12741
+ strokeLinecap: "round",
12742
+ strokeLinejoin: "round"
12743
+ }
12744
+ ) }),
12745
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12746
+ "path",
12747
+ {
12748
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12749
+ stroke: "#A1A1AA",
12750
+ strokeWidth: "1.5",
12751
+ strokeLinecap: "round",
12752
+ strokeLinejoin: "round"
12753
+ }
12754
+ ) }),
12755
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12756
+ "path",
12757
+ {
12758
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12759
+ stroke: "#A1A1AA",
12760
+ strokeWidth: "1.5",
12761
+ strokeLinecap: "round",
12762
+ strokeLinejoin: "round"
12763
+ }
12764
+ ) }),
12765
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12766
+ "path",
12767
+ {
12768
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12769
+ stroke: "#A1A1AA",
12770
+ strokeWidth: "1.5",
12771
+ strokeLinecap: "round",
12772
+ strokeLinejoin: "round"
12773
+ }
12774
+ ) }),
12775
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12776
+ "path",
12777
+ {
12778
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12779
+ stroke: "#A1A1AA",
12780
+ strokeWidth: "1.5",
12781
+ strokeLinecap: "round",
12782
+ strokeLinejoin: "round"
12783
+ }
12784
+ ) }),
12785
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12786
+ "path",
12787
+ {
12788
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12789
+ stroke: "#A1A1AA",
12790
+ strokeWidth: "1.5",
12791
+ strokeLinecap: "round",
12792
+ strokeLinejoin: "round"
12793
+ }
12794
+ ) }),
12795
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12796
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12797
+ "rect",
12737
12798
  {
12738
- options: locations.options,
12739
- fetchNextPage: locations.fetchNextPage,
12740
- isFetchingNextPage: locations.isFetchingNextPage,
12741
- searchValue: locations.searchValue,
12742
- onSearchValueChange: locations.onSearchValueChange,
12743
- placeholder: "Select location",
12744
- onChange: (value) => {
12745
- setValue("shipping_option_id", "", {
12746
- shouldDirty: true,
12747
- shouldTouch: true
12748
- });
12749
- onChange(value);
12750
- },
12751
- ...field
12799
+ width: "12",
12800
+ height: "12",
12801
+ fill: "white",
12802
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12752
12803
  }
12753
- ) })
12754
- ] }) });
12755
- }
12756
- }
12757
- );
12758
- };
12759
- const ShippingOptionField = ({
12760
- shippingProfileId,
12761
- preview,
12762
- control
12763
- }) => {
12764
- var _a;
12765
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12766
- const shippingOptions = useComboboxData({
12767
- queryKey: ["shipping_options", locationId, shippingProfileId],
12768
- queryFn: async (params) => {
12769
- return await sdk.admin.shippingOption.list({
12770
- ...params,
12771
- stock_location_id: locationId,
12772
- shipping_profile_id: shippingProfileId
12773
- });
12774
- },
12775
- getOptions: (data) => {
12776
- return data.shipping_options.map((option) => {
12777
- var _a2;
12778
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12779
- (r) => r.attribute === "is_return" && r.value === "true"
12780
- )) {
12781
- return void 0;
12782
- }
12783
- return {
12784
- label: option.name,
12785
- value: option.id
12786
- };
12787
- }).filter(Boolean);
12788
- },
12789
- enabled: !!locationId && !!shippingProfileId,
12790
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12791
- });
12792
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12793
- return /* @__PURE__ */ jsxRuntime.jsx(
12794
- Form$2.Field,
12795
- {
12796
- control,
12797
- name: "shipping_option_id",
12798
- render: ({ field }) => {
12799
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12800
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12801
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12802
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12803
- ] }),
12804
- /* @__PURE__ */ jsxRuntime.jsx(
12805
- ConditionalTooltip,
12804
+ ) }),
12805
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12806
+ "rect",
12806
12807
  {
12807
- content: tooltipContent,
12808
- showTooltip: !locationId || !shippingProfileId,
12809
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12810
- Combobox,
12811
- {
12812
- options: shippingOptions.options,
12813
- fetchNextPage: shippingOptions.fetchNextPage,
12814
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12815
- searchValue: shippingOptions.searchValue,
12816
- onSearchValueChange: shippingOptions.onSearchValueChange,
12817
- placeholder: "Select shipping option",
12818
- ...field,
12819
- disabled: !locationId || !shippingProfileId
12820
- }
12821
- ) }) })
12808
+ width: "12",
12809
+ height: "12",
12810
+ fill: "white",
12811
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12822
12812
  }
12823
- )
12824
- ] }) });
12825
- }
12826
- }
12827
- );
12828
- };
12829
- const CustomAmountField = ({
12830
- control,
12831
- currencyCode
12832
- }) => {
12833
- return /* @__PURE__ */ jsxRuntime.jsx(
12834
- Form$2.Field,
12835
- {
12836
- control,
12837
- name: "custom_amount",
12838
- render: ({ field: { onChange, ...field } }) => {
12839
- return /* @__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, { optional: true, children: "Custom amount" }),
12842
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12843
- ] }),
12844
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12845
- ui.CurrencyInput,
12813
+ ) }),
12814
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12815
+ "rect",
12846
12816
  {
12847
- ...field,
12848
- onValueChange: (value) => onChange(value),
12849
- symbol: getNativeSymbol(currencyCode),
12850
- code: currencyCode
12817
+ width: "12",
12818
+ height: "12",
12819
+ fill: "white",
12820
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12821
+ }
12822
+ ) }),
12823
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12824
+ "rect",
12825
+ {
12826
+ width: "12",
12827
+ height: "12",
12828
+ fill: "white",
12829
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12830
+ }
12831
+ ) }),
12832
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12833
+ "rect",
12834
+ {
12835
+ width: "12",
12836
+ height: "12",
12837
+ fill: "white",
12838
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12839
+ }
12840
+ ) }),
12841
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12842
+ "rect",
12843
+ {
12844
+ width: "12",
12845
+ height: "12",
12846
+ fill: "white",
12847
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12851
12848
  }
12852
12849
  ) })
12853
- ] });
12854
- }
12850
+ ] })
12851
+ ]
12855
12852
  }
12856
12853
  );
12857
12854
  };
12855
+ const schema$1 = objectType({
12856
+ customer_id: stringType().min(1)
12857
+ });
12858
12858
  const BillingAddress = () => {
12859
12859
  const { id } = reactRouterDom.useParams();
12860
12860
  const { order, isPending, isError, error } = useOrder(id, {
@@ -13089,6 +13089,10 @@ const routeModule = {
13089
13089
  Component: SalesChannel,
13090
13090
  path: "/draft-orders/:id/sales-channel"
13091
13091
  },
13092
+ {
13093
+ Component: Shipping,
13094
+ path: "/draft-orders/:id/shipping"
13095
+ },
13092
13096
  {
13093
13097
  Component: ShippingAddress,
13094
13098
  path: "/draft-orders/:id/shipping-address"
@@ -13097,10 +13101,6 @@ const routeModule = {
13097
13101
  Component: TransferOwnership,
13098
13102
  path: "/draft-orders/:id/transfer-ownership"
13099
13103
  },
13100
- {
13101
- Component: Shipping,
13102
- path: "/draft-orders/:id/shipping"
13103
- },
13104
13104
  {
13105
13105
  Component: BillingAddress,
13106
13106
  path: "/draft-orders/:id/billing-address"