@medusajs/draft-order 2.10.2-snapshot-20250901165744 → 2.10.2-snapshot-20250902104934

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.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9554,75 +9554,10 @@ const ID = () => {
9554
9554
  /* @__PURE__ */ jsx(Outlet, {})
9555
9555
  ] });
9556
9556
  };
9557
- const CustomItems = () => {
9558
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9559
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9560
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9561
- ] });
9562
- };
9563
- const CustomItemsForm = () => {
9564
- const form = useForm({
9565
- resolver: zodResolver(schema$5)
9566
- });
9567
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9568
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9569
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9570
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9571
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9572
- ] }) })
9573
- ] }) });
9574
- };
9575
- const schema$5 = objectType({
9576
- email: stringType().email()
9577
- });
9578
- const InlineTip = forwardRef(
9579
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9580
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9581
- return /* @__PURE__ */ jsxs(
9582
- "div",
9583
- {
9584
- ref,
9585
- className: clx(
9586
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9587
- className
9588
- ),
9589
- ...props,
9590
- children: [
9591
- /* @__PURE__ */ jsx(
9592
- "div",
9593
- {
9594
- role: "presentation",
9595
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9596
- "bg-ui-tag-orange-icon": variant === "warning"
9597
- })
9598
- }
9599
- ),
9600
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9601
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9602
- labelValue,
9603
- ":"
9604
- ] }),
9605
- " ",
9606
- children
9607
- ] })
9608
- ]
9609
- }
9610
- );
9611
- }
9612
- );
9613
- InlineTip.displayName = "InlineTip";
9614
- const MetadataFieldSchema = objectType({
9615
- key: stringType(),
9616
- disabled: booleanType().optional(),
9617
- value: anyType()
9618
- });
9619
- const MetadataSchema = objectType({
9620
- metadata: arrayType(MetadataFieldSchema)
9621
- });
9622
- const Metadata = () => {
9557
+ const BillingAddress = () => {
9623
9558
  const { id } = useParams();
9624
9559
  const { order, isPending, isError, error } = useOrder(id, {
9625
- fields: "metadata"
9560
+ fields: "+billing_address"
9626
9561
  });
9627
9562
  if (isError) {
9628
9563
  throw error;
@@ -9630,33 +9565,36 @@ const Metadata = () => {
9630
9565
  const isReady = !isPending && !!order;
9631
9566
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9632
9567
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9633
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9634
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9568
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9569
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9635
9570
  ] }),
9636
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9571
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9637
9572
  ] });
9638
9573
  };
9639
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9640
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9641
- const MetadataForm = ({ orderId, metadata }) => {
9642
- const { handleSuccess } = useRouteModal();
9643
- const hasUneditableRows = getHasUneditableRows(metadata);
9644
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9574
+ const BillingAddressForm = ({ order }) => {
9575
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9645
9576
  const form = useForm({
9646
9577
  defaultValues: {
9647
- metadata: getDefaultValues(metadata)
9578
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9579
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9580
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9581
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9582
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9583
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9584
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9585
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9586
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9587
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9648
9588
  },
9649
- resolver: zodResolver(MetadataSchema)
9589
+ resolver: zodResolver(schema$5)
9650
9590
  });
9651
- const handleSubmit = form.handleSubmit(async (data) => {
9652
- const parsedData = parseValues(data);
9591
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9592
+ const { handleSuccess } = useRouteModal();
9593
+ const onSubmit = form.handleSubmit(async (data) => {
9653
9594
  await mutateAsync(
9654
- {
9655
- metadata: parsedData
9656
- },
9595
+ { billing_address: data },
9657
9596
  {
9658
9597
  onSuccess: () => {
9659
- toast.success("Metadata updated");
9660
9598
  handleSuccess();
9661
9599
  },
9662
9600
  onError: (error) => {
@@ -9665,266 +9603,236 @@ const MetadataForm = ({ orderId, metadata }) => {
9665
9603
  }
9666
9604
  );
9667
9605
  });
9668
- const { fields, insert, remove } = useFieldArray({
9669
- control: form.control,
9670
- name: "metadata"
9671
- });
9672
- function deleteRow(index) {
9673
- remove(index);
9674
- if (fields.length === 1) {
9675
- insert(0, {
9676
- key: "",
9677
- value: "",
9678
- disabled: false
9679
- });
9680
- }
9681
- }
9682
- function insertRow(index, position) {
9683
- insert(index + (position === "above" ? 0 : 1), {
9684
- key: "",
9685
- value: "",
9686
- disabled: false
9687
- });
9688
- }
9689
9606
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9690
9607
  KeyboundForm,
9691
9608
  {
9692
- onSubmit: handleSubmit,
9693
9609
  className: "flex flex-1 flex-col overflow-hidden",
9610
+ onSubmit,
9694
9611
  children: [
9695
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9696
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9697
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9698
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9699
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9700
- ] }),
9701
- fields.map((field, index) => {
9702
- const isDisabled = field.disabled || false;
9703
- let placeholder = "-";
9704
- if (typeof field.value === "object") {
9705
- placeholder = "{ ... }";
9612
+ /* @__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: [
9613
+ /* @__PURE__ */ jsx(
9614
+ Form$2.Field,
9615
+ {
9616
+ control: form.control,
9617
+ name: "country_code",
9618
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9619
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9620
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9621
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9622
+ ] })
9623
+ }
9624
+ ),
9625
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9626
+ /* @__PURE__ */ jsx(
9627
+ Form$2.Field,
9628
+ {
9629
+ control: form.control,
9630
+ name: "first_name",
9631
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9633
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9634
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
+ ] })
9706
9636
  }
9707
- if (Array.isArray(field.value)) {
9708
- placeholder = "[ ... ]";
9637
+ ),
9638
+ /* @__PURE__ */ jsx(
9639
+ Form$2.Field,
9640
+ {
9641
+ control: form.control,
9642
+ name: "last_name",
9643
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9644
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9645
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9646
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9647
+ ] })
9709
9648
  }
9710
- return /* @__PURE__ */ jsx(
9711
- ConditionalTooltip,
9712
- {
9713
- showTooltip: isDisabled,
9714
- content: "This row is disabled because it contains non-primitive data.",
9715
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9716
- /* @__PURE__ */ jsxs(
9717
- "div",
9718
- {
9719
- className: clx("grid grid-cols-2 divide-x", {
9720
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9721
- }),
9722
- children: [
9723
- /* @__PURE__ */ jsx(
9724
- Form$2.Field,
9725
- {
9726
- control: form.control,
9727
- name: `metadata.${index}.key`,
9728
- render: ({ field: field2 }) => {
9729
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9730
- GridInput,
9731
- {
9732
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9733
- ...field2,
9734
- disabled: isDisabled,
9735
- placeholder: "Key"
9736
- }
9737
- ) }) });
9738
- }
9739
- }
9740
- ),
9741
- /* @__PURE__ */ jsx(
9742
- Form$2.Field,
9743
- {
9744
- control: form.control,
9745
- name: `metadata.${index}.value`,
9746
- render: ({ field: { value, ...field2 } }) => {
9747
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9748
- GridInput,
9749
- {
9750
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9751
- ...field2,
9752
- value: isDisabled ? placeholder : value,
9753
- disabled: isDisabled,
9754
- placeholder: "Value"
9755
- }
9756
- ) }) });
9757
- }
9758
- }
9759
- )
9760
- ]
9761
- }
9762
- ),
9763
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
9764
- /* @__PURE__ */ jsx(
9765
- DropdownMenu.Trigger,
9766
- {
9767
- className: clx(
9768
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9769
- {
9770
- hidden: isDisabled
9771
- }
9772
- ),
9773
- disabled: isDisabled,
9774
- asChild: true,
9775
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
9776
- }
9777
- ),
9778
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9779
- /* @__PURE__ */ jsxs(
9780
- DropdownMenu.Item,
9781
- {
9782
- className: "gap-x-2",
9783
- onClick: () => insertRow(index, "above"),
9784
- children: [
9785
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
9786
- "Insert row above"
9787
- ]
9788
- }
9789
- ),
9790
- /* @__PURE__ */ jsxs(
9791
- DropdownMenu.Item,
9792
- {
9793
- className: "gap-x-2",
9794
- onClick: () => insertRow(index, "below"),
9795
- children: [
9796
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
9797
- "Insert row below"
9798
- ]
9799
- }
9800
- ),
9801
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
9802
- /* @__PURE__ */ jsxs(
9803
- DropdownMenu.Item,
9804
- {
9805
- className: "gap-x-2",
9806
- onClick: () => deleteRow(index),
9807
- children: [
9808
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
9809
- "Delete row"
9810
- ]
9811
- }
9812
- )
9813
- ] })
9814
- ] })
9815
- ] })
9816
- },
9817
- field.id
9818
- );
9819
- })
9649
+ )
9820
9650
  ] }),
9821
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
9822
- ] }),
9823
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9824
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9651
+ /* @__PURE__ */ jsx(
9652
+ Form$2.Field,
9653
+ {
9654
+ control: form.control,
9655
+ name: "company",
9656
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9658
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
+ ] })
9661
+ }
9662
+ ),
9663
+ /* @__PURE__ */ jsx(
9664
+ Form$2.Field,
9665
+ {
9666
+ control: form.control,
9667
+ name: "address_1",
9668
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9669
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9670
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9671
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9672
+ ] })
9673
+ }
9674
+ ),
9675
+ /* @__PURE__ */ jsx(
9676
+ Form$2.Field,
9677
+ {
9678
+ control: form.control,
9679
+ name: "address_2",
9680
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9681
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9682
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9683
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9684
+ ] })
9685
+ }
9686
+ ),
9687
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9688
+ /* @__PURE__ */ jsx(
9689
+ Form$2.Field,
9690
+ {
9691
+ control: form.control,
9692
+ name: "postal_code",
9693
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9695
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
+ ] })
9698
+ }
9699
+ ),
9700
+ /* @__PURE__ */ jsx(
9701
+ Form$2.Field,
9702
+ {
9703
+ control: form.control,
9704
+ name: "city",
9705
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9706
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9707
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9708
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9709
+ ] })
9710
+ }
9711
+ )
9712
+ ] }),
9713
+ /* @__PURE__ */ jsx(
9714
+ Form$2.Field,
9715
+ {
9716
+ control: form.control,
9717
+ name: "province",
9718
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9720
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
+ ] })
9723
+ }
9724
+ ),
9725
+ /* @__PURE__ */ jsx(
9726
+ Form$2.Field,
9727
+ {
9728
+ control: form.control,
9729
+ name: "phone",
9730
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9731
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9732
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9733
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9734
+ ] })
9735
+ }
9736
+ )
9737
+ ] }) }),
9738
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9739
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9825
9740
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9826
9741
  ] }) })
9827
9742
  ]
9828
9743
  }
9829
9744
  ) });
9830
9745
  };
9831
- const GridInput = forwardRef(({ className, ...props }, ref) => {
9832
- return /* @__PURE__ */ jsx(
9833
- "input",
9834
- {
9835
- ref,
9836
- ...props,
9837
- autoComplete: "off",
9838
- className: clx(
9839
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
9840
- className
9841
- )
9842
- }
9843
- );
9844
- });
9845
- GridInput.displayName = "MetadataForm.GridInput";
9846
- const PlaceholderInner = () => {
9847
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9848
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9849
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9850
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
9851
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
9746
+ const schema$5 = addressSchema;
9747
+ const CustomItems = () => {
9748
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9749
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9750
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9751
+ ] });
9752
+ };
9753
+ const CustomItemsForm = () => {
9754
+ const form = useForm({
9755
+ resolver: zodResolver(schema$4)
9756
+ });
9757
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9758
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9759
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9760
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9761
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9852
9762
  ] }) })
9763
+ ] }) });
9764
+ };
9765
+ const schema$4 = objectType({
9766
+ email: stringType().email()
9767
+ });
9768
+ const Email = () => {
9769
+ const { id } = useParams();
9770
+ const { order, isPending, isError, error } = useOrder(id, {
9771
+ fields: "+email"
9772
+ });
9773
+ if (isError) {
9774
+ throw error;
9775
+ }
9776
+ const isReady = !isPending && !!order;
9777
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9778
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9779
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9780
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9781
+ ] }),
9782
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9853
9783
  ] });
9854
9784
  };
9855
- const EDITABLE_TYPES = ["string", "number", "boolean"];
9856
- function getDefaultValues(metadata) {
9857
- if (!metadata || !Object.keys(metadata).length) {
9858
- return [
9785
+ const EmailForm = ({ order }) => {
9786
+ const form = useForm({
9787
+ defaultValues: {
9788
+ email: order.email ?? ""
9789
+ },
9790
+ resolver: zodResolver(schema$3)
9791
+ });
9792
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
+ const { handleSuccess } = useRouteModal();
9794
+ const onSubmit = form.handleSubmit(async (data) => {
9795
+ await mutateAsync(
9796
+ { email: data.email },
9859
9797
  {
9860
- key: "",
9861
- value: "",
9862
- disabled: false
9798
+ onSuccess: () => {
9799
+ handleSuccess();
9800
+ },
9801
+ onError: (error) => {
9802
+ toast.error(error.message);
9803
+ }
9863
9804
  }
9864
- ];
9865
- }
9866
- return Object.entries(metadata).map(([key, value]) => {
9867
- if (!EDITABLE_TYPES.includes(typeof value)) {
9868
- return {
9869
- key,
9870
- value,
9871
- disabled: true
9872
- };
9873
- }
9874
- let stringValue = value;
9875
- if (typeof value !== "string") {
9876
- stringValue = JSON.stringify(value);
9877
- }
9878
- return {
9879
- key,
9880
- value: stringValue,
9881
- original_key: key
9882
- };
9805
+ );
9883
9806
  });
9884
- }
9885
- function parseValues(values) {
9886
- const metadata = values.metadata;
9887
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9888
- if (isEmpty) {
9889
- return null;
9890
- }
9891
- const update = {};
9892
- metadata.forEach((field) => {
9893
- let key = field.key;
9894
- let value = field.value;
9895
- const disabled = field.disabled;
9896
- if (!key || !value) {
9897
- return;
9898
- }
9899
- if (disabled) {
9900
- update[key] = value;
9901
- return;
9902
- }
9903
- key = key.trim();
9904
- value = value.trim();
9905
- if (value === "true") {
9906
- update[key] = true;
9907
- } else if (value === "false") {
9908
- update[key] = false;
9909
- } else {
9910
- const parsedNumber = parseFloat(value);
9911
- if (!isNaN(parsedNumber)) {
9912
- update[key] = parsedNumber;
9913
- } else {
9914
- update[key] = value;
9915
- }
9807
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9808
+ KeyboundForm,
9809
+ {
9810
+ className: "flex flex-1 flex-col overflow-hidden",
9811
+ onSubmit,
9812
+ children: [
9813
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9814
+ Form$2.Field,
9815
+ {
9816
+ control: form.control,
9817
+ name: "email",
9818
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9819
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9820
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9821
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9822
+ ] })
9823
+ }
9824
+ ) }),
9825
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9827
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9828
+ ] }) })
9829
+ ]
9916
9830
  }
9917
- });
9918
- return update;
9919
- }
9920
- function getHasUneditableRows(metadata) {
9921
- if (!metadata) {
9922
- return false;
9923
- }
9924
- return Object.values(metadata).some(
9925
- (value) => !EDITABLE_TYPES.includes(typeof value)
9926
- );
9927
- }
9831
+ ) });
9832
+ };
9833
+ const schema$3 = objectType({
9834
+ email: stringType().email()
9835
+ });
9928
9836
  const NumberInput = forwardRef(
9929
9837
  ({
9930
9838
  value,
@@ -10899,384 +10807,126 @@ const customItemSchema = objectType({
10899
10807
  quantity: numberType(),
10900
10808
  unit_price: unionType([numberType(), stringType()])
10901
10809
  });
10902
- const Email = () => {
10903
- const { id } = useParams();
10904
- const { order, isPending, isError, error } = useOrder(id, {
10905
- fields: "+email"
10810
+ const PROMOTION_QUERY_KEY = "promotions";
10811
+ const promotionsQueryKeys = {
10812
+ list: (query2) => [
10813
+ PROMOTION_QUERY_KEY,
10814
+ query2 ? query2 : void 0
10815
+ ],
10816
+ detail: (id, query2) => [
10817
+ PROMOTION_QUERY_KEY,
10818
+ id,
10819
+ query2 ? query2 : void 0
10820
+ ]
10821
+ };
10822
+ const usePromotions = (query2, options) => {
10823
+ const { data, ...rest } = useQuery({
10824
+ queryKey: promotionsQueryKeys.list(query2),
10825
+ queryFn: async () => sdk.admin.promotion.list(query2),
10826
+ ...options
10906
10827
  });
10907
- if (isError) {
10908
- throw error;
10828
+ return { ...data, ...rest };
10829
+ };
10830
+ const Promotions = () => {
10831
+ const { id } = useParams();
10832
+ const {
10833
+ order: preview,
10834
+ isError: isPreviewError,
10835
+ error: previewError
10836
+ } = useOrderPreview(id, void 0);
10837
+ useInitiateOrderEdit({ preview });
10838
+ const { onCancel } = useCancelOrderEdit({ preview });
10839
+ if (isPreviewError) {
10840
+ throw previewError;
10909
10841
  }
10910
- const isReady = !isPending && !!order;
10911
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10912
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10913
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10914
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10915
- ] }),
10916
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10842
+ const isReady = !!preview;
10843
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10844
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10845
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10917
10846
  ] });
10918
10847
  };
10919
- const EmailForm = ({ order }) => {
10920
- const form = useForm({
10921
- defaultValues: {
10922
- email: order.email ?? ""
10848
+ const PromotionForm = ({ preview }) => {
10849
+ const { items, shipping_methods } = preview;
10850
+ const [isSubmitting, setIsSubmitting] = useState(false);
10851
+ const [comboboxValue, setComboboxValue] = useState("");
10852
+ const { handleSuccess } = useRouteModal();
10853
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10854
+ const promoCodes = getPromotionCodes(items, shipping_methods);
10855
+ const { promotions, isPending, isError, error } = usePromotions(
10856
+ {
10857
+ code: promoCodes
10923
10858
  },
10924
- resolver: zodResolver(schema$4)
10859
+ {
10860
+ enabled: !!promoCodes.length
10861
+ }
10862
+ );
10863
+ const comboboxData = useComboboxData({
10864
+ queryKey: ["promotions", "combobox", promoCodes],
10865
+ queryFn: async (params) => {
10866
+ return await sdk.admin.promotion.list({
10867
+ ...params,
10868
+ code: {
10869
+ $nin: promoCodes
10870
+ }
10871
+ });
10872
+ },
10873
+ getOptions: (data) => {
10874
+ return data.promotions.map((promotion) => ({
10875
+ label: promotion.code,
10876
+ value: promotion.code
10877
+ }));
10878
+ }
10925
10879
  });
10926
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10927
- const { handleSuccess } = useRouteModal();
10928
- const onSubmit = form.handleSubmit(async (data) => {
10929
- await mutateAsync(
10930
- { email: data.email },
10880
+ const add = async (value) => {
10881
+ if (!value) {
10882
+ return;
10883
+ }
10884
+ addPromotions(
10931
10885
  {
10932
- onSuccess: () => {
10933
- handleSuccess();
10886
+ promo_codes: [value]
10887
+ },
10888
+ {
10889
+ onError: (e) => {
10890
+ toast.error(e.message);
10891
+ comboboxData.onSearchValueChange("");
10892
+ setComboboxValue("");
10934
10893
  },
10935
- onError: (error) => {
10936
- toast.error(error.message);
10894
+ onSuccess: () => {
10895
+ comboboxData.onSearchValueChange("");
10896
+ setComboboxValue("");
10937
10897
  }
10938
10898
  }
10939
10899
  );
10940
- });
10941
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10942
- KeyboundForm,
10943
- {
10944
- className: "flex flex-1 flex-col overflow-hidden",
10945
- onSubmit,
10946
- children: [
10947
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10948
- Form$2.Field,
10949
- {
10950
- control: form.control,
10951
- name: "email",
10952
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10953
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10954
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10955
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10956
- ] })
10957
- }
10958
- ) }),
10959
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10960
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10961
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10962
- ] }) })
10963
- ]
10900
+ };
10901
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10902
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10903
+ const onSubmit = async () => {
10904
+ setIsSubmitting(true);
10905
+ let requestSucceeded = false;
10906
+ await requestOrderEdit(void 0, {
10907
+ onError: (e) => {
10908
+ toast.error(e.message);
10909
+ },
10910
+ onSuccess: () => {
10911
+ requestSucceeded = true;
10912
+ }
10913
+ });
10914
+ if (!requestSucceeded) {
10915
+ setIsSubmitting(false);
10916
+ return;
10964
10917
  }
10965
- ) });
10966
- };
10967
- const schema$4 = objectType({
10968
- email: stringType().email()
10969
- });
10970
- const BillingAddress = () => {
10971
- const { id } = useParams();
10972
- const { order, isPending, isError, error } = useOrder(id, {
10973
- fields: "+billing_address"
10974
- });
10975
- if (isError) {
10976
- throw error;
10977
- }
10978
- const isReady = !isPending && !!order;
10979
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10980
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10981
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
10982
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
10983
- ] }),
10984
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
10985
- ] });
10986
- };
10987
- const BillingAddressForm = ({ order }) => {
10988
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10989
- const form = useForm({
10990
- defaultValues: {
10991
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
10992
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
10993
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
10994
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
10995
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
10996
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
10997
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
10998
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
10999
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11000
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11001
- },
11002
- resolver: zodResolver(schema$3)
11003
- });
11004
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11005
- const { handleSuccess } = useRouteModal();
11006
- const onSubmit = form.handleSubmit(async (data) => {
11007
- await mutateAsync(
11008
- { billing_address: data },
11009
- {
11010
- onSuccess: () => {
11011
- handleSuccess();
11012
- },
11013
- onError: (error) => {
11014
- toast.error(error.message);
11015
- }
11016
- }
11017
- );
11018
- });
11019
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11020
- KeyboundForm,
11021
- {
11022
- className: "flex flex-1 flex-col overflow-hidden",
11023
- onSubmit,
11024
- children: [
11025
- /* @__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: [
11026
- /* @__PURE__ */ jsx(
11027
- Form$2.Field,
11028
- {
11029
- control: form.control,
11030
- name: "country_code",
11031
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11032
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11033
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11034
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11035
- ] })
11036
- }
11037
- ),
11038
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11039
- /* @__PURE__ */ jsx(
11040
- Form$2.Field,
11041
- {
11042
- control: form.control,
11043
- name: "first_name",
11044
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11045
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11046
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11047
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11048
- ] })
11049
- }
11050
- ),
11051
- /* @__PURE__ */ jsx(
11052
- Form$2.Field,
11053
- {
11054
- control: form.control,
11055
- name: "last_name",
11056
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11057
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11058
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11059
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11060
- ] })
11061
- }
11062
- )
11063
- ] }),
11064
- /* @__PURE__ */ jsx(
11065
- Form$2.Field,
11066
- {
11067
- control: form.control,
11068
- name: "company",
11069
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11070
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11071
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11072
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11073
- ] })
11074
- }
11075
- ),
11076
- /* @__PURE__ */ jsx(
11077
- Form$2.Field,
11078
- {
11079
- control: form.control,
11080
- name: "address_1",
11081
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11082
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11083
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11084
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11085
- ] })
11086
- }
11087
- ),
11088
- /* @__PURE__ */ jsx(
11089
- Form$2.Field,
11090
- {
11091
- control: form.control,
11092
- name: "address_2",
11093
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11094
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11095
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11096
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11097
- ] })
11098
- }
11099
- ),
11100
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11101
- /* @__PURE__ */ jsx(
11102
- Form$2.Field,
11103
- {
11104
- control: form.control,
11105
- name: "postal_code",
11106
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11107
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11108
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11109
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11110
- ] })
11111
- }
11112
- ),
11113
- /* @__PURE__ */ jsx(
11114
- Form$2.Field,
11115
- {
11116
- control: form.control,
11117
- name: "city",
11118
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11119
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11120
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11121
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11122
- ] })
11123
- }
11124
- )
11125
- ] }),
11126
- /* @__PURE__ */ jsx(
11127
- Form$2.Field,
11128
- {
11129
- control: form.control,
11130
- name: "province",
11131
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11132
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11133
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11134
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11135
- ] })
11136
- }
11137
- ),
11138
- /* @__PURE__ */ jsx(
11139
- Form$2.Field,
11140
- {
11141
- control: form.control,
11142
- name: "phone",
11143
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11144
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11145
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11146
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11147
- ] })
11148
- }
11149
- )
11150
- ] }) }),
11151
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11152
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11153
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11154
- ] }) })
11155
- ]
11156
- }
11157
- ) });
11158
- };
11159
- const schema$3 = addressSchema;
11160
- const PROMOTION_QUERY_KEY = "promotions";
11161
- const promotionsQueryKeys = {
11162
- list: (query2) => [
11163
- PROMOTION_QUERY_KEY,
11164
- query2 ? query2 : void 0
11165
- ],
11166
- detail: (id, query2) => [
11167
- PROMOTION_QUERY_KEY,
11168
- id,
11169
- query2 ? query2 : void 0
11170
- ]
11171
- };
11172
- const usePromotions = (query2, options) => {
11173
- const { data, ...rest } = useQuery({
11174
- queryKey: promotionsQueryKeys.list(query2),
11175
- queryFn: async () => sdk.admin.promotion.list(query2),
11176
- ...options
11177
- });
11178
- return { ...data, ...rest };
11179
- };
11180
- const Promotions = () => {
11181
- const { id } = useParams();
11182
- const {
11183
- order: preview,
11184
- isError: isPreviewError,
11185
- error: previewError
11186
- } = useOrderPreview(id, void 0);
11187
- useInitiateOrderEdit({ preview });
11188
- const { onCancel } = useCancelOrderEdit({ preview });
11189
- if (isPreviewError) {
11190
- throw previewError;
11191
- }
11192
- const isReady = !!preview;
11193
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11194
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11195
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11196
- ] });
11197
- };
11198
- const PromotionForm = ({ preview }) => {
11199
- const { items, shipping_methods } = preview;
11200
- const [isSubmitting, setIsSubmitting] = useState(false);
11201
- const [comboboxValue, setComboboxValue] = useState("");
11202
- const { handleSuccess } = useRouteModal();
11203
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11204
- const promoCodes = getPromotionCodes(items, shipping_methods);
11205
- const { promotions, isPending, isError, error } = usePromotions(
11206
- {
11207
- code: promoCodes
11208
- },
11209
- {
11210
- enabled: !!promoCodes.length
11211
- }
11212
- );
11213
- const comboboxData = useComboboxData({
11214
- queryKey: ["promotions", "combobox", promoCodes],
11215
- queryFn: async (params) => {
11216
- return await sdk.admin.promotion.list({
11217
- ...params,
11218
- code: {
11219
- $nin: promoCodes
11220
- }
11221
- });
11222
- },
11223
- getOptions: (data) => {
11224
- return data.promotions.map((promotion) => ({
11225
- label: promotion.code,
11226
- value: promotion.code
11227
- }));
11228
- }
11229
- });
11230
- const add = async (value) => {
11231
- if (!value) {
11232
- return;
11233
- }
11234
- addPromotions(
11235
- {
11236
- promo_codes: [value]
11237
- },
11238
- {
11239
- onError: (e) => {
11240
- toast.error(e.message);
11241
- comboboxData.onSearchValueChange("");
11242
- setComboboxValue("");
11243
- },
11244
- onSuccess: () => {
11245
- comboboxData.onSearchValueChange("");
11246
- setComboboxValue("");
11247
- }
11248
- }
11249
- );
11250
- };
11251
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11252
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11253
- const onSubmit = async () => {
11254
- setIsSubmitting(true);
11255
- let requestSucceeded = false;
11256
- await requestOrderEdit(void 0, {
11257
- onError: (e) => {
11258
- toast.error(e.message);
11259
- },
11260
- onSuccess: () => {
11261
- requestSucceeded = true;
11262
- }
11263
- });
11264
- if (!requestSucceeded) {
11265
- setIsSubmitting(false);
11266
- return;
11267
- }
11268
- await confirmOrderEdit(void 0, {
11269
- onError: (e) => {
11270
- toast.error(e.message);
11271
- },
11272
- onSuccess: () => {
11273
- handleSuccess();
11274
- },
11275
- onSettled: () => {
11276
- setIsSubmitting(false);
11277
- }
11278
- });
11279
- };
10918
+ await confirmOrderEdit(void 0, {
10919
+ onError: (e) => {
10920
+ toast.error(e.message);
10921
+ },
10922
+ onSuccess: () => {
10923
+ handleSuccess();
10924
+ },
10925
+ onSettled: () => {
10926
+ setIsSubmitting(false);
10927
+ }
10928
+ });
10929
+ };
11280
10930
  if (isError) {
11281
10931
  throw error;
11282
10932
  }
@@ -11434,46 +11084,88 @@ function getPromotionCodes(items, shippingMethods) {
11434
11084
  }
11435
11085
  return Array.from(codes);
11436
11086
  }
11437
- const SalesChannel = () => {
11087
+ const InlineTip = forwardRef(
11088
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11089
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11090
+ return /* @__PURE__ */ jsxs(
11091
+ "div",
11092
+ {
11093
+ ref,
11094
+ className: clx(
11095
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11096
+ className
11097
+ ),
11098
+ ...props,
11099
+ children: [
11100
+ /* @__PURE__ */ jsx(
11101
+ "div",
11102
+ {
11103
+ role: "presentation",
11104
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11105
+ "bg-ui-tag-orange-icon": variant === "warning"
11106
+ })
11107
+ }
11108
+ ),
11109
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
11110
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11111
+ labelValue,
11112
+ ":"
11113
+ ] }),
11114
+ " ",
11115
+ children
11116
+ ] })
11117
+ ]
11118
+ }
11119
+ );
11120
+ }
11121
+ );
11122
+ InlineTip.displayName = "InlineTip";
11123
+ const MetadataFieldSchema = objectType({
11124
+ key: stringType(),
11125
+ disabled: booleanType().optional(),
11126
+ value: anyType()
11127
+ });
11128
+ const MetadataSchema = objectType({
11129
+ metadata: arrayType(MetadataFieldSchema)
11130
+ });
11131
+ const Metadata = () => {
11438
11132
  const { id } = useParams();
11439
- const { draft_order, isPending, isError, error } = useDraftOrder(
11440
- id,
11441
- {
11442
- fields: "+sales_channel_id"
11443
- },
11444
- {
11445
- enabled: !!id
11446
- }
11447
- );
11133
+ const { order, isPending, isError, error } = useOrder(id, {
11134
+ fields: "metadata"
11135
+ });
11448
11136
  if (isError) {
11449
11137
  throw error;
11450
11138
  }
11451
- const ISrEADY = !!draft_order && !isPending;
11139
+ const isReady = !isPending && !!order;
11452
11140
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11453
11141
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11454
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11455
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11142
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
11143
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11456
11144
  ] }),
11457
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11145
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11458
11146
  ] });
11459
11147
  };
11460
- const SalesChannelForm = ({ order }) => {
11148
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11149
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11150
+ const MetadataForm = ({ orderId, metadata }) => {
11151
+ const { handleSuccess } = useRouteModal();
11152
+ const hasUneditableRows = getHasUneditableRows(metadata);
11153
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11461
11154
  const form = useForm({
11462
11155
  defaultValues: {
11463
- sales_channel_id: order.sales_channel_id || ""
11156
+ metadata: getDefaultValues(metadata)
11464
11157
  },
11465
- resolver: zodResolver(schema$2)
11158
+ resolver: zodResolver(MetadataSchema)
11466
11159
  });
11467
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11468
- const { handleSuccess } = useRouteModal();
11469
- const onSubmit = form.handleSubmit(async (data) => {
11160
+ const handleSubmit = form.handleSubmit(async (data) => {
11161
+ const parsedData = parseValues(data);
11470
11162
  await mutateAsync(
11471
11163
  {
11472
- sales_channel_id: data.sales_channel_id
11164
+ metadata: parsedData
11473
11165
  },
11474
11166
  {
11475
11167
  onSuccess: () => {
11476
- toast.success("Sales channel updated");
11168
+ toast.success("Metadata updated");
11477
11169
  handleSuccess();
11478
11170
  },
11479
11171
  onError: (error) => {
@@ -11482,1209 +11174,604 @@ const SalesChannelForm = ({ order }) => {
11482
11174
  }
11483
11175
  );
11484
11176
  });
11177
+ const { fields, insert, remove } = useFieldArray({
11178
+ control: form.control,
11179
+ name: "metadata"
11180
+ });
11181
+ function deleteRow(index) {
11182
+ remove(index);
11183
+ if (fields.length === 1) {
11184
+ insert(0, {
11185
+ key: "",
11186
+ value: "",
11187
+ disabled: false
11188
+ });
11189
+ }
11190
+ }
11191
+ function insertRow(index, position) {
11192
+ insert(index + (position === "above" ? 0 : 1), {
11193
+ key: "",
11194
+ value: "",
11195
+ disabled: false
11196
+ });
11197
+ }
11485
11198
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11486
11199
  KeyboundForm,
11487
11200
  {
11201
+ onSubmit: handleSubmit,
11488
11202
  className: "flex flex-1 flex-col overflow-hidden",
11489
- onSubmit,
11490
11203
  children: [
11491
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11492
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11493
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11204
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11205
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11206
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11207
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
11208
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11209
+ ] }),
11210
+ fields.map((field, index) => {
11211
+ const isDisabled = field.disabled || false;
11212
+ let placeholder = "-";
11213
+ if (typeof field.value === "object") {
11214
+ placeholder = "{ ... }";
11215
+ }
11216
+ if (Array.isArray(field.value)) {
11217
+ placeholder = "[ ... ]";
11218
+ }
11219
+ return /* @__PURE__ */ jsx(
11220
+ ConditionalTooltip,
11221
+ {
11222
+ showTooltip: isDisabled,
11223
+ content: "This row is disabled because it contains non-primitive data.",
11224
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
11225
+ /* @__PURE__ */ jsxs(
11226
+ "div",
11227
+ {
11228
+ className: clx("grid grid-cols-2 divide-x", {
11229
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11230
+ }),
11231
+ children: [
11232
+ /* @__PURE__ */ jsx(
11233
+ Form$2.Field,
11234
+ {
11235
+ control: form.control,
11236
+ name: `metadata.${index}.key`,
11237
+ render: ({ field: field2 }) => {
11238
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11239
+ GridInput,
11240
+ {
11241
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11242
+ ...field2,
11243
+ disabled: isDisabled,
11244
+ placeholder: "Key"
11245
+ }
11246
+ ) }) });
11247
+ }
11248
+ }
11249
+ ),
11250
+ /* @__PURE__ */ jsx(
11251
+ Form$2.Field,
11252
+ {
11253
+ control: form.control,
11254
+ name: `metadata.${index}.value`,
11255
+ render: ({ field: { value, ...field2 } }) => {
11256
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11257
+ GridInput,
11258
+ {
11259
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11260
+ ...field2,
11261
+ value: isDisabled ? placeholder : value,
11262
+ disabled: isDisabled,
11263
+ placeholder: "Value"
11264
+ }
11265
+ ) }) });
11266
+ }
11267
+ }
11268
+ )
11269
+ ]
11270
+ }
11271
+ ),
11272
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11273
+ /* @__PURE__ */ jsx(
11274
+ DropdownMenu.Trigger,
11275
+ {
11276
+ className: clx(
11277
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11278
+ {
11279
+ hidden: isDisabled
11280
+ }
11281
+ ),
11282
+ disabled: isDisabled,
11283
+ asChild: true,
11284
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11285
+ }
11286
+ ),
11287
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11288
+ /* @__PURE__ */ jsxs(
11289
+ DropdownMenu.Item,
11290
+ {
11291
+ className: "gap-x-2",
11292
+ onClick: () => insertRow(index, "above"),
11293
+ children: [
11294
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11295
+ "Insert row above"
11296
+ ]
11297
+ }
11298
+ ),
11299
+ /* @__PURE__ */ jsxs(
11300
+ DropdownMenu.Item,
11301
+ {
11302
+ className: "gap-x-2",
11303
+ onClick: () => insertRow(index, "below"),
11304
+ children: [
11305
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11306
+ "Insert row below"
11307
+ ]
11308
+ }
11309
+ ),
11310
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11311
+ /* @__PURE__ */ jsxs(
11312
+ DropdownMenu.Item,
11313
+ {
11314
+ className: "gap-x-2",
11315
+ onClick: () => deleteRow(index),
11316
+ children: [
11317
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11318
+ "Delete row"
11319
+ ]
11320
+ }
11321
+ )
11322
+ ] })
11323
+ ] })
11324
+ ] })
11325
+ },
11326
+ field.id
11327
+ );
11328
+ })
11329
+ ] }),
11330
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11331
+ ] }),
11332
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11333
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11494
11334
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11495
11335
  ] }) })
11496
11336
  ]
11497
11337
  }
11498
11338
  ) });
11499
11339
  };
11500
- const SalesChannelField = ({ control, order }) => {
11501
- const salesChannels = useComboboxData({
11502
- queryFn: async (params) => {
11503
- return await sdk.admin.salesChannel.list(params);
11504
- },
11505
- queryKey: ["sales-channels"],
11506
- getOptions: (data) => {
11507
- return data.sales_channels.map((salesChannel) => ({
11508
- label: salesChannel.name,
11509
- value: salesChannel.id
11510
- }));
11511
- },
11512
- defaultValue: order.sales_channel_id || void 0
11513
- });
11340
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11514
11341
  return /* @__PURE__ */ jsx(
11515
- Form$2.Field,
11342
+ "input",
11516
11343
  {
11517
- control,
11518
- name: "sales_channel_id",
11519
- render: ({ field }) => {
11520
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11521
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11522
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11523
- Combobox,
11524
- {
11525
- options: salesChannels.options,
11526
- fetchNextPage: salesChannels.fetchNextPage,
11527
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11528
- searchValue: salesChannels.searchValue,
11529
- onSearchValueChange: salesChannels.onSearchValueChange,
11530
- placeholder: "Select sales channel",
11531
- ...field
11532
- }
11533
- ) }),
11534
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11535
- ] });
11536
- }
11344
+ ref,
11345
+ ...props,
11346
+ autoComplete: "off",
11347
+ className: clx(
11348
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11349
+ className
11350
+ )
11537
11351
  }
11538
11352
  );
11539
- };
11540
- const schema$2 = objectType({
11541
- sales_channel_id: stringType().min(1)
11542
11353
  });
11543
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11544
- const Shipping = () => {
11545
- var _a;
11354
+ GridInput.displayName = "MetadataForm.GridInput";
11355
+ const PlaceholderInner = () => {
11356
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11357
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11358
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11359
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11360
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11361
+ ] }) })
11362
+ ] });
11363
+ };
11364
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11365
+ function getDefaultValues(metadata) {
11366
+ if (!metadata || !Object.keys(metadata).length) {
11367
+ return [
11368
+ {
11369
+ key: "",
11370
+ value: "",
11371
+ disabled: false
11372
+ }
11373
+ ];
11374
+ }
11375
+ return Object.entries(metadata).map(([key, value]) => {
11376
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11377
+ return {
11378
+ key,
11379
+ value,
11380
+ disabled: true
11381
+ };
11382
+ }
11383
+ let stringValue = value;
11384
+ if (typeof value !== "string") {
11385
+ stringValue = JSON.stringify(value);
11386
+ }
11387
+ return {
11388
+ key,
11389
+ value: stringValue,
11390
+ original_key: key
11391
+ };
11392
+ });
11393
+ }
11394
+ function parseValues(values) {
11395
+ const metadata = values.metadata;
11396
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11397
+ if (isEmpty) {
11398
+ return null;
11399
+ }
11400
+ const update = {};
11401
+ metadata.forEach((field) => {
11402
+ let key = field.key;
11403
+ let value = field.value;
11404
+ const disabled = field.disabled;
11405
+ if (!key || !value) {
11406
+ return;
11407
+ }
11408
+ if (disabled) {
11409
+ update[key] = value;
11410
+ return;
11411
+ }
11412
+ key = key.trim();
11413
+ value = value.trim();
11414
+ if (value === "true") {
11415
+ update[key] = true;
11416
+ } else if (value === "false") {
11417
+ update[key] = false;
11418
+ } else {
11419
+ const parsedNumber = parseFloat(value);
11420
+ if (!isNaN(parsedNumber)) {
11421
+ update[key] = parsedNumber;
11422
+ } else {
11423
+ update[key] = value;
11424
+ }
11425
+ }
11426
+ });
11427
+ return update;
11428
+ }
11429
+ function getHasUneditableRows(metadata) {
11430
+ if (!metadata) {
11431
+ return false;
11432
+ }
11433
+ return Object.values(metadata).some(
11434
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11435
+ );
11436
+ }
11437
+ const ShippingAddress = () => {
11546
11438
  const { id } = useParams();
11547
11439
  const { order, isPending, isError, error } = useOrder(id, {
11548
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11440
+ fields: "+shipping_address"
11549
11441
  });
11550
- const {
11551
- order: preview,
11552
- isPending: isPreviewPending,
11553
- isError: isPreviewError,
11554
- error: previewError
11555
- } = useOrderPreview(id);
11556
- useInitiateOrderEdit({ preview });
11557
- const { onCancel } = useCancelOrderEdit({ preview });
11558
11442
  if (isError) {
11559
11443
  throw error;
11560
11444
  }
11561
- if (isPreviewError) {
11562
- throw previewError;
11563
- }
11564
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11565
- const isReady = preview && !isPreviewPending && order && !isPending;
11566
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11567
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11568
- /* @__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: [
11569
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11570
- /* @__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." }) })
11571
- ] }) }) }),
11572
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11573
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11574
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11575
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11576
- ] }) });
11445
+ const isReady = !isPending && !!order;
11446
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11447
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11448
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11449
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11450
+ ] }),
11451
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11452
+ ] });
11577
11453
  };
11578
- const ShippingForm = ({ preview, order }) => {
11579
- var _a;
11580
- const { setIsOpen } = useStackedModal();
11581
- const [isSubmitting, setIsSubmitting] = useState(false);
11582
- const [data, setData] = useState(null);
11583
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11584
- const { shipping_options } = useShippingOptions(
11585
- {
11586
- id: appliedShippingOptionIds,
11587
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11454
+ const ShippingAddressForm = ({ order }) => {
11455
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11456
+ const form = useForm({
11457
+ defaultValues: {
11458
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11459
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11460
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11461
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11462
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11463
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11464
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11465
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11466
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11467
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11588
11468
  },
11589
- {
11590
- enabled: appliedShippingOptionIds.length > 0
11591
- }
11592
- );
11593
- const uniqueShippingProfiles = useMemo(() => {
11594
- const profiles = /* @__PURE__ */ new Map();
11595
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11596
- profiles.set(profile.id, profile);
11597
- });
11598
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11599
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11600
- });
11601
- return Array.from(profiles.values());
11602
- }, [order.items, shipping_options]);
11469
+ resolver: zodResolver(schema$2)
11470
+ });
11471
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11603
11472
  const { handleSuccess } = useRouteModal();
11604
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11605
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11606
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11607
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11608
- const onSubmit = async () => {
11609
- setIsSubmitting(true);
11610
- let requestSucceeded = false;
11611
- await requestOrderEdit(void 0, {
11612
- onError: (e) => {
11613
- toast.error(`Failed to request order edit: ${e.message}`);
11614
- },
11615
- onSuccess: () => {
11616
- requestSucceeded = true;
11617
- }
11618
- });
11619
- if (!requestSucceeded) {
11620
- setIsSubmitting(false);
11621
- return;
11622
- }
11623
- await confirmOrderEdit(void 0, {
11624
- onError: (e) => {
11625
- toast.error(`Failed to confirm order edit: ${e.message}`);
11626
- },
11627
- onSuccess: () => {
11628
- handleSuccess();
11473
+ const onSubmit = form.handleSubmit(async (data) => {
11474
+ await mutateAsync(
11475
+ {
11476
+ shipping_address: {
11477
+ first_name: data.first_name,
11478
+ last_name: data.last_name,
11479
+ company: data.company,
11480
+ address_1: data.address_1,
11481
+ address_2: data.address_2,
11482
+ city: data.city,
11483
+ province: data.province,
11484
+ country_code: data.country_code,
11485
+ postal_code: data.postal_code,
11486
+ phone: data.phone
11487
+ }
11629
11488
  },
11630
- onSettled: () => {
11631
- setIsSubmitting(false);
11632
- }
11633
- });
11634
- };
11635
- const onKeydown = useCallback(
11636
- (e) => {
11637
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11638
- if (data || isSubmitting) {
11639
- return;
11489
+ {
11490
+ onSuccess: () => {
11491
+ handleSuccess();
11492
+ },
11493
+ onError: (error) => {
11494
+ toast.error(error.message);
11640
11495
  }
11641
- onSubmit();
11642
11496
  }
11643
- },
11644
- [data, isSubmitting, onSubmit]
11645
- );
11646
- useEffect(() => {
11647
- document.addEventListener("keydown", onKeydown);
11648
- return () => {
11649
- document.removeEventListener("keydown", onKeydown);
11650
- };
11651
- }, [onKeydown]);
11652
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11653
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11654
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11655
- /* @__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: [
11656
- /* @__PURE__ */ jsxs("div", { children: [
11657
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11658
- /* @__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." }) })
11659
- ] }),
11660
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11661
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11662
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11497
+ );
11498
+ });
11499
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11500
+ KeyboundForm,
11501
+ {
11502
+ className: "flex flex-1 flex-col overflow-hidden",
11503
+ onSubmit,
11504
+ children: [
11505
+ /* @__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: [
11506
+ /* @__PURE__ */ jsx(
11507
+ Form$2.Field,
11508
+ {
11509
+ control: form.control,
11510
+ name: "country_code",
11511
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11512
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11513
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11514
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11515
+ ] })
11516
+ }
11517
+ ),
11518
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11663
11519
  /* @__PURE__ */ jsx(
11664
- Text,
11520
+ Form$2.Field,
11665
11521
  {
11666
- size: "xsmall",
11667
- weight: "plus",
11668
- className: "text-ui-fg-muted",
11669
- children: "Shipping profile"
11522
+ control: form.control,
11523
+ name: "first_name",
11524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11528
+ ] })
11670
11529
  }
11671
11530
  ),
11672
11531
  /* @__PURE__ */ jsx(
11673
- Text,
11532
+ Form$2.Field,
11674
11533
  {
11675
- size: "xsmall",
11676
- weight: "plus",
11677
- className: "text-ui-fg-muted",
11678
- children: "Action"
11534
+ control: form.control,
11535
+ name: "last_name",
11536
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11537
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11538
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11539
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11540
+ ] })
11679
11541
  }
11680
11542
  )
11681
11543
  ] }),
11682
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11683
- var _a2, _b, _c, _d, _e, _f, _g;
11684
- const items = getItemsWithShippingProfile(
11685
- profile.id,
11686
- order.items
11687
- );
11688
- const hasItems = items.length > 0;
11689
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11690
- (option) => option.shipping_profile_id === profile.id
11691
- );
11692
- const shippingMethod = preview.shipping_methods.find(
11693
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11694
- );
11695
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11696
- (action) => action.action === "SHIPPING_ADD"
11697
- );
11698
- return /* @__PURE__ */ jsxs(
11699
- Accordion.Item,
11544
+ /* @__PURE__ */ jsx(
11545
+ Form$2.Field,
11546
+ {
11547
+ control: form.control,
11548
+ name: "company",
11549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11550
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11553
+ ] })
11554
+ }
11555
+ ),
11556
+ /* @__PURE__ */ jsx(
11557
+ Form$2.Field,
11558
+ {
11559
+ control: form.control,
11560
+ name: "address_1",
11561
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11562
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11563
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11564
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11565
+ ] })
11566
+ }
11567
+ ),
11568
+ /* @__PURE__ */ jsx(
11569
+ Form$2.Field,
11570
+ {
11571
+ control: form.control,
11572
+ name: "address_2",
11573
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11574
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11575
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11576
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11577
+ ] })
11578
+ }
11579
+ ),
11580
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11581
+ /* @__PURE__ */ jsx(
11582
+ Form$2.Field,
11700
11583
  {
11701
- value: profile.id,
11702
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11703
- children: [
11704
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11705
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11706
- /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11707
- IconButton,
11708
- {
11709
- size: "2xsmall",
11710
- variant: "transparent",
11711
- className: "group/trigger",
11712
- disabled: !hasItems,
11713
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11714
- }
11715
- ) }),
11716
- !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11717
- /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11718
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11719
- /* @__PURE__ */ jsx(
11720
- Text,
11721
- {
11722
- size: "small",
11723
- weight: "plus",
11724
- leading: "compact",
11725
- children: profile.name
11726
- }
11727
- ),
11728
- /* @__PURE__ */ jsxs(
11729
- Text,
11730
- {
11731
- size: "small",
11732
- leading: "compact",
11733
- className: "text-ui-fg-subtle",
11734
- children: [
11735
- items.length,
11736
- " ",
11737
- pluralize(items.length, "items", "item")
11738
- ]
11739
- }
11740
- )
11741
- ] })
11742
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11743
- /* @__PURE__ */ jsx(
11744
- Tooltip,
11745
- {
11746
- content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11747
- var _a3, _b2, _c2;
11748
- return /* @__PURE__ */ jsx(
11749
- "li",
11750
- {
11751
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11752
- },
11753
- item.id
11754
- );
11755
- }) }),
11756
- children: /* @__PURE__ */ jsxs(
11757
- Badge,
11758
- {
11759
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11760
- size: "xsmall",
11761
- children: [
11762
- /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11763
- /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11764
- items.reduce(
11765
- (acc, item) => acc + item.quantity,
11766
- 0
11767
- ),
11768
- "x",
11769
- " ",
11770
- pluralize(items.length, "items", "item")
11771
- ] })
11772
- ]
11773
- }
11774
- )
11775
- }
11776
- ),
11777
- /* @__PURE__ */ jsx(
11778
- Tooltip,
11779
- {
11780
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11781
- children: /* @__PURE__ */ jsxs(
11782
- Badge,
11783
- {
11784
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11785
- size: "xsmall",
11786
- children: [
11787
- /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11788
- /* @__PURE__ */ jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11789
- ]
11790
- }
11791
- )
11792
- }
11793
- ),
11794
- /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11795
- Badge,
11796
- {
11797
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11798
- size: "xsmall",
11799
- children: [
11800
- /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11801
- /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11802
- ]
11803
- }
11804
- ) })
11805
- ] })
11806
- ] }),
11807
- shippingOption ? /* @__PURE__ */ jsx(
11808
- ActionMenu,
11809
- {
11810
- groups: [
11811
- {
11812
- actions: [
11813
- hasItems ? {
11814
- label: "Edit shipping option",
11815
- icon: /* @__PURE__ */ jsx(Channels, {}),
11816
- onClick: () => {
11817
- setIsOpen(
11818
- STACKED_FOCUS_MODAL_ID,
11819
- true
11820
- );
11821
- setData({
11822
- shippingProfileId: profile.id,
11823
- shippingOption,
11824
- shippingMethod
11825
- });
11826
- }
11827
- } : void 0,
11828
- {
11829
- label: "Remove shipping option",
11830
- icon: /* @__PURE__ */ jsx(Trash, {}),
11831
- onClick: () => {
11832
- if (shippingMethod) {
11833
- if (addShippingMethodAction) {
11834
- removeActionShippingMethod(
11835
- addShippingMethodAction.id
11836
- );
11837
- } else {
11838
- removeShippingMethod(
11839
- shippingMethod.id
11840
- );
11841
- }
11842
- }
11843
- }
11844
- }
11845
- ].filter(Boolean)
11846
- }
11847
- ]
11848
- }
11849
- ) : /* @__PURE__ */ jsx(
11850
- StackedModalTrigger,
11851
- {
11852
- shippingProfileId: profile.id,
11853
- shippingOption,
11854
- shippingMethod,
11855
- setData,
11856
- children: "Add shipping option"
11857
- }
11858
- )
11859
- ] }),
11860
- /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11861
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11862
- items.map((item, idx) => {
11863
- var _a3, _b2, _c2, _d2, _e2;
11864
- return /* @__PURE__ */ jsxs("div", { children: [
11865
- /* @__PURE__ */ jsxs(
11866
- "div",
11867
- {
11868
- className: "px-3 flex items-center gap-x-3",
11869
- children: [
11870
- /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11871
- Divider,
11872
- {
11873
- variant: "dashed",
11874
- orientation: "vertical"
11875
- }
11876
- ) }),
11877
- /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11878
- /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11879
- Text,
11880
- {
11881
- size: "small",
11882
- leading: "compact",
11883
- className: "text-ui-fg-subtle",
11884
- children: [
11885
- item.quantity,
11886
- "x"
11887
- ]
11888
- }
11889
- ) }),
11890
- /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
11891
- /* @__PURE__ */ jsxs("div", { children: [
11892
- /* @__PURE__ */ jsxs(
11893
- Text,
11894
- {
11895
- size: "small",
11896
- leading: "compact",
11897
- weight: "plus",
11898
- children: [
11899
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11900
- " (",
11901
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11902
- ")"
11903
- ]
11904
- }
11905
- ),
11906
- /* @__PURE__ */ jsx(
11907
- Text,
11908
- {
11909
- size: "small",
11910
- leading: "compact",
11911
- className: "text-ui-fg-subtle",
11912
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11913
- }
11914
- )
11915
- ] })
11916
- ] })
11917
- ]
11918
- },
11919
- item.id
11920
- ),
11921
- idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11922
- ] }, item.id);
11923
- })
11924
- ] })
11925
- ]
11926
- },
11927
- profile.id
11928
- );
11929
- }) })
11930
- ] }) })
11931
- ] }) }),
11932
- /* @__PURE__ */ jsx(
11933
- StackedFocusModal,
11934
- {
11935
- id: STACKED_FOCUS_MODAL_ID,
11936
- onOpenChangeCallback: (open) => {
11937
- if (!open) {
11938
- setData(null);
11584
+ control: form.control,
11585
+ name: "postal_code",
11586
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11587
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11588
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11589
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11590
+ ] })
11591
+ }
11592
+ ),
11593
+ /* @__PURE__ */ jsx(
11594
+ Form$2.Field,
11595
+ {
11596
+ control: form.control,
11597
+ name: "city",
11598
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11599
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11600
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11601
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11602
+ ] })
11603
+ }
11604
+ )
11605
+ ] }),
11606
+ /* @__PURE__ */ jsx(
11607
+ Form$2.Field,
11608
+ {
11609
+ control: form.control,
11610
+ name: "province",
11611
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11612
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11613
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11614
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11615
+ ] })
11939
11616
  }
11940
- return open;
11941
- },
11942
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11943
- }
11944
- )
11617
+ ),
11618
+ /* @__PURE__ */ jsx(
11619
+ Form$2.Field,
11620
+ {
11621
+ control: form.control,
11622
+ name: "phone",
11623
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11624
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11625
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11626
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11627
+ ] })
11628
+ }
11629
+ )
11630
+ ] }) }),
11631
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11632
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11633
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11634
+ ] }) })
11635
+ ]
11636
+ }
11637
+ ) });
11638
+ };
11639
+ const schema$2 = addressSchema;
11640
+ const TransferOwnership = () => {
11641
+ const { id } = useParams();
11642
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11643
+ fields: "id,customer_id,customer.*"
11644
+ });
11645
+ if (isError) {
11646
+ throw error;
11647
+ }
11648
+ const isReady = !isPending && !!draft_order;
11649
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11650
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11651
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11652
+ /* @__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" }) })
11945
11653
  ] }),
11946
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11947
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11948
- /* @__PURE__ */ jsx(
11949
- Button,
11950
- {
11951
- size: "small",
11952
- type: "button",
11953
- isLoading: isSubmitting,
11954
- onClick: onSubmit,
11955
- children: "Save"
11956
- }
11957
- )
11958
- ] }) })
11654
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11959
11655
  ] });
11960
11656
  };
11961
- const StackedModalTrigger = ({
11962
- shippingProfileId,
11963
- shippingOption,
11964
- shippingMethod,
11965
- setData,
11966
- children
11967
- }) => {
11968
- const { setIsOpen, getIsOpen } = useStackedModal();
11969
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11970
- const onToggle = () => {
11971
- if (isOpen) {
11972
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11973
- setData(null);
11974
- } else {
11975
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11976
- setData({
11977
- shippingProfileId,
11978
- shippingOption,
11979
- shippingMethod
11980
- });
11981
- }
11982
- };
11983
- return /* @__PURE__ */ jsx(
11984
- Button,
11985
- {
11986
- size: "small",
11987
- variant: "secondary",
11988
- onClick: onToggle,
11989
- className: "text-ui-fg-primary shrink-0",
11990
- children
11991
- }
11992
- );
11993
- };
11994
- const ShippingProfileForm = ({
11995
- data,
11996
- order,
11997
- preview
11998
- }) => {
11999
- var _a, _b, _c, _d, _e, _f;
12000
- const { setIsOpen } = useStackedModal();
11657
+ const TransferOwnershipForm = ({ order }) => {
11658
+ var _a, _b;
12001
11659
  const form = useForm({
12002
- resolver: zodResolver(shippingMethodSchema),
12003
11660
  defaultValues: {
12004
- 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,
12005
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12006
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12007
- }
11661
+ customer_id: order.customer_id || ""
11662
+ },
11663
+ resolver: zodResolver(schema$1)
12008
11664
  });
12009
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12010
- const {
12011
- mutateAsync: updateShippingMethod,
12012
- isPending: isUpdatingShippingMethod
12013
- } = useDraftOrderUpdateShippingMethod(order.id);
12014
- const onSubmit = form.handleSubmit(async (values) => {
12015
- if (isEqual(values, form.formState.defaultValues)) {
12016
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12017
- return;
12018
- }
12019
- if (data.shippingMethod) {
12020
- await updateShippingMethod(
12021
- {
12022
- method_id: data.shippingMethod.id,
12023
- shipping_option_id: values.shipping_option_id,
12024
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12025
- },
12026
- {
12027
- onError: (e) => {
12028
- toast.error(e.message);
12029
- },
12030
- onSuccess: () => {
12031
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12032
- }
12033
- }
12034
- );
12035
- return;
12036
- }
12037
- await addShippingMethod(
12038
- {
12039
- shipping_option_id: values.shipping_option_id,
12040
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12041
- },
11665
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11666
+ const { handleSuccess } = useRouteModal();
11667
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11668
+ const currentCustomer = order.customer ? {
11669
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11670
+ value: order.customer.id
11671
+ } : null;
11672
+ const onSubmit = form.handleSubmit(async (data) => {
11673
+ await mutateAsync(
11674
+ { customer_id: data.customer_id },
12042
11675
  {
12043
- onError: (e) => {
12044
- toast.error(e.message);
12045
- },
12046
11676
  onSuccess: () => {
12047
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11677
+ toast.success("Customer updated");
11678
+ handleSuccess();
11679
+ },
11680
+ onError: (error) => {
11681
+ toast.error(error.message);
12048
11682
  }
12049
11683
  }
12050
11684
  );
12051
11685
  });
12052
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11686
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12053
11687
  KeyboundForm,
12054
11688
  {
12055
- className: "flex h-full flex-col overflow-hidden",
11689
+ className: "flex flex-1 flex-col overflow-hidden",
12056
11690
  onSubmit,
12057
11691
  children: [
12058
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12059
- /* @__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: [
12060
- /* @__PURE__ */ jsxs("div", { children: [
12061
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12062
- /* @__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." }) })
11692
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11693
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11694
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11695
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11696
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11697
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11698
+ ] }),
11699
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11700
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11701
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11702
+ ] })
12063
11703
  ] }),
12064
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12065
- /* @__PURE__ */ jsx(
12066
- LocationField,
12067
- {
12068
- control: form.control,
12069
- setValue: form.setValue
12070
- }
12071
- ),
12072
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12073
- /* @__PURE__ */ jsx(
12074
- ShippingOptionField,
12075
- {
12076
- shippingProfileId: data.shippingProfileId,
12077
- preview,
12078
- control: form.control
12079
- }
12080
- ),
12081
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12082
11704
  /* @__PURE__ */ jsx(
12083
- CustomAmountField,
11705
+ CustomerField,
12084
11706
  {
12085
11707
  control: form.control,
12086
- currencyCode: order.currency_code
12087
- }
12088
- ),
12089
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12090
- /* @__PURE__ */ jsx(
12091
- ItemsPreview,
12092
- {
12093
- order,
12094
- shippingProfileId: data.shippingProfileId
12095
- }
12096
- )
12097
- ] }) }) }),
12098
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12099
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12100
- /* @__PURE__ */ jsx(
12101
- Button,
12102
- {
12103
- size: "small",
12104
- type: "submit",
12105
- isLoading: isPending || isUpdatingShippingMethod,
12106
- children: data.shippingMethod ? "Update" : "Add"
11708
+ currentCustomerId: order.customer_id
12107
11709
  }
12108
11710
  )
11711
+ ] }),
11712
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11713
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11714
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12109
11715
  ] }) })
12110
11716
  ]
12111
11717
  }
12112
- ) }) });
12113
- };
12114
- const shippingMethodSchema = objectType({
12115
- location_id: stringType(),
12116
- shipping_option_id: stringType(),
12117
- custom_amount: unionType([numberType(), stringType()]).optional()
12118
- });
12119
- const ItemsPreview = ({ order, shippingProfileId }) => {
12120
- const matches = order.items.filter(
12121
- (item) => {
12122
- var _a, _b, _c;
12123
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12124
- }
12125
- );
12126
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12127
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12128
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12129
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12130
- ] }) }),
12131
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12132
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12133
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12134
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12135
- ] }),
12136
- /* @__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(
12137
- "div",
12138
- {
12139
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12140
- children: [
12141
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12142
- /* @__PURE__ */ jsx(
12143
- Thumbnail,
12144
- {
12145
- thumbnail: item.thumbnail,
12146
- alt: item.product_title ?? void 0
12147
- }
12148
- ),
12149
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12150
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12151
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12152
- /* @__PURE__ */ jsxs(
12153
- Text,
12154
- {
12155
- size: "small",
12156
- leading: "compact",
12157
- className: "text-ui-fg-subtle",
12158
- children: [
12159
- "(",
12160
- item.variant_title,
12161
- ")"
12162
- ]
12163
- }
12164
- )
12165
- ] }),
12166
- /* @__PURE__ */ jsx(
12167
- Text,
12168
- {
12169
- size: "small",
12170
- leading: "compact",
12171
- className: "text-ui-fg-subtle",
12172
- children: item.variant_sku
12173
- }
12174
- )
12175
- ] })
12176
- ] }),
12177
- /* @__PURE__ */ jsxs(
12178
- Text,
12179
- {
12180
- size: "small",
12181
- leading: "compact",
12182
- className: "text-ui-fg-subtle",
12183
- children: [
12184
- item.quantity,
12185
- "x"
12186
- ]
12187
- }
12188
- )
12189
- ]
12190
- },
12191
- item.id
12192
- )) : /* @__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: [
12193
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12194
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12195
- 'No items found for "',
12196
- query,
12197
- '".'
12198
- ] })
12199
- ] }) })
12200
- ] })
12201
- ] });
11718
+ ) });
12202
11719
  };
12203
- const LocationField = ({ control, setValue }) => {
12204
- const locations = useComboboxData({
12205
- queryKey: ["locations"],
11720
+ const CustomerField = ({ control, currentCustomerId }) => {
11721
+ const customers = useComboboxData({
12206
11722
  queryFn: async (params) => {
12207
- return await sdk.admin.stockLocation.list(params);
11723
+ return await sdk.admin.customer.list({
11724
+ ...params,
11725
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11726
+ });
12208
11727
  },
11728
+ queryKey: ["customers"],
12209
11729
  getOptions: (data) => {
12210
- return data.stock_locations.map((location) => ({
12211
- label: location.name,
12212
- value: location.id
12213
- }));
11730
+ return data.customers.map((customer) => {
11731
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11732
+ return {
11733
+ label: name ? `${name} (${customer.email})` : customer.email,
11734
+ value: customer.id
11735
+ };
11736
+ });
12214
11737
  }
12215
11738
  });
12216
11739
  return /* @__PURE__ */ jsx(
12217
11740
  Form$2.Field,
12218
11741
  {
11742
+ name: "customer_id",
12219
11743
  control,
12220
- name: "location_id",
12221
- render: ({ field: { onChange, ...field } }) => {
12222
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12223
- /* @__PURE__ */ jsxs("div", { children: [
12224
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12225
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12226
- ] }),
12227
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12228
- Combobox,
12229
- {
12230
- options: locations.options,
12231
- fetchNextPage: locations.fetchNextPage,
12232
- isFetchingNextPage: locations.isFetchingNextPage,
12233
- searchValue: locations.searchValue,
12234
- onSearchValueChange: locations.onSearchValueChange,
12235
- placeholder: "Select location",
12236
- onChange: (value) => {
12237
- setValue("shipping_option_id", "", {
12238
- shouldDirty: true,
12239
- shouldTouch: true
12240
- });
12241
- onChange(value);
12242
- },
12243
- ...field
12244
- }
12245
- ) })
12246
- ] }) });
12247
- }
12248
- }
12249
- );
12250
- };
12251
- const ShippingOptionField = ({
12252
- shippingProfileId,
12253
- preview,
12254
- control
12255
- }) => {
12256
- var _a;
12257
- const locationId = useWatch({ control, name: "location_id" });
12258
- const shippingOptions = useComboboxData({
12259
- queryKey: ["shipping_options", locationId, shippingProfileId],
12260
- queryFn: async (params) => {
12261
- return await sdk.admin.shippingOption.list({
12262
- ...params,
12263
- stock_location_id: locationId,
12264
- shipping_profile_id: shippingProfileId
12265
- });
12266
- },
12267
- getOptions: (data) => {
12268
- return data.shipping_options.map((option) => {
12269
- var _a2;
12270
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12271
- (r) => r.attribute === "is_return" && r.value === "true"
12272
- )) {
12273
- return void 0;
12274
- }
12275
- return {
12276
- label: option.name,
12277
- value: option.id
12278
- };
12279
- }).filter(Boolean);
12280
- },
12281
- enabled: !!locationId && !!shippingProfileId,
12282
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12283
- });
12284
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12285
- return /* @__PURE__ */ jsx(
12286
- Form$2.Field,
12287
- {
12288
- control,
12289
- name: "shipping_option_id",
12290
- render: ({ field }) => {
12291
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12292
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12293
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12294
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12295
- ] }),
12296
- /* @__PURE__ */ jsx(
12297
- ConditionalTooltip,
12298
- {
12299
- content: tooltipContent,
12300
- showTooltip: !locationId || !shippingProfileId,
12301
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12302
- Combobox,
12303
- {
12304
- options: shippingOptions.options,
12305
- fetchNextPage: shippingOptions.fetchNextPage,
12306
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12307
- searchValue: shippingOptions.searchValue,
12308
- onSearchValueChange: shippingOptions.onSearchValueChange,
12309
- placeholder: "Select shipping option",
12310
- ...field,
12311
- disabled: !locationId || !shippingProfileId
12312
- }
12313
- ) }) })
12314
- }
12315
- )
12316
- ] }) });
12317
- }
12318
- }
12319
- );
12320
- };
12321
- const CustomAmountField = ({
12322
- control,
12323
- currencyCode
12324
- }) => {
12325
- return /* @__PURE__ */ jsx(
12326
- Form$2.Field,
12327
- {
12328
- control,
12329
- name: "custom_amount",
12330
- render: ({ field: { onChange, ...field } }) => {
12331
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12332
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12333
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12334
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12335
- ] }),
12336
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12337
- CurrencyInput,
12338
- {
12339
- ...field,
12340
- onValueChange: (value) => onChange(value),
12341
- symbol: getNativeSymbol(currencyCode),
12342
- code: currencyCode
12343
- }
12344
- ) })
12345
- ] });
12346
- }
11744
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11745
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11746
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11747
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11748
+ ] }),
11749
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11750
+ Combobox,
11751
+ {
11752
+ options: customers.options,
11753
+ fetchNextPage: customers.fetchNextPage,
11754
+ isFetchingNextPage: customers.isFetchingNextPage,
11755
+ searchValue: customers.searchValue,
11756
+ onSearchValueChange: customers.onSearchValueChange,
11757
+ placeholder: "Select customer",
11758
+ ...field
11759
+ }
11760
+ ) }),
11761
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11762
+ ] })
12347
11763
  }
12348
11764
  );
12349
11765
  };
12350
- const ShippingAddress = () => {
12351
- const { id } = useParams();
12352
- const { order, isPending, isError, error } = useOrder(id, {
12353
- fields: "+shipping_address"
12354
- });
12355
- if (isError) {
12356
- throw error;
12357
- }
12358
- const isReady = !isPending && !!order;
12359
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12360
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12361
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12362
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12363
- ] }),
12364
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12365
- ] });
12366
- };
12367
- const ShippingAddressForm = ({ order }) => {
12368
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12369
- const form = useForm({
12370
- defaultValues: {
12371
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12372
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12373
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12374
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12375
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12376
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12377
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12378
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12379
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12380
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12381
- },
12382
- resolver: zodResolver(schema$1)
12383
- });
12384
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12385
- const { handleSuccess } = useRouteModal();
12386
- const onSubmit = form.handleSubmit(async (data) => {
12387
- await mutateAsync(
12388
- {
12389
- shipping_address: {
12390
- first_name: data.first_name,
12391
- last_name: data.last_name,
12392
- company: data.company,
12393
- address_1: data.address_1,
12394
- address_2: data.address_2,
12395
- city: data.city,
12396
- province: data.province,
12397
- country_code: data.country_code,
12398
- postal_code: data.postal_code,
12399
- phone: data.phone
12400
- }
12401
- },
12402
- {
12403
- onSuccess: () => {
12404
- handleSuccess();
12405
- },
12406
- onError: (error) => {
12407
- toast.error(error.message);
12408
- }
12409
- }
12410
- );
12411
- });
12412
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12413
- KeyboundForm,
11766
+ const Illustration = () => {
11767
+ return /* @__PURE__ */ jsxs(
11768
+ "svg",
12414
11769
  {
12415
- className: "flex flex-1 flex-col overflow-hidden",
12416
- onSubmit,
12417
- children: [
12418
- /* @__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: [
12419
- /* @__PURE__ */ jsx(
12420
- Form$2.Field,
12421
- {
12422
- control: form.control,
12423
- name: "country_code",
12424
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12425
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12426
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12427
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12428
- ] })
12429
- }
12430
- ),
12431
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12432
- /* @__PURE__ */ jsx(
12433
- Form$2.Field,
12434
- {
12435
- control: form.control,
12436
- name: "first_name",
12437
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12439
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12440
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
- ] })
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsx(
12445
- Form$2.Field,
12446
- {
12447
- control: form.control,
12448
- name: "last_name",
12449
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12450
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12451
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12452
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12453
- ] })
12454
- }
12455
- )
12456
- ] }),
12457
- /* @__PURE__ */ jsx(
12458
- Form$2.Field,
12459
- {
12460
- control: form.control,
12461
- name: "company",
12462
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12464
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
- ] })
12467
- }
12468
- ),
12469
- /* @__PURE__ */ jsx(
12470
- Form$2.Field,
12471
- {
12472
- control: form.control,
12473
- name: "address_1",
12474
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12475
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12476
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12477
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12478
- ] })
12479
- }
12480
- ),
12481
- /* @__PURE__ */ jsx(
12482
- Form$2.Field,
12483
- {
12484
- control: form.control,
12485
- name: "address_2",
12486
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12487
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12488
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12489
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12490
- ] })
12491
- }
12492
- ),
12493
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12494
- /* @__PURE__ */ jsx(
12495
- Form$2.Field,
12496
- {
12497
- control: form.control,
12498
- name: "postal_code",
12499
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12501
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
- ] })
12504
- }
12505
- ),
12506
- /* @__PURE__ */ jsx(
12507
- Form$2.Field,
12508
- {
12509
- control: form.control,
12510
- name: "city",
12511
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12512
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12513
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12514
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12515
- ] })
12516
- }
12517
- )
12518
- ] }),
12519
- /* @__PURE__ */ jsx(
12520
- Form$2.Field,
12521
- {
12522
- control: form.control,
12523
- name: "province",
12524
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12526
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
- ] })
12529
- }
12530
- ),
12531
- /* @__PURE__ */ jsx(
12532
- Form$2.Field,
12533
- {
12534
- control: form.control,
12535
- name: "phone",
12536
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12537
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12538
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12539
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12540
- ] })
12541
- }
12542
- )
12543
- ] }) }),
12544
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12545
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12546
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12547
- ] }) })
12548
- ]
12549
- }
12550
- ) });
12551
- };
12552
- const schema$1 = addressSchema;
12553
- const TransferOwnership = () => {
12554
- const { id } = useParams();
12555
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12556
- fields: "id,customer_id,customer.*"
12557
- });
12558
- if (isError) {
12559
- throw error;
12560
- }
12561
- const isReady = !isPending && !!draft_order;
12562
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12563
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12564
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12565
- /* @__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" }) })
12566
- ] }),
12567
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12568
- ] });
12569
- };
12570
- const TransferOwnershipForm = ({ order }) => {
12571
- var _a, _b;
12572
- const form = useForm({
12573
- defaultValues: {
12574
- customer_id: order.customer_id || ""
12575
- },
12576
- resolver: zodResolver(schema)
12577
- });
12578
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12579
- const { handleSuccess } = useRouteModal();
12580
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12581
- const currentCustomer = order.customer ? {
12582
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12583
- value: order.customer.id
12584
- } : null;
12585
- const onSubmit = form.handleSubmit(async (data) => {
12586
- await mutateAsync(
12587
- { customer_id: data.customer_id },
12588
- {
12589
- onSuccess: () => {
12590
- toast.success("Customer updated");
12591
- handleSuccess();
12592
- },
12593
- onError: (error) => {
12594
- toast.error(error.message);
12595
- }
12596
- }
12597
- );
12598
- });
12599
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12600
- KeyboundForm,
12601
- {
12602
- className: "flex flex-1 flex-col overflow-hidden",
12603
- onSubmit,
12604
- children: [
12605
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12606
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12607
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12608
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12609
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12610
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12611
- ] }),
12612
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12613
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12614
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12615
- ] })
12616
- ] }),
12617
- /* @__PURE__ */ jsx(
12618
- CustomerField,
12619
- {
12620
- control: form.control,
12621
- currentCustomerId: order.customer_id
12622
- }
12623
- )
12624
- ] }),
12625
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12626
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12627
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12628
- ] }) })
12629
- ]
12630
- }
12631
- ) });
12632
- };
12633
- const CustomerField = ({ control, currentCustomerId }) => {
12634
- const customers = useComboboxData({
12635
- queryFn: async (params) => {
12636
- return await sdk.admin.customer.list({
12637
- ...params,
12638
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12639
- });
12640
- },
12641
- queryKey: ["customers"],
12642
- getOptions: (data) => {
12643
- return data.customers.map((customer) => {
12644
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12645
- return {
12646
- label: name ? `${name} (${customer.email})` : customer.email,
12647
- value: customer.id
12648
- };
12649
- });
12650
- }
12651
- });
12652
- return /* @__PURE__ */ jsx(
12653
- Form$2.Field,
12654
- {
12655
- name: "customer_id",
12656
- control,
12657
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12658
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12659
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12660
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12661
- ] }),
12662
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12663
- Combobox,
12664
- {
12665
- options: customers.options,
12666
- fetchNextPage: customers.fetchNextPage,
12667
- isFetchingNextPage: customers.isFetchingNextPage,
12668
- searchValue: customers.searchValue,
12669
- onSearchValueChange: customers.onSearchValueChange,
12670
- placeholder: "Select customer",
12671
- ...field
12672
- }
12673
- ) }),
12674
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12675
- ] })
12676
- }
12677
- );
12678
- };
12679
- const Illustration = () => {
12680
- return /* @__PURE__ */ jsxs(
12681
- "svg",
12682
- {
12683
- width: "280",
12684
- height: "180",
12685
- viewBox: "0 0 280 180",
12686
- fill: "none",
12687
- xmlns: "http://www.w3.org/2000/svg",
11770
+ width: "280",
11771
+ height: "180",
11772
+ viewBox: "0 0 280 180",
11773
+ fill: "none",
11774
+ xmlns: "http://www.w3.org/2000/svg",
12688
11775
  children: [
12689
11776
  /* @__PURE__ */ jsx(
12690
11777
  "rect",
@@ -12962,69 +12049,982 @@ const Illustration = () => {
12962
12049
  strokeLinecap: "round",
12963
12050
  strokeLinejoin: "round"
12964
12051
  }
12965
- ) }),
12966
- /* @__PURE__ */ jsxs("defs", { children: [
12967
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12968
- "rect",
12052
+ ) }),
12053
+ /* @__PURE__ */ jsxs("defs", { children: [
12054
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12055
+ "rect",
12056
+ {
12057
+ width: "12",
12058
+ height: "12",
12059
+ fill: "white",
12060
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12061
+ }
12062
+ ) }),
12063
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12064
+ "rect",
12065
+ {
12066
+ width: "12",
12067
+ height: "12",
12068
+ fill: "white",
12069
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12070
+ }
12071
+ ) }),
12072
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12073
+ "rect",
12074
+ {
12075
+ width: "12",
12076
+ height: "12",
12077
+ fill: "white",
12078
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12079
+ }
12080
+ ) }),
12081
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12082
+ "rect",
12083
+ {
12084
+ width: "12",
12085
+ height: "12",
12086
+ fill: "white",
12087
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12088
+ }
12089
+ ) }),
12090
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12091
+ "rect",
12092
+ {
12093
+ width: "12",
12094
+ height: "12",
12095
+ fill: "white",
12096
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12097
+ }
12098
+ ) }),
12099
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12100
+ "rect",
12101
+ {
12102
+ width: "12",
12103
+ height: "12",
12104
+ fill: "white",
12105
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12106
+ }
12107
+ ) })
12108
+ ] })
12109
+ ]
12110
+ }
12111
+ );
12112
+ };
12113
+ const schema$1 = objectType({
12114
+ customer_id: stringType().min(1)
12115
+ });
12116
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
12117
+ const Shipping = () => {
12118
+ var _a;
12119
+ const { id } = useParams();
12120
+ const { order, isPending, isError, error } = useOrder(id, {
12121
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12122
+ });
12123
+ const {
12124
+ order: preview,
12125
+ isPending: isPreviewPending,
12126
+ isError: isPreviewError,
12127
+ error: previewError
12128
+ } = useOrderPreview(id);
12129
+ useInitiateOrderEdit({ preview });
12130
+ const { onCancel } = useCancelOrderEdit({ preview });
12131
+ if (isError) {
12132
+ throw error;
12133
+ }
12134
+ if (isPreviewError) {
12135
+ throw previewError;
12136
+ }
12137
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12138
+ const isReady = preview && !isPreviewPending && order && !isPending;
12139
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12140
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12141
+ /* @__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: [
12142
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12143
+ /* @__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." }) })
12144
+ ] }) }) }),
12145
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12146
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
12147
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12148
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12149
+ ] }) });
12150
+ };
12151
+ const ShippingForm = ({ preview, order }) => {
12152
+ var _a;
12153
+ const { setIsOpen } = useStackedModal();
12154
+ const [isSubmitting, setIsSubmitting] = useState(false);
12155
+ const [data, setData] = useState(null);
12156
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12157
+ const { shipping_options } = useShippingOptions(
12158
+ {
12159
+ id: appliedShippingOptionIds,
12160
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12161
+ },
12162
+ {
12163
+ enabled: appliedShippingOptionIds.length > 0
12164
+ }
12165
+ );
12166
+ const uniqueShippingProfiles = useMemo(() => {
12167
+ const profiles = /* @__PURE__ */ new Map();
12168
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12169
+ profiles.set(profile.id, profile);
12170
+ });
12171
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12172
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12173
+ });
12174
+ return Array.from(profiles.values());
12175
+ }, [order.items, shipping_options]);
12176
+ const { handleSuccess } = useRouteModal();
12177
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12178
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12179
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12180
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12181
+ const onSubmit = async () => {
12182
+ setIsSubmitting(true);
12183
+ let requestSucceeded = false;
12184
+ await requestOrderEdit(void 0, {
12185
+ onError: (e) => {
12186
+ toast.error(`Failed to request order edit: ${e.message}`);
12187
+ },
12188
+ onSuccess: () => {
12189
+ requestSucceeded = true;
12190
+ }
12191
+ });
12192
+ if (!requestSucceeded) {
12193
+ setIsSubmitting(false);
12194
+ return;
12195
+ }
12196
+ await confirmOrderEdit(void 0, {
12197
+ onError: (e) => {
12198
+ toast.error(`Failed to confirm order edit: ${e.message}`);
12199
+ },
12200
+ onSuccess: () => {
12201
+ handleSuccess();
12202
+ },
12203
+ onSettled: () => {
12204
+ setIsSubmitting(false);
12205
+ }
12206
+ });
12207
+ };
12208
+ const onKeydown = useCallback(
12209
+ (e) => {
12210
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12211
+ if (data || isSubmitting) {
12212
+ return;
12213
+ }
12214
+ onSubmit();
12215
+ }
12216
+ },
12217
+ [data, isSubmitting, onSubmit]
12218
+ );
12219
+ useEffect(() => {
12220
+ document.addEventListener("keydown", onKeydown);
12221
+ return () => {
12222
+ document.removeEventListener("keydown", onKeydown);
12223
+ };
12224
+ }, [onKeydown]);
12225
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12226
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12227
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12228
+ /* @__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: [
12229
+ /* @__PURE__ */ jsxs("div", { children: [
12230
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12231
+ /* @__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." }) })
12232
+ ] }),
12233
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12234
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
12235
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12236
+ /* @__PURE__ */ jsx(
12237
+ Text,
12238
+ {
12239
+ size: "xsmall",
12240
+ weight: "plus",
12241
+ className: "text-ui-fg-muted",
12242
+ children: "Shipping profile"
12243
+ }
12244
+ ),
12245
+ /* @__PURE__ */ jsx(
12246
+ Text,
12247
+ {
12248
+ size: "xsmall",
12249
+ weight: "plus",
12250
+ className: "text-ui-fg-muted",
12251
+ children: "Action"
12252
+ }
12253
+ )
12254
+ ] }),
12255
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12256
+ var _a2, _b, _c, _d, _e, _f, _g;
12257
+ const items = getItemsWithShippingProfile(
12258
+ profile.id,
12259
+ order.items
12260
+ );
12261
+ const hasItems = items.length > 0;
12262
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12263
+ (option) => option.shipping_profile_id === profile.id
12264
+ );
12265
+ const shippingMethod = preview.shipping_methods.find(
12266
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12267
+ );
12268
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12269
+ (action) => action.action === "SHIPPING_ADD"
12270
+ );
12271
+ return /* @__PURE__ */ jsxs(
12272
+ Accordion.Item,
12273
+ {
12274
+ value: profile.id,
12275
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12276
+ children: [
12277
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
12278
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
12279
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
12280
+ IconButton,
12281
+ {
12282
+ size: "2xsmall",
12283
+ variant: "transparent",
12284
+ className: "group/trigger",
12285
+ disabled: !hasItems,
12286
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
12287
+ }
12288
+ ) }),
12289
+ !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12290
+ /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
12291
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
12292
+ /* @__PURE__ */ jsx(
12293
+ Text,
12294
+ {
12295
+ size: "small",
12296
+ weight: "plus",
12297
+ leading: "compact",
12298
+ children: profile.name
12299
+ }
12300
+ ),
12301
+ /* @__PURE__ */ jsxs(
12302
+ Text,
12303
+ {
12304
+ size: "small",
12305
+ leading: "compact",
12306
+ className: "text-ui-fg-subtle",
12307
+ children: [
12308
+ items.length,
12309
+ " ",
12310
+ pluralize(items.length, "items", "item")
12311
+ ]
12312
+ }
12313
+ )
12314
+ ] })
12315
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
12316
+ /* @__PURE__ */ jsx(
12317
+ Tooltip,
12318
+ {
12319
+ content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
12320
+ var _a3, _b2, _c2;
12321
+ return /* @__PURE__ */ jsx(
12322
+ "li",
12323
+ {
12324
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12325
+ },
12326
+ item.id
12327
+ );
12328
+ }) }),
12329
+ children: /* @__PURE__ */ jsxs(
12330
+ Badge,
12331
+ {
12332
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12333
+ size: "xsmall",
12334
+ children: [
12335
+ /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
12336
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
12337
+ items.reduce(
12338
+ (acc, item) => acc + item.quantity,
12339
+ 0
12340
+ ),
12341
+ "x",
12342
+ " ",
12343
+ pluralize(items.length, "items", "item")
12344
+ ] })
12345
+ ]
12346
+ }
12347
+ )
12348
+ }
12349
+ ),
12350
+ /* @__PURE__ */ jsx(
12351
+ Tooltip,
12352
+ {
12353
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12354
+ children: /* @__PURE__ */ jsxs(
12355
+ Badge,
12356
+ {
12357
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12358
+ size: "xsmall",
12359
+ children: [
12360
+ /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
12361
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12362
+ ]
12363
+ }
12364
+ )
12365
+ }
12366
+ ),
12367
+ /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
12368
+ Badge,
12369
+ {
12370
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12371
+ size: "xsmall",
12372
+ children: [
12373
+ /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
12374
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
12375
+ ]
12376
+ }
12377
+ ) })
12378
+ ] })
12379
+ ] }),
12380
+ shippingOption ? /* @__PURE__ */ jsx(
12381
+ ActionMenu,
12382
+ {
12383
+ groups: [
12384
+ {
12385
+ actions: [
12386
+ hasItems ? {
12387
+ label: "Edit shipping option",
12388
+ icon: /* @__PURE__ */ jsx(Channels, {}),
12389
+ onClick: () => {
12390
+ setIsOpen(
12391
+ STACKED_FOCUS_MODAL_ID,
12392
+ true
12393
+ );
12394
+ setData({
12395
+ shippingProfileId: profile.id,
12396
+ shippingOption,
12397
+ shippingMethod
12398
+ });
12399
+ }
12400
+ } : void 0,
12401
+ {
12402
+ label: "Remove shipping option",
12403
+ icon: /* @__PURE__ */ jsx(Trash, {}),
12404
+ onClick: () => {
12405
+ if (shippingMethod) {
12406
+ if (addShippingMethodAction) {
12407
+ removeActionShippingMethod(
12408
+ addShippingMethodAction.id
12409
+ );
12410
+ } else {
12411
+ removeShippingMethod(
12412
+ shippingMethod.id
12413
+ );
12414
+ }
12415
+ }
12416
+ }
12417
+ }
12418
+ ].filter(Boolean)
12419
+ }
12420
+ ]
12421
+ }
12422
+ ) : /* @__PURE__ */ jsx(
12423
+ StackedModalTrigger,
12424
+ {
12425
+ shippingProfileId: profile.id,
12426
+ shippingOption,
12427
+ shippingMethod,
12428
+ setData,
12429
+ children: "Add shipping option"
12430
+ }
12431
+ )
12432
+ ] }),
12433
+ /* @__PURE__ */ jsxs(Accordion.Content, { children: [
12434
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12435
+ items.map((item, idx) => {
12436
+ var _a3, _b2, _c2, _d2, _e2;
12437
+ return /* @__PURE__ */ jsxs("div", { children: [
12438
+ /* @__PURE__ */ jsxs(
12439
+ "div",
12440
+ {
12441
+ className: "px-3 flex items-center gap-x-3",
12442
+ children: [
12443
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
12444
+ Divider,
12445
+ {
12446
+ variant: "dashed",
12447
+ orientation: "vertical"
12448
+ }
12449
+ ) }),
12450
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12451
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
12452
+ Text,
12453
+ {
12454
+ size: "small",
12455
+ leading: "compact",
12456
+ className: "text-ui-fg-subtle",
12457
+ children: [
12458
+ item.quantity,
12459
+ "x"
12460
+ ]
12461
+ }
12462
+ ) }),
12463
+ /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
12464
+ /* @__PURE__ */ jsxs("div", { children: [
12465
+ /* @__PURE__ */ jsxs(
12466
+ Text,
12467
+ {
12468
+ size: "small",
12469
+ leading: "compact",
12470
+ weight: "plus",
12471
+ children: [
12472
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12473
+ " (",
12474
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12475
+ ")"
12476
+ ]
12477
+ }
12478
+ ),
12479
+ /* @__PURE__ */ jsx(
12480
+ Text,
12481
+ {
12482
+ size: "small",
12483
+ leading: "compact",
12484
+ className: "text-ui-fg-subtle",
12485
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12486
+ }
12487
+ )
12488
+ ] })
12489
+ ] })
12490
+ ]
12491
+ },
12492
+ item.id
12493
+ ),
12494
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
12495
+ ] }, item.id);
12496
+ })
12497
+ ] })
12498
+ ]
12499
+ },
12500
+ profile.id
12501
+ );
12502
+ }) })
12503
+ ] }) })
12504
+ ] }) }),
12505
+ /* @__PURE__ */ jsx(
12506
+ StackedFocusModal,
12507
+ {
12508
+ id: STACKED_FOCUS_MODAL_ID,
12509
+ onOpenChangeCallback: (open) => {
12510
+ if (!open) {
12511
+ setData(null);
12512
+ }
12513
+ return open;
12514
+ },
12515
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
12516
+ }
12517
+ )
12518
+ ] }),
12519
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12520
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12521
+ /* @__PURE__ */ jsx(
12522
+ Button,
12523
+ {
12524
+ size: "small",
12525
+ type: "button",
12526
+ isLoading: isSubmitting,
12527
+ onClick: onSubmit,
12528
+ children: "Save"
12529
+ }
12530
+ )
12531
+ ] }) })
12532
+ ] });
12533
+ };
12534
+ const StackedModalTrigger = ({
12535
+ shippingProfileId,
12536
+ shippingOption,
12537
+ shippingMethod,
12538
+ setData,
12539
+ children
12540
+ }) => {
12541
+ const { setIsOpen, getIsOpen } = useStackedModal();
12542
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12543
+ const onToggle = () => {
12544
+ if (isOpen) {
12545
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12546
+ setData(null);
12547
+ } else {
12548
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12549
+ setData({
12550
+ shippingProfileId,
12551
+ shippingOption,
12552
+ shippingMethod
12553
+ });
12554
+ }
12555
+ };
12556
+ return /* @__PURE__ */ jsx(
12557
+ Button,
12558
+ {
12559
+ size: "small",
12560
+ variant: "secondary",
12561
+ onClick: onToggle,
12562
+ className: "text-ui-fg-primary shrink-0",
12563
+ children
12564
+ }
12565
+ );
12566
+ };
12567
+ const ShippingProfileForm = ({
12568
+ data,
12569
+ order,
12570
+ preview
12571
+ }) => {
12572
+ var _a, _b, _c, _d, _e, _f;
12573
+ const { setIsOpen } = useStackedModal();
12574
+ const form = useForm({
12575
+ resolver: zodResolver(shippingMethodSchema),
12576
+ defaultValues: {
12577
+ 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,
12578
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12579
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12580
+ }
12581
+ });
12582
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12583
+ const {
12584
+ mutateAsync: updateShippingMethod,
12585
+ isPending: isUpdatingShippingMethod
12586
+ } = useDraftOrderUpdateShippingMethod(order.id);
12587
+ const onSubmit = form.handleSubmit(async (values) => {
12588
+ if (isEqual(values, form.formState.defaultValues)) {
12589
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12590
+ return;
12591
+ }
12592
+ if (data.shippingMethod) {
12593
+ await updateShippingMethod(
12594
+ {
12595
+ method_id: data.shippingMethod.id,
12596
+ shipping_option_id: values.shipping_option_id,
12597
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12598
+ },
12599
+ {
12600
+ onError: (e) => {
12601
+ toast.error(e.message);
12602
+ },
12603
+ onSuccess: () => {
12604
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12605
+ }
12606
+ }
12607
+ );
12608
+ return;
12609
+ }
12610
+ await addShippingMethod(
12611
+ {
12612
+ shipping_option_id: values.shipping_option_id,
12613
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12614
+ },
12615
+ {
12616
+ onError: (e) => {
12617
+ toast.error(e.message);
12618
+ },
12619
+ onSuccess: () => {
12620
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12621
+ }
12622
+ }
12623
+ );
12624
+ });
12625
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12626
+ KeyboundForm,
12627
+ {
12628
+ className: "flex h-full flex-col overflow-hidden",
12629
+ onSubmit,
12630
+ children: [
12631
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12632
+ /* @__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: [
12633
+ /* @__PURE__ */ jsxs("div", { children: [
12634
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12635
+ /* @__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." }) })
12636
+ ] }),
12637
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12638
+ /* @__PURE__ */ jsx(
12639
+ LocationField,
12969
12640
  {
12970
- width: "12",
12971
- height: "12",
12972
- fill: "white",
12973
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12641
+ control: form.control,
12642
+ setValue: form.setValue
12974
12643
  }
12975
- ) }),
12976
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12977
- "rect",
12644
+ ),
12645
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12646
+ /* @__PURE__ */ jsx(
12647
+ ShippingOptionField,
12978
12648
  {
12979
- width: "12",
12980
- height: "12",
12981
- fill: "white",
12982
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12649
+ shippingProfileId: data.shippingProfileId,
12650
+ preview,
12651
+ control: form.control
12983
12652
  }
12984
- ) }),
12985
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12986
- "rect",
12653
+ ),
12654
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12655
+ /* @__PURE__ */ jsx(
12656
+ CustomAmountField,
12987
12657
  {
12988
- width: "12",
12989
- height: "12",
12990
- fill: "white",
12991
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12658
+ control: form.control,
12659
+ currencyCode: order.currency_code
12992
12660
  }
12993
- ) }),
12994
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12995
- "rect",
12661
+ ),
12662
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12663
+ /* @__PURE__ */ jsx(
12664
+ ItemsPreview,
12996
12665
  {
12997
- width: "12",
12998
- height: "12",
12999
- fill: "white",
13000
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12666
+ order,
12667
+ shippingProfileId: data.shippingProfileId
12668
+ }
12669
+ )
12670
+ ] }) }) }),
12671
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12672
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12673
+ /* @__PURE__ */ jsx(
12674
+ Button,
12675
+ {
12676
+ size: "small",
12677
+ type: "submit",
12678
+ isLoading: isPending || isUpdatingShippingMethod,
12679
+ children: data.shippingMethod ? "Update" : "Add"
12680
+ }
12681
+ )
12682
+ ] }) })
12683
+ ]
12684
+ }
12685
+ ) }) });
12686
+ };
12687
+ const shippingMethodSchema = objectType({
12688
+ location_id: stringType(),
12689
+ shipping_option_id: stringType(),
12690
+ custom_amount: unionType([numberType(), stringType()]).optional()
12691
+ });
12692
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12693
+ const matches = order.items.filter(
12694
+ (item) => {
12695
+ var _a, _b, _c;
12696
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12697
+ }
12698
+ );
12699
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12700
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12701
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12702
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12703
+ ] }) }),
12704
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12705
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12706
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12707
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12708
+ ] }),
12709
+ /* @__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(
12710
+ "div",
12711
+ {
12712
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12713
+ children: [
12714
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12715
+ /* @__PURE__ */ jsx(
12716
+ Thumbnail,
12717
+ {
12718
+ thumbnail: item.thumbnail,
12719
+ alt: item.product_title ?? void 0
12720
+ }
12721
+ ),
12722
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12723
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12724
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12725
+ /* @__PURE__ */ jsxs(
12726
+ Text,
12727
+ {
12728
+ size: "small",
12729
+ leading: "compact",
12730
+ className: "text-ui-fg-subtle",
12731
+ children: [
12732
+ "(",
12733
+ item.variant_title,
12734
+ ")"
12735
+ ]
12736
+ }
12737
+ )
12738
+ ] }),
12739
+ /* @__PURE__ */ jsx(
12740
+ Text,
12741
+ {
12742
+ size: "small",
12743
+ leading: "compact",
12744
+ className: "text-ui-fg-subtle",
12745
+ children: item.variant_sku
12746
+ }
12747
+ )
12748
+ ] })
12749
+ ] }),
12750
+ /* @__PURE__ */ jsxs(
12751
+ Text,
12752
+ {
12753
+ size: "small",
12754
+ leading: "compact",
12755
+ className: "text-ui-fg-subtle",
12756
+ children: [
12757
+ item.quantity,
12758
+ "x"
12759
+ ]
12760
+ }
12761
+ )
12762
+ ]
12763
+ },
12764
+ item.id
12765
+ )) : /* @__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: [
12766
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12767
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12768
+ 'No items found for "',
12769
+ query,
12770
+ '".'
12771
+ ] })
12772
+ ] }) })
12773
+ ] })
12774
+ ] });
12775
+ };
12776
+ const LocationField = ({ control, setValue }) => {
12777
+ const locations = useComboboxData({
12778
+ queryKey: ["locations"],
12779
+ queryFn: async (params) => {
12780
+ return await sdk.admin.stockLocation.list(params);
12781
+ },
12782
+ getOptions: (data) => {
12783
+ return data.stock_locations.map((location) => ({
12784
+ label: location.name,
12785
+ value: location.id
12786
+ }));
12787
+ }
12788
+ });
12789
+ return /* @__PURE__ */ jsx(
12790
+ Form$2.Field,
12791
+ {
12792
+ control,
12793
+ name: "location_id",
12794
+ render: ({ field: { onChange, ...field } }) => {
12795
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12796
+ /* @__PURE__ */ jsxs("div", { children: [
12797
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12798
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12799
+ ] }),
12800
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12801
+ Combobox,
12802
+ {
12803
+ options: locations.options,
12804
+ fetchNextPage: locations.fetchNextPage,
12805
+ isFetchingNextPage: locations.isFetchingNextPage,
12806
+ searchValue: locations.searchValue,
12807
+ onSearchValueChange: locations.onSearchValueChange,
12808
+ placeholder: "Select location",
12809
+ onChange: (value) => {
12810
+ setValue("shipping_option_id", "", {
12811
+ shouldDirty: true,
12812
+ shouldTouch: true
12813
+ });
12814
+ onChange(value);
12815
+ },
12816
+ ...field
13001
12817
  }
13002
- ) }),
13003
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13004
- "rect",
12818
+ ) })
12819
+ ] }) });
12820
+ }
12821
+ }
12822
+ );
12823
+ };
12824
+ const ShippingOptionField = ({
12825
+ shippingProfileId,
12826
+ preview,
12827
+ control
12828
+ }) => {
12829
+ var _a;
12830
+ const locationId = useWatch({ control, name: "location_id" });
12831
+ const shippingOptions = useComboboxData({
12832
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12833
+ queryFn: async (params) => {
12834
+ return await sdk.admin.shippingOption.list({
12835
+ ...params,
12836
+ stock_location_id: locationId,
12837
+ shipping_profile_id: shippingProfileId
12838
+ });
12839
+ },
12840
+ getOptions: (data) => {
12841
+ return data.shipping_options.map((option) => {
12842
+ var _a2;
12843
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12844
+ (r) => r.attribute === "is_return" && r.value === "true"
12845
+ )) {
12846
+ return void 0;
12847
+ }
12848
+ return {
12849
+ label: option.name,
12850
+ value: option.id
12851
+ };
12852
+ }).filter(Boolean);
12853
+ },
12854
+ enabled: !!locationId && !!shippingProfileId,
12855
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12856
+ });
12857
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12858
+ return /* @__PURE__ */ jsx(
12859
+ Form$2.Field,
12860
+ {
12861
+ control,
12862
+ name: "shipping_option_id",
12863
+ render: ({ field }) => {
12864
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12865
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12866
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12867
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12868
+ ] }),
12869
+ /* @__PURE__ */ jsx(
12870
+ ConditionalTooltip,
13005
12871
  {
13006
- width: "12",
13007
- height: "12",
13008
- fill: "white",
13009
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12872
+ content: tooltipContent,
12873
+ showTooltip: !locationId || !shippingProfileId,
12874
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12875
+ Combobox,
12876
+ {
12877
+ options: shippingOptions.options,
12878
+ fetchNextPage: shippingOptions.fetchNextPage,
12879
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12880
+ searchValue: shippingOptions.searchValue,
12881
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12882
+ placeholder: "Select shipping option",
12883
+ ...field,
12884
+ disabled: !locationId || !shippingProfileId
12885
+ }
12886
+ ) }) })
13010
12887
  }
13011
- ) }),
13012
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13013
- "rect",
12888
+ )
12889
+ ] }) });
12890
+ }
12891
+ }
12892
+ );
12893
+ };
12894
+ const CustomAmountField = ({
12895
+ control,
12896
+ currencyCode
12897
+ }) => {
12898
+ return /* @__PURE__ */ jsx(
12899
+ Form$2.Field,
12900
+ {
12901
+ control,
12902
+ name: "custom_amount",
12903
+ render: ({ field: { onChange, ...field } }) => {
12904
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12905
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12906
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12907
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12908
+ ] }),
12909
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12910
+ CurrencyInput,
13014
12911
  {
13015
- width: "12",
13016
- height: "12",
13017
- fill: "white",
13018
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12912
+ ...field,
12913
+ onValueChange: (value) => onChange(value),
12914
+ symbol: getNativeSymbol(currencyCode),
12915
+ code: currencyCode
13019
12916
  }
13020
12917
  ) })
13021
- ] })
12918
+ ] });
12919
+ }
12920
+ }
12921
+ );
12922
+ };
12923
+ const SalesChannel = () => {
12924
+ const { id } = useParams();
12925
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12926
+ id,
12927
+ {
12928
+ fields: "+sales_channel_id"
12929
+ },
12930
+ {
12931
+ enabled: !!id
12932
+ }
12933
+ );
12934
+ if (isError) {
12935
+ throw error;
12936
+ }
12937
+ const ISrEADY = !!draft_order && !isPending;
12938
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12939
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12940
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12941
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12942
+ ] }),
12943
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12944
+ ] });
12945
+ };
12946
+ const SalesChannelForm = ({ order }) => {
12947
+ const form = useForm({
12948
+ defaultValues: {
12949
+ sales_channel_id: order.sales_channel_id || ""
12950
+ },
12951
+ resolver: zodResolver(schema)
12952
+ });
12953
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12954
+ const { handleSuccess } = useRouteModal();
12955
+ const onSubmit = form.handleSubmit(async (data) => {
12956
+ await mutateAsync(
12957
+ {
12958
+ sales_channel_id: data.sales_channel_id
12959
+ },
12960
+ {
12961
+ onSuccess: () => {
12962
+ toast.success("Sales channel updated");
12963
+ handleSuccess();
12964
+ },
12965
+ onError: (error) => {
12966
+ toast.error(error.message);
12967
+ }
12968
+ }
12969
+ );
12970
+ });
12971
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12972
+ KeyboundForm,
12973
+ {
12974
+ className: "flex flex-1 flex-col overflow-hidden",
12975
+ onSubmit,
12976
+ children: [
12977
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12978
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12979
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12980
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12981
+ ] }) })
13022
12982
  ]
13023
12983
  }
12984
+ ) });
12985
+ };
12986
+ const SalesChannelField = ({ control, order }) => {
12987
+ const salesChannels = useComboboxData({
12988
+ queryFn: async (params) => {
12989
+ return await sdk.admin.salesChannel.list(params);
12990
+ },
12991
+ queryKey: ["sales-channels"],
12992
+ getOptions: (data) => {
12993
+ return data.sales_channels.map((salesChannel) => ({
12994
+ label: salesChannel.name,
12995
+ value: salesChannel.id
12996
+ }));
12997
+ },
12998
+ defaultValue: order.sales_channel_id || void 0
12999
+ });
13000
+ return /* @__PURE__ */ jsx(
13001
+ Form$2.Field,
13002
+ {
13003
+ control,
13004
+ name: "sales_channel_id",
13005
+ render: ({ field }) => {
13006
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13008
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13009
+ Combobox,
13010
+ {
13011
+ options: salesChannels.options,
13012
+ fetchNextPage: salesChannels.fetchNextPage,
13013
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13014
+ searchValue: salesChannels.searchValue,
13015
+ onSearchValueChange: salesChannels.onSearchValueChange,
13016
+ placeholder: "Select sales channel",
13017
+ ...field
13018
+ }
13019
+ ) }),
13020
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13021
+ ] });
13022
+ }
13023
+ }
13024
13024
  );
13025
13025
  };
13026
13026
  const schema = objectType({
13027
- customer_id: stringType().min(1)
13027
+ sales_channel_id: stringType().min(1)
13028
13028
  });
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
@@ -13047,36 +13047,28 @@ const routeModule = {
13047
13047
  loader,
13048
13048
  children: [
13049
13049
  {
13050
- Component: CustomItems,
13051
- path: "/draft-orders/:id/custom-items"
13052
- },
13053
- {
13054
- Component: Metadata,
13055
- path: "/draft-orders/:id/metadata"
13050
+ Component: BillingAddress,
13051
+ path: "/draft-orders/:id/billing-address"
13056
13052
  },
13057
13053
  {
13058
- Component: Items,
13059
- path: "/draft-orders/:id/items"
13054
+ Component: CustomItems,
13055
+ path: "/draft-orders/:id/custom-items"
13060
13056
  },
13061
13057
  {
13062
13058
  Component: Email,
13063
13059
  path: "/draft-orders/:id/email"
13064
13060
  },
13065
13061
  {
13066
- Component: BillingAddress,
13067
- path: "/draft-orders/:id/billing-address"
13062
+ Component: Items,
13063
+ path: "/draft-orders/:id/items"
13068
13064
  },
13069
13065
  {
13070
13066
  Component: Promotions,
13071
13067
  path: "/draft-orders/:id/promotions"
13072
13068
  },
13073
13069
  {
13074
- Component: SalesChannel,
13075
- path: "/draft-orders/:id/sales-channel"
13076
- },
13077
- {
13078
- Component: Shipping,
13079
- path: "/draft-orders/:id/shipping"
13070
+ Component: Metadata,
13071
+ path: "/draft-orders/:id/metadata"
13080
13072
  },
13081
13073
  {
13082
13074
  Component: ShippingAddress,
@@ -13085,6 +13077,14 @@ const routeModule = {
13085
13077
  {
13086
13078
  Component: TransferOwnership,
13087
13079
  path: "/draft-orders/:id/transfer-ownership"
13080
+ },
13081
+ {
13082
+ Component: Shipping,
13083
+ path: "/draft-orders/:id/shipping"
13084
+ },
13085
+ {
13086
+ Component: SalesChannel,
13087
+ path: "/draft-orders/:id/sales-channel"
13088
13088
  }
13089
13089
  ]
13090
13090
  }