@medusajs/draft-order 2.11.2-preview-20251028000318 → 2.11.2-preview-20251028031854

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.
@@ -9571,6 +9571,196 @@ const ID = () => {
9571
9571
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9572
9572
  ] });
9573
9573
  };
9574
+ const BillingAddress = () => {
9575
+ const { id } = reactRouterDom.useParams();
9576
+ const { order, isPending, isError, error } = useOrder(id, {
9577
+ fields: "+billing_address"
9578
+ });
9579
+ if (isError) {
9580
+ throw error;
9581
+ }
9582
+ const isReady = !isPending && !!order;
9583
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9584
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9585
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9587
+ ] }),
9588
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9589
+ ] });
9590
+ };
9591
+ const BillingAddressForm = ({ order }) => {
9592
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9593
+ const form = reactHookForm.useForm({
9594
+ defaultValues: {
9595
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9596
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9597
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9598
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9599
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9600
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9601
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9602
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9603
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9604
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9605
+ },
9606
+ resolver: zod.zodResolver(schema$5)
9607
+ });
9608
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9609
+ const { handleSuccess } = useRouteModal();
9610
+ const onSubmit = form.handleSubmit(async (data) => {
9611
+ await mutateAsync(
9612
+ { billing_address: data },
9613
+ {
9614
+ onSuccess: () => {
9615
+ handleSuccess();
9616
+ },
9617
+ onError: (error) => {
9618
+ ui.toast.error(error.message);
9619
+ }
9620
+ }
9621
+ );
9622
+ });
9623
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9624
+ KeyboundForm,
9625
+ {
9626
+ className: "flex flex-1 flex-col overflow-hidden",
9627
+ onSubmit,
9628
+ children: [
9629
+ /* @__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: [
9630
+ /* @__PURE__ */ jsxRuntime.jsx(
9631
+ Form$2.Field,
9632
+ {
9633
+ control: form.control,
9634
+ name: "country_code",
9635
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9636
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9639
+ ] })
9640
+ }
9641
+ ),
9642
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9643
+ /* @__PURE__ */ jsxRuntime.jsx(
9644
+ Form$2.Field,
9645
+ {
9646
+ control: form.control,
9647
+ name: "first_name",
9648
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9652
+ ] })
9653
+ }
9654
+ ),
9655
+ /* @__PURE__ */ jsxRuntime.jsx(
9656
+ Form$2.Field,
9657
+ {
9658
+ control: form.control,
9659
+ name: "last_name",
9660
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9664
+ ] })
9665
+ }
9666
+ )
9667
+ ] }),
9668
+ /* @__PURE__ */ jsxRuntime.jsx(
9669
+ Form$2.Field,
9670
+ {
9671
+ control: form.control,
9672
+ name: "company",
9673
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9674
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9677
+ ] })
9678
+ }
9679
+ ),
9680
+ /* @__PURE__ */ jsxRuntime.jsx(
9681
+ Form$2.Field,
9682
+ {
9683
+ control: form.control,
9684
+ name: "address_1",
9685
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9686
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9689
+ ] })
9690
+ }
9691
+ ),
9692
+ /* @__PURE__ */ jsxRuntime.jsx(
9693
+ Form$2.Field,
9694
+ {
9695
+ control: form.control,
9696
+ name: "address_2",
9697
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9701
+ ] })
9702
+ }
9703
+ ),
9704
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9705
+ /* @__PURE__ */ jsxRuntime.jsx(
9706
+ Form$2.Field,
9707
+ {
9708
+ control: form.control,
9709
+ name: "postal_code",
9710
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9711
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9714
+ ] })
9715
+ }
9716
+ ),
9717
+ /* @__PURE__ */ jsxRuntime.jsx(
9718
+ Form$2.Field,
9719
+ {
9720
+ control: form.control,
9721
+ name: "city",
9722
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9723
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9726
+ ] })
9727
+ }
9728
+ )
9729
+ ] }),
9730
+ /* @__PURE__ */ jsxRuntime.jsx(
9731
+ Form$2.Field,
9732
+ {
9733
+ control: form.control,
9734
+ name: "province",
9735
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9736
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9739
+ ] })
9740
+ }
9741
+ ),
9742
+ /* @__PURE__ */ jsxRuntime.jsx(
9743
+ Form$2.Field,
9744
+ {
9745
+ control: form.control,
9746
+ name: "phone",
9747
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9748
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9751
+ ] })
9752
+ }
9753
+ )
9754
+ ] }) }),
9755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9756
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9757
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9758
+ ] }) })
9759
+ ]
9760
+ }
9761
+ ) });
9762
+ };
9763
+ const schema$5 = addressSchema;
9574
9764
  const CustomItems = () => {
9575
9765
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9576
9766
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9579,7 +9769,7 @@ const CustomItems = () => {
9579
9769
  };
9580
9770
  const CustomItemsForm = () => {
9581
9771
  const form = reactHookForm.useForm({
9582
- resolver: zod.zodResolver(schema$5)
9772
+ resolver: zod.zodResolver(schema$4)
9583
9773
  });
9584
9774
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9585
9775
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9589,45 +9779,113 @@ const CustomItemsForm = () => {
9589
9779
  ] }) })
9590
9780
  ] }) });
9591
9781
  };
9592
- const schema$5 = objectType({
9782
+ const schema$4 = objectType({
9593
9783
  email: stringType().email()
9594
9784
  });
9595
- const NumberInput = React.forwardRef(
9596
- ({
9597
- value,
9598
- onChange,
9599
- size = "base",
9600
- min = 0,
9601
- max = 100,
9602
- step = 1,
9603
- className,
9604
- disabled,
9605
- ...props
9606
- }, ref) => {
9607
- const handleChange = (event) => {
9608
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9609
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9610
- onChange(newValue);
9611
- }
9612
- };
9613
- const handleIncrement = () => {
9614
- const newValue = value + step;
9615
- if (max === void 0 || newValue <= max) {
9616
- onChange(newValue);
9617
- }
9618
- };
9619
- const handleDecrement = () => {
9620
- const newValue = value - step;
9621
- if (min === void 0 || newValue >= min) {
9622
- onChange(newValue);
9623
- }
9624
- };
9625
- return /* @__PURE__ */ jsxRuntime.jsxs(
9626
- "div",
9785
+ const Email = () => {
9786
+ const { id } = reactRouterDom.useParams();
9787
+ const { order, isPending, isError, error } = useOrder(id, {
9788
+ fields: "+email"
9789
+ });
9790
+ if (isError) {
9791
+ throw error;
9792
+ }
9793
+ const isReady = !isPending && !!order;
9794
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9795
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9796
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9797
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9798
+ ] }),
9799
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9800
+ ] });
9801
+ };
9802
+ const EmailForm = ({ order }) => {
9803
+ const form = reactHookForm.useForm({
9804
+ defaultValues: {
9805
+ email: order.email ?? ""
9806
+ },
9807
+ resolver: zod.zodResolver(schema$3)
9808
+ });
9809
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9810
+ const { handleSuccess } = useRouteModal();
9811
+ const onSubmit = form.handleSubmit(async (data) => {
9812
+ await mutateAsync(
9813
+ { email: data.email },
9627
9814
  {
9628
- className: ui.clx(
9629
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9630
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9815
+ onSuccess: () => {
9816
+ handleSuccess();
9817
+ },
9818
+ onError: (error) => {
9819
+ ui.toast.error(error.message);
9820
+ }
9821
+ }
9822
+ );
9823
+ });
9824
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9825
+ KeyboundForm,
9826
+ {
9827
+ className: "flex flex-1 flex-col overflow-hidden",
9828
+ onSubmit,
9829
+ children: [
9830
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9831
+ Form$2.Field,
9832
+ {
9833
+ control: form.control,
9834
+ name: "email",
9835
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9836
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9837
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9838
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9839
+ ] })
9840
+ }
9841
+ ) }),
9842
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9843
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9844
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9845
+ ] }) })
9846
+ ]
9847
+ }
9848
+ ) });
9849
+ };
9850
+ const schema$3 = objectType({
9851
+ email: stringType().email()
9852
+ });
9853
+ const NumberInput = React.forwardRef(
9854
+ ({
9855
+ value,
9856
+ onChange,
9857
+ size = "base",
9858
+ min = 0,
9859
+ max = 100,
9860
+ step = 1,
9861
+ className,
9862
+ disabled,
9863
+ ...props
9864
+ }, ref) => {
9865
+ const handleChange = (event) => {
9866
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9867
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9868
+ onChange(newValue);
9869
+ }
9870
+ };
9871
+ const handleIncrement = () => {
9872
+ const newValue = value + step;
9873
+ if (max === void 0 || newValue <= max) {
9874
+ onChange(newValue);
9875
+ }
9876
+ };
9877
+ const handleDecrement = () => {
9878
+ const newValue = value - step;
9879
+ if (min === void 0 || newValue >= min) {
9880
+ onChange(newValue);
9881
+ }
9882
+ };
9883
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9884
+ "div",
9885
+ {
9886
+ className: ui.clx(
9887
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9888
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9631
9889
  {
9632
9890
  "h-7": size === "small",
9633
9891
  "h-8": size === "base"
@@ -10564,616 +10822,8 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10564
10822
  const customItemSchema = objectType({
10565
10823
  title: stringType().min(1),
10566
10824
  quantity: numberType(),
10567
- unit_price: unionType([numberType(), stringType()])
10568
- });
10569
- const Email = () => {
10570
- const { id } = reactRouterDom.useParams();
10571
- const { order, isPending, isError, error } = useOrder(id, {
10572
- fields: "+email"
10573
- });
10574
- if (isError) {
10575
- throw error;
10576
- }
10577
- const isReady = !isPending && !!order;
10578
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10579
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10580
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10581
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10582
- ] }),
10583
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10584
- ] });
10585
- };
10586
- const EmailForm = ({ order }) => {
10587
- const form = reactHookForm.useForm({
10588
- defaultValues: {
10589
- email: order.email ?? ""
10590
- },
10591
- resolver: zod.zodResolver(schema$4)
10592
- });
10593
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10594
- const { handleSuccess } = useRouteModal();
10595
- const onSubmit = form.handleSubmit(async (data) => {
10596
- await mutateAsync(
10597
- { email: data.email },
10598
- {
10599
- onSuccess: () => {
10600
- handleSuccess();
10601
- },
10602
- onError: (error) => {
10603
- ui.toast.error(error.message);
10604
- }
10605
- }
10606
- );
10607
- });
10608
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10609
- KeyboundForm,
10610
- {
10611
- className: "flex flex-1 flex-col overflow-hidden",
10612
- onSubmit,
10613
- children: [
10614
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10615
- Form$2.Field,
10616
- {
10617
- control: form.control,
10618
- name: "email",
10619
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10620
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10621
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10622
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10623
- ] })
10624
- }
10625
- ) }),
10626
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10627
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10628
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10629
- ] }) })
10630
- ]
10631
- }
10632
- ) });
10633
- };
10634
- const schema$4 = objectType({
10635
- email: stringType().email()
10636
- });
10637
- const InlineTip = React.forwardRef(
10638
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10639
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10640
- return /* @__PURE__ */ jsxRuntime.jsxs(
10641
- "div",
10642
- {
10643
- ref,
10644
- className: ui.clx(
10645
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10646
- className
10647
- ),
10648
- ...props,
10649
- children: [
10650
- /* @__PURE__ */ jsxRuntime.jsx(
10651
- "div",
10652
- {
10653
- role: "presentation",
10654
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10655
- "bg-ui-tag-orange-icon": variant === "warning"
10656
- })
10657
- }
10658
- ),
10659
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10660
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10661
- labelValue,
10662
- ":"
10663
- ] }),
10664
- " ",
10665
- children
10666
- ] })
10667
- ]
10668
- }
10669
- );
10670
- }
10671
- );
10672
- InlineTip.displayName = "InlineTip";
10673
- const MetadataFieldSchema = objectType({
10674
- key: stringType(),
10675
- disabled: booleanType().optional(),
10676
- value: anyType()
10677
- });
10678
- const MetadataSchema = objectType({
10679
- metadata: arrayType(MetadataFieldSchema)
10680
- });
10681
- const Metadata = () => {
10682
- const { id } = reactRouterDom.useParams();
10683
- const { order, isPending, isError, error } = useOrder(id, {
10684
- fields: "metadata"
10685
- });
10686
- if (isError) {
10687
- throw error;
10688
- }
10689
- const isReady = !isPending && !!order;
10690
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10691
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10692
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10693
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10694
- ] }),
10695
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10696
- ] });
10697
- };
10698
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10699
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10700
- const MetadataForm = ({ orderId, metadata }) => {
10701
- const { handleSuccess } = useRouteModal();
10702
- const hasUneditableRows = getHasUneditableRows(metadata);
10703
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10704
- const form = reactHookForm.useForm({
10705
- defaultValues: {
10706
- metadata: getDefaultValues(metadata)
10707
- },
10708
- resolver: zod.zodResolver(MetadataSchema)
10709
- });
10710
- const handleSubmit = form.handleSubmit(async (data) => {
10711
- const parsedData = parseValues(data);
10712
- await mutateAsync(
10713
- {
10714
- metadata: parsedData
10715
- },
10716
- {
10717
- onSuccess: () => {
10718
- ui.toast.success("Metadata updated");
10719
- handleSuccess();
10720
- },
10721
- onError: (error) => {
10722
- ui.toast.error(error.message);
10723
- }
10724
- }
10725
- );
10726
- });
10727
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10728
- control: form.control,
10729
- name: "metadata"
10730
- });
10731
- function deleteRow(index) {
10732
- remove(index);
10733
- if (fields.length === 1) {
10734
- insert(0, {
10735
- key: "",
10736
- value: "",
10737
- disabled: false
10738
- });
10739
- }
10740
- }
10741
- function insertRow(index, position) {
10742
- insert(index + (position === "above" ? 0 : 1), {
10743
- key: "",
10744
- value: "",
10745
- disabled: false
10746
- });
10747
- }
10748
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10749
- KeyboundForm,
10750
- {
10751
- onSubmit: handleSubmit,
10752
- className: "flex flex-1 flex-col overflow-hidden",
10753
- children: [
10754
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10755
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10756
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10757
- /* @__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" }) }),
10758
- /* @__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" }) })
10759
- ] }),
10760
- fields.map((field, index) => {
10761
- const isDisabled = field.disabled || false;
10762
- let placeholder = "-";
10763
- if (typeof field.value === "object") {
10764
- placeholder = "{ ... }";
10765
- }
10766
- if (Array.isArray(field.value)) {
10767
- placeholder = "[ ... ]";
10768
- }
10769
- return /* @__PURE__ */ jsxRuntime.jsx(
10770
- ConditionalTooltip,
10771
- {
10772
- showTooltip: isDisabled,
10773
- content: "This row is disabled because it contains non-primitive data.",
10774
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10775
- /* @__PURE__ */ jsxRuntime.jsxs(
10776
- "div",
10777
- {
10778
- className: ui.clx("grid grid-cols-2 divide-x", {
10779
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10780
- }),
10781
- children: [
10782
- /* @__PURE__ */ jsxRuntime.jsx(
10783
- Form$2.Field,
10784
- {
10785
- control: form.control,
10786
- name: `metadata.${index}.key`,
10787
- render: ({ field: field2 }) => {
10788
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10789
- GridInput,
10790
- {
10791
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10792
- ...field2,
10793
- disabled: isDisabled,
10794
- placeholder: "Key"
10795
- }
10796
- ) }) });
10797
- }
10798
- }
10799
- ),
10800
- /* @__PURE__ */ jsxRuntime.jsx(
10801
- Form$2.Field,
10802
- {
10803
- control: form.control,
10804
- name: `metadata.${index}.value`,
10805
- render: ({ field: { value, ...field2 } }) => {
10806
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10807
- GridInput,
10808
- {
10809
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10810
- ...field2,
10811
- value: isDisabled ? placeholder : value,
10812
- disabled: isDisabled,
10813
- placeholder: "Value"
10814
- }
10815
- ) }) });
10816
- }
10817
- }
10818
- )
10819
- ]
10820
- }
10821
- ),
10822
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10823
- /* @__PURE__ */ jsxRuntime.jsx(
10824
- ui.DropdownMenu.Trigger,
10825
- {
10826
- className: ui.clx(
10827
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10828
- {
10829
- hidden: isDisabled
10830
- }
10831
- ),
10832
- disabled: isDisabled,
10833
- asChild: true,
10834
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10835
- }
10836
- ),
10837
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10838
- /* @__PURE__ */ jsxRuntime.jsxs(
10839
- ui.DropdownMenu.Item,
10840
- {
10841
- className: "gap-x-2",
10842
- onClick: () => insertRow(index, "above"),
10843
- children: [
10844
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10845
- "Insert row above"
10846
- ]
10847
- }
10848
- ),
10849
- /* @__PURE__ */ jsxRuntime.jsxs(
10850
- ui.DropdownMenu.Item,
10851
- {
10852
- className: "gap-x-2",
10853
- onClick: () => insertRow(index, "below"),
10854
- children: [
10855
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10856
- "Insert row below"
10857
- ]
10858
- }
10859
- ),
10860
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10861
- /* @__PURE__ */ jsxRuntime.jsxs(
10862
- ui.DropdownMenu.Item,
10863
- {
10864
- className: "gap-x-2",
10865
- onClick: () => deleteRow(index),
10866
- children: [
10867
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10868
- "Delete row"
10869
- ]
10870
- }
10871
- )
10872
- ] })
10873
- ] })
10874
- ] })
10875
- },
10876
- field.id
10877
- );
10878
- })
10879
- ] }),
10880
- 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." })
10881
- ] }),
10882
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10883
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10884
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10885
- ] }) })
10886
- ]
10887
- }
10888
- ) });
10889
- };
10890
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10891
- return /* @__PURE__ */ jsxRuntime.jsx(
10892
- "input",
10893
- {
10894
- ref,
10895
- ...props,
10896
- autoComplete: "off",
10897
- className: ui.clx(
10898
- "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",
10899
- className
10900
- )
10901
- }
10902
- );
10903
- });
10904
- GridInput.displayName = "MetadataForm.GridInput";
10905
- const PlaceholderInner = () => {
10906
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10907
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10908
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10909
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10910
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10911
- ] }) })
10912
- ] });
10913
- };
10914
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10915
- function getDefaultValues(metadata) {
10916
- if (!metadata || !Object.keys(metadata).length) {
10917
- return [
10918
- {
10919
- key: "",
10920
- value: "",
10921
- disabled: false
10922
- }
10923
- ];
10924
- }
10925
- return Object.entries(metadata).map(([key, value]) => {
10926
- if (!EDITABLE_TYPES.includes(typeof value)) {
10927
- return {
10928
- key,
10929
- value,
10930
- disabled: true
10931
- };
10932
- }
10933
- let stringValue = value;
10934
- if (typeof value !== "string") {
10935
- stringValue = JSON.stringify(value);
10936
- }
10937
- return {
10938
- key,
10939
- value: stringValue,
10940
- original_key: key
10941
- };
10942
- });
10943
- }
10944
- function parseValues(values) {
10945
- const metadata = values.metadata;
10946
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10947
- if (isEmpty) {
10948
- return null;
10949
- }
10950
- const update = {};
10951
- metadata.forEach((field) => {
10952
- let key = field.key;
10953
- let value = field.value;
10954
- const disabled = field.disabled;
10955
- if (!key || !value) {
10956
- return;
10957
- }
10958
- if (disabled) {
10959
- update[key] = value;
10960
- return;
10961
- }
10962
- key = key.trim();
10963
- value = value.trim();
10964
- if (value === "true") {
10965
- update[key] = true;
10966
- } else if (value === "false") {
10967
- update[key] = false;
10968
- } else {
10969
- const parsedNumber = parseFloat(value);
10970
- if (!isNaN(parsedNumber)) {
10971
- update[key] = parsedNumber;
10972
- } else {
10973
- update[key] = value;
10974
- }
10975
- }
10976
- });
10977
- return update;
10978
- }
10979
- function getHasUneditableRows(metadata) {
10980
- if (!metadata) {
10981
- return false;
10982
- }
10983
- return Object.values(metadata).some(
10984
- (value) => !EDITABLE_TYPES.includes(typeof value)
10985
- );
10986
- }
10987
- const BillingAddress = () => {
10988
- const { id } = reactRouterDom.useParams();
10989
- const { order, isPending, isError, error } = useOrder(id, {
10990
- fields: "+billing_address"
10991
- });
10992
- if (isError) {
10993
- throw error;
10994
- }
10995
- const isReady = !isPending && !!order;
10996
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10997
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10998
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
10999
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
11000
- ] }),
11001
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
11002
- ] });
11003
- };
11004
- const BillingAddressForm = ({ order }) => {
11005
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11006
- const form = reactHookForm.useForm({
11007
- defaultValues: {
11008
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
11009
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
11010
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
11011
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
11012
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
11013
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
11014
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
11015
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
11016
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
11017
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
11018
- },
11019
- resolver: zod.zodResolver(schema$3)
11020
- });
11021
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11022
- const { handleSuccess } = useRouteModal();
11023
- const onSubmit = form.handleSubmit(async (data) => {
11024
- await mutateAsync(
11025
- { billing_address: data },
11026
- {
11027
- onSuccess: () => {
11028
- handleSuccess();
11029
- },
11030
- onError: (error) => {
11031
- ui.toast.error(error.message);
11032
- }
11033
- }
11034
- );
11035
- });
11036
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11037
- KeyboundForm,
11038
- {
11039
- className: "flex flex-1 flex-col overflow-hidden",
11040
- onSubmit,
11041
- children: [
11042
- /* @__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: [
11043
- /* @__PURE__ */ jsxRuntime.jsx(
11044
- Form$2.Field,
11045
- {
11046
- control: form.control,
11047
- name: "country_code",
11048
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11049
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11050
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11051
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11052
- ] })
11053
- }
11054
- ),
11055
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11056
- /* @__PURE__ */ jsxRuntime.jsx(
11057
- Form$2.Field,
11058
- {
11059
- control: form.control,
11060
- name: "first_name",
11061
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11062
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11063
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11064
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11065
- ] })
11066
- }
11067
- ),
11068
- /* @__PURE__ */ jsxRuntime.jsx(
11069
- Form$2.Field,
11070
- {
11071
- control: form.control,
11072
- name: "last_name",
11073
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11074
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11075
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11076
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11077
- ] })
11078
- }
11079
- )
11080
- ] }),
11081
- /* @__PURE__ */ jsxRuntime.jsx(
11082
- Form$2.Field,
11083
- {
11084
- control: form.control,
11085
- name: "company",
11086
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11087
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11088
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11089
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11090
- ] })
11091
- }
11092
- ),
11093
- /* @__PURE__ */ jsxRuntime.jsx(
11094
- Form$2.Field,
11095
- {
11096
- control: form.control,
11097
- name: "address_1",
11098
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11099
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11100
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11101
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11102
- ] })
11103
- }
11104
- ),
11105
- /* @__PURE__ */ jsxRuntime.jsx(
11106
- Form$2.Field,
11107
- {
11108
- control: form.control,
11109
- name: "address_2",
11110
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11111
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11112
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11113
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11114
- ] })
11115
- }
11116
- ),
11117
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11118
- /* @__PURE__ */ jsxRuntime.jsx(
11119
- Form$2.Field,
11120
- {
11121
- control: form.control,
11122
- name: "postal_code",
11123
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11124
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11125
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11126
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11127
- ] })
11128
- }
11129
- ),
11130
- /* @__PURE__ */ jsxRuntime.jsx(
11131
- Form$2.Field,
11132
- {
11133
- control: form.control,
11134
- name: "city",
11135
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11136
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11137
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11138
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11139
- ] })
11140
- }
11141
- )
11142
- ] }),
11143
- /* @__PURE__ */ jsxRuntime.jsx(
11144
- Form$2.Field,
11145
- {
11146
- control: form.control,
11147
- name: "province",
11148
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11149
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11150
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11151
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11152
- ] })
11153
- }
11154
- ),
11155
- /* @__PURE__ */ jsxRuntime.jsx(
11156
- Form$2.Field,
11157
- {
11158
- control: form.control,
11159
- name: "phone",
11160
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11161
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11162
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11163
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11164
- ] })
11165
- }
11166
- )
11167
- ] }) }),
11168
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11169
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11170
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11171
- ] }) })
11172
- ]
11173
- }
11174
- ) });
11175
- };
11176
- const schema$3 = addressSchema;
10825
+ unit_price: unionType([numberType(), stringType()])
10826
+ });
11177
10827
  const PROMOTION_QUERY_KEY = "promotions";
11178
10828
  const promotionsQueryKeys = {
11179
10829
  list: (query2) => [
@@ -11451,46 +11101,88 @@ function getPromotionIds(items, shippingMethods) {
11451
11101
  }
11452
11102
  return Array.from(promotionIds);
11453
11103
  }
11454
- const SalesChannel = () => {
11104
+ const InlineTip = React.forwardRef(
11105
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11106
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11107
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11108
+ "div",
11109
+ {
11110
+ ref,
11111
+ className: ui.clx(
11112
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11113
+ className
11114
+ ),
11115
+ ...props,
11116
+ children: [
11117
+ /* @__PURE__ */ jsxRuntime.jsx(
11118
+ "div",
11119
+ {
11120
+ role: "presentation",
11121
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11122
+ "bg-ui-tag-orange-icon": variant === "warning"
11123
+ })
11124
+ }
11125
+ ),
11126
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11127
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11128
+ labelValue,
11129
+ ":"
11130
+ ] }),
11131
+ " ",
11132
+ children
11133
+ ] })
11134
+ ]
11135
+ }
11136
+ );
11137
+ }
11138
+ );
11139
+ InlineTip.displayName = "InlineTip";
11140
+ const MetadataFieldSchema = objectType({
11141
+ key: stringType(),
11142
+ disabled: booleanType().optional(),
11143
+ value: anyType()
11144
+ });
11145
+ const MetadataSchema = objectType({
11146
+ metadata: arrayType(MetadataFieldSchema)
11147
+ });
11148
+ const Metadata = () => {
11455
11149
  const { id } = reactRouterDom.useParams();
11456
- const { draft_order, isPending, isError, error } = useDraftOrder(
11457
- id,
11458
- {
11459
- fields: "+sales_channel_id"
11460
- },
11461
- {
11462
- enabled: !!id
11463
- }
11464
- );
11150
+ const { order, isPending, isError, error } = useOrder(id, {
11151
+ fields: "metadata"
11152
+ });
11465
11153
  if (isError) {
11466
11154
  throw error;
11467
11155
  }
11468
- const ISrEADY = !!draft_order && !isPending;
11156
+ const isReady = !isPending && !!order;
11469
11157
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11470
11158
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11471
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11472
- /* @__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" }) })
11159
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11160
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11473
11161
  ] }),
11474
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11162
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11475
11163
  ] });
11476
11164
  };
11477
- const SalesChannelForm = ({ order }) => {
11165
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11166
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11167
+ const MetadataForm = ({ orderId, metadata }) => {
11168
+ const { handleSuccess } = useRouteModal();
11169
+ const hasUneditableRows = getHasUneditableRows(metadata);
11170
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11478
11171
  const form = reactHookForm.useForm({
11479
11172
  defaultValues: {
11480
- sales_channel_id: order.sales_channel_id || ""
11173
+ metadata: getDefaultValues(metadata)
11481
11174
  },
11482
- resolver: zod.zodResolver(schema$2)
11175
+ resolver: zod.zodResolver(MetadataSchema)
11483
11176
  });
11484
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11485
- const { handleSuccess } = useRouteModal();
11486
- const onSubmit = form.handleSubmit(async (data) => {
11177
+ const handleSubmit = form.handleSubmit(async (data) => {
11178
+ const parsedData = parseValues(data);
11487
11179
  await mutateAsync(
11488
11180
  {
11489
- sales_channel_id: data.sales_channel_id
11181
+ metadata: parsedData
11490
11182
  },
11491
11183
  {
11492
11184
  onSuccess: () => {
11493
- ui.toast.success("Sales channel updated");
11185
+ ui.toast.success("Metadata updated");
11494
11186
  handleSuccess();
11495
11187
  },
11496
11188
  onError: (error) => {
@@ -11499,64 +11191,266 @@ const SalesChannelForm = ({ order }) => {
11499
11191
  }
11500
11192
  );
11501
11193
  });
11194
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
11195
+ control: form.control,
11196
+ name: "metadata"
11197
+ });
11198
+ function deleteRow(index) {
11199
+ remove(index);
11200
+ if (fields.length === 1) {
11201
+ insert(0, {
11202
+ key: "",
11203
+ value: "",
11204
+ disabled: false
11205
+ });
11206
+ }
11207
+ }
11208
+ function insertRow(index, position) {
11209
+ insert(index + (position === "above" ? 0 : 1), {
11210
+ key: "",
11211
+ value: "",
11212
+ disabled: false
11213
+ });
11214
+ }
11502
11215
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11503
11216
  KeyboundForm,
11504
11217
  {
11218
+ onSubmit: handleSubmit,
11505
11219
  className: "flex flex-1 flex-col overflow-hidden",
11506
- onSubmit,
11507
11220
  children: [
11508
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11509
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11510
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11221
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11222
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11223
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11224
+ /* @__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" }) }),
11225
+ /* @__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" }) })
11226
+ ] }),
11227
+ fields.map((field, index) => {
11228
+ const isDisabled = field.disabled || false;
11229
+ let placeholder = "-";
11230
+ if (typeof field.value === "object") {
11231
+ placeholder = "{ ... }";
11232
+ }
11233
+ if (Array.isArray(field.value)) {
11234
+ placeholder = "[ ... ]";
11235
+ }
11236
+ return /* @__PURE__ */ jsxRuntime.jsx(
11237
+ ConditionalTooltip,
11238
+ {
11239
+ showTooltip: isDisabled,
11240
+ content: "This row is disabled because it contains non-primitive data.",
11241
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11242
+ /* @__PURE__ */ jsxRuntime.jsxs(
11243
+ "div",
11244
+ {
11245
+ className: ui.clx("grid grid-cols-2 divide-x", {
11246
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11247
+ }),
11248
+ children: [
11249
+ /* @__PURE__ */ jsxRuntime.jsx(
11250
+ Form$2.Field,
11251
+ {
11252
+ control: form.control,
11253
+ name: `metadata.${index}.key`,
11254
+ render: ({ field: field2 }) => {
11255
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11256
+ GridInput,
11257
+ {
11258
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11259
+ ...field2,
11260
+ disabled: isDisabled,
11261
+ placeholder: "Key"
11262
+ }
11263
+ ) }) });
11264
+ }
11265
+ }
11266
+ ),
11267
+ /* @__PURE__ */ jsxRuntime.jsx(
11268
+ Form$2.Field,
11269
+ {
11270
+ control: form.control,
11271
+ name: `metadata.${index}.value`,
11272
+ render: ({ field: { value, ...field2 } }) => {
11273
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11274
+ GridInput,
11275
+ {
11276
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11277
+ ...field2,
11278
+ value: isDisabled ? placeholder : value,
11279
+ disabled: isDisabled,
11280
+ placeholder: "Value"
11281
+ }
11282
+ ) }) });
11283
+ }
11284
+ }
11285
+ )
11286
+ ]
11287
+ }
11288
+ ),
11289
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11290
+ /* @__PURE__ */ jsxRuntime.jsx(
11291
+ ui.DropdownMenu.Trigger,
11292
+ {
11293
+ className: ui.clx(
11294
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11295
+ {
11296
+ hidden: isDisabled
11297
+ }
11298
+ ),
11299
+ disabled: isDisabled,
11300
+ asChild: true,
11301
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11302
+ }
11303
+ ),
11304
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11305
+ /* @__PURE__ */ jsxRuntime.jsxs(
11306
+ ui.DropdownMenu.Item,
11307
+ {
11308
+ className: "gap-x-2",
11309
+ onClick: () => insertRow(index, "above"),
11310
+ children: [
11311
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11312
+ "Insert row above"
11313
+ ]
11314
+ }
11315
+ ),
11316
+ /* @__PURE__ */ jsxRuntime.jsxs(
11317
+ ui.DropdownMenu.Item,
11318
+ {
11319
+ className: "gap-x-2",
11320
+ onClick: () => insertRow(index, "below"),
11321
+ children: [
11322
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11323
+ "Insert row below"
11324
+ ]
11325
+ }
11326
+ ),
11327
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11328
+ /* @__PURE__ */ jsxRuntime.jsxs(
11329
+ ui.DropdownMenu.Item,
11330
+ {
11331
+ className: "gap-x-2",
11332
+ onClick: () => deleteRow(index),
11333
+ children: [
11334
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11335
+ "Delete row"
11336
+ ]
11337
+ }
11338
+ )
11339
+ ] })
11340
+ ] })
11341
+ ] })
11342
+ },
11343
+ field.id
11344
+ );
11345
+ })
11346
+ ] }),
11347
+ 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." })
11348
+ ] }),
11349
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11350
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11511
11351
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11512
11352
  ] }) })
11513
11353
  ]
11514
11354
  }
11515
- ) });
11355
+ ) });
11356
+ };
11357
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11358
+ return /* @__PURE__ */ jsxRuntime.jsx(
11359
+ "input",
11360
+ {
11361
+ ref,
11362
+ ...props,
11363
+ autoComplete: "off",
11364
+ className: ui.clx(
11365
+ "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",
11366
+ className
11367
+ )
11368
+ }
11369
+ );
11370
+ });
11371
+ GridInput.displayName = "MetadataForm.GridInput";
11372
+ const PlaceholderInner = () => {
11373
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11374
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11375
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11376
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11377
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11378
+ ] }) })
11379
+ ] });
11516
11380
  };
11517
- const SalesChannelField = ({ control, order }) => {
11518
- const salesChannels = useComboboxData({
11519
- queryFn: async (params) => {
11520
- return await sdk.admin.salesChannel.list(params);
11521
- },
11522
- queryKey: ["sales-channels"],
11523
- getOptions: (data) => {
11524
- return data.sales_channels.map((salesChannel) => ({
11525
- label: salesChannel.name,
11526
- value: salesChannel.id
11527
- }));
11528
- },
11529
- defaultValue: order.sales_channel_id || void 0
11381
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11382
+ function getDefaultValues(metadata) {
11383
+ if (!metadata || !Object.keys(metadata).length) {
11384
+ return [
11385
+ {
11386
+ key: "",
11387
+ value: "",
11388
+ disabled: false
11389
+ }
11390
+ ];
11391
+ }
11392
+ return Object.entries(metadata).map(([key, value]) => {
11393
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11394
+ return {
11395
+ key,
11396
+ value,
11397
+ disabled: true
11398
+ };
11399
+ }
11400
+ let stringValue = value;
11401
+ if (typeof value !== "string") {
11402
+ stringValue = JSON.stringify(value);
11403
+ }
11404
+ return {
11405
+ key,
11406
+ value: stringValue,
11407
+ original_key: key
11408
+ };
11530
11409
  });
11531
- return /* @__PURE__ */ jsxRuntime.jsx(
11532
- Form$2.Field,
11533
- {
11534
- control,
11535
- name: "sales_channel_id",
11536
- render: ({ field }) => {
11537
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11538
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11539
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11540
- Combobox,
11541
- {
11542
- options: salesChannels.options,
11543
- fetchNextPage: salesChannels.fetchNextPage,
11544
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11545
- searchValue: salesChannels.searchValue,
11546
- onSearchValueChange: salesChannels.onSearchValueChange,
11547
- placeholder: "Select sales channel",
11548
- ...field
11549
- }
11550
- ) }),
11551
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11552
- ] });
11410
+ }
11411
+ function parseValues(values) {
11412
+ const metadata = values.metadata;
11413
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11414
+ if (isEmpty) {
11415
+ return null;
11416
+ }
11417
+ const update = {};
11418
+ metadata.forEach((field) => {
11419
+ let key = field.key;
11420
+ let value = field.value;
11421
+ const disabled = field.disabled;
11422
+ if (!key || !value) {
11423
+ return;
11424
+ }
11425
+ if (disabled) {
11426
+ update[key] = value;
11427
+ return;
11428
+ }
11429
+ key = key.trim();
11430
+ value = value.trim();
11431
+ if (value === "true") {
11432
+ update[key] = true;
11433
+ } else if (value === "false") {
11434
+ update[key] = false;
11435
+ } else {
11436
+ const parsedNumber = parseFloat(value);
11437
+ if (!isNaN(parsedNumber)) {
11438
+ update[key] = parsedNumber;
11439
+ } else {
11440
+ update[key] = value;
11553
11441
  }
11554
11442
  }
11443
+ });
11444
+ return update;
11445
+ }
11446
+ function getHasUneditableRows(metadata) {
11447
+ if (!metadata) {
11448
+ return false;
11449
+ }
11450
+ return Object.values(metadata).some(
11451
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11555
11452
  );
11556
- };
11557
- const schema$2 = objectType({
11558
- sales_channel_id: stringType().min(1)
11559
- });
11453
+ }
11560
11454
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11561
11455
  const Shipping = () => {
11562
11456
  var _a;
@@ -12396,7 +12290,7 @@ const ShippingAddressForm = ({ order }) => {
12396
12290
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12397
12291
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12398
12292
  },
12399
- resolver: zod.zodResolver(schema$1)
12293
+ resolver: zod.zodResolver(schema$2)
12400
12294
  });
12401
12295
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12402
12296
  const { handleSuccess } = useRouteModal();
@@ -12566,7 +12460,7 @@ const ShippingAddressForm = ({ order }) => {
12566
12460
  }
12567
12461
  ) });
12568
12462
  };
12569
- const schema$1 = addressSchema;
12463
+ const schema$2 = addressSchema;
12570
12464
  const TransferOwnership = () => {
12571
12465
  const { id } = reactRouterDom.useParams();
12572
12466
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12590,7 +12484,7 @@ const TransferOwnershipForm = ({ order }) => {
12590
12484
  defaultValues: {
12591
12485
  customer_id: order.customer_id || ""
12592
12486
  },
12593
- resolver: zod.zodResolver(schema)
12487
+ resolver: zod.zodResolver(schema$1)
12594
12488
  });
12595
12489
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12596
12490
  const { handleSuccess } = useRouteModal();
@@ -13040,9 +12934,115 @@ const Illustration = () => {
13040
12934
  }
13041
12935
  );
13042
12936
  };
13043
- const schema = objectType({
12937
+ const schema$1 = objectType({
13044
12938
  customer_id: stringType().min(1)
13045
12939
  });
12940
+ const SalesChannel = () => {
12941
+ const { id } = reactRouterDom.useParams();
12942
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12943
+ id,
12944
+ {
12945
+ fields: "+sales_channel_id"
12946
+ },
12947
+ {
12948
+ enabled: !!id
12949
+ }
12950
+ );
12951
+ if (isError) {
12952
+ throw error;
12953
+ }
12954
+ const ISrEADY = !!draft_order && !isPending;
12955
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12956
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12958
+ /* @__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" }) })
12959
+ ] }),
12960
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12961
+ ] });
12962
+ };
12963
+ const SalesChannelForm = ({ order }) => {
12964
+ const form = reactHookForm.useForm({
12965
+ defaultValues: {
12966
+ sales_channel_id: order.sales_channel_id || ""
12967
+ },
12968
+ resolver: zod.zodResolver(schema)
12969
+ });
12970
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12971
+ const { handleSuccess } = useRouteModal();
12972
+ const onSubmit = form.handleSubmit(async (data) => {
12973
+ await mutateAsync(
12974
+ {
12975
+ sales_channel_id: data.sales_channel_id
12976
+ },
12977
+ {
12978
+ onSuccess: () => {
12979
+ ui.toast.success("Sales channel updated");
12980
+ handleSuccess();
12981
+ },
12982
+ onError: (error) => {
12983
+ ui.toast.error(error.message);
12984
+ }
12985
+ }
12986
+ );
12987
+ });
12988
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12989
+ KeyboundForm,
12990
+ {
12991
+ className: "flex flex-1 flex-col overflow-hidden",
12992
+ onSubmit,
12993
+ children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12996
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12998
+ ] }) })
12999
+ ]
13000
+ }
13001
+ ) });
13002
+ };
13003
+ const SalesChannelField = ({ control, order }) => {
13004
+ const salesChannels = useComboboxData({
13005
+ queryFn: async (params) => {
13006
+ return await sdk.admin.salesChannel.list(params);
13007
+ },
13008
+ queryKey: ["sales-channels"],
13009
+ getOptions: (data) => {
13010
+ return data.sales_channels.map((salesChannel) => ({
13011
+ label: salesChannel.name,
13012
+ value: salesChannel.id
13013
+ }));
13014
+ },
13015
+ defaultValue: order.sales_channel_id || void 0
13016
+ });
13017
+ return /* @__PURE__ */ jsxRuntime.jsx(
13018
+ Form$2.Field,
13019
+ {
13020
+ control,
13021
+ name: "sales_channel_id",
13022
+ render: ({ field }) => {
13023
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13024
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13025
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Combobox,
13027
+ {
13028
+ options: salesChannels.options,
13029
+ fetchNextPage: salesChannels.fetchNextPage,
13030
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13031
+ searchValue: salesChannels.searchValue,
13032
+ onSearchValueChange: salesChannels.onSearchValueChange,
13033
+ placeholder: "Select sales channel",
13034
+ ...field
13035
+ }
13036
+ ) }),
13037
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13038
+ ] });
13039
+ }
13040
+ }
13041
+ );
13042
+ };
13043
+ const schema = objectType({
13044
+ sales_channel_id: stringType().min(1)
13045
+ });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13064,32 +13064,28 @@ const routeModule = {
13064
13064
  loader,
13065
13065
  children: [
13066
13066
  {
13067
- Component: CustomItems,
13068
- path: "/draft-orders/:id/custom-items"
13067
+ Component: BillingAddress,
13068
+ path: "/draft-orders/:id/billing-address"
13069
13069
  },
13070
13070
  {
13071
- Component: Items,
13072
- path: "/draft-orders/:id/items"
13071
+ Component: CustomItems,
13072
+ path: "/draft-orders/:id/custom-items"
13073
13073
  },
13074
13074
  {
13075
13075
  Component: Email,
13076
13076
  path: "/draft-orders/:id/email"
13077
13077
  },
13078
13078
  {
13079
- Component: Metadata,
13080
- path: "/draft-orders/:id/metadata"
13081
- },
13082
- {
13083
- Component: BillingAddress,
13084
- path: "/draft-orders/:id/billing-address"
13079
+ Component: Items,
13080
+ path: "/draft-orders/:id/items"
13085
13081
  },
13086
13082
  {
13087
13083
  Component: Promotions,
13088
13084
  path: "/draft-orders/:id/promotions"
13089
13085
  },
13090
13086
  {
13091
- Component: SalesChannel,
13092
- path: "/draft-orders/:id/sales-channel"
13087
+ Component: Metadata,
13088
+ path: "/draft-orders/:id/metadata"
13093
13089
  },
13094
13090
  {
13095
13091
  Component: Shipping,
@@ -13102,6 +13098,10 @@ const routeModule = {
13102
13098
  {
13103
13099
  Component: TransferOwnership,
13104
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
+ },
13102
+ {
13103
+ Component: SalesChannel,
13104
+ path: "/draft-orders/:id/sales-channel"
13105
13105
  }
13106
13106
  ]
13107
13107
  }