@medusajs/draft-order 2.11.0-snapshot-20251017211629 → 2.11.0-snapshot-20251020120939

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.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -7817,12 +7817,10 @@ const CustomerField$1 = ({ control, setValue }) => {
7817
7817
  (option) => option.value === value
7818
7818
  )) == null ? void 0 : _a.label;
7819
7819
  const customerEmail = ((_b = label == null ? void 0 : label.match(/\((.*@.*)\)$/)) == null ? void 0 : _b[1]) || label;
7820
- if (!email && customerEmail) {
7821
- setValue("email", customerEmail, {
7822
- shouldDirty: true,
7823
- shouldTouch: true
7824
- });
7825
- }
7820
+ setValue("email", customerEmail || "", {
7821
+ shouldDirty: true,
7822
+ shouldTouch: true
7823
+ });
7826
7824
  },
7827
7825
  [email, setValue, customers.options]
7828
7826
  );
@@ -9567,6 +9565,196 @@ const ID = () => {
9567
9565
  /* @__PURE__ */ jsx(Outlet, {})
9568
9566
  ] });
9569
9567
  };
9568
+ const BillingAddress = () => {
9569
+ const { id } = useParams();
9570
+ const { order, isPending, isError, error } = useOrder(id, {
9571
+ fields: "+billing_address"
9572
+ });
9573
+ if (isError) {
9574
+ throw error;
9575
+ }
9576
+ const isReady = !isPending && !!order;
9577
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9578
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9579
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9580
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9581
+ ] }),
9582
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9583
+ ] });
9584
+ };
9585
+ const BillingAddressForm = ({ order }) => {
9586
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9587
+ const form = useForm({
9588
+ defaultValues: {
9589
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9590
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9591
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9592
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9593
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9594
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9595
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9596
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9597
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9598
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9599
+ },
9600
+ resolver: zodResolver(schema$5)
9601
+ });
9602
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9603
+ const { handleSuccess } = useRouteModal();
9604
+ const onSubmit = form.handleSubmit(async (data) => {
9605
+ await mutateAsync(
9606
+ { billing_address: data },
9607
+ {
9608
+ onSuccess: () => {
9609
+ handleSuccess();
9610
+ },
9611
+ onError: (error) => {
9612
+ toast.error(error.message);
9613
+ }
9614
+ }
9615
+ );
9616
+ });
9617
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9618
+ KeyboundForm,
9619
+ {
9620
+ className: "flex flex-1 flex-col overflow-hidden",
9621
+ onSubmit,
9622
+ children: [
9623
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
9624
+ /* @__PURE__ */ jsx(
9625
+ Form$2.Field,
9626
+ {
9627
+ control: form.control,
9628
+ name: "country_code",
9629
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9630
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9631
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9632
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9633
+ ] })
9634
+ }
9635
+ ),
9636
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9637
+ /* @__PURE__ */ jsx(
9638
+ Form$2.Field,
9639
+ {
9640
+ control: form.control,
9641
+ name: "first_name",
9642
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9643
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9644
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9645
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9646
+ ] })
9647
+ }
9648
+ ),
9649
+ /* @__PURE__ */ jsx(
9650
+ Form$2.Field,
9651
+ {
9652
+ control: form.control,
9653
+ name: "last_name",
9654
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9655
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9656
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9657
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9658
+ ] })
9659
+ }
9660
+ )
9661
+ ] }),
9662
+ /* @__PURE__ */ jsx(
9663
+ Form$2.Field,
9664
+ {
9665
+ control: form.control,
9666
+ name: "company",
9667
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9668
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9669
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9670
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9671
+ ] })
9672
+ }
9673
+ ),
9674
+ /* @__PURE__ */ jsx(
9675
+ Form$2.Field,
9676
+ {
9677
+ control: form.control,
9678
+ name: "address_1",
9679
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9680
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9681
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9682
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9683
+ ] })
9684
+ }
9685
+ ),
9686
+ /* @__PURE__ */ jsx(
9687
+ Form$2.Field,
9688
+ {
9689
+ control: form.control,
9690
+ name: "address_2",
9691
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9692
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9693
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9694
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9695
+ ] })
9696
+ }
9697
+ ),
9698
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9699
+ /* @__PURE__ */ jsx(
9700
+ Form$2.Field,
9701
+ {
9702
+ control: form.control,
9703
+ name: "postal_code",
9704
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9705
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9706
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9707
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9708
+ ] })
9709
+ }
9710
+ ),
9711
+ /* @__PURE__ */ jsx(
9712
+ Form$2.Field,
9713
+ {
9714
+ control: form.control,
9715
+ name: "city",
9716
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9717
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9718
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9719
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9720
+ ] })
9721
+ }
9722
+ )
9723
+ ] }),
9724
+ /* @__PURE__ */ jsx(
9725
+ Form$2.Field,
9726
+ {
9727
+ control: form.control,
9728
+ name: "province",
9729
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9730
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9731
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9732
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9733
+ ] })
9734
+ }
9735
+ ),
9736
+ /* @__PURE__ */ jsx(
9737
+ Form$2.Field,
9738
+ {
9739
+ control: form.control,
9740
+ name: "phone",
9741
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9742
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9743
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9744
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9745
+ ] })
9746
+ }
9747
+ )
9748
+ ] }) }),
9749
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9750
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9751
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9752
+ ] }) })
9753
+ ]
9754
+ }
9755
+ ) });
9756
+ };
9757
+ const schema$5 = addressSchema;
9570
9758
  const CustomItems = () => {
9571
9759
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9572
9760
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9575,7 +9763,7 @@ const CustomItems = () => {
9575
9763
  };
9576
9764
  const CustomItemsForm = () => {
9577
9765
  const form = useForm({
9578
- resolver: zodResolver(schema$5)
9766
+ resolver: zodResolver(schema$4)
9579
9767
  });
9580
9768
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9581
9769
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9585,7 +9773,7 @@ const CustomItemsForm = () => {
9585
9773
  ] }) })
9586
9774
  ] }) });
9587
9775
  };
9588
- const schema$5 = objectType({
9776
+ const schema$4 = objectType({
9589
9777
  email: stringType().email()
9590
9778
  });
9591
9779
  const Email = () => {
@@ -9610,7 +9798,7 @@ const EmailForm = ({ order }) => {
9610
9798
  defaultValues: {
9611
9799
  email: order.email ?? ""
9612
9800
  },
9613
- resolver: zodResolver(schema$4)
9801
+ resolver: zodResolver(schema$3)
9614
9802
  });
9615
9803
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9616
9804
  const { handleSuccess } = useRouteModal();
@@ -9653,797 +9841,606 @@ const EmailForm = ({ order }) => {
9653
9841
  }
9654
9842
  ) });
9655
9843
  };
9656
- const schema$4 = objectType({
9844
+ const schema$3 = objectType({
9657
9845
  email: stringType().email()
9658
9846
  });
9659
- const InlineTip = forwardRef(
9660
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9661
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9847
+ const NumberInput = forwardRef(
9848
+ ({
9849
+ value,
9850
+ onChange,
9851
+ size = "base",
9852
+ min = 0,
9853
+ max = 100,
9854
+ step = 1,
9855
+ className,
9856
+ disabled,
9857
+ ...props
9858
+ }, ref) => {
9859
+ const handleChange = (event) => {
9860
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9861
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9862
+ onChange(newValue);
9863
+ }
9864
+ };
9865
+ const handleIncrement = () => {
9866
+ const newValue = value + step;
9867
+ if (max === void 0 || newValue <= max) {
9868
+ onChange(newValue);
9869
+ }
9870
+ };
9871
+ const handleDecrement = () => {
9872
+ const newValue = value - step;
9873
+ if (min === void 0 || newValue >= min) {
9874
+ onChange(newValue);
9875
+ }
9876
+ };
9662
9877
  return /* @__PURE__ */ jsxs(
9663
9878
  "div",
9664
9879
  {
9665
- ref,
9666
9880
  className: clx(
9667
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9881
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9882
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9883
+ {
9884
+ "h-7": size === "small",
9885
+ "h-8": size === "base"
9886
+ },
9668
9887
  className
9669
9888
  ),
9670
- ...props,
9671
9889
  children: [
9672
9890
  /* @__PURE__ */ jsx(
9673
- "div",
9891
+ "input",
9674
9892
  {
9675
- role: "presentation",
9676
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9677
- "bg-ui-tag-orange-icon": variant === "warning"
9678
- })
9679
- }
9680
- ),
9681
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9682
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9683
- labelValue,
9684
- ":"
9685
- ] }),
9686
- " ",
9687
- children
9688
- ] })
9893
+ ref,
9894
+ type: "number",
9895
+ value,
9896
+ onChange: handleChange,
9897
+ min,
9898
+ max,
9899
+ step,
9900
+ className: clx(
9901
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9902
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9903
+ "placeholder:text-ui-fg-muted"
9904
+ ),
9905
+ ...props
9906
+ }
9907
+ ),
9908
+ /* @__PURE__ */ jsxs(
9909
+ "button",
9910
+ {
9911
+ className: clx(
9912
+ "flex items-center justify-center outline-none transition-fg",
9913
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9914
+ "focus:bg-ui-bg-field-component-hover",
9915
+ "hover:bg-ui-bg-field-component-hover",
9916
+ {
9917
+ "size-7": size === "small",
9918
+ "size-8": size === "base"
9919
+ }
9920
+ ),
9921
+ type: "button",
9922
+ onClick: handleDecrement,
9923
+ disabled: min !== void 0 && value <= min || disabled,
9924
+ children: [
9925
+ /* @__PURE__ */ jsx(Minus, {}),
9926
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9927
+ ]
9928
+ }
9929
+ ),
9930
+ /* @__PURE__ */ jsxs(
9931
+ "button",
9932
+ {
9933
+ className: clx(
9934
+ "flex items-center justify-center outline-none transition-fg",
9935
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9936
+ "focus:bg-ui-bg-field-hover",
9937
+ "hover:bg-ui-bg-field-hover",
9938
+ {
9939
+ "size-7": size === "small",
9940
+ "size-8": size === "base"
9941
+ }
9942
+ ),
9943
+ type: "button",
9944
+ onClick: handleIncrement,
9945
+ disabled: max !== void 0 && value >= max || disabled,
9946
+ children: [
9947
+ /* @__PURE__ */ jsx(Plus, {}),
9948
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9949
+ ]
9950
+ }
9951
+ )
9689
9952
  ]
9690
9953
  }
9691
9954
  );
9692
9955
  }
9693
9956
  );
9694
- InlineTip.displayName = "InlineTip";
9695
- const MetadataFieldSchema = objectType({
9696
- key: stringType(),
9697
- disabled: booleanType().optional(),
9698
- value: anyType()
9699
- });
9700
- const MetadataSchema = objectType({
9701
- metadata: arrayType(MetadataFieldSchema)
9702
- });
9703
- const Metadata = () => {
9957
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9958
+ const productVariantsQueryKeys = {
9959
+ list: (query2) => [
9960
+ PRODUCT_VARIANTS_QUERY_KEY,
9961
+ query2 ? query2 : void 0
9962
+ ]
9963
+ };
9964
+ const useProductVariants = (query2, options) => {
9965
+ const { data, ...rest } = useQuery({
9966
+ queryKey: productVariantsQueryKeys.list(query2),
9967
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9968
+ ...options
9969
+ });
9970
+ return { ...data, ...rest };
9971
+ };
9972
+ const useCancelOrderEdit = ({ preview }) => {
9973
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9974
+ const onCancel = useCallback(async () => {
9975
+ if (!preview) {
9976
+ return true;
9977
+ }
9978
+ let res = false;
9979
+ await cancelOrderEdit(void 0, {
9980
+ onError: (e) => {
9981
+ toast.error(e.message);
9982
+ },
9983
+ onSuccess: () => {
9984
+ res = true;
9985
+ }
9986
+ });
9987
+ return res;
9988
+ }, [preview, cancelOrderEdit]);
9989
+ return { onCancel };
9990
+ };
9991
+ let IS_REQUEST_RUNNING = false;
9992
+ const useInitiateOrderEdit = ({
9993
+ preview
9994
+ }) => {
9995
+ const navigate = useNavigate();
9996
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9997
+ useEffect(() => {
9998
+ async function run() {
9999
+ if (IS_REQUEST_RUNNING || !preview) {
10000
+ return;
10001
+ }
10002
+ if (preview.order_change) {
10003
+ return;
10004
+ }
10005
+ IS_REQUEST_RUNNING = true;
10006
+ await mutateAsync(void 0, {
10007
+ onError: (e) => {
10008
+ toast.error(e.message);
10009
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10010
+ return;
10011
+ }
10012
+ });
10013
+ IS_REQUEST_RUNNING = false;
10014
+ }
10015
+ run();
10016
+ }, [preview, navigate, mutateAsync]);
10017
+ };
10018
+ function convertNumber(value) {
10019
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10020
+ }
10021
+ const STACKED_MODAL_ID = "items_stacked_modal";
10022
+ const Items = () => {
9704
10023
  const { id } = useParams();
9705
- const { order, isPending, isError, error } = useOrder(id, {
9706
- fields: "metadata"
10024
+ const {
10025
+ order: preview,
10026
+ isPending: isPreviewPending,
10027
+ isError: isPreviewError,
10028
+ error: previewError
10029
+ } = useOrderPreview(id, void 0, {
10030
+ placeholderData: keepPreviousData
9707
10031
  });
10032
+ useInitiateOrderEdit({ preview });
10033
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10034
+ id,
10035
+ {
10036
+ fields: "currency_code"
10037
+ },
10038
+ {
10039
+ enabled: !!id
10040
+ }
10041
+ );
10042
+ const { onCancel } = useCancelOrderEdit({ preview });
9708
10043
  if (isError) {
9709
10044
  throw error;
9710
10045
  }
9711
- const isReady = !isPending && !!order;
9712
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9713
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9714
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9715
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9716
- ] }),
9717
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9718
- ] });
10046
+ if (isPreviewError) {
10047
+ throw previewError;
10048
+ }
10049
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10050
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10051
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10052
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10053
+ ] }) });
9719
10054
  };
9720
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9721
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9722
- const MetadataForm = ({ orderId, metadata }) => {
10055
+ const ItemsForm = ({ preview, currencyCode }) => {
10056
+ var _a;
10057
+ const [isSubmitting, setIsSubmitting] = useState(false);
10058
+ const [modalContent, setModalContent] = useState(
10059
+ null
10060
+ );
9723
10061
  const { handleSuccess } = useRouteModal();
9724
- const hasUneditableRows = getHasUneditableRows(metadata);
9725
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9726
- const form = useForm({
9727
- defaultValues: {
9728
- metadata: getDefaultValues(metadata)
9729
- },
9730
- resolver: zodResolver(MetadataSchema)
9731
- });
9732
- const handleSubmit = form.handleSubmit(async (data) => {
9733
- const parsedData = parseValues(data);
9734
- await mutateAsync(
9735
- {
9736
- metadata: parsedData
10062
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10063
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10064
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10065
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10066
+ const matches = useMemo(() => {
10067
+ return matchSorter(preview.items, query2, {
10068
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10069
+ });
10070
+ }, [preview.items, query2]);
10071
+ const onSubmit = async () => {
10072
+ setIsSubmitting(true);
10073
+ let requestSucceeded = false;
10074
+ await requestOrderEdit(void 0, {
10075
+ onError: (e) => {
10076
+ toast.error(`Failed to request order edit: ${e.message}`);
9737
10077
  },
9738
- {
9739
- onSuccess: () => {
9740
- toast.success("Metadata updated");
9741
- handleSuccess();
9742
- },
9743
- onError: (error) => {
9744
- toast.error(error.message);
9745
- }
10078
+ onSuccess: () => {
10079
+ requestSucceeded = true;
9746
10080
  }
9747
- );
9748
- });
9749
- const { fields, insert, remove } = useFieldArray({
9750
- control: form.control,
9751
- name: "metadata"
9752
- });
9753
- function deleteRow(index) {
9754
- remove(index);
9755
- if (fields.length === 1) {
9756
- insert(0, {
9757
- key: "",
9758
- value: "",
9759
- disabled: false
9760
- });
10081
+ });
10082
+ if (!requestSucceeded) {
10083
+ setIsSubmitting(false);
10084
+ return;
9761
10085
  }
9762
- }
9763
- function insertRow(index, position) {
9764
- insert(index + (position === "above" ? 0 : 1), {
9765
- key: "",
9766
- value: "",
9767
- disabled: false
10086
+ await confirmOrderEdit(void 0, {
10087
+ onError: (e) => {
10088
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10089
+ },
10090
+ onSuccess: () => {
10091
+ handleSuccess();
10092
+ },
10093
+ onSettled: () => {
10094
+ setIsSubmitting(false);
10095
+ }
9768
10096
  });
9769
- }
9770
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9771
- KeyboundForm,
9772
- {
9773
- onSubmit: handleSubmit,
9774
- className: "flex flex-1 flex-col overflow-hidden",
9775
- children: [
9776
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9777
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9778
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9779
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9780
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10097
+ };
10098
+ const onKeyDown = useCallback(
10099
+ (e) => {
10100
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10101
+ if (modalContent || isSubmitting) {
10102
+ return;
10103
+ }
10104
+ onSubmit();
10105
+ }
10106
+ },
10107
+ [modalContent, isSubmitting, onSubmit]
10108
+ );
10109
+ useEffect(() => {
10110
+ document.addEventListener("keydown", onKeyDown);
10111
+ return () => {
10112
+ document.removeEventListener("keydown", onKeyDown);
10113
+ };
10114
+ }, [onKeyDown]);
10115
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10116
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10117
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10118
+ StackedFocusModal,
10119
+ {
10120
+ id: STACKED_MODAL_ID,
10121
+ onOpenChangeCallback: (open) => {
10122
+ if (!open) {
10123
+ setModalContent(null);
10124
+ }
10125
+ },
10126
+ children: [
10127
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10128
+ /* @__PURE__ */ jsxs("div", { children: [
10129
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10130
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
9781
10131
  ] }),
9782
- fields.map((field, index) => {
9783
- const isDisabled = field.disabled || false;
9784
- let placeholder = "-";
9785
- if (typeof field.value === "object") {
9786
- placeholder = "{ ... }";
9787
- }
9788
- if (Array.isArray(field.value)) {
9789
- placeholder = "[ ... ]";
9790
- }
9791
- return /* @__PURE__ */ jsx(
9792
- ConditionalTooltip,
9793
- {
9794
- showTooltip: isDisabled,
9795
- content: "This row is disabled because it contains non-primitive data.",
9796
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9797
- /* @__PURE__ */ jsxs(
9798
- "div",
9799
- {
9800
- className: clx("grid grid-cols-2 divide-x", {
9801
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9802
- }),
9803
- children: [
9804
- /* @__PURE__ */ jsx(
9805
- Form$2.Field,
9806
- {
9807
- control: form.control,
9808
- name: `metadata.${index}.key`,
9809
- render: ({ field: field2 }) => {
9810
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9811
- GridInput,
9812
- {
9813
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9814
- ...field2,
9815
- disabled: isDisabled,
9816
- placeholder: "Key"
9817
- }
9818
- ) }) });
9819
- }
9820
- }
9821
- ),
9822
- /* @__PURE__ */ jsx(
9823
- Form$2.Field,
9824
- {
9825
- control: form.control,
9826
- name: `metadata.${index}.value`,
9827
- render: ({ field: { value, ...field2 } }) => {
9828
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9829
- GridInput,
9830
- {
9831
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9832
- ...field2,
9833
- value: isDisabled ? placeholder : value,
9834
- disabled: isDisabled,
9835
- placeholder: "Value"
9836
- }
9837
- ) }) });
9838
- }
9839
- }
9840
- )
9841
- ]
9842
- }
9843
- ),
9844
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10132
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10133
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10134
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10135
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10136
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10137
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10138
+ ] }),
10139
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10140
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10141
+ Input,
10142
+ {
10143
+ type: "search",
10144
+ placeholder: "Search items",
10145
+ value: searchValue,
10146
+ onChange: (e) => onSearchValueChange(e.target.value)
10147
+ }
10148
+ ) }),
10149
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10150
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10151
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9845
10152
  /* @__PURE__ */ jsx(
9846
- DropdownMenu.Trigger,
10153
+ StackedModalTrigger$1,
9847
10154
  {
9848
- className: clx(
9849
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9850
- {
9851
- hidden: isDisabled
9852
- }
9853
- ),
9854
- disabled: isDisabled,
9855
- asChild: true,
9856
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10155
+ type: "add-items",
10156
+ setModalContent
9857
10157
  }
9858
10158
  ),
9859
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9860
- /* @__PURE__ */ jsxs(
9861
- DropdownMenu.Item,
9862
- {
9863
- className: "gap-x-2",
9864
- onClick: () => insertRow(index, "above"),
9865
- children: [
9866
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
9867
- "Insert row above"
9868
- ]
9869
- }
9870
- ),
9871
- /* @__PURE__ */ jsxs(
9872
- DropdownMenu.Item,
9873
- {
9874
- className: "gap-x-2",
9875
- onClick: () => insertRow(index, "below"),
9876
- children: [
9877
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
9878
- "Insert row below"
9879
- ]
9880
- }
9881
- ),
9882
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
9883
- /* @__PURE__ */ jsxs(
9884
- DropdownMenu.Item,
9885
- {
9886
- className: "gap-x-2",
9887
- onClick: () => deleteRow(index),
9888
- children: [
9889
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
9890
- "Delete row"
9891
- ]
9892
- }
9893
- )
9894
- ] })
10159
+ /* @__PURE__ */ jsx(
10160
+ StackedModalTrigger$1,
10161
+ {
10162
+ type: "add-custom-item",
10163
+ setModalContent
10164
+ }
10165
+ )
9895
10166
  ] })
9896
10167
  ] })
9897
- },
9898
- field.id
9899
- );
9900
- })
9901
- ] }),
9902
- hasUneditableRows && /* @__PURE__ */ 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." })
9903
- ] }),
9904
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9905
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9906
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9907
- ] }) })
9908
- ]
9909
- }
9910
- ) });
9911
- };
9912
- const GridInput = forwardRef(({ className, ...props }, ref) => {
9913
- return /* @__PURE__ */ jsx(
9914
- "input",
9915
- {
9916
- ref,
9917
- ...props,
9918
- autoComplete: "off",
9919
- className: clx(
9920
- "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",
9921
- className
9922
- )
9923
- }
9924
- );
9925
- });
9926
- GridInput.displayName = "MetadataForm.GridInput";
9927
- const PlaceholderInner = () => {
9928
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9929
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9930
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9931
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
9932
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
9933
- ] }) })
9934
- ] });
9935
- };
9936
- const EDITABLE_TYPES = ["string", "number", "boolean"];
9937
- function getDefaultValues(metadata) {
9938
- if (!metadata || !Object.keys(metadata).length) {
9939
- return [
9940
- {
9941
- key: "",
9942
- value: "",
9943
- disabled: false
9944
- }
9945
- ];
9946
- }
9947
- return Object.entries(metadata).map(([key, value]) => {
9948
- if (!EDITABLE_TYPES.includes(typeof value)) {
9949
- return {
9950
- key,
9951
- value,
9952
- disabled: true
9953
- };
9954
- }
9955
- let stringValue = value;
9956
- if (typeof value !== "string") {
9957
- stringValue = JSON.stringify(value);
9958
- }
9959
- return {
9960
- key,
9961
- value: stringValue,
9962
- original_key: key
9963
- };
9964
- });
9965
- }
9966
- function parseValues(values) {
9967
- const metadata = values.metadata;
9968
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9969
- if (isEmpty) {
9970
- return null;
10168
+ ] })
10169
+ ] }),
10170
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10171
+ /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10172
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10173
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10174
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10175
+ /* @__PURE__ */ jsx("div", {})
10176
+ ] }) }),
10177
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ 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: [
10178
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10179
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10180
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10181
+ Item,
10182
+ {
10183
+ item,
10184
+ preview,
10185
+ currencyCode
10186
+ },
10187
+ item.id
10188
+ )) : /* @__PURE__ */ 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: [
10189
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10190
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10191
+ 'No items found for "',
10192
+ query2,
10193
+ '".'
10194
+ ] })
10195
+ ] }) })
10196
+ ] })
10197
+ ] }),
10198
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10199
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10200
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10201
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10202
+ Text,
10203
+ {
10204
+ size: "small",
10205
+ leading: "compact",
10206
+ className: "text-ui-fg-subtle",
10207
+ children: [
10208
+ itemCount,
10209
+ " ",
10210
+ itemCount === 1 ? "item" : "items"
10211
+ ]
10212
+ }
10213
+ ) }),
10214
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10215
+ ] })
10216
+ ] }) }),
10217
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10218
+ CustomItemForm,
10219
+ {
10220
+ orderId: preview.id,
10221
+ currencyCode
10222
+ }
10223
+ ) : null)
10224
+ ]
10225
+ }
10226
+ ) }),
10227
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10228
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10229
+ /* @__PURE__ */ jsx(
10230
+ Button,
10231
+ {
10232
+ size: "small",
10233
+ type: "button",
10234
+ onClick: onSubmit,
10235
+ isLoading: isSubmitting,
10236
+ children: "Save"
10237
+ }
10238
+ )
10239
+ ] }) })
10240
+ ] });
10241
+ };
10242
+ const Item = ({ item, preview, currencyCode }) => {
10243
+ if (item.variant_id) {
10244
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
9971
10245
  }
9972
- const update = {};
9973
- metadata.forEach((field) => {
9974
- let key = field.key;
9975
- let value = field.value;
9976
- const disabled = field.disabled;
9977
- if (!key || !value) {
10246
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10247
+ };
10248
+ const VariantItem = ({ item, preview, currencyCode }) => {
10249
+ const [editing, setEditing] = useState(false);
10250
+ const form = useForm({
10251
+ defaultValues: {
10252
+ quantity: item.quantity,
10253
+ unit_price: item.unit_price
10254
+ },
10255
+ resolver: zodResolver(variantItemSchema)
10256
+ });
10257
+ const actionId = useMemo(() => {
10258
+ var _a, _b;
10259
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10260
+ }, [item]);
10261
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10262
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10263
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10264
+ const onSubmit = form.handleSubmit(async (data) => {
10265
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10266
+ setEditing(false);
9978
10267
  return;
9979
10268
  }
9980
- if (disabled) {
9981
- update[key] = value;
10269
+ if (!actionId) {
10270
+ await updateOriginalItem(
10271
+ {
10272
+ item_id: item.id,
10273
+ quantity: data.quantity,
10274
+ unit_price: convertNumber(data.unit_price)
10275
+ },
10276
+ {
10277
+ onSuccess: () => {
10278
+ setEditing(false);
10279
+ },
10280
+ onError: (e) => {
10281
+ toast.error(e.message);
10282
+ }
10283
+ }
10284
+ );
9982
10285
  return;
9983
10286
  }
9984
- key = key.trim();
9985
- value = value.trim();
9986
- if (value === "true") {
9987
- update[key] = true;
9988
- } else if (value === "false") {
9989
- update[key] = false;
9990
- } else {
9991
- const parsedNumber = parseFloat(value);
9992
- if (!isNaN(parsedNumber)) {
9993
- update[key] = parsedNumber;
9994
- } else {
9995
- update[key] = value;
10287
+ await updateActionItem(
10288
+ {
10289
+ action_id: actionId,
10290
+ quantity: data.quantity,
10291
+ unit_price: convertNumber(data.unit_price)
10292
+ },
10293
+ {
10294
+ onSuccess: () => {
10295
+ setEditing(false);
10296
+ },
10297
+ onError: (e) => {
10298
+ toast.error(e.message);
10299
+ }
9996
10300
  }
9997
- }
10301
+ );
9998
10302
  });
9999
- return update;
10000
- }
10001
- function getHasUneditableRows(metadata) {
10002
- if (!metadata) {
10003
- return false;
10004
- }
10005
- return Object.values(metadata).some(
10006
- (value) => !EDITABLE_TYPES.includes(typeof value)
10007
- );
10008
- }
10009
- const NumberInput = forwardRef(
10010
- ({
10011
- value,
10012
- onChange,
10013
- size = "base",
10014
- min = 0,
10015
- max = 100,
10016
- step = 1,
10017
- className,
10018
- disabled,
10019
- ...props
10020
- }, ref) => {
10021
- const handleChange = (event) => {
10022
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10023
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10024
- onChange(newValue);
10025
- }
10026
- };
10027
- const handleIncrement = () => {
10028
- const newValue = value + step;
10029
- if (max === void 0 || newValue <= max) {
10030
- onChange(newValue);
10031
- }
10032
- };
10033
- const handleDecrement = () => {
10034
- const newValue = value - step;
10035
- if (min === void 0 || newValue >= min) {
10036
- onChange(newValue);
10037
- }
10038
- };
10039
- return /* @__PURE__ */ jsxs(
10040
- "div",
10041
- {
10042
- className: clx(
10043
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10044
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10045
- {
10046
- "h-7": size === "small",
10047
- "h-8": size === "base"
10048
- },
10049
- className
10050
- ),
10051
- children: [
10052
- /* @__PURE__ */ jsx(
10053
- "input",
10054
- {
10055
- ref,
10056
- type: "number",
10057
- value,
10058
- onChange: handleChange,
10059
- min,
10060
- max,
10061
- step,
10062
- className: clx(
10063
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10064
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10065
- "placeholder:text-ui-fg-muted"
10066
- ),
10067
- ...props
10068
- }
10069
- ),
10303
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ 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: [
10304
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10305
+ /* @__PURE__ */ jsx(
10306
+ Thumbnail,
10307
+ {
10308
+ thumbnail: item.thumbnail,
10309
+ alt: item.product_title ?? void 0
10310
+ }
10311
+ ),
10312
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10313
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10314
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10070
10315
  /* @__PURE__ */ jsxs(
10071
- "button",
10316
+ Text,
10072
10317
  {
10073
- className: clx(
10074
- "flex items-center justify-center outline-none transition-fg",
10075
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10076
- "focus:bg-ui-bg-field-component-hover",
10077
- "hover:bg-ui-bg-field-component-hover",
10078
- {
10079
- "size-7": size === "small",
10080
- "size-8": size === "base"
10081
- }
10082
- ),
10083
- type: "button",
10084
- onClick: handleDecrement,
10085
- disabled: min !== void 0 && value <= min || disabled,
10318
+ size: "small",
10319
+ leading: "compact",
10320
+ className: "text-ui-fg-subtle",
10086
10321
  children: [
10087
- /* @__PURE__ */ jsx(Minus, {}),
10088
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10322
+ "(",
10323
+ item.variant_title,
10324
+ ")"
10089
10325
  ]
10090
10326
  }
10091
- ),
10092
- /* @__PURE__ */ jsxs(
10093
- "button",
10327
+ )
10328
+ ] }),
10329
+ /* @__PURE__ */ jsx(
10330
+ Text,
10331
+ {
10332
+ size: "small",
10333
+ leading: "compact",
10334
+ className: "text-ui-fg-subtle",
10335
+ children: item.variant_sku
10336
+ }
10337
+ )
10338
+ ] })
10339
+ ] }),
10340
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10341
+ Form$2.Field,
10342
+ {
10343
+ control: form.control,
10344
+ name: "quantity",
10345
+ render: ({ field }) => {
10346
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10347
+ }
10348
+ }
10349
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10350
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10351
+ Form$2.Field,
10352
+ {
10353
+ control: form.control,
10354
+ name: "unit_price",
10355
+ render: ({ field: { onChange, ...field } }) => {
10356
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10357
+ CurrencyInput,
10094
10358
  {
10095
- className: clx(
10096
- "flex items-center justify-center outline-none transition-fg",
10097
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10098
- "focus:bg-ui-bg-field-hover",
10099
- "hover:bg-ui-bg-field-hover",
10100
- {
10101
- "size-7": size === "small",
10102
- "size-8": size === "base"
10103
- }
10104
- ),
10105
- type: "button",
10106
- onClick: handleIncrement,
10107
- disabled: max !== void 0 && value >= max || disabled,
10108
- children: [
10109
- /* @__PURE__ */ jsx(Plus, {}),
10110
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10111
- ]
10359
+ ...field,
10360
+ symbol: getNativeSymbol(currencyCode),
10361
+ code: currencyCode,
10362
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10112
10363
  }
10113
- )
10114
- ]
10364
+ ) }) });
10365
+ }
10115
10366
  }
10116
- );
10117
- }
10118
- );
10119
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10120
- const productVariantsQueryKeys = {
10121
- list: (query2) => [
10122
- PRODUCT_VARIANTS_QUERY_KEY,
10123
- query2 ? query2 : void 0
10124
- ]
10125
- };
10126
- const useProductVariants = (query2, options) => {
10127
- const { data, ...rest } = useQuery({
10128
- queryKey: productVariantsQueryKeys.list(query2),
10129
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10130
- ...options
10131
- });
10132
- return { ...data, ...rest };
10133
- };
10134
- const useCancelOrderEdit = ({ preview }) => {
10135
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10136
- const onCancel = useCallback(async () => {
10137
- if (!preview) {
10138
- return true;
10139
- }
10140
- let res = false;
10141
- await cancelOrderEdit(void 0, {
10142
- onError: (e) => {
10143
- toast.error(e.message);
10144
- },
10145
- onSuccess: () => {
10146
- res = true;
10367
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10368
+ /* @__PURE__ */ jsx(
10369
+ IconButton,
10370
+ {
10371
+ type: "button",
10372
+ size: "small",
10373
+ onClick: editing ? onSubmit : () => {
10374
+ setEditing(true);
10375
+ },
10376
+ disabled: isPending,
10377
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10147
10378
  }
10148
- });
10149
- return res;
10150
- }, [preview, cancelOrderEdit]);
10151
- return { onCancel };
10379
+ )
10380
+ ] }) }) });
10152
10381
  };
10153
- let IS_REQUEST_RUNNING = false;
10154
- const useInitiateOrderEdit = ({
10155
- preview
10156
- }) => {
10157
- const navigate = useNavigate();
10158
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10382
+ const variantItemSchema = objectType({
10383
+ quantity: numberType(),
10384
+ unit_price: unionType([numberType(), stringType()])
10385
+ });
10386
+ const CustomItem = ({ item, preview, currencyCode }) => {
10387
+ const [editing, setEditing] = useState(false);
10388
+ const { quantity, unit_price, title } = item;
10389
+ const form = useForm({
10390
+ defaultValues: {
10391
+ title,
10392
+ quantity,
10393
+ unit_price
10394
+ },
10395
+ resolver: zodResolver(customItemSchema)
10396
+ });
10159
10397
  useEffect(() => {
10160
- async function run() {
10161
- if (IS_REQUEST_RUNNING || !preview) {
10162
- return;
10163
- }
10164
- if (preview.order_change) {
10165
- return;
10166
- }
10167
- IS_REQUEST_RUNNING = true;
10168
- await mutateAsync(void 0, {
10398
+ form.reset({
10399
+ title,
10400
+ quantity,
10401
+ unit_price
10402
+ });
10403
+ }, [form, title, quantity, unit_price]);
10404
+ const actionId = useMemo(() => {
10405
+ var _a, _b;
10406
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10407
+ }, [item]);
10408
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10409
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10410
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10411
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10412
+ const onSubmit = form.handleSubmit(async (data) => {
10413
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10414
+ setEditing(false);
10415
+ return;
10416
+ }
10417
+ if (!actionId) {
10418
+ await updateOriginalItem(
10419
+ {
10420
+ item_id: item.id,
10421
+ quantity: data.quantity,
10422
+ unit_price: convertNumber(data.unit_price)
10423
+ },
10424
+ {
10425
+ onSuccess: () => {
10426
+ setEditing(false);
10427
+ },
10428
+ onError: (e) => {
10429
+ toast.error(e.message);
10430
+ }
10431
+ }
10432
+ );
10433
+ return;
10434
+ }
10435
+ if (data.quantity === 0) {
10436
+ await removeActionItem(actionId, {
10437
+ onSuccess: () => {
10438
+ setEditing(false);
10439
+ },
10169
10440
  onError: (e) => {
10170
10441
  toast.error(e.message);
10171
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10172
- return;
10173
10442
  }
10174
10443
  });
10175
- IS_REQUEST_RUNNING = false;
10176
- }
10177
- run();
10178
- }, [preview, navigate, mutateAsync]);
10179
- };
10180
- function convertNumber(value) {
10181
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10182
- }
10183
- const STACKED_MODAL_ID = "items_stacked_modal";
10184
- const Items = () => {
10185
- const { id } = useParams();
10186
- const {
10187
- order: preview,
10188
- isPending: isPreviewPending,
10189
- isError: isPreviewError,
10190
- error: previewError
10191
- } = useOrderPreview(id, void 0, {
10192
- placeholderData: keepPreviousData
10193
- });
10194
- useInitiateOrderEdit({ preview });
10195
- const { draft_order, isPending, isError, error } = useDraftOrder(
10196
- id,
10197
- {
10198
- fields: "currency_code"
10199
- },
10200
- {
10201
- enabled: !!id
10202
- }
10203
- );
10204
- const { onCancel } = useCancelOrderEdit({ preview });
10205
- if (isError) {
10206
- throw error;
10207
- }
10208
- if (isPreviewError) {
10209
- throw previewError;
10210
- }
10211
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10212
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10213
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10214
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10215
- ] }) });
10216
- };
10217
- const ItemsForm = ({ preview, currencyCode }) => {
10218
- var _a;
10219
- const [isSubmitting, setIsSubmitting] = useState(false);
10220
- const [modalContent, setModalContent] = useState(
10221
- null
10222
- );
10223
- const { handleSuccess } = useRouteModal();
10224
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10225
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10226
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10227
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10228
- const matches = useMemo(() => {
10229
- return matchSorter(preview.items, query2, {
10230
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10231
- });
10232
- }, [preview.items, query2]);
10233
- const onSubmit = async () => {
10234
- setIsSubmitting(true);
10235
- let requestSucceeded = false;
10236
- await requestOrderEdit(void 0, {
10237
- onError: (e) => {
10238
- toast.error(`Failed to request order edit: ${e.message}`);
10239
- },
10240
- onSuccess: () => {
10241
- requestSucceeded = true;
10242
- }
10243
- });
10244
- if (!requestSucceeded) {
10245
- setIsSubmitting(false);
10246
- return;
10247
- }
10248
- await confirmOrderEdit(void 0, {
10249
- onError: (e) => {
10250
- toast.error(`Failed to confirm order edit: ${e.message}`);
10251
- },
10252
- onSuccess: () => {
10253
- handleSuccess();
10254
- },
10255
- onSettled: () => {
10256
- setIsSubmitting(false);
10257
- }
10258
- });
10259
- };
10260
- const onKeyDown = useCallback(
10261
- (e) => {
10262
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10263
- if (modalContent || isSubmitting) {
10264
- return;
10265
- }
10266
- onSubmit();
10267
- }
10268
- },
10269
- [modalContent, isSubmitting, onSubmit]
10270
- );
10271
- useEffect(() => {
10272
- document.addEventListener("keydown", onKeyDown);
10273
- return () => {
10274
- document.removeEventListener("keydown", onKeyDown);
10275
- };
10276
- }, [onKeyDown]);
10277
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10278
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10279
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10280
- StackedFocusModal,
10281
- {
10282
- id: STACKED_MODAL_ID,
10283
- onOpenChangeCallback: (open) => {
10284
- if (!open) {
10285
- setModalContent(null);
10286
- }
10287
- },
10288
- children: [
10289
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10290
- /* @__PURE__ */ jsxs("div", { children: [
10291
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10292
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
10293
- ] }),
10294
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10295
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10296
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10297
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10298
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10299
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10300
- ] }),
10301
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10302
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10303
- Input,
10304
- {
10305
- type: "search",
10306
- placeholder: "Search items",
10307
- value: searchValue,
10308
- onChange: (e) => onSearchValueChange(e.target.value)
10309
- }
10310
- ) }),
10311
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10312
- /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10313
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10314
- /* @__PURE__ */ jsx(
10315
- StackedModalTrigger$1,
10316
- {
10317
- type: "add-items",
10318
- setModalContent
10319
- }
10320
- ),
10321
- /* @__PURE__ */ jsx(
10322
- StackedModalTrigger$1,
10323
- {
10324
- type: "add-custom-item",
10325
- setModalContent
10326
- }
10327
- )
10328
- ] })
10329
- ] })
10330
- ] })
10331
- ] }),
10332
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10333
- /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10334
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10335
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10336
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10337
- /* @__PURE__ */ jsx("div", {})
10338
- ] }) }),
10339
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ 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: [
10340
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10341
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10342
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10343
- Item,
10344
- {
10345
- item,
10346
- preview,
10347
- currencyCode
10348
- },
10349
- item.id
10350
- )) : /* @__PURE__ */ 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: [
10351
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10352
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10353
- 'No items found for "',
10354
- query2,
10355
- '".'
10356
- ] })
10357
- ] }) })
10358
- ] })
10359
- ] }),
10360
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10361
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10362
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10363
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10364
- Text,
10365
- {
10366
- size: "small",
10367
- leading: "compact",
10368
- className: "text-ui-fg-subtle",
10369
- children: [
10370
- itemCount,
10371
- " ",
10372
- itemCount === 1 ? "item" : "items"
10373
- ]
10374
- }
10375
- ) }),
10376
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10377
- ] })
10378
- ] }) }),
10379
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10380
- CustomItemForm,
10381
- {
10382
- orderId: preview.id,
10383
- currencyCode
10384
- }
10385
- ) : null)
10386
- ]
10387
- }
10388
- ) }),
10389
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10390
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10391
- /* @__PURE__ */ jsx(
10392
- Button,
10393
- {
10394
- size: "small",
10395
- type: "button",
10396
- onClick: onSubmit,
10397
- isLoading: isSubmitting,
10398
- children: "Save"
10399
- }
10400
- )
10401
- ] }) })
10402
- ] });
10403
- };
10404
- const Item = ({ item, preview, currencyCode }) => {
10405
- if (item.variant_id) {
10406
- return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10407
- }
10408
- return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10409
- };
10410
- const VariantItem = ({ item, preview, currencyCode }) => {
10411
- const [editing, setEditing] = useState(false);
10412
- const form = useForm({
10413
- defaultValues: {
10414
- quantity: item.quantity,
10415
- unit_price: item.unit_price
10416
- },
10417
- resolver: zodResolver(variantItemSchema)
10418
- });
10419
- const actionId = useMemo(() => {
10420
- var _a, _b;
10421
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10422
- }, [item]);
10423
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10424
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10425
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10426
- const onSubmit = form.handleSubmit(async (data) => {
10427
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10428
- setEditing(false);
10429
- return;
10430
- }
10431
- if (!actionId) {
10432
- await updateOriginalItem(
10433
- {
10434
- item_id: item.id,
10435
- quantity: data.quantity,
10436
- unit_price: convertNumber(data.unit_price)
10437
- },
10438
- {
10439
- onSuccess: () => {
10440
- setEditing(false);
10441
- },
10442
- onError: (e) => {
10443
- toast.error(e.message);
10444
- }
10445
- }
10446
- );
10447
10444
  return;
10448
10445
  }
10449
10446
  await updateActionItem(
@@ -10463,43 +10460,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10463
10460
  );
10464
10461
  });
10465
10462
  return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ 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: [
10466
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10463
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10467
10464
  /* @__PURE__ */ jsx(
10468
10465
  Thumbnail,
10469
10466
  {
10470
10467
  thumbnail: item.thumbnail,
10471
- alt: item.product_title ?? void 0
10468
+ alt: item.title ?? void 0
10472
10469
  }
10473
10470
  ),
10474
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10475
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10476
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10477
- /* @__PURE__ */ jsxs(
10478
- Text,
10479
- {
10480
- size: "small",
10481
- leading: "compact",
10482
- className: "text-ui-fg-subtle",
10483
- children: [
10484
- "(",
10485
- item.variant_title,
10486
- ")"
10487
- ]
10488
- }
10489
- )
10490
- ] }),
10491
- /* @__PURE__ */ jsx(
10492
- Text,
10493
- {
10494
- size: "small",
10495
- leading: "compact",
10496
- className: "text-ui-fg-subtle",
10497
- children: item.variant_sku
10471
+ editing ? /* @__PURE__ */ jsx(
10472
+ Form$2.Field,
10473
+ {
10474
+ control: form.control,
10475
+ name: "title",
10476
+ render: ({ field }) => {
10477
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10498
10478
  }
10499
- )
10500
- ] })
10479
+ }
10480
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10501
10481
  ] }),
10502
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10482
+ editing ? /* @__PURE__ */ jsx(
10503
10483
  Form$2.Field,
10504
10484
  {
10505
10485
  control: form.control,
@@ -10508,8 +10488,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10508
10488
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10509
10489
  }
10510
10490
  }
10511
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10512
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10491
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10492
+ editing ? /* @__PURE__ */ jsx(
10513
10493
  Form$2.Field,
10514
10494
  {
10515
10495
  control: form.control,
@@ -10526,149 +10506,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10526
10506
  ) }) });
10527
10507
  }
10528
10508
  }
10529
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10530
- /* @__PURE__ */ jsx(
10531
- IconButton,
10532
- {
10533
- type: "button",
10534
- size: "small",
10535
- onClick: editing ? onSubmit : () => {
10536
- setEditing(true);
10537
- },
10538
- disabled: isPending,
10539
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10540
- }
10541
- )
10542
- ] }) }) });
10543
- };
10544
- const variantItemSchema = objectType({
10545
- quantity: numberType(),
10546
- unit_price: unionType([numberType(), stringType()])
10547
- });
10548
- const CustomItem = ({ item, preview, currencyCode }) => {
10549
- const [editing, setEditing] = useState(false);
10550
- const { quantity, unit_price, title } = item;
10551
- const form = useForm({
10552
- defaultValues: {
10553
- title,
10554
- quantity,
10555
- unit_price
10556
- },
10557
- resolver: zodResolver(customItemSchema)
10558
- });
10559
- useEffect(() => {
10560
- form.reset({
10561
- title,
10562
- quantity,
10563
- unit_price
10564
- });
10565
- }, [form, title, quantity, unit_price]);
10566
- const actionId = useMemo(() => {
10567
- var _a, _b;
10568
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10569
- }, [item]);
10570
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10571
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10572
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10573
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10574
- const onSubmit = form.handleSubmit(async (data) => {
10575
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10576
- setEditing(false);
10577
- return;
10578
- }
10579
- if (!actionId) {
10580
- await updateOriginalItem(
10581
- {
10582
- item_id: item.id,
10583
- quantity: data.quantity,
10584
- unit_price: convertNumber(data.unit_price)
10585
- },
10586
- {
10587
- onSuccess: () => {
10588
- setEditing(false);
10589
- },
10590
- onError: (e) => {
10591
- toast.error(e.message);
10592
- }
10593
- }
10594
- );
10595
- return;
10596
- }
10597
- if (data.quantity === 0) {
10598
- await removeActionItem(actionId, {
10599
- onSuccess: () => {
10600
- setEditing(false);
10601
- },
10602
- onError: (e) => {
10603
- toast.error(e.message);
10604
- }
10605
- });
10606
- return;
10607
- }
10608
- await updateActionItem(
10609
- {
10610
- action_id: actionId,
10611
- quantity: data.quantity,
10612
- unit_price: convertNumber(data.unit_price)
10613
- },
10614
- {
10615
- onSuccess: () => {
10616
- setEditing(false);
10617
- },
10618
- onError: (e) => {
10619
- toast.error(e.message);
10620
- }
10621
- }
10622
- );
10623
- });
10624
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ 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: [
10625
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10626
- /* @__PURE__ */ jsx(
10627
- Thumbnail,
10628
- {
10629
- thumbnail: item.thumbnail,
10630
- alt: item.title ?? void 0
10631
- }
10632
- ),
10633
- editing ? /* @__PURE__ */ jsx(
10634
- Form$2.Field,
10635
- {
10636
- control: form.control,
10637
- name: "title",
10638
- render: ({ field }) => {
10639
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10640
- }
10641
- }
10642
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10643
- ] }),
10644
- editing ? /* @__PURE__ */ jsx(
10645
- Form$2.Field,
10646
- {
10647
- control: form.control,
10648
- name: "quantity",
10649
- render: ({ field }) => {
10650
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10651
- }
10652
- }
10653
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10654
- editing ? /* @__PURE__ */ jsx(
10655
- Form$2.Field,
10656
- {
10657
- control: form.control,
10658
- name: "unit_price",
10659
- render: ({ field: { onChange, ...field } }) => {
10660
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10661
- CurrencyInput,
10662
- {
10663
- ...field,
10664
- symbol: getNativeSymbol(currencyCode),
10665
- code: currencyCode,
10666
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10667
- }
10668
- ) }) });
10669
- }
10670
- }
10671
- ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10509
+ ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10672
10510
  /* @__PURE__ */ jsx(
10673
10511
  IconButton,
10674
10512
  {
@@ -11257,46 +11095,88 @@ function getPromotionIds(items, shippingMethods) {
11257
11095
  }
11258
11096
  return Array.from(promotionIds);
11259
11097
  }
11260
- const SalesChannel = () => {
11098
+ const InlineTip = forwardRef(
11099
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11100
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11101
+ return /* @__PURE__ */ jsxs(
11102
+ "div",
11103
+ {
11104
+ ref,
11105
+ className: clx(
11106
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11107
+ className
11108
+ ),
11109
+ ...props,
11110
+ children: [
11111
+ /* @__PURE__ */ jsx(
11112
+ "div",
11113
+ {
11114
+ role: "presentation",
11115
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11116
+ "bg-ui-tag-orange-icon": variant === "warning"
11117
+ })
11118
+ }
11119
+ ),
11120
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
11121
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11122
+ labelValue,
11123
+ ":"
11124
+ ] }),
11125
+ " ",
11126
+ children
11127
+ ] })
11128
+ ]
11129
+ }
11130
+ );
11131
+ }
11132
+ );
11133
+ InlineTip.displayName = "InlineTip";
11134
+ const MetadataFieldSchema = objectType({
11135
+ key: stringType(),
11136
+ disabled: booleanType().optional(),
11137
+ value: anyType()
11138
+ });
11139
+ const MetadataSchema = objectType({
11140
+ metadata: arrayType(MetadataFieldSchema)
11141
+ });
11142
+ const Metadata = () => {
11261
11143
  const { id } = useParams();
11262
- const { draft_order, isPending, isError, error } = useDraftOrder(
11263
- id,
11264
- {
11265
- fields: "+sales_channel_id"
11266
- },
11267
- {
11268
- enabled: !!id
11269
- }
11270
- );
11144
+ const { order, isPending, isError, error } = useOrder(id, {
11145
+ fields: "metadata"
11146
+ });
11271
11147
  if (isError) {
11272
11148
  throw error;
11273
11149
  }
11274
- const ISrEADY = !!draft_order && !isPending;
11150
+ const isReady = !isPending && !!order;
11275
11151
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11276
11152
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11277
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11278
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11153
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
11154
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11279
11155
  ] }),
11280
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11156
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11281
11157
  ] });
11282
11158
  };
11283
- const SalesChannelForm = ({ order }) => {
11159
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11160
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11161
+ const MetadataForm = ({ orderId, metadata }) => {
11162
+ const { handleSuccess } = useRouteModal();
11163
+ const hasUneditableRows = getHasUneditableRows(metadata);
11164
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11284
11165
  const form = useForm({
11285
11166
  defaultValues: {
11286
- sales_channel_id: order.sales_channel_id || ""
11167
+ metadata: getDefaultValues(metadata)
11287
11168
  },
11288
- resolver: zodResolver(schema$3)
11169
+ resolver: zodResolver(MetadataSchema)
11289
11170
  });
11290
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11291
- const { handleSuccess } = useRouteModal();
11292
- const onSubmit = form.handleSubmit(async (data) => {
11171
+ const handleSubmit = form.handleSubmit(async (data) => {
11172
+ const parsedData = parseValues(data);
11293
11173
  await mutateAsync(
11294
11174
  {
11295
- sales_channel_id: data.sales_channel_id
11175
+ metadata: parsedData
11296
11176
  },
11297
11177
  {
11298
11178
  onSuccess: () => {
11299
- toast.success("Sales channel updated");
11179
+ toast.success("Metadata updated");
11300
11180
  handleSuccess();
11301
11181
  },
11302
11182
  onError: (error) => {
@@ -11305,305 +11185,306 @@ const SalesChannelForm = ({ order }) => {
11305
11185
  }
11306
11186
  );
11307
11187
  });
11188
+ const { fields, insert, remove } = useFieldArray({
11189
+ control: form.control,
11190
+ name: "metadata"
11191
+ });
11192
+ function deleteRow(index) {
11193
+ remove(index);
11194
+ if (fields.length === 1) {
11195
+ insert(0, {
11196
+ key: "",
11197
+ value: "",
11198
+ disabled: false
11199
+ });
11200
+ }
11201
+ }
11202
+ function insertRow(index, position) {
11203
+ insert(index + (position === "above" ? 0 : 1), {
11204
+ key: "",
11205
+ value: "",
11206
+ disabled: false
11207
+ });
11208
+ }
11308
11209
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11309
11210
  KeyboundForm,
11310
11211
  {
11212
+ onSubmit: handleSubmit,
11311
11213
  className: "flex flex-1 flex-col overflow-hidden",
11312
- onSubmit,
11313
11214
  children: [
11314
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11315
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11316
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11317
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11318
- ] }) })
11319
- ]
11320
- }
11321
- ) });
11322
- };
11323
- const SalesChannelField = ({ control, order }) => {
11324
- const salesChannels = useComboboxData({
11325
- queryFn: async (params) => {
11326
- return await sdk.admin.salesChannel.list(params);
11327
- },
11328
- queryKey: ["sales-channels"],
11329
- getOptions: (data) => {
11330
- return data.sales_channels.map((salesChannel) => ({
11331
- label: salesChannel.name,
11332
- value: salesChannel.id
11333
- }));
11334
- },
11335
- defaultValue: order.sales_channel_id || void 0
11336
- });
11215
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11216
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11217
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11218
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
11219
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11220
+ ] }),
11221
+ fields.map((field, index) => {
11222
+ const isDisabled = field.disabled || false;
11223
+ let placeholder = "-";
11224
+ if (typeof field.value === "object") {
11225
+ placeholder = "{ ... }";
11226
+ }
11227
+ if (Array.isArray(field.value)) {
11228
+ placeholder = "[ ... ]";
11229
+ }
11230
+ return /* @__PURE__ */ jsx(
11231
+ ConditionalTooltip,
11232
+ {
11233
+ showTooltip: isDisabled,
11234
+ content: "This row is disabled because it contains non-primitive data.",
11235
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
11236
+ /* @__PURE__ */ jsxs(
11237
+ "div",
11238
+ {
11239
+ className: clx("grid grid-cols-2 divide-x", {
11240
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11241
+ }),
11242
+ children: [
11243
+ /* @__PURE__ */ jsx(
11244
+ Form$2.Field,
11245
+ {
11246
+ control: form.control,
11247
+ name: `metadata.${index}.key`,
11248
+ render: ({ field: field2 }) => {
11249
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11250
+ GridInput,
11251
+ {
11252
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11253
+ ...field2,
11254
+ disabled: isDisabled,
11255
+ placeholder: "Key"
11256
+ }
11257
+ ) }) });
11258
+ }
11259
+ }
11260
+ ),
11261
+ /* @__PURE__ */ jsx(
11262
+ Form$2.Field,
11263
+ {
11264
+ control: form.control,
11265
+ name: `metadata.${index}.value`,
11266
+ render: ({ field: { value, ...field2 } }) => {
11267
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11268
+ GridInput,
11269
+ {
11270
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11271
+ ...field2,
11272
+ value: isDisabled ? placeholder : value,
11273
+ disabled: isDisabled,
11274
+ placeholder: "Value"
11275
+ }
11276
+ ) }) });
11277
+ }
11278
+ }
11279
+ )
11280
+ ]
11281
+ }
11282
+ ),
11283
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11284
+ /* @__PURE__ */ jsx(
11285
+ DropdownMenu.Trigger,
11286
+ {
11287
+ className: clx(
11288
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11289
+ {
11290
+ hidden: isDisabled
11291
+ }
11292
+ ),
11293
+ disabled: isDisabled,
11294
+ asChild: true,
11295
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11296
+ }
11297
+ ),
11298
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11299
+ /* @__PURE__ */ jsxs(
11300
+ DropdownMenu.Item,
11301
+ {
11302
+ className: "gap-x-2",
11303
+ onClick: () => insertRow(index, "above"),
11304
+ children: [
11305
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11306
+ "Insert row above"
11307
+ ]
11308
+ }
11309
+ ),
11310
+ /* @__PURE__ */ jsxs(
11311
+ DropdownMenu.Item,
11312
+ {
11313
+ className: "gap-x-2",
11314
+ onClick: () => insertRow(index, "below"),
11315
+ children: [
11316
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11317
+ "Insert row below"
11318
+ ]
11319
+ }
11320
+ ),
11321
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11322
+ /* @__PURE__ */ jsxs(
11323
+ DropdownMenu.Item,
11324
+ {
11325
+ className: "gap-x-2",
11326
+ onClick: () => deleteRow(index),
11327
+ children: [
11328
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11329
+ "Delete row"
11330
+ ]
11331
+ }
11332
+ )
11333
+ ] })
11334
+ ] })
11335
+ ] })
11336
+ },
11337
+ field.id
11338
+ );
11339
+ })
11340
+ ] }),
11341
+ hasUneditableRows && /* @__PURE__ */ 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." })
11342
+ ] }),
11343
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11344
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11345
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11346
+ ] }) })
11347
+ ]
11348
+ }
11349
+ ) });
11350
+ };
11351
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11337
11352
  return /* @__PURE__ */ jsx(
11338
- Form$2.Field,
11353
+ "input",
11339
11354
  {
11340
- control,
11341
- name: "sales_channel_id",
11342
- render: ({ field }) => {
11343
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11344
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11345
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11346
- Combobox,
11347
- {
11348
- options: salesChannels.options,
11349
- fetchNextPage: salesChannels.fetchNextPage,
11350
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11351
- searchValue: salesChannels.searchValue,
11352
- onSearchValueChange: salesChannels.onSearchValueChange,
11353
- placeholder: "Select sales channel",
11354
- ...field
11355
- }
11356
- ) }),
11357
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11358
- ] });
11359
- }
11355
+ ref,
11356
+ ...props,
11357
+ autoComplete: "off",
11358
+ className: clx(
11359
+ "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",
11360
+ className
11361
+ )
11360
11362
  }
11361
11363
  );
11362
- };
11363
- const schema$3 = objectType({
11364
- sales_channel_id: stringType().min(1)
11365
11364
  });
11366
- const ShippingAddress = () => {
11367
- const { id } = useParams();
11368
- const { order, isPending, isError, error } = useOrder(id, {
11369
- fields: "+shipping_address"
11370
- });
11371
- if (isError) {
11372
- throw error;
11373
- }
11374
- const isReady = !isPending && !!order;
11375
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11376
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11377
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11378
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11379
- ] }),
11380
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11365
+ GridInput.displayName = "MetadataForm.GridInput";
11366
+ const PlaceholderInner = () => {
11367
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11368
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11369
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11370
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11371
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11372
+ ] }) })
11381
11373
  ] });
11382
11374
  };
11383
- const ShippingAddressForm = ({ order }) => {
11384
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11385
- const form = useForm({
11386
- defaultValues: {
11387
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11388
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11389
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11390
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11391
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11392
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11393
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11394
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11395
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11396
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11397
- },
11398
- resolver: zodResolver(schema$2)
11399
- });
11400
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11401
- const { handleSuccess } = useRouteModal();
11402
- const onSubmit = form.handleSubmit(async (data) => {
11403
- await mutateAsync(
11404
- {
11405
- shipping_address: {
11406
- first_name: data.first_name,
11407
- last_name: data.last_name,
11408
- company: data.company,
11409
- address_1: data.address_1,
11410
- address_2: data.address_2,
11411
- city: data.city,
11412
- province: data.province,
11413
- country_code: data.country_code,
11414
- postal_code: data.postal_code,
11415
- phone: data.phone
11416
- }
11417
- },
11375
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11376
+ function getDefaultValues(metadata) {
11377
+ if (!metadata || !Object.keys(metadata).length) {
11378
+ return [
11418
11379
  {
11419
- onSuccess: () => {
11420
- handleSuccess();
11421
- },
11422
- onError: (error) => {
11423
- toast.error(error.message);
11424
- }
11380
+ key: "",
11381
+ value: "",
11382
+ disabled: false
11383
+ }
11384
+ ];
11385
+ }
11386
+ return Object.entries(metadata).map(([key, value]) => {
11387
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11388
+ return {
11389
+ key,
11390
+ value,
11391
+ disabled: true
11392
+ };
11393
+ }
11394
+ let stringValue = value;
11395
+ if (typeof value !== "string") {
11396
+ stringValue = JSON.stringify(value);
11397
+ }
11398
+ return {
11399
+ key,
11400
+ value: stringValue,
11401
+ original_key: key
11402
+ };
11403
+ });
11404
+ }
11405
+ function parseValues(values) {
11406
+ const metadata = values.metadata;
11407
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11408
+ if (isEmpty) {
11409
+ return null;
11410
+ }
11411
+ const update = {};
11412
+ metadata.forEach((field) => {
11413
+ let key = field.key;
11414
+ let value = field.value;
11415
+ const disabled = field.disabled;
11416
+ if (!key || !value) {
11417
+ return;
11418
+ }
11419
+ if (disabled) {
11420
+ update[key] = value;
11421
+ return;
11422
+ }
11423
+ key = key.trim();
11424
+ value = value.trim();
11425
+ if (value === "true") {
11426
+ update[key] = true;
11427
+ } else if (value === "false") {
11428
+ update[key] = false;
11429
+ } else {
11430
+ const parsedNumber = parseFloat(value);
11431
+ if (!isNaN(parsedNumber)) {
11432
+ update[key] = parsedNumber;
11433
+ } else {
11434
+ update[key] = value;
11425
11435
  }
11426
- );
11427
- });
11428
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11429
- KeyboundForm,
11430
- {
11431
- className: "flex flex-1 flex-col overflow-hidden",
11432
- onSubmit,
11433
- children: [
11434
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11435
- /* @__PURE__ */ jsx(
11436
- Form$2.Field,
11437
- {
11438
- control: form.control,
11439
- name: "country_code",
11440
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11441
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11442
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11443
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11444
- ] })
11445
- }
11446
- ),
11447
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11448
- /* @__PURE__ */ jsx(
11449
- Form$2.Field,
11450
- {
11451
- control: form.control,
11452
- name: "first_name",
11453
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11454
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11455
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11456
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11457
- ] })
11458
- }
11459
- ),
11460
- /* @__PURE__ */ jsx(
11461
- Form$2.Field,
11462
- {
11463
- control: form.control,
11464
- name: "last_name",
11465
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11466
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11467
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11468
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11469
- ] })
11470
- }
11471
- )
11472
- ] }),
11473
- /* @__PURE__ */ jsx(
11474
- Form$2.Field,
11475
- {
11476
- control: form.control,
11477
- name: "company",
11478
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11479
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11480
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11481
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11482
- ] })
11483
- }
11484
- ),
11485
- /* @__PURE__ */ jsx(
11486
- Form$2.Field,
11487
- {
11488
- control: form.control,
11489
- name: "address_1",
11490
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11491
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11492
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11493
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11494
- ] })
11495
- }
11496
- ),
11497
- /* @__PURE__ */ jsx(
11498
- Form$2.Field,
11499
- {
11500
- control: form.control,
11501
- name: "address_2",
11502
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11503
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11504
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11505
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11506
- ] })
11507
- }
11508
- ),
11509
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11510
- /* @__PURE__ */ jsx(
11511
- Form$2.Field,
11512
- {
11513
- control: form.control,
11514
- name: "postal_code",
11515
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11516
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11517
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11518
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11519
- ] })
11520
- }
11521
- ),
11522
- /* @__PURE__ */ jsx(
11523
- Form$2.Field,
11524
- {
11525
- control: form.control,
11526
- name: "city",
11527
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11528
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11529
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11530
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11531
- ] })
11532
- }
11533
- )
11534
- ] }),
11535
- /* @__PURE__ */ jsx(
11536
- Form$2.Field,
11537
- {
11538
- control: form.control,
11539
- name: "province",
11540
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11541
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11542
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11543
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11544
- ] })
11545
- }
11546
- ),
11547
- /* @__PURE__ */ jsx(
11548
- Form$2.Field,
11549
- {
11550
- control: form.control,
11551
- name: "phone",
11552
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11553
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11554
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11555
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11556
- ] })
11557
- }
11558
- )
11559
- ] }) }),
11560
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11561
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11562
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11563
- ] }) })
11564
- ]
11565
11436
  }
11566
- ) });
11567
- };
11568
- const schema$2 = addressSchema;
11569
- const TransferOwnership = () => {
11570
- const { id } = useParams();
11571
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11572
- fields: "id,customer_id,customer.*"
11573
11437
  });
11438
+ return update;
11439
+ }
11440
+ function getHasUneditableRows(metadata) {
11441
+ if (!metadata) {
11442
+ return false;
11443
+ }
11444
+ return Object.values(metadata).some(
11445
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11446
+ );
11447
+ }
11448
+ const SalesChannel = () => {
11449
+ const { id } = useParams();
11450
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11451
+ id,
11452
+ {
11453
+ fields: "+sales_channel_id"
11454
+ },
11455
+ {
11456
+ enabled: !!id
11457
+ }
11458
+ );
11574
11459
  if (isError) {
11575
11460
  throw error;
11576
11461
  }
11577
- const isReady = !isPending && !!draft_order;
11462
+ const ISrEADY = !!draft_order && !isPending;
11578
11463
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11579
11464
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11580
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11581
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11465
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11582
11467
  ] }),
11583
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11468
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11584
11469
  ] });
11585
11470
  };
11586
- const TransferOwnershipForm = ({ order }) => {
11587
- var _a, _b;
11471
+ const SalesChannelForm = ({ order }) => {
11588
11472
  const form = useForm({
11589
11473
  defaultValues: {
11590
- customer_id: order.customer_id || ""
11474
+ sales_channel_id: order.sales_channel_id || ""
11591
11475
  },
11592
- resolver: zodResolver(schema$1)
11476
+ resolver: zodResolver(schema$2)
11593
11477
  });
11594
11478
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11595
11479
  const { handleSuccess } = useRouteModal();
11596
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11597
- const currentCustomer = order.customer ? {
11598
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11599
- value: order.customer.id
11600
- } : null;
11601
11480
  const onSubmit = form.handleSubmit(async (data) => {
11602
11481
  await mutateAsync(
11603
- { customer_id: data.customer_id },
11482
+ {
11483
+ sales_channel_id: data.sales_channel_id
11484
+ },
11604
11485
  {
11605
11486
  onSuccess: () => {
11606
- toast.success("Customer updated");
11487
+ toast.success("Sales channel updated");
11607
11488
  handleSuccess();
11608
11489
  },
11609
11490
  onError: (error) => {
@@ -11618,472 +11499,100 @@ const TransferOwnershipForm = ({ order }) => {
11618
11499
  className: "flex flex-1 flex-col overflow-hidden",
11619
11500
  onSubmit,
11620
11501
  children: [
11621
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11622
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11623
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11624
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11625
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11626
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11627
- ] }),
11628
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11629
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11630
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11631
- ] })
11632
- ] }),
11633
- /* @__PURE__ */ jsx(
11634
- CustomerField,
11635
- {
11636
- control: form.control,
11637
- currentCustomerId: order.customer_id
11638
- }
11639
- )
11640
- ] }),
11641
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11642
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11643
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11502
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11503
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11504
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11505
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11644
11506
  ] }) })
11645
11507
  ]
11646
11508
  }
11647
11509
  ) });
11648
11510
  };
11649
- const CustomerField = ({ control, currentCustomerId }) => {
11650
- const customers = useComboboxData({
11511
+ const SalesChannelField = ({ control, order }) => {
11512
+ const salesChannels = useComboboxData({
11651
11513
  queryFn: async (params) => {
11652
- return await sdk.admin.customer.list({
11653
- ...params,
11654
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11655
- });
11514
+ return await sdk.admin.salesChannel.list(params);
11656
11515
  },
11657
- queryKey: ["customers"],
11516
+ queryKey: ["sales-channels"],
11658
11517
  getOptions: (data) => {
11659
- return data.customers.map((customer) => {
11660
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11661
- return {
11662
- label: name ? `${name} (${customer.email})` : customer.email,
11663
- value: customer.id
11664
- };
11665
- });
11666
- }
11518
+ return data.sales_channels.map((salesChannel) => ({
11519
+ label: salesChannel.name,
11520
+ value: salesChannel.id
11521
+ }));
11522
+ },
11523
+ defaultValue: order.sales_channel_id || void 0
11667
11524
  });
11668
11525
  return /* @__PURE__ */ jsx(
11669
11526
  Form$2.Field,
11670
11527
  {
11671
- name: "customer_id",
11672
11528
  control,
11673
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11674
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11675
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11676
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11677
- ] }),
11678
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11679
- Combobox,
11680
- {
11681
- options: customers.options,
11682
- fetchNextPage: customers.fetchNextPage,
11683
- isFetchingNextPage: customers.isFetchingNextPage,
11684
- searchValue: customers.searchValue,
11685
- onSearchValueChange: customers.onSearchValueChange,
11686
- placeholder: "Select customer",
11687
- ...field
11688
- }
11689
- ) }),
11690
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11691
- ] })
11529
+ name: "sales_channel_id",
11530
+ render: ({ field }) => {
11531
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11532
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11533
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11534
+ Combobox,
11535
+ {
11536
+ options: salesChannels.options,
11537
+ fetchNextPage: salesChannels.fetchNextPage,
11538
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11539
+ searchValue: salesChannels.searchValue,
11540
+ onSearchValueChange: salesChannels.onSearchValueChange,
11541
+ placeholder: "Select sales channel",
11542
+ ...field
11543
+ }
11544
+ ) }),
11545
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11546
+ ] });
11547
+ }
11692
11548
  }
11693
11549
  );
11694
11550
  };
11695
- const Illustration = () => {
11696
- return /* @__PURE__ */ jsxs(
11697
- "svg",
11698
- {
11699
- width: "280",
11700
- height: "180",
11701
- viewBox: "0 0 280 180",
11702
- fill: "none",
11703
- xmlns: "http://www.w3.org/2000/svg",
11704
- children: [
11705
- /* @__PURE__ */ jsx(
11706
- "rect",
11707
- {
11708
- x: "0.00428286",
11709
- y: "-0.742904",
11710
- width: "33.5",
11711
- height: "65.5",
11712
- rx: "6.75",
11713
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11714
- fill: "#D4D4D8",
11715
- stroke: "#52525B",
11716
- strokeWidth: "1.5"
11717
- }
11718
- ),
11719
- /* @__PURE__ */ jsx(
11720
- "rect",
11721
- {
11722
- x: "0.00428286",
11723
- y: "-0.742904",
11724
- width: "33.5",
11725
- height: "65.5",
11726
- rx: "6.75",
11727
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11728
- fill: "white",
11729
- stroke: "#52525B",
11730
- strokeWidth: "1.5"
11731
- }
11732
- ),
11733
- /* @__PURE__ */ jsx(
11734
- "path",
11735
- {
11736
- d: "M180.579 107.142L179.126 107.959",
11737
- stroke: "#52525B",
11738
- strokeWidth: "1.5",
11739
- strokeLinecap: "round",
11740
- strokeLinejoin: "round"
11741
- }
11742
- ),
11743
- /* @__PURE__ */ jsx(
11744
- "path",
11745
- {
11746
- opacity: "0.88",
11747
- d: "M182.305 109.546L180.257 109.534",
11748
- stroke: "#52525B",
11749
- strokeWidth: "1.5",
11750
- strokeLinecap: "round",
11751
- strokeLinejoin: "round"
11752
- }
11753
- ),
11754
- /* @__PURE__ */ jsx(
11755
- "path",
11756
- {
11757
- opacity: "0.75",
11758
- d: "M180.551 111.93L179.108 111.096",
11759
- stroke: "#52525B",
11760
- strokeWidth: "1.5",
11761
- strokeLinecap: "round",
11762
- strokeLinejoin: "round"
11763
- }
11764
- ),
11765
- /* @__PURE__ */ jsx(
11766
- "path",
11767
- {
11768
- opacity: "0.63",
11769
- d: "M176.347 112.897L176.354 111.73",
11770
- stroke: "#52525B",
11771
- strokeWidth: "1.5",
11772
- strokeLinecap: "round",
11773
- strokeLinejoin: "round"
11774
- }
11775
- ),
11776
- /* @__PURE__ */ jsx(
11777
- "path",
11778
- {
11779
- opacity: "0.5",
11780
- d: "M172.153 111.881L173.606 111.064",
11781
- stroke: "#52525B",
11782
- strokeWidth: "1.5",
11783
- strokeLinecap: "round",
11784
- strokeLinejoin: "round"
11785
- }
11786
- ),
11787
- /* @__PURE__ */ jsx(
11788
- "path",
11789
- {
11790
- opacity: "0.38",
11791
- d: "M170.428 109.478L172.476 109.489",
11792
- stroke: "#52525B",
11793
- strokeWidth: "1.5",
11794
- strokeLinecap: "round",
11795
- strokeLinejoin: "round"
11796
- }
11797
- ),
11798
- /* @__PURE__ */ jsx(
11799
- "path",
11800
- {
11801
- opacity: "0.25",
11802
- d: "M172.181 107.094L173.624 107.928",
11803
- stroke: "#52525B",
11804
- strokeWidth: "1.5",
11805
- strokeLinecap: "round",
11806
- strokeLinejoin: "round"
11807
- }
11808
- ),
11809
- /* @__PURE__ */ jsx(
11810
- "path",
11811
- {
11812
- opacity: "0.13",
11813
- d: "M176.386 106.126L176.379 107.294",
11814
- stroke: "#52525B",
11815
- strokeWidth: "1.5",
11816
- strokeLinecap: "round",
11817
- strokeLinejoin: "round"
11818
- }
11819
- ),
11820
- /* @__PURE__ */ jsx(
11821
- "rect",
11822
- {
11823
- width: "12",
11824
- height: "3",
11825
- rx: "1.5",
11826
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11827
- fill: "#D4D4D8"
11828
- }
11829
- ),
11830
- /* @__PURE__ */ jsx(
11831
- "rect",
11832
- {
11833
- x: "0.00428286",
11834
- y: "-0.742904",
11835
- width: "33.5",
11836
- height: "65.5",
11837
- rx: "6.75",
11838
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11839
- fill: "#D4D4D8",
11840
- stroke: "#52525B",
11841
- strokeWidth: "1.5"
11842
- }
11843
- ),
11844
- /* @__PURE__ */ jsx(
11845
- "rect",
11846
- {
11847
- x: "0.00428286",
11848
- y: "-0.742904",
11849
- width: "33.5",
11850
- height: "65.5",
11851
- rx: "6.75",
11852
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11853
- fill: "white",
11854
- stroke: "#52525B",
11855
- strokeWidth: "1.5"
11856
- }
11857
- ),
11858
- /* @__PURE__ */ jsx(
11859
- "rect",
11860
- {
11861
- width: "12",
11862
- height: "3",
11863
- rx: "1.5",
11864
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11865
- fill: "#D4D4D8"
11866
- }
11867
- ),
11868
- /* @__PURE__ */ jsx(
11869
- "rect",
11870
- {
11871
- width: "17",
11872
- height: "3",
11873
- rx: "1.5",
11874
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11875
- fill: "#D4D4D8"
11876
- }
11877
- ),
11878
- /* @__PURE__ */ jsx(
11879
- "rect",
11880
- {
11881
- width: "12",
11882
- height: "3",
11883
- rx: "1.5",
11884
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11885
- fill: "#D4D4D8"
11886
- }
11887
- ),
11888
- /* @__PURE__ */ jsx(
11889
- "path",
11890
- {
11891
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11892
- fill: "#A1A1AA"
11893
- }
11894
- ),
11895
- /* @__PURE__ */ jsx(
11896
- "rect",
11897
- {
11898
- width: "17",
11899
- height: "3",
11900
- rx: "1.5",
11901
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11902
- fill: "#A1A1AA"
11903
- }
11904
- ),
11905
- /* @__PURE__ */ jsx(
11906
- "rect",
11907
- {
11908
- width: "12",
11909
- height: "3",
11910
- rx: "1.5",
11911
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11912
- fill: "#A1A1AA"
11913
- }
11914
- ),
11915
- /* @__PURE__ */ jsx(
11916
- "path",
11917
- {
11918
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11919
- fill: "#52525B"
11920
- }
11921
- ),
11922
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
11923
- "path",
11924
- {
11925
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11926
- stroke: "#A1A1AA",
11927
- strokeWidth: "1.5",
11928
- strokeLinecap: "round",
11929
- strokeLinejoin: "round"
11930
- }
11931
- ) }),
11932
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
11933
- "path",
11934
- {
11935
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11936
- stroke: "#A1A1AA",
11937
- strokeWidth: "1.5",
11938
- strokeLinecap: "round",
11939
- strokeLinejoin: "round"
11940
- }
11941
- ) }),
11942
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
11943
- "path",
11944
- {
11945
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11946
- stroke: "#A1A1AA",
11947
- strokeWidth: "1.5",
11948
- strokeLinecap: "round",
11949
- strokeLinejoin: "round"
11950
- }
11951
- ) }),
11952
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
11953
- "path",
11954
- {
11955
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11956
- stroke: "#A1A1AA",
11957
- strokeWidth: "1.5",
11958
- strokeLinecap: "round",
11959
- strokeLinejoin: "round"
11960
- }
11961
- ) }),
11962
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
11963
- "path",
11964
- {
11965
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11966
- stroke: "#A1A1AA",
11967
- strokeWidth: "1.5",
11968
- strokeLinecap: "round",
11969
- strokeLinejoin: "round"
11970
- }
11971
- ) }),
11972
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
11973
- "path",
11974
- {
11975
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11976
- stroke: "#A1A1AA",
11977
- strokeWidth: "1.5",
11978
- strokeLinecap: "round",
11979
- strokeLinejoin: "round"
11980
- }
11981
- ) }),
11982
- /* @__PURE__ */ jsxs("defs", { children: [
11983
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
11984
- "rect",
11985
- {
11986
- width: "12",
11987
- height: "12",
11988
- fill: "white",
11989
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11990
- }
11991
- ) }),
11992
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
11993
- "rect",
11994
- {
11995
- width: "12",
11996
- height: "12",
11997
- fill: "white",
11998
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11999
- }
12000
- ) }),
12001
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12002
- "rect",
12003
- {
12004
- width: "12",
12005
- height: "12",
12006
- fill: "white",
12007
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12008
- }
12009
- ) }),
12010
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12011
- "rect",
12012
- {
12013
- width: "12",
12014
- height: "12",
12015
- fill: "white",
12016
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12017
- }
12018
- ) }),
12019
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12020
- "rect",
12021
- {
12022
- width: "12",
12023
- height: "12",
12024
- fill: "white",
12025
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12026
- }
12027
- ) }),
12028
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12029
- "rect",
12030
- {
12031
- width: "12",
12032
- height: "12",
12033
- fill: "white",
12034
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12035
- }
12036
- ) })
12037
- ] })
12038
- ]
12039
- }
12040
- );
12041
- };
12042
- const schema$1 = objectType({
12043
- customer_id: stringType().min(1)
12044
- });
12045
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12046
- const Shipping = () => {
12047
- var _a;
12048
- const { id } = useParams();
12049
- const { order, isPending, isError, error } = useOrder(id, {
12050
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12051
- });
12052
- const {
12053
- order: preview,
12054
- isPending: isPreviewPending,
12055
- isError: isPreviewError,
12056
- error: previewError
12057
- } = useOrderPreview(id);
12058
- useInitiateOrderEdit({ preview });
12059
- const { onCancel } = useCancelOrderEdit({ preview });
12060
- if (isError) {
12061
- throw error;
12062
- }
12063
- if (isPreviewError) {
12064
- throw previewError;
12065
- }
12066
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12067
- const isReady = preview && !isPreviewPending && order && !isPending;
12068
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12069
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12070
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12071
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12072
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12073
- ] }) }) }),
12074
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12075
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
12076
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12077
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12078
- ] }) });
12079
- };
12080
- const ShippingForm = ({ preview, order }) => {
12081
- var _a;
12082
- const { setIsOpen } = useStackedModal();
12083
- const [isSubmitting, setIsSubmitting] = useState(false);
12084
- const [data, setData] = useState(null);
12085
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12086
- const { shipping_options } = useShippingOptions(
11551
+ const schema$2 = objectType({
11552
+ sales_channel_id: stringType().min(1)
11553
+ });
11554
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11555
+ const Shipping = () => {
11556
+ var _a;
11557
+ const { id } = useParams();
11558
+ const { order, isPending, isError, error } = useOrder(id, {
11559
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11560
+ });
11561
+ const {
11562
+ order: preview,
11563
+ isPending: isPreviewPending,
11564
+ isError: isPreviewError,
11565
+ error: previewError
11566
+ } = useOrderPreview(id);
11567
+ useInitiateOrderEdit({ preview });
11568
+ const { onCancel } = useCancelOrderEdit({ preview });
11569
+ if (isError) {
11570
+ throw error;
11571
+ }
11572
+ if (isPreviewError) {
11573
+ throw previewError;
11574
+ }
11575
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11576
+ const isReady = preview && !isPreviewPending && order && !isPending;
11577
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11578
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11579
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11580
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11581
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11582
+ ] }) }) }),
11583
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11584
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11585
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11586
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11587
+ ] }) });
11588
+ };
11589
+ const ShippingForm = ({ preview, order }) => {
11590
+ var _a;
11591
+ const { setIsOpen } = useStackedModal();
11592
+ const [isSubmitting, setIsSubmitting] = useState(false);
11593
+ const [data, setData] = useState(null);
11594
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11595
+ const { shipping_options } = useShippingOptions(
12087
11596
  {
12088
11597
  id: appliedShippingOptionIds,
12089
11598
  fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
@@ -12849,10 +12358,10 @@ const CustomAmountField = ({
12849
12358
  }
12850
12359
  );
12851
12360
  };
12852
- const BillingAddress = () => {
12361
+ const ShippingAddress = () => {
12853
12362
  const { id } = useParams();
12854
12363
  const { order, isPending, isError, error } = useOrder(id, {
12855
- fields: "+billing_address"
12364
+ fields: "+shipping_address"
12856
12365
  });
12857
12366
  if (isError) {
12858
12367
  throw error;
@@ -12860,34 +12369,47 @@ const BillingAddress = () => {
12860
12369
  const isReady = !isPending && !!order;
12861
12370
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
12371
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12863
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12372
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12373
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12865
12374
  ] }),
12866
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12375
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12867
12376
  ] });
12868
12377
  };
12869
- const BillingAddressForm = ({ order }) => {
12378
+ const ShippingAddressForm = ({ order }) => {
12870
12379
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12871
12380
  const form = useForm({
12872
12381
  defaultValues: {
12873
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12382
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12383
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12384
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12385
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12386
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12387
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12388
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12389
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12390
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12883
12392
  },
12884
- resolver: zodResolver(schema)
12393
+ resolver: zodResolver(schema$1)
12885
12394
  });
12886
12395
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
12396
  const { handleSuccess } = useRouteModal();
12888
12397
  const onSubmit = form.handleSubmit(async (data) => {
12889
12398
  await mutateAsync(
12890
- { billing_address: data },
12399
+ {
12400
+ shipping_address: {
12401
+ first_name: data.first_name,
12402
+ last_name: data.last_name,
12403
+ company: data.company,
12404
+ address_1: data.address_1,
12405
+ address_2: data.address_2,
12406
+ city: data.city,
12407
+ province: data.province,
12408
+ country_code: data.country_code,
12409
+ postal_code: data.postal_code,
12410
+ phone: data.phone
12411
+ }
12412
+ },
12891
12413
  {
12892
12414
  onSuccess: () => {
12893
12415
  handleSuccess();
@@ -12908,137 +12430,613 @@ const BillingAddressForm = ({ order }) => {
12908
12430
  /* @__PURE__ */ jsx(
12909
12431
  Form$2.Field,
12910
12432
  {
12911
- control: form.control,
12912
- name: "country_code",
12913
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
- ] })
12433
+ control: form.control,
12434
+ name: "country_code",
12435
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12436
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12437
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12438
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12439
+ ] })
12440
+ }
12441
+ ),
12442
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12443
+ /* @__PURE__ */ jsx(
12444
+ Form$2.Field,
12445
+ {
12446
+ control: form.control,
12447
+ name: "first_name",
12448
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12449
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12450
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12451
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12452
+ ] })
12453
+ }
12454
+ ),
12455
+ /* @__PURE__ */ jsx(
12456
+ Form$2.Field,
12457
+ {
12458
+ control: form.control,
12459
+ name: "last_name",
12460
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12461
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12462
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12463
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12464
+ ] })
12465
+ }
12466
+ )
12467
+ ] }),
12468
+ /* @__PURE__ */ jsx(
12469
+ Form$2.Field,
12470
+ {
12471
+ control: form.control,
12472
+ name: "company",
12473
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12474
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12475
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12476
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12477
+ ] })
12478
+ }
12479
+ ),
12480
+ /* @__PURE__ */ jsx(
12481
+ Form$2.Field,
12482
+ {
12483
+ control: form.control,
12484
+ name: "address_1",
12485
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12486
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12487
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12488
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12489
+ ] })
12490
+ }
12491
+ ),
12492
+ /* @__PURE__ */ jsx(
12493
+ Form$2.Field,
12494
+ {
12495
+ control: form.control,
12496
+ name: "address_2",
12497
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12498
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12499
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12500
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12501
+ ] })
12502
+ }
12503
+ ),
12504
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12505
+ /* @__PURE__ */ jsx(
12506
+ Form$2.Field,
12507
+ {
12508
+ control: form.control,
12509
+ name: "postal_code",
12510
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12511
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12512
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12513
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12514
+ ] })
12515
+ }
12516
+ ),
12517
+ /* @__PURE__ */ jsx(
12518
+ Form$2.Field,
12519
+ {
12520
+ control: form.control,
12521
+ name: "city",
12522
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12523
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12524
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12525
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12526
+ ] })
12527
+ }
12528
+ )
12529
+ ] }),
12530
+ /* @__PURE__ */ jsx(
12531
+ Form$2.Field,
12532
+ {
12533
+ control: form.control,
12534
+ name: "province",
12535
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12536
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12537
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12538
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12539
+ ] })
12540
+ }
12541
+ ),
12542
+ /* @__PURE__ */ jsx(
12543
+ Form$2.Field,
12544
+ {
12545
+ control: form.control,
12546
+ name: "phone",
12547
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12548
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12549
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12550
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12551
+ ] })
12552
+ }
12553
+ )
12554
+ ] }) }),
12555
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12556
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12557
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12558
+ ] }) })
12559
+ ]
12560
+ }
12561
+ ) });
12562
+ };
12563
+ const schema$1 = addressSchema;
12564
+ const TransferOwnership = () => {
12565
+ const { id } = useParams();
12566
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12567
+ fields: "id,customer_id,customer.*"
12568
+ });
12569
+ if (isError) {
12570
+ throw error;
12571
+ }
12572
+ const isReady = !isPending && !!draft_order;
12573
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12574
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12575
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12576
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12577
+ ] }),
12578
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12579
+ ] });
12580
+ };
12581
+ const TransferOwnershipForm = ({ order }) => {
12582
+ var _a, _b;
12583
+ const form = useForm({
12584
+ defaultValues: {
12585
+ customer_id: order.customer_id || ""
12586
+ },
12587
+ resolver: zodResolver(schema)
12588
+ });
12589
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
+ const { handleSuccess } = useRouteModal();
12591
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12592
+ const currentCustomer = order.customer ? {
12593
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12594
+ value: order.customer.id
12595
+ } : null;
12596
+ const onSubmit = form.handleSubmit(async (data) => {
12597
+ await mutateAsync(
12598
+ { customer_id: data.customer_id },
12599
+ {
12600
+ onSuccess: () => {
12601
+ toast.success("Customer updated");
12602
+ handleSuccess();
12603
+ },
12604
+ onError: (error) => {
12605
+ toast.error(error.message);
12606
+ }
12607
+ }
12608
+ );
12609
+ });
12610
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12611
+ KeyboundForm,
12612
+ {
12613
+ className: "flex flex-1 flex-col overflow-hidden",
12614
+ onSubmit,
12615
+ children: [
12616
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12617
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12618
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12619
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12620
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12621
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12622
+ ] }),
12623
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12624
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12625
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12626
+ ] })
12627
+ ] }),
12628
+ /* @__PURE__ */ jsx(
12629
+ CustomerField,
12630
+ {
12631
+ control: form.control,
12632
+ currentCustomerId: order.customer_id
12633
+ }
12634
+ )
12635
+ ] }),
12636
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12637
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12638
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12639
+ ] }) })
12640
+ ]
12641
+ }
12642
+ ) });
12643
+ };
12644
+ const CustomerField = ({ control, currentCustomerId }) => {
12645
+ const customers = useComboboxData({
12646
+ queryFn: async (params) => {
12647
+ return await sdk.admin.customer.list({
12648
+ ...params,
12649
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12650
+ });
12651
+ },
12652
+ queryKey: ["customers"],
12653
+ getOptions: (data) => {
12654
+ return data.customers.map((customer) => {
12655
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12656
+ return {
12657
+ label: name ? `${name} (${customer.email})` : customer.email,
12658
+ value: customer.id
12659
+ };
12660
+ });
12661
+ }
12662
+ });
12663
+ return /* @__PURE__ */ jsx(
12664
+ Form$2.Field,
12665
+ {
12666
+ name: "customer_id",
12667
+ control,
12668
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12669
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12670
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12671
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12672
+ ] }),
12673
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12674
+ Combobox,
12675
+ {
12676
+ options: customers.options,
12677
+ fetchNextPage: customers.fetchNextPage,
12678
+ isFetchingNextPage: customers.isFetchingNextPage,
12679
+ searchValue: customers.searchValue,
12680
+ onSearchValueChange: customers.onSearchValueChange,
12681
+ placeholder: "Select customer",
12682
+ ...field
12683
+ }
12684
+ ) }),
12685
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12686
+ ] })
12687
+ }
12688
+ );
12689
+ };
12690
+ const Illustration = () => {
12691
+ return /* @__PURE__ */ jsxs(
12692
+ "svg",
12693
+ {
12694
+ width: "280",
12695
+ height: "180",
12696
+ viewBox: "0 0 280 180",
12697
+ fill: "none",
12698
+ xmlns: "http://www.w3.org/2000/svg",
12699
+ children: [
12700
+ /* @__PURE__ */ jsx(
12701
+ "rect",
12702
+ {
12703
+ x: "0.00428286",
12704
+ y: "-0.742904",
12705
+ width: "33.5",
12706
+ height: "65.5",
12707
+ rx: "6.75",
12708
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12709
+ fill: "#D4D4D8",
12710
+ stroke: "#52525B",
12711
+ strokeWidth: "1.5"
12712
+ }
12713
+ ),
12714
+ /* @__PURE__ */ jsx(
12715
+ "rect",
12716
+ {
12717
+ x: "0.00428286",
12718
+ y: "-0.742904",
12719
+ width: "33.5",
12720
+ height: "65.5",
12721
+ rx: "6.75",
12722
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12723
+ fill: "white",
12724
+ stroke: "#52525B",
12725
+ strokeWidth: "1.5"
12726
+ }
12727
+ ),
12728
+ /* @__PURE__ */ jsx(
12729
+ "path",
12730
+ {
12731
+ d: "M180.579 107.142L179.126 107.959",
12732
+ stroke: "#52525B",
12733
+ strokeWidth: "1.5",
12734
+ strokeLinecap: "round",
12735
+ strokeLinejoin: "round"
12736
+ }
12737
+ ),
12738
+ /* @__PURE__ */ jsx(
12739
+ "path",
12740
+ {
12741
+ opacity: "0.88",
12742
+ d: "M182.305 109.546L180.257 109.534",
12743
+ stroke: "#52525B",
12744
+ strokeWidth: "1.5",
12745
+ strokeLinecap: "round",
12746
+ strokeLinejoin: "round"
12747
+ }
12748
+ ),
12749
+ /* @__PURE__ */ jsx(
12750
+ "path",
12751
+ {
12752
+ opacity: "0.75",
12753
+ d: "M180.551 111.93L179.108 111.096",
12754
+ stroke: "#52525B",
12755
+ strokeWidth: "1.5",
12756
+ strokeLinecap: "round",
12757
+ strokeLinejoin: "round"
12758
+ }
12759
+ ),
12760
+ /* @__PURE__ */ jsx(
12761
+ "path",
12762
+ {
12763
+ opacity: "0.63",
12764
+ d: "M176.347 112.897L176.354 111.73",
12765
+ stroke: "#52525B",
12766
+ strokeWidth: "1.5",
12767
+ strokeLinecap: "round",
12768
+ strokeLinejoin: "round"
12769
+ }
12770
+ ),
12771
+ /* @__PURE__ */ jsx(
12772
+ "path",
12773
+ {
12774
+ opacity: "0.5",
12775
+ d: "M172.153 111.881L173.606 111.064",
12776
+ stroke: "#52525B",
12777
+ strokeWidth: "1.5",
12778
+ strokeLinecap: "round",
12779
+ strokeLinejoin: "round"
12780
+ }
12781
+ ),
12782
+ /* @__PURE__ */ jsx(
12783
+ "path",
12784
+ {
12785
+ opacity: "0.38",
12786
+ d: "M170.428 109.478L172.476 109.489",
12787
+ stroke: "#52525B",
12788
+ strokeWidth: "1.5",
12789
+ strokeLinecap: "round",
12790
+ strokeLinejoin: "round"
12791
+ }
12792
+ ),
12793
+ /* @__PURE__ */ jsx(
12794
+ "path",
12795
+ {
12796
+ opacity: "0.25",
12797
+ d: "M172.181 107.094L173.624 107.928",
12798
+ stroke: "#52525B",
12799
+ strokeWidth: "1.5",
12800
+ strokeLinecap: "round",
12801
+ strokeLinejoin: "round"
12802
+ }
12803
+ ),
12804
+ /* @__PURE__ */ jsx(
12805
+ "path",
12806
+ {
12807
+ opacity: "0.13",
12808
+ d: "M176.386 106.126L176.379 107.294",
12809
+ stroke: "#52525B",
12810
+ strokeWidth: "1.5",
12811
+ strokeLinecap: "round",
12812
+ strokeLinejoin: "round"
12813
+ }
12814
+ ),
12815
+ /* @__PURE__ */ jsx(
12816
+ "rect",
12817
+ {
12818
+ width: "12",
12819
+ height: "3",
12820
+ rx: "1.5",
12821
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12822
+ fill: "#D4D4D8"
12823
+ }
12824
+ ),
12825
+ /* @__PURE__ */ jsx(
12826
+ "rect",
12827
+ {
12828
+ x: "0.00428286",
12829
+ y: "-0.742904",
12830
+ width: "33.5",
12831
+ height: "65.5",
12832
+ rx: "6.75",
12833
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12834
+ fill: "#D4D4D8",
12835
+ stroke: "#52525B",
12836
+ strokeWidth: "1.5"
12837
+ }
12838
+ ),
12839
+ /* @__PURE__ */ jsx(
12840
+ "rect",
12841
+ {
12842
+ x: "0.00428286",
12843
+ y: "-0.742904",
12844
+ width: "33.5",
12845
+ height: "65.5",
12846
+ rx: "6.75",
12847
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12848
+ fill: "white",
12849
+ stroke: "#52525B",
12850
+ strokeWidth: "1.5"
12851
+ }
12852
+ ),
12853
+ /* @__PURE__ */ jsx(
12854
+ "rect",
12855
+ {
12856
+ width: "12",
12857
+ height: "3",
12858
+ rx: "1.5",
12859
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12860
+ fill: "#D4D4D8"
12861
+ }
12862
+ ),
12863
+ /* @__PURE__ */ jsx(
12864
+ "rect",
12865
+ {
12866
+ width: "17",
12867
+ height: "3",
12868
+ rx: "1.5",
12869
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12870
+ fill: "#D4D4D8"
12871
+ }
12872
+ ),
12873
+ /* @__PURE__ */ jsx(
12874
+ "rect",
12875
+ {
12876
+ width: "12",
12877
+ height: "3",
12878
+ rx: "1.5",
12879
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12880
+ fill: "#D4D4D8"
12881
+ }
12882
+ ),
12883
+ /* @__PURE__ */ jsx(
12884
+ "path",
12885
+ {
12886
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12887
+ fill: "#A1A1AA"
12888
+ }
12889
+ ),
12890
+ /* @__PURE__ */ jsx(
12891
+ "rect",
12892
+ {
12893
+ width: "17",
12894
+ height: "3",
12895
+ rx: "1.5",
12896
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12897
+ fill: "#A1A1AA"
12898
+ }
12899
+ ),
12900
+ /* @__PURE__ */ jsx(
12901
+ "rect",
12902
+ {
12903
+ width: "12",
12904
+ height: "3",
12905
+ rx: "1.5",
12906
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12907
+ fill: "#A1A1AA"
12908
+ }
12909
+ ),
12910
+ /* @__PURE__ */ jsx(
12911
+ "path",
12912
+ {
12913
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12914
+ fill: "#52525B"
12915
+ }
12916
+ ),
12917
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12918
+ "path",
12919
+ {
12920
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12921
+ stroke: "#A1A1AA",
12922
+ strokeWidth: "1.5",
12923
+ strokeLinecap: "round",
12924
+ strokeLinejoin: "round"
12925
+ }
12926
+ ) }),
12927
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12928
+ "path",
12929
+ {
12930
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12931
+ stroke: "#A1A1AA",
12932
+ strokeWidth: "1.5",
12933
+ strokeLinecap: "round",
12934
+ strokeLinejoin: "round"
12935
+ }
12936
+ ) }),
12937
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12938
+ "path",
12939
+ {
12940
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12941
+ stroke: "#A1A1AA",
12942
+ strokeWidth: "1.5",
12943
+ strokeLinecap: "round",
12944
+ strokeLinejoin: "round"
12945
+ }
12946
+ ) }),
12947
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12948
+ "path",
12949
+ {
12950
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12951
+ stroke: "#A1A1AA",
12952
+ strokeWidth: "1.5",
12953
+ strokeLinecap: "round",
12954
+ strokeLinejoin: "round"
12955
+ }
12956
+ ) }),
12957
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12958
+ "path",
12959
+ {
12960
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12961
+ stroke: "#A1A1AA",
12962
+ strokeWidth: "1.5",
12963
+ strokeLinecap: "round",
12964
+ strokeLinejoin: "round"
12965
+ }
12966
+ ) }),
12967
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12968
+ "path",
12969
+ {
12970
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12971
+ stroke: "#A1A1AA",
12972
+ strokeWidth: "1.5",
12973
+ strokeLinecap: "round",
12974
+ strokeLinejoin: "round"
12975
+ }
12976
+ ) }),
12977
+ /* @__PURE__ */ jsxs("defs", { children: [
12978
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12979
+ "rect",
12980
+ {
12981
+ width: "12",
12982
+ height: "12",
12983
+ fill: "white",
12984
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12918
12985
  }
12919
- ),
12920
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
- /* @__PURE__ */ jsx(
12922
- Form$2.Field,
12923
- {
12924
- control: form.control,
12925
- name: "first_name",
12926
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
- ] })
12931
- }
12932
- ),
12933
- /* @__PURE__ */ jsx(
12934
- Form$2.Field,
12935
- {
12936
- control: form.control,
12937
- name: "last_name",
12938
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
- ] })
12943
- }
12944
- )
12945
- ] }),
12946
- /* @__PURE__ */ jsx(
12947
- Form$2.Field,
12986
+ ) }),
12987
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12988
+ "rect",
12948
12989
  {
12949
- control: form.control,
12950
- name: "company",
12951
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
- ] })
12990
+ width: "12",
12991
+ height: "12",
12992
+ fill: "white",
12993
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12956
12994
  }
12957
- ),
12958
- /* @__PURE__ */ jsx(
12959
- Form$2.Field,
12995
+ ) }),
12996
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12997
+ "rect",
12960
12998
  {
12961
- control: form.control,
12962
- name: "address_1",
12963
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
- ] })
12999
+ width: "12",
13000
+ height: "12",
13001
+ fill: "white",
13002
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12968
13003
  }
12969
- ),
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
13004
+ ) }),
13005
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13006
+ "rect",
12972
13007
  {
12973
- control: form.control,
12974
- name: "address_2",
12975
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
- ] })
13008
+ width: "12",
13009
+ height: "12",
13010
+ fill: "white",
13011
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12980
13012
  }
12981
- ),
12982
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
- /* @__PURE__ */ jsx(
12984
- Form$2.Field,
12985
- {
12986
- control: form.control,
12987
- name: "postal_code",
12988
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
- ] })
12993
- }
12994
- ),
12995
- /* @__PURE__ */ jsx(
12996
- Form$2.Field,
12997
- {
12998
- control: form.control,
12999
- name: "city",
13000
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
- ] })
13005
- }
13006
- )
13007
- ] }),
13008
- /* @__PURE__ */ jsx(
13009
- Form$2.Field,
13013
+ ) }),
13014
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13015
+ "rect",
13010
13016
  {
13011
- control: form.control,
13012
- name: "province",
13013
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
- ] })
13017
+ width: "12",
13018
+ height: "12",
13019
+ fill: "white",
13020
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13018
13021
  }
13019
- ),
13020
- /* @__PURE__ */ jsx(
13021
- Form$2.Field,
13022
+ ) }),
13023
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13024
+ "rect",
13022
13025
  {
13023
- control: form.control,
13024
- name: "phone",
13025
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
- ] })
13026
+ width: "12",
13027
+ height: "12",
13028
+ fill: "white",
13029
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13030
13030
  }
13031
- )
13032
- ] }) }),
13033
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13036
- ] }) })
13031
+ ) })
13032
+ ] })
13037
13033
  ]
13038
13034
  }
13039
- ) });
13035
+ );
13040
13036
  };
13041
- const schema = addressSchema;
13037
+ const schema = objectType({
13038
+ customer_id: stringType().min(1)
13039
+ });
13042
13040
  const widgetModule = { widgets: [] };
13043
13041
  const routeModule = {
13044
13042
  routes: [
@@ -13059,6 +13057,10 @@ const routeModule = {
13059
13057
  handle,
13060
13058
  loader,
13061
13059
  children: [
13060
+ {
13061
+ Component: BillingAddress,
13062
+ path: "/draft-orders/:id/billing-address"
13063
+ },
13062
13064
  {
13063
13065
  Component: CustomItems,
13064
13066
  path: "/draft-orders/:id/custom-items"
@@ -13067,10 +13069,6 @@ const routeModule = {
13067
13069
  Component: Email,
13068
13070
  path: "/draft-orders/:id/email"
13069
13071
  },
13070
- {
13071
- Component: Metadata,
13072
- path: "/draft-orders/:id/metadata"
13073
- },
13074
13072
  {
13075
13073
  Component: Items,
13076
13074
  path: "/draft-orders/:id/items"
@@ -13079,10 +13077,18 @@ const routeModule = {
13079
13077
  Component: Promotions,
13080
13078
  path: "/draft-orders/:id/promotions"
13081
13079
  },
13080
+ {
13081
+ Component: Metadata,
13082
+ path: "/draft-orders/:id/metadata"
13083
+ },
13082
13084
  {
13083
13085
  Component: SalesChannel,
13084
13086
  path: "/draft-orders/:id/sales-channel"
13085
13087
  },
13088
+ {
13089
+ Component: Shipping,
13090
+ path: "/draft-orders/:id/shipping"
13091
+ },
13086
13092
  {
13087
13093
  Component: ShippingAddress,
13088
13094
  path: "/draft-orders/:id/shipping-address"
@@ -13090,14 +13096,6 @@ const routeModule = {
13090
13096
  {
13091
13097
  Component: TransferOwnership,
13092
13098
  path: "/draft-orders/:id/transfer-ownership"
13093
- },
13094
- {
13095
- Component: Shipping,
13096
- path: "/draft-orders/:id/shipping"
13097
- },
13098
- {
13099
- Component: BillingAddress,
13100
- path: "/draft-orders/:id/billing-address"
13101
13099
  }
13102
13100
  ]
13103
13101
  }