@medusajs/draft-order 2.12.0-preview-20251103180145 → 2.12.1

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.
@@ -9,7 +9,7 @@ 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";
11
11
  import { zodResolver } from "@hookform/resolvers/zod";
12
- import { FormProvider, Controller, useFormContext, useFormState, useForm, useWatch, useFieldArray } from "react-hook-form";
12
+ import { FormProvider, useFormContext, useFormState, Controller, useForm, useWatch, useFieldArray } from "react-hook-form";
13
13
  import { Slot, Collapsible, Accordion } from "radix-ui";
14
14
  import { ComboboxProvider, Combobox as Combobox$1, ComboboxDisclosure, ComboboxPopover, ComboboxItem, ComboboxItemCheck, ComboboxItemValue, Separator } from "@ariakit/react";
15
15
  import { matchSorter } from "match-sorter";
@@ -345,10 +345,14 @@ const DataTableAction = ({
345
345
  }
346
346
  return /* @__PURE__ */ jsx(Button, { ...buttonProps, onClick: props.onClick, children: label });
347
347
  };
348
+ const backendUrl = __BACKEND_URL__ ?? "/";
349
+ const authType = __AUTH_TYPE__ ?? "session";
350
+ const jwtTokenStorageKey = __JWT_TOKEN_STORAGE_KEY__ || void 0;
348
351
  const sdk = new Medusa({
349
- baseUrl: __BACKEND_URL__ || "/",
352
+ baseUrl: backendUrl,
350
353
  auth: {
351
- type: "session"
354
+ type: authType,
355
+ jwtTokenStorageKey
352
356
  }
353
357
  });
354
358
  const CUSTOMER_QUERY_KEY = "customers";
@@ -4647,9 +4651,6 @@ ZodReadonly.create = (type, params) => {
4647
4651
  ...processCreateParams(params)
4648
4652
  });
4649
4653
  };
4650
- ({
4651
- object: ZodObject.lazycreate
4652
- });
4653
4654
  var ZodFirstPartyTypeKind;
4654
4655
  (function(ZodFirstPartyTypeKind2) {
4655
4656
  ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
@@ -4696,7 +4697,6 @@ const anyType = ZodAny.create;
4696
4697
  ZodNever.create;
4697
4698
  const arrayType = ZodArray.create;
4698
4699
  const objectType = ZodObject.create;
4699
- ZodObject.strictCreate;
4700
4700
  const unionType = ZodUnion.create;
4701
4701
  ZodIntersection.create;
4702
4702
  ZodTuple.create;
@@ -8722,7 +8722,7 @@ const Contact = ({ order }) => {
8722
8722
  children: phone
8723
8723
  }
8724
8724
  ),
8725
- /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Copy, { content: email, className: "text-ui-fg-muted" }) })
8725
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(Copy, { content: phone, className: "text-ui-fg-muted" }) })
8726
8726
  ] })
8727
8727
  ] })
8728
8728
  ] });
@@ -10818,632 +10818,632 @@ const customItemSchema = objectType({
10818
10818
  quantity: numberType(),
10819
10819
  unit_price: unionType([numberType(), stringType()])
10820
10820
  });
10821
- const InlineTip = forwardRef(
10822
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10824
- return /* @__PURE__ */ jsxs(
10825
- "div",
10826
- {
10827
- ref,
10828
- className: clx(
10829
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10830
- className
10831
- ),
10832
- ...props,
10833
- children: [
10834
- /* @__PURE__ */ jsx(
10835
- "div",
10836
- {
10837
- role: "presentation",
10838
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10839
- "bg-ui-tag-orange-icon": variant === "warning"
10840
- })
10841
- }
10842
- ),
10843
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10844
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10845
- labelValue,
10846
- ":"
10847
- ] }),
10848
- " ",
10849
- children
10850
- ] })
10851
- ]
10852
- }
10853
- );
10854
- }
10855
- );
10856
- InlineTip.displayName = "InlineTip";
10857
- const MetadataFieldSchema = objectType({
10858
- key: stringType(),
10859
- disabled: booleanType().optional(),
10860
- value: anyType()
10861
- });
10862
- const MetadataSchema = objectType({
10863
- metadata: arrayType(MetadataFieldSchema)
10864
- });
10865
- const Metadata = () => {
10866
- const { id } = useParams();
10867
- const { order, isPending, isError, error } = useOrder(id, {
10868
- fields: "metadata"
10821
+ const PROMOTION_QUERY_KEY = "promotions";
10822
+ const promotionsQueryKeys = {
10823
+ list: (query2) => [
10824
+ PROMOTION_QUERY_KEY,
10825
+ query2 ? query2 : void 0
10826
+ ],
10827
+ detail: (id, query2) => [
10828
+ PROMOTION_QUERY_KEY,
10829
+ id,
10830
+ query2 ? query2 : void 0
10831
+ ]
10832
+ };
10833
+ const usePromotions = (query2, options) => {
10834
+ const { data, ...rest } = useQuery({
10835
+ queryKey: promotionsQueryKeys.list(query2),
10836
+ queryFn: async () => sdk.admin.promotion.list(query2),
10837
+ ...options
10869
10838
  });
10870
- if (isError) {
10871
- throw error;
10839
+ return { ...data, ...rest };
10840
+ };
10841
+ const Promotions = () => {
10842
+ const { id } = useParams();
10843
+ const {
10844
+ order: preview,
10845
+ isError: isPreviewError,
10846
+ error: previewError
10847
+ } = useOrderPreview(id, void 0);
10848
+ useInitiateOrderEdit({ preview });
10849
+ const { onCancel } = useCancelOrderEdit({ preview });
10850
+ if (isPreviewError) {
10851
+ throw previewError;
10872
10852
  }
10873
- const isReady = !isPending && !!order;
10874
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10875
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10876
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10877
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10878
- ] }),
10879
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10853
+ const isReady = !!preview;
10854
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10855
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10856
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10880
10857
  ] });
10881
10858
  };
10882
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10883
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10884
- const MetadataForm = ({ orderId, metadata }) => {
10859
+ const PromotionForm = ({ preview }) => {
10860
+ const { items, shipping_methods } = preview;
10861
+ const [isSubmitting, setIsSubmitting] = useState(false);
10862
+ const [comboboxValue, setComboboxValue] = useState("");
10885
10863
  const { handleSuccess } = useRouteModal();
10886
- const hasUneditableRows = getHasUneditableRows(metadata);
10887
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10888
- const form = useForm({
10889
- defaultValues: {
10890
- metadata: getDefaultValues(metadata)
10864
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10865
+ const promoIds = getPromotionIds(items, shipping_methods);
10866
+ const { promotions, isPending, isError, error } = usePromotions(
10867
+ {
10868
+ id: promoIds
10891
10869
  },
10892
- resolver: zodResolver(MetadataSchema)
10870
+ {
10871
+ enabled: !!promoIds.length
10872
+ }
10873
+ );
10874
+ const comboboxData = useComboboxData({
10875
+ queryKey: ["promotions", "combobox", promoIds],
10876
+ queryFn: async (params) => {
10877
+ return await sdk.admin.promotion.list({
10878
+ ...params,
10879
+ id: {
10880
+ $nin: promoIds
10881
+ }
10882
+ });
10883
+ },
10884
+ getOptions: (data) => {
10885
+ return data.promotions.map((promotion) => ({
10886
+ label: promotion.code,
10887
+ value: promotion.code
10888
+ }));
10889
+ }
10893
10890
  });
10894
- const handleSubmit = form.handleSubmit(async (data) => {
10895
- const parsedData = parseValues(data);
10896
- await mutateAsync(
10891
+ const add = async (value) => {
10892
+ if (!value) {
10893
+ return;
10894
+ }
10895
+ addPromotions(
10897
10896
  {
10898
- metadata: parsedData
10897
+ promo_codes: [value]
10899
10898
  },
10900
10899
  {
10901
- onSuccess: () => {
10902
- toast.success("Metadata updated");
10903
- handleSuccess();
10900
+ onError: (e) => {
10901
+ toast.error(e.message);
10902
+ comboboxData.onSearchValueChange("");
10903
+ setComboboxValue("");
10904
10904
  },
10905
- onError: (error) => {
10906
- toast.error(error.message);
10905
+ onSuccess: () => {
10906
+ comboboxData.onSearchValueChange("");
10907
+ setComboboxValue("");
10907
10908
  }
10908
10909
  }
10909
10910
  );
10910
- });
10911
- const { fields, insert, remove } = useFieldArray({
10912
- control: form.control,
10913
- name: "metadata"
10914
- });
10915
- function deleteRow(index) {
10916
- remove(index);
10917
- if (fields.length === 1) {
10918
- insert(0, {
10919
- key: "",
10920
- value: "",
10921
- disabled: false
10922
- });
10911
+ };
10912
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10913
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10914
+ const onSubmit = async () => {
10915
+ setIsSubmitting(true);
10916
+ let requestSucceeded = false;
10917
+ await requestOrderEdit(void 0, {
10918
+ onError: (e) => {
10919
+ toast.error(e.message);
10920
+ },
10921
+ onSuccess: () => {
10922
+ requestSucceeded = true;
10923
+ }
10924
+ });
10925
+ if (!requestSucceeded) {
10926
+ setIsSubmitting(false);
10927
+ return;
10923
10928
  }
10924
- }
10925
- function insertRow(index, position) {
10926
- insert(index + (position === "above" ? 0 : 1), {
10927
- key: "",
10928
- value: "",
10929
- disabled: false
10929
+ await confirmOrderEdit(void 0, {
10930
+ onError: (e) => {
10931
+ toast.error(e.message);
10932
+ },
10933
+ onSuccess: () => {
10934
+ handleSuccess();
10935
+ },
10936
+ onSettled: () => {
10937
+ setIsSubmitting(false);
10938
+ }
10930
10939
  });
10940
+ };
10941
+ if (isError) {
10942
+ throw error;
10931
10943
  }
10932
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10933
- KeyboundForm,
10934
- {
10935
- onSubmit: handleSubmit,
10936
- className: "flex flex-1 flex-col overflow-hidden",
10937
- children: [
10938
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10939
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10940
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10941
- /* @__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" }) }),
10942
- /* @__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" }) })
10943
- ] }),
10944
- fields.map((field, index) => {
10945
- const isDisabled = field.disabled || false;
10946
- let placeholder = "-";
10947
- if (typeof field.value === "object") {
10948
- placeholder = "{ ... }";
10949
- }
10950
- if (Array.isArray(field.value)) {
10951
- placeholder = "[ ... ]";
10952
- }
10953
- return /* @__PURE__ */ jsx(
10954
- ConditionalTooltip,
10955
- {
10956
- showTooltip: isDisabled,
10957
- content: "This row is disabled because it contains non-primitive data.",
10958
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10959
- /* @__PURE__ */ jsxs(
10960
- "div",
10961
- {
10962
- className: clx("grid grid-cols-2 divide-x", {
10963
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10964
- }),
10965
- children: [
10966
- /* @__PURE__ */ jsx(
10967
- Form$2.Field,
10968
- {
10969
- control: form.control,
10970
- name: `metadata.${index}.key`,
10971
- render: ({ field: field2 }) => {
10972
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10973
- GridInput,
10974
- {
10975
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10976
- ...field2,
10977
- disabled: isDisabled,
10978
- placeholder: "Key"
10979
- }
10980
- ) }) });
10981
- }
10982
- }
10983
- ),
10984
- /* @__PURE__ */ jsx(
10985
- Form$2.Field,
10986
- {
10987
- control: form.control,
10988
- name: `metadata.${index}.value`,
10989
- render: ({ field: { value, ...field2 } }) => {
10990
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10991
- GridInput,
10992
- {
10993
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10994
- ...field2,
10995
- value: isDisabled ? placeholder : value,
10996
- disabled: isDisabled,
10997
- placeholder: "Value"
10998
- }
10999
- ) }) });
11000
- }
11001
- }
11002
- )
11003
- ]
11004
- }
11005
- ),
11006
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11007
- /* @__PURE__ */ jsx(
11008
- DropdownMenu.Trigger,
11009
- {
11010
- className: clx(
11011
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11012
- {
11013
- hidden: isDisabled
11014
- }
11015
- ),
11016
- disabled: isDisabled,
11017
- asChild: true,
11018
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11019
- }
11020
- ),
11021
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11022
- /* @__PURE__ */ jsxs(
11023
- DropdownMenu.Item,
11024
- {
11025
- className: "gap-x-2",
11026
- onClick: () => insertRow(index, "above"),
11027
- children: [
11028
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11029
- "Insert row above"
11030
- ]
11031
- }
11032
- ),
11033
- /* @__PURE__ */ jsxs(
11034
- DropdownMenu.Item,
11035
- {
11036
- className: "gap-x-2",
11037
- onClick: () => insertRow(index, "below"),
11038
- children: [
11039
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11040
- "Insert row below"
11041
- ]
11042
- }
11043
- ),
11044
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11045
- /* @__PURE__ */ jsxs(
11046
- DropdownMenu.Item,
11047
- {
11048
- className: "gap-x-2",
11049
- onClick: () => deleteRow(index),
11050
- children: [
11051
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11052
- "Delete row"
11053
- ]
11054
- }
11055
- )
11056
- ] })
11057
- ] })
11058
- ] })
11059
- },
11060
- field.id
11061
- );
11062
- })
11063
- ] }),
11064
- 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." })
10944
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10945
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10946
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10947
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10948
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10949
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11065
10950
  ] }),
11066
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11067
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11068
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11069
- ] }) })
11070
- ]
11071
- }
11072
- ) });
11073
- };
11074
- const GridInput = forwardRef(({ className, ...props }, ref) => {
11075
- return /* @__PURE__ */ jsx(
11076
- "input",
11077
- {
11078
- ref,
11079
- ...props,
11080
- autoComplete: "off",
11081
- className: clx(
11082
- "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",
11083
- className
10951
+ /* @__PURE__ */ jsx(
10952
+ Combobox,
10953
+ {
10954
+ id: "promotion-combobox",
10955
+ "aria-describedby": "promotion-combobox-hint",
10956
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10957
+ fetchNextPage: comboboxData.fetchNextPage,
10958
+ options: comboboxData.options,
10959
+ onSearchValueChange: comboboxData.onSearchValueChange,
10960
+ searchValue: comboboxData.searchValue,
10961
+ disabled: comboboxData.disabled || isAddingPromotions,
10962
+ onChange: add,
10963
+ value: comboboxValue
10964
+ }
10965
+ )
10966
+ ] }),
10967
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10968
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10969
+ PromotionItem,
10970
+ {
10971
+ promotion,
10972
+ orderId: preview.id,
10973
+ isLoading: isPending
10974
+ },
10975
+ promotion.id
10976
+ )) })
10977
+ ] }) }),
10978
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10979
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10980
+ /* @__PURE__ */ jsx(
10981
+ Button,
10982
+ {
10983
+ size: "small",
10984
+ type: "submit",
10985
+ isLoading: isSubmitting || isAddingPromotions,
10986
+ children: "Save"
10987
+ }
11084
10988
  )
11085
- }
11086
- );
11087
- });
11088
- GridInput.displayName = "MetadataForm.GridInput";
11089
- const PlaceholderInner = () => {
11090
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11091
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11092
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11093
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11094
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11095
10989
  ] }) })
11096
10990
  ] });
11097
10991
  };
11098
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11099
- function getDefaultValues(metadata) {
11100
- if (!metadata || !Object.keys(metadata).length) {
11101
- return [
10992
+ const PromotionItem = ({
10993
+ promotion,
10994
+ orderId,
10995
+ isLoading
10996
+ }) => {
10997
+ var _a;
10998
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10999
+ const onRemove = async () => {
11000
+ removePromotions(
11102
11001
  {
11103
- key: "",
11104
- value: "",
11105
- disabled: false
11002
+ promo_codes: [promotion.code]
11003
+ },
11004
+ {
11005
+ onError: (e) => {
11006
+ toast.error(e.message);
11007
+ }
11106
11008
  }
11107
- ];
11009
+ );
11010
+ };
11011
+ const displayValue = getDisplayValue(promotion);
11012
+ return /* @__PURE__ */ jsxs(
11013
+ "div",
11014
+ {
11015
+ className: clx(
11016
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11017
+ {
11018
+ "animate-pulse": isLoading
11019
+ }
11020
+ ),
11021
+ children: [
11022
+ /* @__PURE__ */ jsxs("div", { children: [
11023
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11024
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11025
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11026
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11027
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11028
+ ] }),
11029
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11030
+ ] })
11031
+ ] }),
11032
+ /* @__PURE__ */ jsx(
11033
+ IconButton,
11034
+ {
11035
+ size: "small",
11036
+ type: "button",
11037
+ variant: "transparent",
11038
+ onClick: onRemove,
11039
+ isLoading: isPending || isLoading,
11040
+ children: /* @__PURE__ */ jsx(XMark, {})
11041
+ }
11042
+ )
11043
+ ]
11044
+ },
11045
+ promotion.id
11046
+ );
11047
+ };
11048
+ function getDisplayValue(promotion) {
11049
+ var _a, _b, _c, _d;
11050
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11051
+ if (!value) {
11052
+ return null;
11108
11053
  }
11109
- return Object.entries(metadata).map(([key, value]) => {
11110
- if (!EDITABLE_TYPES.includes(typeof value)) {
11111
- return {
11112
- key,
11113
- value,
11114
- disabled: true
11115
- };
11116
- }
11117
- let stringValue = value;
11118
- if (typeof value !== "string") {
11119
- stringValue = JSON.stringify(value);
11054
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11055
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11056
+ if (!currency) {
11057
+ return null;
11120
11058
  }
11121
- return {
11122
- key,
11123
- value: stringValue,
11124
- original_key: key
11125
- };
11126
- });
11059
+ return getLocaleAmount(value, currency);
11060
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11061
+ return formatPercentage(value);
11062
+ }
11063
+ return null;
11127
11064
  }
11128
- function parseValues(values) {
11129
- const metadata = values.metadata;
11130
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11131
- if (isEmpty) {
11132
- return null;
11065
+ const formatter = new Intl.NumberFormat([], {
11066
+ style: "percent",
11067
+ minimumFractionDigits: 2
11068
+ });
11069
+ const formatPercentage = (value, isPercentageValue = false) => {
11070
+ let val = value || 0;
11071
+ if (!isPercentageValue) {
11072
+ val = val / 100;
11133
11073
  }
11134
- const update = {};
11135
- metadata.forEach((field) => {
11136
- let key = field.key;
11137
- let value = field.value;
11138
- const disabled = field.disabled;
11139
- if (!key || !value) {
11140
- return;
11141
- }
11142
- if (disabled) {
11143
- update[key] = value;
11144
- return;
11074
+ return formatter.format(val);
11075
+ };
11076
+ function getPromotionIds(items, shippingMethods) {
11077
+ const promotionIds = /* @__PURE__ */ new Set();
11078
+ for (const item of items) {
11079
+ if (item.adjustments) {
11080
+ for (const adjustment of item.adjustments) {
11081
+ if (adjustment.promotion_id) {
11082
+ promotionIds.add(adjustment.promotion_id);
11083
+ }
11084
+ }
11145
11085
  }
11146
- key = key.trim();
11147
- value = value.trim();
11148
- if (value === "true") {
11149
- update[key] = true;
11150
- } else if (value === "false") {
11151
- update[key] = false;
11152
- } else {
11153
- const parsedNumber = parseFloat(value);
11154
- if (!isNaN(parsedNumber)) {
11155
- update[key] = parsedNumber;
11156
- } else {
11157
- update[key] = value;
11086
+ }
11087
+ for (const shippingMethod of shippingMethods) {
11088
+ if (shippingMethod.adjustments) {
11089
+ for (const adjustment of shippingMethod.adjustments) {
11090
+ if (adjustment.promotion_id) {
11091
+ promotionIds.add(adjustment.promotion_id);
11092
+ }
11158
11093
  }
11159
11094
  }
11160
- });
11161
- return update;
11162
- }
11163
- function getHasUneditableRows(metadata) {
11164
- if (!metadata) {
11165
- return false;
11166
11095
  }
11167
- return Object.values(metadata).some(
11168
- (value) => !EDITABLE_TYPES.includes(typeof value)
11169
- );
11096
+ return Array.from(promotionIds);
11170
11097
  }
11171
- const PROMOTION_QUERY_KEY = "promotions";
11172
- const promotionsQueryKeys = {
11173
- list: (query2) => [
11174
- PROMOTION_QUERY_KEY,
11175
- query2 ? query2 : void 0
11176
- ],
11177
- detail: (id, query2) => [
11178
- PROMOTION_QUERY_KEY,
11179
- id,
11180
- query2 ? query2 : void 0
11181
- ]
11182
- };
11183
- const usePromotions = (query2, options) => {
11184
- const { data, ...rest } = useQuery({
11185
- queryKey: promotionsQueryKeys.list(query2),
11186
- queryFn: async () => sdk.admin.promotion.list(query2),
11187
- ...options
11188
- });
11189
- return { ...data, ...rest };
11190
- };
11191
- const Promotions = () => {
11098
+ const InlineTip = forwardRef(
11099
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11100
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11101
+ return /* @__PURE__ */ jsxs(
11102
+ "div",
11103
+ {
11104
+ ref,
11105
+ className: clx(
11106
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11107
+ className
11108
+ ),
11109
+ ...props,
11110
+ children: [
11111
+ /* @__PURE__ */ jsx(
11112
+ "div",
11113
+ {
11114
+ role: "presentation",
11115
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11116
+ "bg-ui-tag-orange-icon": variant === "warning"
11117
+ })
11118
+ }
11119
+ ),
11120
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
11121
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11122
+ labelValue,
11123
+ ":"
11124
+ ] }),
11125
+ " ",
11126
+ children
11127
+ ] })
11128
+ ]
11129
+ }
11130
+ );
11131
+ }
11132
+ );
11133
+ InlineTip.displayName = "InlineTip";
11134
+ const MetadataFieldSchema = objectType({
11135
+ key: stringType(),
11136
+ disabled: booleanType().optional(),
11137
+ value: anyType()
11138
+ });
11139
+ const MetadataSchema = objectType({
11140
+ metadata: arrayType(MetadataFieldSchema)
11141
+ });
11142
+ const Metadata = () => {
11192
11143
  const { id } = useParams();
11193
- const {
11194
- order: preview,
11195
- isError: isPreviewError,
11196
- error: previewError
11197
- } = useOrderPreview(id, void 0);
11198
- useInitiateOrderEdit({ preview });
11199
- const { onCancel } = useCancelOrderEdit({ preview });
11200
- if (isPreviewError) {
11201
- throw previewError;
11144
+ const { order, isPending, isError, error } = useOrder(id, {
11145
+ fields: "metadata"
11146
+ });
11147
+ if (isError) {
11148
+ throw error;
11202
11149
  }
11203
- const isReady = !!preview;
11204
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11205
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11206
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11150
+ const isReady = !isPending && !!order;
11151
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11152
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11153
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
11154
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11155
+ ] }),
11156
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11207
11157
  ] });
11208
11158
  };
11209
- const PromotionForm = ({ preview }) => {
11210
- const { items, shipping_methods } = preview;
11211
- const [isSubmitting, setIsSubmitting] = useState(false);
11212
- const [comboboxValue, setComboboxValue] = useState("");
11159
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11160
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11161
+ const MetadataForm = ({ orderId, metadata }) => {
11213
11162
  const { handleSuccess } = useRouteModal();
11214
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11215
- const promoIds = getPromotionIds(items, shipping_methods);
11216
- const { promotions, isPending, isError, error } = usePromotions(
11217
- {
11218
- id: promoIds
11219
- },
11220
- {
11221
- enabled: !!promoIds.length
11222
- }
11223
- );
11224
- const comboboxData = useComboboxData({
11225
- queryKey: ["promotions", "combobox", promoIds],
11226
- queryFn: async (params) => {
11227
- return await sdk.admin.promotion.list({
11228
- ...params,
11229
- id: {
11230
- $nin: promoIds
11231
- }
11232
- });
11163
+ const hasUneditableRows = getHasUneditableRows(metadata);
11164
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11165
+ const form = useForm({
11166
+ defaultValues: {
11167
+ metadata: getDefaultValues(metadata)
11233
11168
  },
11234
- getOptions: (data) => {
11235
- return data.promotions.map((promotion) => ({
11236
- label: promotion.code,
11237
- value: promotion.code
11238
- }));
11239
- }
11169
+ resolver: zodResolver(MetadataSchema)
11240
11170
  });
11241
- const add = async (value) => {
11242
- if (!value) {
11243
- return;
11244
- }
11245
- addPromotions(
11171
+ const handleSubmit = form.handleSubmit(async (data) => {
11172
+ const parsedData = parseValues(data);
11173
+ await mutateAsync(
11246
11174
  {
11247
- promo_codes: [value]
11175
+ metadata: parsedData
11248
11176
  },
11249
11177
  {
11250
- onError: (e) => {
11251
- toast.error(e.message);
11252
- comboboxData.onSearchValueChange("");
11253
- setComboboxValue("");
11254
- },
11255
11178
  onSuccess: () => {
11256
- comboboxData.onSearchValueChange("");
11257
- setComboboxValue("");
11179
+ toast.success("Metadata updated");
11180
+ handleSuccess();
11181
+ },
11182
+ onError: (error) => {
11183
+ toast.error(error.message);
11258
11184
  }
11259
11185
  }
11260
11186
  );
11261
- };
11262
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11263
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11264
- const onSubmit = async () => {
11265
- setIsSubmitting(true);
11266
- let requestSucceeded = false;
11267
- await requestOrderEdit(void 0, {
11268
- onError: (e) => {
11269
- toast.error(e.message);
11270
- },
11271
- onSuccess: () => {
11272
- requestSucceeded = true;
11273
- }
11274
- });
11275
- if (!requestSucceeded) {
11276
- setIsSubmitting(false);
11277
- return;
11187
+ });
11188
+ const { fields, insert, remove } = useFieldArray({
11189
+ control: form.control,
11190
+ name: "metadata"
11191
+ });
11192
+ function deleteRow(index) {
11193
+ remove(index);
11194
+ if (fields.length === 1) {
11195
+ insert(0, {
11196
+ key: "",
11197
+ value: "",
11198
+ disabled: false
11199
+ });
11278
11200
  }
11279
- await confirmOrderEdit(void 0, {
11280
- onError: (e) => {
11281
- toast.error(e.message);
11282
- },
11283
- onSuccess: () => {
11284
- handleSuccess();
11285
- },
11286
- onSettled: () => {
11287
- setIsSubmitting(false);
11288
- }
11201
+ }
11202
+ function insertRow(index, position) {
11203
+ insert(index + (position === "above" ? 0 : 1), {
11204
+ key: "",
11205
+ value: "",
11206
+ disabled: false
11289
11207
  });
11290
- };
11291
- if (isError) {
11292
- throw error;
11293
11208
  }
11294
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11295
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11296
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11297
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11298
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11299
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11300
- ] }),
11301
- /* @__PURE__ */ jsx(
11302
- Combobox,
11303
- {
11304
- id: "promotion-combobox",
11305
- "aria-describedby": "promotion-combobox-hint",
11306
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11307
- fetchNextPage: comboboxData.fetchNextPage,
11308
- options: comboboxData.options,
11309
- onSearchValueChange: comboboxData.onSearchValueChange,
11310
- searchValue: comboboxData.searchValue,
11311
- disabled: comboboxData.disabled || isAddingPromotions,
11312
- onChange: add,
11313
- value: comboboxValue
11314
- }
11315
- )
11316
- ] }),
11317
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11318
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11319
- PromotionItem,
11320
- {
11321
- promotion,
11322
- orderId: preview.id,
11323
- isLoading: isPending
11324
- },
11325
- promotion.id
11326
- )) })
11327
- ] }) }),
11328
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11329
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11330
- /* @__PURE__ */ jsx(
11331
- Button,
11332
- {
11333
- size: "small",
11334
- type: "submit",
11335
- isLoading: isSubmitting || isAddingPromotions,
11336
- children: "Save"
11337
- }
11338
- )
11339
- ] }) })
11340
- ] });
11341
- };
11342
- const PromotionItem = ({
11343
- promotion,
11344
- orderId,
11345
- isLoading
11346
- }) => {
11347
- var _a;
11348
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11349
- const onRemove = async () => {
11350
- removePromotions(
11351
- {
11352
- promo_codes: [promotion.code]
11353
- },
11354
- {
11355
- onError: (e) => {
11356
- toast.error(e.message);
11357
- }
11358
- }
11359
- );
11360
- };
11361
- const displayValue = getDisplayValue(promotion);
11362
- return /* @__PURE__ */ jsxs(
11363
- "div",
11209
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11210
+ KeyboundForm,
11364
11211
  {
11365
- className: clx(
11366
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11367
- {
11368
- "animate-pulse": isLoading
11369
- }
11370
- ),
11212
+ onSubmit: handleSubmit,
11213
+ className: "flex flex-1 flex-col overflow-hidden",
11371
11214
  children: [
11372
- /* @__PURE__ */ jsxs("div", { children: [
11373
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11374
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11375
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11376
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11377
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11215
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11216
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11217
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11218
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
11219
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11378
11220
  ] }),
11379
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11380
- ] })
11221
+ fields.map((field, index) => {
11222
+ const isDisabled = field.disabled || false;
11223
+ let placeholder = "-";
11224
+ if (typeof field.value === "object") {
11225
+ placeholder = "{ ... }";
11226
+ }
11227
+ if (Array.isArray(field.value)) {
11228
+ placeholder = "[ ... ]";
11229
+ }
11230
+ return /* @__PURE__ */ jsx(
11231
+ ConditionalTooltip,
11232
+ {
11233
+ showTooltip: isDisabled,
11234
+ content: "This row is disabled because it contains non-primitive data.",
11235
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
11236
+ /* @__PURE__ */ jsxs(
11237
+ "div",
11238
+ {
11239
+ className: clx("grid grid-cols-2 divide-x", {
11240
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11241
+ }),
11242
+ children: [
11243
+ /* @__PURE__ */ jsx(
11244
+ Form$2.Field,
11245
+ {
11246
+ control: form.control,
11247
+ name: `metadata.${index}.key`,
11248
+ render: ({ field: field2 }) => {
11249
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11250
+ GridInput,
11251
+ {
11252
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11253
+ ...field2,
11254
+ disabled: isDisabled,
11255
+ placeholder: "Key"
11256
+ }
11257
+ ) }) });
11258
+ }
11259
+ }
11260
+ ),
11261
+ /* @__PURE__ */ jsx(
11262
+ Form$2.Field,
11263
+ {
11264
+ control: form.control,
11265
+ name: `metadata.${index}.value`,
11266
+ render: ({ field: { value, ...field2 } }) => {
11267
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11268
+ GridInput,
11269
+ {
11270
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11271
+ ...field2,
11272
+ value: isDisabled ? placeholder : value,
11273
+ disabled: isDisabled,
11274
+ placeholder: "Value"
11275
+ }
11276
+ ) }) });
11277
+ }
11278
+ }
11279
+ )
11280
+ ]
11281
+ }
11282
+ ),
11283
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11284
+ /* @__PURE__ */ jsx(
11285
+ DropdownMenu.Trigger,
11286
+ {
11287
+ className: clx(
11288
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11289
+ {
11290
+ hidden: isDisabled
11291
+ }
11292
+ ),
11293
+ disabled: isDisabled,
11294
+ asChild: true,
11295
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11296
+ }
11297
+ ),
11298
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11299
+ /* @__PURE__ */ jsxs(
11300
+ DropdownMenu.Item,
11301
+ {
11302
+ className: "gap-x-2",
11303
+ onClick: () => insertRow(index, "above"),
11304
+ children: [
11305
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11306
+ "Insert row above"
11307
+ ]
11308
+ }
11309
+ ),
11310
+ /* @__PURE__ */ jsxs(
11311
+ DropdownMenu.Item,
11312
+ {
11313
+ className: "gap-x-2",
11314
+ onClick: () => insertRow(index, "below"),
11315
+ children: [
11316
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11317
+ "Insert row below"
11318
+ ]
11319
+ }
11320
+ ),
11321
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11322
+ /* @__PURE__ */ jsxs(
11323
+ DropdownMenu.Item,
11324
+ {
11325
+ className: "gap-x-2",
11326
+ onClick: () => deleteRow(index),
11327
+ children: [
11328
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11329
+ "Delete row"
11330
+ ]
11331
+ }
11332
+ )
11333
+ ] })
11334
+ ] })
11335
+ ] })
11336
+ },
11337
+ field.id
11338
+ );
11339
+ })
11340
+ ] }),
11341
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11381
11342
  ] }),
11382
- /* @__PURE__ */ jsx(
11383
- IconButton,
11384
- {
11385
- size: "small",
11386
- type: "button",
11387
- variant: "transparent",
11388
- onClick: onRemove,
11389
- isLoading: isPending || isLoading,
11390
- children: /* @__PURE__ */ jsx(XMark, {})
11391
- }
11392
- )
11343
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11344
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11345
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11346
+ ] }) })
11393
11347
  ]
11394
- },
11395
- promotion.id
11396
- );
11397
- };
11398
- function getDisplayValue(promotion) {
11399
- var _a, _b, _c, _d;
11400
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11401
- if (!value) {
11402
- return null;
11403
- }
11404
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11405
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11406
- if (!currency) {
11407
- return null;
11408
11348
  }
11409
- return getLocaleAmount(value, currency);
11410
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11411
- return formatPercentage(value);
11412
- }
11413
- return null;
11414
- }
11415
- const formatter = new Intl.NumberFormat([], {
11416
- style: "percent",
11417
- minimumFractionDigits: 2
11418
- });
11419
- const formatPercentage = (value, isPercentageValue = false) => {
11420
- let val = value || 0;
11421
- if (!isPercentageValue) {
11422
- val = val / 100;
11423
- }
11424
- return formatter.format(val);
11349
+ ) });
11425
11350
  };
11426
- function getPromotionIds(items, shippingMethods) {
11427
- const promotionIds = /* @__PURE__ */ new Set();
11428
- for (const item of items) {
11429
- if (item.adjustments) {
11430
- for (const adjustment of item.adjustments) {
11431
- if (adjustment.promotion_id) {
11432
- promotionIds.add(adjustment.promotion_id);
11433
- }
11351
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11352
+ return /* @__PURE__ */ jsx(
11353
+ "input",
11354
+ {
11355
+ ref,
11356
+ ...props,
11357
+ autoComplete: "off",
11358
+ className: clx(
11359
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11360
+ className
11361
+ )
11362
+ }
11363
+ );
11364
+ });
11365
+ GridInput.displayName = "MetadataForm.GridInput";
11366
+ const PlaceholderInner = () => {
11367
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11368
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11369
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11370
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11371
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11372
+ ] }) })
11373
+ ] });
11374
+ };
11375
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11376
+ function getDefaultValues(metadata) {
11377
+ if (!metadata || !Object.keys(metadata).length) {
11378
+ return [
11379
+ {
11380
+ key: "",
11381
+ value: "",
11382
+ disabled: false
11434
11383
  }
11384
+ ];
11385
+ }
11386
+ return Object.entries(metadata).map(([key, value]) => {
11387
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11388
+ return {
11389
+ key,
11390
+ value,
11391
+ disabled: true
11392
+ };
11435
11393
  }
11394
+ let stringValue = value;
11395
+ if (typeof value !== "string") {
11396
+ stringValue = JSON.stringify(value);
11397
+ }
11398
+ return {
11399
+ key,
11400
+ value: stringValue,
11401
+ original_key: key
11402
+ };
11403
+ });
11404
+ }
11405
+ function parseValues(values) {
11406
+ const metadata = values.metadata;
11407
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11408
+ if (isEmpty) {
11409
+ return null;
11436
11410
  }
11437
- for (const shippingMethod of shippingMethods) {
11438
- if (shippingMethod.adjustments) {
11439
- for (const adjustment of shippingMethod.adjustments) {
11440
- if (adjustment.promotion_id) {
11441
- promotionIds.add(adjustment.promotion_id);
11442
- }
11411
+ const update = {};
11412
+ metadata.forEach((field) => {
11413
+ let key = field.key;
11414
+ let value = field.value;
11415
+ const disabled = field.disabled;
11416
+ if (!key || !value) {
11417
+ return;
11418
+ }
11419
+ if (disabled) {
11420
+ update[key] = value;
11421
+ return;
11422
+ }
11423
+ key = key.trim();
11424
+ value = value.trim();
11425
+ if (value === "true") {
11426
+ update[key] = true;
11427
+ } else if (value === "false") {
11428
+ update[key] = false;
11429
+ } else {
11430
+ const parsedNumber = parseFloat(value);
11431
+ if (!isNaN(parsedNumber)) {
11432
+ update[key] = parsedNumber;
11433
+ } else {
11434
+ update[key] = value;
11443
11435
  }
11444
11436
  }
11437
+ });
11438
+ return update;
11439
+ }
11440
+ function getHasUneditableRows(metadata) {
11441
+ if (!metadata) {
11442
+ return false;
11445
11443
  }
11446
- return Array.from(promotionIds);
11444
+ return Object.values(metadata).some(
11445
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11446
+ );
11447
11447
  }
11448
11448
  const SalesChannel = () => {
11449
11449
  const { id } = useParams();
@@ -11551,1151 +11551,141 @@ const SalesChannelField = ({ control, order }) => {
11551
11551
  const schema$2 = objectType({
11552
11552
  sales_channel_id: stringType().min(1)
11553
11553
  });
11554
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11555
- const Shipping = () => {
11556
- var _a;
11554
+ const TransferOwnership = () => {
11557
11555
  const { id } = useParams();
11558
- const { order, isPending, isError, error } = useOrder(id, {
11559
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11556
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11557
+ fields: "id,customer_id,customer.*"
11560
11558
  });
11561
- const {
11562
- order: preview,
11563
- isPending: isPreviewPending,
11564
- isError: isPreviewError,
11565
- error: previewError
11566
- } = useOrderPreview(id);
11567
- useInitiateOrderEdit({ preview });
11568
- const { onCancel } = useCancelOrderEdit({ preview });
11569
11559
  if (isError) {
11570
11560
  throw error;
11571
11561
  }
11572
- if (isPreviewError) {
11573
- throw previewError;
11574
- }
11575
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11576
- const isReady = preview && !isPreviewPending && order && !isPending;
11577
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11578
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11579
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11580
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11581
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11582
- ] }) }) }),
11583
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11584
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11585
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11586
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11587
- ] }) });
11562
+ const isReady = !isPending && !!draft_order;
11563
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11564
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11565
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
11566
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11567
+ ] }),
11568
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
11569
+ ] });
11588
11570
  };
11589
- const ShippingForm = ({ preview, order }) => {
11590
- var _a;
11591
- const { setIsOpen } = useStackedModal();
11592
- const [isSubmitting, setIsSubmitting] = useState(false);
11593
- const [data, setData] = useState(null);
11594
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11595
- const { shipping_options } = useShippingOptions(
11596
- {
11597
- id: appliedShippingOptionIds,
11598
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11571
+ const TransferOwnershipForm = ({ order }) => {
11572
+ var _a, _b;
11573
+ const form = useForm({
11574
+ defaultValues: {
11575
+ customer_id: order.customer_id || ""
11599
11576
  },
11600
- {
11601
- enabled: appliedShippingOptionIds.length > 0
11602
- }
11603
- );
11604
- const uniqueShippingProfiles = useMemo(() => {
11605
- const profiles = /* @__PURE__ */ new Map();
11606
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11607
- profiles.set(profile.id, profile);
11608
- });
11609
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11610
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11611
- });
11612
- return Array.from(profiles.values());
11613
- }, [order.items, shipping_options]);
11577
+ resolver: zodResolver(schema$1)
11578
+ });
11579
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11614
11580
  const { handleSuccess } = useRouteModal();
11615
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11616
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11617
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11618
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11619
- const onSubmit = async () => {
11620
- setIsSubmitting(true);
11621
- let requestSucceeded = false;
11622
- await requestOrderEdit(void 0, {
11623
- onError: (e) => {
11624
- toast.error(`Failed to request order edit: ${e.message}`);
11625
- },
11626
- onSuccess: () => {
11627
- requestSucceeded = true;
11628
- }
11629
- });
11630
- if (!requestSucceeded) {
11631
- setIsSubmitting(false);
11632
- return;
11633
- }
11634
- await confirmOrderEdit(void 0, {
11635
- onError: (e) => {
11636
- toast.error(`Failed to confirm order edit: ${e.message}`);
11637
- },
11638
- onSuccess: () => {
11639
- handleSuccess();
11640
- },
11641
- onSettled: () => {
11642
- setIsSubmitting(false);
11643
- }
11644
- });
11645
- };
11646
- const onKeydown = useCallback(
11647
- (e) => {
11648
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11649
- if (data || isSubmitting) {
11650
- return;
11581
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11582
+ const currentCustomer = order.customer ? {
11583
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11584
+ value: order.customer.id
11585
+ } : null;
11586
+ const onSubmit = form.handleSubmit(async (data) => {
11587
+ await mutateAsync(
11588
+ { customer_id: data.customer_id },
11589
+ {
11590
+ onSuccess: () => {
11591
+ toast.success("Customer updated");
11592
+ handleSuccess();
11593
+ },
11594
+ onError: (error) => {
11595
+ toast.error(error.message);
11651
11596
  }
11652
- onSubmit();
11653
11597
  }
11654
- },
11655
- [data, isSubmitting, onSubmit]
11656
- );
11657
- useEffect(() => {
11658
- document.addEventListener("keydown", onKeydown);
11659
- return () => {
11660
- document.removeEventListener("keydown", onKeydown);
11661
- };
11662
- }, [onKeydown]);
11663
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11664
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11665
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11666
- /* @__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: [
11667
- /* @__PURE__ */ jsxs("div", { children: [
11668
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11669
- /* @__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." }) })
11670
- ] }),
11671
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11672
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11673
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11674
- /* @__PURE__ */ jsx(
11675
- Text,
11676
- {
11677
- size: "xsmall",
11678
- weight: "plus",
11679
- className: "text-ui-fg-muted",
11680
- children: "Shipping profile"
11681
- }
11682
- ),
11683
- /* @__PURE__ */ jsx(
11684
- Text,
11685
- {
11686
- size: "xsmall",
11687
- weight: "plus",
11688
- className: "text-ui-fg-muted",
11689
- children: "Action"
11690
- }
11691
- )
11598
+ );
11599
+ });
11600
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11601
+ KeyboundForm,
11602
+ {
11603
+ className: "flex flex-1 flex-col overflow-hidden",
11604
+ onSubmit,
11605
+ children: [
11606
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11607
+ /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
11608
+ currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
11609
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11610
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11611
+ /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
11612
+ ] }),
11613
+ /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
11614
+ /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
11615
+ /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11616
+ ] })
11692
11617
  ] }),
11693
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11694
- var _a2, _b, _c, _d, _e, _f, _g;
11695
- const items = getItemsWithShippingProfile(
11696
- profile.id,
11697
- order.items
11698
- );
11699
- const hasItems = items.length > 0;
11700
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11701
- (option) => option.shipping_profile_id === profile.id
11702
- );
11703
- const shippingMethod = preview.shipping_methods.find(
11704
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11705
- );
11706
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11707
- (action) => action.action === "SHIPPING_ADD"
11708
- );
11709
- return /* @__PURE__ */ jsxs(
11710
- Accordion.Item,
11711
- {
11712
- value: profile.id,
11713
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11714
- children: [
11715
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11716
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11717
- /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11718
- IconButton,
11719
- {
11720
- size: "2xsmall",
11721
- variant: "transparent",
11722
- className: "group/trigger",
11723
- disabled: !hasItems,
11724
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11725
- }
11726
- ) }),
11727
- !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11728
- /* @__PURE__ */ jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11729
- /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col", children: [
11730
- /* @__PURE__ */ jsx(
11731
- Text,
11732
- {
11733
- size: "small",
11734
- weight: "plus",
11735
- leading: "compact",
11736
- children: profile.name
11737
- }
11738
- ),
11739
- /* @__PURE__ */ jsxs(
11740
- Text,
11741
- {
11742
- size: "small",
11743
- leading: "compact",
11744
- className: "text-ui-fg-subtle",
11745
- children: [
11746
- items.length,
11747
- " ",
11748
- pluralize(items.length, "items", "item")
11749
- ]
11750
- }
11751
- )
11752
- ] })
11753
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11754
- /* @__PURE__ */ jsx(
11755
- Tooltip,
11756
- {
11757
- content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
11758
- var _a3, _b2, _c2;
11759
- return /* @__PURE__ */ jsx(
11760
- "li",
11761
- {
11762
- 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})`
11763
- },
11764
- item.id
11765
- );
11766
- }) }),
11767
- children: /* @__PURE__ */ jsxs(
11768
- Badge,
11769
- {
11770
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11771
- size: "xsmall",
11772
- children: [
11773
- /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
11774
- /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
11775
- items.reduce(
11776
- (acc, item) => acc + item.quantity,
11777
- 0
11778
- ),
11779
- "x",
11780
- " ",
11781
- pluralize(items.length, "items", "item")
11782
- ] })
11783
- ]
11784
- }
11785
- )
11786
- }
11787
- ),
11788
- /* @__PURE__ */ jsx(
11789
- Tooltip,
11790
- {
11791
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11792
- children: /* @__PURE__ */ jsxs(
11793
- Badge,
11794
- {
11795
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11796
- size: "xsmall",
11797
- children: [
11798
- /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
11799
- /* @__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 })
11800
- ]
11801
- }
11802
- )
11803
- }
11804
- ),
11805
- /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
11806
- Badge,
11807
- {
11808
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11809
- size: "xsmall",
11810
- children: [
11811
- /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
11812
- /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
11813
- ]
11814
- }
11815
- ) })
11816
- ] })
11817
- ] }),
11818
- shippingOption ? /* @__PURE__ */ jsx(
11819
- ActionMenu,
11820
- {
11821
- groups: [
11822
- {
11823
- actions: [
11824
- hasItems ? {
11825
- label: "Edit shipping option",
11826
- icon: /* @__PURE__ */ jsx(Channels, {}),
11827
- onClick: () => {
11828
- setIsOpen(
11829
- STACKED_FOCUS_MODAL_ID,
11830
- true
11831
- );
11832
- setData({
11833
- shippingProfileId: profile.id,
11834
- shippingOption,
11835
- shippingMethod
11836
- });
11837
- }
11838
- } : void 0,
11839
- {
11840
- label: "Remove shipping option",
11841
- icon: /* @__PURE__ */ jsx(Trash, {}),
11842
- onClick: () => {
11843
- if (shippingMethod) {
11844
- if (addShippingMethodAction) {
11845
- removeActionShippingMethod(
11846
- addShippingMethodAction.id
11847
- );
11848
- } else {
11849
- removeShippingMethod(
11850
- shippingMethod.id
11851
- );
11852
- }
11853
- }
11854
- }
11855
- }
11856
- ].filter(Boolean)
11857
- }
11858
- ]
11859
- }
11860
- ) : /* @__PURE__ */ jsx(
11861
- StackedModalTrigger,
11862
- {
11863
- shippingProfileId: profile.id,
11864
- shippingOption,
11865
- shippingMethod,
11866
- setData,
11867
- children: "Add shipping option"
11868
- }
11869
- )
11870
- ] }),
11871
- /* @__PURE__ */ jsxs(Accordion.Content, { children: [
11872
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11873
- items.map((item, idx) => {
11874
- var _a3, _b2, _c2, _d2, _e2;
11875
- return /* @__PURE__ */ jsxs("div", { children: [
11876
- /* @__PURE__ */ jsxs(
11877
- "div",
11878
- {
11879
- className: "flex items-center gap-x-3 px-3",
11880
- children: [
11881
- /* @__PURE__ */ jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsx(
11882
- Divider,
11883
- {
11884
- variant: "dashed",
11885
- orientation: "vertical"
11886
- }
11887
- ) }),
11888
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
11889
- /* @__PURE__ */ jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11890
- Text,
11891
- {
11892
- size: "small",
11893
- leading: "compact",
11894
- className: "text-ui-fg-subtle",
11895
- children: [
11896
- item.quantity,
11897
- "x"
11898
- ]
11899
- }
11900
- ) }),
11901
- /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
11902
- /* @__PURE__ */ jsxs("div", { children: [
11903
- /* @__PURE__ */ jsxs(
11904
- Text,
11905
- {
11906
- size: "small",
11907
- leading: "compact",
11908
- weight: "plus",
11909
- children: [
11910
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11911
- " (",
11912
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11913
- ")"
11914
- ]
11915
- }
11916
- ),
11917
- /* @__PURE__ */ jsx(
11918
- Text,
11919
- {
11920
- size: "small",
11921
- leading: "compact",
11922
- className: "text-ui-fg-subtle",
11923
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11924
- }
11925
- )
11926
- ] })
11927
- ] })
11928
- ]
11929
- },
11930
- item.id
11931
- ),
11932
- idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11933
- ] }, item.id);
11934
- })
11935
- ] })
11936
- ]
11937
- },
11938
- profile.id
11939
- );
11940
- }) })
11941
- ] }) })
11942
- ] }) }),
11943
- /* @__PURE__ */ jsx(
11944
- StackedFocusModal,
11945
- {
11946
- id: STACKED_FOCUS_MODAL_ID,
11947
- onOpenChangeCallback: (open) => {
11948
- if (!open) {
11949
- setData(null);
11950
- }
11951
- return open;
11952
- },
11953
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11954
- }
11955
- )
11956
- ] }),
11957
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11958
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11959
- /* @__PURE__ */ jsx(
11960
- Button,
11961
- {
11962
- size: "small",
11963
- type: "button",
11964
- isLoading: isSubmitting,
11965
- onClick: onSubmit,
11966
- children: "Save"
11967
- }
11968
- )
11969
- ] }) })
11970
- ] });
11971
- };
11972
- const StackedModalTrigger = ({
11973
- shippingProfileId,
11974
- shippingOption,
11975
- shippingMethod,
11976
- setData,
11977
- children
11978
- }) => {
11979
- const { setIsOpen, getIsOpen } = useStackedModal();
11980
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11981
- const onToggle = () => {
11982
- if (isOpen) {
11983
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11984
- setData(null);
11985
- } else {
11986
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11987
- setData({
11988
- shippingProfileId,
11989
- shippingOption,
11990
- shippingMethod
11991
- });
11992
- }
11993
- };
11994
- return /* @__PURE__ */ jsx(
11995
- Button,
11996
- {
11997
- size: "small",
11998
- variant: "secondary",
11999
- onClick: onToggle,
12000
- className: "text-ui-fg-primary shrink-0",
12001
- children
12002
- }
12003
- );
12004
- };
12005
- const ShippingProfileForm = ({
12006
- data,
12007
- order,
12008
- preview
12009
- }) => {
12010
- var _a, _b, _c, _d, _e, _f;
12011
- const { setIsOpen } = useStackedModal();
12012
- const form = useForm({
12013
- resolver: zodResolver(shippingMethodSchema),
12014
- defaultValues: {
12015
- 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,
12016
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12017
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12018
- }
12019
- });
12020
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12021
- const {
12022
- mutateAsync: updateShippingMethod,
12023
- isPending: isUpdatingShippingMethod
12024
- } = useDraftOrderUpdateShippingMethod(order.id);
12025
- const onSubmit = form.handleSubmit(async (values) => {
12026
- if (isEqual(values, form.formState.defaultValues)) {
12027
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12028
- return;
12029
- }
12030
- if (data.shippingMethod) {
12031
- await updateShippingMethod(
12032
- {
12033
- method_id: data.shippingMethod.id,
12034
- shipping_option_id: values.shipping_option_id,
12035
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12036
- },
12037
- {
12038
- onError: (e) => {
12039
- toast.error(e.message);
12040
- },
12041
- onSuccess: () => {
12042
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12043
- }
12044
- }
12045
- );
12046
- return;
12047
- }
12048
- await addShippingMethod(
12049
- {
12050
- shipping_option_id: values.shipping_option_id,
12051
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12052
- },
12053
- {
12054
- onError: (e) => {
12055
- toast.error(e.message);
12056
- },
12057
- onSuccess: () => {
12058
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12059
- }
12060
- }
12061
- );
12062
- });
12063
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12064
- KeyboundForm,
12065
- {
12066
- className: "flex h-full flex-col overflow-hidden",
12067
- onSubmit,
12068
- children: [
12069
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12070
- /* @__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 px-6 py-16", children: [
12071
- /* @__PURE__ */ jsxs("div", { children: [
12072
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12073
- /* @__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." }) })
12074
- ] }),
12075
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12076
- /* @__PURE__ */ jsx(
12077
- LocationField,
12078
- {
12079
- control: form.control,
12080
- setValue: form.setValue
12081
- }
12082
- ),
12083
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12084
- /* @__PURE__ */ jsx(
12085
- ShippingOptionField,
12086
- {
12087
- shippingProfileId: data.shippingProfileId,
12088
- preview,
12089
- control: form.control
12090
- }
12091
- ),
12092
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12093
11618
  /* @__PURE__ */ jsx(
12094
- CustomAmountField,
11619
+ CustomerField,
12095
11620
  {
12096
11621
  control: form.control,
12097
- currencyCode: order.currency_code
12098
- }
12099
- ),
12100
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12101
- /* @__PURE__ */ jsx(
12102
- ItemsPreview,
12103
- {
12104
- order,
12105
- shippingProfileId: data.shippingProfileId
12106
- }
12107
- )
12108
- ] }) }) }),
12109
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12110
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12111
- /* @__PURE__ */ jsx(
12112
- Button,
12113
- {
12114
- size: "small",
12115
- type: "submit",
12116
- isLoading: isPending || isUpdatingShippingMethod,
12117
- children: data.shippingMethod ? "Update" : "Add"
11622
+ currentCustomerId: order.customer_id
12118
11623
  }
12119
11624
  )
11625
+ ] }),
11626
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11627
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11628
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12120
11629
  ] }) })
12121
11630
  ]
12122
11631
  }
12123
- ) }) });
11632
+ ) });
12124
11633
  };
12125
- const shippingMethodSchema = objectType({
12126
- location_id: stringType(),
12127
- shipping_option_id: stringType(),
12128
- custom_amount: unionType([numberType(), stringType()]).optional()
12129
- });
12130
- const ItemsPreview = ({ order, shippingProfileId }) => {
12131
- const matches = order.items.filter(
12132
- (item) => {
12133
- var _a, _b, _c;
12134
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12135
- }
12136
- );
12137
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12138
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12139
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12140
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12141
- ] }) }),
12142
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12143
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12144
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12145
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12146
- ] }),
12147
- /* @__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(
12148
- "div",
12149
- {
12150
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12151
- children: [
12152
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12153
- /* @__PURE__ */ jsx(
12154
- Thumbnail,
12155
- {
12156
- thumbnail: item.thumbnail,
12157
- alt: item.product_title ?? void 0
12158
- }
12159
- ),
12160
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12161
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12162
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12163
- /* @__PURE__ */ jsxs(
12164
- Text,
12165
- {
12166
- size: "small",
12167
- leading: "compact",
12168
- className: "text-ui-fg-subtle",
12169
- children: [
12170
- "(",
12171
- item.variant_title,
12172
- ")"
12173
- ]
12174
- }
12175
- )
12176
- ] }),
12177
- /* @__PURE__ */ jsx(
12178
- Text,
12179
- {
12180
- size: "small",
12181
- leading: "compact",
12182
- className: "text-ui-fg-subtle",
12183
- children: item.variant_sku
12184
- }
12185
- )
12186
- ] })
12187
- ] }),
12188
- /* @__PURE__ */ jsxs(
12189
- Text,
12190
- {
12191
- size: "small",
12192
- leading: "compact",
12193
- className: "text-ui-fg-subtle",
12194
- children: [
12195
- item.quantity,
12196
- "x"
12197
- ]
12198
- }
12199
- )
12200
- ]
12201
- },
12202
- item.id
12203
- )) : /* @__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: [
12204
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12205
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12206
- 'No items found for "',
12207
- query,
12208
- '".'
12209
- ] })
12210
- ] }) })
12211
- ] })
12212
- ] });
12213
- };
12214
- const LocationField = ({ control, setValue }) => {
12215
- const locations = useComboboxData({
12216
- queryKey: ["locations"],
12217
- queryFn: async (params) => {
12218
- return await sdk.admin.stockLocation.list(params);
12219
- },
12220
- getOptions: (data) => {
12221
- return data.stock_locations.map((location) => ({
12222
- label: location.name,
12223
- value: location.id
12224
- }));
12225
- }
12226
- });
12227
- return /* @__PURE__ */ jsx(
12228
- Form$2.Field,
12229
- {
12230
- control,
12231
- name: "location_id",
12232
- render: ({ field: { onChange, ...field } }) => {
12233
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12234
- /* @__PURE__ */ jsxs("div", { children: [
12235
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12236
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12237
- ] }),
12238
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12239
- Combobox,
12240
- {
12241
- options: locations.options,
12242
- fetchNextPage: locations.fetchNextPage,
12243
- isFetchingNextPage: locations.isFetchingNextPage,
12244
- searchValue: locations.searchValue,
12245
- onSearchValueChange: locations.onSearchValueChange,
12246
- placeholder: "Select location",
12247
- onChange: (value) => {
12248
- setValue("shipping_option_id", "", {
12249
- shouldDirty: true,
12250
- shouldTouch: true
12251
- });
12252
- onChange(value);
12253
- },
12254
- ...field
12255
- }
12256
- ) })
12257
- ] }) });
12258
- }
12259
- }
12260
- );
12261
- };
12262
- const ShippingOptionField = ({
12263
- shippingProfileId,
12264
- preview,
12265
- control
12266
- }) => {
12267
- var _a;
12268
- const locationId = useWatch({ control, name: "location_id" });
12269
- const shippingOptions = useComboboxData({
12270
- queryKey: ["shipping_options", locationId, shippingProfileId],
12271
- queryFn: async (params) => {
12272
- return await sdk.admin.shippingOption.list({
12273
- ...params,
12274
- stock_location_id: locationId,
12275
- shipping_profile_id: shippingProfileId
12276
- });
12277
- },
12278
- getOptions: (data) => {
12279
- return data.shipping_options.map((option) => {
12280
- var _a2;
12281
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12282
- (r) => r.attribute === "is_return" && r.value === "true"
12283
- )) {
12284
- return void 0;
12285
- }
12286
- return {
12287
- label: option.name,
12288
- value: option.id
12289
- };
12290
- }).filter(Boolean);
12291
- },
12292
- enabled: !!locationId && !!shippingProfileId,
12293
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12294
- });
12295
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12296
- return /* @__PURE__ */ jsx(
12297
- Form$2.Field,
12298
- {
12299
- control,
12300
- name: "shipping_option_id",
12301
- render: ({ field }) => {
12302
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12303
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12304
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12305
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12306
- ] }),
12307
- /* @__PURE__ */ jsx(
12308
- ConditionalTooltip,
12309
- {
12310
- content: tooltipContent,
12311
- showTooltip: !locationId || !shippingProfileId,
12312
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12313
- Combobox,
12314
- {
12315
- options: shippingOptions.options,
12316
- fetchNextPage: shippingOptions.fetchNextPage,
12317
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12318
- searchValue: shippingOptions.searchValue,
12319
- onSearchValueChange: shippingOptions.onSearchValueChange,
12320
- placeholder: "Select shipping option",
12321
- ...field,
12322
- disabled: !locationId || !shippingProfileId
12323
- }
12324
- ) }) })
12325
- }
12326
- )
12327
- ] }) });
12328
- }
11634
+ const CustomerField = ({ control, currentCustomerId }) => {
11635
+ const customers = useComboboxData({
11636
+ queryFn: async (params) => {
11637
+ return await sdk.admin.customer.list({
11638
+ ...params,
11639
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11640
+ });
11641
+ },
11642
+ queryKey: ["customers"],
11643
+ getOptions: (data) => {
11644
+ return data.customers.map((customer) => {
11645
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11646
+ return {
11647
+ label: name ? `${name} (${customer.email})` : customer.email,
11648
+ value: customer.id
11649
+ };
11650
+ });
11651
+ }
11652
+ });
11653
+ return /* @__PURE__ */ jsx(
11654
+ Form$2.Field,
11655
+ {
11656
+ name: "customer_id",
11657
+ control,
11658
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
11659
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11660
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
11661
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11662
+ ] }),
11663
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11664
+ Combobox,
11665
+ {
11666
+ options: customers.options,
11667
+ fetchNextPage: customers.fetchNextPage,
11668
+ isFetchingNextPage: customers.isFetchingNextPage,
11669
+ searchValue: customers.searchValue,
11670
+ onSearchValueChange: customers.onSearchValueChange,
11671
+ placeholder: "Select customer",
11672
+ ...field
11673
+ }
11674
+ ) }),
11675
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11676
+ ] })
12329
11677
  }
12330
11678
  );
12331
11679
  };
12332
- const CustomAmountField = ({
12333
- control,
12334
- currencyCode
12335
- }) => {
12336
- return /* @__PURE__ */ jsx(
12337
- Form$2.Field,
11680
+ const Illustration = () => {
11681
+ return /* @__PURE__ */ jsxs(
11682
+ "svg",
12338
11683
  {
12339
- control,
12340
- name: "custom_amount",
12341
- render: ({ field: { onChange, ...field } }) => {
12342
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12343
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12345
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12346
- ] }),
12347
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12348
- CurrencyInput,
12349
- {
12350
- ...field,
12351
- onValueChange: (value) => onChange(value),
12352
- symbol: getNativeSymbol(currencyCode),
12353
- code: currencyCode
12354
- }
12355
- ) })
12356
- ] });
12357
- }
12358
- }
12359
- );
12360
- };
12361
- const ShippingAddress = () => {
12362
- const { id } = useParams();
12363
- const { order, isPending, isError, error } = useOrder(id, {
12364
- fields: "+shipping_address"
12365
- });
12366
- if (isError) {
12367
- throw error;
12368
- }
12369
- const isReady = !isPending && !!order;
12370
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12371
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12372
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12373
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12374
- ] }),
12375
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12376
- ] });
12377
- };
12378
- const ShippingAddressForm = ({ order }) => {
12379
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12380
- const form = useForm({
12381
- defaultValues: {
12382
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12383
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12384
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12385
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12386
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12387
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12388
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12389
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12390
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12391
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12392
- },
12393
- resolver: zodResolver(schema$1)
12394
- });
12395
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12396
- const { handleSuccess } = useRouteModal();
12397
- const onSubmit = form.handleSubmit(async (data) => {
12398
- await mutateAsync(
12399
- {
12400
- shipping_address: {
12401
- first_name: data.first_name,
12402
- last_name: data.last_name,
12403
- company: data.company,
12404
- address_1: data.address_1,
12405
- address_2: data.address_2,
12406
- city: data.city,
12407
- province: data.province,
12408
- country_code: data.country_code,
12409
- postal_code: data.postal_code,
12410
- phone: data.phone
12411
- }
12412
- },
12413
- {
12414
- onSuccess: () => {
12415
- handleSuccess();
12416
- },
12417
- onError: (error) => {
12418
- toast.error(error.message);
12419
- }
12420
- }
12421
- );
12422
- });
12423
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12424
- KeyboundForm,
12425
- {
12426
- className: "flex flex-1 flex-col overflow-hidden",
12427
- onSubmit,
12428
- children: [
12429
- /* @__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: [
12430
- /* @__PURE__ */ jsx(
12431
- Form$2.Field,
12432
- {
12433
- control: form.control,
12434
- name: "country_code",
12435
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12436
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12437
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12438
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12439
- ] })
12440
- }
12441
- ),
12442
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12443
- /* @__PURE__ */ jsx(
12444
- Form$2.Field,
12445
- {
12446
- control: form.control,
12447
- name: "first_name",
12448
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12449
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12450
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12451
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12452
- ] })
12453
- }
12454
- ),
12455
- /* @__PURE__ */ jsx(
12456
- Form$2.Field,
12457
- {
12458
- control: form.control,
12459
- name: "last_name",
12460
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12461
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12462
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12463
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12464
- ] })
12465
- }
12466
- )
12467
- ] }),
12468
- /* @__PURE__ */ jsx(
12469
- Form$2.Field,
12470
- {
12471
- control: form.control,
12472
- name: "company",
12473
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12474
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12475
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12476
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12477
- ] })
12478
- }
12479
- ),
12480
- /* @__PURE__ */ jsx(
12481
- Form$2.Field,
12482
- {
12483
- control: form.control,
12484
- name: "address_1",
12485
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12486
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12487
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12488
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12489
- ] })
12490
- }
12491
- ),
12492
- /* @__PURE__ */ jsx(
12493
- Form$2.Field,
12494
- {
12495
- control: form.control,
12496
- name: "address_2",
12497
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12498
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12499
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12500
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12501
- ] })
12502
- }
12503
- ),
12504
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12505
- /* @__PURE__ */ jsx(
12506
- Form$2.Field,
12507
- {
12508
- control: form.control,
12509
- name: "postal_code",
12510
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12511
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12512
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12513
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12514
- ] })
12515
- }
12516
- ),
12517
- /* @__PURE__ */ jsx(
12518
- Form$2.Field,
12519
- {
12520
- control: form.control,
12521
- name: "city",
12522
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12523
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12524
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12525
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12526
- ] })
12527
- }
12528
- )
12529
- ] }),
12530
- /* @__PURE__ */ jsx(
12531
- Form$2.Field,
12532
- {
12533
- control: form.control,
12534
- name: "province",
12535
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12536
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12537
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12538
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12539
- ] })
12540
- }
12541
- ),
12542
- /* @__PURE__ */ jsx(
12543
- Form$2.Field,
12544
- {
12545
- control: form.control,
12546
- name: "phone",
12547
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12548
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12549
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12550
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12551
- ] })
12552
- }
12553
- )
12554
- ] }) }),
12555
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12556
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12557
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12558
- ] }) })
12559
- ]
12560
- }
12561
- ) });
12562
- };
12563
- const schema$1 = addressSchema;
12564
- const TransferOwnership = () => {
12565
- const { id } = useParams();
12566
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12567
- fields: "id,customer_id,customer.*"
12568
- });
12569
- if (isError) {
12570
- throw error;
12571
- }
12572
- const isReady = !isPending && !!draft_order;
12573
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12574
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12575
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12576
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12577
- ] }),
12578
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12579
- ] });
12580
- };
12581
- const TransferOwnershipForm = ({ order }) => {
12582
- var _a, _b;
12583
- const form = useForm({
12584
- defaultValues: {
12585
- customer_id: order.customer_id || ""
12586
- },
12587
- resolver: zodResolver(schema)
12588
- });
12589
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
- const { handleSuccess } = useRouteModal();
12591
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12592
- const currentCustomer = order.customer ? {
12593
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12594
- value: order.customer.id
12595
- } : null;
12596
- const onSubmit = form.handleSubmit(async (data) => {
12597
- await mutateAsync(
12598
- { customer_id: data.customer_id },
12599
- {
12600
- onSuccess: () => {
12601
- toast.success("Customer updated");
12602
- handleSuccess();
12603
- },
12604
- onError: (error) => {
12605
- toast.error(error.message);
12606
- }
12607
- }
12608
- );
12609
- });
12610
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12611
- KeyboundForm,
12612
- {
12613
- className: "flex flex-1 flex-col overflow-hidden",
12614
- onSubmit,
12615
- children: [
12616
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12617
- /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsx(Illustration, {}) }),
12618
- currentCustomer && /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-3", children: [
12619
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12620
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12621
- /* @__PURE__ */ jsx(Hint$1, { children: "The customer that is currently associated with this draft order." })
12622
- ] }),
12623
- /* @__PURE__ */ jsxs(Select, { disabled: true, value: currentCustomer.value, children: [
12624
- /* @__PURE__ */ jsx(Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsx(Select.Value, {}) }),
12625
- /* @__PURE__ */ jsx(Select.Content, { children: /* @__PURE__ */ jsx(Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12626
- ] })
12627
- ] }),
12628
- /* @__PURE__ */ jsx(
12629
- CustomerField,
12630
- {
12631
- control: form.control,
12632
- currentCustomerId: order.customer_id
12633
- }
12634
- )
12635
- ] }),
12636
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12637
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12638
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12639
- ] }) })
12640
- ]
12641
- }
12642
- ) });
12643
- };
12644
- const CustomerField = ({ control, currentCustomerId }) => {
12645
- const customers = useComboboxData({
12646
- queryFn: async (params) => {
12647
- return await sdk.admin.customer.list({
12648
- ...params,
12649
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12650
- });
12651
- },
12652
- queryKey: ["customers"],
12653
- getOptions: (data) => {
12654
- return data.customers.map((customer) => {
12655
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12656
- return {
12657
- label: name ? `${name} (${customer.email})` : customer.email,
12658
- value: customer.id
12659
- };
12660
- });
12661
- }
12662
- });
12663
- return /* @__PURE__ */ jsx(
12664
- Form$2.Field,
12665
- {
12666
- name: "customer_id",
12667
- control,
12668
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { className: "space-y-3", children: [
12669
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12670
- /* @__PURE__ */ jsx(Form$2.Label, { children: "New customer" }),
12671
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12672
- ] }),
12673
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12674
- Combobox,
12675
- {
12676
- options: customers.options,
12677
- fetchNextPage: customers.fetchNextPage,
12678
- isFetchingNextPage: customers.isFetchingNextPage,
12679
- searchValue: customers.searchValue,
12680
- onSearchValueChange: customers.onSearchValueChange,
12681
- placeholder: "Select customer",
12682
- ...field
12683
- }
12684
- ) }),
12685
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12686
- ] })
12687
- }
12688
- );
12689
- };
12690
- const Illustration = () => {
12691
- return /* @__PURE__ */ jsxs(
12692
- "svg",
12693
- {
12694
- width: "280",
12695
- height: "180",
12696
- viewBox: "0 0 280 180",
12697
- fill: "none",
12698
- xmlns: "http://www.w3.org/2000/svg",
11684
+ width: "280",
11685
+ height: "180",
11686
+ viewBox: "0 0 280 180",
11687
+ fill: "none",
11688
+ xmlns: "http://www.w3.org/2000/svg",
12699
11689
  children: [
12700
11690
  /* @__PURE__ */ jsx(
12701
11691
  "rect",
@@ -12978,65 +11968,1075 @@ const Illustration = () => {
12978
11968
  /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12979
11969
  "rect",
12980
11970
  {
12981
- width: "12",
12982
- height: "12",
12983
- fill: "white",
12984
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11971
+ width: "12",
11972
+ height: "12",
11973
+ fill: "white",
11974
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11975
+ }
11976
+ ) }),
11977
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
11978
+ "rect",
11979
+ {
11980
+ width: "12",
11981
+ height: "12",
11982
+ fill: "white",
11983
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11984
+ }
11985
+ ) }),
11986
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
11987
+ "rect",
11988
+ {
11989
+ width: "12",
11990
+ height: "12",
11991
+ fill: "white",
11992
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11993
+ }
11994
+ ) }),
11995
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
11996
+ "rect",
11997
+ {
11998
+ width: "12",
11999
+ height: "12",
12000
+ fill: "white",
12001
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12002
+ }
12003
+ ) }),
12004
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12005
+ "rect",
12006
+ {
12007
+ width: "12",
12008
+ height: "12",
12009
+ fill: "white",
12010
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12011
+ }
12012
+ ) }),
12013
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12014
+ "rect",
12015
+ {
12016
+ width: "12",
12017
+ height: "12",
12018
+ fill: "white",
12019
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12020
+ }
12021
+ ) })
12022
+ ] })
12023
+ ]
12024
+ }
12025
+ );
12026
+ };
12027
+ const schema$1 = objectType({
12028
+ customer_id: stringType().min(1)
12029
+ });
12030
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
12031
+ const Shipping = () => {
12032
+ var _a;
12033
+ const { id } = useParams();
12034
+ const { order, isPending, isError, error } = useOrder(id, {
12035
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12036
+ });
12037
+ const {
12038
+ order: preview,
12039
+ isPending: isPreviewPending,
12040
+ isError: isPreviewError,
12041
+ error: previewError
12042
+ } = useOrderPreview(id);
12043
+ useInitiateOrderEdit({ preview });
12044
+ const { onCancel } = useCancelOrderEdit({ preview });
12045
+ if (isError) {
12046
+ throw error;
12047
+ }
12048
+ if (isPreviewError) {
12049
+ throw previewError;
12050
+ }
12051
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12052
+ const isReady = preview && !isPreviewPending && order && !isPending;
12053
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12054
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12055
+ /* @__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 px-6 py-16", children: [
12056
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12057
+ /* @__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." }) })
12058
+ ] }) }) }),
12059
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12060
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
12061
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12062
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12063
+ ] }) });
12064
+ };
12065
+ const ShippingForm = ({ preview, order }) => {
12066
+ var _a;
12067
+ const { setIsOpen } = useStackedModal();
12068
+ const [isSubmitting, setIsSubmitting] = useState(false);
12069
+ const [data, setData] = useState(null);
12070
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12071
+ const { shipping_options } = useShippingOptions(
12072
+ {
12073
+ id: appliedShippingOptionIds,
12074
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12075
+ },
12076
+ {
12077
+ enabled: appliedShippingOptionIds.length > 0
12078
+ }
12079
+ );
12080
+ const uniqueShippingProfiles = useMemo(() => {
12081
+ const profiles = /* @__PURE__ */ new Map();
12082
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12083
+ profiles.set(profile.id, profile);
12084
+ });
12085
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12086
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12087
+ });
12088
+ return Array.from(profiles.values());
12089
+ }, [order.items, shipping_options]);
12090
+ const { handleSuccess } = useRouteModal();
12091
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12092
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12093
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12094
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12095
+ const onSubmit = async () => {
12096
+ setIsSubmitting(true);
12097
+ let requestSucceeded = false;
12098
+ await requestOrderEdit(void 0, {
12099
+ onError: (e) => {
12100
+ toast.error(`Failed to request order edit: ${e.message}`);
12101
+ },
12102
+ onSuccess: () => {
12103
+ requestSucceeded = true;
12104
+ }
12105
+ });
12106
+ if (!requestSucceeded) {
12107
+ setIsSubmitting(false);
12108
+ return;
12109
+ }
12110
+ await confirmOrderEdit(void 0, {
12111
+ onError: (e) => {
12112
+ toast.error(`Failed to confirm order edit: ${e.message}`);
12113
+ },
12114
+ onSuccess: () => {
12115
+ handleSuccess();
12116
+ },
12117
+ onSettled: () => {
12118
+ setIsSubmitting(false);
12119
+ }
12120
+ });
12121
+ };
12122
+ const onKeydown = useCallback(
12123
+ (e) => {
12124
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12125
+ if (data || isSubmitting) {
12126
+ return;
12127
+ }
12128
+ onSubmit();
12129
+ }
12130
+ },
12131
+ [data, isSubmitting, onSubmit]
12132
+ );
12133
+ useEffect(() => {
12134
+ document.addEventListener("keydown", onKeydown);
12135
+ return () => {
12136
+ document.removeEventListener("keydown", onKeydown);
12137
+ };
12138
+ }, [onKeydown]);
12139
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12140
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12141
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12142
+ /* @__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: [
12143
+ /* @__PURE__ */ jsxs("div", { children: [
12144
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12145
+ /* @__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." }) })
12146
+ ] }),
12147
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12148
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12149
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
12150
+ /* @__PURE__ */ jsx(
12151
+ Text,
12152
+ {
12153
+ size: "xsmall",
12154
+ weight: "plus",
12155
+ className: "text-ui-fg-muted",
12156
+ children: "Shipping profile"
12157
+ }
12158
+ ),
12159
+ /* @__PURE__ */ jsx(
12160
+ Text,
12161
+ {
12162
+ size: "xsmall",
12163
+ weight: "plus",
12164
+ className: "text-ui-fg-muted",
12165
+ children: "Action"
12166
+ }
12167
+ )
12168
+ ] }),
12169
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12170
+ var _a2, _b, _c, _d, _e, _f, _g;
12171
+ const items = getItemsWithShippingProfile(
12172
+ profile.id,
12173
+ order.items
12174
+ );
12175
+ const hasItems = items.length > 0;
12176
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12177
+ (option) => option.shipping_profile_id === profile.id
12178
+ );
12179
+ const shippingMethod = preview.shipping_methods.find(
12180
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12181
+ );
12182
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12183
+ (action) => action.action === "SHIPPING_ADD"
12184
+ );
12185
+ return /* @__PURE__ */ jsxs(
12186
+ Accordion.Item,
12187
+ {
12188
+ value: profile.id,
12189
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12190
+ children: [
12191
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
12192
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
12193
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
12194
+ IconButton,
12195
+ {
12196
+ size: "2xsmall",
12197
+ variant: "transparent",
12198
+ className: "group/trigger",
12199
+ disabled: !hasItems,
12200
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
12201
+ }
12202
+ ) }),
12203
+ !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12204
+ /* @__PURE__ */ jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
12205
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col", children: [
12206
+ /* @__PURE__ */ jsx(
12207
+ Text,
12208
+ {
12209
+ size: "small",
12210
+ weight: "plus",
12211
+ leading: "compact",
12212
+ children: profile.name
12213
+ }
12214
+ ),
12215
+ /* @__PURE__ */ jsxs(
12216
+ Text,
12217
+ {
12218
+ size: "small",
12219
+ leading: "compact",
12220
+ className: "text-ui-fg-subtle",
12221
+ children: [
12222
+ items.length,
12223
+ " ",
12224
+ pluralize(items.length, "items", "item")
12225
+ ]
12226
+ }
12227
+ )
12228
+ ] })
12229
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
12230
+ /* @__PURE__ */ jsx(
12231
+ Tooltip,
12232
+ {
12233
+ content: /* @__PURE__ */ jsx("ul", { children: items.map((item) => {
12234
+ var _a3, _b2, _c2;
12235
+ return /* @__PURE__ */ jsx(
12236
+ "li",
12237
+ {
12238
+ 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})`
12239
+ },
12240
+ item.id
12241
+ );
12242
+ }) }),
12243
+ children: /* @__PURE__ */ jsxs(
12244
+ Badge,
12245
+ {
12246
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12247
+ size: "xsmall",
12248
+ children: [
12249
+ /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
12250
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
12251
+ items.reduce(
12252
+ (acc, item) => acc + item.quantity,
12253
+ 0
12254
+ ),
12255
+ "x",
12256
+ " ",
12257
+ pluralize(items.length, "items", "item")
12258
+ ] })
12259
+ ]
12260
+ }
12261
+ )
12262
+ }
12263
+ ),
12264
+ /* @__PURE__ */ jsx(
12265
+ Tooltip,
12266
+ {
12267
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12268
+ children: /* @__PURE__ */ jsxs(
12269
+ Badge,
12270
+ {
12271
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12272
+ size: "xsmall",
12273
+ children: [
12274
+ /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
12275
+ /* @__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 })
12276
+ ]
12277
+ }
12278
+ )
12279
+ }
12280
+ ),
12281
+ /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
12282
+ Badge,
12283
+ {
12284
+ className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
12285
+ size: "xsmall",
12286
+ children: [
12287
+ /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
12288
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: shippingOption.name })
12289
+ ]
12290
+ }
12291
+ ) })
12292
+ ] })
12293
+ ] }),
12294
+ shippingOption ? /* @__PURE__ */ jsx(
12295
+ ActionMenu,
12296
+ {
12297
+ groups: [
12298
+ {
12299
+ actions: [
12300
+ hasItems ? {
12301
+ label: "Edit shipping option",
12302
+ icon: /* @__PURE__ */ jsx(Channels, {}),
12303
+ onClick: () => {
12304
+ setIsOpen(
12305
+ STACKED_FOCUS_MODAL_ID,
12306
+ true
12307
+ );
12308
+ setData({
12309
+ shippingProfileId: profile.id,
12310
+ shippingOption,
12311
+ shippingMethod
12312
+ });
12313
+ }
12314
+ } : void 0,
12315
+ {
12316
+ label: "Remove shipping option",
12317
+ icon: /* @__PURE__ */ jsx(Trash, {}),
12318
+ onClick: () => {
12319
+ if (shippingMethod) {
12320
+ if (addShippingMethodAction) {
12321
+ removeActionShippingMethod(
12322
+ addShippingMethodAction.id
12323
+ );
12324
+ } else {
12325
+ removeShippingMethod(
12326
+ shippingMethod.id
12327
+ );
12328
+ }
12329
+ }
12330
+ }
12331
+ }
12332
+ ].filter(Boolean)
12333
+ }
12334
+ ]
12335
+ }
12336
+ ) : /* @__PURE__ */ jsx(
12337
+ StackedModalTrigger,
12338
+ {
12339
+ shippingProfileId: profile.id,
12340
+ shippingOption,
12341
+ shippingMethod,
12342
+ setData,
12343
+ children: "Add shipping option"
12344
+ }
12345
+ )
12346
+ ] }),
12347
+ /* @__PURE__ */ jsxs(Accordion.Content, { children: [
12348
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12349
+ items.map((item, idx) => {
12350
+ var _a3, _b2, _c2, _d2, _e2;
12351
+ return /* @__PURE__ */ jsxs("div", { children: [
12352
+ /* @__PURE__ */ jsxs(
12353
+ "div",
12354
+ {
12355
+ className: "flex items-center gap-x-3 px-3",
12356
+ children: [
12357
+ /* @__PURE__ */ jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsx(
12358
+ Divider,
12359
+ {
12360
+ variant: "dashed",
12361
+ orientation: "vertical"
12362
+ }
12363
+ ) }),
12364
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12365
+ /* @__PURE__ */ jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
12366
+ Text,
12367
+ {
12368
+ size: "small",
12369
+ leading: "compact",
12370
+ className: "text-ui-fg-subtle",
12371
+ children: [
12372
+ item.quantity,
12373
+ "x"
12374
+ ]
12375
+ }
12376
+ ) }),
12377
+ /* @__PURE__ */ jsx(Thumbnail, { thumbnail: item.thumbnail }),
12378
+ /* @__PURE__ */ jsxs("div", { children: [
12379
+ /* @__PURE__ */ jsxs(
12380
+ Text,
12381
+ {
12382
+ size: "small",
12383
+ leading: "compact",
12384
+ weight: "plus",
12385
+ children: [
12386
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12387
+ " (",
12388
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12389
+ ")"
12390
+ ]
12391
+ }
12392
+ ),
12393
+ /* @__PURE__ */ jsx(
12394
+ Text,
12395
+ {
12396
+ size: "small",
12397
+ leading: "compact",
12398
+ className: "text-ui-fg-subtle",
12399
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12400
+ }
12401
+ )
12402
+ ] })
12403
+ ] })
12404
+ ]
12405
+ },
12406
+ item.id
12407
+ ),
12408
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
12409
+ ] }, item.id);
12410
+ })
12411
+ ] })
12412
+ ]
12413
+ },
12414
+ profile.id
12415
+ );
12416
+ }) })
12417
+ ] }) })
12418
+ ] }) }),
12419
+ /* @__PURE__ */ jsx(
12420
+ StackedFocusModal,
12421
+ {
12422
+ id: STACKED_FOCUS_MODAL_ID,
12423
+ onOpenChangeCallback: (open) => {
12424
+ if (!open) {
12425
+ setData(null);
12426
+ }
12427
+ return open;
12428
+ },
12429
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
12430
+ }
12431
+ )
12432
+ ] }),
12433
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12434
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12435
+ /* @__PURE__ */ jsx(
12436
+ Button,
12437
+ {
12438
+ size: "small",
12439
+ type: "button",
12440
+ isLoading: isSubmitting,
12441
+ onClick: onSubmit,
12442
+ children: "Save"
12443
+ }
12444
+ )
12445
+ ] }) })
12446
+ ] });
12447
+ };
12448
+ const StackedModalTrigger = ({
12449
+ shippingProfileId,
12450
+ shippingOption,
12451
+ shippingMethod,
12452
+ setData,
12453
+ children
12454
+ }) => {
12455
+ const { setIsOpen, getIsOpen } = useStackedModal();
12456
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12457
+ const onToggle = () => {
12458
+ if (isOpen) {
12459
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12460
+ setData(null);
12461
+ } else {
12462
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12463
+ setData({
12464
+ shippingProfileId,
12465
+ shippingOption,
12466
+ shippingMethod
12467
+ });
12468
+ }
12469
+ };
12470
+ return /* @__PURE__ */ jsx(
12471
+ Button,
12472
+ {
12473
+ size: "small",
12474
+ variant: "secondary",
12475
+ onClick: onToggle,
12476
+ className: "text-ui-fg-primary shrink-0",
12477
+ children
12478
+ }
12479
+ );
12480
+ };
12481
+ const ShippingProfileForm = ({
12482
+ data,
12483
+ order,
12484
+ preview
12485
+ }) => {
12486
+ var _a, _b, _c, _d, _e, _f;
12487
+ const { setIsOpen } = useStackedModal();
12488
+ const form = useForm({
12489
+ resolver: zodResolver(shippingMethodSchema),
12490
+ defaultValues: {
12491
+ 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,
12492
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12493
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12494
+ }
12495
+ });
12496
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12497
+ const {
12498
+ mutateAsync: updateShippingMethod,
12499
+ isPending: isUpdatingShippingMethod
12500
+ } = useDraftOrderUpdateShippingMethod(order.id);
12501
+ const onSubmit = form.handleSubmit(async (values) => {
12502
+ if (isEqual(values, form.formState.defaultValues)) {
12503
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12504
+ return;
12505
+ }
12506
+ if (data.shippingMethod) {
12507
+ await updateShippingMethod(
12508
+ {
12509
+ method_id: data.shippingMethod.id,
12510
+ shipping_option_id: values.shipping_option_id,
12511
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12512
+ },
12513
+ {
12514
+ onError: (e) => {
12515
+ toast.error(e.message);
12516
+ },
12517
+ onSuccess: () => {
12518
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12519
+ }
12520
+ }
12521
+ );
12522
+ return;
12523
+ }
12524
+ await addShippingMethod(
12525
+ {
12526
+ shipping_option_id: values.shipping_option_id,
12527
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12528
+ },
12529
+ {
12530
+ onError: (e) => {
12531
+ toast.error(e.message);
12532
+ },
12533
+ onSuccess: () => {
12534
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12535
+ }
12536
+ }
12537
+ );
12538
+ });
12539
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12540
+ KeyboundForm,
12541
+ {
12542
+ className: "flex h-full flex-col overflow-hidden",
12543
+ onSubmit,
12544
+ children: [
12545
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12546
+ /* @__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 px-6 py-16", children: [
12547
+ /* @__PURE__ */ jsxs("div", { children: [
12548
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12549
+ /* @__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." }) })
12550
+ ] }),
12551
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12552
+ /* @__PURE__ */ jsx(
12553
+ LocationField,
12554
+ {
12555
+ control: form.control,
12556
+ setValue: form.setValue
12557
+ }
12558
+ ),
12559
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12560
+ /* @__PURE__ */ jsx(
12561
+ ShippingOptionField,
12562
+ {
12563
+ shippingProfileId: data.shippingProfileId,
12564
+ preview,
12565
+ control: form.control
12566
+ }
12567
+ ),
12568
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12569
+ /* @__PURE__ */ jsx(
12570
+ CustomAmountField,
12571
+ {
12572
+ control: form.control,
12573
+ currencyCode: order.currency_code
12574
+ }
12575
+ ),
12576
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12577
+ /* @__PURE__ */ jsx(
12578
+ ItemsPreview,
12579
+ {
12580
+ order,
12581
+ shippingProfileId: data.shippingProfileId
12582
+ }
12583
+ )
12584
+ ] }) }) }),
12585
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12586
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12587
+ /* @__PURE__ */ jsx(
12588
+ Button,
12589
+ {
12590
+ size: "small",
12591
+ type: "submit",
12592
+ isLoading: isPending || isUpdatingShippingMethod,
12593
+ children: data.shippingMethod ? "Update" : "Add"
12594
+ }
12595
+ )
12596
+ ] }) })
12597
+ ]
12598
+ }
12599
+ ) }) });
12600
+ };
12601
+ const shippingMethodSchema = objectType({
12602
+ location_id: stringType(),
12603
+ shipping_option_id: stringType(),
12604
+ custom_amount: unionType([numberType(), stringType()]).optional()
12605
+ });
12606
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12607
+ const matches = order.items.filter(
12608
+ (item) => {
12609
+ var _a, _b, _c;
12610
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12611
+ }
12612
+ );
12613
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12614
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12615
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12616
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12617
+ ] }) }),
12618
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12619
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
12620
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12621
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12622
+ ] }),
12623
+ /* @__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(
12624
+ "div",
12625
+ {
12626
+ className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
12627
+ children: [
12628
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12629
+ /* @__PURE__ */ jsx(
12630
+ Thumbnail,
12631
+ {
12632
+ thumbnail: item.thumbnail,
12633
+ alt: item.product_title ?? void 0
12634
+ }
12635
+ ),
12636
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12637
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12638
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12639
+ /* @__PURE__ */ jsxs(
12640
+ Text,
12641
+ {
12642
+ size: "small",
12643
+ leading: "compact",
12644
+ className: "text-ui-fg-subtle",
12645
+ children: [
12646
+ "(",
12647
+ item.variant_title,
12648
+ ")"
12649
+ ]
12650
+ }
12651
+ )
12652
+ ] }),
12653
+ /* @__PURE__ */ jsx(
12654
+ Text,
12655
+ {
12656
+ size: "small",
12657
+ leading: "compact",
12658
+ className: "text-ui-fg-subtle",
12659
+ children: item.variant_sku
12660
+ }
12661
+ )
12662
+ ] })
12663
+ ] }),
12664
+ /* @__PURE__ */ jsxs(
12665
+ Text,
12666
+ {
12667
+ size: "small",
12668
+ leading: "compact",
12669
+ className: "text-ui-fg-subtle",
12670
+ children: [
12671
+ item.quantity,
12672
+ "x"
12673
+ ]
12674
+ }
12675
+ )
12676
+ ]
12677
+ },
12678
+ item.id
12679
+ )) : /* @__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: [
12680
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12681
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12682
+ 'No items found for "',
12683
+ query,
12684
+ '".'
12685
+ ] })
12686
+ ] }) })
12687
+ ] })
12688
+ ] });
12689
+ };
12690
+ const LocationField = ({ control, setValue }) => {
12691
+ const locations = useComboboxData({
12692
+ queryKey: ["locations"],
12693
+ queryFn: async (params) => {
12694
+ return await sdk.admin.stockLocation.list(params);
12695
+ },
12696
+ getOptions: (data) => {
12697
+ return data.stock_locations.map((location) => ({
12698
+ label: location.name,
12699
+ value: location.id
12700
+ }));
12701
+ }
12702
+ });
12703
+ return /* @__PURE__ */ jsx(
12704
+ Form$2.Field,
12705
+ {
12706
+ control,
12707
+ name: "location_id",
12708
+ render: ({ field: { onChange, ...field } }) => {
12709
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12710
+ /* @__PURE__ */ jsxs("div", { children: [
12711
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12712
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12713
+ ] }),
12714
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12715
+ Combobox,
12716
+ {
12717
+ options: locations.options,
12718
+ fetchNextPage: locations.fetchNextPage,
12719
+ isFetchingNextPage: locations.isFetchingNextPage,
12720
+ searchValue: locations.searchValue,
12721
+ onSearchValueChange: locations.onSearchValueChange,
12722
+ placeholder: "Select location",
12723
+ onChange: (value) => {
12724
+ setValue("shipping_option_id", "", {
12725
+ shouldDirty: true,
12726
+ shouldTouch: true
12727
+ });
12728
+ onChange(value);
12729
+ },
12730
+ ...field
12731
+ }
12732
+ ) })
12733
+ ] }) });
12734
+ }
12735
+ }
12736
+ );
12737
+ };
12738
+ const ShippingOptionField = ({
12739
+ shippingProfileId,
12740
+ preview,
12741
+ control
12742
+ }) => {
12743
+ var _a;
12744
+ const locationId = useWatch({ control, name: "location_id" });
12745
+ const shippingOptions = useComboboxData({
12746
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12747
+ queryFn: async (params) => {
12748
+ return await sdk.admin.shippingOption.list({
12749
+ ...params,
12750
+ stock_location_id: locationId,
12751
+ shipping_profile_id: shippingProfileId
12752
+ });
12753
+ },
12754
+ getOptions: (data) => {
12755
+ return data.shipping_options.map((option) => {
12756
+ var _a2;
12757
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12758
+ (r) => r.attribute === "is_return" && r.value === "true"
12759
+ )) {
12760
+ return void 0;
12761
+ }
12762
+ return {
12763
+ label: option.name,
12764
+ value: option.id
12765
+ };
12766
+ }).filter(Boolean);
12767
+ },
12768
+ enabled: !!locationId && !!shippingProfileId,
12769
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12770
+ });
12771
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12772
+ return /* @__PURE__ */ jsx(
12773
+ Form$2.Field,
12774
+ {
12775
+ control,
12776
+ name: "shipping_option_id",
12777
+ render: ({ field }) => {
12778
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12779
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12780
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12781
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12782
+ ] }),
12783
+ /* @__PURE__ */ jsx(
12784
+ ConditionalTooltip,
12785
+ {
12786
+ content: tooltipContent,
12787
+ showTooltip: !locationId || !shippingProfileId,
12788
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12789
+ Combobox,
12790
+ {
12791
+ options: shippingOptions.options,
12792
+ fetchNextPage: shippingOptions.fetchNextPage,
12793
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12794
+ searchValue: shippingOptions.searchValue,
12795
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12796
+ placeholder: "Select shipping option",
12797
+ ...field,
12798
+ disabled: !locationId || !shippingProfileId
12799
+ }
12800
+ ) }) })
12801
+ }
12802
+ )
12803
+ ] }) });
12804
+ }
12805
+ }
12806
+ );
12807
+ };
12808
+ const CustomAmountField = ({
12809
+ control,
12810
+ currencyCode
12811
+ }) => {
12812
+ return /* @__PURE__ */ jsx(
12813
+ Form$2.Field,
12814
+ {
12815
+ control,
12816
+ name: "custom_amount",
12817
+ render: ({ field: { onChange, ...field } }) => {
12818
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12819
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12820
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12821
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12822
+ ] }),
12823
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12824
+ CurrencyInput,
12825
+ {
12826
+ ...field,
12827
+ onValueChange: (value) => onChange(value),
12828
+ symbol: getNativeSymbol(currencyCode),
12829
+ code: currencyCode
12830
+ }
12831
+ ) })
12832
+ ] });
12833
+ }
12834
+ }
12835
+ );
12836
+ };
12837
+ const ShippingAddress = () => {
12838
+ const { id } = useParams();
12839
+ const { order, isPending, isError, error } = useOrder(id, {
12840
+ fields: "+shipping_address"
12841
+ });
12842
+ if (isError) {
12843
+ throw error;
12844
+ }
12845
+ const isReady = !isPending && !!order;
12846
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12847
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12848
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12849
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12850
+ ] }),
12851
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12852
+ ] });
12853
+ };
12854
+ const ShippingAddressForm = ({ order }) => {
12855
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12856
+ const form = useForm({
12857
+ defaultValues: {
12858
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12859
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12860
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12861
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12862
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12863
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12864
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12865
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12866
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12867
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12868
+ },
12869
+ resolver: zodResolver(schema)
12870
+ });
12871
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12872
+ const { handleSuccess } = useRouteModal();
12873
+ const onSubmit = form.handleSubmit(async (data) => {
12874
+ await mutateAsync(
12875
+ {
12876
+ shipping_address: {
12877
+ first_name: data.first_name,
12878
+ last_name: data.last_name,
12879
+ company: data.company,
12880
+ address_1: data.address_1,
12881
+ address_2: data.address_2,
12882
+ city: data.city,
12883
+ province: data.province,
12884
+ country_code: data.country_code,
12885
+ postal_code: data.postal_code,
12886
+ phone: data.phone
12887
+ }
12888
+ },
12889
+ {
12890
+ onSuccess: () => {
12891
+ handleSuccess();
12892
+ },
12893
+ onError: (error) => {
12894
+ toast.error(error.message);
12895
+ }
12896
+ }
12897
+ );
12898
+ });
12899
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12900
+ KeyboundForm,
12901
+ {
12902
+ className: "flex flex-1 flex-col overflow-hidden",
12903
+ onSubmit,
12904
+ children: [
12905
+ /* @__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: [
12906
+ /* @__PURE__ */ jsx(
12907
+ Form$2.Field,
12908
+ {
12909
+ control: form.control,
12910
+ name: "country_code",
12911
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12912
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12913
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12914
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12915
+ ] })
12985
12916
  }
12986
- ) }),
12987
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12988
- "rect",
12917
+ ),
12918
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12919
+ /* @__PURE__ */ jsx(
12920
+ Form$2.Field,
12921
+ {
12922
+ control: form.control,
12923
+ name: "first_name",
12924
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12925
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12926
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12927
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12928
+ ] })
12929
+ }
12930
+ ),
12931
+ /* @__PURE__ */ jsx(
12932
+ Form$2.Field,
12933
+ {
12934
+ control: form.control,
12935
+ name: "last_name",
12936
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12937
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12938
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12939
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12940
+ ] })
12941
+ }
12942
+ )
12943
+ ] }),
12944
+ /* @__PURE__ */ jsx(
12945
+ Form$2.Field,
12989
12946
  {
12990
- width: "12",
12991
- height: "12",
12992
- fill: "white",
12993
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12947
+ control: form.control,
12948
+ name: "company",
12949
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12950
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12951
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12952
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
+ ] })
12994
12954
  }
12995
- ) }),
12996
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12997
- "rect",
12955
+ ),
12956
+ /* @__PURE__ */ jsx(
12957
+ Form$2.Field,
12998
12958
  {
12999
- width: "12",
13000
- height: "12",
13001
- fill: "white",
13002
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12959
+ control: form.control,
12960
+ name: "address_1",
12961
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12962
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12963
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12964
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12965
+ ] })
13003
12966
  }
13004
- ) }),
13005
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13006
- "rect",
12967
+ ),
12968
+ /* @__PURE__ */ jsx(
12969
+ Form$2.Field,
13007
12970
  {
13008
- width: "12",
13009
- height: "12",
13010
- fill: "white",
13011
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12971
+ control: form.control,
12972
+ name: "address_2",
12973
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12974
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12975
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12976
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12977
+ ] })
13012
12978
  }
13013
- ) }),
13014
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13015
- "rect",
12979
+ ),
12980
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12981
+ /* @__PURE__ */ jsx(
12982
+ Form$2.Field,
12983
+ {
12984
+ control: form.control,
12985
+ name: "postal_code",
12986
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12987
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12988
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12989
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12990
+ ] })
12991
+ }
12992
+ ),
12993
+ /* @__PURE__ */ jsx(
12994
+ Form$2.Field,
12995
+ {
12996
+ control: form.control,
12997
+ name: "city",
12998
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12999
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13000
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13001
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13002
+ ] })
13003
+ }
13004
+ )
13005
+ ] }),
13006
+ /* @__PURE__ */ jsx(
13007
+ Form$2.Field,
13016
13008
  {
13017
- width: "12",
13018
- height: "12",
13019
- fill: "white",
13020
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13009
+ control: form.control,
13010
+ name: "province",
13011
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13013
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
+ ] })
13021
13016
  }
13022
- ) }),
13023
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13024
- "rect",
13017
+ ),
13018
+ /* @__PURE__ */ jsx(
13019
+ Form$2.Field,
13025
13020
  {
13026
- width: "12",
13027
- height: "12",
13028
- fill: "white",
13029
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13021
+ control: form.control,
13022
+ name: "phone",
13023
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13024
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13025
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13026
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13027
+ ] })
13030
13028
  }
13031
- ) })
13032
- ] })
13029
+ )
13030
+ ] }) }),
13031
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13033
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13034
+ ] }) })
13033
13035
  ]
13034
13036
  }
13035
- );
13037
+ ) });
13036
13038
  };
13037
- const schema = objectType({
13038
- customer_id: stringType().min(1)
13039
- });
13039
+ const schema = addressSchema;
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13073,18 +13073,22 @@ const routeModule = {
13073
13073
  Component: Items,
13074
13074
  path: "/draft-orders/:id/items"
13075
13075
  },
13076
- {
13077
- Component: Metadata,
13078
- path: "/draft-orders/:id/metadata"
13079
- },
13080
13076
  {
13081
13077
  Component: Promotions,
13082
13078
  path: "/draft-orders/:id/promotions"
13083
13079
  },
13080
+ {
13081
+ Component: Metadata,
13082
+ path: "/draft-orders/:id/metadata"
13083
+ },
13084
13084
  {
13085
13085
  Component: SalesChannel,
13086
13086
  path: "/draft-orders/:id/sales-channel"
13087
13087
  },
13088
+ {
13089
+ Component: TransferOwnership,
13090
+ path: "/draft-orders/:id/transfer-ownership"
13091
+ },
13088
13092
  {
13089
13093
  Component: Shipping,
13090
13094
  path: "/draft-orders/:id/shipping"
@@ -13092,10 +13096,6 @@ const routeModule = {
13092
13096
  {
13093
13097
  Component: ShippingAddress,
13094
13098
  path: "/draft-orders/:id/shipping-address"
13095
- },
13096
- {
13097
- Component: TransferOwnership,
13098
- path: "/draft-orders/:id/transfer-ownership"
13099
13099
  }
13100
13100
  ]
13101
13101
  }
@@ -13107,7 +13107,9 @@ const menuItemModule = {
13107
13107
  label: config.label,
13108
13108
  icon: void 0,
13109
13109
  path: "/draft-orders",
13110
- nested: "/orders"
13110
+ nested: "/orders",
13111
+ rank: void 0,
13112
+ translationNs: void 0
13111
13113
  }
13112
13114
  ]
13113
13115
  };