@medusajs/draft-order 2.11.0-preview-20251016060156 → 2.11.0-preview-20251016120206

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";
@@ -9757,6 +9757,27 @@ const BillingAddressForm = ({ order }) => {
9757
9757
  ) });
9758
9758
  };
9759
9759
  const schema$5 = addressSchema;
9760
+ const CustomItems = () => {
9761
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
+ ] });
9765
+ };
9766
+ const CustomItemsForm = () => {
9767
+ const form = useForm({
9768
+ resolver: zodResolver(schema$4)
9769
+ });
9770
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
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", children: "Save" })
9775
+ ] }) })
9776
+ ] }) });
9777
+ };
9778
+ const schema$4 = objectType({
9779
+ email: stringType().email()
9780
+ });
9760
9781
  const Email = () => {
9761
9782
  const { id } = useParams();
9762
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9779,7 +9800,7 @@ const EmailForm = ({ order }) => {
9779
9800
  defaultValues: {
9780
9801
  email: order.email ?? ""
9781
9802
  },
9782
- resolver: zodResolver(schema$4)
9803
+ resolver: zodResolver(schema$3)
9783
9804
  });
9784
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9785
9806
  const { handleSuccess } = useRouteModal();
@@ -9822,46 +9843,130 @@ const EmailForm = ({ order }) => {
9822
9843
  }
9823
9844
  ) });
9824
9845
  };
9825
- const schema$4 = objectType({
9826
- email: stringType().email()
9827
- });
9828
- const CustomItems = () => {
9829
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9830
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9831
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9832
- ] });
9833
- };
9834
- const CustomItemsForm = () => {
9835
- const form = useForm({
9836
- resolver: zodResolver(schema$3)
9837
- });
9838
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9839
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9840
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9841
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9842
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9843
- ] }) })
9844
- ] }) });
9845
- };
9846
9846
  const schema$3 = objectType({
9847
9847
  email: stringType().email()
9848
9848
  });
9849
- const PROMOTION_QUERY_KEY = "promotions";
9850
- const promotionsQueryKeys = {
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
+ };
9879
+ return /* @__PURE__ */ jsxs(
9880
+ "div",
9881
+ {
9882
+ className: clx(
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
+ },
9889
+ className
9890
+ ),
9891
+ children: [
9892
+ /* @__PURE__ */ jsx(
9893
+ "input",
9894
+ {
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
9908
+ }
9909
+ ),
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
+ )
9954
+ ]
9955
+ }
9956
+ );
9957
+ }
9958
+ );
9959
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9960
+ const productVariantsQueryKeys = {
9851
9961
  list: (query2) => [
9852
- PROMOTION_QUERY_KEY,
9853
- query2 ? query2 : void 0
9854
- ],
9855
- detail: (id, query2) => [
9856
- PROMOTION_QUERY_KEY,
9857
- id,
9962
+ PRODUCT_VARIANTS_QUERY_KEY,
9858
9963
  query2 ? query2 : void 0
9859
9964
  ]
9860
9965
  };
9861
- const usePromotions = (query2, options) => {
9966
+ const useProductVariants = (query2, options) => {
9862
9967
  const { data, ...rest } = useQuery({
9863
- queryKey: promotionsQueryKeys.list(query2),
9864
- queryFn: async () => sdk.admin.promotion.list(query2),
9968
+ queryKey: productVariantsQueryKeys.list(query2),
9969
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9865
9970
  ...options
9866
9971
  });
9867
9972
  return { ...data, ...rest };
@@ -9912,97 +10017,77 @@ const useInitiateOrderEdit = ({
9912
10017
  run();
9913
10018
  }, [preview, navigate, mutateAsync]);
9914
10019
  };
9915
- const Promotions = () => {
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 = () => {
9916
10025
  const { id } = useParams();
9917
10026
  const {
9918
10027
  order: preview,
10028
+ isPending: isPreviewPending,
9919
10029
  isError: isPreviewError,
9920
10030
  error: previewError
9921
- } = useOrderPreview(id, void 0);
10031
+ } = useOrderPreview(id, void 0, {
10032
+ placeholderData: keepPreviousData
10033
+ });
9922
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
+ );
9923
10044
  const { onCancel } = useCancelOrderEdit({ preview });
10045
+ if (isError) {
10046
+ throw error;
10047
+ }
9924
10048
  if (isPreviewError) {
9925
10049
  throw previewError;
9926
10050
  }
9927
- const isReady = !!preview;
9928
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
9929
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
9930
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
9931
- ] });
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
+ ] }) });
9932
10056
  };
9933
- const PromotionForm = ({ preview }) => {
9934
- const { items, shipping_methods } = preview;
10057
+ const ItemsForm = ({ preview, currencyCode }) => {
10058
+ var _a;
9935
10059
  const [isSubmitting, setIsSubmitting] = useState(false);
9936
- const [comboboxValue, setComboboxValue] = useState("");
10060
+ const [modalContent, setModalContent] = useState(
10061
+ null
10062
+ );
9937
10063
  const { handleSuccess } = useRouteModal();
9938
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
9939
- const promoIds = getPromotionIds(items, shipping_methods);
9940
- const { promotions, isPending, isError, error } = usePromotions(
9941
- {
9942
- id: promoIds
9943
- },
9944
- {
9945
- enabled: !!promoIds.length
9946
- }
9947
- );
9948
- const comboboxData = useComboboxData({
9949
- queryKey: ["promotions", "combobox", promoIds],
9950
- queryFn: async (params) => {
9951
- return await sdk.admin.promotion.list({
9952
- ...params,
9953
- id: {
9954
- $nin: promoIds
9955
- }
9956
- });
9957
- },
9958
- getOptions: (data) => {
9959
- return data.promotions.map((promotion) => ({
9960
- label: promotion.code,
9961
- value: promotion.code
9962
- }));
9963
- }
9964
- });
9965
- const add = async (value) => {
9966
- if (!value) {
9967
- return;
9968
- }
9969
- addPromotions(
9970
- {
9971
- promo_codes: [value]
9972
- },
9973
- {
9974
- onError: (e) => {
9975
- toast.error(e.message);
9976
- comboboxData.onSearchValueChange("");
9977
- setComboboxValue("");
9978
- },
9979
- onSuccess: () => {
9980
- comboboxData.onSearchValueChange("");
9981
- setComboboxValue("");
9982
- }
9983
- }
9984
- );
9985
- };
9986
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
9987
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
9988
- const onSubmit = async () => {
9989
- setIsSubmitting(true);
9990
- let requestSucceeded = false;
9991
- await requestOrderEdit(void 0, {
9992
- onError: (e) => {
9993
- toast.error(e.message);
9994
- },
9995
- onSuccess: () => {
9996
- requestSucceeded = true;
9997
- }
9998
- });
9999
- if (!requestSucceeded) {
10000
- setIsSubmitting(false);
10001
- return;
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}`);
10079
+ },
10080
+ onSuccess: () => {
10081
+ requestSucceeded = true;
10082
+ }
10083
+ });
10084
+ if (!requestSucceeded) {
10085
+ setIsSubmitting(false);
10086
+ return;
10002
10087
  }
10003
10088
  await confirmOrderEdit(void 0, {
10004
10089
  onError: (e) => {
10005
- toast.error(e.message);
10090
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10006
10091
  },
10007
10092
  onSuccess: () => {
10008
10093
  handleSuccess();
@@ -10012,905 +10097,352 @@ const PromotionForm = ({ preview }) => {
10012
10097
  }
10013
10098
  });
10014
10099
  };
10015
- if (isError) {
10016
- throw error;
10017
- }
10018
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10019
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10020
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10021
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10022
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10023
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10024
- ] }),
10025
- /* @__PURE__ */ jsx(
10026
- Combobox,
10027
- {
10028
- id: "promotion-combobox",
10029
- "aria-describedby": "promotion-combobox-hint",
10030
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10031
- fetchNextPage: comboboxData.fetchNextPage,
10032
- options: comboboxData.options,
10033
- onSearchValueChange: comboboxData.onSearchValueChange,
10034
- searchValue: comboboxData.searchValue,
10035
- disabled: comboboxData.disabled || isAddingPromotions,
10036
- onChange: add,
10037
- value: comboboxValue
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);
10038
10126
  }
10039
- )
10040
- ] }),
10041
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10042
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10043
- PromotionItem,
10044
- {
10045
- promotion,
10046
- orderId: preview.id,
10047
- isLoading: isPending
10048
10127
  },
10049
- promotion.id
10050
- )) })
10051
- ] }) }),
10052
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10053
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
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: [
10154
+ /* @__PURE__ */ jsx(
10155
+ StackedModalTrigger$1,
10156
+ {
10157
+ type: "add-items",
10158
+ setModalContent
10159
+ }
10160
+ ),
10161
+ /* @__PURE__ */ jsx(
10162
+ StackedModalTrigger$1,
10163
+ {
10164
+ type: "add-custom-item",
10165
+ setModalContent
10166
+ }
10167
+ )
10168
+ ] })
10169
+ ] })
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,
10205
+ {
10206
+ size: "small",
10207
+ leading: "compact",
10208
+ className: "text-ui-fg-subtle",
10209
+ children: [
10210
+ itemCount,
10211
+ " ",
10212
+ itemCount === 1 ? "item" : "items"
10213
+ ]
10214
+ }
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,
10221
+ {
10222
+ orderId: preview.id,
10223
+ currencyCode
10224
+ }
10225
+ ) : null)
10226
+ ]
10227
+ }
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" }) }),
10054
10231
  /* @__PURE__ */ jsx(
10055
10232
  Button,
10056
10233
  {
10057
10234
  size: "small",
10058
- type: "submit",
10059
- isLoading: isSubmitting || isAddingPromotions,
10235
+ type: "button",
10236
+ onClick: onSubmit,
10237
+ isLoading: isSubmitting,
10060
10238
  children: "Save"
10061
10239
  }
10062
10240
  )
10063
10241
  ] }) })
10064
10242
  ] });
10065
10243
  };
10066
- const PromotionItem = ({
10067
- promotion,
10068
- orderId,
10069
- isLoading
10070
- }) => {
10071
- var _a;
10072
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10073
- const onRemove = async () => {
10074
- removePromotions(
10075
- {
10076
- promo_codes: [promotion.code]
10077
- },
10078
- {
10079
- onError: (e) => {
10080
- toast.error(e.message);
10081
- }
10082
- }
10083
- );
10084
- };
10085
- const displayValue = getDisplayValue(promotion);
10086
- return /* @__PURE__ */ jsxs(
10087
- "div",
10088
- {
10089
- className: clx(
10090
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10091
- {
10092
- "animate-pulse": isLoading
10093
- }
10094
- ),
10095
- children: [
10096
- /* @__PURE__ */ jsxs("div", { children: [
10097
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10098
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10099
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
10100
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
10101
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
10102
- ] }),
10103
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10104
- ] })
10105
- ] }),
10106
- /* @__PURE__ */ jsx(
10107
- IconButton,
10108
- {
10109
- size: "small",
10110
- type: "button",
10111
- variant: "transparent",
10112
- onClick: onRemove,
10113
- isLoading: isPending || isLoading,
10114
- children: /* @__PURE__ */ jsx(XMark, {})
10115
- }
10116
- )
10117
- ]
10118
- },
10119
- promotion.id
10120
- );
10121
- };
10122
- function getDisplayValue(promotion) {
10123
- var _a, _b, _c, _d;
10124
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10125
- if (!value) {
10126
- return null;
10127
- }
10128
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10129
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10130
- if (!currency) {
10131
- return null;
10132
- }
10133
- return getLocaleAmount(value, currency);
10134
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10135
- return formatPercentage(value);
10136
- }
10137
- return null;
10138
- }
10139
- const formatter = new Intl.NumberFormat([], {
10140
- style: "percent",
10141
- minimumFractionDigits: 2
10142
- });
10143
- const formatPercentage = (value, isPercentageValue = false) => {
10144
- let val = value || 0;
10145
- if (!isPercentageValue) {
10146
- val = val / 100;
10147
- }
10148
- return formatter.format(val);
10149
- };
10150
- function getPromotionIds(items, shippingMethods) {
10151
- const promotionIds = /* @__PURE__ */ new Set();
10152
- for (const item of items) {
10153
- if (item.adjustments) {
10154
- for (const adjustment of item.adjustments) {
10155
- if (adjustment.promotion_id) {
10156
- promotionIds.add(adjustment.promotion_id);
10157
- }
10158
- }
10159
- }
10160
- }
10161
- for (const shippingMethod of shippingMethods) {
10162
- if (shippingMethod.adjustments) {
10163
- for (const adjustment of shippingMethod.adjustments) {
10164
- if (adjustment.promotion_id) {
10165
- promotionIds.add(adjustment.promotion_id);
10166
- }
10167
- }
10168
- }
10169
- }
10170
- return Array.from(promotionIds);
10171
- }
10172
- const InlineTip = forwardRef(
10173
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10174
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10175
- return /* @__PURE__ */ jsxs(
10176
- "div",
10177
- {
10178
- ref,
10179
- className: clx(
10180
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10181
- className
10182
- ),
10183
- ...props,
10184
- children: [
10185
- /* @__PURE__ */ jsx(
10186
- "div",
10187
- {
10188
- role: "presentation",
10189
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10190
- "bg-ui-tag-orange-icon": variant === "warning"
10191
- })
10192
- }
10193
- ),
10194
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10195
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10196
- labelValue,
10197
- ":"
10198
- ] }),
10199
- " ",
10200
- children
10201
- ] })
10202
- ]
10203
- }
10204
- );
10205
- }
10206
- );
10207
- InlineTip.displayName = "InlineTip";
10208
- const MetadataFieldSchema = objectType({
10209
- key: stringType(),
10210
- disabled: booleanType().optional(),
10211
- value: anyType()
10212
- });
10213
- const MetadataSchema = objectType({
10214
- metadata: arrayType(MetadataFieldSchema)
10215
- });
10216
- const Metadata = () => {
10217
- const { id } = useParams();
10218
- const { order, isPending, isError, error } = useOrder(id, {
10219
- fields: "metadata"
10220
- });
10221
- if (isError) {
10222
- throw error;
10244
+ const Item = ({ item, preview, currencyCode }) => {
10245
+ if (item.variant_id) {
10246
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10223
10247
  }
10224
- const isReady = !isPending && !!order;
10225
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10226
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10227
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10228
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10229
- ] }),
10230
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10231
- ] });
10248
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10232
10249
  };
10233
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10234
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10235
- const MetadataForm = ({ orderId, metadata }) => {
10236
- const { handleSuccess } = useRouteModal();
10237
- const hasUneditableRows = getHasUneditableRows(metadata);
10238
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10250
+ const VariantItem = ({ item, preview, currencyCode }) => {
10251
+ const [editing, setEditing] = useState(false);
10239
10252
  const form = useForm({
10240
10253
  defaultValues: {
10241
- metadata: getDefaultValues(metadata)
10254
+ quantity: item.quantity,
10255
+ unit_price: item.unit_price
10242
10256
  },
10243
- resolver: zodResolver(MetadataSchema)
10257
+ resolver: zodResolver(variantItemSchema)
10244
10258
  });
10245
- const handleSubmit = form.handleSubmit(async (data) => {
10246
- const parsedData = parseValues(data);
10247
- await mutateAsync(
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;
10270
+ }
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
+ }
10285
+ }
10286
+ );
10287
+ return;
10288
+ }
10289
+ await updateActionItem(
10248
10290
  {
10249
- metadata: parsedData
10291
+ action_id: actionId,
10292
+ quantity: data.quantity,
10293
+ unit_price: convertNumber(data.unit_price)
10250
10294
  },
10251
10295
  {
10252
10296
  onSuccess: () => {
10253
- toast.success("Metadata updated");
10254
- handleSuccess();
10297
+ setEditing(false);
10255
10298
  },
10256
- onError: (error) => {
10257
- toast.error(error.message);
10299
+ onError: (e) => {
10300
+ toast.error(e.message);
10258
10301
  }
10259
10302
  }
10260
10303
  );
10261
10304
  });
10262
- const { fields, insert, remove } = useFieldArray({
10263
- control: form.control,
10264
- name: "metadata"
10265
- });
10266
- function deleteRow(index) {
10267
- remove(index);
10268
- if (fields.length === 1) {
10269
- insert(0, {
10270
- key: "",
10271
- value: "",
10272
- disabled: false
10273
- });
10274
- }
10275
- }
10276
- function insertRow(index, position) {
10277
- insert(index + (position === "above" ? 0 : 1), {
10278
- key: "",
10279
- value: "",
10280
- disabled: false
10281
- });
10282
- }
10283
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10284
- KeyboundForm,
10285
- {
10286
- onSubmit: handleSubmit,
10287
- className: "flex flex-1 flex-col overflow-hidden",
10288
- children: [
10289
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10290
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10291
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10292
- /* @__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" }) }),
10293
- /* @__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" }) })
10294
- ] }),
10295
- fields.map((field, index) => {
10296
- const isDisabled = field.disabled || false;
10297
- let placeholder = "-";
10298
- if (typeof field.value === "object") {
10299
- placeholder = "{ ... }";
10300
- }
10301
- if (Array.isArray(field.value)) {
10302
- placeholder = "[ ... ]";
10303
- }
10304
- return /* @__PURE__ */ jsx(
10305
- ConditionalTooltip,
10306
- {
10307
- showTooltip: isDisabled,
10308
- content: "This row is disabled because it contains non-primitive data.",
10309
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10310
- /* @__PURE__ */ jsxs(
10311
- "div",
10312
- {
10313
- className: clx("grid grid-cols-2 divide-x", {
10314
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10315
- }),
10316
- children: [
10317
- /* @__PURE__ */ jsx(
10318
- Form$2.Field,
10319
- {
10320
- control: form.control,
10321
- name: `metadata.${index}.key`,
10322
- render: ({ field: field2 }) => {
10323
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10324
- GridInput,
10325
- {
10326
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10327
- ...field2,
10328
- disabled: isDisabled,
10329
- placeholder: "Key"
10330
- }
10331
- ) }) });
10332
- }
10333
- }
10334
- ),
10335
- /* @__PURE__ */ jsx(
10336
- Form$2.Field,
10337
- {
10338
- control: form.control,
10339
- name: `metadata.${index}.value`,
10340
- render: ({ field: { value, ...field2 } }) => {
10341
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10342
- GridInput,
10343
- {
10344
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10345
- ...field2,
10346
- value: isDisabled ? placeholder : value,
10347
- disabled: isDisabled,
10348
- placeholder: "Value"
10349
- }
10350
- ) }) });
10351
- }
10352
- }
10353
- )
10354
- ]
10355
- }
10356
- ),
10357
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10358
- /* @__PURE__ */ jsx(
10359
- DropdownMenu.Trigger,
10360
- {
10361
- className: clx(
10362
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10363
- {
10364
- hidden: isDisabled
10365
- }
10366
- ),
10367
- disabled: isDisabled,
10368
- asChild: true,
10369
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10370
- }
10371
- ),
10372
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10373
- /* @__PURE__ */ jsxs(
10374
- DropdownMenu.Item,
10375
- {
10376
- className: "gap-x-2",
10377
- onClick: () => insertRow(index, "above"),
10378
- children: [
10379
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10380
- "Insert row above"
10381
- ]
10382
- }
10383
- ),
10384
- /* @__PURE__ */ jsxs(
10385
- DropdownMenu.Item,
10386
- {
10387
- className: "gap-x-2",
10388
- onClick: () => insertRow(index, "below"),
10389
- children: [
10390
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10391
- "Insert row below"
10392
- ]
10393
- }
10394
- ),
10395
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10396
- /* @__PURE__ */ jsxs(
10397
- DropdownMenu.Item,
10398
- {
10399
- className: "gap-x-2",
10400
- onClick: () => deleteRow(index),
10401
- children: [
10402
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10403
- "Delete row"
10404
- ]
10405
- }
10406
- )
10407
- ] })
10408
- ] })
10409
- ] })
10410
- },
10411
- field.id
10412
- );
10413
- })
10414
- ] }),
10415
- 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." })
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
+ )
10416
10330
  ] }),
10417
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10418
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10419
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10420
- ] }) })
10421
- ]
10422
- }
10423
- ) });
10424
- };
10425
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10426
- return /* @__PURE__ */ jsx(
10427
- "input",
10428
- {
10429
- ref,
10430
- ...props,
10431
- autoComplete: "off",
10432
- className: clx(
10433
- "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",
10434
- className
10435
- )
10436
- }
10437
- );
10438
- });
10439
- GridInput.displayName = "MetadataForm.GridInput";
10440
- const PlaceholderInner = () => {
10441
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10442
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10443
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10444
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10445
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10446
- ] }) })
10447
- ] });
10448
- };
10449
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10450
- function getDefaultValues(metadata) {
10451
- if (!metadata || !Object.keys(metadata).length) {
10452
- return [
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,
10453
10344
  {
10454
- key: "",
10455
- value: "",
10456
- disabled: false
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 }) }) });
10349
+ }
10457
10350
  }
10458
- ];
10459
- }
10460
- return Object.entries(metadata).map(([key, value]) => {
10461
- if (!EDITABLE_TYPES.includes(typeof value)) {
10462
- return {
10463
- key,
10464
- value,
10465
- disabled: true
10466
- };
10467
- }
10468
- let stringValue = value;
10469
- if (typeof value !== "string") {
10470
- stringValue = JSON.stringify(value);
10471
- }
10472
- return {
10473
- key,
10474
- value: stringValue,
10475
- original_key: key
10476
- };
10477
- });
10478
- }
10479
- function parseValues(values) {
10480
- const metadata = values.metadata;
10481
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10482
- if (isEmpty) {
10483
- return null;
10484
- }
10485
- const update = {};
10486
- metadata.forEach((field) => {
10487
- let key = field.key;
10488
- let value = field.value;
10489
- const disabled = field.disabled;
10490
- if (!key || !value) {
10491
- return;
10492
- }
10493
- if (disabled) {
10494
- update[key] = value;
10495
- return;
10496
- }
10497
- key = key.trim();
10498
- value = value.trim();
10499
- if (value === "true") {
10500
- update[key] = true;
10501
- } else if (value === "false") {
10502
- update[key] = false;
10503
- } else {
10504
- const parsedNumber = parseFloat(value);
10505
- if (!isNaN(parsedNumber)) {
10506
- update[key] = parsedNumber;
10507
- } else {
10508
- update[key] = value;
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,
10354
+ {
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
+ }
10509
10368
  }
10510
- }
10511
- });
10512
- return update;
10513
- }
10514
- function getHasUneditableRows(metadata) {
10515
- if (!metadata) {
10516
- return false;
10517
- }
10518
- return Object.values(metadata).some(
10519
- (value) => !EDITABLE_TYPES.includes(typeof value)
10520
- );
10521
- }
10522
- const NumberInput = forwardRef(
10523
- ({
10524
- value,
10525
- onChange,
10526
- size = "base",
10527
- min = 0,
10528
- max = 100,
10529
- step = 1,
10530
- className,
10531
- disabled,
10532
- ...props
10533
- }, ref) => {
10534
- const handleChange = (event) => {
10535
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10536
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10537
- onChange(newValue);
10538
- }
10539
- };
10540
- const handleIncrement = () => {
10541
- const newValue = value + step;
10542
- if (max === void 0 || newValue <= max) {
10543
- onChange(newValue);
10544
- }
10545
- };
10546
- const handleDecrement = () => {
10547
- const newValue = value - step;
10548
- if (min === void 0 || newValue >= min) {
10549
- onChange(newValue);
10550
- }
10551
- };
10552
- return /* @__PURE__ */ jsxs(
10553
- "div",
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,
10554
10372
  {
10555
- className: clx(
10556
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10557
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10558
- {
10559
- "h-7": size === "small",
10560
- "h-8": size === "base"
10561
- },
10562
- className
10563
- ),
10564
- children: [
10565
- /* @__PURE__ */ jsx(
10566
- "input",
10567
- {
10568
- ref,
10569
- type: "number",
10570
- value,
10571
- onChange: handleChange,
10572
- min,
10573
- max,
10574
- step,
10575
- className: clx(
10576
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10577
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10578
- "placeholder:text-ui-fg-muted"
10579
- ),
10580
- ...props
10581
- }
10582
- ),
10583
- /* @__PURE__ */ jsxs(
10584
- "button",
10585
- {
10586
- className: clx(
10587
- "flex items-center justify-center outline-none transition-fg",
10588
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10589
- "focus:bg-ui-bg-field-component-hover",
10590
- "hover:bg-ui-bg-field-component-hover",
10591
- {
10592
- "size-7": size === "small",
10593
- "size-8": size === "base"
10594
- }
10595
- ),
10596
- type: "button",
10597
- onClick: handleDecrement,
10598
- disabled: min !== void 0 && value <= min || disabled,
10599
- children: [
10600
- /* @__PURE__ */ jsx(Minus, {}),
10601
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10602
- ]
10603
- }
10604
- ),
10605
- /* @__PURE__ */ jsxs(
10606
- "button",
10607
- {
10608
- className: clx(
10609
- "flex items-center justify-center outline-none transition-fg",
10610
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10611
- "focus:bg-ui-bg-field-hover",
10612
- "hover:bg-ui-bg-field-hover",
10613
- {
10614
- "size-7": size === "small",
10615
- "size-8": size === "base"
10616
- }
10617
- ),
10618
- type: "button",
10619
- onClick: handleIncrement,
10620
- disabled: max !== void 0 && value >= max || disabled,
10621
- children: [
10622
- /* @__PURE__ */ jsx(Plus, {}),
10623
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10624
- ]
10625
- }
10626
- )
10627
- ]
10373
+ type: "button",
10374
+ size: "small",
10375
+ onClick: editing ? onSubmit : () => {
10376
+ setEditing(true);
10377
+ },
10378
+ disabled: isPending,
10379
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10628
10380
  }
10629
- );
10630
- }
10631
- );
10632
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10633
- const productVariantsQueryKeys = {
10634
- list: (query2) => [
10635
- PRODUCT_VARIANTS_QUERY_KEY,
10636
- query2 ? query2 : void 0
10637
- ]
10638
- };
10639
- const useProductVariants = (query2, options) => {
10640
- const { data, ...rest } = useQuery({
10641
- queryKey: productVariantsQueryKeys.list(query2),
10642
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10643
- ...options
10644
- });
10645
- return { ...data, ...rest };
10381
+ )
10382
+ ] }) }) });
10646
10383
  };
10647
- function convertNumber(value) {
10648
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10649
- }
10650
- const STACKED_MODAL_ID = "items_stacked_modal";
10651
- const Items = () => {
10652
- const { id } = useParams();
10653
- const {
10654
- order: preview,
10655
- isPending: isPreviewPending,
10656
- isError: isPreviewError,
10657
- error: previewError
10658
- } = useOrderPreview(id, void 0, {
10659
- placeholderData: keepPreviousData
10660
- });
10661
- useInitiateOrderEdit({ preview });
10662
- const { draft_order, isPending, isError, error } = useDraftOrder(
10663
- id,
10664
- {
10665
- fields: "currency_code"
10384
+ const variantItemSchema = objectType({
10385
+ quantity: numberType(),
10386
+ unit_price: unionType([numberType(), stringType()])
10387
+ });
10388
+ const CustomItem = ({ item, preview, currencyCode }) => {
10389
+ const [editing, setEditing] = useState(false);
10390
+ const { quantity, unit_price, title } = item;
10391
+ const form = useForm({
10392
+ defaultValues: {
10393
+ title,
10394
+ quantity,
10395
+ unit_price
10666
10396
  },
10667
- {
10668
- enabled: !!id
10669
- }
10670
- );
10671
- const { onCancel } = useCancelOrderEdit({ preview });
10672
- if (isError) {
10673
- throw error;
10674
- }
10675
- if (isPreviewError) {
10676
- throw previewError;
10677
- }
10678
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10679
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10680
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10681
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10682
- ] }) });
10683
- };
10684
- const ItemsForm = ({ preview, currencyCode }) => {
10685
- var _a;
10686
- const [isSubmitting, setIsSubmitting] = useState(false);
10687
- const [modalContent, setModalContent] = useState(
10688
- null
10689
- );
10690
- const { handleSuccess } = useRouteModal();
10691
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10692
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10693
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10694
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10695
- const matches = useMemo(() => {
10696
- return matchSorter(preview.items, query2, {
10697
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10698
- });
10699
- }, [preview.items, query2]);
10700
- const onSubmit = async () => {
10701
- setIsSubmitting(true);
10702
- let requestSucceeded = false;
10703
- await requestOrderEdit(void 0, {
10704
- onError: (e) => {
10705
- toast.error(`Failed to request order edit: ${e.message}`);
10706
- },
10707
- onSuccess: () => {
10708
- requestSucceeded = true;
10709
- }
10397
+ resolver: zodResolver(customItemSchema)
10398
+ });
10399
+ useEffect(() => {
10400
+ form.reset({
10401
+ title,
10402
+ quantity,
10403
+ unit_price
10710
10404
  });
10711
- if (!requestSucceeded) {
10712
- setIsSubmitting(false);
10405
+ }, [form, title, quantity, unit_price]);
10406
+ const actionId = useMemo(() => {
10407
+ var _a, _b;
10408
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10409
+ }, [item]);
10410
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10411
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10412
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10413
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10414
+ const onSubmit = form.handleSubmit(async (data) => {
10415
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10416
+ setEditing(false);
10713
10417
  return;
10714
10418
  }
10715
- await confirmOrderEdit(void 0, {
10716
- onError: (e) => {
10717
- toast.error(`Failed to confirm order edit: ${e.message}`);
10718
- },
10719
- onSuccess: () => {
10720
- handleSuccess();
10721
- },
10722
- onSettled: () => {
10723
- setIsSubmitting(false);
10724
- }
10725
- });
10726
- };
10727
- const onKeyDown = useCallback(
10728
- (e) => {
10729
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10730
- if (modalContent || isSubmitting) {
10731
- return;
10419
+ if (!actionId) {
10420
+ await updateOriginalItem(
10421
+ {
10422
+ item_id: item.id,
10423
+ quantity: data.quantity,
10424
+ unit_price: convertNumber(data.unit_price)
10425
+ },
10426
+ {
10427
+ onSuccess: () => {
10428
+ setEditing(false);
10429
+ },
10430
+ onError: (e) => {
10431
+ toast.error(e.message);
10432
+ }
10732
10433
  }
10733
- onSubmit();
10734
- }
10735
- },
10736
- [modalContent, isSubmitting, onSubmit]
10737
- );
10738
- useEffect(() => {
10739
- document.addEventListener("keydown", onKeyDown);
10740
- return () => {
10741
- document.removeEventListener("keydown", onKeyDown);
10742
- };
10743
- }, [onKeyDown]);
10744
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10745
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10746
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10747
- StackedFocusModal,
10748
- {
10749
- id: STACKED_MODAL_ID,
10750
- onOpenChangeCallback: (open) => {
10751
- if (!open) {
10752
- setModalContent(null);
10753
- }
10754
- },
10755
- children: [
10756
- /* @__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: [
10757
- /* @__PURE__ */ jsxs("div", { children: [
10758
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10759
- /* @__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" }) })
10760
- ] }),
10761
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10762
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10763
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10764
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10765
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10766
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10767
- ] }),
10768
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10769
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10770
- Input,
10771
- {
10772
- type: "search",
10773
- placeholder: "Search items",
10774
- value: searchValue,
10775
- onChange: (e) => onSearchValueChange(e.target.value)
10776
- }
10777
- ) }),
10778
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10779
- /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10780
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10781
- /* @__PURE__ */ jsx(
10782
- StackedModalTrigger$1,
10783
- {
10784
- type: "add-items",
10785
- setModalContent
10786
- }
10787
- ),
10788
- /* @__PURE__ */ jsx(
10789
- StackedModalTrigger$1,
10790
- {
10791
- type: "add-custom-item",
10792
- setModalContent
10793
- }
10794
- )
10795
- ] })
10796
- ] })
10797
- ] })
10798
- ] }),
10799
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10800
- /* @__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: [
10801
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10802
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10803
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10804
- /* @__PURE__ */ jsx("div", {})
10805
- ] }) }),
10806
- /* @__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: [
10807
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10808
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10809
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10810
- Item,
10811
- {
10812
- item,
10813
- preview,
10814
- currencyCode
10815
- },
10816
- item.id
10817
- )) : /* @__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: [
10818
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10819
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10820
- 'No items found for "',
10821
- query2,
10822
- '".'
10823
- ] })
10824
- ] }) })
10825
- ] })
10826
- ] }),
10827
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10828
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10829
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10830
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10831
- Text,
10832
- {
10833
- size: "small",
10834
- leading: "compact",
10835
- className: "text-ui-fg-subtle",
10836
- children: [
10837
- itemCount,
10838
- " ",
10839
- itemCount === 1 ? "item" : "items"
10840
- ]
10841
- }
10842
- ) }),
10843
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10844
- ] })
10845
- ] }) }),
10846
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10847
- CustomItemForm,
10848
- {
10849
- orderId: preview.id,
10850
- currencyCode
10851
- }
10852
- ) : null)
10853
- ]
10854
- }
10855
- ) }),
10856
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10857
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10858
- /* @__PURE__ */ jsx(
10859
- Button,
10860
- {
10861
- size: "small",
10862
- type: "button",
10863
- onClick: onSubmit,
10864
- isLoading: isSubmitting,
10865
- children: "Save"
10866
- }
10867
- )
10868
- ] }) })
10869
- ] });
10870
- };
10871
- const Item = ({ item, preview, currencyCode }) => {
10872
- if (item.variant_id) {
10873
- return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10874
- }
10875
- return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10876
- };
10877
- const VariantItem = ({ item, preview, currencyCode }) => {
10878
- const [editing, setEditing] = useState(false);
10879
- const form = useForm({
10880
- defaultValues: {
10881
- quantity: item.quantity,
10882
- unit_price: item.unit_price
10883
- },
10884
- resolver: zodResolver(variantItemSchema)
10885
- });
10886
- const actionId = useMemo(() => {
10887
- var _a, _b;
10888
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10889
- }, [item]);
10890
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10891
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10892
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10893
- const onSubmit = form.handleSubmit(async (data) => {
10894
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10895
- setEditing(false);
10434
+ );
10896
10435
  return;
10897
10436
  }
10898
- if (!actionId) {
10899
- await updateOriginalItem(
10900
- {
10901
- item_id: item.id,
10902
- quantity: data.quantity,
10903
- unit_price: convertNumber(data.unit_price)
10437
+ if (data.quantity === 0) {
10438
+ await removeActionItem(actionId, {
10439
+ onSuccess: () => {
10440
+ setEditing(false);
10904
10441
  },
10905
- {
10906
- onSuccess: () => {
10907
- setEditing(false);
10908
- },
10909
- onError: (e) => {
10910
- toast.error(e.message);
10911
- }
10442
+ onError: (e) => {
10443
+ toast.error(e.message);
10912
10444
  }
10913
- );
10445
+ });
10914
10446
  return;
10915
10447
  }
10916
10448
  await updateActionItem(
@@ -10930,43 +10462,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10930
10462
  );
10931
10463
  });
10932
10464
  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: [
10933
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10465
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10934
10466
  /* @__PURE__ */ jsx(
10935
10467
  Thumbnail,
10936
10468
  {
10937
10469
  thumbnail: item.thumbnail,
10938
- alt: item.product_title ?? void 0
10470
+ alt: item.title ?? void 0
10939
10471
  }
10940
10472
  ),
10941
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10942
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10943
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10944
- /* @__PURE__ */ jsxs(
10945
- Text,
10946
- {
10947
- size: "small",
10948
- leading: "compact",
10949
- className: "text-ui-fg-subtle",
10950
- children: [
10951
- "(",
10952
- item.variant_title,
10953
- ")"
10954
- ]
10955
- }
10956
- )
10957
- ] }),
10958
- /* @__PURE__ */ jsx(
10959
- Text,
10960
- {
10961
- size: "small",
10962
- leading: "compact",
10963
- className: "text-ui-fg-subtle",
10964
- children: item.variant_sku
10473
+ editing ? /* @__PURE__ */ jsx(
10474
+ Form$2.Field,
10475
+ {
10476
+ control: form.control,
10477
+ name: "title",
10478
+ render: ({ field }) => {
10479
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10965
10480
  }
10966
- )
10967
- ] })
10481
+ }
10482
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10968
10483
  ] }),
10969
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10484
+ editing ? /* @__PURE__ */ jsx(
10970
10485
  Form$2.Field,
10971
10486
  {
10972
10487
  control: form.control,
@@ -10975,8 +10490,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10975
10490
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10976
10491
  }
10977
10492
  }
10978
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10979
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10493
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10494
+ editing ? /* @__PURE__ */ jsx(
10980
10495
  Form$2.Field,
10981
10496
  {
10982
10497
  control: form.control,
@@ -10993,149 +10508,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10993
10508
  ) }) });
10994
10509
  }
10995
10510
  }
10996
- ) }) : /* @__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) }) }),
10997
- /* @__PURE__ */ jsx(
10998
- IconButton,
10999
- {
11000
- type: "button",
11001
- size: "small",
11002
- onClick: editing ? onSubmit : () => {
11003
- setEditing(true);
11004
- },
11005
- disabled: isPending,
11006
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
11007
- }
11008
- )
11009
- ] }) }) });
11010
- };
11011
- const variantItemSchema = objectType({
11012
- quantity: numberType(),
11013
- unit_price: unionType([numberType(), stringType()])
11014
- });
11015
- const CustomItem = ({ item, preview, currencyCode }) => {
11016
- const [editing, setEditing] = useState(false);
11017
- const { quantity, unit_price, title } = item;
11018
- const form = useForm({
11019
- defaultValues: {
11020
- title,
11021
- quantity,
11022
- unit_price
11023
- },
11024
- resolver: zodResolver(customItemSchema)
11025
- });
11026
- useEffect(() => {
11027
- form.reset({
11028
- title,
11029
- quantity,
11030
- unit_price
11031
- });
11032
- }, [form, title, quantity, unit_price]);
11033
- const actionId = useMemo(() => {
11034
- var _a, _b;
11035
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11036
- }, [item]);
11037
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11038
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
11039
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11040
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11041
- const onSubmit = form.handleSubmit(async (data) => {
11042
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
11043
- setEditing(false);
11044
- return;
11045
- }
11046
- if (!actionId) {
11047
- await updateOriginalItem(
11048
- {
11049
- item_id: item.id,
11050
- quantity: data.quantity,
11051
- unit_price: convertNumber(data.unit_price)
11052
- },
11053
- {
11054
- onSuccess: () => {
11055
- setEditing(false);
11056
- },
11057
- onError: (e) => {
11058
- toast.error(e.message);
11059
- }
11060
- }
11061
- );
11062
- return;
11063
- }
11064
- if (data.quantity === 0) {
11065
- await removeActionItem(actionId, {
11066
- onSuccess: () => {
11067
- setEditing(false);
11068
- },
11069
- onError: (e) => {
11070
- toast.error(e.message);
11071
- }
11072
- });
11073
- return;
11074
- }
11075
- await updateActionItem(
11076
- {
11077
- action_id: actionId,
11078
- quantity: data.quantity,
11079
- unit_price: convertNumber(data.unit_price)
11080
- },
11081
- {
11082
- onSuccess: () => {
11083
- setEditing(false);
11084
- },
11085
- onError: (e) => {
11086
- toast.error(e.message);
11087
- }
11088
- }
11089
- );
11090
- });
11091
- 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: [
11092
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11093
- /* @__PURE__ */ jsx(
11094
- Thumbnail,
11095
- {
11096
- thumbnail: item.thumbnail,
11097
- alt: item.title ?? void 0
11098
- }
11099
- ),
11100
- editing ? /* @__PURE__ */ jsx(
11101
- Form$2.Field,
11102
- {
11103
- control: form.control,
11104
- name: "title",
11105
- render: ({ field }) => {
11106
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
11107
- }
11108
- }
11109
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
11110
- ] }),
11111
- editing ? /* @__PURE__ */ jsx(
11112
- Form$2.Field,
11113
- {
11114
- control: form.control,
11115
- name: "quantity",
11116
- render: ({ field }) => {
11117
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
11118
- }
11119
- }
11120
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
11121
- editing ? /* @__PURE__ */ jsx(
11122
- Form$2.Field,
11123
- {
11124
- control: form.control,
11125
- name: "unit_price",
11126
- render: ({ field: { onChange, ...field } }) => {
11127
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11128
- CurrencyInput,
11129
- {
11130
- ...field,
11131
- symbol: getNativeSymbol(currencyCode),
11132
- code: currencyCode,
11133
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11134
- }
11135
- ) }) });
11136
- }
11137
- }
11138
- ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10511
+ ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11139
10512
  /* @__PURE__ */ jsx(
11140
10513
  IconButton,
11141
10514
  {
@@ -11447,46 +10820,88 @@ const customItemSchema = objectType({
11447
10820
  quantity: numberType(),
11448
10821
  unit_price: unionType([numberType(), stringType()])
11449
10822
  });
11450
- const SalesChannel = () => {
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",
10828
+ {
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
+ ]
10854
+ }
10855
+ );
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 = () => {
11451
10868
  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
- );
10869
+ const { order, isPending, isError, error } = useOrder(id, {
10870
+ fields: "metadata"
10871
+ });
11461
10872
  if (isError) {
11462
10873
  throw error;
11463
10874
  }
11464
- const ISrEADY = !!draft_order && !isPending;
10875
+ const isReady = !isPending && !!order;
11465
10876
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
10877
  /* @__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" }) })
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." }) })
11469
10880
  ] }),
11470
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
10881
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11471
10882
  ] });
11472
10883
  };
11473
- const SalesChannelForm = ({ order }) => {
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);
11474
10890
  const form = useForm({
11475
10891
  defaultValues: {
11476
- sales_channel_id: order.sales_channel_id || ""
10892
+ metadata: getDefaultValues(metadata)
11477
10893
  },
11478
- resolver: zodResolver(schema$2)
10894
+ resolver: zodResolver(MetadataSchema)
11479
10895
  });
11480
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
- const { handleSuccess } = useRouteModal();
11482
- const onSubmit = form.handleSubmit(async (data) => {
10896
+ const handleSubmit = form.handleSubmit(async (data) => {
10897
+ const parsedData = parseValues(data);
11483
10898
  await mutateAsync(
11484
10899
  {
11485
- sales_channel_id: data.sales_channel_id
10900
+ metadata: parsedData
11486
10901
  },
11487
10902
  {
11488
10903
  onSuccess: () => {
11489
- toast.success("Sales channel updated");
10904
+ toast.success("Metadata updated");
11490
10905
  handleSuccess();
11491
10906
  },
11492
10907
  onError: (error) => {
@@ -11495,1074 +10910,1553 @@ const SalesChannelForm = ({ order }) => {
11495
10910
  }
11496
10911
  );
11497
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
+ }
11498
10934
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11499
10935
  KeyboundForm,
11500
10936
  {
10937
+ onSubmit: handleSubmit,
11501
10938
  className: "flex flex-1 flex-col overflow-hidden",
11502
- onSubmit,
11503
10939
  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" }) }),
11507
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
- ] }) })
11509
- ]
11510
- }
11511
- ) });
11512
- };
11513
- const SalesChannelField = ({ control, order }) => {
11514
- const salesChannels = useComboboxData({
11515
- queryFn: async (params) => {
11516
- return await sdk.admin.salesChannel.list(params);
11517
- },
11518
- queryKey: ["sales-channels"],
11519
- getOptions: (data) => {
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
11526
- });
11527
- return /* @__PURE__ */ jsx(
11528
- Form$2.Field,
11529
- {
11530
- control,
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
- }
11550
- }
11551
- );
11552
- };
11553
- const schema$2 = objectType({
11554
- sales_channel_id: stringType().min(1)
11555
- });
11556
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11557
- const Shipping = () => {
11558
- var _a;
11559
- const { id } = useParams();
11560
- const { order, isPending, isError, error } = useOrder(id, {
11561
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11562
- });
11563
- const {
11564
- order: preview,
11565
- isPending: isPreviewPending,
11566
- isError: isPreviewError,
11567
- error: previewError
11568
- } = useOrderPreview(id);
11569
- useInitiateOrderEdit({ preview });
11570
- const { onCancel } = useCancelOrderEdit({ preview });
11571
- if (isError) {
11572
- throw error;
11573
- }
11574
- if (isPreviewError) {
11575
- throw previewError;
11576
- }
11577
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11578
- const isReady = preview && !isPreviewPending && order && !isPending;
11579
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11580
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11581
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11582
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11583
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11584
- ] }) }) }),
11585
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11586
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11587
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11588
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11589
- ] }) });
11590
- };
11591
- const ShippingForm = ({ preview, order }) => {
11592
- var _a;
11593
- const { setIsOpen } = useStackedModal();
11594
- const [isSubmitting, setIsSubmitting] = useState(false);
11595
- const [data, setData] = useState(null);
11596
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11597
- const { shipping_options } = useShippingOptions(
11598
- {
11599
- id: appliedShippingOptionIds,
11600
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11601
- },
11602
- {
11603
- enabled: appliedShippingOptionIds.length > 0
11604
- }
11605
- );
11606
- const uniqueShippingProfiles = useMemo(() => {
11607
- const profiles = /* @__PURE__ */ new Map();
11608
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11609
- profiles.set(profile.id, profile);
11610
- });
11611
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11612
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11613
- });
11614
- return Array.from(profiles.values());
11615
- }, [order.items, shipping_options]);
11616
- const { handleSuccess } = useRouteModal();
11617
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11618
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11619
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11620
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11621
- const onSubmit = async () => {
11622
- setIsSubmitting(true);
11623
- let requestSucceeded = false;
11624
- await requestOrderEdit(void 0, {
11625
- onError: (e) => {
11626
- toast.error(`Failed to request order edit: ${e.message}`);
11627
- },
11628
- onSuccess: () => {
11629
- requestSucceeded = true;
11630
- }
11631
- });
11632
- if (!requestSucceeded) {
11633
- setIsSubmitting(false);
11634
- return;
11635
- }
11636
- await confirmOrderEdit(void 0, {
11637
- onError: (e) => {
11638
- toast.error(`Failed to confirm order edit: ${e.message}`);
11639
- },
11640
- onSuccess: () => {
11641
- handleSuccess();
11642
- },
11643
- onSettled: () => {
11644
- setIsSubmitting(false);
11645
- }
11646
- });
11647
- };
11648
- const onKeydown = useCallback(
11649
- (e) => {
11650
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11651
- if (data || isSubmitting) {
11652
- return;
11653
- }
11654
- onSubmit();
11655
- }
11656
- },
11657
- [data, isSubmitting, onSubmit]
11658
- );
11659
- useEffect(() => {
11660
- document.addEventListener("keydown", onKeydown);
11661
- return () => {
11662
- document.removeEventListener("keydown", onKeydown);
11663
- };
11664
- }, [onKeydown]);
11665
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11666
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11667
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11668
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11669
- /* @__PURE__ */ jsxs("div", { children: [
11670
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11671
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11672
- ] }),
11673
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11674
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11675
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11676
- /* @__PURE__ */ jsx(
11677
- Text,
11678
- {
11679
- size: "xsmall",
11680
- weight: "plus",
11681
- className: "text-ui-fg-muted",
11682
- children: "Shipping profile"
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 = "{ ... }";
11683
10951
  }
11684
- ),
11685
- /* @__PURE__ */ jsx(
11686
- Text,
11687
- {
11688
- size: "xsmall",
11689
- weight: "plus",
11690
- className: "text-ui-fg-muted",
11691
- children: "Action"
10952
+ if (Array.isArray(field.value)) {
10953
+ placeholder = "[ ... ]";
11692
10954
  }
11693
- )
11694
- ] }),
11695
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11696
- var _a2, _b, _c, _d, _e, _f, _g;
11697
- const items = getItemsWithShippingProfile(
11698
- profile.id,
11699
- order.items
11700
- );
11701
- const hasItems = items.length > 0;
11702
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11703
- (option) => option.shipping_profile_id === profile.id
11704
- );
11705
- const shippingMethod = preview.shipping_methods.find(
11706
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11707
- );
11708
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11709
- (action) => action.action === "SHIPPING_ADD"
11710
- );
11711
- return /* @__PURE__ */ jsxs(
11712
- Accordion.Item,
11713
- {
11714
- value: profile.id,
11715
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11716
- children: [
11717
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11718
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11719
- /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11720
- IconButton,
11721
- {
11722
- size: "2xsmall",
11723
- variant: "transparent",
11724
- className: "group/trigger",
11725
- disabled: !hasItems,
11726
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11727
- }
11728
- ) }),
11729
- !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11730
- /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11731
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
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: [
11732
10968
  /* @__PURE__ */ jsx(
11733
- Text,
10969
+ Form$2.Field,
11734
10970
  {
11735
- size: "small",
11736
- weight: "plus",
11737
- leading: "compact",
11738
- children: profile.name
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
+ }
11739
10984
  }
11740
10985
  ),
11741
- /* @__PURE__ */ jsxs(
11742
- Text,
10986
+ /* @__PURE__ */ jsx(
10987
+ Form$2.Field,
11743
10988
  {
11744
- size: "small",
11745
- leading: "compact",
11746
- className: "text-ui-fg-subtle",
11747
- children: [
11748
- items.length,
11749
- " ",
11750
- pluralize(items.length, "items", "item")
11751
- ]
11752
- }
11753
- )
11754
- ] })
11755
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11756
- /* @__PURE__ */ jsx(
11757
- Tooltip,
11758
- {
11759
- content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11760
- var _a3, _b2, _c2;
11761
- return /* @__PURE__ */ jsx(
11762
- "li",
11763
- {
11764
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11765
- },
11766
- item.id
11767
- );
11768
- }) }),
11769
- children: /* @__PURE__ */ jsxs(
11770
- Badge,
11771
- {
11772
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11773
- size: "xsmall",
11774
- children: [
11775
- /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11776
- /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11777
- items.reduce(
11778
- (acc, item) => acc + item.quantity,
11779
- 0
11780
- ),
11781
- "x",
11782
- " ",
11783
- pluralize(items.length, "items", "item")
11784
- ] })
11785
- ]
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
+ ) }) });
11786
11002
  }
11787
- )
11788
- }
11789
- ),
11790
- /* @__PURE__ */ jsx(
11791
- Tooltip,
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,
11792
11026
  {
11793
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11794
- children: /* @__PURE__ */ jsxs(
11795
- Badge,
11796
- {
11797
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11798
- size: "xsmall",
11799
- children: [
11800
- /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11801
- /* @__PURE__ */ jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11802
- ]
11803
- }
11804
- )
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
+ ]
11805
11033
  }
11806
11034
  ),
11807
- /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11808
- Badge,
11035
+ /* @__PURE__ */ jsxs(
11036
+ DropdownMenu.Item,
11809
11037
  {
11810
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11811
- size: "xsmall",
11038
+ className: "gap-x-2",
11039
+ onClick: () => insertRow(index, "below"),
11812
11040
  children: [
11813
- /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11814
- /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11041
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11042
+ "Insert row below"
11815
11043
  ]
11816
11044
  }
11817
- ) })
11818
- ] })
11819
- ] }),
11820
- shippingOption ? /* @__PURE__ */ jsx(
11821
- ActionMenu,
11822
- {
11823
- groups: [
11824
- {
11825
- actions: [
11826
- hasItems ? {
11827
- label: "Edit shipping option",
11828
- icon: /* @__PURE__ */ jsx(Channels, {}),
11829
- onClick: () => {
11830
- setIsOpen(
11831
- STACKED_FOCUS_MODAL_ID,
11832
- true
11833
- );
11834
- setData({
11835
- shippingProfileId: profile.id,
11836
- shippingOption,
11837
- shippingMethod
11838
- });
11839
- }
11840
- } : void 0,
11841
- {
11842
- label: "Remove shipping option",
11843
- icon: /* @__PURE__ */ jsx(Trash, {}),
11844
- onClick: () => {
11845
- if (shippingMethod) {
11846
- if (addShippingMethodAction) {
11847
- removeActionShippingMethod(
11848
- addShippingMethodAction.id
11849
- );
11850
- } else {
11851
- removeShippingMethod(
11852
- shippingMethod.id
11853
- );
11854
- }
11855
- }
11856
- }
11857
- }
11858
- ].filter(Boolean)
11859
- }
11860
- ]
11861
- }
11862
- ) : /* @__PURE__ */ jsx(
11863
- StackedModalTrigger,
11864
- {
11865
- shippingProfileId: profile.id,
11866
- shippingOption,
11867
- shippingMethod,
11868
- setData,
11869
- children: "Add shipping option"
11870
- }
11871
- )
11872
- ] }),
11873
- /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11874
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11875
- items.map((item, idx) => {
11876
- var _a3, _b2, _c2, _d2, _e2;
11877
- return /* @__PURE__ */ jsxs("div", { children: [
11045
+ ),
11046
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11878
11047
  /* @__PURE__ */ jsxs(
11879
- "div",
11048
+ DropdownMenu.Item,
11880
11049
  {
11881
- className: "px-3 flex items-center gap-x-3",
11050
+ className: "gap-x-2",
11051
+ onClick: () => deleteRow(index),
11882
11052
  children: [
11883
- /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11884
- Divider,
11885
- {
11886
- variant: "dashed",
11887
- orientation: "vertical"
11888
- }
11889
- ) }),
11890
- /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11891
- /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11892
- Text,
11893
- {
11894
- size: "small",
11895
- leading: "compact",
11896
- className: "text-ui-fg-subtle",
11897
- children: [
11898
- item.quantity,
11899
- "x"
11900
- ]
11901
- }
11902
- ) }),
11903
- /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
11904
- /* @__PURE__ */ jsxs("div", { children: [
11905
- /* @__PURE__ */ jsxs(
11906
- Text,
11907
- {
11908
- size: "small",
11909
- leading: "compact",
11910
- weight: "plus",
11911
- children: [
11912
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11913
- " (",
11914
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11915
- ")"
11916
- ]
11917
- }
11918
- ),
11919
- /* @__PURE__ */ jsx(
11920
- Text,
11921
- {
11922
- size: "small",
11923
- leading: "compact",
11924
- className: "text-ui-fg-subtle",
11925
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11926
- }
11927
- )
11928
- ] })
11929
- ] })
11053
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11054
+ "Delete row"
11930
11055
  ]
11931
- },
11932
- item.id
11933
- ),
11934
- idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11935
- ] }, item.id);
11936
- })
11056
+ }
11057
+ )
11058
+ ] })
11059
+ ] })
11937
11060
  ] })
11938
- ]
11939
- },
11940
- profile.id
11941
- );
11942
- }) })
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" })
11943
11071
  ] }) })
11944
- ] }) }),
11945
- /* @__PURE__ */ jsx(
11946
- StackedFocusModal,
11947
- {
11948
- id: STACKED_FOCUS_MODAL_ID,
11949
- onOpenChangeCallback: (open) => {
11950
- if (!open) {
11951
- setData(null);
11952
- }
11953
- return open;
11954
- },
11955
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11956
- }
11957
- )
11958
- ] }),
11959
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11960
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11961
- /* @__PURE__ */ jsx(
11962
- Button,
11963
- {
11964
- size: "small",
11965
- type: "button",
11966
- isLoading: isSubmitting,
11967
- onClick: onSubmit,
11968
- children: "Save"
11969
- }
11072
+ ]
11073
+ }
11074
+ ) });
11075
+ };
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
11970
11086
  )
11087
+ }
11088
+ );
11089
+ });
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" })
11971
11097
  ] }) })
11972
11098
  ] });
11973
11099
  };
11974
- const StackedModalTrigger = ({
11975
- shippingProfileId,
11976
- shippingOption,
11977
- shippingMethod,
11978
- setData,
11979
- children
11980
- }) => {
11981
- const { setIsOpen, getIsOpen } = useStackedModal();
11982
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11983
- const onToggle = () => {
11984
- if (isOpen) {
11985
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11986
- setData(null);
11987
- } else {
11988
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11989
- setData({
11990
- shippingProfileId,
11991
- shippingOption,
11992
- shippingMethod
11993
- });
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
11108
+ }
11109
+ ];
11110
+ }
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
+ };
11994
11118
  }
11995
- };
11996
- return /* @__PURE__ */ jsx(
11997
- Button,
11998
- {
11999
- size: "small",
12000
- variant: "secondary",
12001
- onClick: onToggle,
12002
- className: "text-ui-fg-primary shrink-0",
12003
- children
11119
+ let stringValue = value;
11120
+ if (typeof value !== "string") {
11121
+ stringValue = JSON.stringify(value);
11122
+ }
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;
11135
+ }
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;
11143
+ }
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;
11160
+ }
12004
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)
12005
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
+ ]
12006
11184
  };
12007
- const ShippingProfileForm = ({
12008
- data,
12009
- order,
12010
- preview
12011
- }) => {
12012
- var _a, _b, _c, _d, _e, _f;
12013
- const { setIsOpen } = useStackedModal();
12014
- const form = useForm({
12015
- resolver: zodResolver(shippingMethodSchema),
12016
- defaultValues: {
12017
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12018
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12019
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12020
- }
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
12021
11190
  });
12022
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11191
+ return { ...data, ...rest };
11192
+ };
11193
+ const Promotions = () => {
11194
+ const { id } = useParams();
12023
11195
  const {
12024
- mutateAsync: updateShippingMethod,
12025
- isPending: isUpdatingShippingMethod
12026
- } = useDraftOrderUpdateShippingMethod(order.id);
12027
- const onSubmit = form.handleSubmit(async (values) => {
12028
- if (isEqual(values, form.formState.defaultValues)) {
12029
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12030
- return;
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;
11204
+ }
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 })
11209
+ ] });
11210
+ };
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
11221
+ },
11222
+ {
11223
+ enabled: !!promoIds.length
12031
11224
  }
12032
- if (data.shippingMethod) {
12033
- await updateShippingMethod(
12034
- {
12035
- method_id: data.shippingMethod.id,
12036
- shipping_option_id: values.shipping_option_id,
12037
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12038
- },
12039
- {
12040
- onError: (e) => {
12041
- toast.error(e.message);
12042
- },
12043
- onSuccess: () => {
12044
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12045
- }
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
12046
11233
  }
12047
- );
11234
+ });
11235
+ },
11236
+ getOptions: (data) => {
11237
+ return data.promotions.map((promotion) => ({
11238
+ label: promotion.code,
11239
+ value: promotion.code
11240
+ }));
11241
+ }
11242
+ });
11243
+ const add = async (value) => {
11244
+ if (!value) {
12048
11245
  return;
12049
11246
  }
12050
- await addShippingMethod(
11247
+ addPromotions(
12051
11248
  {
12052
- shipping_option_id: values.shipping_option_id,
12053
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11249
+ promo_codes: [value]
12054
11250
  },
12055
11251
  {
12056
11252
  onError: (e) => {
12057
11253
  toast.error(e.message);
11254
+ comboboxData.onSearchValueChange("");
11255
+ setComboboxValue("");
12058
11256
  },
12059
11257
  onSuccess: () => {
12060
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
12061
11260
  }
12062
11261
  }
12063
11262
  );
12064
- });
12065
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12066
- KeyboundForm,
12067
- {
12068
- className: "flex h-full flex-col overflow-hidden",
12069
- onSubmit,
12070
- children: [
12071
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12072
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12073
- /* @__PURE__ */ jsxs("div", { children: [
12074
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12075
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12076
- ] }),
12077
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12078
- /* @__PURE__ */ jsx(
12079
- LocationField,
12080
- {
12081
- control: form.control,
12082
- setValue: form.setValue
12083
- }
12084
- ),
12085
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12086
- /* @__PURE__ */ jsx(
12087
- ShippingOptionField,
12088
- {
12089
- shippingProfileId: data.shippingProfileId,
12090
- preview,
12091
- control: form.control
12092
- }
12093
- ),
12094
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12095
- /* @__PURE__ */ jsx(
12096
- CustomAmountField,
12097
- {
12098
- control: form.control,
12099
- currencyCode: order.currency_code
12100
- }
12101
- ),
12102
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12103
- /* @__PURE__ */ jsx(
12104
- ItemsPreview,
12105
- {
12106
- order,
12107
- shippingProfileId: data.shippingProfileId
12108
- }
12109
- )
12110
- ] }) }) }),
12111
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12112
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12113
- /* @__PURE__ */ jsx(
12114
- Button,
12115
- {
12116
- size: "small",
12117
- type: "submit",
12118
- isLoading: isPending || isUpdatingShippingMethod,
12119
- children: data.shippingMethod ? "Update" : "Add"
12120
- }
12121
- )
12122
- ] }) })
12123
- ]
12124
- }
12125
- ) }) });
12126
- };
12127
- const shippingMethodSchema = objectType({
12128
- location_id: stringType(),
12129
- shipping_option_id: stringType(),
12130
- custom_amount: unionType([numberType(), stringType()]).optional()
12131
- });
12132
- const ItemsPreview = ({ order, shippingProfileId }) => {
12133
- const matches = order.items.filter(
12134
- (item) => {
12135
- var _a, _b, _c;
12136
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
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;
12137
11280
  }
12138
- );
12139
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12140
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12141
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12142
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12143
- ] }) }),
12144
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12145
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12146
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12147
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
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
+ };
11293
+ if (isError) {
11294
+ throw error;
11295
+ }
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
+ )
12148
11318
  ] }),
12149
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12150
- "div",
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,
12151
11322
  {
12152
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12153
- children: [
12154
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12155
- /* @__PURE__ */ jsx(
12156
- Thumbnail,
12157
- {
12158
- thumbnail: item.thumbnail,
12159
- alt: item.product_title ?? void 0
12160
- }
12161
- ),
12162
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12163
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12164
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12165
- /* @__PURE__ */ jsxs(
12166
- Text,
12167
- {
12168
- size: "small",
12169
- leading: "compact",
12170
- className: "text-ui-fg-subtle",
12171
- children: [
12172
- "(",
12173
- item.variant_title,
12174
- ")"
12175
- ]
12176
- }
12177
- )
12178
- ] }),
12179
- /* @__PURE__ */ jsx(
12180
- Text,
12181
- {
12182
- size: "small",
12183
- leading: "compact",
12184
- className: "text-ui-fg-subtle",
12185
- children: item.variant_sku
12186
- }
12187
- )
12188
- ] })
12189
- ] }),
12190
- /* @__PURE__ */ jsxs(
12191
- Text,
12192
- {
12193
- size: "small",
12194
- leading: "compact",
12195
- className: "text-ui-fg-subtle",
12196
- children: [
12197
- item.quantity,
12198
- "x"
12199
- ]
12200
- }
12201
- )
12202
- ]
11323
+ promotion,
11324
+ orderId: preview.id,
11325
+ isLoading: isPending
12203
11326
  },
12204
- item.id
12205
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12206
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12207
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12208
- 'No items found for "',
12209
- query,
12210
- '".'
12211
- ] })
12212
- ] }) })
12213
- ] })
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
+ ] }) })
12214
11342
  ] });
12215
11343
  };
12216
- const LocationField = ({ control, setValue }) => {
12217
- const locations = useComboboxData({
12218
- queryKey: ["locations"],
12219
- queryFn: async (params) => {
12220
- return await sdk.admin.stockLocation.list(params);
12221
- },
12222
- getOptions: (data) => {
12223
- return data.stock_locations.map((location) => ({
12224
- label: location.name,
12225
- value: location.id
12226
- }));
12227
- }
12228
- });
12229
- return /* @__PURE__ */ jsx(
12230
- Form$2.Field,
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(
11353
+ {
11354
+ promo_codes: [promotion.code]
11355
+ },
11356
+ {
11357
+ onError: (e) => {
11358
+ toast.error(e.message);
11359
+ }
11360
+ }
11361
+ );
11362
+ };
11363
+ const displayValue = getDisplayValue(promotion);
11364
+ return /* @__PURE__ */ jsxs(
11365
+ "div",
12231
11366
  {
12232
- control,
12233
- name: "location_id",
12234
- render: ({ field: { onChange, ...field } }) => {
12235
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12236
- /* @__PURE__ */ jsxs("div", { children: [
12237
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12238
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12239
- ] }),
12240
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12241
- Combobox,
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
+ ),
11373
+ children: [
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: "·" })
11380
+ ] }),
11381
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11382
+ ] })
11383
+ ] }),
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 ShippingAddress = () => {
11451
+ const { id } = useParams();
11452
+ const { order, isPending, isError, error } = useOrder(id, {
11453
+ fields: "+shipping_address"
11454
+ });
11455
+ if (isError) {
11456
+ throw error;
11457
+ }
11458
+ const isReady = !isPending && !!order;
11459
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11460
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11461
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11462
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11463
+ ] }),
11464
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11465
+ ] });
11466
+ };
11467
+ const ShippingAddressForm = ({ order }) => {
11468
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11469
+ const form = useForm({
11470
+ defaultValues: {
11471
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11472
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11473
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11474
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11475
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11476
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11477
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11478
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11479
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11480
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11481
+ },
11482
+ resolver: zodResolver(schema$2)
11483
+ });
11484
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11485
+ const { handleSuccess } = useRouteModal();
11486
+ const onSubmit = form.handleSubmit(async (data) => {
11487
+ await mutateAsync(
11488
+ {
11489
+ shipping_address: {
11490
+ first_name: data.first_name,
11491
+ last_name: data.last_name,
11492
+ company: data.company,
11493
+ address_1: data.address_1,
11494
+ address_2: data.address_2,
11495
+ city: data.city,
11496
+ province: data.province,
11497
+ country_code: data.country_code,
11498
+ postal_code: data.postal_code,
11499
+ phone: data.phone
11500
+ }
11501
+ },
11502
+ {
11503
+ onSuccess: () => {
11504
+ handleSuccess();
11505
+ },
11506
+ onError: (error) => {
11507
+ toast.error(error.message);
11508
+ }
11509
+ }
11510
+ );
11511
+ });
11512
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11513
+ KeyboundForm,
11514
+ {
11515
+ className: "flex flex-1 flex-col overflow-hidden",
11516
+ onSubmit,
11517
+ children: [
11518
+ /* @__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: [
11519
+ /* @__PURE__ */ jsx(
11520
+ Form$2.Field,
12242
11521
  {
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);
11522
+ control: form.control,
11523
+ name: "country_code",
11524
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11525
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11526
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11527
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11528
+ ] })
11529
+ }
11530
+ ),
11531
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11532
+ /* @__PURE__ */ jsx(
11533
+ Form$2.Field,
11534
+ {
11535
+ control: form.control,
11536
+ name: "first_name",
11537
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11538
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11539
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11540
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11541
+ ] })
11542
+ }
11543
+ ),
11544
+ /* @__PURE__ */ jsx(
11545
+ Form$2.Field,
11546
+ {
11547
+ control: form.control,
11548
+ name: "last_name",
11549
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11550
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11551
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11552
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11553
+ ] })
11554
+ }
11555
+ )
11556
+ ] }),
11557
+ /* @__PURE__ */ jsx(
11558
+ Form$2.Field,
11559
+ {
11560
+ control: form.control,
11561
+ name: "company",
11562
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11563
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11564
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11565
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11566
+ ] })
11567
+ }
11568
+ ),
11569
+ /* @__PURE__ */ jsx(
11570
+ Form$2.Field,
11571
+ {
11572
+ control: form.control,
11573
+ name: "address_1",
11574
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11575
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11576
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11577
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11578
+ ] })
11579
+ }
11580
+ ),
11581
+ /* @__PURE__ */ jsx(
11582
+ Form$2.Field,
11583
+ {
11584
+ control: form.control,
11585
+ name: "address_2",
11586
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11587
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11588
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11589
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11590
+ ] })
11591
+ }
11592
+ ),
11593
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11594
+ /* @__PURE__ */ jsx(
11595
+ Form$2.Field,
11596
+ {
11597
+ control: form.control,
11598
+ name: "postal_code",
11599
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11600
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11601
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11602
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11603
+ ] })
11604
+ }
11605
+ ),
11606
+ /* @__PURE__ */ jsx(
11607
+ Form$2.Field,
11608
+ {
11609
+ control: form.control,
11610
+ name: "city",
11611
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11612
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11613
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11614
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11615
+ ] })
11616
+ }
11617
+ )
11618
+ ] }),
11619
+ /* @__PURE__ */ jsx(
11620
+ Form$2.Field,
11621
+ {
11622
+ control: form.control,
11623
+ name: "province",
11624
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11625
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11626
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11627
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11628
+ ] })
11629
+ }
11630
+ ),
11631
+ /* @__PURE__ */ jsx(
11632
+ Form$2.Field,
11633
+ {
11634
+ control: form.control,
11635
+ name: "phone",
11636
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11637
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11638
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11639
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11640
+ ] })
11641
+ }
11642
+ )
11643
+ ] }) }),
11644
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11645
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11646
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11647
+ ] }) })
11648
+ ]
11649
+ }
11650
+ ) });
11651
+ };
11652
+ const schema$2 = addressSchema;
11653
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11654
+ const Shipping = () => {
11655
+ var _a;
11656
+ const { id } = useParams();
11657
+ const { order, isPending, isError, error } = useOrder(id, {
11658
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11659
+ });
11660
+ const {
11661
+ order: preview,
11662
+ isPending: isPreviewPending,
11663
+ isError: isPreviewError,
11664
+ error: previewError
11665
+ } = useOrderPreview(id);
11666
+ useInitiateOrderEdit({ preview });
11667
+ const { onCancel } = useCancelOrderEdit({ preview });
11668
+ if (isError) {
11669
+ throw error;
11670
+ }
11671
+ if (isPreviewError) {
11672
+ throw previewError;
11673
+ }
11674
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11675
+ const isReady = preview && !isPreviewPending && order && !isPending;
11676
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11677
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11678
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11679
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11680
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11681
+ ] }) }) }),
11682
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11683
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11684
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11685
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11686
+ ] }) });
11687
+ };
11688
+ const ShippingForm = ({ preview, order }) => {
11689
+ var _a;
11690
+ const { setIsOpen } = useStackedModal();
11691
+ const [isSubmitting, setIsSubmitting] = useState(false);
11692
+ const [data, setData] = useState(null);
11693
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11694
+ const { shipping_options } = useShippingOptions(
11695
+ {
11696
+ id: appliedShippingOptionIds,
11697
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11698
+ },
11699
+ {
11700
+ enabled: appliedShippingOptionIds.length > 0
11701
+ }
11702
+ );
11703
+ const uniqueShippingProfiles = useMemo(() => {
11704
+ const profiles = /* @__PURE__ */ new Map();
11705
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11706
+ profiles.set(profile.id, profile);
11707
+ });
11708
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11709
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11710
+ });
11711
+ return Array.from(profiles.values());
11712
+ }, [order.items, shipping_options]);
11713
+ const { handleSuccess } = useRouteModal();
11714
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11715
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11716
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11717
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11718
+ const onSubmit = async () => {
11719
+ setIsSubmitting(true);
11720
+ let requestSucceeded = false;
11721
+ await requestOrderEdit(void 0, {
11722
+ onError: (e) => {
11723
+ toast.error(`Failed to request order edit: ${e.message}`);
11724
+ },
11725
+ onSuccess: () => {
11726
+ requestSucceeded = true;
11727
+ }
11728
+ });
11729
+ if (!requestSucceeded) {
11730
+ setIsSubmitting(false);
11731
+ return;
11732
+ }
11733
+ await confirmOrderEdit(void 0, {
11734
+ onError: (e) => {
11735
+ toast.error(`Failed to confirm order edit: ${e.message}`);
11736
+ },
11737
+ onSuccess: () => {
11738
+ handleSuccess();
11739
+ },
11740
+ onSettled: () => {
11741
+ setIsSubmitting(false);
11742
+ }
11743
+ });
11744
+ };
11745
+ const onKeydown = useCallback(
11746
+ (e) => {
11747
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11748
+ if (data || isSubmitting) {
11749
+ return;
11750
+ }
11751
+ onSubmit();
11752
+ }
11753
+ },
11754
+ [data, isSubmitting, onSubmit]
11755
+ );
11756
+ useEffect(() => {
11757
+ document.addEventListener("keydown", onKeydown);
11758
+ return () => {
11759
+ document.removeEventListener("keydown", onKeydown);
11760
+ };
11761
+ }, [onKeydown]);
11762
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11763
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11764
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11765
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11766
+ /* @__PURE__ */ jsxs("div", { children: [
11767
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11768
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11769
+ ] }),
11770
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11771
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11772
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11773
+ /* @__PURE__ */ jsx(
11774
+ Text,
11775
+ {
11776
+ size: "xsmall",
11777
+ weight: "plus",
11778
+ className: "text-ui-fg-muted",
11779
+ children: "Shipping profile"
11780
+ }
11781
+ ),
11782
+ /* @__PURE__ */ jsx(
11783
+ Text,
11784
+ {
11785
+ size: "xsmall",
11786
+ weight: "plus",
11787
+ className: "text-ui-fg-muted",
11788
+ children: "Action"
11789
+ }
11790
+ )
11791
+ ] }),
11792
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11793
+ var _a2, _b, _c, _d, _e, _f, _g;
11794
+ const items = getItemsWithShippingProfile(
11795
+ profile.id,
11796
+ order.items
11797
+ );
11798
+ const hasItems = items.length > 0;
11799
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11800
+ (option) => option.shipping_profile_id === profile.id
11801
+ );
11802
+ const shippingMethod = preview.shipping_methods.find(
11803
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11804
+ );
11805
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11806
+ (action) => action.action === "SHIPPING_ADD"
11807
+ );
11808
+ return /* @__PURE__ */ jsxs(
11809
+ Accordion.Item,
11810
+ {
11811
+ value: profile.id,
11812
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11813
+ children: [
11814
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11815
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11816
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11817
+ IconButton,
11818
+ {
11819
+ size: "2xsmall",
11820
+ variant: "transparent",
11821
+ className: "group/trigger",
11822
+ disabled: !hasItems,
11823
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11824
+ }
11825
+ ) }),
11826
+ !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11827
+ /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11828
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11829
+ /* @__PURE__ */ jsx(
11830
+ Text,
11831
+ {
11832
+ size: "small",
11833
+ weight: "plus",
11834
+ leading: "compact",
11835
+ children: profile.name
11836
+ }
11837
+ ),
11838
+ /* @__PURE__ */ jsxs(
11839
+ Text,
11840
+ {
11841
+ size: "small",
11842
+ leading: "compact",
11843
+ className: "text-ui-fg-subtle",
11844
+ children: [
11845
+ items.length,
11846
+ " ",
11847
+ pluralize(items.length, "items", "item")
11848
+ ]
11849
+ }
11850
+ )
11851
+ ] })
11852
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11853
+ /* @__PURE__ */ jsx(
11854
+ Tooltip,
11855
+ {
11856
+ content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11857
+ var _a3, _b2, _c2;
11858
+ return /* @__PURE__ */ jsx(
11859
+ "li",
11860
+ {
11861
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11862
+ },
11863
+ item.id
11864
+ );
11865
+ }) }),
11866
+ children: /* @__PURE__ */ jsxs(
11867
+ Badge,
11868
+ {
11869
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11870
+ size: "xsmall",
11871
+ children: [
11872
+ /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11873
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11874
+ items.reduce(
11875
+ (acc, item) => acc + item.quantity,
11876
+ 0
11877
+ ),
11878
+ "x",
11879
+ " ",
11880
+ pluralize(items.length, "items", "item")
11881
+ ] })
11882
+ ]
11883
+ }
11884
+ )
11885
+ }
11886
+ ),
11887
+ /* @__PURE__ */ jsx(
11888
+ Tooltip,
11889
+ {
11890
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11891
+ children: /* @__PURE__ */ jsxs(
11892
+ Badge,
11893
+ {
11894
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11895
+ size: "xsmall",
11896
+ children: [
11897
+ /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11898
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11899
+ ]
11900
+ }
11901
+ )
11902
+ }
11903
+ ),
11904
+ /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11905
+ Badge,
11906
+ {
11907
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11908
+ size: "xsmall",
11909
+ children: [
11910
+ /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11911
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11912
+ ]
11913
+ }
11914
+ ) })
11915
+ ] })
11916
+ ] }),
11917
+ shippingOption ? /* @__PURE__ */ jsx(
11918
+ ActionMenu,
11919
+ {
11920
+ groups: [
11921
+ {
11922
+ actions: [
11923
+ hasItems ? {
11924
+ label: "Edit shipping option",
11925
+ icon: /* @__PURE__ */ jsx(Channels, {}),
11926
+ onClick: () => {
11927
+ setIsOpen(
11928
+ STACKED_FOCUS_MODAL_ID,
11929
+ true
11930
+ );
11931
+ setData({
11932
+ shippingProfileId: profile.id,
11933
+ shippingOption,
11934
+ shippingMethod
11935
+ });
11936
+ }
11937
+ } : void 0,
11938
+ {
11939
+ label: "Remove shipping option",
11940
+ icon: /* @__PURE__ */ jsx(Trash, {}),
11941
+ onClick: () => {
11942
+ if (shippingMethod) {
11943
+ if (addShippingMethodAction) {
11944
+ removeActionShippingMethod(
11945
+ addShippingMethodAction.id
11946
+ );
11947
+ } else {
11948
+ removeShippingMethod(
11949
+ shippingMethod.id
11950
+ );
11951
+ }
11952
+ }
11953
+ }
11954
+ }
11955
+ ].filter(Boolean)
11956
+ }
11957
+ ]
11958
+ }
11959
+ ) : /* @__PURE__ */ jsx(
11960
+ StackedModalTrigger,
11961
+ {
11962
+ shippingProfileId: profile.id,
11963
+ shippingOption,
11964
+ shippingMethod,
11965
+ setData,
11966
+ children: "Add shipping option"
11967
+ }
11968
+ )
11969
+ ] }),
11970
+ /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11971
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11972
+ items.map((item, idx) => {
11973
+ var _a3, _b2, _c2, _d2, _e2;
11974
+ return /* @__PURE__ */ jsxs("div", { children: [
11975
+ /* @__PURE__ */ jsxs(
11976
+ "div",
11977
+ {
11978
+ className: "px-3 flex items-center gap-x-3",
11979
+ children: [
11980
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
11981
+ Divider,
11982
+ {
11983
+ variant: "dashed",
11984
+ orientation: "vertical"
11985
+ }
11986
+ ) }),
11987
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11988
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11989
+ Text,
11990
+ {
11991
+ size: "small",
11992
+ leading: "compact",
11993
+ className: "text-ui-fg-subtle",
11994
+ children: [
11995
+ item.quantity,
11996
+ "x"
11997
+ ]
11998
+ }
11999
+ ) }),
12000
+ /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
12001
+ /* @__PURE__ */ jsxs("div", { children: [
12002
+ /* @__PURE__ */ jsxs(
12003
+ Text,
12004
+ {
12005
+ size: "small",
12006
+ leading: "compact",
12007
+ weight: "plus",
12008
+ children: [
12009
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12010
+ " (",
12011
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12012
+ ")"
12013
+ ]
12014
+ }
12015
+ ),
12016
+ /* @__PURE__ */ jsx(
12017
+ Text,
12018
+ {
12019
+ size: "small",
12020
+ leading: "compact",
12021
+ className: "text-ui-fg-subtle",
12022
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12023
+ }
12024
+ )
12025
+ ] })
12026
+ ] })
12027
+ ]
12028
+ },
12029
+ item.id
12030
+ ),
12031
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
12032
+ ] }, item.id);
12033
+ })
12034
+ ] })
12035
+ ]
12255
12036
  },
12256
- ...field
12037
+ profile.id
12038
+ );
12039
+ }) })
12040
+ ] }) })
12041
+ ] }) }),
12042
+ /* @__PURE__ */ jsx(
12043
+ StackedFocusModal,
12044
+ {
12045
+ id: STACKED_FOCUS_MODAL_ID,
12046
+ onOpenChangeCallback: (open) => {
12047
+ if (!open) {
12048
+ setData(null);
12257
12049
  }
12258
- ) })
12259
- ] }) });
12260
- }
12261
- }
12262
- );
12050
+ return open;
12051
+ },
12052
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
12053
+ }
12054
+ )
12055
+ ] }),
12056
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12057
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12058
+ /* @__PURE__ */ jsx(
12059
+ Button,
12060
+ {
12061
+ size: "small",
12062
+ type: "button",
12063
+ isLoading: isSubmitting,
12064
+ onClick: onSubmit,
12065
+ children: "Save"
12066
+ }
12067
+ )
12068
+ ] }) })
12069
+ ] });
12263
12070
  };
12264
- const ShippingOptionField = ({
12071
+ const StackedModalTrigger = ({
12265
12072
  shippingProfileId,
12266
- preview,
12267
- control
12073
+ shippingOption,
12074
+ shippingMethod,
12075
+ setData,
12076
+ children
12268
12077
  }) => {
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
12078
+ const { setIsOpen, getIsOpen } = useStackedModal();
12079
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12080
+ const onToggle = () => {
12081
+ if (isOpen) {
12082
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12083
+ setData(null);
12084
+ } else {
12085
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12086
+ setData({
12087
+ shippingProfileId,
12088
+ shippingOption,
12089
+ shippingMethod
12278
12090
  });
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
12091
  }
12332
- );
12333
- };
12334
- const CustomAmountField = ({
12335
- control,
12336
- currencyCode
12337
- }) => {
12092
+ };
12338
12093
  return /* @__PURE__ */ jsx(
12339
- Form$2.Field,
12094
+ Button,
12340
12095
  {
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
- }
12096
+ size: "small",
12097
+ variant: "secondary",
12098
+ onClick: onToggle,
12099
+ className: "text-ui-fg-primary shrink-0",
12100
+ children
12360
12101
  }
12361
12102
  );
12362
12103
  };
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;
12104
+ const ShippingProfileForm = ({
12105
+ data,
12106
+ order,
12107
+ preview
12108
+ }) => {
12109
+ var _a, _b, _c, _d, _e, _f;
12110
+ const { setIsOpen } = useStackedModal();
12382
12111
  const form = useForm({
12112
+ resolver: zodResolver(shippingMethodSchema),
12383
12113
  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)
12114
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12115
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12116
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12117
+ }
12396
12118
  });
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
12119
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12120
+ const {
12121
+ mutateAsync: updateShippingMethod,
12122
+ isPending: isUpdatingShippingMethod
12123
+ } = useDraftOrderUpdateShippingMethod(order.id);
12124
+ const onSubmit = form.handleSubmit(async (values) => {
12125
+ if (isEqual(values, form.formState.defaultValues)) {
12126
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12127
+ return;
12128
+ }
12129
+ if (data.shippingMethod) {
12130
+ await updateShippingMethod(
12131
+ {
12132
+ method_id: data.shippingMethod.id,
12133
+ shipping_option_id: values.shipping_option_id,
12134
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12135
+ },
12136
+ {
12137
+ onError: (e) => {
12138
+ toast.error(e.message);
12139
+ },
12140
+ onSuccess: () => {
12141
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12142
+ }
12413
12143
  }
12144
+ );
12145
+ return;
12146
+ }
12147
+ await addShippingMethod(
12148
+ {
12149
+ shipping_option_id: values.shipping_option_id,
12150
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12414
12151
  },
12415
12152
  {
12416
- onSuccess: () => {
12417
- handleSuccess();
12153
+ onError: (e) => {
12154
+ toast.error(e.message);
12418
12155
  },
12419
- onError: (error) => {
12420
- toast.error(error.message);
12156
+ onSuccess: () => {
12157
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12421
12158
  }
12422
12159
  }
12423
12160
  );
12424
12161
  });
12425
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12162
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12426
12163
  KeyboundForm,
12427
12164
  {
12428
- className: "flex flex-1 flex-col overflow-hidden",
12165
+ className: "flex h-full flex-col overflow-hidden",
12429
12166
  onSubmit,
12430
12167
  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: [
12168
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12169
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12170
+ /* @__PURE__ */ jsxs("div", { children: [
12171
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12172
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12173
+ ] }),
12174
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12432
12175
  /* @__PURE__ */ jsx(
12433
- Form$2.Field,
12176
+ LocationField,
12434
12177
  {
12435
12178
  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
- ] })
12179
+ setValue: form.setValue
12442
12180
  }
12443
12181
  ),
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
- ] }),
12182
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12470
12183
  /* @__PURE__ */ jsx(
12471
- Form$2.Field,
12184
+ ShippingOptionField,
12472
12185
  {
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
- ] })
12186
+ shippingProfileId: data.shippingProfileId,
12187
+ preview,
12188
+ control: form.control
12480
12189
  }
12481
12190
  ),
12191
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12482
12192
  /* @__PURE__ */ jsx(
12483
- Form$2.Field,
12193
+ CustomAmountField,
12484
12194
  {
12485
12195
  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
- ] })
12196
+ currencyCode: order.currency_code
12492
12197
  }
12493
12198
  ),
12199
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12494
12200
  /* @__PURE__ */ jsx(
12495
- Form$2.Field,
12201
+ ItemsPreview,
12496
12202
  {
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
- ] })
12203
+ order,
12204
+ shippingProfileId: data.shippingProfileId
12504
12205
  }
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,
12206
+ )
12207
+ ] }) }) }),
12208
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12209
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12210
+ /* @__PURE__ */ jsx(
12211
+ Button,
12212
+ {
12213
+ size: "small",
12214
+ type: "submit",
12215
+ isLoading: isPending || isUpdatingShippingMethod,
12216
+ children: data.shippingMethod ? "Update" : "Add"
12217
+ }
12218
+ )
12219
+ ] }) })
12220
+ ]
12221
+ }
12222
+ ) }) });
12223
+ };
12224
+ const shippingMethodSchema = objectType({
12225
+ location_id: stringType(),
12226
+ shipping_option_id: stringType(),
12227
+ custom_amount: unionType([numberType(), stringType()]).optional()
12228
+ });
12229
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12230
+ const matches = order.items.filter(
12231
+ (item) => {
12232
+ var _a, _b, _c;
12233
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12234
+ }
12235
+ );
12236
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12237
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12238
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12239
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12240
+ ] }) }),
12241
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12242
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12243
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12244
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12245
+ ] }),
12246
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12247
+ "div",
12248
+ {
12249
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12250
+ children: [
12251
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12252
+ /* @__PURE__ */ jsx(
12253
+ Thumbnail,
12254
+ {
12255
+ thumbnail: item.thumbnail,
12256
+ alt: item.product_title ?? void 0
12257
+ }
12258
+ ),
12259
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12260
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12261
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12262
+ /* @__PURE__ */ jsxs(
12263
+ Text,
12264
+ {
12265
+ size: "small",
12266
+ leading: "compact",
12267
+ className: "text-ui-fg-subtle",
12268
+ children: [
12269
+ "(",
12270
+ item.variant_title,
12271
+ ")"
12272
+ ]
12273
+ }
12274
+ )
12275
+ ] }),
12276
+ /* @__PURE__ */ jsx(
12277
+ Text,
12278
+ {
12279
+ size: "small",
12280
+ leading: "compact",
12281
+ className: "text-ui-fg-subtle",
12282
+ children: item.variant_sku
12283
+ }
12284
+ )
12285
+ ] })
12286
+ ] }),
12287
+ /* @__PURE__ */ jsxs(
12288
+ Text,
12521
12289
  {
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
- ] })
12290
+ size: "small",
12291
+ leading: "compact",
12292
+ className: "text-ui-fg-subtle",
12293
+ children: [
12294
+ item.quantity,
12295
+ "x"
12296
+ ]
12529
12297
  }
12530
12298
  )
12299
+ ]
12300
+ },
12301
+ item.id
12302
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12303
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12304
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12305
+ 'No items found for "',
12306
+ query,
12307
+ '".'
12308
+ ] })
12309
+ ] }) })
12310
+ ] })
12311
+ ] });
12312
+ };
12313
+ const LocationField = ({ control, setValue }) => {
12314
+ const locations = useComboboxData({
12315
+ queryKey: ["locations"],
12316
+ queryFn: async (params) => {
12317
+ return await sdk.admin.stockLocation.list(params);
12318
+ },
12319
+ getOptions: (data) => {
12320
+ return data.stock_locations.map((location) => ({
12321
+ label: location.name,
12322
+ value: location.id
12323
+ }));
12324
+ }
12325
+ });
12326
+ return /* @__PURE__ */ jsx(
12327
+ Form$2.Field,
12328
+ {
12329
+ control,
12330
+ name: "location_id",
12331
+ render: ({ field: { onChange, ...field } }) => {
12332
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12333
+ /* @__PURE__ */ jsxs("div", { children: [
12334
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12335
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12336
+ ] }),
12337
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12338
+ Combobox,
12339
+ {
12340
+ options: locations.options,
12341
+ fetchNextPage: locations.fetchNextPage,
12342
+ isFetchingNextPage: locations.isFetchingNextPage,
12343
+ searchValue: locations.searchValue,
12344
+ onSearchValueChange: locations.onSearchValueChange,
12345
+ placeholder: "Select location",
12346
+ onChange: (value) => {
12347
+ setValue("shipping_option_id", "", {
12348
+ shouldDirty: true,
12349
+ shouldTouch: true
12350
+ });
12351
+ onChange(value);
12352
+ },
12353
+ ...field
12354
+ }
12355
+ ) })
12356
+ ] }) });
12357
+ }
12358
+ }
12359
+ );
12360
+ };
12361
+ const ShippingOptionField = ({
12362
+ shippingProfileId,
12363
+ preview,
12364
+ control
12365
+ }) => {
12366
+ var _a;
12367
+ const locationId = useWatch({ control, name: "location_id" });
12368
+ const shippingOptions = useComboboxData({
12369
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12370
+ queryFn: async (params) => {
12371
+ return await sdk.admin.shippingOption.list({
12372
+ ...params,
12373
+ stock_location_id: locationId,
12374
+ shipping_profile_id: shippingProfileId
12375
+ });
12376
+ },
12377
+ getOptions: (data) => {
12378
+ return data.shipping_options.map((option) => {
12379
+ var _a2;
12380
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12381
+ (r) => r.attribute === "is_return" && r.value === "true"
12382
+ )) {
12383
+ return void 0;
12384
+ }
12385
+ return {
12386
+ label: option.name,
12387
+ value: option.id
12388
+ };
12389
+ }).filter(Boolean);
12390
+ },
12391
+ enabled: !!locationId && !!shippingProfileId,
12392
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12393
+ });
12394
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12395
+ return /* @__PURE__ */ jsx(
12396
+ Form$2.Field,
12397
+ {
12398
+ control,
12399
+ name: "shipping_option_id",
12400
+ render: ({ field }) => {
12401
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12402
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12403
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12404
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12531
12405
  ] }),
12532
12406
  /* @__PURE__ */ jsx(
12533
- Form$2.Field,
12407
+ ConditionalTooltip,
12534
12408
  {
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
- ] })
12409
+ content: tooltipContent,
12410
+ showTooltip: !locationId || !shippingProfileId,
12411
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12412
+ Combobox,
12413
+ {
12414
+ options: shippingOptions.options,
12415
+ fetchNextPage: shippingOptions.fetchNextPage,
12416
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12417
+ searchValue: shippingOptions.searchValue,
12418
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12419
+ placeholder: "Select shipping option",
12420
+ ...field,
12421
+ disabled: !locationId || !shippingProfileId
12422
+ }
12423
+ ) }) })
12542
12424
  }
12543
- ),
12544
- /* @__PURE__ */ jsx(
12545
- Form$2.Field,
12425
+ )
12426
+ ] }) });
12427
+ }
12428
+ }
12429
+ );
12430
+ };
12431
+ const CustomAmountField = ({
12432
+ control,
12433
+ currencyCode
12434
+ }) => {
12435
+ return /* @__PURE__ */ jsx(
12436
+ Form$2.Field,
12437
+ {
12438
+ control,
12439
+ name: "custom_amount",
12440
+ render: ({ field: { onChange, ...field } }) => {
12441
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12442
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12443
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12444
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12445
+ ] }),
12446
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12447
+ CurrencyInput,
12546
12448
  {
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
- ] })
12449
+ ...field,
12450
+ onValueChange: (value) => onChange(value),
12451
+ symbol: getNativeSymbol(currencyCode),
12452
+ code: currencyCode
12554
12453
  }
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
- ]
12454
+ ) })
12455
+ ] });
12456
+ }
12562
12457
  }
12563
- ) });
12458
+ );
12564
12459
  };
12565
- const schema$1 = addressSchema;
12566
12460
  const TransferOwnership = () => {
12567
12461
  const { id } = useParams();
12568
12462
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12586,7 +12480,7 @@ const TransferOwnershipForm = ({ order }) => {
12586
12480
  defaultValues: {
12587
12481
  customer_id: order.customer_id || ""
12588
12482
  },
12589
- resolver: zodResolver(schema)
12483
+ resolver: zodResolver(schema$1)
12590
12484
  });
12591
12485
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
12486
  const { handleSuccess } = useRouteModal();
@@ -13036,9 +12930,115 @@ const Illustration = () => {
13036
12930
  }
13037
12931
  );
13038
12932
  };
13039
- const schema = objectType({
12933
+ const schema$1 = objectType({
13040
12934
  customer_id: stringType().min(1)
13041
12935
  });
12936
+ const SalesChannel = () => {
12937
+ const { id } = useParams();
12938
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12939
+ id,
12940
+ {
12941
+ fields: "+sales_channel_id"
12942
+ },
12943
+ {
12944
+ enabled: !!id
12945
+ }
12946
+ );
12947
+ if (isError) {
12948
+ throw error;
12949
+ }
12950
+ const ISrEADY = !!draft_order && !isPending;
12951
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12952
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12953
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12954
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12955
+ ] }),
12956
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12957
+ ] });
12958
+ };
12959
+ const SalesChannelForm = ({ order }) => {
12960
+ const form = useForm({
12961
+ defaultValues: {
12962
+ sales_channel_id: order.sales_channel_id || ""
12963
+ },
12964
+ resolver: zodResolver(schema)
12965
+ });
12966
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12967
+ const { handleSuccess } = useRouteModal();
12968
+ const onSubmit = form.handleSubmit(async (data) => {
12969
+ await mutateAsync(
12970
+ {
12971
+ sales_channel_id: data.sales_channel_id
12972
+ },
12973
+ {
12974
+ onSuccess: () => {
12975
+ toast.success("Sales channel updated");
12976
+ handleSuccess();
12977
+ },
12978
+ onError: (error) => {
12979
+ toast.error(error.message);
12980
+ }
12981
+ }
12982
+ );
12983
+ });
12984
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12985
+ KeyboundForm,
12986
+ {
12987
+ className: "flex flex-1 flex-col overflow-hidden",
12988
+ onSubmit,
12989
+ children: [
12990
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12991
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12992
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12993
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12994
+ ] }) })
12995
+ ]
12996
+ }
12997
+ ) });
12998
+ };
12999
+ const SalesChannelField = ({ control, order }) => {
13000
+ const salesChannels = useComboboxData({
13001
+ queryFn: async (params) => {
13002
+ return await sdk.admin.salesChannel.list(params);
13003
+ },
13004
+ queryKey: ["sales-channels"],
13005
+ getOptions: (data) => {
13006
+ return data.sales_channels.map((salesChannel) => ({
13007
+ label: salesChannel.name,
13008
+ value: salesChannel.id
13009
+ }));
13010
+ },
13011
+ defaultValue: order.sales_channel_id || void 0
13012
+ });
13013
+ return /* @__PURE__ */ jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control,
13017
+ name: "sales_channel_id",
13018
+ render: ({ field }) => {
13019
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
13021
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
13022
+ Combobox,
13023
+ {
13024
+ options: salesChannels.options,
13025
+ fetchNextPage: salesChannels.fetchNextPage,
13026
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
13027
+ searchValue: salesChannels.searchValue,
13028
+ onSearchValueChange: salesChannels.onSearchValueChange,
13029
+ placeholder: "Select sales channel",
13030
+ ...field
13031
+ }
13032
+ ) }),
13033
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13034
+ ] });
13035
+ }
13036
+ }
13037
+ );
13038
+ };
13039
+ const schema = objectType({
13040
+ sales_channel_id: stringType().min(1)
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13063,41 +13063,41 @@ const routeModule = {
13063
13063
  Component: BillingAddress,
13064
13064
  path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
- {
13067
- Component: Email,
13068
- path: "/draft-orders/:id/email"
13069
- },
13070
13066
  {
13071
13067
  Component: CustomItems,
13072
13068
  path: "/draft-orders/:id/custom-items"
13073
13069
  },
13074
13070
  {
13075
- Component: Promotions,
13076
- path: "/draft-orders/:id/promotions"
13077
- },
13078
- {
13079
- Component: Metadata,
13080
- path: "/draft-orders/:id/metadata"
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13081
13073
  },
13082
13074
  {
13083
13075
  Component: Items,
13084
13076
  path: "/draft-orders/:id/items"
13085
13077
  },
13086
13078
  {
13087
- Component: SalesChannel,
13088
- path: "/draft-orders/:id/sales-channel"
13079
+ Component: Metadata,
13080
+ path: "/draft-orders/:id/metadata"
13089
13081
  },
13090
13082
  {
13091
- Component: Shipping,
13092
- path: "/draft-orders/:id/shipping"
13083
+ Component: Promotions,
13084
+ path: "/draft-orders/:id/promotions"
13093
13085
  },
13094
13086
  {
13095
13087
  Component: ShippingAddress,
13096
13088
  path: "/draft-orders/:id/shipping-address"
13097
13089
  },
13090
+ {
13091
+ Component: Shipping,
13092
+ path: "/draft-orders/:id/shipping"
13093
+ },
13098
13094
  {
13099
13095
  Component: TransferOwnership,
13100
13096
  path: "/draft-orders/:id/transfer-ownership"
13097
+ },
13098
+ {
13099
+ Component: SalesChannel,
13100
+ path: "/draft-orders/:id/sales-channel"
13101
13101
  }
13102
13102
  ]
13103
13103
  }