@medusajs/draft-order 2.10.2-preview-20250911120205 → 2.10.2-preview-20250911210151

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