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