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

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";
@@ -9588,6 +9588,196 @@ const CustomItemsForm = () => {
9588
9588
  const schema$5 = objectType({
9589
9589
  email: stringType().email()
9590
9590
  });
9591
+ const BillingAddress = () => {
9592
+ const { id } = useParams();
9593
+ const { order, isPending, isError, error } = useOrder(id, {
9594
+ fields: "+billing_address"
9595
+ });
9596
+ if (isError) {
9597
+ throw error;
9598
+ }
9599
+ const isReady = !isPending && !!order;
9600
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9601
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9602
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9603
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9604
+ ] }),
9605
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9606
+ ] });
9607
+ };
9608
+ const BillingAddressForm = ({ order }) => {
9609
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9610
+ const form = useForm({
9611
+ defaultValues: {
9612
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9613
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9614
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9615
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9616
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9617
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9618
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9619
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9620
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9621
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9622
+ },
9623
+ resolver: zodResolver(schema$4)
9624
+ });
9625
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9626
+ const { handleSuccess } = useRouteModal();
9627
+ const onSubmit = form.handleSubmit(async (data) => {
9628
+ await mutateAsync(
9629
+ { billing_address: data },
9630
+ {
9631
+ onSuccess: () => {
9632
+ handleSuccess();
9633
+ },
9634
+ onError: (error) => {
9635
+ toast.error(error.message);
9636
+ }
9637
+ }
9638
+ );
9639
+ });
9640
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9641
+ KeyboundForm,
9642
+ {
9643
+ className: "flex flex-1 flex-col overflow-hidden",
9644
+ onSubmit,
9645
+ children: [
9646
+ /* @__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: [
9647
+ /* @__PURE__ */ jsx(
9648
+ Form$2.Field,
9649
+ {
9650
+ control: form.control,
9651
+ name: "country_code",
9652
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9653
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9654
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9655
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9656
+ ] })
9657
+ }
9658
+ ),
9659
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9660
+ /* @__PURE__ */ jsx(
9661
+ Form$2.Field,
9662
+ {
9663
+ control: form.control,
9664
+ name: "first_name",
9665
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9666
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9667
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9668
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9669
+ ] })
9670
+ }
9671
+ ),
9672
+ /* @__PURE__ */ jsx(
9673
+ Form$2.Field,
9674
+ {
9675
+ control: form.control,
9676
+ name: "last_name",
9677
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9678
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9679
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9680
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9681
+ ] })
9682
+ }
9683
+ )
9684
+ ] }),
9685
+ /* @__PURE__ */ jsx(
9686
+ Form$2.Field,
9687
+ {
9688
+ control: form.control,
9689
+ name: "company",
9690
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9691
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9692
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9693
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9694
+ ] })
9695
+ }
9696
+ ),
9697
+ /* @__PURE__ */ jsx(
9698
+ Form$2.Field,
9699
+ {
9700
+ control: form.control,
9701
+ name: "address_1",
9702
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9703
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9704
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9705
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9706
+ ] })
9707
+ }
9708
+ ),
9709
+ /* @__PURE__ */ jsx(
9710
+ Form$2.Field,
9711
+ {
9712
+ control: form.control,
9713
+ name: "address_2",
9714
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9715
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9716
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9717
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9718
+ ] })
9719
+ }
9720
+ ),
9721
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9722
+ /* @__PURE__ */ jsx(
9723
+ Form$2.Field,
9724
+ {
9725
+ control: form.control,
9726
+ name: "postal_code",
9727
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9728
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9729
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9730
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9731
+ ] })
9732
+ }
9733
+ ),
9734
+ /* @__PURE__ */ jsx(
9735
+ Form$2.Field,
9736
+ {
9737
+ control: form.control,
9738
+ name: "city",
9739
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9740
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9741
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9742
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9743
+ ] })
9744
+ }
9745
+ )
9746
+ ] }),
9747
+ /* @__PURE__ */ jsx(
9748
+ Form$2.Field,
9749
+ {
9750
+ control: form.control,
9751
+ name: "province",
9752
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9753
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9754
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9755
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9756
+ ] })
9757
+ }
9758
+ ),
9759
+ /* @__PURE__ */ jsx(
9760
+ Form$2.Field,
9761
+ {
9762
+ control: form.control,
9763
+ name: "phone",
9764
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9765
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9766
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9767
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9768
+ ] })
9769
+ }
9770
+ )
9771
+ ] }) }),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9775
+ ] }) })
9776
+ ]
9777
+ }
9778
+ ) });
9779
+ };
9780
+ const schema$4 = addressSchema;
9591
9781
  const Email = () => {
9592
9782
  const { id } = useParams();
9593
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9610,7 +9800,7 @@ const EmailForm = ({ order }) => {
9610
9800
  defaultValues: {
9611
9801
  email: order.email ?? ""
9612
9802
  },
9613
- resolver: zodResolver(schema$4)
9803
+ resolver: zodResolver(schema$3)
9614
9804
  });
9615
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9616
9806
  const { handleSuccess } = useRouteModal();
@@ -9653,887 +9843,537 @@ const EmailForm = ({ order }) => {
9653
9843
  }
9654
9844
  ) });
9655
9845
  };
9656
- const schema$4 = objectType({
9846
+ const schema$3 = objectType({
9657
9847
  email: stringType().email()
9658
9848
  });
9659
- const InlineTip = forwardRef(
9660
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9661
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9849
+ const NumberInput = forwardRef(
9850
+ ({
9851
+ value,
9852
+ onChange,
9853
+ size = "base",
9854
+ min = 0,
9855
+ max = 100,
9856
+ step = 1,
9857
+ className,
9858
+ disabled,
9859
+ ...props
9860
+ }, ref) => {
9861
+ const handleChange = (event) => {
9862
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9863
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9864
+ onChange(newValue);
9865
+ }
9866
+ };
9867
+ const handleIncrement = () => {
9868
+ const newValue = value + step;
9869
+ if (max === void 0 || newValue <= max) {
9870
+ onChange(newValue);
9871
+ }
9872
+ };
9873
+ const handleDecrement = () => {
9874
+ const newValue = value - step;
9875
+ if (min === void 0 || newValue >= min) {
9876
+ onChange(newValue);
9877
+ }
9878
+ };
9662
9879
  return /* @__PURE__ */ jsxs(
9663
9880
  "div",
9664
9881
  {
9665
- ref,
9666
9882
  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",
9883
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9884
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9885
+ {
9886
+ "h-7": size === "small",
9887
+ "h-8": size === "base"
9888
+ },
9668
9889
  className
9669
9890
  ),
9670
- ...props,
9671
9891
  children: [
9672
9892
  /* @__PURE__ */ jsx(
9673
- "div",
9893
+ "input",
9674
9894
  {
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
- })
9895
+ ref,
9896
+ type: "number",
9897
+ value,
9898
+ onChange: handleChange,
9899
+ min,
9900
+ max,
9901
+ step,
9902
+ className: clx(
9903
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9904
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9905
+ "placeholder:text-ui-fg-muted"
9906
+ ),
9907
+ ...props
9679
9908
  }
9680
9909
  ),
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
- ] })
9910
+ /* @__PURE__ */ jsxs(
9911
+ "button",
9912
+ {
9913
+ className: clx(
9914
+ "flex items-center justify-center outline-none transition-fg",
9915
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9916
+ "focus:bg-ui-bg-field-component-hover",
9917
+ "hover:bg-ui-bg-field-component-hover",
9918
+ {
9919
+ "size-7": size === "small",
9920
+ "size-8": size === "base"
9921
+ }
9922
+ ),
9923
+ type: "button",
9924
+ onClick: handleDecrement,
9925
+ disabled: min !== void 0 && value <= min || disabled,
9926
+ children: [
9927
+ /* @__PURE__ */ jsx(Minus, {}),
9928
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9929
+ ]
9930
+ }
9931
+ ),
9932
+ /* @__PURE__ */ jsxs(
9933
+ "button",
9934
+ {
9935
+ className: clx(
9936
+ "flex items-center justify-center outline-none transition-fg",
9937
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9938
+ "focus:bg-ui-bg-field-hover",
9939
+ "hover:bg-ui-bg-field-hover",
9940
+ {
9941
+ "size-7": size === "small",
9942
+ "size-8": size === "base"
9943
+ }
9944
+ ),
9945
+ type: "button",
9946
+ onClick: handleIncrement,
9947
+ disabled: max !== void 0 && value >= max || disabled,
9948
+ children: [
9949
+ /* @__PURE__ */ jsx(Plus, {}),
9950
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9951
+ ]
9952
+ }
9953
+ )
9689
9954
  ]
9690
9955
  }
9691
9956
  );
9692
9957
  }
9693
9958
  );
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 = () => {
9959
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9960
+ const productVariantsQueryKeys = {
9961
+ list: (query2) => [
9962
+ PRODUCT_VARIANTS_QUERY_KEY,
9963
+ query2 ? query2 : void 0
9964
+ ]
9965
+ };
9966
+ const useProductVariants = (query2, options) => {
9967
+ const { data, ...rest } = useQuery({
9968
+ queryKey: productVariantsQueryKeys.list(query2),
9969
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9970
+ ...options
9971
+ });
9972
+ return { ...data, ...rest };
9973
+ };
9974
+ const useCancelOrderEdit = ({ preview }) => {
9975
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9976
+ const onCancel = useCallback(async () => {
9977
+ if (!preview) {
9978
+ return true;
9979
+ }
9980
+ let res = false;
9981
+ await cancelOrderEdit(void 0, {
9982
+ onError: (e) => {
9983
+ toast.error(e.message);
9984
+ },
9985
+ onSuccess: () => {
9986
+ res = true;
9987
+ }
9988
+ });
9989
+ return res;
9990
+ }, [preview, cancelOrderEdit]);
9991
+ return { onCancel };
9992
+ };
9993
+ let IS_REQUEST_RUNNING = false;
9994
+ const useInitiateOrderEdit = ({
9995
+ preview
9996
+ }) => {
9997
+ const navigate = useNavigate();
9998
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9999
+ useEffect(() => {
10000
+ async function run() {
10001
+ if (IS_REQUEST_RUNNING || !preview) {
10002
+ return;
10003
+ }
10004
+ if (preview.order_change) {
10005
+ return;
10006
+ }
10007
+ IS_REQUEST_RUNNING = true;
10008
+ await mutateAsync(void 0, {
10009
+ onError: (e) => {
10010
+ toast.error(e.message);
10011
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10012
+ return;
10013
+ }
10014
+ });
10015
+ IS_REQUEST_RUNNING = false;
10016
+ }
10017
+ run();
10018
+ }, [preview, navigate, mutateAsync]);
10019
+ };
10020
+ function convertNumber(value) {
10021
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10022
+ }
10023
+ const STACKED_MODAL_ID = "items_stacked_modal";
10024
+ const Items = () => {
9704
10025
  const { id } = useParams();
9705
- const { order, isPending, isError, error } = useOrder(id, {
9706
- fields: "metadata"
10026
+ const {
10027
+ order: preview,
10028
+ isPending: isPreviewPending,
10029
+ isError: isPreviewError,
10030
+ error: previewError
10031
+ } = useOrderPreview(id, void 0, {
10032
+ placeholderData: keepPreviousData
9707
10033
  });
10034
+ useInitiateOrderEdit({ preview });
10035
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10036
+ id,
10037
+ {
10038
+ fields: "currency_code"
10039
+ },
10040
+ {
10041
+ enabled: !!id
10042
+ }
10043
+ );
10044
+ const { onCancel } = useCancelOrderEdit({ preview });
9708
10045
  if (isError) {
9709
10046
  throw error;
9710
10047
  }
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
- ] });
10048
+ if (isPreviewError) {
10049
+ throw previewError;
10050
+ }
10051
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10052
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10053
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10054
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10055
+ ] }) });
9719
10056
  };
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 }) => {
10057
+ const ItemsForm = ({ preview, currencyCode }) => {
10058
+ var _a;
10059
+ const [isSubmitting, setIsSubmitting] = useState(false);
10060
+ const [modalContent, setModalContent] = useState(
10061
+ null
10062
+ );
9723
10063
  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
10064
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10065
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10066
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10067
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10068
+ const matches = useMemo(() => {
10069
+ return matchSorter(preview.items, query2, {
10070
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10071
+ });
10072
+ }, [preview.items, query2]);
10073
+ const onSubmit = async () => {
10074
+ setIsSubmitting(true);
10075
+ let requestSucceeded = false;
10076
+ await requestOrderEdit(void 0, {
10077
+ onError: (e) => {
10078
+ toast.error(`Failed to request order edit: ${e.message}`);
9737
10079
  },
9738
- {
9739
- onSuccess: () => {
9740
- toast.success("Metadata updated");
9741
- handleSuccess();
9742
- },
9743
- onError: (error) => {
9744
- toast.error(error.message);
9745
- }
10080
+ onSuccess: () => {
10081
+ requestSucceeded = true;
9746
10082
  }
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
- });
10083
+ });
10084
+ if (!requestSucceeded) {
10085
+ setIsSubmitting(false);
10086
+ return;
9761
10087
  }
9762
- }
9763
- function insertRow(index, position) {
9764
- insert(index + (position === "above" ? 0 : 1), {
9765
- key: "",
9766
- value: "",
9767
- disabled: false
10088
+ await confirmOrderEdit(void 0, {
10089
+ onError: (e) => {
10090
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10091
+ },
10092
+ onSuccess: () => {
10093
+ handleSuccess();
10094
+ },
10095
+ onSettled: () => {
10096
+ setIsSubmitting(false);
10097
+ }
9768
10098
  });
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" }) })
9781
- ] }),
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: [
10099
+ };
10100
+ const onKeyDown = useCallback(
10101
+ (e) => {
10102
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10103
+ if (modalContent || isSubmitting) {
10104
+ return;
10105
+ }
10106
+ onSubmit();
10107
+ }
10108
+ },
10109
+ [modalContent, isSubmitting, onSubmit]
10110
+ );
10111
+ useEffect(() => {
10112
+ document.addEventListener("keydown", onKeyDown);
10113
+ return () => {
10114
+ document.removeEventListener("keydown", onKeyDown);
10115
+ };
10116
+ }, [onKeyDown]);
10117
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10118
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10119
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10120
+ StackedFocusModal,
10121
+ {
10122
+ id: STACKED_MODAL_ID,
10123
+ onOpenChangeCallback: (open) => {
10124
+ if (!open) {
10125
+ setModalContent(null);
10126
+ }
10127
+ },
10128
+ children: [
10129
+ /* @__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: [
10130
+ /* @__PURE__ */ jsxs("div", { children: [
10131
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10132
+ /* @__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" }) })
10133
+ ] }),
10134
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10135
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10136
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10137
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10138
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10139
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10140
+ ] }),
10141
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10142
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10143
+ Input,
10144
+ {
10145
+ type: "search",
10146
+ placeholder: "Search items",
10147
+ value: searchValue,
10148
+ onChange: (e) => onSearchValueChange(e.target.value)
10149
+ }
10150
+ ) }),
10151
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10152
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10153
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9845
10154
  /* @__PURE__ */ jsx(
9846
- DropdownMenu.Trigger,
10155
+ StackedModalTrigger$1,
9847
10156
  {
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, {}) })
10157
+ type: "add-items",
10158
+ setModalContent
9857
10159
  }
9858
10160
  ),
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
- ] })
10161
+ /* @__PURE__ */ jsx(
10162
+ StackedModalTrigger$1,
10163
+ {
10164
+ type: "add-custom-item",
10165
+ setModalContent
10166
+ }
10167
+ )
9895
10168
  ] })
9896
10169
  ] })
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;
9971
- }
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) {
9978
- return;
9979
- }
9980
- if (disabled) {
9981
- update[key] = value;
9982
- return;
9983
- }
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;
9996
- }
9997
- }
9998
- });
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
- ),
10070
- /* @__PURE__ */ jsxs(
10071
- "button",
10072
- {
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",
10170
+ ] })
10171
+ ] }),
10172
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10173
+ /* @__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: [
10174
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10175
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10176
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10177
+ /* @__PURE__ */ jsx("div", {})
10178
+ ] }) }),
10179
+ /* @__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: [
10180
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10181
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10182
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10183
+ Item,
10184
+ {
10185
+ item,
10186
+ preview,
10187
+ currencyCode
10188
+ },
10189
+ item.id
10190
+ )) : /* @__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: [
10191
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10192
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10193
+ 'No items found for "',
10194
+ query2,
10195
+ '".'
10196
+ ] })
10197
+ ] }) })
10198
+ ] })
10199
+ ] }),
10200
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10201
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10202
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10203
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10204
+ Text,
10078
10205
  {
10079
- "size-7": size === "small",
10080
- "size-8": size === "base"
10206
+ size: "small",
10207
+ leading: "compact",
10208
+ className: "text-ui-fg-subtle",
10209
+ children: [
10210
+ itemCount,
10211
+ " ",
10212
+ itemCount === 1 ? "item" : "items"
10213
+ ]
10081
10214
  }
10082
- ),
10083
- type: "button",
10084
- onClick: handleDecrement,
10085
- disabled: min !== void 0 && value <= min || disabled,
10086
- children: [
10087
- /* @__PURE__ */ jsx(Minus, {}),
10088
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10089
- ]
10090
- }
10091
- ),
10092
- /* @__PURE__ */ jsxs(
10093
- "button",
10215
+ ) }),
10216
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10217
+ ] })
10218
+ ] }) }),
10219
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10220
+ CustomItemForm,
10094
10221
  {
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
- ]
10222
+ orderId: preview.id,
10223
+ currencyCode
10112
10224
  }
10113
- )
10225
+ ) : null)
10114
10226
  ]
10115
10227
  }
10116
- );
10228
+ ) }),
10229
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10230
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10231
+ /* @__PURE__ */ jsx(
10232
+ Button,
10233
+ {
10234
+ size: "small",
10235
+ type: "button",
10236
+ onClick: onSubmit,
10237
+ isLoading: isSubmitting,
10238
+ children: "Save"
10239
+ }
10240
+ )
10241
+ ] }) })
10242
+ ] });
10243
+ };
10244
+ const Item = ({ item, preview, currencyCode }) => {
10245
+ if (item.variant_id) {
10246
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10117
10247
  }
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
- ]
10248
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10125
10249
  };
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
10250
+ const VariantItem = ({ item, preview, currencyCode }) => {
10251
+ const [editing, setEditing] = useState(false);
10252
+ const form = useForm({
10253
+ defaultValues: {
10254
+ quantity: item.quantity,
10255
+ unit_price: item.unit_price
10256
+ },
10257
+ resolver: zodResolver(variantItemSchema)
10131
10258
  });
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;
10259
+ const actionId = useMemo(() => {
10260
+ var _a, _b;
10261
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10262
+ }, [item]);
10263
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10264
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10265
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10266
+ const onSubmit = form.handleSubmit(async (data) => {
10267
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10268
+ setEditing(false);
10269
+ return;
10139
10270
  }
10140
- let res = false;
10141
- await cancelOrderEdit(void 0, {
10142
- onError: (e) => {
10143
- toast.error(e.message);
10144
- },
10145
- onSuccess: () => {
10146
- res = true;
10147
- }
10148
- });
10149
- return res;
10150
- }, [preview, cancelOrderEdit]);
10151
- return { onCancel };
10152
- };
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);
10159
- 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, {
10169
- onError: (e) => {
10170
- toast.error(e.message);
10171
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10172
- return;
10271
+ if (!actionId) {
10272
+ await updateOriginalItem(
10273
+ {
10274
+ item_id: item.id,
10275
+ quantity: data.quantity,
10276
+ unit_price: convertNumber(data.unit_price)
10277
+ },
10278
+ {
10279
+ onSuccess: () => {
10280
+ setEditing(false);
10281
+ },
10282
+ onError: (e) => {
10283
+ toast.error(e.message);
10284
+ }
10173
10285
  }
10174
- });
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);
10286
+ );
10246
10287
  return;
10247
10288
  }
10248
- await confirmOrderEdit(void 0, {
10249
- onError: (e) => {
10250
- toast.error(`Failed to confirm order edit: ${e.message}`);
10251
- },
10252
- onSuccess: () => {
10253
- handleSuccess();
10289
+ await updateActionItem(
10290
+ {
10291
+ action_id: actionId,
10292
+ quantity: data.quantity,
10293
+ unit_price: convertNumber(data.unit_price)
10254
10294
  },
10255
- onSettled: () => {
10256
- setIsSubmitting(false);
10295
+ {
10296
+ onSuccess: () => {
10297
+ setEditing(false);
10298
+ },
10299
+ onError: (e) => {
10300
+ toast.error(e.message);
10301
+ }
10257
10302
  }
10258
- });
10259
- };
10260
- const onKeyDown = useCallback(
10261
- (e) => {
10262
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10263
- if (modalContent || isSubmitting) {
10264
- return;
10303
+ );
10304
+ });
10305
+ 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: [
10306
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10307
+ /* @__PURE__ */ jsx(
10308
+ Thumbnail,
10309
+ {
10310
+ thumbnail: item.thumbnail,
10311
+ alt: item.product_title ?? void 0
10312
+ }
10313
+ ),
10314
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10315
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10316
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10317
+ /* @__PURE__ */ jsxs(
10318
+ Text,
10319
+ {
10320
+ size: "small",
10321
+ leading: "compact",
10322
+ className: "text-ui-fg-subtle",
10323
+ children: [
10324
+ "(",
10325
+ item.variant_title,
10326
+ ")"
10327
+ ]
10328
+ }
10329
+ )
10330
+ ] }),
10331
+ /* @__PURE__ */ jsx(
10332
+ Text,
10333
+ {
10334
+ size: "small",
10335
+ leading: "compact",
10336
+ className: "text-ui-fg-subtle",
10337
+ children: item.variant_sku
10338
+ }
10339
+ )
10340
+ ] })
10341
+ ] }),
10342
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10343
+ Form$2.Field,
10344
+ {
10345
+ control: form.control,
10346
+ name: "quantity",
10347
+ render: ({ field }) => {
10348
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10265
10349
  }
10266
- onSubmit();
10267
10350
  }
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,
10351
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10352
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10353
+ Form$2.Field,
10281
10354
  {
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
- return;
10448
- }
10449
- await updateActionItem(
10450
- {
10451
- action_id: actionId,
10452
- quantity: data.quantity,
10453
- unit_price: convertNumber(data.unit_price)
10454
- },
10455
- {
10456
- onSuccess: () => {
10457
- setEditing(false);
10458
- },
10459
- onError: (e) => {
10460
- toast.error(e.message);
10461
- }
10462
- }
10463
- );
10464
- });
10465
- 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: [
10467
- /* @__PURE__ */ jsx(
10468
- Thumbnail,
10469
- {
10470
- thumbnail: item.thumbnail,
10471
- alt: item.product_title ?? void 0
10472
- }
10473
- ),
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
10498
- }
10499
- )
10500
- ] })
10501
- ] }),
10502
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10503
- Form$2.Field,
10504
- {
10505
- control: form.control,
10506
- name: "quantity",
10507
- render: ({ field }) => {
10508
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10509
- }
10510
- }
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(
10513
- Form$2.Field,
10514
- {
10515
- control: form.control,
10516
- name: "unit_price",
10517
- render: ({ field: { onChange, ...field } }) => {
10518
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10519
- CurrencyInput,
10520
- {
10521
- ...field,
10522
- symbol: getNativeSymbol(currencyCode),
10523
- code: currencyCode,
10524
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10525
- }
10526
- ) }) });
10527
- }
10528
- }
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);
10355
+ control: form.control,
10356
+ name: "unit_price",
10357
+ render: ({ field: { onChange, ...field } }) => {
10358
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10359
+ CurrencyInput,
10360
+ {
10361
+ ...field,
10362
+ symbol: getNativeSymbol(currencyCode),
10363
+ code: currencyCode,
10364
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10365
+ }
10366
+ ) }) });
10367
+ }
10368
+ }
10369
+ ) }) : /* @__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) }) }),
10370
+ /* @__PURE__ */ jsx(
10371
+ IconButton,
10372
+ {
10373
+ type: "button",
10374
+ size: "small",
10375
+ onClick: editing ? onSubmit : () => {
10376
+ setEditing(true);
10537
10377
  },
10538
10378
  disabled: isPending,
10539
10379
  children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
@@ -10980,1067 +10820,738 @@ const customItemSchema = objectType({
10980
10820
  quantity: numberType(),
10981
10821
  unit_price: unionType([numberType(), stringType()])
10982
10822
  });
10983
- const PROMOTION_QUERY_KEY = "promotions";
10984
- const promotionsQueryKeys = {
10985
- list: (query2) => [
10986
- PROMOTION_QUERY_KEY,
10987
- query2 ? query2 : void 0
10988
- ],
10989
- detail: (id, query2) => [
10990
- PROMOTION_QUERY_KEY,
10991
- id,
10992
- query2 ? query2 : void 0
10993
- ]
10994
- };
10995
- const usePromotions = (query2, options) => {
10996
- const { data, ...rest } = useQuery({
10997
- queryKey: promotionsQueryKeys.list(query2),
10998
- queryFn: async () => sdk.admin.promotion.list(query2),
10999
- ...options
11000
- });
11001
- return { ...data, ...rest };
11002
- };
11003
- const Promotions = () => {
11004
- const { id } = useParams();
11005
- const {
11006
- order: preview,
11007
- isError: isPreviewError,
11008
- error: previewError
11009
- } = useOrderPreview(id, void 0);
11010
- useInitiateOrderEdit({ preview });
11011
- const { onCancel } = useCancelOrderEdit({ preview });
11012
- if (isPreviewError) {
11013
- throw previewError;
11014
- }
11015
- const isReady = !!preview;
11016
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11017
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11018
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11019
- ] });
11020
- };
11021
- const PromotionForm = ({ preview }) => {
11022
- const { items, shipping_methods } = preview;
11023
- const [isSubmitting, setIsSubmitting] = useState(false);
11024
- const [comboboxValue, setComboboxValue] = useState("");
11025
- const { handleSuccess } = useRouteModal();
11026
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11027
- const promoIds = getPromotionIds(items, shipping_methods);
11028
- const { promotions, isPending, isError, error } = usePromotions(
11029
- {
11030
- id: promoIds
11031
- },
11032
- {
11033
- enabled: !!promoIds.length
11034
- }
11035
- );
11036
- const comboboxData = useComboboxData({
11037
- queryKey: ["promotions", "combobox", promoIds],
11038
- queryFn: async (params) => {
11039
- return await sdk.admin.promotion.list({
11040
- ...params,
11041
- id: {
11042
- $nin: promoIds
11043
- }
11044
- });
11045
- },
11046
- getOptions: (data) => {
11047
- return data.promotions.map((promotion) => ({
11048
- label: promotion.code,
11049
- value: promotion.code
11050
- }));
11051
- }
11052
- });
11053
- const add = async (value) => {
11054
- if (!value) {
11055
- return;
11056
- }
11057
- addPromotions(
11058
- {
11059
- promo_codes: [value]
11060
- },
10823
+ const InlineTip = forwardRef(
10824
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10825
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10826
+ return /* @__PURE__ */ jsxs(
10827
+ "div",
11061
10828
  {
11062
- onError: (e) => {
11063
- toast.error(e.message);
11064
- comboboxData.onSearchValueChange("");
11065
- setComboboxValue("");
11066
- },
11067
- onSuccess: () => {
11068
- comboboxData.onSearchValueChange("");
11069
- setComboboxValue("");
11070
- }
10829
+ ref,
10830
+ className: clx(
10831
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10832
+ className
10833
+ ),
10834
+ ...props,
10835
+ children: [
10836
+ /* @__PURE__ */ jsx(
10837
+ "div",
10838
+ {
10839
+ role: "presentation",
10840
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10841
+ "bg-ui-tag-orange-icon": variant === "warning"
10842
+ })
10843
+ }
10844
+ ),
10845
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10846
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10847
+ labelValue,
10848
+ ":"
10849
+ ] }),
10850
+ " ",
10851
+ children
10852
+ ] })
10853
+ ]
11071
10854
  }
11072
10855
  );
11073
- };
11074
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11075
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11076
- const onSubmit = async () => {
11077
- setIsSubmitting(true);
11078
- let requestSucceeded = false;
11079
- await requestOrderEdit(void 0, {
11080
- onError: (e) => {
11081
- toast.error(e.message);
11082
- },
11083
- onSuccess: () => {
11084
- requestSucceeded = true;
11085
- }
11086
- });
11087
- if (!requestSucceeded) {
11088
- setIsSubmitting(false);
11089
- return;
11090
- }
11091
- await confirmOrderEdit(void 0, {
11092
- onError: (e) => {
11093
- toast.error(e.message);
11094
- },
11095
- onSuccess: () => {
11096
- handleSuccess();
11097
- },
11098
- onSettled: () => {
11099
- setIsSubmitting(false);
11100
- }
11101
- });
11102
- };
10856
+ }
10857
+ );
10858
+ InlineTip.displayName = "InlineTip";
10859
+ const MetadataFieldSchema = objectType({
10860
+ key: stringType(),
10861
+ disabled: booleanType().optional(),
10862
+ value: anyType()
10863
+ });
10864
+ const MetadataSchema = objectType({
10865
+ metadata: arrayType(MetadataFieldSchema)
10866
+ });
10867
+ const Metadata = () => {
10868
+ const { id } = useParams();
10869
+ const { order, isPending, isError, error } = useOrder(id, {
10870
+ fields: "metadata"
10871
+ });
11103
10872
  if (isError) {
11104
10873
  throw error;
11105
10874
  }
11106
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11107
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11108
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11109
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11110
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11111
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11112
- ] }),
11113
- /* @__PURE__ */ jsx(
11114
- Combobox,
11115
- {
11116
- id: "promotion-combobox",
11117
- "aria-describedby": "promotion-combobox-hint",
11118
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11119
- fetchNextPage: comboboxData.fetchNextPage,
11120
- options: comboboxData.options,
11121
- onSearchValueChange: comboboxData.onSearchValueChange,
11122
- searchValue: comboboxData.searchValue,
11123
- disabled: comboboxData.disabled || isAddingPromotions,
11124
- onChange: add,
11125
- value: comboboxValue
11126
- }
11127
- )
11128
- ] }),
11129
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11130
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11131
- PromotionItem,
11132
- {
11133
- promotion,
11134
- orderId: preview.id,
11135
- isLoading: isPending
11136
- },
11137
- promotion.id
11138
- )) })
11139
- ] }) }),
11140
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11141
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11142
- /* @__PURE__ */ jsx(
11143
- Button,
11144
- {
11145
- size: "small",
11146
- type: "submit",
11147
- isLoading: isSubmitting || isAddingPromotions,
11148
- children: "Save"
11149
- }
11150
- )
11151
- ] }) })
10875
+ const isReady = !isPending && !!order;
10876
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10877
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10878
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10879
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10880
+ ] }),
10881
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11152
10882
  ] });
11153
10883
  };
11154
- const PromotionItem = ({
11155
- promotion,
11156
- orderId,
11157
- isLoading
11158
- }) => {
11159
- var _a;
11160
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11161
- const onRemove = async () => {
11162
- removePromotions(
10884
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10885
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10886
+ const MetadataForm = ({ orderId, metadata }) => {
10887
+ const { handleSuccess } = useRouteModal();
10888
+ const hasUneditableRows = getHasUneditableRows(metadata);
10889
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10890
+ const form = useForm({
10891
+ defaultValues: {
10892
+ metadata: getDefaultValues(metadata)
10893
+ },
10894
+ resolver: zodResolver(MetadataSchema)
10895
+ });
10896
+ const handleSubmit = form.handleSubmit(async (data) => {
10897
+ const parsedData = parseValues(data);
10898
+ await mutateAsync(
11163
10899
  {
11164
- promo_codes: [promotion.code]
10900
+ metadata: parsedData
11165
10901
  },
11166
10902
  {
11167
- onError: (e) => {
11168
- toast.error(e.message);
10903
+ onSuccess: () => {
10904
+ toast.success("Metadata updated");
10905
+ handleSuccess();
10906
+ },
10907
+ onError: (error) => {
10908
+ toast.error(error.message);
11169
10909
  }
11170
10910
  }
11171
10911
  );
11172
- };
11173
- const displayValue = getDisplayValue(promotion);
11174
- return /* @__PURE__ */ jsxs(
11175
- "div",
10912
+ });
10913
+ const { fields, insert, remove } = useFieldArray({
10914
+ control: form.control,
10915
+ name: "metadata"
10916
+ });
10917
+ function deleteRow(index) {
10918
+ remove(index);
10919
+ if (fields.length === 1) {
10920
+ insert(0, {
10921
+ key: "",
10922
+ value: "",
10923
+ disabled: false
10924
+ });
10925
+ }
10926
+ }
10927
+ function insertRow(index, position) {
10928
+ insert(index + (position === "above" ? 0 : 1), {
10929
+ key: "",
10930
+ value: "",
10931
+ disabled: false
10932
+ });
10933
+ }
10934
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10935
+ KeyboundForm,
11176
10936
  {
11177
- className: clx(
11178
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11179
- {
11180
- "animate-pulse": isLoading
11181
- }
11182
- ),
10937
+ onSubmit: handleSubmit,
10938
+ className: "flex flex-1 flex-col overflow-hidden",
11183
10939
  children: [
11184
- /* @__PURE__ */ jsxs("div", { children: [
11185
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11186
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11187
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11188
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11189
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11190
- ] }),
11191
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11192
- ] })
11193
- ] }),
11194
- /* @__PURE__ */ jsx(
11195
- IconButton,
11196
- {
11197
- size: "small",
11198
- type: "button",
11199
- variant: "transparent",
11200
- onClick: onRemove,
11201
- isLoading: isPending || isLoading,
11202
- children: /* @__PURE__ */ jsx(XMark, {})
11203
- }
11204
- )
10940
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10941
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10942
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10943
+ /* @__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" }) }),
10944
+ /* @__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" }) })
10945
+ ] }),
10946
+ fields.map((field, index) => {
10947
+ const isDisabled = field.disabled || false;
10948
+ let placeholder = "-";
10949
+ if (typeof field.value === "object") {
10950
+ placeholder = "{ ... }";
10951
+ }
10952
+ if (Array.isArray(field.value)) {
10953
+ placeholder = "[ ... ]";
10954
+ }
10955
+ return /* @__PURE__ */ jsx(
10956
+ ConditionalTooltip,
10957
+ {
10958
+ showTooltip: isDisabled,
10959
+ content: "This row is disabled because it contains non-primitive data.",
10960
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10961
+ /* @__PURE__ */ jsxs(
10962
+ "div",
10963
+ {
10964
+ className: clx("grid grid-cols-2 divide-x", {
10965
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10966
+ }),
10967
+ children: [
10968
+ /* @__PURE__ */ jsx(
10969
+ Form$2.Field,
10970
+ {
10971
+ control: form.control,
10972
+ name: `metadata.${index}.key`,
10973
+ render: ({ field: field2 }) => {
10974
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10975
+ GridInput,
10976
+ {
10977
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10978
+ ...field2,
10979
+ disabled: isDisabled,
10980
+ placeholder: "Key"
10981
+ }
10982
+ ) }) });
10983
+ }
10984
+ }
10985
+ ),
10986
+ /* @__PURE__ */ jsx(
10987
+ Form$2.Field,
10988
+ {
10989
+ control: form.control,
10990
+ name: `metadata.${index}.value`,
10991
+ render: ({ field: { value, ...field2 } }) => {
10992
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10993
+ GridInput,
10994
+ {
10995
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10996
+ ...field2,
10997
+ value: isDisabled ? placeholder : value,
10998
+ disabled: isDisabled,
10999
+ placeholder: "Value"
11000
+ }
11001
+ ) }) });
11002
+ }
11003
+ }
11004
+ )
11005
+ ]
11006
+ }
11007
+ ),
11008
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11009
+ /* @__PURE__ */ jsx(
11010
+ DropdownMenu.Trigger,
11011
+ {
11012
+ className: clx(
11013
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11014
+ {
11015
+ hidden: isDisabled
11016
+ }
11017
+ ),
11018
+ disabled: isDisabled,
11019
+ asChild: true,
11020
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11021
+ }
11022
+ ),
11023
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11024
+ /* @__PURE__ */ jsxs(
11025
+ DropdownMenu.Item,
11026
+ {
11027
+ className: "gap-x-2",
11028
+ onClick: () => insertRow(index, "above"),
11029
+ children: [
11030
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11031
+ "Insert row above"
11032
+ ]
11033
+ }
11034
+ ),
11035
+ /* @__PURE__ */ jsxs(
11036
+ DropdownMenu.Item,
11037
+ {
11038
+ className: "gap-x-2",
11039
+ onClick: () => insertRow(index, "below"),
11040
+ children: [
11041
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11042
+ "Insert row below"
11043
+ ]
11044
+ }
11045
+ ),
11046
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11047
+ /* @__PURE__ */ jsxs(
11048
+ DropdownMenu.Item,
11049
+ {
11050
+ className: "gap-x-2",
11051
+ onClick: () => deleteRow(index),
11052
+ children: [
11053
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11054
+ "Delete row"
11055
+ ]
11056
+ }
11057
+ )
11058
+ ] })
11059
+ ] })
11060
+ ] })
11061
+ },
11062
+ field.id
11063
+ );
11064
+ })
11065
+ ] }),
11066
+ 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." })
11067
+ ] }),
11068
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11069
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11070
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11071
+ ] }) })
11205
11072
  ]
11206
- },
11207
- promotion.id
11208
- );
11073
+ }
11074
+ ) });
11209
11075
  };
11210
- function getDisplayValue(promotion) {
11211
- var _a, _b, _c, _d;
11212
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11213
- if (!value) {
11214
- return null;
11215
- }
11216
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11217
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11218
- if (!currency) {
11219
- return null;
11076
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11077
+ return /* @__PURE__ */ jsx(
11078
+ "input",
11079
+ {
11080
+ ref,
11081
+ ...props,
11082
+ autoComplete: "off",
11083
+ className: clx(
11084
+ "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",
11085
+ className
11086
+ )
11220
11087
  }
11221
- return getLocaleAmount(value, currency);
11222
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11223
- return formatPercentage(value);
11224
- }
11225
- return null;
11226
- }
11227
- const formatter = new Intl.NumberFormat([], {
11228
- style: "percent",
11229
- minimumFractionDigits: 2
11088
+ );
11230
11089
  });
11231
- const formatPercentage = (value, isPercentageValue = false) => {
11232
- let val = value || 0;
11233
- if (!isPercentageValue) {
11234
- val = val / 100;
11235
- }
11236
- return formatter.format(val);
11090
+ GridInput.displayName = "MetadataForm.GridInput";
11091
+ const PlaceholderInner = () => {
11092
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11093
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11094
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11095
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11096
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11097
+ ] }) })
11098
+ ] });
11237
11099
  };
11238
- function getPromotionIds(items, shippingMethods) {
11239
- const promotionIds = /* @__PURE__ */ new Set();
11240
- for (const item of items) {
11241
- if (item.adjustments) {
11242
- for (const adjustment of item.adjustments) {
11243
- if (adjustment.promotion_id) {
11244
- promotionIds.add(adjustment.promotion_id);
11245
- }
11100
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11101
+ function getDefaultValues(metadata) {
11102
+ if (!metadata || !Object.keys(metadata).length) {
11103
+ return [
11104
+ {
11105
+ key: "",
11106
+ value: "",
11107
+ disabled: false
11246
11108
  }
11247
- }
11109
+ ];
11248
11110
  }
11249
- for (const shippingMethod of shippingMethods) {
11250
- if (shippingMethod.adjustments) {
11251
- for (const adjustment of shippingMethod.adjustments) {
11252
- if (adjustment.promotion_id) {
11253
- promotionIds.add(adjustment.promotion_id);
11254
- }
11255
- }
11111
+ return Object.entries(metadata).map(([key, value]) => {
11112
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11113
+ return {
11114
+ key,
11115
+ value,
11116
+ disabled: true
11117
+ };
11256
11118
  }
11257
- }
11258
- return Array.from(promotionIds);
11259
- }
11260
- const SalesChannel = () => {
11261
- const { id } = useParams();
11262
- const { draft_order, isPending, isError, error } = useDraftOrder(
11263
- id,
11264
- {
11265
- fields: "+sales_channel_id"
11266
- },
11267
- {
11268
- enabled: !!id
11119
+ let stringValue = value;
11120
+ if (typeof value !== "string") {
11121
+ stringValue = JSON.stringify(value);
11269
11122
  }
11270
- );
11271
- if (isError) {
11272
- throw error;
11123
+ return {
11124
+ key,
11125
+ value: stringValue,
11126
+ original_key: key
11127
+ };
11128
+ });
11129
+ }
11130
+ function parseValues(values) {
11131
+ const metadata = values.metadata;
11132
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11133
+ if (isEmpty) {
11134
+ return null;
11273
11135
  }
11274
- const ISrEADY = !!draft_order && !isPending;
11275
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11276
- /* @__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" }) })
11279
- ] }),
11280
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11281
- ] });
11282
- };
11283
- const SalesChannelForm = ({ order }) => {
11284
- const form = useForm({
11285
- defaultValues: {
11286
- sales_channel_id: order.sales_channel_id || ""
11287
- },
11288
- resolver: zodResolver(schema$3)
11289
- });
11290
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11291
- const { handleSuccess } = useRouteModal();
11292
- const onSubmit = form.handleSubmit(async (data) => {
11293
- await mutateAsync(
11294
- {
11295
- sales_channel_id: data.sales_channel_id
11296
- },
11297
- {
11298
- onSuccess: () => {
11299
- toast.success("Sales channel updated");
11300
- handleSuccess();
11301
- },
11302
- onError: (error) => {
11303
- toast.error(error.message);
11304
- }
11305
- }
11306
- );
11307
- });
11308
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11309
- KeyboundForm,
11310
- {
11311
- className: "flex flex-1 flex-col overflow-hidden",
11312
- onSubmit,
11313
- 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
- ]
11136
+ const update = {};
11137
+ metadata.forEach((field) => {
11138
+ let key = field.key;
11139
+ let value = field.value;
11140
+ const disabled = field.disabled;
11141
+ if (!key || !value) {
11142
+ return;
11320
11143
  }
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
- });
11337
- return /* @__PURE__ */ jsx(
11338
- Form$2.Field,
11339
- {
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
- ] });
11144
+ if (disabled) {
11145
+ update[key] = value;
11146
+ return;
11147
+ }
11148
+ key = key.trim();
11149
+ value = value.trim();
11150
+ if (value === "true") {
11151
+ update[key] = true;
11152
+ } else if (value === "false") {
11153
+ update[key] = false;
11154
+ } else {
11155
+ const parsedNumber = parseFloat(value);
11156
+ if (!isNaN(parsedNumber)) {
11157
+ update[key] = parsedNumber;
11158
+ } else {
11159
+ update[key] = value;
11359
11160
  }
11360
11161
  }
11162
+ });
11163
+ return update;
11164
+ }
11165
+ function getHasUneditableRows(metadata) {
11166
+ if (!metadata) {
11167
+ return false;
11168
+ }
11169
+ return Object.values(metadata).some(
11170
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11361
11171
  );
11172
+ }
11173
+ const PROMOTION_QUERY_KEY = "promotions";
11174
+ const promotionsQueryKeys = {
11175
+ list: (query2) => [
11176
+ PROMOTION_QUERY_KEY,
11177
+ query2 ? query2 : void 0
11178
+ ],
11179
+ detail: (id, query2) => [
11180
+ PROMOTION_QUERY_KEY,
11181
+ id,
11182
+ query2 ? query2 : void 0
11183
+ ]
11362
11184
  };
11363
- const schema$3 = objectType({
11364
- sales_channel_id: stringType().min(1)
11365
- });
11366
- const ShippingAddress = () => {
11367
- const { id } = useParams();
11368
- const { order, isPending, isError, error } = useOrder(id, {
11369
- fields: "+shipping_address"
11185
+ const usePromotions = (query2, options) => {
11186
+ const { data, ...rest } = useQuery({
11187
+ queryKey: promotionsQueryKeys.list(query2),
11188
+ queryFn: async () => sdk.admin.promotion.list(query2),
11189
+ ...options
11370
11190
  });
11371
- if (isError) {
11372
- throw error;
11191
+ return { ...data, ...rest };
11192
+ };
11193
+ const Promotions = () => {
11194
+ const { id } = useParams();
11195
+ const {
11196
+ order: preview,
11197
+ isError: isPreviewError,
11198
+ error: previewError
11199
+ } = useOrderPreview(id, void 0);
11200
+ useInitiateOrderEdit({ preview });
11201
+ const { onCancel } = useCancelOrderEdit({ preview });
11202
+ if (isPreviewError) {
11203
+ throw previewError;
11373
11204
  }
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 })
11205
+ const isReady = !!preview;
11206
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11207
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11208
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11381
11209
  ] });
11382
11210
  };
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) ?? ""
11211
+ const PromotionForm = ({ preview }) => {
11212
+ const { items, shipping_methods } = preview;
11213
+ const [isSubmitting, setIsSubmitting] = useState(false);
11214
+ const [comboboxValue, setComboboxValue] = useState("");
11215
+ const { handleSuccess } = useRouteModal();
11216
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11217
+ const promoIds = getPromotionIds(items, shipping_methods);
11218
+ const { promotions, isPending, isError, error } = usePromotions(
11219
+ {
11220
+ id: promoIds
11397
11221
  },
11398
- resolver: zodResolver(schema$2)
11222
+ {
11223
+ enabled: !!promoIds.length
11224
+ }
11225
+ );
11226
+ const comboboxData = useComboboxData({
11227
+ queryKey: ["promotions", "combobox", promoIds],
11228
+ queryFn: async (params) => {
11229
+ return await sdk.admin.promotion.list({
11230
+ ...params,
11231
+ id: {
11232
+ $nin: promoIds
11233
+ }
11234
+ });
11235
+ },
11236
+ getOptions: (data) => {
11237
+ return data.promotions.map((promotion) => ({
11238
+ label: promotion.code,
11239
+ value: promotion.code
11240
+ }));
11241
+ }
11399
11242
  });
11400
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11401
- const { handleSuccess } = useRouteModal();
11402
- const onSubmit = form.handleSubmit(async (data) => {
11403
- await mutateAsync(
11243
+ const add = async (value) => {
11244
+ if (!value) {
11245
+ return;
11246
+ }
11247
+ addPromotions(
11404
11248
  {
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
- }
11249
+ promo_codes: [value]
11417
11250
  },
11418
11251
  {
11419
- onSuccess: () => {
11420
- handleSuccess();
11252
+ onError: (e) => {
11253
+ toast.error(e.message);
11254
+ comboboxData.onSearchValueChange("");
11255
+ setComboboxValue("");
11421
11256
  },
11422
- onError: (error) => {
11423
- toast.error(error.message);
11257
+ onSuccess: () => {
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
11424
11260
  }
11425
11261
  }
11426
11262
  );
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
- ]
11263
+ };
11264
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11265
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11266
+ const onSubmit = async () => {
11267
+ setIsSubmitting(true);
11268
+ let requestSucceeded = false;
11269
+ await requestOrderEdit(void 0, {
11270
+ onError: (e) => {
11271
+ toast.error(e.message);
11272
+ },
11273
+ onSuccess: () => {
11274
+ requestSucceeded = true;
11275
+ }
11276
+ });
11277
+ if (!requestSucceeded) {
11278
+ setIsSubmitting(false);
11279
+ return;
11565
11280
  }
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
- });
11281
+ await confirmOrderEdit(void 0, {
11282
+ onError: (e) => {
11283
+ toast.error(e.message);
11284
+ },
11285
+ onSuccess: () => {
11286
+ handleSuccess();
11287
+ },
11288
+ onSettled: () => {
11289
+ setIsSubmitting(false);
11290
+ }
11291
+ });
11292
+ };
11574
11293
  if (isError) {
11575
11294
  throw error;
11576
11295
  }
11577
- const isReady = !isPending && !!draft_order;
11578
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11579
- /* @__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" }) })
11582
- ] }),
11583
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11296
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11297
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11298
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11299
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11300
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11301
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11302
+ ] }),
11303
+ /* @__PURE__ */ jsx(
11304
+ Combobox,
11305
+ {
11306
+ id: "promotion-combobox",
11307
+ "aria-describedby": "promotion-combobox-hint",
11308
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11309
+ fetchNextPage: comboboxData.fetchNextPage,
11310
+ options: comboboxData.options,
11311
+ onSearchValueChange: comboboxData.onSearchValueChange,
11312
+ searchValue: comboboxData.searchValue,
11313
+ disabled: comboboxData.disabled || isAddingPromotions,
11314
+ onChange: add,
11315
+ value: comboboxValue
11316
+ }
11317
+ )
11318
+ ] }),
11319
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11320
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11321
+ PromotionItem,
11322
+ {
11323
+ promotion,
11324
+ orderId: preview.id,
11325
+ isLoading: isPending
11326
+ },
11327
+ promotion.id
11328
+ )) })
11329
+ ] }) }),
11330
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11331
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11332
+ /* @__PURE__ */ jsx(
11333
+ Button,
11334
+ {
11335
+ size: "small",
11336
+ type: "submit",
11337
+ isLoading: isSubmitting || isAddingPromotions,
11338
+ children: "Save"
11339
+ }
11340
+ )
11341
+ ] }) })
11584
11342
  ] });
11585
11343
  };
11586
- const TransferOwnershipForm = ({ order }) => {
11587
- var _a, _b;
11588
- const form = useForm({
11589
- defaultValues: {
11590
- customer_id: order.customer_id || ""
11591
- },
11592
- resolver: zodResolver(schema$1)
11593
- });
11594
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11595
- 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
- const onSubmit = form.handleSubmit(async (data) => {
11602
- await mutateAsync(
11603
- { customer_id: data.customer_id },
11344
+ const PromotionItem = ({
11345
+ promotion,
11346
+ orderId,
11347
+ isLoading
11348
+ }) => {
11349
+ var _a;
11350
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11351
+ const onRemove = async () => {
11352
+ removePromotions(
11604
11353
  {
11605
- onSuccess: () => {
11606
- toast.success("Customer updated");
11607
- handleSuccess();
11608
- },
11609
- onError: (error) => {
11610
- toast.error(error.message);
11354
+ promo_codes: [promotion.code]
11355
+ },
11356
+ {
11357
+ onError: (e) => {
11358
+ toast.error(e.message);
11611
11359
  }
11612
11360
  }
11613
11361
  );
11614
- });
11615
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11616
- KeyboundForm,
11362
+ };
11363
+ const displayValue = getDisplayValue(promotion);
11364
+ return /* @__PURE__ */ jsxs(
11365
+ "div",
11617
11366
  {
11618
- className: "flex flex-1 flex-col overflow-hidden",
11619
- onSubmit,
11367
+ className: clx(
11368
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11369
+ {
11370
+ "animate-pulse": isLoading
11371
+ }
11372
+ ),
11620
11373
  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." })
11374
+ /* @__PURE__ */ jsxs("div", { children: [
11375
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11376
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11377
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11378
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11379
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11627
11380
  ] }),
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
- )
11381
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11382
+ ] })
11640
11383
  ] }),
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" }) }),
11384
+ /* @__PURE__ */ jsx(
11385
+ IconButton,
11386
+ {
11387
+ size: "small",
11388
+ type: "button",
11389
+ variant: "transparent",
11390
+ onClick: onRemove,
11391
+ isLoading: isPending || isLoading,
11392
+ children: /* @__PURE__ */ jsx(XMark, {})
11393
+ }
11394
+ )
11395
+ ]
11396
+ },
11397
+ promotion.id
11398
+ );
11399
+ };
11400
+ function getDisplayValue(promotion) {
11401
+ var _a, _b, _c, _d;
11402
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11403
+ if (!value) {
11404
+ return null;
11405
+ }
11406
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11407
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11408
+ if (!currency) {
11409
+ return null;
11410
+ }
11411
+ return getLocaleAmount(value, currency);
11412
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11413
+ return formatPercentage(value);
11414
+ }
11415
+ return null;
11416
+ }
11417
+ const formatter = new Intl.NumberFormat([], {
11418
+ style: "percent",
11419
+ minimumFractionDigits: 2
11420
+ });
11421
+ const formatPercentage = (value, isPercentageValue = false) => {
11422
+ let val = value || 0;
11423
+ if (!isPercentageValue) {
11424
+ val = val / 100;
11425
+ }
11426
+ return formatter.format(val);
11427
+ };
11428
+ function getPromotionIds(items, shippingMethods) {
11429
+ const promotionIds = /* @__PURE__ */ new Set();
11430
+ for (const item of items) {
11431
+ if (item.adjustments) {
11432
+ for (const adjustment of item.adjustments) {
11433
+ if (adjustment.promotion_id) {
11434
+ promotionIds.add(adjustment.promotion_id);
11435
+ }
11436
+ }
11437
+ }
11438
+ }
11439
+ for (const shippingMethod of shippingMethods) {
11440
+ if (shippingMethod.adjustments) {
11441
+ for (const adjustment of shippingMethod.adjustments) {
11442
+ if (adjustment.promotion_id) {
11443
+ promotionIds.add(adjustment.promotion_id);
11444
+ }
11445
+ }
11446
+ }
11447
+ }
11448
+ return Array.from(promotionIds);
11449
+ }
11450
+ const SalesChannel = () => {
11451
+ const { id } = useParams();
11452
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11453
+ id,
11454
+ {
11455
+ fields: "+sales_channel_id"
11456
+ },
11457
+ {
11458
+ enabled: !!id
11459
+ }
11460
+ );
11461
+ if (isError) {
11462
+ throw error;
11463
+ }
11464
+ const ISrEADY = !!draft_order && !isPending;
11465
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
+ ] }),
11470
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11471
+ ] });
11472
+ };
11473
+ const SalesChannelForm = ({ order }) => {
11474
+ const form = useForm({
11475
+ defaultValues: {
11476
+ sales_channel_id: order.sales_channel_id || ""
11477
+ },
11478
+ resolver: zodResolver(schema$2)
11479
+ });
11480
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
+ const { handleSuccess } = useRouteModal();
11482
+ const onSubmit = form.handleSubmit(async (data) => {
11483
+ await mutateAsync(
11484
+ {
11485
+ sales_channel_id: data.sales_channel_id
11486
+ },
11487
+ {
11488
+ onSuccess: () => {
11489
+ toast.success("Sales channel updated");
11490
+ handleSuccess();
11491
+ },
11492
+ onError: (error) => {
11493
+ toast.error(error.message);
11494
+ }
11495
+ }
11496
+ );
11497
+ });
11498
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11499
+ KeyboundForm,
11500
+ {
11501
+ className: "flex flex-1 flex-col overflow-hidden",
11502
+ onSubmit,
11503
+ children: [
11504
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11643
11507
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11644
11508
  ] }) })
11645
11509
  ]
11646
11510
  }
11647
11511
  ) });
11648
11512
  };
11649
- const CustomerField = ({ control, currentCustomerId }) => {
11650
- const customers = useComboboxData({
11513
+ const SalesChannelField = ({ control, order }) => {
11514
+ const salesChannels = useComboboxData({
11651
11515
  queryFn: async (params) => {
11652
- return await sdk.admin.customer.list({
11653
- ...params,
11654
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11655
- });
11516
+ return await sdk.admin.salesChannel.list(params);
11656
11517
  },
11657
- queryKey: ["customers"],
11518
+ queryKey: ["sales-channels"],
11658
11519
  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
- }
11520
+ return data.sales_channels.map((salesChannel) => ({
11521
+ label: salesChannel.name,
11522
+ value: salesChannel.id
11523
+ }));
11524
+ },
11525
+ defaultValue: order.sales_channel_id || void 0
11667
11526
  });
11668
11527
  return /* @__PURE__ */ jsx(
11669
11528
  Form$2.Field,
11670
11529
  {
11671
- name: "customer_id",
11672
11530
  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
- ] })
11531
+ name: "sales_channel_id",
11532
+ render: ({ field }) => {
11533
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
+ Combobox,
11537
+ {
11538
+ options: salesChannels.options,
11539
+ fetchNextPage: salesChannels.fetchNextPage,
11540
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
+ searchValue: salesChannels.searchValue,
11542
+ onSearchValueChange: salesChannels.onSearchValueChange,
11543
+ placeholder: "Select sales channel",
11544
+ ...field
11545
+ }
11546
+ ) }),
11547
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
+ ] });
11549
+ }
11692
11550
  }
11693
11551
  );
11694
11552
  };
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)
11553
+ const schema$2 = objectType({
11554
+ sales_channel_id: stringType().min(1)
12044
11555
  });
12045
11556
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
12046
11557
  const Shipping = () => {
@@ -12729,167 +12240,367 @@ const LocationField = ({ control, setValue }) => {
12729
12240
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12730
12241
  Combobox,
12731
12242
  {
12732
- options: locations.options,
12733
- fetchNextPage: locations.fetchNextPage,
12734
- isFetchingNextPage: locations.isFetchingNextPage,
12735
- searchValue: locations.searchValue,
12736
- onSearchValueChange: locations.onSearchValueChange,
12737
- placeholder: "Select location",
12738
- onChange: (value) => {
12739
- setValue("shipping_option_id", "", {
12740
- shouldDirty: true,
12741
- shouldTouch: true
12742
- });
12743
- onChange(value);
12744
- },
12745
- ...field
12243
+ options: locations.options,
12244
+ fetchNextPage: locations.fetchNextPage,
12245
+ isFetchingNextPage: locations.isFetchingNextPage,
12246
+ searchValue: locations.searchValue,
12247
+ onSearchValueChange: locations.onSearchValueChange,
12248
+ placeholder: "Select location",
12249
+ onChange: (value) => {
12250
+ setValue("shipping_option_id", "", {
12251
+ shouldDirty: true,
12252
+ shouldTouch: true
12253
+ });
12254
+ onChange(value);
12255
+ },
12256
+ ...field
12257
+ }
12258
+ ) })
12259
+ ] }) });
12260
+ }
12261
+ }
12262
+ );
12263
+ };
12264
+ const ShippingOptionField = ({
12265
+ shippingProfileId,
12266
+ preview,
12267
+ control
12268
+ }) => {
12269
+ var _a;
12270
+ const locationId = useWatch({ control, name: "location_id" });
12271
+ const shippingOptions = useComboboxData({
12272
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12273
+ queryFn: async (params) => {
12274
+ return await sdk.admin.shippingOption.list({
12275
+ ...params,
12276
+ stock_location_id: locationId,
12277
+ shipping_profile_id: shippingProfileId
12278
+ });
12279
+ },
12280
+ getOptions: (data) => {
12281
+ return data.shipping_options.map((option) => {
12282
+ var _a2;
12283
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12284
+ (r) => r.attribute === "is_return" && r.value === "true"
12285
+ )) {
12286
+ return void 0;
12287
+ }
12288
+ return {
12289
+ label: option.name,
12290
+ value: option.id
12291
+ };
12292
+ }).filter(Boolean);
12293
+ },
12294
+ enabled: !!locationId && !!shippingProfileId,
12295
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12296
+ });
12297
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12298
+ return /* @__PURE__ */ jsx(
12299
+ Form$2.Field,
12300
+ {
12301
+ control,
12302
+ name: "shipping_option_id",
12303
+ render: ({ field }) => {
12304
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12305
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12306
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12307
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12308
+ ] }),
12309
+ /* @__PURE__ */ jsx(
12310
+ ConditionalTooltip,
12311
+ {
12312
+ content: tooltipContent,
12313
+ showTooltip: !locationId || !shippingProfileId,
12314
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12315
+ Combobox,
12316
+ {
12317
+ options: shippingOptions.options,
12318
+ fetchNextPage: shippingOptions.fetchNextPage,
12319
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12320
+ searchValue: shippingOptions.searchValue,
12321
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12322
+ placeholder: "Select shipping option",
12323
+ ...field,
12324
+ disabled: !locationId || !shippingProfileId
12325
+ }
12326
+ ) }) })
12327
+ }
12328
+ )
12329
+ ] }) });
12330
+ }
12331
+ }
12332
+ );
12333
+ };
12334
+ const CustomAmountField = ({
12335
+ control,
12336
+ currencyCode
12337
+ }) => {
12338
+ return /* @__PURE__ */ jsx(
12339
+ Form$2.Field,
12340
+ {
12341
+ control,
12342
+ name: "custom_amount",
12343
+ render: ({ field: { onChange, ...field } }) => {
12344
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12345
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12346
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12347
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12348
+ ] }),
12349
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12350
+ CurrencyInput,
12351
+ {
12352
+ ...field,
12353
+ onValueChange: (value) => onChange(value),
12354
+ symbol: getNativeSymbol(currencyCode),
12355
+ code: currencyCode
12356
+ }
12357
+ ) })
12358
+ ] });
12359
+ }
12360
+ }
12361
+ );
12362
+ };
12363
+ const ShippingAddress = () => {
12364
+ const { id } = useParams();
12365
+ const { order, isPending, isError, error } = useOrder(id, {
12366
+ fields: "+shipping_address"
12367
+ });
12368
+ if (isError) {
12369
+ throw error;
12370
+ }
12371
+ const isReady = !isPending && !!order;
12372
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12373
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12374
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12375
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12376
+ ] }),
12377
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12378
+ ] });
12379
+ };
12380
+ const ShippingAddressForm = ({ order }) => {
12381
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12382
+ const form = useForm({
12383
+ defaultValues: {
12384
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12385
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12386
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12387
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12388
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12389
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12390
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12391
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12392
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12393
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12394
+ },
12395
+ resolver: zodResolver(schema$1)
12396
+ });
12397
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12398
+ const { handleSuccess } = useRouteModal();
12399
+ const onSubmit = form.handleSubmit(async (data) => {
12400
+ await mutateAsync(
12401
+ {
12402
+ shipping_address: {
12403
+ first_name: data.first_name,
12404
+ last_name: data.last_name,
12405
+ company: data.company,
12406
+ address_1: data.address_1,
12407
+ address_2: data.address_2,
12408
+ city: data.city,
12409
+ province: data.province,
12410
+ country_code: data.country_code,
12411
+ postal_code: data.postal_code,
12412
+ phone: data.phone
12413
+ }
12414
+ },
12415
+ {
12416
+ onSuccess: () => {
12417
+ handleSuccess();
12418
+ },
12419
+ onError: (error) => {
12420
+ toast.error(error.message);
12421
+ }
12422
+ }
12423
+ );
12424
+ });
12425
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12426
+ KeyboundForm,
12427
+ {
12428
+ className: "flex flex-1 flex-col overflow-hidden",
12429
+ onSubmit,
12430
+ children: [
12431
+ /* @__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: [
12432
+ /* @__PURE__ */ jsx(
12433
+ Form$2.Field,
12434
+ {
12435
+ control: form.control,
12436
+ name: "country_code",
12437
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12438
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12439
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12440
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12441
+ ] })
12442
+ }
12443
+ ),
12444
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12445
+ /* @__PURE__ */ jsx(
12446
+ Form$2.Field,
12447
+ {
12448
+ control: form.control,
12449
+ name: "first_name",
12450
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12451
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12452
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12453
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12454
+ ] })
12455
+ }
12456
+ ),
12457
+ /* @__PURE__ */ jsx(
12458
+ Form$2.Field,
12459
+ {
12460
+ control: form.control,
12461
+ name: "last_name",
12462
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12463
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12464
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12465
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12466
+ ] })
12467
+ }
12468
+ )
12469
+ ] }),
12470
+ /* @__PURE__ */ jsx(
12471
+ Form$2.Field,
12472
+ {
12473
+ control: form.control,
12474
+ name: "company",
12475
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12476
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12477
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12478
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12479
+ ] })
12480
+ }
12481
+ ),
12482
+ /* @__PURE__ */ jsx(
12483
+ Form$2.Field,
12484
+ {
12485
+ control: form.control,
12486
+ name: "address_1",
12487
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12488
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12489
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12490
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12491
+ ] })
12492
+ }
12493
+ ),
12494
+ /* @__PURE__ */ jsx(
12495
+ Form$2.Field,
12496
+ {
12497
+ control: form.control,
12498
+ name: "address_2",
12499
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12500
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12501
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12502
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12503
+ ] })
12746
12504
  }
12747
- ) })
12748
- ] }) });
12749
- }
12750
- }
12751
- );
12752
- };
12753
- const ShippingOptionField = ({
12754
- shippingProfileId,
12755
- preview,
12756
- control
12757
- }) => {
12758
- var _a;
12759
- const locationId = useWatch({ control, name: "location_id" });
12760
- const shippingOptions = useComboboxData({
12761
- queryKey: ["shipping_options", locationId, shippingProfileId],
12762
- queryFn: async (params) => {
12763
- return await sdk.admin.shippingOption.list({
12764
- ...params,
12765
- stock_location_id: locationId,
12766
- shipping_profile_id: shippingProfileId
12767
- });
12768
- },
12769
- getOptions: (data) => {
12770
- return data.shipping_options.map((option) => {
12771
- var _a2;
12772
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12773
- (r) => r.attribute === "is_return" && r.value === "true"
12774
- )) {
12775
- return void 0;
12776
- }
12777
- return {
12778
- label: option.name,
12779
- value: option.id
12780
- };
12781
- }).filter(Boolean);
12782
- },
12783
- enabled: !!locationId && !!shippingProfileId,
12784
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12785
- });
12786
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12787
- return /* @__PURE__ */ jsx(
12788
- Form$2.Field,
12789
- {
12790
- control,
12791
- name: "shipping_option_id",
12792
- render: ({ field }) => {
12793
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12794
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12795
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12796
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12505
+ ),
12506
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12507
+ /* @__PURE__ */ jsx(
12508
+ Form$2.Field,
12509
+ {
12510
+ control: form.control,
12511
+ name: "postal_code",
12512
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12513
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12514
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12515
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12516
+ ] })
12517
+ }
12518
+ ),
12519
+ /* @__PURE__ */ jsx(
12520
+ Form$2.Field,
12521
+ {
12522
+ control: form.control,
12523
+ name: "city",
12524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12528
+ ] })
12529
+ }
12530
+ )
12797
12531
  ] }),
12798
12532
  /* @__PURE__ */ jsx(
12799
- ConditionalTooltip,
12533
+ Form$2.Field,
12800
12534
  {
12801
- content: tooltipContent,
12802
- showTooltip: !locationId || !shippingProfileId,
12803
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12804
- Combobox,
12805
- {
12806
- options: shippingOptions.options,
12807
- fetchNextPage: shippingOptions.fetchNextPage,
12808
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12809
- searchValue: shippingOptions.searchValue,
12810
- onSearchValueChange: shippingOptions.onSearchValueChange,
12811
- placeholder: "Select shipping option",
12812
- ...field,
12813
- disabled: !locationId || !shippingProfileId
12814
- }
12815
- ) }) })
12535
+ control: form.control,
12536
+ name: "province",
12537
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12538
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12539
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12540
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12541
+ ] })
12816
12542
  }
12817
- )
12818
- ] }) });
12819
- }
12820
- }
12821
- );
12822
- };
12823
- const CustomAmountField = ({
12824
- control,
12825
- currencyCode
12826
- }) => {
12827
- return /* @__PURE__ */ jsx(
12828
- Form$2.Field,
12829
- {
12830
- control,
12831
- name: "custom_amount",
12832
- render: ({ field: { onChange, ...field } }) => {
12833
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12834
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12835
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12836
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12837
- ] }),
12838
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12839
- CurrencyInput,
12543
+ ),
12544
+ /* @__PURE__ */ jsx(
12545
+ Form$2.Field,
12840
12546
  {
12841
- ...field,
12842
- onValueChange: (value) => onChange(value),
12843
- symbol: getNativeSymbol(currencyCode),
12844
- code: currencyCode
12547
+ control: form.control,
12548
+ name: "phone",
12549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12550
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12553
+ ] })
12845
12554
  }
12846
- ) })
12847
- ] });
12848
- }
12555
+ )
12556
+ ] }) }),
12557
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12558
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12559
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12560
+ ] }) })
12561
+ ]
12849
12562
  }
12850
- );
12563
+ ) });
12851
12564
  };
12852
- const BillingAddress = () => {
12565
+ const schema$1 = addressSchema;
12566
+ const TransferOwnership = () => {
12853
12567
  const { id } = useParams();
12854
- const { order, isPending, isError, error } = useOrder(id, {
12855
- fields: "+billing_address"
12568
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12569
+ fields: "id,customer_id,customer.*"
12856
12570
  });
12857
12571
  if (isError) {
12858
12572
  throw error;
12859
12573
  }
12860
- const isReady = !isPending && !!order;
12574
+ const isReady = !isPending && !!draft_order;
12861
12575
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
12576
  /* @__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" }) })
12577
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12578
+ /* @__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" }) })
12865
12579
  ] }),
12866
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12580
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12867
12581
  ] });
12868
12582
  };
12869
- const BillingAddressForm = ({ order }) => {
12870
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12583
+ const TransferOwnershipForm = ({ order }) => {
12584
+ var _a, _b;
12871
12585
  const form = useForm({
12872
12586
  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) ?? ""
12587
+ customer_id: order.customer_id || ""
12883
12588
  },
12884
12589
  resolver: zodResolver(schema)
12885
12590
  });
12886
12591
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
12592
  const { handleSuccess } = useRouteModal();
12593
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12594
+ const currentCustomer = order.customer ? {
12595
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12596
+ value: order.customer.id
12597
+ } : null;
12888
12598
  const onSubmit = form.handleSubmit(async (data) => {
12889
12599
  await mutateAsync(
12890
- { billing_address: data },
12600
+ { customer_id: data.customer_id },
12891
12601
  {
12892
12602
  onSuccess: () => {
12603
+ toast.success("Customer updated");
12893
12604
  handleSuccess();
12894
12605
  },
12895
12606
  onError: (error) => {
@@ -12898,147 +12609,436 @@ const BillingAddressForm = ({ order }) => {
12898
12609
  }
12899
12610
  );
12900
12611
  });
12901
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
- KeyboundForm,
12612
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12613
+ KeyboundForm,
12614
+ {
12615
+ className: "flex flex-1 flex-col overflow-hidden",
12616
+ onSubmit,
12617
+ children: [
12618
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12619
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12620
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12621
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12622
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12623
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12624
+ ] }),
12625
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12626
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12627
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12628
+ ] })
12629
+ ] }),
12630
+ /* @__PURE__ */ jsx(
12631
+ CustomerField,
12632
+ {
12633
+ control: form.control,
12634
+ currentCustomerId: order.customer_id
12635
+ }
12636
+ )
12637
+ ] }),
12638
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12639
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12640
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12641
+ ] }) })
12642
+ ]
12643
+ }
12644
+ ) });
12645
+ };
12646
+ const CustomerField = ({ control, currentCustomerId }) => {
12647
+ const customers = useComboboxData({
12648
+ queryFn: async (params) => {
12649
+ return await sdk.admin.customer.list({
12650
+ ...params,
12651
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12652
+ });
12653
+ },
12654
+ queryKey: ["customers"],
12655
+ getOptions: (data) => {
12656
+ return data.customers.map((customer) => {
12657
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12658
+ return {
12659
+ label: name ? `${name} (${customer.email})` : customer.email,
12660
+ value: customer.id
12661
+ };
12662
+ });
12663
+ }
12664
+ });
12665
+ return /* @__PURE__ */ jsx(
12666
+ Form$2.Field,
12903
12667
  {
12904
- className: "flex flex-1 flex-col overflow-hidden",
12905
- onSubmit,
12668
+ name: "customer_id",
12669
+ control,
12670
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12671
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12672
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12673
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12674
+ ] }),
12675
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12676
+ Combobox,
12677
+ {
12678
+ options: customers.options,
12679
+ fetchNextPage: customers.fetchNextPage,
12680
+ isFetchingNextPage: customers.isFetchingNextPage,
12681
+ searchValue: customers.searchValue,
12682
+ onSearchValueChange: customers.onSearchValueChange,
12683
+ placeholder: "Select customer",
12684
+ ...field
12685
+ }
12686
+ ) }),
12687
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12688
+ ] })
12689
+ }
12690
+ );
12691
+ };
12692
+ const Illustration = () => {
12693
+ return /* @__PURE__ */ jsxs(
12694
+ "svg",
12695
+ {
12696
+ width: "280",
12697
+ height: "180",
12698
+ viewBox: "0 0 280 180",
12699
+ fill: "none",
12700
+ xmlns: "http://www.w3.org/2000/svg",
12906
12701
  children: [
12907
- /* @__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: [
12908
- /* @__PURE__ */ jsx(
12909
- Form$2.Field,
12702
+ /* @__PURE__ */ jsx(
12703
+ "rect",
12704
+ {
12705
+ x: "0.00428286",
12706
+ y: "-0.742904",
12707
+ width: "33.5",
12708
+ height: "65.5",
12709
+ rx: "6.75",
12710
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12711
+ fill: "#D4D4D8",
12712
+ stroke: "#52525B",
12713
+ strokeWidth: "1.5"
12714
+ }
12715
+ ),
12716
+ /* @__PURE__ */ jsx(
12717
+ "rect",
12718
+ {
12719
+ x: "0.00428286",
12720
+ y: "-0.742904",
12721
+ width: "33.5",
12722
+ height: "65.5",
12723
+ rx: "6.75",
12724
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12725
+ fill: "white",
12726
+ stroke: "#52525B",
12727
+ strokeWidth: "1.5"
12728
+ }
12729
+ ),
12730
+ /* @__PURE__ */ jsx(
12731
+ "path",
12732
+ {
12733
+ d: "M180.579 107.142L179.126 107.959",
12734
+ stroke: "#52525B",
12735
+ strokeWidth: "1.5",
12736
+ strokeLinecap: "round",
12737
+ strokeLinejoin: "round"
12738
+ }
12739
+ ),
12740
+ /* @__PURE__ */ jsx(
12741
+ "path",
12742
+ {
12743
+ opacity: "0.88",
12744
+ d: "M182.305 109.546L180.257 109.534",
12745
+ stroke: "#52525B",
12746
+ strokeWidth: "1.5",
12747
+ strokeLinecap: "round",
12748
+ strokeLinejoin: "round"
12749
+ }
12750
+ ),
12751
+ /* @__PURE__ */ jsx(
12752
+ "path",
12753
+ {
12754
+ opacity: "0.75",
12755
+ d: "M180.551 111.93L179.108 111.096",
12756
+ stroke: "#52525B",
12757
+ strokeWidth: "1.5",
12758
+ strokeLinecap: "round",
12759
+ strokeLinejoin: "round"
12760
+ }
12761
+ ),
12762
+ /* @__PURE__ */ jsx(
12763
+ "path",
12764
+ {
12765
+ opacity: "0.63",
12766
+ d: "M176.347 112.897L176.354 111.73",
12767
+ stroke: "#52525B",
12768
+ strokeWidth: "1.5",
12769
+ strokeLinecap: "round",
12770
+ strokeLinejoin: "round"
12771
+ }
12772
+ ),
12773
+ /* @__PURE__ */ jsx(
12774
+ "path",
12775
+ {
12776
+ opacity: "0.5",
12777
+ d: "M172.153 111.881L173.606 111.064",
12778
+ stroke: "#52525B",
12779
+ strokeWidth: "1.5",
12780
+ strokeLinecap: "round",
12781
+ strokeLinejoin: "round"
12782
+ }
12783
+ ),
12784
+ /* @__PURE__ */ jsx(
12785
+ "path",
12786
+ {
12787
+ opacity: "0.38",
12788
+ d: "M170.428 109.478L172.476 109.489",
12789
+ stroke: "#52525B",
12790
+ strokeWidth: "1.5",
12791
+ strokeLinecap: "round",
12792
+ strokeLinejoin: "round"
12793
+ }
12794
+ ),
12795
+ /* @__PURE__ */ jsx(
12796
+ "path",
12797
+ {
12798
+ opacity: "0.25",
12799
+ d: "M172.181 107.094L173.624 107.928",
12800
+ stroke: "#52525B",
12801
+ strokeWidth: "1.5",
12802
+ strokeLinecap: "round",
12803
+ strokeLinejoin: "round"
12804
+ }
12805
+ ),
12806
+ /* @__PURE__ */ jsx(
12807
+ "path",
12808
+ {
12809
+ opacity: "0.13",
12810
+ d: "M176.386 106.126L176.379 107.294",
12811
+ stroke: "#52525B",
12812
+ strokeWidth: "1.5",
12813
+ strokeLinecap: "round",
12814
+ strokeLinejoin: "round"
12815
+ }
12816
+ ),
12817
+ /* @__PURE__ */ jsx(
12818
+ "rect",
12819
+ {
12820
+ width: "12",
12821
+ height: "3",
12822
+ rx: "1.5",
12823
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12824
+ fill: "#D4D4D8"
12825
+ }
12826
+ ),
12827
+ /* @__PURE__ */ jsx(
12828
+ "rect",
12829
+ {
12830
+ x: "0.00428286",
12831
+ y: "-0.742904",
12832
+ width: "33.5",
12833
+ height: "65.5",
12834
+ rx: "6.75",
12835
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12836
+ fill: "#D4D4D8",
12837
+ stroke: "#52525B",
12838
+ strokeWidth: "1.5"
12839
+ }
12840
+ ),
12841
+ /* @__PURE__ */ jsx(
12842
+ "rect",
12843
+ {
12844
+ x: "0.00428286",
12845
+ y: "-0.742904",
12846
+ width: "33.5",
12847
+ height: "65.5",
12848
+ rx: "6.75",
12849
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12850
+ fill: "white",
12851
+ stroke: "#52525B",
12852
+ strokeWidth: "1.5"
12853
+ }
12854
+ ),
12855
+ /* @__PURE__ */ jsx(
12856
+ "rect",
12857
+ {
12858
+ width: "12",
12859
+ height: "3",
12860
+ rx: "1.5",
12861
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12862
+ fill: "#D4D4D8"
12863
+ }
12864
+ ),
12865
+ /* @__PURE__ */ jsx(
12866
+ "rect",
12867
+ {
12868
+ width: "17",
12869
+ height: "3",
12870
+ rx: "1.5",
12871
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12872
+ fill: "#D4D4D8"
12873
+ }
12874
+ ),
12875
+ /* @__PURE__ */ jsx(
12876
+ "rect",
12877
+ {
12878
+ width: "12",
12879
+ height: "3",
12880
+ rx: "1.5",
12881
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12882
+ fill: "#D4D4D8"
12883
+ }
12884
+ ),
12885
+ /* @__PURE__ */ jsx(
12886
+ "path",
12887
+ {
12888
+ 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",
12889
+ fill: "#A1A1AA"
12890
+ }
12891
+ ),
12892
+ /* @__PURE__ */ jsx(
12893
+ "rect",
12894
+ {
12895
+ width: "17",
12896
+ height: "3",
12897
+ rx: "1.5",
12898
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12899
+ fill: "#A1A1AA"
12900
+ }
12901
+ ),
12902
+ /* @__PURE__ */ jsx(
12903
+ "rect",
12904
+ {
12905
+ width: "12",
12906
+ height: "3",
12907
+ rx: "1.5",
12908
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12909
+ fill: "#A1A1AA"
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ "path",
12914
+ {
12915
+ 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",
12916
+ fill: "#52525B"
12917
+ }
12918
+ ),
12919
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12920
+ "path",
12921
+ {
12922
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12923
+ stroke: "#A1A1AA",
12924
+ strokeWidth: "1.5",
12925
+ strokeLinecap: "round",
12926
+ strokeLinejoin: "round"
12927
+ }
12928
+ ) }),
12929
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12930
+ "path",
12931
+ {
12932
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12933
+ stroke: "#A1A1AA",
12934
+ strokeWidth: "1.5",
12935
+ strokeLinecap: "round",
12936
+ strokeLinejoin: "round"
12937
+ }
12938
+ ) }),
12939
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12940
+ "path",
12941
+ {
12942
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12943
+ stroke: "#A1A1AA",
12944
+ strokeWidth: "1.5",
12945
+ strokeLinecap: "round",
12946
+ strokeLinejoin: "round"
12947
+ }
12948
+ ) }),
12949
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12950
+ "path",
12951
+ {
12952
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12953
+ stroke: "#A1A1AA",
12954
+ strokeWidth: "1.5",
12955
+ strokeLinecap: "round",
12956
+ strokeLinejoin: "round"
12957
+ }
12958
+ ) }),
12959
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
+ "path",
12961
+ {
12962
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
+ stroke: "#A1A1AA",
12964
+ strokeWidth: "1.5",
12965
+ strokeLinecap: "round",
12966
+ strokeLinejoin: "round"
12967
+ }
12968
+ ) }),
12969
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
+ "path",
12971
+ {
12972
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
+ stroke: "#A1A1AA",
12974
+ strokeWidth: "1.5",
12975
+ strokeLinecap: "round",
12976
+ strokeLinejoin: "round"
12977
+ }
12978
+ ) }),
12979
+ /* @__PURE__ */ jsxs("defs", { children: [
12980
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
+ "rect",
12910
12982
  {
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
- ] })
12983
+ width: "12",
12984
+ height: "12",
12985
+ fill: "white",
12986
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12918
12987
  }
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,
12988
+ ) }),
12989
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
+ "rect",
12948
12991
  {
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
- ] })
12992
+ width: "12",
12993
+ height: "12",
12994
+ fill: "white",
12995
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12956
12996
  }
12957
- ),
12958
- /* @__PURE__ */ jsx(
12959
- Form$2.Field,
12997
+ ) }),
12998
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
+ "rect",
12960
13000
  {
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
- ] })
13001
+ width: "12",
13002
+ height: "12",
13003
+ fill: "white",
13004
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12968
13005
  }
12969
- ),
12970
- /* @__PURE__ */ jsx(
12971
- Form$2.Field,
13006
+ ) }),
13007
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
+ "rect",
12972
13009
  {
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
- ] })
13010
+ width: "12",
13011
+ height: "12",
13012
+ fill: "white",
13013
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12980
13014
  }
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,
13015
+ ) }),
13016
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
+ "rect",
13010
13018
  {
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
- ] })
13019
+ width: "12",
13020
+ height: "12",
13021
+ fill: "white",
13022
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13018
13023
  }
13019
- ),
13020
- /* @__PURE__ */ jsx(
13021
- Form$2.Field,
13024
+ ) }),
13025
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
+ "rect",
13022
13027
  {
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
- ] })
13028
+ width: "12",
13029
+ height: "12",
13030
+ fill: "white",
13031
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13030
13032
  }
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
- ] }) })
13033
+ ) })
13034
+ ] })
13037
13035
  ]
13038
13036
  }
13039
- ) });
13037
+ );
13040
13038
  };
13041
- const schema = addressSchema;
13039
+ const schema = objectType({
13040
+ customer_id: stringType().min(1)
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13064,17 +13064,21 @@ const routeModule = {
13064
13064
  path: "/draft-orders/:id/custom-items"
13065
13065
  },
13066
13066
  {
13067
- Component: Email,
13068
- path: "/draft-orders/:id/email"
13067
+ Component: BillingAddress,
13068
+ path: "/draft-orders/:id/billing-address"
13069
13069
  },
13070
13070
  {
13071
- Component: Metadata,
13072
- path: "/draft-orders/:id/metadata"
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13073
13073
  },
13074
13074
  {
13075
13075
  Component: Items,
13076
13076
  path: "/draft-orders/:id/items"
13077
13077
  },
13078
+ {
13079
+ Component: Metadata,
13080
+ path: "/draft-orders/:id/metadata"
13081
+ },
13078
13082
  {
13079
13083
  Component: Promotions,
13080
13084
  path: "/draft-orders/:id/promotions"
@@ -13083,6 +13087,10 @@ const routeModule = {
13083
13087
  Component: SalesChannel,
13084
13088
  path: "/draft-orders/:id/sales-channel"
13085
13089
  },
13090
+ {
13091
+ Component: Shipping,
13092
+ path: "/draft-orders/:id/shipping"
13093
+ },
13086
13094
  {
13087
13095
  Component: ShippingAddress,
13088
13096
  path: "/draft-orders/:id/shipping-address"
@@ -13090,14 +13098,6 @@ const routeModule = {
13090
13098
  {
13091
13099
  Component: TransferOwnership,
13092
13100
  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
13101
  }
13102
13102
  ]
13103
13103
  }