@medusajs/draft-order 0.0.10 → 0.0.11

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.
@@ -9712,6 +9712,27 @@ const ID = () => {
9712
9712
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9713
9713
  ] });
9714
9714
  };
9715
+ const CustomItems = () => {
9716
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9717
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9718
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9719
+ ] });
9720
+ };
9721
+ const CustomItemsForm = () => {
9722
+ const form = reactHookForm.useForm({
9723
+ resolver: zod.zodResolver(schema$5)
9724
+ });
9725
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9726
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9727
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9728
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9729
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9730
+ ] }) })
9731
+ ] }) });
9732
+ };
9733
+ const schema$5 = z.object({
9734
+ email: z.string().email()
9735
+ });
9715
9736
  const BillingAddress = () => {
9716
9737
  const { id } = reactRouterDom.useParams();
9717
9738
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9744,7 +9765,7 @@ const BillingAddressForm = ({ order }) => {
9744
9765
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9745
9766
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9746
9767
  },
9747
- resolver: zod.zodResolver(schema$5)
9768
+ resolver: zod.zodResolver(schema$4)
9748
9769
  });
9749
9770
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9750
9771
  const { handleSuccess } = useRouteModal();
@@ -9901,28 +9922,7 @@ const BillingAddressForm = ({ order }) => {
9901
9922
  }
9902
9923
  ) });
9903
9924
  };
9904
- const schema$5 = addressSchema;
9905
- const CustomItems = () => {
9906
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9907
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9908
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9909
- ] });
9910
- };
9911
- const CustomItemsForm = () => {
9912
- const form = reactHookForm.useForm({
9913
- resolver: zod.zodResolver(schema$4)
9914
- });
9915
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9916
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9917
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9918
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9919
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9920
- ] }) })
9921
- ] }) });
9922
- };
9923
- const schema$4 = z.object({
9924
- email: z.string().email()
9925
- });
9925
+ const schema$4 = addressSchema;
9926
9926
  const InlineTip = React.forwardRef(
9927
9927
  ({ variant = "tip", label, className, children, ...props }, ref) => {
9928
9928
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -10596,6 +10596,180 @@ function getPromotionCodes(items, shippingMethods) {
10596
10596
  }
10597
10597
  return Array.from(codes);
10598
10598
  }
10599
+ const Email = () => {
10600
+ const { id } = reactRouterDom.useParams();
10601
+ const { order, isPending, isError, error } = useOrder(id, {
10602
+ fields: "+email"
10603
+ });
10604
+ if (isError) {
10605
+ throw error;
10606
+ }
10607
+ const isReady = !isPending && !!order;
10608
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10609
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10610
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10611
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10612
+ ] }),
10613
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10614
+ ] });
10615
+ };
10616
+ const EmailForm = ({ order }) => {
10617
+ const form = reactHookForm.useForm({
10618
+ defaultValues: {
10619
+ email: order.email ?? ""
10620
+ },
10621
+ resolver: zod.zodResolver(schema$3)
10622
+ });
10623
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10624
+ const { handleSuccess } = useRouteModal();
10625
+ const onSubmit = form.handleSubmit(async (data) => {
10626
+ await mutateAsync(
10627
+ { email: data.email },
10628
+ {
10629
+ onSuccess: () => {
10630
+ handleSuccess();
10631
+ },
10632
+ onError: (error) => {
10633
+ ui.toast.error(error.message);
10634
+ }
10635
+ }
10636
+ );
10637
+ });
10638
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10639
+ KeyboundForm,
10640
+ {
10641
+ className: "flex flex-1 flex-col overflow-hidden",
10642
+ onSubmit,
10643
+ children: [
10644
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10645
+ Form$2.Field,
10646
+ {
10647
+ control: form.control,
10648
+ name: "email",
10649
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10652
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10653
+ ] })
10654
+ }
10655
+ ) }),
10656
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10657
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10658
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10659
+ ] }) })
10660
+ ]
10661
+ }
10662
+ ) });
10663
+ };
10664
+ const schema$3 = z.object({
10665
+ email: z.string().email()
10666
+ });
10667
+ const SalesChannel = () => {
10668
+ const { id } = reactRouterDom.useParams();
10669
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10670
+ id,
10671
+ {
10672
+ fields: "+sales_channel_id"
10673
+ },
10674
+ {
10675
+ enabled: !!id
10676
+ }
10677
+ );
10678
+ if (isError) {
10679
+ throw error;
10680
+ }
10681
+ const ISrEADY = !!draft_order && !isPending;
10682
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10683
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10684
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
10685
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
10686
+ ] }),
10687
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
10688
+ ] });
10689
+ };
10690
+ const SalesChannelForm = ({ order }) => {
10691
+ const form = reactHookForm.useForm({
10692
+ defaultValues: {
10693
+ sales_channel_id: order.sales_channel_id || ""
10694
+ },
10695
+ resolver: zod.zodResolver(schema$2)
10696
+ });
10697
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10698
+ const { handleSuccess } = useRouteModal();
10699
+ const onSubmit = form.handleSubmit(async (data) => {
10700
+ await mutateAsync(
10701
+ {
10702
+ sales_channel_id: data.sales_channel_id
10703
+ },
10704
+ {
10705
+ onSuccess: () => {
10706
+ ui.toast.success("Sales channel updated");
10707
+ handleSuccess();
10708
+ },
10709
+ onError: (error) => {
10710
+ ui.toast.error(error.message);
10711
+ }
10712
+ }
10713
+ );
10714
+ });
10715
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10716
+ KeyboundForm,
10717
+ {
10718
+ className: "flex flex-1 flex-col overflow-hidden",
10719
+ onSubmit,
10720
+ children: [
10721
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
10722
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10723
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10724
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10725
+ ] }) })
10726
+ ]
10727
+ }
10728
+ ) });
10729
+ };
10730
+ const SalesChannelField = ({ control, order }) => {
10731
+ const salesChannels = useComboboxData({
10732
+ queryFn: async (params) => {
10733
+ return await sdk.admin.salesChannel.list(params);
10734
+ },
10735
+ queryKey: ["sales-channels"],
10736
+ getOptions: (data) => {
10737
+ return data.sales_channels.map((salesChannel) => ({
10738
+ label: salesChannel.name,
10739
+ value: salesChannel.id
10740
+ }));
10741
+ },
10742
+ defaultValue: order.sales_channel_id || void 0
10743
+ });
10744
+ return /* @__PURE__ */ jsxRuntime.jsx(
10745
+ Form$2.Field,
10746
+ {
10747
+ control,
10748
+ name: "sales_channel_id",
10749
+ render: ({ field }) => {
10750
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
10752
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10753
+ Combobox,
10754
+ {
10755
+ options: salesChannels.options,
10756
+ fetchNextPage: salesChannels.fetchNextPage,
10757
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
10758
+ searchValue: salesChannels.searchValue,
10759
+ onSearchValueChange: salesChannels.onSearchValueChange,
10760
+ placeholder: "Select sales channel",
10761
+ ...field
10762
+ }
10763
+ ) }),
10764
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10765
+ ] });
10766
+ }
10767
+ }
10768
+ );
10769
+ };
10770
+ const schema$2 = z.object({
10771
+ sales_channel_id: z.string().min(1)
10772
+ });
10599
10773
  function convertNumber(value) {
10600
10774
  return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10601
10775
  }
@@ -11406,46 +11580,60 @@ const CustomAmountField = ({
11406
11580
  }
11407
11581
  );
11408
11582
  };
11409
- const SalesChannel = () => {
11583
+ const ShippingAddress = () => {
11410
11584
  const { id } = reactRouterDom.useParams();
11411
- const { draft_order, isPending, isError, error } = useDraftOrder(
11412
- id,
11413
- {
11414
- fields: "+sales_channel_id"
11415
- },
11416
- {
11417
- enabled: !!id
11418
- }
11419
- );
11585
+ const { order, isPending, isError, error } = useOrder(id, {
11586
+ fields: "+shipping_address"
11587
+ });
11420
11588
  if (isError) {
11421
11589
  throw error;
11422
11590
  }
11423
- const ISrEADY = !!draft_order && !isPending;
11591
+ const isReady = !isPending && !!order;
11424
11592
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11425
11593
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11426
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11427
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11594
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11595
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11428
11596
  ] }),
11429
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11597
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11430
11598
  ] });
11431
11599
  };
11432
- const SalesChannelForm = ({ order }) => {
11600
+ const ShippingAddressForm = ({ order }) => {
11601
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11433
11602
  const form = reactHookForm.useForm({
11434
11603
  defaultValues: {
11435
- sales_channel_id: order.sales_channel_id || ""
11604
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11605
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11606
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11607
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11608
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11609
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11610
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11611
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11612
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11613
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11436
11614
  },
11437
- resolver: zod.zodResolver(schema$3)
11615
+ resolver: zod.zodResolver(schema$1)
11438
11616
  });
11439
11617
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11440
11618
  const { handleSuccess } = useRouteModal();
11441
11619
  const onSubmit = form.handleSubmit(async (data) => {
11442
11620
  await mutateAsync(
11443
11621
  {
11444
- sales_channel_id: data.sales_channel_id
11445
- },
11446
- {
11622
+ shipping_address: {
11623
+ first_name: data.first_name,
11624
+ last_name: data.last_name,
11625
+ company: data.company,
11626
+ address_1: data.address_1,
11627
+ address_2: data.address_2,
11628
+ city: data.city,
11629
+ province: data.province,
11630
+ country_code: data.country_code,
11631
+ postal_code: data.postal_code,
11632
+ phone: data.phone
11633
+ }
11634
+ },
11635
+ {
11447
11636
  onSuccess: () => {
11448
- ui.toast.success("Sales channel updated");
11449
11637
  handleSuccess();
11450
11638
  },
11451
11639
  onError: (error) => {
@@ -11460,7 +11648,132 @@ const SalesChannelForm = ({ order }) => {
11460
11648
  className: "flex flex-1 flex-col overflow-hidden",
11461
11649
  onSubmit,
11462
11650
  children: [
11463
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11651
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11652
+ /* @__PURE__ */ jsxRuntime.jsx(
11653
+ Form$2.Field,
11654
+ {
11655
+ control: form.control,
11656
+ name: "country_code",
11657
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11658
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11659
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11660
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11661
+ ] })
11662
+ }
11663
+ ),
11664
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11665
+ /* @__PURE__ */ jsxRuntime.jsx(
11666
+ Form$2.Field,
11667
+ {
11668
+ control: form.control,
11669
+ name: "first_name",
11670
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11671
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11672
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11673
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11674
+ ] })
11675
+ }
11676
+ ),
11677
+ /* @__PURE__ */ jsxRuntime.jsx(
11678
+ Form$2.Field,
11679
+ {
11680
+ control: form.control,
11681
+ name: "last_name",
11682
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11683
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11684
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11685
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11686
+ ] })
11687
+ }
11688
+ )
11689
+ ] }),
11690
+ /* @__PURE__ */ jsxRuntime.jsx(
11691
+ Form$2.Field,
11692
+ {
11693
+ control: form.control,
11694
+ name: "company",
11695
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11696
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11697
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11699
+ ] })
11700
+ }
11701
+ ),
11702
+ /* @__PURE__ */ jsxRuntime.jsx(
11703
+ Form$2.Field,
11704
+ {
11705
+ control: form.control,
11706
+ name: "address_1",
11707
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11708
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11709
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11710
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11711
+ ] })
11712
+ }
11713
+ ),
11714
+ /* @__PURE__ */ jsxRuntime.jsx(
11715
+ Form$2.Field,
11716
+ {
11717
+ control: form.control,
11718
+ name: "address_2",
11719
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11720
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11721
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11722
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11723
+ ] })
11724
+ }
11725
+ ),
11726
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11727
+ /* @__PURE__ */ jsxRuntime.jsx(
11728
+ Form$2.Field,
11729
+ {
11730
+ control: form.control,
11731
+ name: "postal_code",
11732
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11733
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11734
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11735
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11736
+ ] })
11737
+ }
11738
+ ),
11739
+ /* @__PURE__ */ jsxRuntime.jsx(
11740
+ Form$2.Field,
11741
+ {
11742
+ control: form.control,
11743
+ name: "city",
11744
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11745
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11746
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11747
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11748
+ ] })
11749
+ }
11750
+ )
11751
+ ] }),
11752
+ /* @__PURE__ */ jsxRuntime.jsx(
11753
+ Form$2.Field,
11754
+ {
11755
+ control: form.control,
11756
+ name: "province",
11757
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11758
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11759
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11760
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11761
+ ] })
11762
+ }
11763
+ ),
11764
+ /* @__PURE__ */ jsxRuntime.jsx(
11765
+ Form$2.Field,
11766
+ {
11767
+ control: form.control,
11768
+ name: "phone",
11769
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11770
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11771
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11772
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11773
+ ] })
11774
+ }
11775
+ )
11776
+ ] }) }),
11464
11777
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11465
11778
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11466
11779
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11469,1393 +11782,223 @@ const SalesChannelForm = ({ order }) => {
11469
11782
  }
11470
11783
  ) });
11471
11784
  };
11472
- const SalesChannelField = ({ control, order }) => {
11473
- const salesChannels = useComboboxData({
11785
+ const schema$1 = addressSchema;
11786
+ const TransferOwnership = () => {
11787
+ const { id } = reactRouterDom.useParams();
11788
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11789
+ fields: "id,customer_id,customer.*"
11790
+ });
11791
+ if (isError) {
11792
+ throw error;
11793
+ }
11794
+ const isReady = !isPending && !!draft_order;
11795
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11796
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11797
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11798
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11799
+ ] }),
11800
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11801
+ ] });
11802
+ };
11803
+ const TransferOwnershipForm = ({ order }) => {
11804
+ var _a, _b;
11805
+ const form = reactHookForm.useForm({
11806
+ defaultValues: {
11807
+ customer_id: order.customer_id || ""
11808
+ },
11809
+ resolver: zod.zodResolver(schema)
11810
+ });
11811
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11812
+ const { handleSuccess } = useRouteModal();
11813
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11814
+ const currentCustomer = order.customer ? {
11815
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11816
+ value: order.customer.id
11817
+ } : null;
11818
+ const onSubmit = form.handleSubmit(async (data) => {
11819
+ await mutateAsync(
11820
+ { customer_id: data.customer_id },
11821
+ {
11822
+ onSuccess: () => {
11823
+ ui.toast.success("Customer updated");
11824
+ handleSuccess();
11825
+ },
11826
+ onError: (error) => {
11827
+ ui.toast.error(error.message);
11828
+ }
11829
+ }
11830
+ );
11831
+ });
11832
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11833
+ KeyboundForm,
11834
+ {
11835
+ className: "flex flex-1 flex-col overflow-hidden",
11836
+ onSubmit,
11837
+ children: [
11838
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11839
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11840
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11841
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11842
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11843
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11844
+ ] }),
11845
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11846
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11847
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11848
+ ] })
11849
+ ] }),
11850
+ /* @__PURE__ */ jsxRuntime.jsx(
11851
+ CustomerField,
11852
+ {
11853
+ control: form.control,
11854
+ currentCustomerId: order.customer_id
11855
+ }
11856
+ )
11857
+ ] }),
11858
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11859
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11860
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11861
+ ] }) })
11862
+ ]
11863
+ }
11864
+ ) });
11865
+ };
11866
+ const CustomerField = ({ control, currentCustomerId }) => {
11867
+ const customers = useComboboxData({
11474
11868
  queryFn: async (params) => {
11475
- return await sdk.admin.salesChannel.list(params);
11869
+ return await sdk.admin.customer.list({
11870
+ ...params,
11871
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11872
+ });
11476
11873
  },
11477
- queryKey: ["sales-channels"],
11874
+ queryKey: ["customers"],
11478
11875
  getOptions: (data) => {
11479
- return data.sales_channels.map((salesChannel) => ({
11480
- label: salesChannel.name,
11481
- value: salesChannel.id
11482
- }));
11483
- },
11484
- defaultValue: order.sales_channel_id || void 0
11876
+ return data.customers.map((customer) => {
11877
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11878
+ return {
11879
+ label: name ? `${name} (${customer.email})` : customer.email,
11880
+ value: customer.id
11881
+ };
11882
+ });
11883
+ }
11485
11884
  });
11486
11885
  return /* @__PURE__ */ jsxRuntime.jsx(
11487
11886
  Form$2.Field,
11488
11887
  {
11888
+ name: "customer_id",
11489
11889
  control,
11490
- name: "sales_channel_id",
11491
- render: ({ field }) => {
11492
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11493
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11494
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11495
- Combobox,
11496
- {
11497
- options: salesChannels.options,
11498
- fetchNextPage: salesChannels.fetchNextPage,
11499
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11500
- searchValue: salesChannels.searchValue,
11501
- onSearchValueChange: salesChannels.onSearchValueChange,
11502
- placeholder: "Select sales channel",
11503
- ...field
11504
- }
11505
- ) }),
11506
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11507
- ] });
11508
- }
11890
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11891
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11892
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11893
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11894
+ ] }),
11895
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11896
+ Combobox,
11897
+ {
11898
+ options: customers.options,
11899
+ fetchNextPage: customers.fetchNextPage,
11900
+ isFetchingNextPage: customers.isFetchingNextPage,
11901
+ searchValue: customers.searchValue,
11902
+ onSearchValueChange: customers.onSearchValueChange,
11903
+ placeholder: "Select customer",
11904
+ ...field
11905
+ }
11906
+ ) }),
11907
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11908
+ ] })
11509
11909
  }
11510
11910
  );
11511
11911
  };
11512
- const schema$3 = z.object({
11513
- sales_channel_id: z.string().min(1)
11514
- });
11515
- const NumberInput = React.forwardRef(
11516
- ({
11517
- value,
11518
- onChange,
11519
- size = "base",
11520
- min = 0,
11521
- max = 100,
11522
- step = 1,
11523
- className,
11524
- disabled,
11525
- ...props
11526
- }, ref) => {
11527
- const handleChange = (event) => {
11528
- const newValue = event.target.value === "" ? min : Number(event.target.value);
11529
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
11530
- onChange(newValue);
11531
- }
11532
- };
11533
- const handleIncrement = () => {
11534
- const newValue = value + step;
11535
- if (max === void 0 || newValue <= max) {
11536
- onChange(newValue);
11537
- }
11538
- };
11539
- const handleDecrement = () => {
11540
- const newValue = value - step;
11541
- if (min === void 0 || newValue >= min) {
11542
- onChange(newValue);
11543
- }
11544
- };
11545
- return /* @__PURE__ */ jsxRuntime.jsxs(
11546
- "div",
11547
- {
11548
- className: ui.clx(
11549
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
11550
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
11912
+ const Illustration = () => {
11913
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11914
+ "svg",
11915
+ {
11916
+ width: "280",
11917
+ height: "180",
11918
+ viewBox: "0 0 280 180",
11919
+ fill: "none",
11920
+ xmlns: "http://www.w3.org/2000/svg",
11921
+ children: [
11922
+ /* @__PURE__ */ jsxRuntime.jsx(
11923
+ "rect",
11551
11924
  {
11552
- "h-7": size === "small",
11553
- "h-8": size === "base"
11554
- },
11555
- className
11925
+ x: "0.00428286",
11926
+ y: "-0.742904",
11927
+ width: "33.5",
11928
+ height: "65.5",
11929
+ rx: "6.75",
11930
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11931
+ fill: "#D4D4D8",
11932
+ stroke: "#52525B",
11933
+ strokeWidth: "1.5"
11934
+ }
11556
11935
  ),
11557
- children: [
11558
- /* @__PURE__ */ jsxRuntime.jsx(
11559
- "input",
11560
- {
11561
- ref,
11562
- type: "number",
11563
- value,
11564
- onChange: handleChange,
11565
- min,
11566
- max,
11567
- step,
11568
- className: ui.clx(
11569
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
11570
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
11571
- "placeholder:text-ui-fg-muted"
11572
- ),
11573
- ...props
11574
- }
11575
- ),
11576
- /* @__PURE__ */ jsxRuntime.jsxs(
11577
- "button",
11578
- {
11579
- className: ui.clx(
11580
- "flex items-center justify-center outline-none transition-fg",
11581
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11582
- "focus:bg-ui-bg-field-component-hover",
11583
- "hover:bg-ui-bg-field-component-hover",
11584
- {
11585
- "size-7": size === "small",
11586
- "size-8": size === "base"
11587
- }
11588
- ),
11589
- type: "button",
11590
- onClick: handleDecrement,
11591
- disabled: min !== void 0 && value <= min || disabled,
11592
- children: [
11593
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
11594
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
11595
- ]
11596
- }
11597
- ),
11598
- /* @__PURE__ */ jsxRuntime.jsxs(
11599
- "button",
11600
- {
11601
- className: ui.clx(
11602
- "flex items-center justify-center outline-none transition-fg",
11603
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11604
- "focus:bg-ui-bg-field-hover",
11605
- "hover:bg-ui-bg-field-hover",
11606
- {
11607
- "size-7": size === "small",
11608
- "size-8": size === "base"
11609
- }
11610
- ),
11611
- type: "button",
11612
- onClick: handleIncrement,
11613
- disabled: max !== void 0 && value >= max || disabled,
11614
- children: [
11615
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
11616
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
11617
- ]
11618
- }
11619
- )
11620
- ]
11621
- }
11622
- );
11623
- }
11624
- );
11625
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
11626
- const productVariantsQueryKeys = {
11627
- list: (query2) => [
11628
- PRODUCT_VARIANTS_QUERY_KEY,
11629
- query2 ? query2 : void 0
11630
- ]
11631
- };
11632
- const useProductVariants = (query2, options) => {
11633
- const { data, ...rest } = reactQuery.useQuery({
11634
- queryKey: productVariantsQueryKeys.list(query2),
11635
- queryFn: async () => await sdk.admin.productVariant.list(query2),
11636
- ...options
11637
- });
11638
- return { ...data, ...rest };
11639
- };
11640
- const STACKED_MODAL_ID = "items_stacked_modal";
11641
- const Items = () => {
11642
- const { id } = reactRouterDom.useParams();
11643
- const {
11644
- order: preview,
11645
- isPending: isPreviewPending,
11646
- isError: isPreviewError,
11647
- error: previewError
11648
- } = useOrderPreview(id, void 0, {
11649
- placeholderData: reactQuery.keepPreviousData
11650
- });
11651
- useInitiateOrderEdit({ preview });
11652
- const { draft_order, isPending, isError, error } = useDraftOrder(
11653
- id,
11654
- {
11655
- fields: "currency_code"
11656
- },
11657
- {
11658
- enabled: !!id
11659
- }
11660
- );
11661
- const { onCancel } = useCancelOrderEdit({ preview });
11662
- if (isError) {
11663
- throw error;
11664
- }
11665
- if (isPreviewError) {
11666
- throw previewError;
11667
- }
11668
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
11669
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11670
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
11671
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11672
- ] }) });
11673
- };
11674
- const ItemsForm = ({ preview, currencyCode }) => {
11675
- var _a;
11676
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11677
- const [modalContent, setModalContent] = React.useState(
11678
- null
11679
- );
11680
- const { handleSuccess } = useRouteModal();
11681
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
11682
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11683
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11684
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
11685
- const matches = React.useMemo(() => {
11686
- return matchSorter.matchSorter(preview.items, query2, {
11687
- keys: ["product_title", "variant_title", "variant_sku", "title"]
11688
- });
11689
- }, [preview.items, query2]);
11690
- const onSubmit = async () => {
11691
- setIsSubmitting(true);
11692
- let requestSucceeded = false;
11693
- await requestOrderEdit(void 0, {
11694
- onError: (e) => {
11695
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11696
- },
11697
- onSuccess: () => {
11698
- requestSucceeded = true;
11699
- }
11700
- });
11701
- if (!requestSucceeded) {
11702
- setIsSubmitting(false);
11703
- return;
11704
- }
11705
- await confirmOrderEdit(void 0, {
11706
- onError: (e) => {
11707
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11708
- },
11709
- onSuccess: () => {
11710
- handleSuccess();
11711
- },
11712
- onSettled: () => {
11713
- setIsSubmitting(false);
11714
- }
11715
- });
11716
- };
11717
- const onKeyDown = React.useCallback(
11718
- (e) => {
11719
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11720
- if (modalContent || isSubmitting) {
11721
- return;
11722
- }
11723
- onSubmit();
11724
- }
11725
- },
11726
- [modalContent, isSubmitting, onSubmit]
11727
- );
11728
- React.useEffect(() => {
11729
- document.addEventListener("keydown", onKeyDown);
11730
- return () => {
11731
- document.removeEventListener("keydown", onKeyDown);
11732
- };
11733
- }, [onKeyDown]);
11734
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11735
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11736
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
11737
- StackedFocusModal,
11738
- {
11739
- id: STACKED_MODAL_ID,
11740
- onOpenChangeCallback: (open) => {
11741
- if (!open) {
11742
- setModalContent(null);
11743
- }
11744
- },
11745
- children: [
11746
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11747
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11748
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
11749
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
11750
- ] }),
11751
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11752
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11753
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
11754
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11755
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
11756
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
11757
- ] }),
11758
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
11759
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
11760
- ui.Input,
11761
- {
11762
- type: "search",
11763
- placeholder: "Search items",
11764
- value: searchValue,
11765
- onChange: (e) => onSearchValueChange(e.target.value)
11766
- }
11767
- ) }),
11768
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11769
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
11770
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11771
- /* @__PURE__ */ jsxRuntime.jsx(
11772
- StackedModalTrigger,
11773
- {
11774
- type: "add-items",
11775
- setModalContent
11776
- }
11777
- ),
11778
- /* @__PURE__ */ jsxRuntime.jsx(
11779
- StackedModalTrigger,
11780
- {
11781
- type: "add-custom-item",
11782
- setModalContent
11783
- }
11784
- )
11785
- ] })
11786
- ] })
11787
- ] })
11788
- ] }),
11789
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11790
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
11791
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11792
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
11793
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
11794
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
11795
- ] }) }),
11796
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11797
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
11798
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
11799
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
11800
- Item,
11801
- {
11802
- item,
11803
- preview,
11804
- currencyCode
11805
- },
11806
- item.id
11807
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11808
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11809
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
11810
- 'No items found for "',
11811
- query2,
11812
- '".'
11813
- ] })
11814
- ] }) })
11815
- ] })
11816
- ] }),
11817
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11818
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
11819
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
11820
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
11821
- ui.Text,
11822
- {
11823
- size: "small",
11824
- leading: "compact",
11825
- className: "text-ui-fg-subtle",
11826
- children: [
11827
- itemCount,
11828
- " ",
11829
- itemCount === 1 ? "item" : "items"
11830
- ]
11831
- }
11832
- ) }),
11833
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
11834
- ] })
11835
- ] }) }),
11836
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
11837
- CustomItemForm,
11838
- {
11839
- orderId: preview.id,
11840
- currencyCode
11841
- }
11842
- ) : null)
11843
- ]
11844
- }
11845
- ) }),
11846
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
11847
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11848
- /* @__PURE__ */ jsxRuntime.jsx(
11849
- ui.Button,
11850
- {
11851
- size: "small",
11852
- type: "button",
11853
- onClick: onSubmit,
11854
- isLoading: isSubmitting,
11855
- children: "Save"
11856
- }
11857
- )
11858
- ] }) })
11859
- ] });
11860
- };
11861
- const Item = ({ item, preview, currencyCode }) => {
11862
- if (item.variant_id) {
11863
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
11864
- }
11865
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
11866
- };
11867
- const VariantItem = ({ item, preview, currencyCode }) => {
11868
- const [editing, setEditing] = React.useState(false);
11869
- const form = reactHookForm.useForm({
11870
- defaultValues: {
11871
- quantity: item.quantity,
11872
- unit_price: item.unit_price
11873
- },
11874
- resolver: zod.zodResolver(variantItemSchema)
11875
- });
11876
- const actionId = React.useMemo(() => {
11877
- var _a, _b;
11878
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11879
- }, [item]);
11880
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11881
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11882
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11883
- const onSubmit = form.handleSubmit(async (data) => {
11884
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
11885
- setEditing(false);
11886
- return;
11887
- }
11888
- if (!actionId) {
11889
- await updateOriginalItem(
11890
- {
11891
- item_id: item.id,
11892
- quantity: data.quantity,
11893
- unit_price: convertNumber(data.unit_price)
11894
- },
11895
- {
11896
- onSuccess: () => {
11897
- setEditing(false);
11898
- },
11899
- onError: (e) => {
11900
- ui.toast.error(e.message);
11936
+ /* @__PURE__ */ jsxRuntime.jsx(
11937
+ "rect",
11938
+ {
11939
+ x: "0.00428286",
11940
+ y: "-0.742904",
11941
+ width: "33.5",
11942
+ height: "65.5",
11943
+ rx: "6.75",
11944
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11945
+ fill: "white",
11946
+ stroke: "#52525B",
11947
+ strokeWidth: "1.5"
11901
11948
  }
11902
- }
11903
- );
11904
- return;
11905
- }
11906
- await updateActionItem(
11907
- {
11908
- action_id: actionId,
11909
- quantity: data.quantity,
11910
- unit_price: convertNumber(data.unit_price)
11911
- },
11912
- {
11913
- onSuccess: () => {
11914
- setEditing(false);
11915
- },
11916
- onError: (e) => {
11917
- ui.toast.error(e.message);
11918
- }
11919
- }
11920
- );
11921
- });
11922
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.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: [
11923
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
11924
- /* @__PURE__ */ jsxRuntime.jsx(
11925
- Thumbnail,
11926
- {
11927
- thumbnail: item.thumbnail,
11928
- alt: item.product_title ?? void 0
11929
- }
11930
- ),
11931
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11932
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11933
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11934
- /* @__PURE__ */ jsxRuntime.jsxs(
11935
- ui.Text,
11936
- {
11937
- size: "small",
11938
- leading: "compact",
11939
- className: "text-ui-fg-subtle",
11940
- children: [
11941
- "(",
11942
- item.variant_title,
11943
- ")"
11944
- ]
11945
- }
11946
- )
11947
- ] }),
11949
+ ),
11948
11950
  /* @__PURE__ */ jsxRuntime.jsx(
11949
- ui.Text,
11951
+ "path",
11950
11952
  {
11951
- size: "small",
11952
- leading: "compact",
11953
- className: "text-ui-fg-subtle",
11954
- children: item.variant_sku
11953
+ d: "M180.579 107.142L179.126 107.959",
11954
+ stroke: "#52525B",
11955
+ strokeWidth: "1.5",
11956
+ strokeLinecap: "round",
11957
+ strokeLinejoin: "round"
11955
11958
  }
11956
- )
11957
- ] })
11958
- ] }),
11959
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
11960
- Form$2.Field,
11961
- {
11962
- control: form.control,
11963
- name: "quantity",
11964
- render: ({ field }) => {
11965
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
11966
- }
11967
- }
11968
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
11969
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
11970
- Form$2.Field,
11971
- {
11972
- control: form.control,
11973
- name: "unit_price",
11974
- render: ({ field: { onChange, ...field } }) => {
11975
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11976
- ui.CurrencyInput,
11977
- {
11978
- ...field,
11979
- symbol: getNativeSymbol(currencyCode),
11980
- code: currencyCode,
11981
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11982
- }
11983
- ) }) });
11984
- }
11985
- }
11986
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11987
- /* @__PURE__ */ jsxRuntime.jsx(
11988
- ui.IconButton,
11989
- {
11990
- type: "button",
11991
- size: "small",
11992
- onClick: editing ? onSubmit : () => {
11993
- setEditing(true);
11994
- },
11995
- disabled: isPending,
11996
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
11997
- }
11998
- )
11999
- ] }) }) });
12000
- };
12001
- const variantItemSchema = z.object({
12002
- quantity: z.number(),
12003
- unit_price: z.union([z.number(), z.string()])
12004
- });
12005
- const CustomItem = ({ item, preview, currencyCode }) => {
12006
- const [editing, setEditing] = React.useState(false);
12007
- const { quantity, unit_price, title } = item;
12008
- const form = reactHookForm.useForm({
12009
- defaultValues: {
12010
- title,
12011
- quantity,
12012
- unit_price
12013
- },
12014
- resolver: zod.zodResolver(customItemSchema)
12015
- });
12016
- React.useEffect(() => {
12017
- form.reset({
12018
- title,
12019
- quantity,
12020
- unit_price
12021
- });
12022
- }, [form, title, quantity, unit_price]);
12023
- const actionId = React.useMemo(() => {
12024
- var _a, _b;
12025
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12026
- }, [item]);
12027
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12028
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12029
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12030
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12031
- const onSubmit = form.handleSubmit(async (data) => {
12032
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12033
- setEditing(false);
12034
- return;
12035
- }
12036
- if (!actionId) {
12037
- await updateOriginalItem(
12038
- {
12039
- item_id: item.id,
12040
- quantity: data.quantity,
12041
- unit_price: convertNumber(data.unit_price)
12042
- },
12043
- {
12044
- onSuccess: () => {
12045
- setEditing(false);
12046
- },
12047
- onError: (e) => {
12048
- ui.toast.error(e.message);
11959
+ ),
11960
+ /* @__PURE__ */ jsxRuntime.jsx(
11961
+ "path",
11962
+ {
11963
+ opacity: "0.88",
11964
+ d: "M182.305 109.546L180.257 109.534",
11965
+ stroke: "#52525B",
11966
+ strokeWidth: "1.5",
11967
+ strokeLinecap: "round",
11968
+ strokeLinejoin: "round"
12049
11969
  }
12050
- }
12051
- );
12052
- return;
12053
- }
12054
- if (data.quantity === 0) {
12055
- await removeActionItem(actionId, {
12056
- onSuccess: () => {
12057
- setEditing(false);
12058
- },
12059
- onError: (e) => {
12060
- ui.toast.error(e.message);
12061
- }
12062
- });
12063
- return;
12064
- }
12065
- await updateActionItem(
12066
- {
12067
- action_id: actionId,
12068
- quantity: data.quantity,
12069
- unit_price: convertNumber(data.unit_price)
12070
- },
12071
- {
12072
- onSuccess: () => {
12073
- setEditing(false);
12074
- },
12075
- onError: (e) => {
12076
- ui.toast.error(e.message);
12077
- }
12078
- }
12079
- );
12080
- });
12081
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.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: [
12082
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12083
- /* @__PURE__ */ jsxRuntime.jsx(
12084
- Thumbnail,
12085
- {
12086
- thumbnail: item.thumbnail,
12087
- alt: item.title ?? void 0
12088
- }
12089
- ),
12090
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12091
- Form$2.Field,
12092
- {
12093
- control: form.control,
12094
- name: "title",
12095
- render: ({ field }) => {
12096
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
11970
+ ),
11971
+ /* @__PURE__ */ jsxRuntime.jsx(
11972
+ "path",
11973
+ {
11974
+ opacity: "0.75",
11975
+ d: "M180.551 111.93L179.108 111.096",
11976
+ stroke: "#52525B",
11977
+ strokeWidth: "1.5",
11978
+ strokeLinecap: "round",
11979
+ strokeLinejoin: "round"
12097
11980
  }
12098
- }
12099
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
12100
- ] }),
12101
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12102
- Form$2.Field,
12103
- {
12104
- control: form.control,
12105
- name: "quantity",
12106
- render: ({ field }) => {
12107
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12108
- }
12109
- }
12110
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
12111
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
12112
- Form$2.Field,
12113
- {
12114
- control: form.control,
12115
- name: "unit_price",
12116
- render: ({ field: { onChange, ...field } }) => {
12117
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12118
- ui.CurrencyInput,
12119
- {
12120
- ...field,
12121
- symbol: getNativeSymbol(currencyCode),
12122
- code: currencyCode,
12123
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12124
- }
12125
- ) }) });
12126
- }
12127
- }
12128
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12129
- /* @__PURE__ */ jsxRuntime.jsx(
12130
- ui.IconButton,
12131
- {
12132
- type: "button",
12133
- size: "small",
12134
- onClick: editing ? onSubmit : () => {
12135
- setEditing(true);
12136
- },
12137
- disabled: isPending,
12138
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12139
- }
12140
- )
12141
- ] }) }) });
12142
- };
12143
- const StackedModalTrigger = ({
12144
- type,
12145
- setModalContent
12146
- }) => {
12147
- const { setIsOpen } = useStackedModal();
12148
- const onClick = React.useCallback(() => {
12149
- setModalContent(type);
12150
- setIsOpen(STACKED_MODAL_ID, true);
12151
- }, [setModalContent, setIsOpen, type]);
12152
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12153
- };
12154
- const VARIANT_PREFIX = "items";
12155
- const LIMIT = 50;
12156
- const ExistingItemsForm = ({ orderId, items }) => {
12157
- const { setIsOpen } = useStackedModal();
12158
- const [rowSelection, setRowSelection] = React.useState(
12159
- items.reduce((acc, item) => {
12160
- acc[item.variant_id] = true;
12161
- return acc;
12162
- }, {})
12163
- );
12164
- React.useEffect(() => {
12165
- setRowSelection(
12166
- items.reduce((acc, item) => {
12167
- if (item.variant_id) {
12168
- acc[item.variant_id] = true;
12169
- }
12170
- return acc;
12171
- }, {})
12172
- );
12173
- }, [items]);
12174
- const { q, order, offset } = useQueryParams(
12175
- ["q", "order", "offset"],
12176
- VARIANT_PREFIX
12177
- );
12178
- const { variants, count, isPending, isError, error } = useProductVariants(
12179
- {
12180
- q,
12181
- order,
12182
- offset: offset ? parseInt(offset) : void 0,
12183
- limit: LIMIT
12184
- },
12185
- {
12186
- placeholderData: reactQuery.keepPreviousData
12187
- }
12188
- );
12189
- const columns = useColumns();
12190
- const { mutateAsync } = useDraftOrderAddItems(orderId);
12191
- const onSubmit = async () => {
12192
- const ids = Object.keys(rowSelection).filter(
12193
- (id) => !items.find((i) => i.variant_id === id)
12194
- );
12195
- await mutateAsync(
12196
- {
12197
- items: ids.map((id) => ({
12198
- variant_id: id,
12199
- quantity: 1
12200
- }))
12201
- },
12202
- {
12203
- onSuccess: () => {
12204
- setRowSelection({});
12205
- setIsOpen(STACKED_MODAL_ID, false);
12206
- },
12207
- onError: (e) => {
12208
- ui.toast.error(e.message);
12209
- }
12210
- }
12211
- );
12212
- };
12213
- if (isError) {
12214
- throw error;
12215
- }
12216
- return /* @__PURE__ */ jsxRuntime.jsxs(
12217
- StackedFocusModal.Content,
12218
- {
12219
- onOpenAutoFocus: (e) => {
12220
- e.preventDefault();
12221
- const searchInput = document.querySelector(
12222
- "[data-modal-id='modal-search-input']"
12223
- );
12224
- if (searchInput) {
12225
- searchInput.focus();
12226
- }
12227
- },
12228
- children: [
12229
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
12230
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12231
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12232
- ] }),
12233
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
12234
- DataTable,
11981
+ ),
11982
+ /* @__PURE__ */ jsxRuntime.jsx(
11983
+ "path",
12235
11984
  {
12236
- data: variants,
12237
- columns,
12238
- isLoading: isPending,
12239
- getRowId: (row) => row.id,
12240
- rowCount: count,
12241
- prefix: VARIANT_PREFIX,
12242
- layout: "fill",
12243
- rowSelection: {
12244
- state: rowSelection,
12245
- onRowSelectionChange: setRowSelection,
12246
- enableRowSelection: (row) => {
12247
- return !items.find((i) => i.variant_id === row.original.id);
12248
- }
12249
- },
12250
- autoFocusSearch: true
11985
+ opacity: "0.63",
11986
+ d: "M176.347 112.897L176.354 111.73",
11987
+ stroke: "#52525B",
11988
+ strokeWidth: "1.5",
11989
+ strokeLinecap: "round",
11990
+ strokeLinejoin: "round"
12251
11991
  }
12252
- ) }),
12253
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12254
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12255
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12256
- ] }) })
12257
- ]
12258
- }
12259
- );
12260
- };
12261
- const columnHelper = ui.createDataTableColumnHelper();
12262
- const useColumns = () => {
12263
- return React.useMemo(() => {
12264
- return [
12265
- columnHelper.select(),
12266
- columnHelper.accessor("product.title", {
12267
- header: "Product",
12268
- cell: ({ row }) => {
12269
- var _a, _b, _c;
12270
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
12271
- /* @__PURE__ */ jsxRuntime.jsx(
12272
- Thumbnail,
12273
- {
12274
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12275
- alt: (_b = row.original.product) == null ? void 0 : _b.title
12276
- }
12277
- ),
12278
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12279
- ] });
12280
- },
12281
- enableSorting: true
12282
- }),
12283
- columnHelper.accessor("title", {
12284
- header: "Variant",
12285
- enableSorting: true
12286
- }),
12287
- columnHelper.accessor("sku", {
12288
- header: "SKU",
12289
- cell: ({ getValue }) => {
12290
- return getValue() ?? "-";
12291
- },
12292
- enableSorting: true
12293
- }),
12294
- columnHelper.accessor("updated_at", {
12295
- header: "Updated",
12296
- cell: ({ getValue }) => {
12297
- return /* @__PURE__ */ jsxRuntime.jsx(
12298
- ui.Tooltip,
12299
- {
12300
- content: getFullDate({ date: getValue(), includeTime: true }),
12301
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
12302
- }
12303
- );
12304
- },
12305
- enableSorting: true,
12306
- sortAscLabel: "Oldest first",
12307
- sortDescLabel: "Newest first"
12308
- }),
12309
- columnHelper.accessor("created_at", {
12310
- header: "Created",
12311
- cell: ({ getValue }) => {
12312
- return /* @__PURE__ */ jsxRuntime.jsx(
12313
- ui.Tooltip,
12314
- {
12315
- content: getFullDate({ date: getValue(), includeTime: true }),
12316
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
12317
- }
12318
- );
12319
- },
12320
- enableSorting: true,
12321
- sortAscLabel: "Oldest first",
12322
- sortDescLabel: "Newest first"
12323
- })
12324
- ];
12325
- }, []);
12326
- };
12327
- const CustomItemForm = ({ orderId, currencyCode }) => {
12328
- const { setIsOpen } = useStackedModal();
12329
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12330
- const form = reactHookForm.useForm({
12331
- defaultValues: {
12332
- title: "",
12333
- quantity: 1,
12334
- unit_price: ""
12335
- },
12336
- resolver: zod.zodResolver(customItemSchema)
12337
- });
12338
- const onSubmit = form.handleSubmit(async (data) => {
12339
- await addItems(
12340
- {
12341
- items: [
11992
+ ),
11993
+ /* @__PURE__ */ jsxRuntime.jsx(
11994
+ "path",
12342
11995
  {
12343
- title: data.title,
12344
- quantity: data.quantity,
12345
- unit_price: convertNumber(data.unit_price)
12346
- }
12347
- ]
12348
- },
12349
- {
12350
- onSuccess: () => {
12351
- setIsOpen(STACKED_MODAL_ID, false);
12352
- },
12353
- onError: (e) => {
12354
- ui.toast.error(e.message);
12355
- }
12356
- }
12357
- );
12358
- });
12359
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
12360
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12361
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
12362
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12363
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
12364
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
12365
- ] }),
12366
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12367
- /* @__PURE__ */ jsxRuntime.jsx(
12368
- Form$2.Field,
12369
- {
12370
- control: form.control,
12371
- name: "title",
12372
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12373
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12374
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
12375
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
12376
- ] }),
12377
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12378
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12379
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12380
- ] })
12381
- ] }) })
12382
- }
12383
- ),
12384
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12385
- /* @__PURE__ */ jsxRuntime.jsx(
12386
- Form$2.Field,
12387
- {
12388
- control: form.control,
12389
- name: "unit_price",
12390
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12391
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12392
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
12393
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12394
- ] }),
12395
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12396
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12397
- ui.CurrencyInput,
12398
- {
12399
- symbol: getNativeSymbol(currencyCode),
12400
- code: currencyCode,
12401
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12402
- ...field
12403
- }
12404
- ) }),
12405
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12406
- ] })
12407
- ] }) })
12408
- }
12409
- ),
12410
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12411
- /* @__PURE__ */ jsxRuntime.jsx(
12412
- Form$2.Field,
12413
- {
12414
- control: form.control,
12415
- name: "quantity",
12416
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12417
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12418
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
12419
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
12420
- ] }),
12421
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
12422
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
12423
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12424
- ] })
12425
- ] }) })
12426
- }
12427
- )
12428
- ] }) }) }),
12429
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12430
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12431
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
12432
- ] }) })
12433
- ] }) }) });
12434
- };
12435
- const customItemSchema = z.object({
12436
- title: z.string().min(1),
12437
- quantity: z.number(),
12438
- unit_price: z.union([z.number(), z.string()])
12439
- });
12440
- const ShippingAddress = () => {
12441
- const { id } = reactRouterDom.useParams();
12442
- const { order, isPending, isError, error } = useOrder(id, {
12443
- fields: "+shipping_address"
12444
- });
12445
- if (isError) {
12446
- throw error;
12447
- }
12448
- const isReady = !isPending && !!order;
12449
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12450
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12451
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12452
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12453
- ] }),
12454
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12455
- ] });
12456
- };
12457
- const ShippingAddressForm = ({ order }) => {
12458
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12459
- const form = reactHookForm.useForm({
12460
- defaultValues: {
12461
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12462
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12463
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12464
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12465
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12466
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12467
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12468
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12469
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12470
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12471
- },
12472
- resolver: zod.zodResolver(schema$2)
12473
- });
12474
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12475
- const { handleSuccess } = useRouteModal();
12476
- const onSubmit = form.handleSubmit(async (data) => {
12477
- await mutateAsync(
12478
- {
12479
- shipping_address: {
12480
- first_name: data.first_name,
12481
- last_name: data.last_name,
12482
- company: data.company,
12483
- address_1: data.address_1,
12484
- address_2: data.address_2,
12485
- city: data.city,
12486
- province: data.province,
12487
- country_code: data.country_code,
12488
- postal_code: data.postal_code,
12489
- phone: data.phone
12490
- }
12491
- },
12492
- {
12493
- onSuccess: () => {
12494
- handleSuccess();
12495
- },
12496
- onError: (error) => {
12497
- ui.toast.error(error.message);
12498
- }
12499
- }
12500
- );
12501
- });
12502
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12503
- KeyboundForm,
12504
- {
12505
- className: "flex flex-1 flex-col overflow-hidden",
12506
- onSubmit,
12507
- children: [
12508
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12509
- /* @__PURE__ */ jsxRuntime.jsx(
12510
- Form$2.Field,
12511
- {
12512
- control: form.control,
12513
- name: "country_code",
12514
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12515
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12516
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12517
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12518
- ] })
12519
- }
12520
- ),
12521
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12522
- /* @__PURE__ */ jsxRuntime.jsx(
12523
- Form$2.Field,
12524
- {
12525
- control: form.control,
12526
- name: "first_name",
12527
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12528
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12529
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12530
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12531
- ] })
12532
- }
12533
- ),
12534
- /* @__PURE__ */ jsxRuntime.jsx(
12535
- Form$2.Field,
12536
- {
12537
- control: form.control,
12538
- name: "last_name",
12539
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12541
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12542
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12543
- ] })
12544
- }
12545
- )
12546
- ] }),
12547
- /* @__PURE__ */ jsxRuntime.jsx(
12548
- Form$2.Field,
12549
- {
12550
- control: form.control,
12551
- name: "company",
12552
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12553
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12554
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12555
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12556
- ] })
12557
- }
12558
- ),
12559
- /* @__PURE__ */ jsxRuntime.jsx(
12560
- Form$2.Field,
12561
- {
12562
- control: form.control,
12563
- name: "address_1",
12564
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12565
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12566
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12567
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12568
- ] })
12569
- }
12570
- ),
12571
- /* @__PURE__ */ jsxRuntime.jsx(
12572
- Form$2.Field,
12573
- {
12574
- control: form.control,
12575
- name: "address_2",
12576
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12577
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12578
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12579
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12580
- ] })
12581
- }
12582
- ),
12583
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12584
- /* @__PURE__ */ jsxRuntime.jsx(
12585
- Form$2.Field,
12586
- {
12587
- control: form.control,
12588
- name: "postal_code",
12589
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12590
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12591
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12592
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12593
- ] })
12594
- }
12595
- ),
12596
- /* @__PURE__ */ jsxRuntime.jsx(
12597
- Form$2.Field,
12598
- {
12599
- control: form.control,
12600
- name: "city",
12601
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12602
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12603
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12604
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12605
- ] })
12606
- }
12607
- )
12608
- ] }),
12609
- /* @__PURE__ */ jsxRuntime.jsx(
12610
- Form$2.Field,
12611
- {
12612
- control: form.control,
12613
- name: "province",
12614
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12615
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12616
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12617
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12618
- ] })
12619
- }
12620
- ),
12621
- /* @__PURE__ */ jsxRuntime.jsx(
12622
- Form$2.Field,
12623
- {
12624
- control: form.control,
12625
- name: "phone",
12626
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12627
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12628
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12629
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12630
- ] })
12631
- }
12632
- )
12633
- ] }) }),
12634
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12635
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12636
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12637
- ] }) })
12638
- ]
12639
- }
12640
- ) });
12641
- };
12642
- const schema$2 = addressSchema;
12643
- const TransferOwnership = () => {
12644
- const { id } = reactRouterDom.useParams();
12645
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12646
- fields: "id,customer_id,customer.*"
12647
- });
12648
- if (isError) {
12649
- throw error;
12650
- }
12651
- const isReady = !isPending && !!draft_order;
12652
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12653
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12654
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12655
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12656
- ] }),
12657
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12658
- ] });
12659
- };
12660
- const TransferOwnershipForm = ({ order }) => {
12661
- var _a, _b;
12662
- const form = reactHookForm.useForm({
12663
- defaultValues: {
12664
- customer_id: order.customer_id || ""
12665
- },
12666
- resolver: zod.zodResolver(schema$1)
12667
- });
12668
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12669
- const { handleSuccess } = useRouteModal();
12670
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12671
- const currentCustomer = order.customer ? {
12672
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12673
- value: order.customer.id
12674
- } : null;
12675
- const onSubmit = form.handleSubmit(async (data) => {
12676
- await mutateAsync(
12677
- { customer_id: data.customer_id },
12678
- {
12679
- onSuccess: () => {
12680
- ui.toast.success("Customer updated");
12681
- handleSuccess();
12682
- },
12683
- onError: (error) => {
12684
- ui.toast.error(error.message);
12685
- }
12686
- }
12687
- );
12688
- });
12689
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12690
- KeyboundForm,
12691
- {
12692
- className: "flex flex-1 flex-col overflow-hidden",
12693
- onSubmit,
12694
- children: [
12695
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12696
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12697
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12698
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12699
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12700
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12701
- ] }),
12702
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12703
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12704
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12705
- ] })
12706
- ] }),
12707
- /* @__PURE__ */ jsxRuntime.jsx(
12708
- CustomerField,
12709
- {
12710
- control: form.control,
12711
- currentCustomerId: order.customer_id
12712
- }
12713
- )
12714
- ] }),
12715
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12716
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12717
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12718
- ] }) })
12719
- ]
12720
- }
12721
- ) });
12722
- };
12723
- const CustomerField = ({ control, currentCustomerId }) => {
12724
- const customers = useComboboxData({
12725
- queryFn: async (params) => {
12726
- return await sdk.admin.customer.list({
12727
- ...params,
12728
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12729
- });
12730
- },
12731
- queryKey: ["customers"],
12732
- getOptions: (data) => {
12733
- return data.customers.map((customer) => {
12734
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12735
- return {
12736
- label: name ? `${name} (${customer.email})` : customer.email,
12737
- value: customer.id
12738
- };
12739
- });
12740
- }
12741
- });
12742
- return /* @__PURE__ */ jsxRuntime.jsx(
12743
- Form$2.Field,
12744
- {
12745
- name: "customer_id",
12746
- control,
12747
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12748
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12751
- ] }),
12752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12753
- Combobox,
12754
- {
12755
- options: customers.options,
12756
- fetchNextPage: customers.fetchNextPage,
12757
- isFetchingNextPage: customers.isFetchingNextPage,
12758
- searchValue: customers.searchValue,
12759
- onSearchValueChange: customers.onSearchValueChange,
12760
- placeholder: "Select customer",
12761
- ...field
12762
- }
12763
- ) }),
12764
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12765
- ] })
12766
- }
12767
- );
12768
- };
12769
- const Illustration = () => {
12770
- return /* @__PURE__ */ jsxRuntime.jsxs(
12771
- "svg",
12772
- {
12773
- width: "280",
12774
- height: "180",
12775
- viewBox: "0 0 280 180",
12776
- fill: "none",
12777
- xmlns: "http://www.w3.org/2000/svg",
12778
- children: [
12779
- /* @__PURE__ */ jsxRuntime.jsx(
12780
- "rect",
12781
- {
12782
- x: "0.00428286",
12783
- y: "-0.742904",
12784
- width: "33.5",
12785
- height: "65.5",
12786
- rx: "6.75",
12787
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12788
- fill: "#D4D4D8",
12789
- stroke: "#52525B",
12790
- strokeWidth: "1.5"
12791
- }
12792
- ),
12793
- /* @__PURE__ */ jsxRuntime.jsx(
12794
- "rect",
12795
- {
12796
- x: "0.00428286",
12797
- y: "-0.742904",
12798
- width: "33.5",
12799
- height: "65.5",
12800
- rx: "6.75",
12801
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12802
- fill: "white",
12803
- stroke: "#52525B",
12804
- strokeWidth: "1.5"
12805
- }
12806
- ),
12807
- /* @__PURE__ */ jsxRuntime.jsx(
12808
- "path",
12809
- {
12810
- d: "M180.579 107.142L179.126 107.959",
12811
- stroke: "#52525B",
12812
- strokeWidth: "1.5",
12813
- strokeLinecap: "round",
12814
- strokeLinejoin: "round"
12815
- }
12816
- ),
12817
- /* @__PURE__ */ jsxRuntime.jsx(
12818
- "path",
12819
- {
12820
- opacity: "0.88",
12821
- d: "M182.305 109.546L180.257 109.534",
12822
- stroke: "#52525B",
12823
- strokeWidth: "1.5",
12824
- strokeLinecap: "round",
12825
- strokeLinejoin: "round"
12826
- }
12827
- ),
12828
- /* @__PURE__ */ jsxRuntime.jsx(
12829
- "path",
12830
- {
12831
- opacity: "0.75",
12832
- d: "M180.551 111.93L179.108 111.096",
12833
- stroke: "#52525B",
12834
- strokeWidth: "1.5",
12835
- strokeLinecap: "round",
12836
- strokeLinejoin: "round"
12837
- }
12838
- ),
12839
- /* @__PURE__ */ jsxRuntime.jsx(
12840
- "path",
12841
- {
12842
- opacity: "0.63",
12843
- d: "M176.347 112.897L176.354 111.73",
12844
- stroke: "#52525B",
12845
- strokeWidth: "1.5",
12846
- strokeLinecap: "round",
12847
- strokeLinejoin: "round"
12848
- }
12849
- ),
12850
- /* @__PURE__ */ jsxRuntime.jsx(
12851
- "path",
12852
- {
12853
- opacity: "0.5",
12854
- d: "M172.153 111.881L173.606 111.064",
12855
- stroke: "#52525B",
12856
- strokeWidth: "1.5",
12857
- strokeLinecap: "round",
12858
- strokeLinejoin: "round"
11996
+ opacity: "0.5",
11997
+ d: "M172.153 111.881L173.606 111.064",
11998
+ stroke: "#52525B",
11999
+ strokeWidth: "1.5",
12000
+ strokeLinecap: "round",
12001
+ strokeLinejoin: "round"
12859
12002
  }
12860
12003
  ),
12861
12004
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -12975,214 +12118,1071 @@ const Illustration = () => {
12975
12118
  transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12976
12119
  fill: "#A1A1AA"
12977
12120
  }
12978
- ),
12979
- /* @__PURE__ */ jsxRuntime.jsx(
12980
- "rect",
12981
- {
12982
- width: "12",
12983
- height: "3",
12984
- rx: "1.5",
12985
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12986
- fill: "#A1A1AA"
12121
+ ),
12122
+ /* @__PURE__ */ jsxRuntime.jsx(
12123
+ "rect",
12124
+ {
12125
+ width: "12",
12126
+ height: "3",
12127
+ rx: "1.5",
12128
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12129
+ fill: "#A1A1AA"
12130
+ }
12131
+ ),
12132
+ /* @__PURE__ */ jsxRuntime.jsx(
12133
+ "path",
12134
+ {
12135
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12136
+ fill: "#52525B"
12137
+ }
12138
+ ),
12139
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12140
+ "path",
12141
+ {
12142
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12143
+ stroke: "#A1A1AA",
12144
+ strokeWidth: "1.5",
12145
+ strokeLinecap: "round",
12146
+ strokeLinejoin: "round"
12147
+ }
12148
+ ) }),
12149
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12150
+ "path",
12151
+ {
12152
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12153
+ stroke: "#A1A1AA",
12154
+ strokeWidth: "1.5",
12155
+ strokeLinecap: "round",
12156
+ strokeLinejoin: "round"
12157
+ }
12158
+ ) }),
12159
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12160
+ "path",
12161
+ {
12162
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12163
+ stroke: "#A1A1AA",
12164
+ strokeWidth: "1.5",
12165
+ strokeLinecap: "round",
12166
+ strokeLinejoin: "round"
12167
+ }
12168
+ ) }),
12169
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12170
+ "path",
12171
+ {
12172
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12173
+ stroke: "#A1A1AA",
12174
+ strokeWidth: "1.5",
12175
+ strokeLinecap: "round",
12176
+ strokeLinejoin: "round"
12177
+ }
12178
+ ) }),
12179
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12180
+ "path",
12181
+ {
12182
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12183
+ stroke: "#A1A1AA",
12184
+ strokeWidth: "1.5",
12185
+ strokeLinecap: "round",
12186
+ strokeLinejoin: "round"
12187
+ }
12188
+ ) }),
12189
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12190
+ "path",
12191
+ {
12192
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12193
+ stroke: "#A1A1AA",
12194
+ strokeWidth: "1.5",
12195
+ strokeLinecap: "round",
12196
+ strokeLinejoin: "round"
12197
+ }
12198
+ ) }),
12199
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12200
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12201
+ "rect",
12202
+ {
12203
+ width: "12",
12204
+ height: "12",
12205
+ fill: "white",
12206
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12207
+ }
12208
+ ) }),
12209
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12210
+ "rect",
12211
+ {
12212
+ width: "12",
12213
+ height: "12",
12214
+ fill: "white",
12215
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12216
+ }
12217
+ ) }),
12218
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12219
+ "rect",
12220
+ {
12221
+ width: "12",
12222
+ height: "12",
12223
+ fill: "white",
12224
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12225
+ }
12226
+ ) }),
12227
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12228
+ "rect",
12229
+ {
12230
+ width: "12",
12231
+ height: "12",
12232
+ fill: "white",
12233
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12234
+ }
12235
+ ) }),
12236
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12237
+ "rect",
12238
+ {
12239
+ width: "12",
12240
+ height: "12",
12241
+ fill: "white",
12242
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12243
+ }
12244
+ ) }),
12245
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12246
+ "rect",
12247
+ {
12248
+ width: "12",
12249
+ height: "12",
12250
+ fill: "white",
12251
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12252
+ }
12253
+ ) })
12254
+ ] })
12255
+ ]
12256
+ }
12257
+ );
12258
+ };
12259
+ const schema = z.object({
12260
+ customer_id: z.string().min(1)
12261
+ });
12262
+ const NumberInput = React.forwardRef(
12263
+ ({
12264
+ value,
12265
+ onChange,
12266
+ size = "base",
12267
+ min = 0,
12268
+ max = 100,
12269
+ step = 1,
12270
+ className,
12271
+ disabled,
12272
+ ...props
12273
+ }, ref) => {
12274
+ const handleChange = (event) => {
12275
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
12276
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
12277
+ onChange(newValue);
12278
+ }
12279
+ };
12280
+ const handleIncrement = () => {
12281
+ const newValue = value + step;
12282
+ if (max === void 0 || newValue <= max) {
12283
+ onChange(newValue);
12284
+ }
12285
+ };
12286
+ const handleDecrement = () => {
12287
+ const newValue = value - step;
12288
+ if (min === void 0 || newValue >= min) {
12289
+ onChange(newValue);
12290
+ }
12291
+ };
12292
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12293
+ "div",
12294
+ {
12295
+ className: ui.clx(
12296
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
12297
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
12298
+ {
12299
+ "h-7": size === "small",
12300
+ "h-8": size === "base"
12301
+ },
12302
+ className
12303
+ ),
12304
+ children: [
12305
+ /* @__PURE__ */ jsxRuntime.jsx(
12306
+ "input",
12307
+ {
12308
+ ref,
12309
+ type: "number",
12310
+ value,
12311
+ onChange: handleChange,
12312
+ min,
12313
+ max,
12314
+ step,
12315
+ className: ui.clx(
12316
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
12317
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
12318
+ "placeholder:text-ui-fg-muted"
12319
+ ),
12320
+ ...props
12321
+ }
12322
+ ),
12323
+ /* @__PURE__ */ jsxRuntime.jsxs(
12324
+ "button",
12325
+ {
12326
+ className: ui.clx(
12327
+ "flex items-center justify-center outline-none transition-fg",
12328
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12329
+ "focus:bg-ui-bg-field-component-hover",
12330
+ "hover:bg-ui-bg-field-component-hover",
12331
+ {
12332
+ "size-7": size === "small",
12333
+ "size-8": size === "base"
12334
+ }
12335
+ ),
12336
+ type: "button",
12337
+ onClick: handleDecrement,
12338
+ disabled: min !== void 0 && value <= min || disabled,
12339
+ children: [
12340
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
12341
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12342
+ ]
12343
+ }
12344
+ ),
12345
+ /* @__PURE__ */ jsxRuntime.jsxs(
12346
+ "button",
12347
+ {
12348
+ className: ui.clx(
12349
+ "flex items-center justify-center outline-none transition-fg",
12350
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12351
+ "focus:bg-ui-bg-field-hover",
12352
+ "hover:bg-ui-bg-field-hover",
12353
+ {
12354
+ "size-7": size === "small",
12355
+ "size-8": size === "base"
12356
+ }
12357
+ ),
12358
+ type: "button",
12359
+ onClick: handleIncrement,
12360
+ disabled: max !== void 0 && value >= max || disabled,
12361
+ children: [
12362
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
12363
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12364
+ ]
12365
+ }
12366
+ )
12367
+ ]
12368
+ }
12369
+ );
12370
+ }
12371
+ );
12372
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12373
+ const productVariantsQueryKeys = {
12374
+ list: (query2) => [
12375
+ PRODUCT_VARIANTS_QUERY_KEY,
12376
+ query2 ? query2 : void 0
12377
+ ]
12378
+ };
12379
+ const useProductVariants = (query2, options) => {
12380
+ const { data, ...rest } = reactQuery.useQuery({
12381
+ queryKey: productVariantsQueryKeys.list(query2),
12382
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
12383
+ ...options
12384
+ });
12385
+ return { ...data, ...rest };
12386
+ };
12387
+ const STACKED_MODAL_ID = "items_stacked_modal";
12388
+ const Items = () => {
12389
+ const { id } = reactRouterDom.useParams();
12390
+ const {
12391
+ order: preview,
12392
+ isPending: isPreviewPending,
12393
+ isError: isPreviewError,
12394
+ error: previewError
12395
+ } = useOrderPreview(id, void 0, {
12396
+ placeholderData: reactQuery.keepPreviousData
12397
+ });
12398
+ useInitiateOrderEdit({ preview });
12399
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12400
+ id,
12401
+ {
12402
+ fields: "currency_code"
12403
+ },
12404
+ {
12405
+ enabled: !!id
12406
+ }
12407
+ );
12408
+ const { onCancel } = useCancelOrderEdit({ preview });
12409
+ if (isError) {
12410
+ throw error;
12411
+ }
12412
+ if (isPreviewError) {
12413
+ throw previewError;
12414
+ }
12415
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12416
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12417
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12418
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12419
+ ] }) });
12420
+ };
12421
+ const ItemsForm = ({ preview, currencyCode }) => {
12422
+ var _a;
12423
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12424
+ const [modalContent, setModalContent] = React.useState(
12425
+ null
12426
+ );
12427
+ const { handleSuccess } = useRouteModal();
12428
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12429
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12430
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12431
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12432
+ const matches = React.useMemo(() => {
12433
+ return matchSorter.matchSorter(preview.items, query2, {
12434
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
12435
+ });
12436
+ }, [preview.items, query2]);
12437
+ const onSubmit = async () => {
12438
+ setIsSubmitting(true);
12439
+ let requestSucceeded = false;
12440
+ await requestOrderEdit(void 0, {
12441
+ onError: (e) => {
12442
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12443
+ },
12444
+ onSuccess: () => {
12445
+ requestSucceeded = true;
12446
+ }
12447
+ });
12448
+ if (!requestSucceeded) {
12449
+ setIsSubmitting(false);
12450
+ return;
12451
+ }
12452
+ await confirmOrderEdit(void 0, {
12453
+ onError: (e) => {
12454
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12455
+ },
12456
+ onSuccess: () => {
12457
+ handleSuccess();
12458
+ },
12459
+ onSettled: () => {
12460
+ setIsSubmitting(false);
12461
+ }
12462
+ });
12463
+ };
12464
+ const onKeyDown = React.useCallback(
12465
+ (e) => {
12466
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12467
+ if (modalContent || isSubmitting) {
12468
+ return;
12469
+ }
12470
+ onSubmit();
12471
+ }
12472
+ },
12473
+ [modalContent, isSubmitting, onSubmit]
12474
+ );
12475
+ React.useEffect(() => {
12476
+ document.addEventListener("keydown", onKeyDown);
12477
+ return () => {
12478
+ document.removeEventListener("keydown", onKeyDown);
12479
+ };
12480
+ }, [onKeyDown]);
12481
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12482
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
12484
+ StackedFocusModal,
12485
+ {
12486
+ id: STACKED_MODAL_ID,
12487
+ onOpenChangeCallback: (open) => {
12488
+ if (!open) {
12489
+ setModalContent(null);
12490
+ }
12491
+ },
12492
+ children: [
12493
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
12494
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12495
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
12496
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order." }) })
12497
+ ] }),
12498
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12499
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12500
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12501
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12502
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12503
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12504
+ ] }),
12505
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
12506
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
12507
+ ui.Input,
12508
+ {
12509
+ type: "search",
12510
+ placeholder: "Search items",
12511
+ value: searchValue,
12512
+ onChange: (e) => onSearchValueChange(e.target.value)
12513
+ }
12514
+ ) }),
12515
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12516
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
12517
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12518
+ /* @__PURE__ */ jsxRuntime.jsx(
12519
+ StackedModalTrigger,
12520
+ {
12521
+ type: "add-items",
12522
+ setModalContent
12523
+ }
12524
+ ),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(
12526
+ StackedModalTrigger,
12527
+ {
12528
+ type: "add-custom-item",
12529
+ setModalContent
12530
+ }
12531
+ )
12532
+ ] })
12533
+ ] })
12534
+ ] })
12535
+ ] }),
12536
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12537
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
12538
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12539
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12540
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
12541
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
12542
+ ] }) }),
12543
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12544
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12546
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
12547
+ Item,
12548
+ {
12549
+ item,
12550
+ preview,
12551
+ currencyCode
12552
+ },
12553
+ item.id
12554
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12555
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12556
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12557
+ 'No items found for "',
12558
+ query2,
12559
+ '".'
12560
+ ] })
12561
+ ] }) })
12562
+ ] })
12563
+ ] }),
12564
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12565
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12566
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12567
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
12568
+ ui.Text,
12569
+ {
12570
+ size: "small",
12571
+ leading: "compact",
12572
+ className: "text-ui-fg-subtle",
12573
+ children: [
12574
+ itemCount,
12575
+ " ",
12576
+ itemCount === 1 ? "item" : "items"
12577
+ ]
12578
+ }
12579
+ ) }),
12580
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
12581
+ ] })
12582
+ ] }) }),
12583
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
12584
+ CustomItemForm,
12585
+ {
12586
+ orderId: preview.id,
12587
+ currencyCode
12588
+ }
12589
+ ) : null)
12590
+ ]
12591
+ }
12592
+ ) }),
12593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
12594
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12595
+ /* @__PURE__ */ jsxRuntime.jsx(
12596
+ ui.Button,
12597
+ {
12598
+ size: "small",
12599
+ type: "button",
12600
+ onClick: onSubmit,
12601
+ isLoading: isSubmitting,
12602
+ children: "Save"
12603
+ }
12604
+ )
12605
+ ] }) })
12606
+ ] });
12607
+ };
12608
+ const Item = ({ item, preview, currencyCode }) => {
12609
+ if (item.variant_id) {
12610
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
12611
+ }
12612
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
12613
+ };
12614
+ const VariantItem = ({ item, preview, currencyCode }) => {
12615
+ const [editing, setEditing] = React.useState(false);
12616
+ const form = reactHookForm.useForm({
12617
+ defaultValues: {
12618
+ quantity: item.quantity,
12619
+ unit_price: item.unit_price
12620
+ },
12621
+ resolver: zod.zodResolver(variantItemSchema)
12622
+ });
12623
+ const actionId = React.useMemo(() => {
12624
+ var _a, _b;
12625
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12626
+ }, [item]);
12627
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12628
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12629
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12630
+ const onSubmit = form.handleSubmit(async (data) => {
12631
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12632
+ setEditing(false);
12633
+ return;
12634
+ }
12635
+ if (!actionId) {
12636
+ await updateOriginalItem(
12637
+ {
12638
+ item_id: item.id,
12639
+ quantity: data.quantity,
12640
+ unit_price: convertNumber(data.unit_price)
12641
+ },
12642
+ {
12643
+ onSuccess: () => {
12644
+ setEditing(false);
12645
+ },
12646
+ onError: (e) => {
12647
+ ui.toast.error(e.message);
12987
12648
  }
12988
- ),
12649
+ }
12650
+ );
12651
+ return;
12652
+ }
12653
+ await updateActionItem(
12654
+ {
12655
+ action_id: actionId,
12656
+ quantity: data.quantity,
12657
+ unit_price: convertNumber(data.unit_price)
12658
+ },
12659
+ {
12660
+ onSuccess: () => {
12661
+ setEditing(false);
12662
+ },
12663
+ onError: (e) => {
12664
+ ui.toast.error(e.message);
12665
+ }
12666
+ }
12667
+ );
12668
+ });
12669
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.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: [
12670
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
12671
+ /* @__PURE__ */ jsxRuntime.jsx(
12672
+ Thumbnail,
12673
+ {
12674
+ thumbnail: item.thumbnail,
12675
+ alt: item.product_title ?? void 0
12676
+ }
12677
+ ),
12678
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12679
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12680
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12681
+ /* @__PURE__ */ jsxRuntime.jsxs(
12682
+ ui.Text,
12683
+ {
12684
+ size: "small",
12685
+ leading: "compact",
12686
+ className: "text-ui-fg-subtle",
12687
+ children: [
12688
+ "(",
12689
+ item.variant_title,
12690
+ ")"
12691
+ ]
12692
+ }
12693
+ )
12694
+ ] }),
12989
12695
  /* @__PURE__ */ jsxRuntime.jsx(
12990
- "path",
12991
- {
12992
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12993
- fill: "#52525B"
12994
- }
12995
- ),
12996
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12997
- "path",
12998
- {
12999
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
13000
- stroke: "#A1A1AA",
13001
- strokeWidth: "1.5",
13002
- strokeLinecap: "round",
13003
- strokeLinejoin: "round"
13004
- }
13005
- ) }),
13006
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13007
- "path",
13008
- {
13009
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
13010
- stroke: "#A1A1AA",
13011
- strokeWidth: "1.5",
13012
- strokeLinecap: "round",
13013
- strokeLinejoin: "round"
13014
- }
13015
- ) }),
13016
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13017
- "path",
13018
- {
13019
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
13020
- stroke: "#A1A1AA",
13021
- strokeWidth: "1.5",
13022
- strokeLinecap: "round",
13023
- strokeLinejoin: "round"
13024
- }
13025
- ) }),
13026
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13027
- "path",
12696
+ ui.Text,
13028
12697
  {
13029
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
13030
- stroke: "#A1A1AA",
13031
- strokeWidth: "1.5",
13032
- strokeLinecap: "round",
13033
- strokeLinejoin: "round"
12698
+ size: "small",
12699
+ leading: "compact",
12700
+ className: "text-ui-fg-subtle",
12701
+ children: item.variant_sku
13034
12702
  }
13035
- ) }),
13036
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13037
- "path",
13038
- {
13039
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
13040
- stroke: "#A1A1AA",
13041
- strokeWidth: "1.5",
13042
- strokeLinecap: "round",
13043
- strokeLinejoin: "round"
12703
+ )
12704
+ ] })
12705
+ ] }),
12706
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
12707
+ Form$2.Field,
12708
+ {
12709
+ control: form.control,
12710
+ name: "quantity",
12711
+ render: ({ field }) => {
12712
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12713
+ }
12714
+ }
12715
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
12716
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
12717
+ Form$2.Field,
12718
+ {
12719
+ control: form.control,
12720
+ name: "unit_price",
12721
+ render: ({ field: { onChange, ...field } }) => {
12722
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12723
+ ui.CurrencyInput,
12724
+ {
12725
+ ...field,
12726
+ symbol: getNativeSymbol(currencyCode),
12727
+ code: currencyCode,
12728
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12729
+ }
12730
+ ) }) });
12731
+ }
12732
+ }
12733
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12734
+ /* @__PURE__ */ jsxRuntime.jsx(
12735
+ ui.IconButton,
12736
+ {
12737
+ type: "button",
12738
+ size: "small",
12739
+ onClick: editing ? onSubmit : () => {
12740
+ setEditing(true);
12741
+ },
12742
+ disabled: isPending,
12743
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12744
+ }
12745
+ )
12746
+ ] }) }) });
12747
+ };
12748
+ const variantItemSchema = z.object({
12749
+ quantity: z.number(),
12750
+ unit_price: z.union([z.number(), z.string()])
12751
+ });
12752
+ const CustomItem = ({ item, preview, currencyCode }) => {
12753
+ const [editing, setEditing] = React.useState(false);
12754
+ const { quantity, unit_price, title } = item;
12755
+ const form = reactHookForm.useForm({
12756
+ defaultValues: {
12757
+ title,
12758
+ quantity,
12759
+ unit_price
12760
+ },
12761
+ resolver: zod.zodResolver(customItemSchema)
12762
+ });
12763
+ React.useEffect(() => {
12764
+ form.reset({
12765
+ title,
12766
+ quantity,
12767
+ unit_price
12768
+ });
12769
+ }, [form, title, quantity, unit_price]);
12770
+ const actionId = React.useMemo(() => {
12771
+ var _a, _b;
12772
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12773
+ }, [item]);
12774
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12775
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12776
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12777
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12778
+ const onSubmit = form.handleSubmit(async (data) => {
12779
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12780
+ setEditing(false);
12781
+ return;
12782
+ }
12783
+ if (!actionId) {
12784
+ await updateOriginalItem(
12785
+ {
12786
+ item_id: item.id,
12787
+ quantity: data.quantity,
12788
+ unit_price: convertNumber(data.unit_price)
12789
+ },
12790
+ {
12791
+ onSuccess: () => {
12792
+ setEditing(false);
12793
+ },
12794
+ onError: (e) => {
12795
+ ui.toast.error(e.message);
13044
12796
  }
13045
- ) }),
13046
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
13047
- "path",
13048
- {
13049
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
13050
- stroke: "#A1A1AA",
13051
- strokeWidth: "1.5",
13052
- strokeLinecap: "round",
13053
- strokeLinejoin: "round"
12797
+ }
12798
+ );
12799
+ return;
12800
+ }
12801
+ if (data.quantity === 0) {
12802
+ await removeActionItem(actionId, {
12803
+ onSuccess: () => {
12804
+ setEditing(false);
12805
+ },
12806
+ onError: (e) => {
12807
+ ui.toast.error(e.message);
12808
+ }
12809
+ });
12810
+ return;
12811
+ }
12812
+ await updateActionItem(
12813
+ {
12814
+ action_id: actionId,
12815
+ quantity: data.quantity,
12816
+ unit_price: convertNumber(data.unit_price)
12817
+ },
12818
+ {
12819
+ onSuccess: () => {
12820
+ setEditing(false);
12821
+ },
12822
+ onError: (e) => {
12823
+ ui.toast.error(e.message);
12824
+ }
12825
+ }
12826
+ );
12827
+ });
12828
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.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: [
12829
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12830
+ /* @__PURE__ */ jsxRuntime.jsx(
12831
+ Thumbnail,
12832
+ {
12833
+ thumbnail: item.thumbnail,
12834
+ alt: item.title ?? void 0
12835
+ }
12836
+ ),
12837
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12838
+ Form$2.Field,
12839
+ {
12840
+ control: form.control,
12841
+ name: "title",
12842
+ render: ({ field }) => {
12843
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
13054
12844
  }
13055
- ) }),
13056
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
13057
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13058
- "rect",
13059
- {
13060
- width: "12",
13061
- height: "12",
13062
- fill: "white",
13063
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
13064
- }
13065
- ) }),
13066
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13067
- "rect",
13068
- {
13069
- width: "12",
13070
- height: "12",
13071
- fill: "white",
13072
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13073
- }
13074
- ) }),
13075
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13076
- "rect",
13077
- {
13078
- width: "12",
13079
- height: "12",
13080
- fill: "white",
13081
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13082
- }
13083
- ) }),
13084
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13085
- "rect",
13086
- {
13087
- width: "12",
13088
- height: "12",
13089
- fill: "white",
13090
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13091
- }
13092
- ) }),
13093
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13094
- "rect",
13095
- {
13096
- width: "12",
13097
- height: "12",
13098
- fill: "white",
13099
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13100
- }
13101
- ) }),
13102
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13103
- "rect",
12845
+ }
12846
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
12847
+ ] }),
12848
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12849
+ Form$2.Field,
12850
+ {
12851
+ control: form.control,
12852
+ name: "quantity",
12853
+ render: ({ field }) => {
12854
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
12855
+ }
12856
+ }
12857
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
12858
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
12859
+ Form$2.Field,
12860
+ {
12861
+ control: form.control,
12862
+ name: "unit_price",
12863
+ render: ({ field: { onChange, ...field } }) => {
12864
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12865
+ ui.CurrencyInput,
13104
12866
  {
13105
- width: "12",
13106
- height: "12",
13107
- fill: "white",
13108
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12867
+ ...field,
12868
+ symbol: getNativeSymbol(currencyCode),
12869
+ code: currencyCode,
12870
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
13109
12871
  }
13110
- ) })
13111
- ] })
12872
+ ) }) });
12873
+ }
12874
+ }
12875
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12876
+ /* @__PURE__ */ jsxRuntime.jsx(
12877
+ ui.IconButton,
12878
+ {
12879
+ type: "button",
12880
+ size: "small",
12881
+ onClick: editing ? onSubmit : () => {
12882
+ setEditing(true);
12883
+ },
12884
+ disabled: isPending,
12885
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
12886
+ }
12887
+ )
12888
+ ] }) }) });
12889
+ };
12890
+ const StackedModalTrigger = ({
12891
+ type,
12892
+ setModalContent
12893
+ }) => {
12894
+ const { setIsOpen } = useStackedModal();
12895
+ const onClick = React.useCallback(() => {
12896
+ setModalContent(type);
12897
+ setIsOpen(STACKED_MODAL_ID, true);
12898
+ }, [setModalContent, setIsOpen, type]);
12899
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12900
+ };
12901
+ const VARIANT_PREFIX = "items";
12902
+ const LIMIT = 50;
12903
+ const ExistingItemsForm = ({ orderId, items }) => {
12904
+ const { setIsOpen } = useStackedModal();
12905
+ const [rowSelection, setRowSelection] = React.useState(
12906
+ items.reduce((acc, item) => {
12907
+ acc[item.variant_id] = true;
12908
+ return acc;
12909
+ }, {})
12910
+ );
12911
+ React.useEffect(() => {
12912
+ setRowSelection(
12913
+ items.reduce((acc, item) => {
12914
+ if (item.variant_id) {
12915
+ acc[item.variant_id] = true;
12916
+ }
12917
+ return acc;
12918
+ }, {})
12919
+ );
12920
+ }, [items]);
12921
+ const { q, order, offset } = useQueryParams(
12922
+ ["q", "order", "offset"],
12923
+ VARIANT_PREFIX
12924
+ );
12925
+ const { variants, count, isPending, isError, error } = useProductVariants(
12926
+ {
12927
+ q,
12928
+ order,
12929
+ offset: offset ? parseInt(offset) : void 0,
12930
+ limit: LIMIT
12931
+ },
12932
+ {
12933
+ placeholderData: reactQuery.keepPreviousData
12934
+ }
12935
+ );
12936
+ const columns = useColumns();
12937
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
12938
+ const onSubmit = async () => {
12939
+ const ids = Object.keys(rowSelection).filter(
12940
+ (id) => !items.find((i) => i.variant_id === id)
12941
+ );
12942
+ await mutateAsync(
12943
+ {
12944
+ items: ids.map((id) => ({
12945
+ variant_id: id,
12946
+ quantity: 1
12947
+ }))
12948
+ },
12949
+ {
12950
+ onSuccess: () => {
12951
+ setRowSelection({});
12952
+ setIsOpen(STACKED_MODAL_ID, false);
12953
+ },
12954
+ onError: (e) => {
12955
+ ui.toast.error(e.message);
12956
+ }
12957
+ }
12958
+ );
12959
+ };
12960
+ if (isError) {
12961
+ throw error;
12962
+ }
12963
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12964
+ StackedFocusModal.Content,
12965
+ {
12966
+ onOpenAutoFocus: (e) => {
12967
+ e.preventDefault();
12968
+ const searchInput = document.querySelector(
12969
+ "[data-modal-id='modal-search-input']"
12970
+ );
12971
+ if (searchInput) {
12972
+ searchInput.focus();
12973
+ }
12974
+ },
12975
+ children: [
12976
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
12977
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12978
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12979
+ ] }),
12980
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
12981
+ DataTable,
12982
+ {
12983
+ data: variants,
12984
+ columns,
12985
+ isLoading: isPending,
12986
+ getRowId: (row) => row.id,
12987
+ rowCount: count,
12988
+ prefix: VARIANT_PREFIX,
12989
+ layout: "fill",
12990
+ rowSelection: {
12991
+ state: rowSelection,
12992
+ onRowSelectionChange: setRowSelection,
12993
+ enableRowSelection: (row) => {
12994
+ return !items.find((i) => i.variant_id === row.original.id);
12995
+ }
12996
+ },
12997
+ autoFocusSearch: true
12998
+ }
12999
+ ) }),
13000
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
13001
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13002
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
13003
+ ] }) })
13112
13004
  ]
13113
13005
  }
13114
13006
  );
13115
13007
  };
13116
- const schema$1 = z.object({
13117
- customer_id: z.string().min(1)
13118
- });
13119
- const Email = () => {
13120
- const { id } = reactRouterDom.useParams();
13121
- const { order, isPending, isError, error } = useOrder(id, {
13122
- fields: "+email"
13123
- });
13124
- if (isError) {
13125
- throw error;
13126
- }
13127
- const isReady = !isPending && !!order;
13128
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13129
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
13130
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
13131
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
13132
- ] }),
13133
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
13134
- ] });
13008
+ const columnHelper = ui.createDataTableColumnHelper();
13009
+ const useColumns = () => {
13010
+ return React.useMemo(() => {
13011
+ return [
13012
+ columnHelper.select(),
13013
+ columnHelper.accessor("product.title", {
13014
+ header: "Product",
13015
+ cell: ({ row }) => {
13016
+ var _a, _b, _c;
13017
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
13018
+ /* @__PURE__ */ jsxRuntime.jsx(
13019
+ Thumbnail,
13020
+ {
13021
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
13022
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
13023
+ }
13024
+ ),
13025
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
13026
+ ] });
13027
+ },
13028
+ enableSorting: true
13029
+ }),
13030
+ columnHelper.accessor("title", {
13031
+ header: "Variant",
13032
+ enableSorting: true
13033
+ }),
13034
+ columnHelper.accessor("sku", {
13035
+ header: "SKU",
13036
+ cell: ({ getValue }) => {
13037
+ return getValue() ?? "-";
13038
+ },
13039
+ enableSorting: true
13040
+ }),
13041
+ columnHelper.accessor("updated_at", {
13042
+ header: "Updated",
13043
+ cell: ({ getValue }) => {
13044
+ return /* @__PURE__ */ jsxRuntime.jsx(
13045
+ ui.Tooltip,
13046
+ {
13047
+ content: getFullDate({ date: getValue(), includeTime: true }),
13048
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
13049
+ }
13050
+ );
13051
+ },
13052
+ enableSorting: true,
13053
+ sortAscLabel: "Oldest first",
13054
+ sortDescLabel: "Newest first"
13055
+ }),
13056
+ columnHelper.accessor("created_at", {
13057
+ header: "Created",
13058
+ cell: ({ getValue }) => {
13059
+ return /* @__PURE__ */ jsxRuntime.jsx(
13060
+ ui.Tooltip,
13061
+ {
13062
+ content: getFullDate({ date: getValue(), includeTime: true }),
13063
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
13064
+ }
13065
+ );
13066
+ },
13067
+ enableSorting: true,
13068
+ sortAscLabel: "Oldest first",
13069
+ sortDescLabel: "Newest first"
13070
+ })
13071
+ ];
13072
+ }, []);
13135
13073
  };
13136
- const EmailForm = ({ order }) => {
13074
+ const CustomItemForm = ({ orderId, currencyCode }) => {
13075
+ const { setIsOpen } = useStackedModal();
13076
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
13137
13077
  const form = reactHookForm.useForm({
13138
13078
  defaultValues: {
13139
- email: order.email ?? ""
13079
+ title: "",
13080
+ quantity: 1,
13081
+ unit_price: ""
13140
13082
  },
13141
- resolver: zod.zodResolver(schema)
13083
+ resolver: zod.zodResolver(customItemSchema)
13142
13084
  });
13143
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
13144
- const { handleSuccess } = useRouteModal();
13145
13085
  const onSubmit = form.handleSubmit(async (data) => {
13146
- await mutateAsync(
13147
- { email: data.email },
13086
+ await addItems(
13087
+ {
13088
+ items: [
13089
+ {
13090
+ title: data.title,
13091
+ quantity: data.quantity,
13092
+ unit_price: convertNumber(data.unit_price)
13093
+ }
13094
+ ]
13095
+ },
13148
13096
  {
13149
13097
  onSuccess: () => {
13150
- handleSuccess();
13098
+ setIsOpen(STACKED_MODAL_ID, false);
13151
13099
  },
13152
- onError: (error) => {
13153
- ui.toast.error(error.message);
13100
+ onError: (e) => {
13101
+ ui.toast.error(e.message);
13154
13102
  }
13155
13103
  }
13156
13104
  );
13157
13105
  });
13158
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13159
- KeyboundForm,
13160
- {
13161
- className: "flex flex-1 flex-col overflow-hidden",
13162
- onSubmit,
13163
- children: [
13164
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13165
- Form$2.Field,
13166
- {
13167
- control: form.control,
13168
- name: "email",
13169
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13170
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13106
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
13107
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
13108
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
13109
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13110
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
13111
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
13112
+ ] }),
13113
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13114
+ /* @__PURE__ */ jsxRuntime.jsx(
13115
+ Form$2.Field,
13116
+ {
13117
+ control: form.control,
13118
+ name: "title",
13119
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13120
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13121
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
13122
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
13123
+ ] }),
13124
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13171
13125
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13172
13126
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13173
13127
  ] })
13174
- }
13175
- ) }),
13176
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13177
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13178
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13179
- ] }) })
13180
- ]
13181
- }
13182
- ) });
13128
+ ] }) })
13129
+ }
13130
+ ),
13131
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13132
+ /* @__PURE__ */ jsxRuntime.jsx(
13133
+ Form$2.Field,
13134
+ {
13135
+ control: form.control,
13136
+ name: "unit_price",
13137
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13138
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13139
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
13140
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
13141
+ ] }),
13142
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13143
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13144
+ ui.CurrencyInput,
13145
+ {
13146
+ symbol: getNativeSymbol(currencyCode),
13147
+ code: currencyCode,
13148
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
13149
+ ...field
13150
+ }
13151
+ ) }),
13152
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13153
+ ] })
13154
+ ] }) })
13155
+ }
13156
+ ),
13157
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
13158
+ /* @__PURE__ */ jsxRuntime.jsx(
13159
+ Form$2.Field,
13160
+ {
13161
+ control: form.control,
13162
+ name: "quantity",
13163
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13164
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
13165
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
13166
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
13167
+ ] }),
13168
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 w-full", children: [
13169
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
13170
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13171
+ ] })
13172
+ ] }) })
13173
+ }
13174
+ )
13175
+ ] }) }) }),
13176
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
13177
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13178
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
13179
+ ] }) })
13180
+ ] }) }) });
13183
13181
  };
13184
- const schema = z.object({
13185
- email: z.string().email()
13182
+ const customItemSchema = z.object({
13183
+ title: z.string().min(1),
13184
+ quantity: z.number(),
13185
+ unit_price: z.union([z.number(), z.string()])
13186
13186
  });
13187
13187
  const widgetModule = { widgets: [] };
13188
13188
  const routeModule = {
@@ -13204,14 +13204,14 @@ const routeModule = {
13204
13204
  handle,
13205
13205
  loader,
13206
13206
  children: [
13207
- {
13208
- Component: BillingAddress,
13209
- path: "/draft-orders/:id/billing-address"
13210
- },
13211
13207
  {
13212
13208
  Component: CustomItems,
13213
13209
  path: "/draft-orders/:id/custom-items"
13214
13210
  },
13211
+ {
13212
+ Component: BillingAddress,
13213
+ path: "/draft-orders/:id/billing-address"
13214
+ },
13215
13215
  {
13216
13216
  Component: Metadata,
13217
13217
  path: "/draft-orders/:id/metadata"
@@ -13221,16 +13221,16 @@ const routeModule = {
13221
13221
  path: "/draft-orders/:id/promotions"
13222
13222
  },
13223
13223
  {
13224
- Component: Shipping,
13225
- path: "/draft-orders/:id/shipping"
13224
+ Component: Email,
13225
+ path: "/draft-orders/:id/email"
13226
13226
  },
13227
13227
  {
13228
13228
  Component: SalesChannel,
13229
13229
  path: "/draft-orders/:id/sales-channel"
13230
13230
  },
13231
13231
  {
13232
- Component: Items,
13233
- path: "/draft-orders/:id/items"
13232
+ Component: Shipping,
13233
+ path: "/draft-orders/:id/shipping"
13234
13234
  },
13235
13235
  {
13236
13236
  Component: ShippingAddress,
@@ -13241,8 +13241,8 @@ const routeModule = {
13241
13241
  path: "/draft-orders/:id/transfer-ownership"
13242
13242
  },
13243
13243
  {
13244
- Component: Email,
13245
- path: "/draft-orders/:id/email"
13244
+ Component: Items,
13245
+ path: "/draft-orders/:id/items"
13246
13246
  }
13247
13247
  ]
13248
13248
  }