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