@medusajs/draft-order 2.10.4-snapshot-20251003114416 → 2.10.4-snapshot-20251003141424

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,10 +9573,31 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const BillingAddress = () => {
9576
+ const CustomItems = () => {
9577
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9579
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9580
+ ] });
9581
+ };
9582
+ const CustomItemsForm = () => {
9583
+ const form = reactHookForm.useForm({
9584
+ resolver: zod.zodResolver(schema$5)
9585
+ });
9586
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9590
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9591
+ ] }) })
9592
+ ] }) });
9593
+ };
9594
+ const schema$5 = objectType({
9595
+ email: stringType().email()
9596
+ });
9597
+ const Email = () => {
9577
9598
  const { id } = reactRouterDom.useParams();
9578
9599
  const { order, isPending, isError, error } = useOrder(id, {
9579
- fields: "+billing_address"
9600
+ fields: "+email"
9580
9601
  });
9581
9602
  if (isError) {
9582
9603
  throw error;
@@ -9584,34 +9605,24 @@ const BillingAddress = () => {
9584
9605
  const isReady = !isPending && !!order;
9585
9606
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
9607
  /* @__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" }) })
9608
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9609
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9589
9610
  ] }),
9590
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9611
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9591
9612
  ] });
9592
9613
  };
9593
- const BillingAddressForm = ({ order }) => {
9594
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9614
+ const EmailForm = ({ order }) => {
9595
9615
  const form = reactHookForm.useForm({
9596
9616
  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) ?? ""
9617
+ email: order.email ?? ""
9607
9618
  },
9608
- resolver: zod.zodResolver(schema$5)
9619
+ resolver: zod.zodResolver(schema$4)
9609
9620
  });
9610
9621
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
9622
  const { handleSuccess } = useRouteModal();
9612
9623
  const onSubmit = form.handleSubmit(async (data) => {
9613
9624
  await mutateAsync(
9614
- { billing_address: data },
9625
+ { email: data.email },
9615
9626
  {
9616
9627
  onSuccess: () => {
9617
9628
  handleSuccess();
@@ -9628,132 +9639,18 @@ const BillingAddressForm = ({ order }) => {
9628
9639
  className: "flex flex-1 flex-col overflow-hidden",
9629
9640
  onSubmit,
9630
9641
  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
- ] }) }),
9642
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9643
+ Form$2.Field,
9644
+ {
9645
+ control: form.control,
9646
+ name: "email",
9647
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9651
+ ] })
9652
+ }
9653
+ ) }),
9757
9654
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
9655
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
9656
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -9762,698 +9659,1029 @@ const BillingAddressForm = ({ order }) => {
9762
9659
  }
9763
9660
  ) });
9764
9661
  };
9765
- const schema$5 = addressSchema;
9766
- const CustomItems = () => {
9767
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
- ] });
9771
- };
9772
- const CustomItemsForm = () => {
9773
- const form = reactHookForm.useForm({
9774
- resolver: zod.zodResolver(schema$4)
9775
- });
9776
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
- ] }) })
9782
- ] }) });
9783
- };
9784
9662
  const schema$4 = objectType({
9785
9663
  email: stringType().email()
9786
9664
  });
9787
- const NumberInput = React.forwardRef(
9788
- ({
9789
- value,
9790
- onChange,
9791
- size = "base",
9792
- min = 0,
9793
- max = 100,
9794
- step = 1,
9795
- className,
9796
- disabled,
9797
- ...props
9798
- }, ref) => {
9799
- const handleChange = (event) => {
9800
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9801
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9802
- onChange(newValue);
9803
- }
9804
- };
9805
- const handleIncrement = () => {
9806
- const newValue = value + step;
9807
- if (max === void 0 || newValue <= max) {
9808
- onChange(newValue);
9809
- }
9810
- };
9811
- const handleDecrement = () => {
9812
- const newValue = value - step;
9813
- if (min === void 0 || newValue >= min) {
9814
- onChange(newValue);
9815
- }
9816
- };
9665
+ const InlineTip = React.forwardRef(
9666
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9667
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9817
9668
  return /* @__PURE__ */ jsxRuntime.jsxs(
9818
9669
  "div",
9819
9670
  {
9671
+ ref,
9820
9672
  className: ui.clx(
9821
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9822
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9823
- {
9824
- "h-7": size === "small",
9825
- "h-8": size === "base"
9826
- },
9673
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9827
9674
  className
9828
9675
  ),
9676
+ ...props,
9829
9677
  children: [
9830
9678
  /* @__PURE__ */ jsxRuntime.jsx(
9831
- "input",
9679
+ "div",
9832
9680
  {
9833
- ref,
9834
- type: "number",
9835
- value,
9836
- onChange: handleChange,
9837
- min,
9838
- max,
9839
- step,
9840
- className: ui.clx(
9841
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9842
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9843
- "placeholder:text-ui-fg-muted"
9844
- ),
9845
- ...props
9846
- }
9847
- ),
9848
- /* @__PURE__ */ jsxRuntime.jsxs(
9849
- "button",
9850
- {
9851
- className: ui.clx(
9852
- "flex items-center justify-center outline-none transition-fg",
9853
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9854
- "focus:bg-ui-bg-field-component-hover",
9855
- "hover:bg-ui-bg-field-component-hover",
9856
- {
9857
- "size-7": size === "small",
9858
- "size-8": size === "base"
9859
- }
9860
- ),
9861
- type: "button",
9862
- onClick: handleDecrement,
9863
- disabled: min !== void 0 && value <= min || disabled,
9864
- children: [
9865
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9866
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9867
- ]
9681
+ role: "presentation",
9682
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9683
+ "bg-ui-tag-orange-icon": variant === "warning"
9684
+ })
9868
9685
  }
9869
9686
  ),
9870
- /* @__PURE__ */ jsxRuntime.jsxs(
9871
- "button",
9872
- {
9873
- className: ui.clx(
9874
- "flex items-center justify-center outline-none transition-fg",
9875
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9876
- "focus:bg-ui-bg-field-hover",
9877
- "hover:bg-ui-bg-field-hover",
9878
- {
9879
- "size-7": size === "small",
9880
- "size-8": size === "base"
9881
- }
9882
- ),
9883
- type: "button",
9884
- onClick: handleIncrement,
9885
- disabled: max !== void 0 && value >= max || disabled,
9886
- children: [
9887
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9888
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9889
- ]
9890
- }
9891
- )
9687
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9688
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9689
+ labelValue,
9690
+ ":"
9691
+ ] }),
9692
+ " ",
9693
+ children
9694
+ ] })
9892
9695
  ]
9893
9696
  }
9894
9697
  );
9895
9698
  }
9896
9699
  );
9897
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9898
- const productVariantsQueryKeys = {
9899
- list: (query2) => [
9900
- PRODUCT_VARIANTS_QUERY_KEY,
9901
- query2 ? query2 : void 0
9902
- ]
9903
- };
9904
- const useProductVariants = (query2, options) => {
9905
- const { data, ...rest } = reactQuery.useQuery({
9906
- queryKey: productVariantsQueryKeys.list(query2),
9907
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9908
- ...options
9909
- });
9910
- return { ...data, ...rest };
9911
- };
9912
- const useCancelOrderEdit = ({ preview }) => {
9913
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9914
- const onCancel = React.useCallback(async () => {
9915
- if (!preview) {
9916
- return true;
9917
- }
9918
- let res = false;
9919
- await cancelOrderEdit(void 0, {
9920
- onError: (e) => {
9921
- ui.toast.error(e.message);
9922
- },
9923
- onSuccess: () => {
9924
- res = true;
9925
- }
9926
- });
9927
- return res;
9928
- }, [preview, cancelOrderEdit]);
9929
- return { onCancel };
9930
- };
9931
- let IS_REQUEST_RUNNING = false;
9932
- const useInitiateOrderEdit = ({
9933
- preview
9934
- }) => {
9935
- const navigate = reactRouterDom.useNavigate();
9936
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9937
- React.useEffect(() => {
9938
- async function run() {
9939
- if (IS_REQUEST_RUNNING || !preview) {
9940
- return;
9941
- }
9942
- if (preview.order_change) {
9943
- return;
9944
- }
9945
- IS_REQUEST_RUNNING = true;
9946
- await mutateAsync(void 0, {
9947
- onError: (e) => {
9948
- ui.toast.error(e.message);
9949
- navigate(`/draft-orders/${preview.id}`, { replace: true });
9950
- return;
9951
- }
9952
- });
9953
- IS_REQUEST_RUNNING = false;
9954
- }
9955
- run();
9956
- }, [preview, navigate, mutateAsync]);
9957
- };
9958
- function convertNumber(value) {
9959
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
9960
- }
9961
- const STACKED_MODAL_ID = "items_stacked_modal";
9962
- const Items = () => {
9700
+ InlineTip.displayName = "InlineTip";
9701
+ const MetadataFieldSchema = objectType({
9702
+ key: stringType(),
9703
+ disabled: booleanType().optional(),
9704
+ value: anyType()
9705
+ });
9706
+ const MetadataSchema = objectType({
9707
+ metadata: arrayType(MetadataFieldSchema)
9708
+ });
9709
+ const Metadata = () => {
9963
9710
  const { id } = reactRouterDom.useParams();
9964
- const {
9965
- order: preview,
9966
- isPending: isPreviewPending,
9967
- isError: isPreviewError,
9968
- error: previewError
9969
- } = useOrderPreview(id, void 0, {
9970
- placeholderData: reactQuery.keepPreviousData
9711
+ const { order, isPending, isError, error } = useOrder(id, {
9712
+ fields: "metadata"
9971
9713
  });
9972
- useInitiateOrderEdit({ preview });
9973
- const { draft_order, isPending, isError, error } = useDraftOrder(
9974
- id,
9975
- {
9976
- fields: "currency_code"
9977
- },
9978
- {
9979
- enabled: !!id
9980
- }
9981
- );
9982
- const { onCancel } = useCancelOrderEdit({ preview });
9983
9714
  if (isError) {
9984
9715
  throw error;
9985
9716
  }
9986
- if (isPreviewError) {
9987
- throw previewError;
9988
- }
9989
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
9990
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9991
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
9992
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
9993
- ] }) });
9717
+ const isReady = !isPending && !!order;
9718
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9719
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9720
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9721
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9722
+ ] }),
9723
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9724
+ ] });
9994
9725
  };
9995
- const ItemsForm = ({ preview, currencyCode }) => {
9996
- var _a;
9997
- const [isSubmitting, setIsSubmitting] = React.useState(false);
9998
- const [modalContent, setModalContent] = React.useState(
9999
- null
10000
- );
9726
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9727
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9728
+ const MetadataForm = ({ orderId, metadata }) => {
10001
9729
  const { handleSuccess } = useRouteModal();
10002
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10003
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10004
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10005
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10006
- const matches = React.useMemo(() => {
10007
- return matchSorter.matchSorter(preview.items, query2, {
10008
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10009
- });
10010
- }, [preview.items, query2]);
10011
- const onSubmit = async () => {
10012
- setIsSubmitting(true);
10013
- let requestSucceeded = false;
10014
- await requestOrderEdit(void 0, {
10015
- onError: (e) => {
10016
- ui.toast.error(`Failed to request order edit: ${e.message}`);
9730
+ const hasUneditableRows = getHasUneditableRows(metadata);
9731
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9732
+ const form = reactHookForm.useForm({
9733
+ defaultValues: {
9734
+ metadata: getDefaultValues(metadata)
9735
+ },
9736
+ resolver: zod.zodResolver(MetadataSchema)
9737
+ });
9738
+ const handleSubmit = form.handleSubmit(async (data) => {
9739
+ const parsedData = parseValues(data);
9740
+ await mutateAsync(
9741
+ {
9742
+ metadata: parsedData
10017
9743
  },
10018
- onSuccess: () => {
10019
- requestSucceeded = true;
9744
+ {
9745
+ onSuccess: () => {
9746
+ ui.toast.success("Metadata updated");
9747
+ handleSuccess();
9748
+ },
9749
+ onError: (error) => {
9750
+ ui.toast.error(error.message);
9751
+ }
10020
9752
  }
10021
- });
10022
- if (!requestSucceeded) {
10023
- setIsSubmitting(false);
10024
- return;
9753
+ );
9754
+ });
9755
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9756
+ control: form.control,
9757
+ name: "metadata"
9758
+ });
9759
+ function deleteRow(index) {
9760
+ remove(index);
9761
+ if (fields.length === 1) {
9762
+ insert(0, {
9763
+ key: "",
9764
+ value: "",
9765
+ disabled: false
9766
+ });
10025
9767
  }
10026
- await confirmOrderEdit(void 0, {
10027
- onError: (e) => {
10028
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10029
- },
10030
- onSuccess: () => {
10031
- handleSuccess();
10032
- },
10033
- onSettled: () => {
10034
- setIsSubmitting(false);
10035
- }
9768
+ }
9769
+ function insertRow(index, position) {
9770
+ insert(index + (position === "above" ? 0 : 1), {
9771
+ key: "",
9772
+ value: "",
9773
+ disabled: false
10036
9774
  });
10037
- };
10038
- const onKeyDown = React.useCallback(
10039
- (e) => {
10040
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10041
- if (modalContent || isSubmitting) {
10042
- return;
10043
- }
10044
- onSubmit();
10045
- }
10046
- },
10047
- [modalContent, isSubmitting, onSubmit]
10048
- );
10049
- React.useEffect(() => {
10050
- document.addEventListener("keydown", onKeyDown);
10051
- return () => {
10052
- document.removeEventListener("keydown", onKeyDown);
10053
- };
10054
- }, [onKeyDown]);
10055
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10056
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10057
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10058
- StackedFocusModal,
10059
- {
10060
- id: STACKED_MODAL_ID,
10061
- onOpenChangeCallback: (open) => {
10062
- if (!open) {
10063
- setModalContent(null);
10064
- }
10065
- },
10066
- children: [
10067
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10068
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10069
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10070
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
9775
+ }
9776
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9777
+ KeyboundForm,
9778
+ {
9779
+ onSubmit: handleSubmit,
9780
+ className: "flex flex-1 flex-col overflow-hidden",
9781
+ children: [
9782
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9783
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9784
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9785
+ /* @__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" }) }),
9786
+ /* @__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" }) })
10071
9787
  ] }),
10072
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10073
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10074
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10075
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10076
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10077
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10078
- ] }),
10079
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10080
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10081
- ui.Input,
10082
- {
10083
- type: "search",
10084
- placeholder: "Search items",
10085
- value: searchValue,
10086
- onChange: (e) => onSearchValueChange(e.target.value)
10087
- }
10088
- ) }),
10089
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10090
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10091
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9788
+ fields.map((field, index) => {
9789
+ const isDisabled = field.disabled || false;
9790
+ let placeholder = "-";
9791
+ if (typeof field.value === "object") {
9792
+ placeholder = "{ ... }";
9793
+ }
9794
+ if (Array.isArray(field.value)) {
9795
+ placeholder = "[ ... ]";
9796
+ }
9797
+ return /* @__PURE__ */ jsxRuntime.jsx(
9798
+ ConditionalTooltip,
9799
+ {
9800
+ showTooltip: isDisabled,
9801
+ content: "This row is disabled because it contains non-primitive data.",
9802
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9803
+ /* @__PURE__ */ jsxRuntime.jsxs(
9804
+ "div",
9805
+ {
9806
+ className: ui.clx("grid grid-cols-2 divide-x", {
9807
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9808
+ }),
9809
+ children: [
9810
+ /* @__PURE__ */ jsxRuntime.jsx(
9811
+ Form$2.Field,
9812
+ {
9813
+ control: form.control,
9814
+ name: `metadata.${index}.key`,
9815
+ render: ({ field: field2 }) => {
9816
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9817
+ GridInput,
9818
+ {
9819
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9820
+ ...field2,
9821
+ disabled: isDisabled,
9822
+ placeholder: "Key"
9823
+ }
9824
+ ) }) });
9825
+ }
9826
+ }
9827
+ ),
9828
+ /* @__PURE__ */ jsxRuntime.jsx(
9829
+ Form$2.Field,
9830
+ {
9831
+ control: form.control,
9832
+ name: `metadata.${index}.value`,
9833
+ render: ({ field: { value, ...field2 } }) => {
9834
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9835
+ GridInput,
9836
+ {
9837
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9838
+ ...field2,
9839
+ value: isDisabled ? placeholder : value,
9840
+ disabled: isDisabled,
9841
+ placeholder: "Value"
9842
+ }
9843
+ ) }) });
9844
+ }
9845
+ }
9846
+ )
9847
+ ]
9848
+ }
9849
+ ),
9850
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10092
9851
  /* @__PURE__ */ jsxRuntime.jsx(
10093
- StackedModalTrigger$1,
9852
+ ui.DropdownMenu.Trigger,
10094
9853
  {
10095
- type: "add-items",
10096
- setModalContent
9854
+ className: ui.clx(
9855
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9856
+ {
9857
+ hidden: isDisabled
9858
+ }
9859
+ ),
9860
+ disabled: isDisabled,
9861
+ asChild: true,
9862
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10097
9863
  }
10098
9864
  ),
10099
- /* @__PURE__ */ jsxRuntime.jsx(
10100
- StackedModalTrigger$1,
10101
- {
10102
- type: "add-custom-item",
10103
- setModalContent
10104
- }
10105
- )
9865
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9866
+ /* @__PURE__ */ jsxRuntime.jsxs(
9867
+ ui.DropdownMenu.Item,
9868
+ {
9869
+ className: "gap-x-2",
9870
+ onClick: () => insertRow(index, "above"),
9871
+ children: [
9872
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9873
+ "Insert row above"
9874
+ ]
9875
+ }
9876
+ ),
9877
+ /* @__PURE__ */ jsxRuntime.jsxs(
9878
+ ui.DropdownMenu.Item,
9879
+ {
9880
+ className: "gap-x-2",
9881
+ onClick: () => insertRow(index, "below"),
9882
+ children: [
9883
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
9884
+ "Insert row below"
9885
+ ]
9886
+ }
9887
+ ),
9888
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
9889
+ /* @__PURE__ */ jsxRuntime.jsxs(
9890
+ ui.DropdownMenu.Item,
9891
+ {
9892
+ className: "gap-x-2",
9893
+ onClick: () => deleteRow(index),
9894
+ children: [
9895
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
9896
+ "Delete row"
9897
+ ]
9898
+ }
9899
+ )
9900
+ ] })
10106
9901
  ] })
10107
9902
  ] })
10108
- ] })
10109
- ] }),
10110
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10111
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10112
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10113
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10114
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10115
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
10116
- ] }) }),
10117
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10118
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10119
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10120
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10121
- Item,
10122
- {
10123
- item,
10124
- preview,
10125
- currencyCode
10126
- },
10127
- item.id
10128
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10129
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10130
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10131
- 'No items found for "',
10132
- query2,
10133
- '".'
10134
- ] })
10135
- ] }) })
10136
- ] })
10137
- ] }),
10138
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10139
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10140
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10141
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10142
- ui.Text,
10143
- {
10144
- size: "small",
10145
- leading: "compact",
10146
- className: "text-ui-fg-subtle",
10147
- children: [
10148
- itemCount,
10149
- " ",
10150
- itemCount === 1 ? "item" : "items"
10151
- ]
10152
- }
10153
- ) }),
10154
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10155
- ] })
10156
- ] }) }),
10157
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10158
- CustomItemForm,
10159
- {
10160
- orderId: preview.id,
10161
- currencyCode
10162
- }
10163
- ) : null)
10164
- ]
10165
- }
10166
- ) }),
10167
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10168
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10169
- /* @__PURE__ */ jsxRuntime.jsx(
10170
- ui.Button,
10171
- {
10172
- size: "small",
10173
- type: "button",
10174
- onClick: onSubmit,
10175
- isLoading: isSubmitting,
10176
- children: "Save"
10177
- }
10178
- )
10179
- ] }) })
10180
- ] });
9903
+ },
9904
+ field.id
9905
+ );
9906
+ })
9907
+ ] }),
9908
+ 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." })
9909
+ ] }),
9910
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9911
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9912
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9913
+ ] }) })
9914
+ ]
9915
+ }
9916
+ ) });
10181
9917
  };
10182
- const Item = ({ item, preview, currencyCode }) => {
10183
- if (item.variant_id) {
10184
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10185
- }
10186
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
9918
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
9919
+ return /* @__PURE__ */ jsxRuntime.jsx(
9920
+ "input",
9921
+ {
9922
+ ref,
9923
+ ...props,
9924
+ autoComplete: "off",
9925
+ className: ui.clx(
9926
+ "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",
9927
+ className
9928
+ )
9929
+ }
9930
+ );
9931
+ });
9932
+ GridInput.displayName = "MetadataForm.GridInput";
9933
+ const PlaceholderInner = () => {
9934
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9935
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9936
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9937
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
9938
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
9939
+ ] }) })
9940
+ ] });
10187
9941
  };
10188
- const VariantItem = ({ item, preview, currencyCode }) => {
10189
- const [editing, setEditing] = React.useState(false);
10190
- const form = reactHookForm.useForm({
10191
- defaultValues: {
10192
- quantity: item.quantity,
10193
- unit_price: item.unit_price
10194
- },
10195
- resolver: zod.zodResolver(variantItemSchema)
9942
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
9943
+ function getDefaultValues(metadata) {
9944
+ if (!metadata || !Object.keys(metadata).length) {
9945
+ return [
9946
+ {
9947
+ key: "",
9948
+ value: "",
9949
+ disabled: false
9950
+ }
9951
+ ];
9952
+ }
9953
+ return Object.entries(metadata).map(([key, value]) => {
9954
+ if (!EDITABLE_TYPES.includes(typeof value)) {
9955
+ return {
9956
+ key,
9957
+ value,
9958
+ disabled: true
9959
+ };
9960
+ }
9961
+ let stringValue = value;
9962
+ if (typeof value !== "string") {
9963
+ stringValue = JSON.stringify(value);
9964
+ }
9965
+ return {
9966
+ key,
9967
+ value: stringValue,
9968
+ original_key: key
9969
+ };
10196
9970
  });
10197
- const actionId = React.useMemo(() => {
10198
- var _a, _b;
10199
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10200
- }, [item]);
10201
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10202
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10203
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10204
- const onSubmit = form.handleSubmit(async (data) => {
10205
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10206
- setEditing(false);
9971
+ }
9972
+ function parseValues(values) {
9973
+ const metadata = values.metadata;
9974
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9975
+ if (isEmpty) {
9976
+ return null;
9977
+ }
9978
+ const update = {};
9979
+ metadata.forEach((field) => {
9980
+ let key = field.key;
9981
+ let value = field.value;
9982
+ const disabled = field.disabled;
9983
+ if (!key || !value) {
10207
9984
  return;
10208
9985
  }
10209
- if (!actionId) {
10210
- await updateOriginalItem(
10211
- {
10212
- item_id: item.id,
10213
- quantity: data.quantity,
10214
- unit_price: convertNumber(data.unit_price)
10215
- },
10216
- {
10217
- onSuccess: () => {
10218
- setEditing(false);
10219
- },
10220
- onError: (e) => {
10221
- ui.toast.error(e.message);
10222
- }
10223
- }
10224
- );
9986
+ if (disabled) {
9987
+ update[key] = value;
10225
9988
  return;
10226
9989
  }
10227
- await updateActionItem(
10228
- {
10229
- action_id: actionId,
10230
- quantity: data.quantity,
10231
- unit_price: convertNumber(data.unit_price)
10232
- },
10233
- {
10234
- onSuccess: () => {
10235
- setEditing(false);
10236
- },
10237
- onError: (e) => {
10238
- ui.toast.error(e.message);
10239
- }
9990
+ key = key.trim();
9991
+ value = value.trim();
9992
+ if (value === "true") {
9993
+ update[key] = true;
9994
+ } else if (value === "false") {
9995
+ update[key] = false;
9996
+ } else {
9997
+ const parsedNumber = parseFloat(value);
9998
+ if (!isNaN(parsedNumber)) {
9999
+ update[key] = parsedNumber;
10000
+ } else {
10001
+ update[key] = value;
10240
10002
  }
10241
- );
10003
+ }
10242
10004
  });
10243
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10244
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10245
- /* @__PURE__ */ jsxRuntime.jsx(
10246
- Thumbnail,
10247
- {
10248
- thumbnail: item.thumbnail,
10249
- alt: item.product_title ?? void 0
10250
- }
10251
- ),
10252
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10253
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10254
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10005
+ return update;
10006
+ }
10007
+ function getHasUneditableRows(metadata) {
10008
+ if (!metadata) {
10009
+ return false;
10010
+ }
10011
+ return Object.values(metadata).some(
10012
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10013
+ );
10014
+ }
10015
+ const NumberInput = React.forwardRef(
10016
+ ({
10017
+ value,
10018
+ onChange,
10019
+ size = "base",
10020
+ min = 0,
10021
+ max = 100,
10022
+ step = 1,
10023
+ className,
10024
+ disabled,
10025
+ ...props
10026
+ }, ref) => {
10027
+ const handleChange = (event) => {
10028
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10029
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10030
+ onChange(newValue);
10031
+ }
10032
+ };
10033
+ const handleIncrement = () => {
10034
+ const newValue = value + step;
10035
+ if (max === void 0 || newValue <= max) {
10036
+ onChange(newValue);
10037
+ }
10038
+ };
10039
+ const handleDecrement = () => {
10040
+ const newValue = value - step;
10041
+ if (min === void 0 || newValue >= min) {
10042
+ onChange(newValue);
10043
+ }
10044
+ };
10045
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10046
+ "div",
10047
+ {
10048
+ className: ui.clx(
10049
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10050
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10051
+ {
10052
+ "h-7": size === "small",
10053
+ "h-8": size === "base"
10054
+ },
10055
+ className
10056
+ ),
10057
+ children: [
10058
+ /* @__PURE__ */ jsxRuntime.jsx(
10059
+ "input",
10060
+ {
10061
+ ref,
10062
+ type: "number",
10063
+ value,
10064
+ onChange: handleChange,
10065
+ min,
10066
+ max,
10067
+ step,
10068
+ className: ui.clx(
10069
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10070
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10071
+ "placeholder:text-ui-fg-muted"
10072
+ ),
10073
+ ...props
10074
+ }
10075
+ ),
10255
10076
  /* @__PURE__ */ jsxRuntime.jsxs(
10256
- ui.Text,
10077
+ "button",
10257
10078
  {
10258
- size: "small",
10259
- leading: "compact",
10260
- className: "text-ui-fg-subtle",
10079
+ className: ui.clx(
10080
+ "flex items-center justify-center outline-none transition-fg",
10081
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10082
+ "focus:bg-ui-bg-field-component-hover",
10083
+ "hover:bg-ui-bg-field-component-hover",
10084
+ {
10085
+ "size-7": size === "small",
10086
+ "size-8": size === "base"
10087
+ }
10088
+ ),
10089
+ type: "button",
10090
+ onClick: handleDecrement,
10091
+ disabled: min !== void 0 && value <= min || disabled,
10261
10092
  children: [
10262
- "(",
10263
- item.variant_title,
10264
- ")"
10093
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10094
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10265
10095
  ]
10266
10096
  }
10267
- )
10268
- ] }),
10269
- /* @__PURE__ */ jsxRuntime.jsx(
10270
- ui.Text,
10271
- {
10272
- size: "small",
10273
- leading: "compact",
10274
- className: "text-ui-fg-subtle",
10275
- children: item.variant_sku
10276
- }
10277
- )
10278
- ] })
10279
- ] }),
10280
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10281
- Form$2.Field,
10282
- {
10283
- control: form.control,
10284
- name: "quantity",
10285
- render: ({ field }) => {
10286
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10287
- }
10288
- }
10289
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10290
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10291
- Form$2.Field,
10292
- {
10293
- control: form.control,
10294
- name: "unit_price",
10295
- render: ({ field: { onChange, ...field } }) => {
10296
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10297
- ui.CurrencyInput,
10097
+ ),
10098
+ /* @__PURE__ */ jsxRuntime.jsxs(
10099
+ "button",
10298
10100
  {
10299
- ...field,
10300
- symbol: getNativeSymbol(currencyCode),
10301
- code: currencyCode,
10302
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10101
+ className: ui.clx(
10102
+ "flex items-center justify-center outline-none transition-fg",
10103
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10104
+ "focus:bg-ui-bg-field-hover",
10105
+ "hover:bg-ui-bg-field-hover",
10106
+ {
10107
+ "size-7": size === "small",
10108
+ "size-8": size === "base"
10109
+ }
10110
+ ),
10111
+ type: "button",
10112
+ onClick: handleIncrement,
10113
+ disabled: max !== void 0 && value >= max || disabled,
10114
+ children: [
10115
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10116
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10117
+ ]
10303
10118
  }
10304
- ) }) });
10305
- }
10306
- }
10307
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10308
- /* @__PURE__ */ jsxRuntime.jsx(
10309
- ui.IconButton,
10310
- {
10311
- type: "button",
10312
- size: "small",
10313
- onClick: editing ? onSubmit : () => {
10314
- setEditing(true);
10315
- },
10316
- disabled: isPending,
10317
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10119
+ )
10120
+ ]
10318
10121
  }
10319
- )
10320
- ] }) }) });
10122
+ );
10123
+ }
10124
+ );
10125
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10126
+ const productVariantsQueryKeys = {
10127
+ list: (query2) => [
10128
+ PRODUCT_VARIANTS_QUERY_KEY,
10129
+ query2 ? query2 : void 0
10130
+ ]
10321
10131
  };
10322
- const variantItemSchema = objectType({
10323
- quantity: numberType(),
10324
- unit_price: unionType([numberType(), stringType()])
10325
- });
10326
- const CustomItem = ({ item, preview, currencyCode }) => {
10327
- const [editing, setEditing] = React.useState(false);
10328
- const { quantity, unit_price, title } = item;
10329
- const form = reactHookForm.useForm({
10330
- defaultValues: {
10331
- title,
10332
- quantity,
10333
- unit_price
10334
- },
10335
- resolver: zod.zodResolver(customItemSchema)
10132
+ const useProductVariants = (query2, options) => {
10133
+ const { data, ...rest } = reactQuery.useQuery({
10134
+ queryKey: productVariantsQueryKeys.list(query2),
10135
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10136
+ ...options
10336
10137
  });
10337
- React.useEffect(() => {
10338
- form.reset({
10339
- title,
10340
- quantity,
10341
- unit_price
10342
- });
10343
- }, [form, title, quantity, unit_price]);
10344
- const actionId = React.useMemo(() => {
10345
- var _a, _b;
10346
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10347
- }, [item]);
10348
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10349
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10350
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10351
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10352
- const onSubmit = form.handleSubmit(async (data) => {
10353
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10354
- setEditing(false);
10355
- return;
10356
- }
10357
- if (!actionId) {
10358
- await updateOriginalItem(
10359
- {
10360
- item_id: item.id,
10361
- quantity: data.quantity,
10362
- unit_price: convertNumber(data.unit_price)
10363
- },
10364
- {
10365
- onSuccess: () => {
10366
- setEditing(false);
10367
- },
10368
- onError: (e) => {
10369
- ui.toast.error(e.message);
10370
- }
10371
- }
10372
- );
10373
- return;
10138
+ return { ...data, ...rest };
10139
+ };
10140
+ const useCancelOrderEdit = ({ preview }) => {
10141
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10142
+ const onCancel = React.useCallback(async () => {
10143
+ if (!preview) {
10144
+ return true;
10374
10145
  }
10375
- if (data.quantity === 0) {
10376
- await removeActionItem(actionId, {
10377
- onSuccess: () => {
10378
- setEditing(false);
10379
- },
10146
+ let res = false;
10147
+ await cancelOrderEdit(void 0, {
10148
+ onError: (e) => {
10149
+ ui.toast.error(e.message);
10150
+ },
10151
+ onSuccess: () => {
10152
+ res = true;
10153
+ }
10154
+ });
10155
+ return res;
10156
+ }, [preview, cancelOrderEdit]);
10157
+ return { onCancel };
10158
+ };
10159
+ let IS_REQUEST_RUNNING = false;
10160
+ const useInitiateOrderEdit = ({
10161
+ preview
10162
+ }) => {
10163
+ const navigate = reactRouterDom.useNavigate();
10164
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10165
+ React.useEffect(() => {
10166
+ async function run() {
10167
+ if (IS_REQUEST_RUNNING || !preview) {
10168
+ return;
10169
+ }
10170
+ if (preview.order_change) {
10171
+ return;
10172
+ }
10173
+ IS_REQUEST_RUNNING = true;
10174
+ await mutateAsync(void 0, {
10380
10175
  onError: (e) => {
10381
10176
  ui.toast.error(e.message);
10177
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10178
+ return;
10382
10179
  }
10383
10180
  });
10384
- return;
10181
+ IS_REQUEST_RUNNING = false;
10385
10182
  }
10386
- await updateActionItem(
10387
- {
10388
- action_id: actionId,
10389
- quantity: data.quantity,
10390
- unit_price: convertNumber(data.unit_price)
10183
+ run();
10184
+ }, [preview, navigate, mutateAsync]);
10185
+ };
10186
+ function convertNumber(value) {
10187
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10188
+ }
10189
+ const STACKED_MODAL_ID = "items_stacked_modal";
10190
+ const Items = () => {
10191
+ const { id } = reactRouterDom.useParams();
10192
+ const {
10193
+ order: preview,
10194
+ isPending: isPreviewPending,
10195
+ isError: isPreviewError,
10196
+ error: previewError
10197
+ } = useOrderPreview(id, void 0, {
10198
+ placeholderData: reactQuery.keepPreviousData
10199
+ });
10200
+ useInitiateOrderEdit({ preview });
10201
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10202
+ id,
10203
+ {
10204
+ fields: "currency_code"
10205
+ },
10206
+ {
10207
+ enabled: !!id
10208
+ }
10209
+ );
10210
+ const { onCancel } = useCancelOrderEdit({ preview });
10211
+ if (isError) {
10212
+ throw error;
10213
+ }
10214
+ if (isPreviewError) {
10215
+ throw previewError;
10216
+ }
10217
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10218
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10219
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10220
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10221
+ ] }) });
10222
+ };
10223
+ const ItemsForm = ({ preview, currencyCode }) => {
10224
+ var _a;
10225
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10226
+ const [modalContent, setModalContent] = React.useState(
10227
+ null
10228
+ );
10229
+ const { handleSuccess } = useRouteModal();
10230
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10231
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10232
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10233
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10234
+ const matches = React.useMemo(() => {
10235
+ return matchSorter.matchSorter(preview.items, query2, {
10236
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10237
+ });
10238
+ }, [preview.items, query2]);
10239
+ const onSubmit = async () => {
10240
+ setIsSubmitting(true);
10241
+ let requestSucceeded = false;
10242
+ await requestOrderEdit(void 0, {
10243
+ onError: (e) => {
10244
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10391
10245
  },
10392
- {
10393
- onSuccess: () => {
10394
- setEditing(false);
10395
- },
10396
- onError: (e) => {
10397
- ui.toast.error(e.message);
10398
- }
10246
+ onSuccess: () => {
10247
+ requestSucceeded = true;
10399
10248
  }
10400
- );
10401
- });
10402
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10403
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10249
+ });
10250
+ if (!requestSucceeded) {
10251
+ setIsSubmitting(false);
10252
+ return;
10253
+ }
10254
+ await confirmOrderEdit(void 0, {
10255
+ onError: (e) => {
10256
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10257
+ },
10258
+ onSuccess: () => {
10259
+ handleSuccess();
10260
+ },
10261
+ onSettled: () => {
10262
+ setIsSubmitting(false);
10263
+ }
10264
+ });
10265
+ };
10266
+ const onKeyDown = React.useCallback(
10267
+ (e) => {
10268
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10269
+ if (modalContent || isSubmitting) {
10270
+ return;
10271
+ }
10272
+ onSubmit();
10273
+ }
10274
+ },
10275
+ [modalContent, isSubmitting, onSubmit]
10276
+ );
10277
+ React.useEffect(() => {
10278
+ document.addEventListener("keydown", onKeyDown);
10279
+ return () => {
10280
+ document.removeEventListener("keydown", onKeyDown);
10281
+ };
10282
+ }, [onKeyDown]);
10283
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10284
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10285
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10286
+ StackedFocusModal,
10287
+ {
10288
+ id: STACKED_MODAL_ID,
10289
+ onOpenChangeCallback: (open) => {
10290
+ if (!open) {
10291
+ setModalContent(null);
10292
+ }
10293
+ },
10294
+ children: [
10295
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10296
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10297
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10298
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
10299
+ ] }),
10300
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10301
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10302
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10303
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10304
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10305
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10306
+ ] }),
10307
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10308
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10309
+ ui.Input,
10310
+ {
10311
+ type: "search",
10312
+ placeholder: "Search items",
10313
+ value: searchValue,
10314
+ onChange: (e) => onSearchValueChange(e.target.value)
10315
+ }
10316
+ ) }),
10317
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10318
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10319
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10320
+ /* @__PURE__ */ jsxRuntime.jsx(
10321
+ StackedModalTrigger$1,
10322
+ {
10323
+ type: "add-items",
10324
+ setModalContent
10325
+ }
10326
+ ),
10327
+ /* @__PURE__ */ jsxRuntime.jsx(
10328
+ StackedModalTrigger$1,
10329
+ {
10330
+ type: "add-custom-item",
10331
+ setModalContent
10332
+ }
10333
+ )
10334
+ ] })
10335
+ ] })
10336
+ ] })
10337
+ ] }),
10338
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10339
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10340
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10341
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10342
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10343
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
10344
+ ] }) }),
10345
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10346
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10347
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10348
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10349
+ Item,
10350
+ {
10351
+ item,
10352
+ preview,
10353
+ currencyCode
10354
+ },
10355
+ item.id
10356
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10357
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10358
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10359
+ 'No items found for "',
10360
+ query2,
10361
+ '".'
10362
+ ] })
10363
+ ] }) })
10364
+ ] })
10365
+ ] }),
10366
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10367
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10368
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10369
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10370
+ ui.Text,
10371
+ {
10372
+ size: "small",
10373
+ leading: "compact",
10374
+ className: "text-ui-fg-subtle",
10375
+ children: [
10376
+ itemCount,
10377
+ " ",
10378
+ itemCount === 1 ? "item" : "items"
10379
+ ]
10380
+ }
10381
+ ) }),
10382
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10383
+ ] })
10384
+ ] }) }),
10385
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10386
+ CustomItemForm,
10387
+ {
10388
+ orderId: preview.id,
10389
+ currencyCode
10390
+ }
10391
+ ) : null)
10392
+ ]
10393
+ }
10394
+ ) }),
10395
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10396
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10404
10397
  /* @__PURE__ */ jsxRuntime.jsx(
10405
- Thumbnail,
10398
+ ui.Button,
10406
10399
  {
10407
- thumbnail: item.thumbnail,
10408
- alt: item.title ?? void 0
10400
+ size: "small",
10401
+ type: "button",
10402
+ onClick: onSubmit,
10403
+ isLoading: isSubmitting,
10404
+ children: "Save"
10409
10405
  }
10410
- ),
10411
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10412
- Form$2.Field,
10406
+ )
10407
+ ] }) })
10408
+ ] });
10409
+ };
10410
+ const Item = ({ item, preview, currencyCode }) => {
10411
+ if (item.variant_id) {
10412
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10413
+ }
10414
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10415
+ };
10416
+ const VariantItem = ({ item, preview, currencyCode }) => {
10417
+ const [editing, setEditing] = React.useState(false);
10418
+ const form = reactHookForm.useForm({
10419
+ defaultValues: {
10420
+ quantity: item.quantity,
10421
+ unit_price: item.unit_price
10422
+ },
10423
+ resolver: zod.zodResolver(variantItemSchema)
10424
+ });
10425
+ const actionId = React.useMemo(() => {
10426
+ var _a, _b;
10427
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10428
+ }, [item]);
10429
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10430
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10431
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10432
+ const onSubmit = form.handleSubmit(async (data) => {
10433
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10434
+ setEditing(false);
10435
+ return;
10436
+ }
10437
+ if (!actionId) {
10438
+ await updateOriginalItem(
10413
10439
  {
10414
- control: form.control,
10415
- name: "title",
10416
- render: ({ field }) => {
10417
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10440
+ item_id: item.id,
10441
+ quantity: data.quantity,
10442
+ unit_price: convertNumber(data.unit_price)
10443
+ },
10444
+ {
10445
+ onSuccess: () => {
10446
+ setEditing(false);
10447
+ },
10448
+ onError: (e) => {
10449
+ ui.toast.error(e.message);
10418
10450
  }
10419
10451
  }
10420
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10421
- ] }),
10422
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10423
- Form$2.Field,
10452
+ );
10453
+ return;
10454
+ }
10455
+ await updateActionItem(
10424
10456
  {
10425
- control: form.control,
10426
- name: "quantity",
10427
- render: ({ field }) => {
10428
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10429
- }
10430
- }
10431
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10432
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10433
- Form$2.Field,
10457
+ action_id: actionId,
10458
+ quantity: data.quantity,
10459
+ unit_price: convertNumber(data.unit_price)
10460
+ },
10434
10461
  {
10435
- control: form.control,
10436
- name: "unit_price",
10437
- render: ({ field: { onChange, ...field } }) => {
10438
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10439
- ui.CurrencyInput,
10440
- {
10441
- ...field,
10442
- symbol: getNativeSymbol(currencyCode),
10443
- code: currencyCode,
10444
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10445
- }
10446
- ) }) });
10462
+ onSuccess: () => {
10463
+ setEditing(false);
10464
+ },
10465
+ onError: (e) => {
10466
+ ui.toast.error(e.message);
10447
10467
  }
10448
10468
  }
10449
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10450
- /* @__PURE__ */ jsxRuntime.jsx(
10451
- ui.IconButton,
10452
- {
10453
- type: "button",
10454
- size: "small",
10455
- onClick: editing ? onSubmit : () => {
10456
- setEditing(true);
10469
+ );
10470
+ });
10471
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10472
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10473
+ /* @__PURE__ */ jsxRuntime.jsx(
10474
+ Thumbnail,
10475
+ {
10476
+ thumbnail: item.thumbnail,
10477
+ alt: item.product_title ?? void 0
10478
+ }
10479
+ ),
10480
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10481
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10482
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10483
+ /* @__PURE__ */ jsxRuntime.jsxs(
10484
+ ui.Text,
10485
+ {
10486
+ size: "small",
10487
+ leading: "compact",
10488
+ className: "text-ui-fg-subtle",
10489
+ children: [
10490
+ "(",
10491
+ item.variant_title,
10492
+ ")"
10493
+ ]
10494
+ }
10495
+ )
10496
+ ] }),
10497
+ /* @__PURE__ */ jsxRuntime.jsx(
10498
+ ui.Text,
10499
+ {
10500
+ size: "small",
10501
+ leading: "compact",
10502
+ className: "text-ui-fg-subtle",
10503
+ children: item.variant_sku
10504
+ }
10505
+ )
10506
+ ] })
10507
+ ] }),
10508
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10509
+ Form$2.Field,
10510
+ {
10511
+ control: form.control,
10512
+ name: "quantity",
10513
+ render: ({ field }) => {
10514
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10515
+ }
10516
+ }
10517
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10518
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10519
+ Form$2.Field,
10520
+ {
10521
+ control: form.control,
10522
+ name: "unit_price",
10523
+ render: ({ field: { onChange, ...field } }) => {
10524
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10525
+ ui.CurrencyInput,
10526
+ {
10527
+ ...field,
10528
+ symbol: getNativeSymbol(currencyCode),
10529
+ code: currencyCode,
10530
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10531
+ }
10532
+ ) }) });
10533
+ }
10534
+ }
10535
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10536
+ /* @__PURE__ */ jsxRuntime.jsx(
10537
+ ui.IconButton,
10538
+ {
10539
+ type: "button",
10540
+ size: "small",
10541
+ onClick: editing ? onSubmit : () => {
10542
+ setEditing(true);
10543
+ },
10544
+ disabled: isPending,
10545
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10546
+ }
10547
+ )
10548
+ ] }) }) });
10549
+ };
10550
+ const variantItemSchema = objectType({
10551
+ quantity: numberType(),
10552
+ unit_price: unionType([numberType(), stringType()])
10553
+ });
10554
+ const CustomItem = ({ item, preview, currencyCode }) => {
10555
+ const [editing, setEditing] = React.useState(false);
10556
+ const { quantity, unit_price, title } = item;
10557
+ const form = reactHookForm.useForm({
10558
+ defaultValues: {
10559
+ title,
10560
+ quantity,
10561
+ unit_price
10562
+ },
10563
+ resolver: zod.zodResolver(customItemSchema)
10564
+ });
10565
+ React.useEffect(() => {
10566
+ form.reset({
10567
+ title,
10568
+ quantity,
10569
+ unit_price
10570
+ });
10571
+ }, [form, title, quantity, unit_price]);
10572
+ const actionId = React.useMemo(() => {
10573
+ var _a, _b;
10574
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10575
+ }, [item]);
10576
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10577
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10578
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10579
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10580
+ const onSubmit = form.handleSubmit(async (data) => {
10581
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10582
+ setEditing(false);
10583
+ return;
10584
+ }
10585
+ if (!actionId) {
10586
+ await updateOriginalItem(
10587
+ {
10588
+ item_id: item.id,
10589
+ quantity: data.quantity,
10590
+ unit_price: convertNumber(data.unit_price)
10591
+ },
10592
+ {
10593
+ onSuccess: () => {
10594
+ setEditing(false);
10595
+ },
10596
+ onError: (e) => {
10597
+ ui.toast.error(e.message);
10598
+ }
10599
+ }
10600
+ );
10601
+ return;
10602
+ }
10603
+ if (data.quantity === 0) {
10604
+ await removeActionItem(actionId, {
10605
+ onSuccess: () => {
10606
+ setEditing(false);
10607
+ },
10608
+ onError: (e) => {
10609
+ ui.toast.error(e.message);
10610
+ }
10611
+ });
10612
+ return;
10613
+ }
10614
+ await updateActionItem(
10615
+ {
10616
+ action_id: actionId,
10617
+ quantity: data.quantity,
10618
+ unit_price: convertNumber(data.unit_price)
10619
+ },
10620
+ {
10621
+ onSuccess: () => {
10622
+ setEditing(false);
10623
+ },
10624
+ onError: (e) => {
10625
+ ui.toast.error(e.message);
10626
+ }
10627
+ }
10628
+ );
10629
+ });
10630
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10631
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10632
+ /* @__PURE__ */ jsxRuntime.jsx(
10633
+ Thumbnail,
10634
+ {
10635
+ thumbnail: item.thumbnail,
10636
+ alt: item.title ?? void 0
10637
+ }
10638
+ ),
10639
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10640
+ Form$2.Field,
10641
+ {
10642
+ control: form.control,
10643
+ name: "title",
10644
+ render: ({ field }) => {
10645
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10646
+ }
10647
+ }
10648
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10649
+ ] }),
10650
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10651
+ Form$2.Field,
10652
+ {
10653
+ control: form.control,
10654
+ name: "quantity",
10655
+ render: ({ field }) => {
10656
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10657
+ }
10658
+ }
10659
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10660
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10661
+ Form$2.Field,
10662
+ {
10663
+ control: form.control,
10664
+ name: "unit_price",
10665
+ render: ({ field: { onChange, ...field } }) => {
10666
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10667
+ ui.CurrencyInput,
10668
+ {
10669
+ ...field,
10670
+ symbol: getNativeSymbol(currencyCode),
10671
+ code: currencyCode,
10672
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10673
+ }
10674
+ ) }) });
10675
+ }
10676
+ }
10677
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10678
+ /* @__PURE__ */ jsxRuntime.jsx(
10679
+ ui.IconButton,
10680
+ {
10681
+ type: "button",
10682
+ size: "small",
10683
+ onClick: editing ? onSubmit : () => {
10684
+ setEditing(true);
10457
10685
  },
10458
10686
  disabled: isPending,
10459
10687
  children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
@@ -10758,91 +10986,23 @@ const customItemSchema = objectType({
10758
10986
  quantity: numberType(),
10759
10987
  unit_price: unionType([numberType(), stringType()])
10760
10988
  });
10761
- const Email = () => {
10762
- const { id } = reactRouterDom.useParams();
10763
- const { order, isPending, isError, error } = useOrder(id, {
10764
- fields: "+email"
10765
- });
10766
- if (isError) {
10767
- throw error;
10768
- }
10769
- const isReady = !isPending && !!order;
10770
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10771
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10772
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10773
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10774
- ] }),
10775
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10776
- ] });
10989
+ const PROMOTION_QUERY_KEY = "promotions";
10990
+ const promotionsQueryKeys = {
10991
+ list: (query2) => [
10992
+ PROMOTION_QUERY_KEY,
10993
+ query2 ? query2 : void 0
10994
+ ],
10995
+ detail: (id, query2) => [
10996
+ PROMOTION_QUERY_KEY,
10997
+ id,
10998
+ query2 ? query2 : void 0
10999
+ ]
10777
11000
  };
10778
- const EmailForm = ({ order }) => {
10779
- const form = reactHookForm.useForm({
10780
- defaultValues: {
10781
- email: order.email ?? ""
10782
- },
10783
- resolver: zod.zodResolver(schema$3)
10784
- });
10785
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10786
- const { handleSuccess } = useRouteModal();
10787
- const onSubmit = form.handleSubmit(async (data) => {
10788
- await mutateAsync(
10789
- { email: data.email },
10790
- {
10791
- onSuccess: () => {
10792
- handleSuccess();
10793
- },
10794
- onError: (error) => {
10795
- ui.toast.error(error.message);
10796
- }
10797
- }
10798
- );
10799
- });
10800
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10801
- KeyboundForm,
10802
- {
10803
- className: "flex flex-1 flex-col overflow-hidden",
10804
- onSubmit,
10805
- children: [
10806
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10807
- Form$2.Field,
10808
- {
10809
- control: form.control,
10810
- name: "email",
10811
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10812
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10813
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10814
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10815
- ] })
10816
- }
10817
- ) }),
10818
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10819
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10820
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10821
- ] }) })
10822
- ]
10823
- }
10824
- ) });
10825
- };
10826
- const schema$3 = objectType({
10827
- email: stringType().email()
10828
- });
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
11001
+ const usePromotions = (query2, options) => {
11002
+ const { data, ...rest } = reactQuery.useQuery({
11003
+ queryKey: promotionsQueryKeys.list(query2),
11004
+ queryFn: async () => sdk.admin.promotion.list(query2),
11005
+ ...options
10846
11006
  });
10847
11007
  return { ...data, ...rest };
10848
11008
  };
@@ -11103,54 +11263,116 @@ function getPromotionIds(items, shippingMethods) {
11103
11263
  }
11104
11264
  return Array.from(promotionIds);
11105
11265
  }
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",
11266
+ const SalesChannel = () => {
11267
+ const { id } = reactRouterDom.useParams();
11268
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11269
+ id,
11270
+ {
11271
+ fields: "+sales_channel_id"
11272
+ },
11273
+ {
11274
+ enabled: !!id
11275
+ }
11276
+ );
11277
+ if (isError) {
11278
+ throw error;
11279
+ }
11280
+ const ISrEADY = !!draft_order && !isPending;
11281
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11282
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11283
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11284
+ /* @__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" }) })
11285
+ ] }),
11286
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11287
+ ] });
11288
+ };
11289
+ const SalesChannelForm = ({ order }) => {
11290
+ const form = reactHookForm.useForm({
11291
+ defaultValues: {
11292
+ sales_channel_id: order.sales_channel_id || ""
11293
+ },
11294
+ resolver: zod.zodResolver(schema$3)
11295
+ });
11296
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11297
+ const { handleSuccess } = useRouteModal();
11298
+ const onSubmit = form.handleSubmit(async (data) => {
11299
+ await mutateAsync(
11111
11300
  {
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",
11301
+ sales_channel_id: data.sales_channel_id
11302
+ },
11303
+ {
11304
+ onSuccess: () => {
11305
+ ui.toast.success("Sales channel updated");
11306
+ handleSuccess();
11307
+ },
11308
+ onError: (error) => {
11309
+ ui.toast.error(error.message);
11310
+ }
11311
+ }
11312
+ );
11313
+ });
11314
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
+ KeyboundForm,
11316
+ {
11317
+ className: "flex flex-1 flex-col overflow-hidden",
11318
+ onSubmit,
11319
+ children: [
11320
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11321
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11322
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11323
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11324
+ ] }) })
11325
+ ]
11326
+ }
11327
+ ) });
11328
+ };
11329
+ const SalesChannelField = ({ control, order }) => {
11330
+ const salesChannels = useComboboxData({
11331
+ queryFn: async (params) => {
11332
+ return await sdk.admin.salesChannel.list(params);
11333
+ },
11334
+ queryKey: ["sales-channels"],
11335
+ getOptions: (data) => {
11336
+ return data.sales_channels.map((salesChannel) => ({
11337
+ label: salesChannel.name,
11338
+ value: salesChannel.id
11339
+ }));
11340
+ },
11341
+ defaultValue: order.sales_channel_id || void 0
11342
+ });
11343
+ return /* @__PURE__ */ jsxRuntime.jsx(
11344
+ Form$2.Field,
11345
+ {
11346
+ control,
11347
+ name: "sales_channel_id",
11348
+ render: ({ field }) => {
11349
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11350
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11351
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11352
+ Combobox,
11121
11353
  {
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
- })
11354
+ options: salesChannels.options,
11355
+ fetchNextPage: salesChannels.fetchNextPage,
11356
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11357
+ searchValue: salesChannels.searchValue,
11358
+ onSearchValueChange: salesChannels.onSearchValueChange,
11359
+ placeholder: "Select sales channel",
11360
+ ...field
11126
11361
  }
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
- ]
11362
+ ) }),
11363
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11364
+ ] });
11137
11365
  }
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)
11366
+ }
11367
+ );
11368
+ };
11369
+ const schema$3 = objectType({
11370
+ sales_channel_id: stringType().min(1)
11149
11371
  });
11150
- const Metadata = () => {
11372
+ const ShippingAddress = () => {
11151
11373
  const { id } = reactRouterDom.useParams();
11152
11374
  const { order, isPending, isError, error } = useOrder(id, {
11153
- fields: "metadata"
11375
+ fields: "+shipping_address"
11154
11376
  });
11155
11377
  if (isError) {
11156
11378
  throw error;
@@ -11158,33 +11380,49 @@ const Metadata = () => {
11158
11380
  const isReady = !isPending && !!order;
11159
11381
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11160
11382
  /* @__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." }) })
11383
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11384
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11163
11385
  ] }),
11164
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11386
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11165
11387
  ] });
11166
11388
  };
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 }) => {
11170
- const { handleSuccess } = useRouteModal();
11171
- const hasUneditableRows = getHasUneditableRows(metadata);
11172
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11389
+ const ShippingAddressForm = ({ order }) => {
11390
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11173
11391
  const form = reactHookForm.useForm({
11174
11392
  defaultValues: {
11175
- metadata: getDefaultValues(metadata)
11393
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11394
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11395
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11396
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11397
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11398
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11399
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11400
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11401
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11402
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11176
11403
  },
11177
- resolver: zod.zodResolver(MetadataSchema)
11404
+ resolver: zod.zodResolver(schema$2)
11178
11405
  });
11179
- const handleSubmit = form.handleSubmit(async (data) => {
11180
- const parsedData = parseValues(data);
11406
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11407
+ const { handleSuccess } = useRouteModal();
11408
+ const onSubmit = form.handleSubmit(async (data) => {
11181
11409
  await mutateAsync(
11182
11410
  {
11183
- metadata: parsedData
11411
+ shipping_address: {
11412
+ first_name: data.first_name,
11413
+ last_name: data.last_name,
11414
+ company: data.company,
11415
+ address_1: data.address_1,
11416
+ address_2: data.address_2,
11417
+ city: data.city,
11418
+ province: data.province,
11419
+ country_code: data.country_code,
11420
+ postal_code: data.postal_code,
11421
+ phone: data.phone
11422
+ }
11184
11423
  },
11185
11424
  {
11186
11425
  onSuccess: () => {
11187
- ui.toast.success("Metadata updated");
11188
11426
  handleSuccess();
11189
11427
  },
11190
11428
  onError: (error) => {
@@ -11193,266 +11431,147 @@ const MetadataForm = ({ orderId, metadata }) => {
11193
11431
  }
11194
11432
  );
11195
11433
  });
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
- });
11208
- }
11209
- }
11210
- function insertRow(index, position) {
11211
- insert(index + (position === "above" ? 0 : 1), {
11212
- key: "",
11213
- value: "",
11214
- disabled: false
11215
- });
11216
- }
11217
11434
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11218
11435
  KeyboundForm,
11219
11436
  {
11220
- onSubmit: handleSubmit,
11221
11437
  className: "flex flex-1 flex-col overflow-hidden",
11438
+ onSubmit,
11222
11439
  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 = "{ ... }";
11440
+ /* @__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: [
11441
+ /* @__PURE__ */ jsxRuntime.jsx(
11442
+ Form$2.Field,
11443
+ {
11444
+ control: form.control,
11445
+ name: "country_code",
11446
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11447
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11448
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11449
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11450
+ ] })
11451
+ }
11452
+ ),
11453
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11454
+ /* @__PURE__ */ jsxRuntime.jsx(
11455
+ Form$2.Field,
11456
+ {
11457
+ control: form.control,
11458
+ name: "first_name",
11459
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11460
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11461
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11462
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11463
+ ] })
11234
11464
  }
11235
- if (Array.isArray(field.value)) {
11236
- placeholder = "[ ... ]";
11465
+ ),
11466
+ /* @__PURE__ */ jsxRuntime.jsx(
11467
+ Form$2.Field,
11468
+ {
11469
+ control: form.control,
11470
+ name: "last_name",
11471
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11473
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11474
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11475
+ ] })
11237
11476
  }
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: [
11251
- /* @__PURE__ */ jsxRuntime.jsx(
11252
- Form$2.Field,
11253
- {
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
- }
11267
- }
11268
- ),
11269
- /* @__PURE__ */ jsxRuntime.jsx(
11270
- Form$2.Field,
11271
- {
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
- }
11286
- }
11287
- )
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,
11309
- {
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
- ]
11316
- }
11317
- ),
11318
- /* @__PURE__ */ jsxRuntime.jsxs(
11319
- ui.DropdownMenu.Item,
11320
- {
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
- ]
11327
- }
11328
- ),
11329
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11330
- /* @__PURE__ */ jsxRuntime.jsxs(
11331
- ui.DropdownMenu.Item,
11332
- {
11333
- className: "gap-x-2",
11334
- onClick: () => deleteRow(index),
11335
- children: [
11336
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11337
- "Delete row"
11338
- ]
11339
- }
11340
- )
11341
- ] })
11342
- ] })
11343
- ] })
11344
- },
11345
- field.id
11346
- );
11347
- })
11477
+ )
11348
11478
  ] }),
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" })
11354
- ] }) })
11355
- ]
11356
- }
11357
- ) });
11358
- };
11359
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11360
- return /* @__PURE__ */ jsxRuntime.jsx(
11361
- "input",
11362
- {
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
- )
11370
- }
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
- ] });
11382
- };
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);
11405
- }
11406
- return {
11407
- key,
11408
- value: stringValue,
11409
- original_key: key
11410
- };
11411
- });
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) {
11425
- return;
11426
- }
11427
- if (disabled) {
11428
- update[key] = value;
11429
- return;
11430
- }
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;
11443
- }
11479
+ /* @__PURE__ */ jsxRuntime.jsx(
11480
+ Form$2.Field,
11481
+ {
11482
+ control: form.control,
11483
+ name: "company",
11484
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11485
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11486
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11487
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11488
+ ] })
11489
+ }
11490
+ ),
11491
+ /* @__PURE__ */ jsxRuntime.jsx(
11492
+ Form$2.Field,
11493
+ {
11494
+ control: form.control,
11495
+ name: "address_1",
11496
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11497
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11498
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11499
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11500
+ ] })
11501
+ }
11502
+ ),
11503
+ /* @__PURE__ */ jsxRuntime.jsx(
11504
+ Form$2.Field,
11505
+ {
11506
+ control: form.control,
11507
+ name: "address_2",
11508
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11509
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11510
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11512
+ ] })
11513
+ }
11514
+ ),
11515
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11516
+ /* @__PURE__ */ jsxRuntime.jsx(
11517
+ Form$2.Field,
11518
+ {
11519
+ control: form.control,
11520
+ name: "postal_code",
11521
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11522
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11523
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11524
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11525
+ ] })
11526
+ }
11527
+ ),
11528
+ /* @__PURE__ */ jsxRuntime.jsx(
11529
+ Form$2.Field,
11530
+ {
11531
+ control: form.control,
11532
+ name: "city",
11533
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11535
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11536
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11537
+ ] })
11538
+ }
11539
+ )
11540
+ ] }),
11541
+ /* @__PURE__ */ jsxRuntime.jsx(
11542
+ Form$2.Field,
11543
+ {
11544
+ control: form.control,
11545
+ name: "province",
11546
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11547
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11548
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11549
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11550
+ ] })
11551
+ }
11552
+ ),
11553
+ /* @__PURE__ */ jsxRuntime.jsx(
11554
+ Form$2.Field,
11555
+ {
11556
+ control: form.control,
11557
+ name: "phone",
11558
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11559
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11560
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11561
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11562
+ ] })
11563
+ }
11564
+ )
11565
+ ] }) }),
11566
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11567
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11568
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11569
+ ] }) })
11570
+ ]
11444
11571
  }
11445
- });
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
- }
11572
+ ) });
11573
+ };
11574
+ const schema$2 = addressSchema;
11456
11575
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11457
11576
  const Shipping = () => {
11458
11577
  var _a;
@@ -11889,686 +12008,377 @@ const StackedModalTrigger = ({
11889
12008
  setData({
11890
12009
  shippingProfileId,
11891
12010
  shippingOption,
11892
- shippingMethod
11893
- });
11894
- }
11895
- };
11896
- return /* @__PURE__ */ jsxRuntime.jsx(
11897
- ui.Button,
11898
- {
11899
- size: "small",
11900
- variant: "secondary",
11901
- onClick: onToggle,
11902
- className: "text-ui-fg-primary shrink-0",
11903
- children
11904
- }
11905
- );
11906
- };
11907
- const ShippingProfileForm = ({
11908
- data,
11909
- order,
11910
- preview
11911
- }) => {
11912
- var _a, _b, _c, _d, _e, _f;
11913
- const { setIsOpen } = useStackedModal();
11914
- const form = reactHookForm.useForm({
11915
- resolver: zod.zodResolver(shippingMethodSchema),
11916
- defaultValues: {
11917
- 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,
11918
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11919
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11920
- }
11921
- });
11922
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11923
- const {
11924
- mutateAsync: updateShippingMethod,
11925
- isPending: isUpdatingShippingMethod
11926
- } = useDraftOrderUpdateShippingMethod(order.id);
11927
- const onSubmit = form.handleSubmit(async (values) => {
11928
- if (lodash.isEqual(values, form.formState.defaultValues)) {
11929
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11930
- return;
11931
- }
11932
- if (data.shippingMethod) {
11933
- await updateShippingMethod(
11934
- {
11935
- method_id: data.shippingMethod.id,
11936
- shipping_option_id: values.shipping_option_id,
11937
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11938
- },
11939
- {
11940
- onError: (e) => {
11941
- ui.toast.error(e.message);
11942
- },
11943
- onSuccess: () => {
11944
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11945
- }
11946
- }
11947
- );
11948
- return;
11949
- }
11950
- await addShippingMethod(
11951
- {
11952
- shipping_option_id: values.shipping_option_id,
11953
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11954
- },
11955
- {
11956
- onError: (e) => {
11957
- ui.toast.error(e.message);
11958
- },
11959
- onSuccess: () => {
11960
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11961
- }
11962
- }
11963
- );
11964
- });
11965
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11966
- KeyboundForm,
11967
- {
11968
- className: "flex h-full flex-col overflow-hidden",
11969
- onSubmit,
11970
- children: [
11971
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11972
- /* @__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: [
11973
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11974
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11975
- /* @__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." }) })
11976
- ] }),
11977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11978
- /* @__PURE__ */ jsxRuntime.jsx(
11979
- LocationField,
11980
- {
11981
- control: form.control,
11982
- setValue: form.setValue
11983
- }
11984
- ),
11985
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11986
- /* @__PURE__ */ jsxRuntime.jsx(
11987
- ShippingOptionField,
11988
- {
11989
- shippingProfileId: data.shippingProfileId,
11990
- preview,
11991
- control: form.control
11992
- }
11993
- ),
11994
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11995
- /* @__PURE__ */ jsxRuntime.jsx(
11996
- CustomAmountField,
11997
- {
11998
- control: form.control,
11999
- currencyCode: order.currency_code
12000
- }
12001
- ),
12002
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12003
- /* @__PURE__ */ jsxRuntime.jsx(
12004
- ItemsPreview,
12005
- {
12006
- order,
12007
- shippingProfileId: data.shippingProfileId
12008
- }
12009
- )
12010
- ] }) }) }),
12011
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12012
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12013
- /* @__PURE__ */ jsxRuntime.jsx(
12014
- ui.Button,
12015
- {
12016
- size: "small",
12017
- type: "submit",
12018
- isLoading: isPending || isUpdatingShippingMethod,
12019
- children: data.shippingMethod ? "Update" : "Add"
12020
- }
12021
- )
12022
- ] }) })
12023
- ]
12024
- }
12025
- ) }) });
12026
- };
12027
- const shippingMethodSchema = objectType({
12028
- location_id: stringType(),
12029
- shipping_option_id: stringType(),
12030
- custom_amount: unionType([numberType(), stringType()]).optional()
12031
- });
12032
- const ItemsPreview = ({ order, shippingProfileId }) => {
12033
- const matches = order.items.filter(
12034
- (item) => {
12035
- var _a, _b, _c;
12036
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12037
- }
12038
- );
12039
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12040
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12041
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12042
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12043
- ] }) }),
12044
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12045
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12046
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12047
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12048
- ] }),
12049
- /* @__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(
12050
- "div",
12051
- {
12052
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12053
- children: [
12054
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12055
- /* @__PURE__ */ jsxRuntime.jsx(
12056
- Thumbnail,
12057
- {
12058
- thumbnail: item.thumbnail,
12059
- alt: item.product_title ?? void 0
12060
- }
12061
- ),
12062
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12063
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12064
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12065
- /* @__PURE__ */ jsxRuntime.jsxs(
12066
- ui.Text,
12067
- {
12068
- size: "small",
12069
- leading: "compact",
12070
- className: "text-ui-fg-subtle",
12071
- children: [
12072
- "(",
12073
- item.variant_title,
12074
- ")"
12075
- ]
12076
- }
12077
- )
12078
- ] }),
12079
- /* @__PURE__ */ jsxRuntime.jsx(
12080
- ui.Text,
12081
- {
12082
- size: "small",
12083
- leading: "compact",
12084
- className: "text-ui-fg-subtle",
12085
- children: item.variant_sku
12086
- }
12087
- )
12088
- ] })
12089
- ] }),
12090
- /* @__PURE__ */ jsxRuntime.jsxs(
12091
- ui.Text,
12092
- {
12093
- size: "small",
12094
- leading: "compact",
12095
- className: "text-ui-fg-subtle",
12096
- children: [
12097
- item.quantity,
12098
- "x"
12099
- ]
12100
- }
12101
- )
12102
- ]
12103
- },
12104
- item.id
12105
- )) : /* @__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: [
12106
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12107
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12108
- 'No items found for "',
12109
- query,
12110
- '".'
12111
- ] })
12112
- ] }) })
12113
- ] })
12114
- ] });
12115
- };
12116
- const LocationField = ({ control, setValue }) => {
12117
- const locations = useComboboxData({
12118
- queryKey: ["locations"],
12119
- queryFn: async (params) => {
12120
- return await sdk.admin.stockLocation.list(params);
12121
- },
12122
- getOptions: (data) => {
12123
- return data.stock_locations.map((location) => ({
12124
- label: location.name,
12125
- value: location.id
12126
- }));
12127
- }
12128
- });
12129
- return /* @__PURE__ */ jsxRuntime.jsx(
12130
- Form$2.Field,
12131
- {
12132
- control,
12133
- name: "location_id",
12134
- render: ({ field: { onChange, ...field } }) => {
12135
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12136
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12137
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12138
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12139
- ] }),
12140
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12141
- Combobox,
12142
- {
12143
- options: locations.options,
12144
- fetchNextPage: locations.fetchNextPage,
12145
- isFetchingNextPage: locations.isFetchingNextPage,
12146
- searchValue: locations.searchValue,
12147
- onSearchValueChange: locations.onSearchValueChange,
12148
- placeholder: "Select location",
12149
- onChange: (value) => {
12150
- setValue("shipping_option_id", "", {
12151
- shouldDirty: true,
12152
- shouldTouch: true
12153
- });
12154
- onChange(value);
12155
- },
12156
- ...field
12157
- }
12158
- ) })
12159
- ] }) });
12160
- }
12161
- }
12162
- );
12163
- };
12164
- const ShippingOptionField = ({
12165
- shippingProfileId,
12166
- preview,
12167
- control
12168
- }) => {
12169
- var _a;
12170
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12171
- const shippingOptions = useComboboxData({
12172
- queryKey: ["shipping_options", locationId, shippingProfileId],
12173
- queryFn: async (params) => {
12174
- return await sdk.admin.shippingOption.list({
12175
- ...params,
12176
- stock_location_id: locationId,
12177
- shipping_profile_id: shippingProfileId
12178
- });
12179
- },
12180
- getOptions: (data) => {
12181
- return data.shipping_options.map((option) => {
12182
- var _a2;
12183
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12184
- (r) => r.attribute === "is_return" && r.value === "true"
12185
- )) {
12186
- return void 0;
12187
- }
12188
- return {
12189
- label: option.name,
12190
- value: option.id
12191
- };
12192
- }).filter(Boolean);
12193
- },
12194
- enabled: !!locationId && !!shippingProfileId,
12195
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12196
- });
12197
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12198
- return /* @__PURE__ */ jsxRuntime.jsx(
12199
- Form$2.Field,
12200
- {
12201
- control,
12202
- name: "shipping_option_id",
12203
- render: ({ field }) => {
12204
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12205
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12206
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12207
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12208
- ] }),
12209
- /* @__PURE__ */ jsxRuntime.jsx(
12210
- ConditionalTooltip,
12211
- {
12212
- content: tooltipContent,
12213
- showTooltip: !locationId || !shippingProfileId,
12214
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12215
- Combobox,
12216
- {
12217
- options: shippingOptions.options,
12218
- fetchNextPage: shippingOptions.fetchNextPage,
12219
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12220
- searchValue: shippingOptions.searchValue,
12221
- onSearchValueChange: shippingOptions.onSearchValueChange,
12222
- placeholder: "Select shipping option",
12223
- ...field,
12224
- disabled: !locationId || !shippingProfileId
12225
- }
12226
- ) }) })
12227
- }
12228
- )
12229
- ] }) });
12230
- }
12231
- }
12232
- );
12233
- };
12234
- const CustomAmountField = ({
12235
- control,
12236
- currencyCode
12237
- }) => {
12238
- return /* @__PURE__ */ jsxRuntime.jsx(
12239
- Form$2.Field,
12240
- {
12241
- control,
12242
- name: "custom_amount",
12243
- render: ({ field: { onChange, ...field } }) => {
12244
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12245
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12246
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12247
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12248
- ] }),
12249
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12250
- ui.CurrencyInput,
12251
- {
12252
- ...field,
12253
- onValueChange: (value) => onChange(value),
12254
- symbol: getNativeSymbol(currencyCode),
12255
- code: currencyCode
12256
- }
12257
- ) })
12258
- ] });
12259
- }
12260
- }
12261
- );
12262
- };
12263
- const ShippingAddress = () => {
12264
- const { id } = reactRouterDom.useParams();
12265
- const { order, isPending, isError, error } = useOrder(id, {
12266
- fields: "+shipping_address"
12267
- });
12268
- if (isError) {
12269
- throw error;
12270
- }
12271
- const isReady = !isPending && !!order;
12272
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12273
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12274
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12275
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12276
- ] }),
12277
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12278
- ] });
12011
+ shippingMethod
12012
+ });
12013
+ }
12014
+ };
12015
+ return /* @__PURE__ */ jsxRuntime.jsx(
12016
+ ui.Button,
12017
+ {
12018
+ size: "small",
12019
+ variant: "secondary",
12020
+ onClick: onToggle,
12021
+ className: "text-ui-fg-primary shrink-0",
12022
+ children
12023
+ }
12024
+ );
12279
12025
  };
12280
- const ShippingAddressForm = ({ order }) => {
12281
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12026
+ const ShippingProfileForm = ({
12027
+ data,
12028
+ order,
12029
+ preview
12030
+ }) => {
12031
+ var _a, _b, _c, _d, _e, _f;
12032
+ const { setIsOpen } = useStackedModal();
12282
12033
  const form = reactHookForm.useForm({
12034
+ resolver: zod.zodResolver(shippingMethodSchema),
12283
12035
  defaultValues: {
12284
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12285
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12286
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12287
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12288
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12289
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12290
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12291
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12292
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12293
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12294
- },
12295
- resolver: zod.zodResolver(schema$2)
12036
+ 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,
12037
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12038
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12039
+ }
12296
12040
  });
12297
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12298
- const { handleSuccess } = useRouteModal();
12299
- const onSubmit = form.handleSubmit(async (data) => {
12300
- await mutateAsync(
12301
- {
12302
- shipping_address: {
12303
- first_name: data.first_name,
12304
- last_name: data.last_name,
12305
- company: data.company,
12306
- address_1: data.address_1,
12307
- address_2: data.address_2,
12308
- city: data.city,
12309
- province: data.province,
12310
- country_code: data.country_code,
12311
- postal_code: data.postal_code,
12312
- phone: data.phone
12041
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12042
+ const {
12043
+ mutateAsync: updateShippingMethod,
12044
+ isPending: isUpdatingShippingMethod
12045
+ } = useDraftOrderUpdateShippingMethod(order.id);
12046
+ const onSubmit = form.handleSubmit(async (values) => {
12047
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12048
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12049
+ return;
12050
+ }
12051
+ if (data.shippingMethod) {
12052
+ await updateShippingMethod(
12053
+ {
12054
+ method_id: data.shippingMethod.id,
12055
+ shipping_option_id: values.shipping_option_id,
12056
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12057
+ },
12058
+ {
12059
+ onError: (e) => {
12060
+ ui.toast.error(e.message);
12061
+ },
12062
+ onSuccess: () => {
12063
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12064
+ }
12313
12065
  }
12066
+ );
12067
+ return;
12068
+ }
12069
+ await addShippingMethod(
12070
+ {
12071
+ shipping_option_id: values.shipping_option_id,
12072
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12314
12073
  },
12315
12074
  {
12316
- onSuccess: () => {
12317
- handleSuccess();
12075
+ onError: (e) => {
12076
+ ui.toast.error(e.message);
12318
12077
  },
12319
- onError: (error) => {
12320
- ui.toast.error(error.message);
12078
+ onSuccess: () => {
12079
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12321
12080
  }
12322
12081
  }
12323
12082
  );
12324
12083
  });
12325
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12084
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12326
12085
  KeyboundForm,
12327
12086
  {
12328
- className: "flex flex-1 flex-col overflow-hidden",
12087
+ className: "flex h-full flex-col overflow-hidden",
12329
12088
  onSubmit,
12330
12089
  children: [
12331
- /* @__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: [
12090
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12091
+ /* @__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: [
12092
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12093
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12094
+ /* @__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." }) })
12095
+ ] }),
12096
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12332
12097
  /* @__PURE__ */ jsxRuntime.jsx(
12333
- Form$2.Field,
12098
+ LocationField,
12334
12099
  {
12335
12100
  control: form.control,
12336
- name: "country_code",
12337
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12338
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12339
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12340
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12341
- ] })
12101
+ setValue: form.setValue
12342
12102
  }
12343
12103
  ),
12344
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12345
- /* @__PURE__ */ jsxRuntime.jsx(
12346
- Form$2.Field,
12347
- {
12348
- control: form.control,
12349
- name: "first_name",
12350
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12354
- ] })
12355
- }
12356
- ),
12357
- /* @__PURE__ */ jsxRuntime.jsx(
12358
- Form$2.Field,
12359
- {
12360
- control: form.control,
12361
- name: "last_name",
12362
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12365
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12366
- ] })
12367
- }
12368
- )
12369
- ] }),
12104
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12370
12105
  /* @__PURE__ */ jsxRuntime.jsx(
12371
- Form$2.Field,
12106
+ ShippingOptionField,
12372
12107
  {
12373
- control: form.control,
12374
- name: "company",
12375
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12376
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12377
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12378
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12379
- ] })
12108
+ shippingProfileId: data.shippingProfileId,
12109
+ preview,
12110
+ control: form.control
12380
12111
  }
12381
12112
  ),
12113
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12382
12114
  /* @__PURE__ */ jsxRuntime.jsx(
12383
- Form$2.Field,
12115
+ CustomAmountField,
12384
12116
  {
12385
12117
  control: form.control,
12386
- name: "address_1",
12387
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12388
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12389
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12390
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12391
- ] })
12118
+ currencyCode: order.currency_code
12392
12119
  }
12393
12120
  ),
12121
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12394
12122
  /* @__PURE__ */ jsxRuntime.jsx(
12395
- Form$2.Field,
12123
+ ItemsPreview,
12396
12124
  {
12397
- control: form.control,
12398
- name: "address_2",
12399
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12400
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12401
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12402
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12125
+ order,
12126
+ shippingProfileId: data.shippingProfileId
12127
+ }
12128
+ )
12129
+ ] }) }) }),
12130
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12131
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12132
+ /* @__PURE__ */ jsxRuntime.jsx(
12133
+ ui.Button,
12134
+ {
12135
+ size: "small",
12136
+ type: "submit",
12137
+ isLoading: isPending || isUpdatingShippingMethod,
12138
+ children: data.shippingMethod ? "Update" : "Add"
12139
+ }
12140
+ )
12141
+ ] }) })
12142
+ ]
12143
+ }
12144
+ ) }) });
12145
+ };
12146
+ const shippingMethodSchema = objectType({
12147
+ location_id: stringType(),
12148
+ shipping_option_id: stringType(),
12149
+ custom_amount: unionType([numberType(), stringType()]).optional()
12150
+ });
12151
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12152
+ const matches = order.items.filter(
12153
+ (item) => {
12154
+ var _a, _b, _c;
12155
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12156
+ }
12157
+ );
12158
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12159
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12160
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12161
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12162
+ ] }) }),
12163
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12164
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12165
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12166
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12167
+ ] }),
12168
+ /* @__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(
12169
+ "div",
12170
+ {
12171
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12172
+ children: [
12173
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12174
+ /* @__PURE__ */ jsxRuntime.jsx(
12175
+ Thumbnail,
12176
+ {
12177
+ thumbnail: item.thumbnail,
12178
+ alt: item.product_title ?? void 0
12179
+ }
12180
+ ),
12181
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12182
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12183
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12184
+ /* @__PURE__ */ jsxRuntime.jsxs(
12185
+ ui.Text,
12186
+ {
12187
+ size: "small",
12188
+ leading: "compact",
12189
+ className: "text-ui-fg-subtle",
12190
+ children: [
12191
+ "(",
12192
+ item.variant_title,
12193
+ ")"
12194
+ ]
12195
+ }
12196
+ )
12197
+ ] }),
12198
+ /* @__PURE__ */ jsxRuntime.jsx(
12199
+ ui.Text,
12200
+ {
12201
+ size: "small",
12202
+ leading: "compact",
12203
+ className: "text-ui-fg-subtle",
12204
+ children: item.variant_sku
12205
+ }
12206
+ )
12403
12207
  ] })
12404
- }
12405
- ),
12406
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12407
- /* @__PURE__ */ jsxRuntime.jsx(
12408
- Form$2.Field,
12409
- {
12410
- control: form.control,
12411
- name: "postal_code",
12412
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12413
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12414
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12415
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12416
- ] })
12417
- }
12418
- ),
12419
- /* @__PURE__ */ jsxRuntime.jsx(
12420
- Form$2.Field,
12208
+ ] }),
12209
+ /* @__PURE__ */ jsxRuntime.jsxs(
12210
+ ui.Text,
12421
12211
  {
12422
- control: form.control,
12423
- name: "city",
12424
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12425
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12426
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12427
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12428
- ] })
12212
+ size: "small",
12213
+ leading: "compact",
12214
+ className: "text-ui-fg-subtle",
12215
+ children: [
12216
+ item.quantity,
12217
+ "x"
12218
+ ]
12429
12219
  }
12430
12220
  )
12431
- ] }),
12432
- /* @__PURE__ */ jsxRuntime.jsx(
12433
- Form$2.Field,
12434
- {
12435
- control: form.control,
12436
- name: "province",
12437
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12438
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12440
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12441
- ] })
12442
- }
12443
- ),
12444
- /* @__PURE__ */ jsxRuntime.jsx(
12445
- Form$2.Field,
12446
- {
12447
- control: form.control,
12448
- name: "phone",
12449
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12451
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12452
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12453
- ] })
12454
- }
12455
- )
12456
- ] }) }),
12457
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12458
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12459
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12460
- ] }) })
12461
- ]
12462
- }
12463
- ) });
12464
- };
12465
- const schema$2 = addressSchema;
12466
- const SalesChannel = () => {
12467
- const { id } = reactRouterDom.useParams();
12468
- const { draft_order, isPending, isError, error } = useDraftOrder(
12469
- id,
12470
- {
12471
- fields: "+sales_channel_id"
12472
- },
12473
- {
12474
- enabled: !!id
12475
- }
12476
- );
12477
- if (isError) {
12478
- throw error;
12479
- }
12480
- const ISrEADY = !!draft_order && !isPending;
12481
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12482
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12483
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12484
- /* @__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" }) })
12485
- ] }),
12486
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12221
+ ]
12222
+ },
12223
+ item.id
12224
+ )) : /* @__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: [
12225
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12226
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12227
+ 'No items found for "',
12228
+ query,
12229
+ '".'
12230
+ ] })
12231
+ ] }) })
12232
+ ] })
12487
12233
  ] });
12488
12234
  };
12489
- const SalesChannelForm = ({ order }) => {
12490
- const form = reactHookForm.useForm({
12491
- defaultValues: {
12492
- sales_channel_id: order.sales_channel_id || ""
12235
+ const LocationField = ({ control, setValue }) => {
12236
+ const locations = useComboboxData({
12237
+ queryKey: ["locations"],
12238
+ queryFn: async (params) => {
12239
+ return await sdk.admin.stockLocation.list(params);
12493
12240
  },
12494
- resolver: zod.zodResolver(schema$1)
12495
- });
12496
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12497
- const { handleSuccess } = useRouteModal();
12498
- const onSubmit = form.handleSubmit(async (data) => {
12499
- await mutateAsync(
12500
- {
12501
- sales_channel_id: data.sales_channel_id
12502
- },
12503
- {
12504
- onSuccess: () => {
12505
- ui.toast.success("Sales channel updated");
12506
- handleSuccess();
12507
- },
12508
- onError: (error) => {
12509
- ui.toast.error(error.message);
12510
- }
12511
- }
12512
- );
12241
+ getOptions: (data) => {
12242
+ return data.stock_locations.map((location) => ({
12243
+ label: location.name,
12244
+ value: location.id
12245
+ }));
12246
+ }
12513
12247
  });
12514
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12515
- KeyboundForm,
12248
+ return /* @__PURE__ */ jsxRuntime.jsx(
12249
+ Form$2.Field,
12516
12250
  {
12517
- className: "flex flex-1 flex-col overflow-hidden",
12518
- onSubmit,
12519
- children: [
12520
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12521
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12522
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12523
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12524
- ] }) })
12525
- ]
12251
+ control,
12252
+ name: "location_id",
12253
+ render: ({ field: { onChange, ...field } }) => {
12254
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12255
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12256
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12257
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12258
+ ] }),
12259
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12260
+ Combobox,
12261
+ {
12262
+ options: locations.options,
12263
+ fetchNextPage: locations.fetchNextPage,
12264
+ isFetchingNextPage: locations.isFetchingNextPage,
12265
+ searchValue: locations.searchValue,
12266
+ onSearchValueChange: locations.onSearchValueChange,
12267
+ placeholder: "Select location",
12268
+ onChange: (value) => {
12269
+ setValue("shipping_option_id", "", {
12270
+ shouldDirty: true,
12271
+ shouldTouch: true
12272
+ });
12273
+ onChange(value);
12274
+ },
12275
+ ...field
12276
+ }
12277
+ ) })
12278
+ ] }) });
12279
+ }
12526
12280
  }
12527
- ) });
12281
+ );
12528
12282
  };
12529
- const SalesChannelField = ({ control, order }) => {
12530
- const salesChannels = useComboboxData({
12283
+ const ShippingOptionField = ({
12284
+ shippingProfileId,
12285
+ preview,
12286
+ control
12287
+ }) => {
12288
+ var _a;
12289
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12290
+ const shippingOptions = useComboboxData({
12291
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12531
12292
  queryFn: async (params) => {
12532
- return await sdk.admin.salesChannel.list(params);
12293
+ return await sdk.admin.shippingOption.list({
12294
+ ...params,
12295
+ stock_location_id: locationId,
12296
+ shipping_profile_id: shippingProfileId
12297
+ });
12533
12298
  },
12534
- queryKey: ["sales-channels"],
12535
12299
  getOptions: (data) => {
12536
- return data.sales_channels.map((salesChannel) => ({
12537
- label: salesChannel.name,
12538
- value: salesChannel.id
12539
- }));
12300
+ return data.shipping_options.map((option) => {
12301
+ var _a2;
12302
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12303
+ (r) => r.attribute === "is_return" && r.value === "true"
12304
+ )) {
12305
+ return void 0;
12306
+ }
12307
+ return {
12308
+ label: option.name,
12309
+ value: option.id
12310
+ };
12311
+ }).filter(Boolean);
12540
12312
  },
12541
- defaultValue: order.sales_channel_id || void 0
12313
+ enabled: !!locationId && !!shippingProfileId,
12314
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12542
12315
  });
12316
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12317
+ return /* @__PURE__ */ jsxRuntime.jsx(
12318
+ Form$2.Field,
12319
+ {
12320
+ control,
12321
+ name: "shipping_option_id",
12322
+ render: ({ field }) => {
12323
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12324
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12325
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12326
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12327
+ ] }),
12328
+ /* @__PURE__ */ jsxRuntime.jsx(
12329
+ ConditionalTooltip,
12330
+ {
12331
+ content: tooltipContent,
12332
+ showTooltip: !locationId || !shippingProfileId,
12333
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12334
+ Combobox,
12335
+ {
12336
+ options: shippingOptions.options,
12337
+ fetchNextPage: shippingOptions.fetchNextPage,
12338
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12339
+ searchValue: shippingOptions.searchValue,
12340
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12341
+ placeholder: "Select shipping option",
12342
+ ...field,
12343
+ disabled: !locationId || !shippingProfileId
12344
+ }
12345
+ ) }) })
12346
+ }
12347
+ )
12348
+ ] }) });
12349
+ }
12350
+ }
12351
+ );
12352
+ };
12353
+ const CustomAmountField = ({
12354
+ control,
12355
+ currencyCode
12356
+ }) => {
12543
12357
  return /* @__PURE__ */ jsxRuntime.jsx(
12544
12358
  Form$2.Field,
12545
12359
  {
12546
12360
  control,
12547
- name: "sales_channel_id",
12548
- render: ({ field }) => {
12549
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12550
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12361
+ name: "custom_amount",
12362
+ render: ({ field: { onChange, ...field } }) => {
12363
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12364
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12365
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12367
+ ] }),
12551
12368
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12552
- Combobox,
12369
+ ui.CurrencyInput,
12553
12370
  {
12554
- options: salesChannels.options,
12555
- fetchNextPage: salesChannels.fetchNextPage,
12556
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12557
- searchValue: salesChannels.searchValue,
12558
- onSearchValueChange: salesChannels.onSearchValueChange,
12559
- placeholder: "Select sales channel",
12560
- ...field
12371
+ ...field,
12372
+ onValueChange: (value) => onChange(value),
12373
+ symbol: getNativeSymbol(currencyCode),
12374
+ code: currencyCode
12561
12375
  }
12562
- ) }),
12563
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12376
+ ) })
12564
12377
  ] });
12565
12378
  }
12566
12379
  }
12567
12380
  );
12568
12381
  };
12569
- const schema$1 = objectType({
12570
- sales_channel_id: stringType().min(1)
12571
- });
12572
12382
  const TransferOwnership = () => {
12573
12383
  const { id } = reactRouterDom.useParams();
12574
12384
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12592,7 +12402,7 @@ const TransferOwnershipForm = ({ order }) => {
12592
12402
  defaultValues: {
12593
12403
  customer_id: order.customer_id || ""
12594
12404
  },
12595
- resolver: zod.zodResolver(schema)
12405
+ resolver: zod.zodResolver(schema$1)
12596
12406
  });
12597
12407
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12598
12408
  const { handleSuccess } = useRouteModal();
@@ -13042,9 +12852,199 @@ const Illustration = () => {
13042
12852
  }
13043
12853
  );
13044
12854
  };
13045
- const schema = objectType({
12855
+ const schema$1 = objectType({
13046
12856
  customer_id: stringType().min(1)
13047
12857
  });
12858
+ const BillingAddress = () => {
12859
+ const { id } = reactRouterDom.useParams();
12860
+ const { order, isPending, isError, error } = useOrder(id, {
12861
+ fields: "+billing_address"
12862
+ });
12863
+ if (isError) {
12864
+ throw error;
12865
+ }
12866
+ const isReady = !isPending && !!order;
12867
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12868
+ /* @__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" }) })
12871
+ ] }),
12872
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12873
+ ] });
12874
+ };
12875
+ const BillingAddressForm = ({ order }) => {
12876
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12877
+ const form = reactHookForm.useForm({
12878
+ 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) ?? ""
12889
+ },
12890
+ resolver: zod.zodResolver(schema)
12891
+ });
12892
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12893
+ const { handleSuccess } = useRouteModal();
12894
+ const onSubmit = form.handleSubmit(async (data) => {
12895
+ await mutateAsync(
12896
+ { billing_address: data },
12897
+ {
12898
+ onSuccess: () => {
12899
+ handleSuccess();
12900
+ },
12901
+ onError: (error) => {
12902
+ ui.toast.error(error.message);
12903
+ }
12904
+ }
12905
+ );
12906
+ });
12907
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12908
+ KeyboundForm,
12909
+ {
12910
+ className: "flex flex-1 flex-col overflow-hidden",
12911
+ onSubmit,
12912
+ 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,
12916
+ {
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
+ ] })
12924
+ }
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,
12954
+ {
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
+ ] })
12962
+ }
12963
+ ),
12964
+ /* @__PURE__ */ jsxRuntime.jsx(
12965
+ Form$2.Field,
12966
+ {
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
+ ] })
12974
+ }
12975
+ ),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
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
+ ] })
12986
+ }
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,
13016
+ {
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
+ ] })
13024
+ }
13025
+ ),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(
13027
+ Form$2.Field,
13028
+ {
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
+ ] })
13036
+ }
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
+ ] }) })
13043
+ ]
13044
+ }
13045
+ ) });
13046
+ };
13047
+ const schema = addressSchema;
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,45 +13065,45 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13071
- },
13072
13068
  {
13073
13069
  Component: CustomItems,
13074
13070
  path: "/draft-orders/:id/custom-items"
13075
13071
  },
13076
- {
13077
- Component: Items,
13078
- path: "/draft-orders/:id/items"
13079
- },
13080
13072
  {
13081
13073
  Component: Email,
13082
13074
  path: "/draft-orders/:id/email"
13083
13075
  },
13084
- {
13085
- Component: Promotions,
13086
- path: "/draft-orders/:id/promotions"
13087
- },
13088
13076
  {
13089
13077
  Component: Metadata,
13090
13078
  path: "/draft-orders/:id/metadata"
13091
13079
  },
13092
13080
  {
13093
- Component: Shipping,
13094
- path: "/draft-orders/:id/shipping"
13081
+ Component: Items,
13082
+ path: "/draft-orders/:id/items"
13095
13083
  },
13096
13084
  {
13097
- Component: ShippingAddress,
13098
- path: "/draft-orders/:id/shipping-address"
13085
+ Component: Promotions,
13086
+ path: "/draft-orders/:id/promotions"
13099
13087
  },
13100
13088
  {
13101
13089
  Component: SalesChannel,
13102
13090
  path: "/draft-orders/:id/sales-channel"
13103
13091
  },
13092
+ {
13093
+ Component: ShippingAddress,
13094
+ path: "/draft-orders/:id/shipping-address"
13095
+ },
13096
+ {
13097
+ Component: Shipping,
13098
+ path: "/draft-orders/:id/shipping"
13099
+ },
13104
13100
  {
13105
13101
  Component: TransferOwnership,
13106
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
+ },
13104
+ {
13105
+ Component: BillingAddress,
13106
+ path: "/draft-orders/:id/billing-address"
13107
13107
  }
13108
13108
  ]
13109
13109
  }