@medusajs/draft-order 2.10.4-preview-20251006000321 → 2.10.4-preview-20251006060203

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