@medusajs/draft-order 2.10.2-preview-20250905060154 → 2.10.2-preview-20250905120200

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.
@@ -7567,12 +7567,12 @@ const addressSchema = objectType({
7567
7567
  first_name: stringType().min(1),
7568
7568
  last_name: stringType().min(1),
7569
7569
  address_1: stringType().min(1),
7570
- address_2: stringType().optional(),
7571
- company: stringType().optional(),
7570
+ address_2: stringType().nullish(),
7571
+ company: stringType().nullish(),
7572
7572
  city: stringType().min(1),
7573
- province: stringType().optional(),
7573
+ province: stringType().nullish(),
7574
7574
  postal_code: stringType().min(1),
7575
- phone: stringType().optional()
7575
+ phone: stringType().nullish()
7576
7576
  });
7577
7577
  const Create = () => {
7578
7578
  return /* @__PURE__ */ jsx(RouteFocusModal, { children: /* @__PURE__ */ jsx(CreateForm, {}) });
@@ -8322,7 +8322,7 @@ const ActivitySection = ({ order, changes }) => {
8322
8322
  () => getActivityItems(order, changes),
8323
8323
  [order, changes]
8324
8324
  );
8325
- return /* @__PURE__ */ jsxs(Container, { className: "p-0 overflow-hidden", children: [
8325
+ return /* @__PURE__ */ jsxs(Container, { className: "overflow-hidden p-0", children: [
8326
8326
  /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Heading, { children: "Activity" }) }),
8327
8327
  /* @__PURE__ */ jsx(ActivityItemList, { items: activityItems })
8328
8328
  ] });
@@ -8353,8 +8353,8 @@ const CollapsibleActivityItemList = ({
8353
8353
  const [open, setOpen] = useState(false);
8354
8354
  return /* @__PURE__ */ jsxs(Collapsible.Root, { open, onOpenChange: setOpen, children: [
8355
8355
  !open && /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[20px_1fr] items-start gap-2", children: [
8356
- /* @__PURE__ */ jsx("div", { className: "flex size-full flex-col items-center", children: /* @__PURE__ */ jsx("div", { className: "border-ui-border-strong w-px flex-1 bg-[linear-gradient(var(--border-strong)_33%,rgba(255,255,255,0)_0%)] bg-[length:1px_3px] bg-right bg-repeat-y bg-clip-content" }) }),
8357
- /* @__PURE__ */ jsx(Collapsible.Trigger, { className: "text-left p-0 m-0 pb-4 text-ui-fg-muted hover:text-ui-fg-base focus:text-ui-fg-base outline-none transition-colors", children: /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", children: `Show ${items.length} more ${items.length === 1 ? "activity" : "activities"}` }) })
8356
+ /* @__PURE__ */ jsx("div", { className: "flex size-full flex-col items-center", children: /* @__PURE__ */ jsx("div", { className: "border-ui-border-strong w-px flex-1 bg-[linear-gradient(var(--border-strong)_33%,rgba(255,255,255,0)_0%)] bg-[length:1px_3px] bg-clip-content bg-right bg-repeat-y" }) }),
8357
+ /* @__PURE__ */ jsx(Collapsible.Trigger, { className: "text-ui-fg-muted hover:text-ui-fg-base focus:text-ui-fg-base m-0 p-0 pb-4 text-left outline-none transition-colors", children: /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", weight: "plus", children: `Show ${items.length} more ${items.length === 1 ? "activity" : "activities"}` }) })
8358
8358
  ] }),
8359
8359
  /* @__PURE__ */ jsx(Collapsible.Content, { children: /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-0.5", children: items.map((item, idx) => {
8360
8360
  return /* @__PURE__ */ jsx(ActivityItem, { item }, idx);
@@ -8372,14 +8372,14 @@ const ActivityItem = ({ item, isFirst = false }) => {
8372
8372
  return /* @__PURE__ */ jsxs(
8373
8373
  "div",
8374
8374
  {
8375
- className: clx("grid grid-cols-[20px_1fr] items-start gap-x-2 w-full"),
8375
+ className: clx("grid w-full grid-cols-[20px_1fr] items-start gap-x-2"),
8376
8376
  children: [
8377
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-0.5 h-full", children: [
8378
- /* @__PURE__ */ jsx("div", { className: "size-5 flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-2.5 rounded-full shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-1.5 rounded-full bg-ui-tag-neutral-icon" }) }) }),
8379
- !isFirst && /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "h-full w-px bg-ui-border-base" }) })
8377
+ /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col items-center gap-0.5", children: [
8378
+ /* @__PURE__ */ jsx("div", { className: "flex size-5 items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "shadow-borders-base flex size-2.5 items-center justify-center rounded-full", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-tag-neutral-icon size-1.5 rounded-full" }) }) }),
8379
+ !isFirst && /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-border-base h-full w-px" }) })
8380
8380
  ] }),
8381
8381
  /* @__PURE__ */ jsxs("div", { className: clx("flex flex-col", !isFirst && "pb-4"), children: [
8382
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-between", children: [
8382
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-x-2", children: [
8383
8383
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.label }),
8384
8384
  /* @__PURE__ */ jsx(
8385
8385
  Tooltip,
@@ -8390,7 +8390,7 @@ const ActivityItem = ({ item, isFirst = false }) => {
8390
8390
  )
8391
8391
  ] }),
8392
8392
  item.content && renderContent(item.content),
8393
- item.userId && /* @__PURE__ */ jsx("div", { className: "pt-2 text-ui-fg-muted", children: isUserLoaded ? /* @__PURE__ */ jsx(Link, { to: `/settings/users/${user.id}`, className: "w-fit", children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1.5 w-fit", children: [
8393
+ item.userId && /* @__PURE__ */ jsx("div", { className: "text-ui-fg-muted pt-2", children: isUserLoaded ? /* @__PURE__ */ jsx(Link, { to: `/settings/users/${user.id}`, className: "w-fit", children: /* @__PURE__ */ jsxs("div", { className: "flex w-fit items-center gap-x-1.5", children: [
8394
8394
  /* @__PURE__ */ jsx(Text, { size: "small", children: "By" }),
8395
8395
  /* @__PURE__ */ jsx(
8396
8396
  Avatar,
@@ -8406,8 +8406,8 @@ const ActivityItem = ({ item, isFirst = false }) => {
8406
8406
  ] })
8407
8407
  ] }) }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1.5", children: [
8408
8408
  /* @__PURE__ */ jsx(Text, { size: "small", children: "By" }),
8409
- /* @__PURE__ */ jsx(Skeleton, { className: "rounded-full w-5 h-5" }),
8410
- /* @__PURE__ */ jsx(Skeleton, { className: "w-[75px] h-4" })
8409
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-5 w-5 rounded-full" }),
8410
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-[75px]" })
8411
8411
  ] }) })
8412
8412
  ] })
8413
8413
  ]
@@ -8430,7 +8430,12 @@ function getEditActivityItems(change) {
8430
8430
  promotionsAdded: 0,
8431
8431
  promotionsRemoved: 0
8432
8432
  };
8433
- for (const action of change.actions) {
8433
+ const orderedActions = change.actions.sort((a, b) => {
8434
+ return a.ordering - b.ordering;
8435
+ });
8436
+ const addedPromotionMap = /* @__PURE__ */ new Map();
8437
+ const removedPromotionMap = /* @__PURE__ */ new Map();
8438
+ for (const action of orderedActions) {
8434
8439
  if (!action.details) {
8435
8440
  continue;
8436
8441
  }
@@ -8448,13 +8453,21 @@ function getEditActivityItems(change) {
8448
8453
  case "SHIPPING_REMOVE":
8449
8454
  counts.shippingMethodsRemoved += 1;
8450
8455
  break;
8451
- case "PROMOTION_ADD":
8452
- counts.promotionsAdded += 1;
8456
+ case "PROMOTION_ADD": {
8457
+ addedPromotionMap.set(action.reference_id, true);
8453
8458
  break;
8454
- case "PROMOTION_REMOVE":
8455
- counts.promotionsRemoved += 1;
8459
+ }
8460
+ case "PROMOTION_REMOVE": {
8461
+ if (addedPromotionMap.has(action.reference_id)) {
8462
+ addedPromotionMap.delete(action.reference_id);
8463
+ } else {
8464
+ removedPromotionMap.set(action.reference_id, true);
8465
+ }
8456
8466
  break;
8467
+ }
8457
8468
  }
8469
+ counts.promotionsAdded = addedPromotionMap.size;
8470
+ counts.promotionsRemoved = removedPromotionMap.size;
8458
8471
  }
8459
8472
  const createActivityItem = (type, added, removed) => {
8460
8473
  if (added === 0 && removed === 0) return;
@@ -9554,6 +9567,217 @@ const ID = () => {
9554
9567
  /* @__PURE__ */ jsx(Outlet, {})
9555
9568
  ] });
9556
9569
  };
9570
+ const BillingAddress = () => {
9571
+ const { id } = useParams();
9572
+ const { order, isPending, isError, error } = useOrder(id, {
9573
+ fields: "+billing_address"
9574
+ });
9575
+ if (isError) {
9576
+ throw error;
9577
+ }
9578
+ const isReady = !isPending && !!order;
9579
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
+ ] }),
9584
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9585
+ ] });
9586
+ };
9587
+ const BillingAddressForm = ({ order }) => {
9588
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9589
+ const form = useForm({
9590
+ defaultValues: {
9591
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
+ },
9602
+ resolver: zodResolver(schema$5)
9603
+ });
9604
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
+ const { handleSuccess } = useRouteModal();
9606
+ const onSubmit = form.handleSubmit(async (data) => {
9607
+ await mutateAsync(
9608
+ { billing_address: data },
9609
+ {
9610
+ onSuccess: () => {
9611
+ handleSuccess();
9612
+ },
9613
+ onError: (error) => {
9614
+ toast.error(error.message);
9615
+ }
9616
+ }
9617
+ );
9618
+ });
9619
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
+ KeyboundForm,
9621
+ {
9622
+ className: "flex flex-1 flex-col overflow-hidden",
9623
+ onSubmit,
9624
+ children: [
9625
+ /* @__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: [
9626
+ /* @__PURE__ */ jsx(
9627
+ Form$2.Field,
9628
+ {
9629
+ control: form.control,
9630
+ name: "country_code",
9631
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
+ ] })
9636
+ }
9637
+ ),
9638
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
+ /* @__PURE__ */ jsx(
9640
+ Form$2.Field,
9641
+ {
9642
+ control: form.control,
9643
+ name: "first_name",
9644
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
+ ] })
9649
+ }
9650
+ ),
9651
+ /* @__PURE__ */ jsx(
9652
+ Form$2.Field,
9653
+ {
9654
+ control: form.control,
9655
+ name: "last_name",
9656
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
+ ] })
9661
+ }
9662
+ )
9663
+ ] }),
9664
+ /* @__PURE__ */ jsx(
9665
+ Form$2.Field,
9666
+ {
9667
+ control: form.control,
9668
+ name: "company",
9669
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
+ ] })
9674
+ }
9675
+ ),
9676
+ /* @__PURE__ */ jsx(
9677
+ Form$2.Field,
9678
+ {
9679
+ control: form.control,
9680
+ name: "address_1",
9681
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
+ ] })
9686
+ }
9687
+ ),
9688
+ /* @__PURE__ */ jsx(
9689
+ Form$2.Field,
9690
+ {
9691
+ control: form.control,
9692
+ name: "address_2",
9693
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
+ ] })
9698
+ }
9699
+ ),
9700
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
+ /* @__PURE__ */ jsx(
9702
+ Form$2.Field,
9703
+ {
9704
+ control: form.control,
9705
+ name: "postal_code",
9706
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
+ ] })
9711
+ }
9712
+ ),
9713
+ /* @__PURE__ */ jsx(
9714
+ Form$2.Field,
9715
+ {
9716
+ control: form.control,
9717
+ name: "city",
9718
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
+ ] })
9723
+ }
9724
+ )
9725
+ ] }),
9726
+ /* @__PURE__ */ jsx(
9727
+ Form$2.Field,
9728
+ {
9729
+ control: form.control,
9730
+ name: "province",
9731
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
+ ] })
9736
+ }
9737
+ ),
9738
+ /* @__PURE__ */ jsx(
9739
+ Form$2.Field,
9740
+ {
9741
+ control: form.control,
9742
+ name: "phone",
9743
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
+ ] })
9748
+ }
9749
+ )
9750
+ ] }) }),
9751
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
+ ] }) })
9755
+ ]
9756
+ }
9757
+ ) });
9758
+ };
9759
+ const schema$5 = addressSchema;
9760
+ const CustomItems = () => {
9761
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
+ ] });
9765
+ };
9766
+ const CustomItemsForm = () => {
9767
+ const form = useForm({
9768
+ resolver: zodResolver(schema$4)
9769
+ });
9770
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
+ ] }) })
9776
+ ] }) });
9777
+ };
9778
+ const schema$4 = objectType({
9779
+ email: stringType().email()
9780
+ });
9557
9781
  const Email = () => {
9558
9782
  const { id } = useParams();
9559
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9576,7 +9800,7 @@ const EmailForm = ({ order }) => {
9576
9800
  defaultValues: {
9577
9801
  email: order.email ?? ""
9578
9802
  },
9579
- resolver: zodResolver(schema$5)
9803
+ resolver: zodResolver(schema$3)
9580
9804
  });
9581
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9582
9806
  const { handleSuccess } = useRouteModal();
@@ -9619,7 +9843,7 @@ const EmailForm = ({ order }) => {
9619
9843
  }
9620
9844
  ) });
9621
9845
  };
9622
- const schema$5 = objectType({
9846
+ const schema$3 = objectType({
9623
9847
  email: stringType().email()
9624
9848
  });
9625
9849
  const NumberInput = forwardRef(
@@ -9905,7 +10129,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
9905
10129
  /* @__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 px-6 py-16", children: [
9906
10130
  /* @__PURE__ */ jsxs("div", { children: [
9907
10131
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
9908
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
10132
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
9909
10133
  ] }),
9910
10134
  /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
9911
10135
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
@@ -9946,13 +10170,13 @@ const ItemsForm = ({ preview, currencyCode }) => {
9946
10170
  ] })
9947
10171
  ] }),
9948
10172
  /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
9949
- /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
10173
+ /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
9950
10174
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
9951
10175
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
9952
10176
  /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
9953
10177
  /* @__PURE__ */ jsx("div", {})
9954
10178
  ] }) }),
9955
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10179
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
9956
10180
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
9957
10181
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
9958
10182
  ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
@@ -9963,7 +10187,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
9963
10187
  currencyCode
9964
10188
  },
9965
10189
  item.id
9966
- )) : /* @__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: [
10190
+ )) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
9967
10191
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
9968
10192
  /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
9969
10193
  'No items found for "',
@@ -10002,7 +10226,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
10002
10226
  ]
10003
10227
  }
10004
10228
  ) }),
10005
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10229
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10006
10230
  /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10007
10231
  /* @__PURE__ */ jsx(
10008
10232
  Button,
@@ -10078,8 +10302,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10078
10302
  }
10079
10303
  );
10080
10304
  });
10081
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10082
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
10305
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10306
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10083
10307
  /* @__PURE__ */ jsx(
10084
10308
  Thumbnail,
10085
10309
  {
@@ -10115,7 +10339,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10115
10339
  )
10116
10340
  ] })
10117
10341
  ] }),
10118
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10342
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10119
10343
  Form$2.Field,
10120
10344
  {
10121
10345
  control: form.control,
@@ -10124,8 +10348,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10124
10348
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10125
10349
  }
10126
10350
  }
10127
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10128
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10351
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10352
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10129
10353
  Form$2.Field,
10130
10354
  {
10131
10355
  control: form.control,
@@ -10142,7 +10366,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10142
10366
  ) }) });
10143
10367
  }
10144
10368
  }
10145
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10369
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10146
10370
  /* @__PURE__ */ jsx(
10147
10371
  IconButton,
10148
10372
  {
@@ -10237,7 +10461,7 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10237
10461
  }
10238
10462
  );
10239
10463
  });
10240
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10464
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10241
10465
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10242
10466
  /* @__PURE__ */ jsx(
10243
10467
  Thumbnail,
@@ -10284,7 +10508,7 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10284
10508
  ) }) });
10285
10509
  }
10286
10510
  }
10287
- ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10511
+ ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10288
10512
  /* @__PURE__ */ jsx(
10289
10513
  IconButton,
10290
10514
  {
@@ -10409,7 +10633,7 @@ const ExistingItemsForm = ({ orderId, items }) => {
10409
10633
  autoFocusSearch: true
10410
10634
  }
10411
10635
  ) }),
10412
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10636
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10413
10637
  /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10414
10638
  /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10415
10639
  ] }) })
@@ -10577,15 +10801,15 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10577
10801
  /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10578
10802
  /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10579
10803
  ] }),
10580
- /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
10581
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10804
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10805
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10582
10806
  /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10583
10807
  ] })
10584
10808
  ] }) })
10585
10809
  }
10586
10810
  )
10587
10811
  ] }) }) }),
10588
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10812
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10589
10813
  /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10590
10814
  /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10591
10815
  ] }) })
@@ -10990,22 +11214,22 @@ const PromotionForm = ({ preview }) => {
10990
11214
  const [comboboxValue, setComboboxValue] = useState("");
10991
11215
  const { handleSuccess } = useRouteModal();
10992
11216
  const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10993
- const promoCodes = getPromotionCodes(items, shipping_methods);
11217
+ const promoIds = getPromotionIds(items, shipping_methods);
10994
11218
  const { promotions, isPending, isError, error } = usePromotions(
10995
11219
  {
10996
- code: promoCodes
11220
+ id: promoIds
10997
11221
  },
10998
11222
  {
10999
- enabled: !!promoCodes.length
11223
+ enabled: !!promoIds.length
11000
11224
  }
11001
11225
  );
11002
11226
  const comboboxData = useComboboxData({
11003
- queryKey: ["promotions", "combobox", promoCodes],
11227
+ queryKey: ["promotions", "combobox", promoIds],
11004
11228
  queryFn: async (params) => {
11005
11229
  return await sdk.admin.promotion.list({
11006
11230
  ...params,
11007
- code: {
11008
- $nin: promoCodes
11231
+ id: {
11232
+ $nin: promoIds
11009
11233
  }
11010
11234
  });
11011
11235
  },
@@ -11141,7 +11365,7 @@ const PromotionItem = ({
11141
11365
  "div",
11142
11366
  {
11143
11367
  className: clx(
11144
- "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
11368
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11145
11369
  {
11146
11370
  "animate-pulse": isLoading
11147
11371
  }
@@ -11149,7 +11373,7 @@ const PromotionItem = ({
11149
11373
  children: [
11150
11374
  /* @__PURE__ */ jsxs("div", { children: [
11151
11375
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11152
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
11376
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11153
11377
  displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11154
11378
  /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11155
11379
  /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
@@ -11201,13 +11425,13 @@ const formatPercentage = (value, isPercentageValue = false) => {
11201
11425
  }
11202
11426
  return formatter.format(val);
11203
11427
  };
11204
- function getPromotionCodes(items, shippingMethods) {
11205
- const codes = /* @__PURE__ */ new Set();
11428
+ function getPromotionIds(items, shippingMethods) {
11429
+ const promotionIds = /* @__PURE__ */ new Set();
11206
11430
  for (const item of items) {
11207
11431
  if (item.adjustments) {
11208
11432
  for (const adjustment of item.adjustments) {
11209
- if (adjustment.code) {
11210
- codes.add(adjustment.code);
11433
+ if (adjustment.promotion_id) {
11434
+ promotionIds.add(adjustment.promotion_id);
11211
11435
  }
11212
11436
  }
11213
11437
  }
@@ -11215,135 +11439,29 @@ function getPromotionCodes(items, shippingMethods) {
11215
11439
  for (const shippingMethod of shippingMethods) {
11216
11440
  if (shippingMethod.adjustments) {
11217
11441
  for (const adjustment of shippingMethod.adjustments) {
11218
- if (adjustment.code) {
11219
- codes.add(adjustment.code);
11442
+ if (adjustment.promotion_id) {
11443
+ promotionIds.add(adjustment.promotion_id);
11220
11444
  }
11221
11445
  }
11222
11446
  }
11223
11447
  }
11224
- return Array.from(codes);
11448
+ return Array.from(promotionIds);
11225
11449
  }
11226
- const SalesChannel = () => {
11450
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11451
+ const Shipping = () => {
11452
+ var _a;
11227
11453
  const { id } = useParams();
11228
- const { draft_order, isPending, isError, error } = useDraftOrder(
11229
- id,
11230
- {
11231
- fields: "+sales_channel_id"
11232
- },
11233
- {
11234
- enabled: !!id
11235
- }
11236
- );
11237
- if (isError) {
11238
- throw error;
11239
- }
11240
- const ISrEADY = !!draft_order && !isPending;
11241
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11242
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11243
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11244
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11245
- ] }),
11246
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11247
- ] });
11248
- };
11249
- const SalesChannelForm = ({ order }) => {
11250
- const form = useForm({
11251
- defaultValues: {
11252
- sales_channel_id: order.sales_channel_id || ""
11253
- },
11254
- resolver: zodResolver(schema$4)
11255
- });
11256
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11257
- const { handleSuccess } = useRouteModal();
11258
- const onSubmit = form.handleSubmit(async (data) => {
11259
- await mutateAsync(
11260
- {
11261
- sales_channel_id: data.sales_channel_id
11262
- },
11263
- {
11264
- onSuccess: () => {
11265
- toast.success("Sales channel updated");
11266
- handleSuccess();
11267
- },
11268
- onError: (error) => {
11269
- toast.error(error.message);
11270
- }
11271
- }
11272
- );
11273
- });
11274
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11275
- KeyboundForm,
11276
- {
11277
- className: "flex flex-1 flex-col overflow-hidden",
11278
- onSubmit,
11279
- children: [
11280
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11281
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11282
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11283
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11284
- ] }) })
11285
- ]
11286
- }
11287
- ) });
11288
- };
11289
- const SalesChannelField = ({ control, order }) => {
11290
- const salesChannels = useComboboxData({
11291
- queryFn: async (params) => {
11292
- return await sdk.admin.salesChannel.list(params);
11293
- },
11294
- queryKey: ["sales-channels"],
11295
- getOptions: (data) => {
11296
- return data.sales_channels.map((salesChannel) => ({
11297
- label: salesChannel.name,
11298
- value: salesChannel.id
11299
- }));
11300
- },
11301
- defaultValue: order.sales_channel_id || void 0
11302
- });
11303
- return /* @__PURE__ */ jsx(
11304
- Form$2.Field,
11305
- {
11306
- control,
11307
- name: "sales_channel_id",
11308
- render: ({ field }) => {
11309
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11310
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11311
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11312
- Combobox,
11313
- {
11314
- options: salesChannels.options,
11315
- fetchNextPage: salesChannels.fetchNextPage,
11316
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11317
- searchValue: salesChannels.searchValue,
11318
- onSearchValueChange: salesChannels.onSearchValueChange,
11319
- placeholder: "Select sales channel",
11320
- ...field
11321
- }
11322
- ) }),
11323
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11324
- ] });
11325
- }
11326
- }
11327
- );
11328
- };
11329
- const schema$4 = objectType({
11330
- sales_channel_id: stringType().min(1)
11331
- });
11332
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11333
- const Shipping = () => {
11334
- var _a;
11335
- const { id } = useParams();
11336
- const { order, isPending, isError, error } = useOrder(id, {
11337
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11338
- });
11339
- const {
11340
- order: preview,
11341
- isPending: isPreviewPending,
11342
- isError: isPreviewError,
11343
- error: previewError
11344
- } = useOrderPreview(id);
11345
- useInitiateOrderEdit({ preview });
11346
- const { onCancel } = useCancelOrderEdit({ preview });
11454
+ const { order, isPending, isError, error } = useOrder(id, {
11455
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11456
+ });
11457
+ const {
11458
+ order: preview,
11459
+ isPending: isPreviewPending,
11460
+ isError: isPreviewError,
11461
+ error: previewError
11462
+ } = useOrderPreview(id);
11463
+ useInitiateOrderEdit({ preview });
11464
+ const { onCancel } = useCancelOrderEdit({ preview });
11347
11465
  if (isError) {
11348
11466
  throw error;
11349
11467
  }
@@ -12136,6 +12254,112 @@ const CustomAmountField = ({
12136
12254
  }
12137
12255
  );
12138
12256
  };
12257
+ const SalesChannel = () => {
12258
+ const { id } = useParams();
12259
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12260
+ id,
12261
+ {
12262
+ fields: "+sales_channel_id"
12263
+ },
12264
+ {
12265
+ enabled: !!id
12266
+ }
12267
+ );
12268
+ if (isError) {
12269
+ throw error;
12270
+ }
12271
+ const ISrEADY = !!draft_order && !isPending;
12272
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12273
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12274
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12275
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12276
+ ] }),
12277
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12278
+ ] });
12279
+ };
12280
+ const SalesChannelForm = ({ order }) => {
12281
+ const form = useForm({
12282
+ defaultValues: {
12283
+ sales_channel_id: order.sales_channel_id || ""
12284
+ },
12285
+ resolver: zodResolver(schema$2)
12286
+ });
12287
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12288
+ const { handleSuccess } = useRouteModal();
12289
+ const onSubmit = form.handleSubmit(async (data) => {
12290
+ await mutateAsync(
12291
+ {
12292
+ sales_channel_id: data.sales_channel_id
12293
+ },
12294
+ {
12295
+ onSuccess: () => {
12296
+ toast.success("Sales channel updated");
12297
+ handleSuccess();
12298
+ },
12299
+ onError: (error) => {
12300
+ toast.error(error.message);
12301
+ }
12302
+ }
12303
+ );
12304
+ });
12305
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12306
+ KeyboundForm,
12307
+ {
12308
+ className: "flex flex-1 flex-col overflow-hidden",
12309
+ onSubmit,
12310
+ children: [
12311
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12312
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12313
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12314
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12315
+ ] }) })
12316
+ ]
12317
+ }
12318
+ ) });
12319
+ };
12320
+ const SalesChannelField = ({ control, order }) => {
12321
+ const salesChannels = useComboboxData({
12322
+ queryFn: async (params) => {
12323
+ return await sdk.admin.salesChannel.list(params);
12324
+ },
12325
+ queryKey: ["sales-channels"],
12326
+ getOptions: (data) => {
12327
+ return data.sales_channels.map((salesChannel) => ({
12328
+ label: salesChannel.name,
12329
+ value: salesChannel.id
12330
+ }));
12331
+ },
12332
+ defaultValue: order.sales_channel_id || void 0
12333
+ });
12334
+ return /* @__PURE__ */ jsx(
12335
+ Form$2.Field,
12336
+ {
12337
+ control,
12338
+ name: "sales_channel_id",
12339
+ render: ({ field }) => {
12340
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12341
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12342
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12343
+ Combobox,
12344
+ {
12345
+ options: salesChannels.options,
12346
+ fetchNextPage: salesChannels.fetchNextPage,
12347
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12348
+ searchValue: salesChannels.searchValue,
12349
+ onSearchValueChange: salesChannels.onSearchValueChange,
12350
+ placeholder: "Select sales channel",
12351
+ ...field
12352
+ }
12353
+ ) }),
12354
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12355
+ ] });
12356
+ }
12357
+ }
12358
+ );
12359
+ };
12360
+ const schema$2 = objectType({
12361
+ sales_channel_id: stringType().min(1)
12362
+ });
12139
12363
  const ShippingAddress = () => {
12140
12364
  const { id } = useParams();
12141
12365
  const { order, isPending, isError, error } = useOrder(id, {
@@ -12168,7 +12392,7 @@ const ShippingAddressForm = ({ order }) => {
12168
12392
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12169
12393
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12170
12394
  },
12171
- resolver: zodResolver(schema$3)
12395
+ resolver: zodResolver(schema$1)
12172
12396
  });
12173
12397
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12174
12398
  const { handleSuccess } = useRouteModal();
@@ -12338,7 +12562,7 @@ const ShippingAddressForm = ({ order }) => {
12338
12562
  }
12339
12563
  ) });
12340
12564
  };
12341
- const schema$3 = addressSchema;
12565
+ const schema$1 = addressSchema;
12342
12566
  const TransferOwnership = () => {
12343
12567
  const { id } = useParams();
12344
12568
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12362,7 +12586,7 @@ const TransferOwnershipForm = ({ order }) => {
12362
12586
  defaultValues: {
12363
12587
  customer_id: order.customer_id || ""
12364
12588
  },
12365
- resolver: zodResolver(schema$2)
12589
+ resolver: zodResolver(schema)
12366
12590
  });
12367
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12368
12592
  const { handleSuccess } = useRouteModal();
@@ -12812,220 +13036,9 @@ const Illustration = () => {
12812
13036
  }
12813
13037
  );
12814
13038
  };
12815
- const schema$2 = objectType({
13039
+ const schema = objectType({
12816
13040
  customer_id: stringType().min(1)
12817
13041
  });
12818
- const CustomItems = () => {
12819
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12820
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
12821
- /* @__PURE__ */ jsx(CustomItemsForm, {})
12822
- ] });
12823
- };
12824
- const CustomItemsForm = () => {
12825
- const form = useForm({
12826
- resolver: zodResolver(schema$1)
12827
- });
12828
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
12829
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
12830
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12831
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12832
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
12833
- ] }) })
12834
- ] }) });
12835
- };
12836
- const schema$1 = objectType({
12837
- email: stringType().email()
12838
- });
12839
- const BillingAddress = () => {
12840
- const { id } = useParams();
12841
- const { order, isPending, isError, error } = useOrder(id, {
12842
- fields: "+billing_address"
12843
- });
12844
- if (isError) {
12845
- throw error;
12846
- }
12847
- const isReady = !isPending && !!order;
12848
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12849
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12850
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12851
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12852
- ] }),
12853
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12854
- ] });
12855
- };
12856
- const BillingAddressForm = ({ order }) => {
12857
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12858
- const form = useForm({
12859
- defaultValues: {
12860
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12861
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12862
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12863
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12864
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12865
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12866
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12867
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12868
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12869
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12870
- },
12871
- resolver: zodResolver(schema)
12872
- });
12873
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12874
- const { handleSuccess } = useRouteModal();
12875
- const onSubmit = form.handleSubmit(async (data) => {
12876
- await mutateAsync(
12877
- { billing_address: data },
12878
- {
12879
- onSuccess: () => {
12880
- handleSuccess();
12881
- },
12882
- onError: (error) => {
12883
- toast.error(error.message);
12884
- }
12885
- }
12886
- );
12887
- });
12888
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12889
- KeyboundForm,
12890
- {
12891
- className: "flex flex-1 flex-col overflow-hidden",
12892
- onSubmit,
12893
- children: [
12894
- /* @__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: [
12895
- /* @__PURE__ */ jsx(
12896
- Form$2.Field,
12897
- {
12898
- control: form.control,
12899
- name: "country_code",
12900
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12901
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12902
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12903
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12904
- ] })
12905
- }
12906
- ),
12907
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12910
- {
12911
- control: form.control,
12912
- name: "first_name",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12918
- }
12919
- ),
12920
- /* @__PURE__ */ jsx(
12921
- Form$2.Field,
12922
- {
12923
- control: form.control,
12924
- name: "last_name",
12925
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12926
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12927
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12928
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12929
- ] })
12930
- }
12931
- )
12932
- ] }),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "company",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- ),
12945
- /* @__PURE__ */ jsx(
12946
- Form$2.Field,
12947
- {
12948
- control: form.control,
12949
- name: "address_1",
12950
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12951
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12952
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12953
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12954
- ] })
12955
- }
12956
- ),
12957
- /* @__PURE__ */ jsx(
12958
- Form$2.Field,
12959
- {
12960
- control: form.control,
12961
- name: "address_2",
12962
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12963
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12964
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12965
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12966
- ] })
12967
- }
12968
- ),
12969
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
12972
- {
12973
- control: form.control,
12974
- name: "postal_code",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
12980
- }
12981
- ),
12982
- /* @__PURE__ */ jsx(
12983
- Form$2.Field,
12984
- {
12985
- control: form.control,
12986
- name: "city",
12987
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12988
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12989
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12990
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12991
- ] })
12992
- }
12993
- )
12994
- ] }),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "province",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- ),
13007
- /* @__PURE__ */ jsx(
13008
- Form$2.Field,
13009
- {
13010
- control: form.control,
13011
- name: "phone",
13012
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13013
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13014
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13015
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13016
- ] })
13017
- }
13018
- )
13019
- ] }) }),
13020
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13021
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13022
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13023
- ] }) })
13024
- ]
13025
- }
13026
- ) });
13027
- };
13028
- const schema = addressSchema;
13029
13042
  const widgetModule = { widgets: [] };
13030
13043
  const routeModule = {
13031
13044
  routes: [
@@ -13046,6 +13059,14 @@ const routeModule = {
13046
13059
  handle,
13047
13060
  loader,
13048
13061
  children: [
13062
+ {
13063
+ Component: BillingAddress,
13064
+ path: "/draft-orders/:id/billing-address"
13065
+ },
13066
+ {
13067
+ Component: CustomItems,
13068
+ path: "/draft-orders/:id/custom-items"
13069
+ },
13049
13070
  {
13050
13071
  Component: Email,
13051
13072
  path: "/draft-orders/:id/email"
@@ -13062,14 +13083,14 @@ const routeModule = {
13062
13083
  Component: Promotions,
13063
13084
  path: "/draft-orders/:id/promotions"
13064
13085
  },
13065
- {
13066
- Component: SalesChannel,
13067
- path: "/draft-orders/:id/sales-channel"
13068
- },
13069
13086
  {
13070
13087
  Component: Shipping,
13071
13088
  path: "/draft-orders/:id/shipping"
13072
13089
  },
13090
+ {
13091
+ Component: SalesChannel,
13092
+ path: "/draft-orders/:id/sales-channel"
13093
+ },
13073
13094
  {
13074
13095
  Component: ShippingAddress,
13075
13096
  path: "/draft-orders/:id/shipping-address"
@@ -13077,14 +13098,6 @@ const routeModule = {
13077
13098
  {
13078
13099
  Component: TransferOwnership,
13079
13100
  path: "/draft-orders/:id/transfer-ownership"
13080
- },
13081
- {
13082
- Component: CustomItems,
13083
- path: "/draft-orders/:id/custom-items"
13084
- },
13085
- {
13086
- Component: BillingAddress,
13087
- path: "/draft-orders/:id/billing-address"
13088
13101
  }
13089
13102
  ]
13090
13103
  }