@medusajs/draft-order 2.10.0-snapshot-20250828112445 → 2.10.0-snapshot-20250828114928

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9765,54 +9765,10 @@ const CustomItemsForm = () => {
9765
9765
  const schema$4 = objectType({
9766
9766
  email: stringType().email()
9767
9767
  });
9768
- const InlineTip = forwardRef(
9769
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9770
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9771
- return /* @__PURE__ */ jsxs(
9772
- "div",
9773
- {
9774
- ref,
9775
- className: clx(
9776
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9777
- className
9778
- ),
9779
- ...props,
9780
- children: [
9781
- /* @__PURE__ */ jsx(
9782
- "div",
9783
- {
9784
- role: "presentation",
9785
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9786
- "bg-ui-tag-orange-icon": variant === "warning"
9787
- })
9788
- }
9789
- ),
9790
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9791
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9792
- labelValue,
9793
- ":"
9794
- ] }),
9795
- " ",
9796
- children
9797
- ] })
9798
- ]
9799
- }
9800
- );
9801
- }
9802
- );
9803
- InlineTip.displayName = "InlineTip";
9804
- const MetadataFieldSchema = objectType({
9805
- key: stringType(),
9806
- disabled: booleanType().optional(),
9807
- value: anyType()
9808
- });
9809
- const MetadataSchema = objectType({
9810
- metadata: arrayType(MetadataFieldSchema)
9811
- });
9812
- const Metadata = () => {
9768
+ const Email = () => {
9813
9769
  const { id } = useParams();
9814
9770
  const { order, isPending, isError, error } = useOrder(id, {
9815
- fields: "metadata"
9771
+ fields: "+email"
9816
9772
  });
9817
9773
  if (isError) {
9818
9774
  throw error;
@@ -9820,33 +9776,26 @@ const Metadata = () => {
9820
9776
  const isReady = !isPending && !!order;
9821
9777
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9822
9778
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9823
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9824
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9779
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9780
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9825
9781
  ] }),
9826
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9782
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9827
9783
  ] });
9828
9784
  };
9829
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9830
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9831
- const MetadataForm = ({ orderId, metadata }) => {
9832
- const { handleSuccess } = useRouteModal();
9833
- const hasUneditableRows = getHasUneditableRows(metadata);
9834
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9785
+ const EmailForm = ({ order }) => {
9835
9786
  const form = useForm({
9836
9787
  defaultValues: {
9837
- metadata: getDefaultValues(metadata)
9788
+ email: order.email ?? ""
9838
9789
  },
9839
- resolver: zodResolver(MetadataSchema)
9790
+ resolver: zodResolver(schema$3)
9840
9791
  });
9841
- const handleSubmit = form.handleSubmit(async (data) => {
9842
- const parsedData = parseValues(data);
9792
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
+ const { handleSuccess } = useRouteModal();
9794
+ const onSubmit = form.handleSubmit(async (data) => {
9843
9795
  await mutateAsync(
9844
- {
9845
- metadata: parsedData
9846
- },
9796
+ { email: data.email },
9847
9797
  {
9848
9798
  onSuccess: () => {
9849
- toast.success("Metadata updated");
9850
9799
  handleSuccess();
9851
9800
  },
9852
9801
  onError: (error) => {
@@ -9855,266 +9804,35 @@ const MetadataForm = ({ orderId, metadata }) => {
9855
9804
  }
9856
9805
  );
9857
9806
  });
9858
- const { fields, insert, remove } = useFieldArray({
9859
- control: form.control,
9860
- name: "metadata"
9861
- });
9862
- function deleteRow(index) {
9863
- remove(index);
9864
- if (fields.length === 1) {
9865
- insert(0, {
9866
- key: "",
9867
- value: "",
9868
- disabled: false
9869
- });
9870
- }
9871
- }
9872
- function insertRow(index, position) {
9873
- insert(index + (position === "above" ? 0 : 1), {
9874
- key: "",
9875
- value: "",
9876
- disabled: false
9877
- });
9878
- }
9879
9807
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9880
9808
  KeyboundForm,
9881
9809
  {
9882
- onSubmit: handleSubmit,
9883
9810
  className: "flex flex-1 flex-col overflow-hidden",
9811
+ onSubmit,
9884
9812
  children: [
9885
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9886
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9887
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9888
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9889
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9890
- ] }),
9891
- fields.map((field, index) => {
9892
- const isDisabled = field.disabled || false;
9893
- let placeholder = "-";
9894
- if (typeof field.value === "object") {
9895
- placeholder = "{ ... }";
9896
- }
9897
- if (Array.isArray(field.value)) {
9898
- placeholder = "[ ... ]";
9899
- }
9900
- return /* @__PURE__ */ jsx(
9901
- ConditionalTooltip,
9902
- {
9903
- showTooltip: isDisabled,
9904
- content: "This row is disabled because it contains non-primitive data.",
9905
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9906
- /* @__PURE__ */ jsxs(
9907
- "div",
9908
- {
9909
- className: clx("grid grid-cols-2 divide-x", {
9910
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9911
- }),
9912
- children: [
9913
- /* @__PURE__ */ jsx(
9914
- Form$2.Field,
9915
- {
9916
- control: form.control,
9917
- name: `metadata.${index}.key`,
9918
- render: ({ field: field2 }) => {
9919
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9920
- GridInput,
9921
- {
9922
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9923
- ...field2,
9924
- disabled: isDisabled,
9925
- placeholder: "Key"
9926
- }
9927
- ) }) });
9928
- }
9929
- }
9930
- ),
9931
- /* @__PURE__ */ jsx(
9932
- Form$2.Field,
9933
- {
9934
- control: form.control,
9935
- name: `metadata.${index}.value`,
9936
- render: ({ field: { value, ...field2 } }) => {
9937
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9938
- GridInput,
9939
- {
9940
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9941
- ...field2,
9942
- value: isDisabled ? placeholder : value,
9943
- disabled: isDisabled,
9944
- placeholder: "Value"
9945
- }
9946
- ) }) });
9947
- }
9948
- }
9949
- )
9950
- ]
9951
- }
9952
- ),
9953
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
9954
- /* @__PURE__ */ jsx(
9955
- DropdownMenu.Trigger,
9956
- {
9957
- className: clx(
9958
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9959
- {
9960
- hidden: isDisabled
9961
- }
9962
- ),
9963
- disabled: isDisabled,
9964
- asChild: true,
9965
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
9966
- }
9967
- ),
9968
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9969
- /* @__PURE__ */ jsxs(
9970
- DropdownMenu.Item,
9971
- {
9972
- className: "gap-x-2",
9973
- onClick: () => insertRow(index, "above"),
9974
- children: [
9975
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
9976
- "Insert row above"
9977
- ]
9978
- }
9979
- ),
9980
- /* @__PURE__ */ jsxs(
9981
- DropdownMenu.Item,
9982
- {
9983
- className: "gap-x-2",
9984
- onClick: () => insertRow(index, "below"),
9985
- children: [
9986
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
9987
- "Insert row below"
9988
- ]
9989
- }
9990
- ),
9991
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
9992
- /* @__PURE__ */ jsxs(
9993
- DropdownMenu.Item,
9994
- {
9995
- className: "gap-x-2",
9996
- onClick: () => deleteRow(index),
9997
- children: [
9998
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
9999
- "Delete row"
10000
- ]
10001
- }
10002
- )
10003
- ] })
10004
- ] })
10005
- ] })
10006
- },
10007
- field.id
10008
- );
10009
- })
10010
- ] }),
10011
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10012
- ] }),
10013
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10014
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9813
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9814
+ Form$2.Field,
9815
+ {
9816
+ control: form.control,
9817
+ name: "email",
9818
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9819
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9820
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9821
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9822
+ ] })
9823
+ }
9824
+ ) }),
9825
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9826
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10015
9827
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10016
9828
  ] }) })
10017
9829
  ]
10018
9830
  }
10019
9831
  ) });
10020
9832
  };
10021
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10022
- return /* @__PURE__ */ jsx(
10023
- "input",
10024
- {
10025
- ref,
10026
- ...props,
10027
- autoComplete: "off",
10028
- className: clx(
10029
- "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",
10030
- className
10031
- )
10032
- }
10033
- );
9833
+ const schema$3 = objectType({
9834
+ email: stringType().email()
10034
9835
  });
10035
- GridInput.displayName = "MetadataForm.GridInput";
10036
- const PlaceholderInner = () => {
10037
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10038
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10039
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10040
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10041
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10042
- ] }) })
10043
- ] });
10044
- };
10045
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10046
- function getDefaultValues(metadata) {
10047
- if (!metadata || !Object.keys(metadata).length) {
10048
- return [
10049
- {
10050
- key: "",
10051
- value: "",
10052
- disabled: false
10053
- }
10054
- ];
10055
- }
10056
- return Object.entries(metadata).map(([key, value]) => {
10057
- if (!EDITABLE_TYPES.includes(typeof value)) {
10058
- return {
10059
- key,
10060
- value,
10061
- disabled: true
10062
- };
10063
- }
10064
- let stringValue = value;
10065
- if (typeof value !== "string") {
10066
- stringValue = JSON.stringify(value);
10067
- }
10068
- return {
10069
- key,
10070
- value: stringValue,
10071
- original_key: key
10072
- };
10073
- });
10074
- }
10075
- function parseValues(values) {
10076
- const metadata = values.metadata;
10077
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10078
- if (isEmpty) {
10079
- return null;
10080
- }
10081
- const update = {};
10082
- metadata.forEach((field) => {
10083
- let key = field.key;
10084
- let value = field.value;
10085
- const disabled = field.disabled;
10086
- if (!key || !value) {
10087
- return;
10088
- }
10089
- if (disabled) {
10090
- update[key] = value;
10091
- return;
10092
- }
10093
- key = key.trim();
10094
- value = value.trim();
10095
- if (value === "true") {
10096
- update[key] = true;
10097
- } else if (value === "false") {
10098
- update[key] = false;
10099
- } else {
10100
- const parsedNumber = parseFloat(value);
10101
- if (!isNaN(parsedNumber)) {
10102
- update[key] = parsedNumber;
10103
- } else {
10104
- update[key] = value;
10105
- }
10106
- }
10107
- });
10108
- return update;
10109
- }
10110
- function getHasUneditableRows(metadata) {
10111
- if (!metadata) {
10112
- return false;
10113
- }
10114
- return Object.values(metadata).some(
10115
- (value) => !EDITABLE_TYPES.includes(typeof value)
10116
- );
10117
- }
10118
9836
  const NumberInput = forwardRef(
10119
9837
  ({
10120
9838
  value,
@@ -11089,195 +10807,545 @@ const customItemSchema = objectType({
11089
10807
  quantity: numberType(),
11090
10808
  unit_price: unionType([numberType(), stringType()])
11091
10809
  });
11092
- const PROMOTION_QUERY_KEY = "promotions";
11093
- const promotionsQueryKeys = {
11094
- list: (query2) => [
11095
- PROMOTION_QUERY_KEY,
11096
- query2 ? query2 : void 0
11097
- ],
11098
- detail: (id, query2) => [
11099
- PROMOTION_QUERY_KEY,
11100
- id,
11101
- query2 ? query2 : void 0
11102
- ]
11103
- };
11104
- const usePromotions = (query2, options) => {
11105
- const { data, ...rest } = useQuery({
11106
- queryKey: promotionsQueryKeys.list(query2),
11107
- queryFn: async () => sdk.admin.promotion.list(query2),
11108
- ...options
11109
- });
11110
- return { ...data, ...rest };
11111
- };
11112
- const Promotions = () => {
10810
+ const InlineTip = forwardRef(
10811
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10812
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10813
+ return /* @__PURE__ */ jsxs(
10814
+ "div",
10815
+ {
10816
+ ref,
10817
+ className: clx(
10818
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10819
+ className
10820
+ ),
10821
+ ...props,
10822
+ children: [
10823
+ /* @__PURE__ */ jsx(
10824
+ "div",
10825
+ {
10826
+ role: "presentation",
10827
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10828
+ "bg-ui-tag-orange-icon": variant === "warning"
10829
+ })
10830
+ }
10831
+ ),
10832
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10833
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10834
+ labelValue,
10835
+ ":"
10836
+ ] }),
10837
+ " ",
10838
+ children
10839
+ ] })
10840
+ ]
10841
+ }
10842
+ );
10843
+ }
10844
+ );
10845
+ InlineTip.displayName = "InlineTip";
10846
+ const MetadataFieldSchema = objectType({
10847
+ key: stringType(),
10848
+ disabled: booleanType().optional(),
10849
+ value: anyType()
10850
+ });
10851
+ const MetadataSchema = objectType({
10852
+ metadata: arrayType(MetadataFieldSchema)
10853
+ });
10854
+ const Metadata = () => {
11113
10855
  const { id } = useParams();
11114
- const {
11115
- order: preview,
11116
- isError: isPreviewError,
11117
- error: previewError
11118
- } = useOrderPreview(id, void 0);
11119
- useInitiateOrderEdit({ preview });
11120
- const { onCancel } = useCancelOrderEdit({ preview });
11121
- if (isPreviewError) {
11122
- throw previewError;
10856
+ const { order, isPending, isError, error } = useOrder(id, {
10857
+ fields: "metadata"
10858
+ });
10859
+ if (isError) {
10860
+ throw error;
11123
10861
  }
11124
- const isReady = !!preview;
11125
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11126
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11127
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10862
+ const isReady = !isPending && !!order;
10863
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10864
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10865
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10866
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10867
+ ] }),
10868
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11128
10869
  ] });
11129
10870
  };
11130
- const PromotionForm = ({ preview }) => {
11131
- const { items, shipping_methods } = preview;
11132
- const [isSubmitting, setIsSubmitting] = useState(false);
11133
- const [comboboxValue, setComboboxValue] = useState("");
10871
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10872
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10873
+ const MetadataForm = ({ orderId, metadata }) => {
11134
10874
  const { handleSuccess } = useRouteModal();
11135
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11136
- const promoCodes = getPromotionCodes(items, shipping_methods);
11137
- const { promotions, isPending, isError, error } = usePromotions(
11138
- {
11139
- code: promoCodes
11140
- },
11141
- {
11142
- enabled: !!promoCodes.length
11143
- }
11144
- );
11145
- const comboboxData = useComboboxData({
11146
- queryKey: ["promotions", "combobox", promoCodes],
11147
- queryFn: async (params) => {
11148
- return await sdk.admin.promotion.list({
11149
- ...params,
11150
- code: {
11151
- $nin: promoCodes
11152
- }
11153
- });
10875
+ const hasUneditableRows = getHasUneditableRows(metadata);
10876
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10877
+ const form = useForm({
10878
+ defaultValues: {
10879
+ metadata: getDefaultValues(metadata)
11154
10880
  },
11155
- getOptions: (data) => {
11156
- return data.promotions.map((promotion) => ({
11157
- label: promotion.code,
11158
- value: promotion.code
11159
- }));
11160
- }
10881
+ resolver: zodResolver(MetadataSchema)
11161
10882
  });
11162
- const add = async (value) => {
11163
- if (!value) {
11164
- return;
11165
- }
11166
- addPromotions(
10883
+ const handleSubmit = form.handleSubmit(async (data) => {
10884
+ const parsedData = parseValues(data);
10885
+ await mutateAsync(
11167
10886
  {
11168
- promo_codes: [value]
10887
+ metadata: parsedData
11169
10888
  },
11170
10889
  {
11171
- onError: (e) => {
11172
- toast.error(e.message);
11173
- comboboxData.onSearchValueChange("");
11174
- setComboboxValue("");
11175
- },
11176
10890
  onSuccess: () => {
11177
- comboboxData.onSearchValueChange("");
11178
- setComboboxValue("");
10891
+ toast.success("Metadata updated");
10892
+ handleSuccess();
10893
+ },
10894
+ onError: (error) => {
10895
+ toast.error(error.message);
11179
10896
  }
11180
10897
  }
11181
10898
  );
11182
- };
11183
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11184
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11185
- const onSubmit = async () => {
11186
- setIsSubmitting(true);
11187
- let requestSucceeded = false;
11188
- await requestOrderEdit(void 0, {
11189
- onError: (e) => {
11190
- toast.error(e.message);
11191
- },
11192
- onSuccess: () => {
11193
- requestSucceeded = true;
11194
- }
11195
- });
11196
- if (!requestSucceeded) {
11197
- setIsSubmitting(false);
11198
- return;
11199
- }
11200
- await confirmOrderEdit(void 0, {
11201
- onError: (e) => {
11202
- toast.error(e.message);
11203
- },
11204
- onSuccess: () => {
11205
- handleSuccess();
11206
- },
11207
- onSettled: () => {
11208
- setIsSubmitting(false);
11209
- }
10899
+ });
10900
+ const { fields, insert, remove } = useFieldArray({
10901
+ control: form.control,
10902
+ name: "metadata"
10903
+ });
10904
+ function deleteRow(index) {
10905
+ remove(index);
10906
+ if (fields.length === 1) {
10907
+ insert(0, {
10908
+ key: "",
10909
+ value: "",
10910
+ disabled: false
10911
+ });
10912
+ }
10913
+ }
10914
+ function insertRow(index, position) {
10915
+ insert(index + (position === "above" ? 0 : 1), {
10916
+ key: "",
10917
+ value: "",
10918
+ disabled: false
11210
10919
  });
11211
- };
11212
- if (isError) {
11213
- throw error;
11214
10920
  }
11215
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11216
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11217
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11218
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11219
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11220
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10921
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10922
+ KeyboundForm,
10923
+ {
10924
+ onSubmit: handleSubmit,
10925
+ className: "flex flex-1 flex-col overflow-hidden",
10926
+ children: [
10927
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10928
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10929
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10930
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10931
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10932
+ ] }),
10933
+ fields.map((field, index) => {
10934
+ const isDisabled = field.disabled || false;
10935
+ let placeholder = "-";
10936
+ if (typeof field.value === "object") {
10937
+ placeholder = "{ ... }";
10938
+ }
10939
+ if (Array.isArray(field.value)) {
10940
+ placeholder = "[ ... ]";
10941
+ }
10942
+ return /* @__PURE__ */ jsx(
10943
+ ConditionalTooltip,
10944
+ {
10945
+ showTooltip: isDisabled,
10946
+ content: "This row is disabled because it contains non-primitive data.",
10947
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10948
+ /* @__PURE__ */ jsxs(
10949
+ "div",
10950
+ {
10951
+ className: clx("grid grid-cols-2 divide-x", {
10952
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10953
+ }),
10954
+ children: [
10955
+ /* @__PURE__ */ jsx(
10956
+ Form$2.Field,
10957
+ {
10958
+ control: form.control,
10959
+ name: `metadata.${index}.key`,
10960
+ render: ({ field: field2 }) => {
10961
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10962
+ GridInput,
10963
+ {
10964
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10965
+ ...field2,
10966
+ disabled: isDisabled,
10967
+ placeholder: "Key"
10968
+ }
10969
+ ) }) });
10970
+ }
10971
+ }
10972
+ ),
10973
+ /* @__PURE__ */ jsx(
10974
+ Form$2.Field,
10975
+ {
10976
+ control: form.control,
10977
+ name: `metadata.${index}.value`,
10978
+ render: ({ field: { value, ...field2 } }) => {
10979
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10980
+ GridInput,
10981
+ {
10982
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10983
+ ...field2,
10984
+ value: isDisabled ? placeholder : value,
10985
+ disabled: isDisabled,
10986
+ placeholder: "Value"
10987
+ }
10988
+ ) }) });
10989
+ }
10990
+ }
10991
+ )
10992
+ ]
10993
+ }
10994
+ ),
10995
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10996
+ /* @__PURE__ */ jsx(
10997
+ DropdownMenu.Trigger,
10998
+ {
10999
+ className: clx(
11000
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11001
+ {
11002
+ hidden: isDisabled
11003
+ }
11004
+ ),
11005
+ disabled: isDisabled,
11006
+ asChild: true,
11007
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11008
+ }
11009
+ ),
11010
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11011
+ /* @__PURE__ */ jsxs(
11012
+ DropdownMenu.Item,
11013
+ {
11014
+ className: "gap-x-2",
11015
+ onClick: () => insertRow(index, "above"),
11016
+ children: [
11017
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11018
+ "Insert row above"
11019
+ ]
11020
+ }
11021
+ ),
11022
+ /* @__PURE__ */ jsxs(
11023
+ DropdownMenu.Item,
11024
+ {
11025
+ className: "gap-x-2",
11026
+ onClick: () => insertRow(index, "below"),
11027
+ children: [
11028
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11029
+ "Insert row below"
11030
+ ]
11031
+ }
11032
+ ),
11033
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11034
+ /* @__PURE__ */ jsxs(
11035
+ DropdownMenu.Item,
11036
+ {
11037
+ className: "gap-x-2",
11038
+ onClick: () => deleteRow(index),
11039
+ children: [
11040
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11041
+ "Delete row"
11042
+ ]
11043
+ }
11044
+ )
11045
+ ] })
11046
+ ] })
11047
+ ] })
11048
+ },
11049
+ field.id
11050
+ );
11051
+ })
11052
+ ] }),
11053
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11221
11054
  ] }),
11222
- /* @__PURE__ */ jsx(
11223
- Combobox,
11224
- {
11225
- id: "promotion-combobox",
11226
- "aria-describedby": "promotion-combobox-hint",
11227
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11228
- fetchNextPage: comboboxData.fetchNextPage,
11229
- options: comboboxData.options,
11230
- onSearchValueChange: comboboxData.onSearchValueChange,
11231
- searchValue: comboboxData.searchValue,
11232
- disabled: comboboxData.disabled || isAddingPromotions,
11233
- onChange: add,
11234
- value: comboboxValue
11235
- }
11236
- )
11237
- ] }),
11238
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11239
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11240
- PromotionItem,
11241
- {
11242
- promotion,
11243
- orderId: preview.id,
11244
- isLoading: isPending
11245
- },
11246
- promotion.id
11247
- )) })
11248
- ] }) }),
11249
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11250
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11251
- /* @__PURE__ */ jsx(
11252
- Button,
11253
- {
11254
- size: "small",
11255
- type: "submit",
11256
- isLoading: isSubmitting || isAddingPromotions,
11257
- children: "Save"
11258
- }
11055
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11056
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11057
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11058
+ ] }) })
11059
+ ]
11060
+ }
11061
+ ) });
11062
+ };
11063
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11064
+ return /* @__PURE__ */ jsx(
11065
+ "input",
11066
+ {
11067
+ ref,
11068
+ ...props,
11069
+ autoComplete: "off",
11070
+ className: clx(
11071
+ "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",
11072
+ className
11259
11073
  )
11074
+ }
11075
+ );
11076
+ });
11077
+ GridInput.displayName = "MetadataForm.GridInput";
11078
+ const PlaceholderInner = () => {
11079
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11080
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11081
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11082
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11083
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11260
11084
  ] }) })
11261
11085
  ] });
11262
11086
  };
11263
- const PromotionItem = ({
11264
- promotion,
11265
- orderId,
11266
- isLoading
11267
- }) => {
11268
- var _a;
11269
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11270
- const onRemove = async () => {
11271
- removePromotions(
11272
- {
11273
- promo_codes: [promotion.code]
11274
- },
11087
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11088
+ function getDefaultValues(metadata) {
11089
+ if (!metadata || !Object.keys(metadata).length) {
11090
+ return [
11275
11091
  {
11276
- onError: (e) => {
11277
- toast.error(e.message);
11278
- }
11092
+ key: "",
11093
+ value: "",
11094
+ disabled: false
11279
11095
  }
11280
- );
11096
+ ];
11097
+ }
11098
+ return Object.entries(metadata).map(([key, value]) => {
11099
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11100
+ return {
11101
+ key,
11102
+ value,
11103
+ disabled: true
11104
+ };
11105
+ }
11106
+ let stringValue = value;
11107
+ if (typeof value !== "string") {
11108
+ stringValue = JSON.stringify(value);
11109
+ }
11110
+ return {
11111
+ key,
11112
+ value: stringValue,
11113
+ original_key: key
11114
+ };
11115
+ });
11116
+ }
11117
+ function parseValues(values) {
11118
+ const metadata = values.metadata;
11119
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11120
+ if (isEmpty) {
11121
+ return null;
11122
+ }
11123
+ const update = {};
11124
+ metadata.forEach((field) => {
11125
+ let key = field.key;
11126
+ let value = field.value;
11127
+ const disabled = field.disabled;
11128
+ if (!key || !value) {
11129
+ return;
11130
+ }
11131
+ if (disabled) {
11132
+ update[key] = value;
11133
+ return;
11134
+ }
11135
+ key = key.trim();
11136
+ value = value.trim();
11137
+ if (value === "true") {
11138
+ update[key] = true;
11139
+ } else if (value === "false") {
11140
+ update[key] = false;
11141
+ } else {
11142
+ const parsedNumber = parseFloat(value);
11143
+ if (!isNaN(parsedNumber)) {
11144
+ update[key] = parsedNumber;
11145
+ } else {
11146
+ update[key] = value;
11147
+ }
11148
+ }
11149
+ });
11150
+ return update;
11151
+ }
11152
+ function getHasUneditableRows(metadata) {
11153
+ if (!metadata) {
11154
+ return false;
11155
+ }
11156
+ return Object.values(metadata).some(
11157
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11158
+ );
11159
+ }
11160
+ const PROMOTION_QUERY_KEY = "promotions";
11161
+ const promotionsQueryKeys = {
11162
+ list: (query2) => [
11163
+ PROMOTION_QUERY_KEY,
11164
+ query2 ? query2 : void 0
11165
+ ],
11166
+ detail: (id, query2) => [
11167
+ PROMOTION_QUERY_KEY,
11168
+ id,
11169
+ query2 ? query2 : void 0
11170
+ ]
11171
+ };
11172
+ const usePromotions = (query2, options) => {
11173
+ const { data, ...rest } = useQuery({
11174
+ queryKey: promotionsQueryKeys.list(query2),
11175
+ queryFn: async () => sdk.admin.promotion.list(query2),
11176
+ ...options
11177
+ });
11178
+ return { ...data, ...rest };
11179
+ };
11180
+ const Promotions = () => {
11181
+ const { id } = useParams();
11182
+ const {
11183
+ order: preview,
11184
+ isError: isPreviewError,
11185
+ error: previewError
11186
+ } = useOrderPreview(id, void 0);
11187
+ useInitiateOrderEdit({ preview });
11188
+ const { onCancel } = useCancelOrderEdit({ preview });
11189
+ if (isPreviewError) {
11190
+ throw previewError;
11191
+ }
11192
+ const isReady = !!preview;
11193
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11194
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11195
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11196
+ ] });
11197
+ };
11198
+ const PromotionForm = ({ preview }) => {
11199
+ const { items, shipping_methods } = preview;
11200
+ const [isSubmitting, setIsSubmitting] = useState(false);
11201
+ const [comboboxValue, setComboboxValue] = useState("");
11202
+ const { handleSuccess } = useRouteModal();
11203
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11204
+ const promoCodes = getPromotionCodes(items, shipping_methods);
11205
+ const { promotions, isPending, isError, error } = usePromotions(
11206
+ {
11207
+ code: promoCodes
11208
+ },
11209
+ {
11210
+ enabled: !!promoCodes.length
11211
+ }
11212
+ );
11213
+ const comboboxData = useComboboxData({
11214
+ queryKey: ["promotions", "combobox", promoCodes],
11215
+ queryFn: async (params) => {
11216
+ return await sdk.admin.promotion.list({
11217
+ ...params,
11218
+ code: {
11219
+ $nin: promoCodes
11220
+ }
11221
+ });
11222
+ },
11223
+ getOptions: (data) => {
11224
+ return data.promotions.map((promotion) => ({
11225
+ label: promotion.code,
11226
+ value: promotion.code
11227
+ }));
11228
+ }
11229
+ });
11230
+ const add = async (value) => {
11231
+ if (!value) {
11232
+ return;
11233
+ }
11234
+ addPromotions(
11235
+ {
11236
+ promo_codes: [value]
11237
+ },
11238
+ {
11239
+ onError: (e) => {
11240
+ toast.error(e.message);
11241
+ comboboxData.onSearchValueChange("");
11242
+ setComboboxValue("");
11243
+ },
11244
+ onSuccess: () => {
11245
+ comboboxData.onSearchValueChange("");
11246
+ setComboboxValue("");
11247
+ }
11248
+ }
11249
+ );
11250
+ };
11251
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11252
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11253
+ const onSubmit = async () => {
11254
+ setIsSubmitting(true);
11255
+ let requestSucceeded = false;
11256
+ await requestOrderEdit(void 0, {
11257
+ onError: (e) => {
11258
+ toast.error(e.message);
11259
+ },
11260
+ onSuccess: () => {
11261
+ requestSucceeded = true;
11262
+ }
11263
+ });
11264
+ if (!requestSucceeded) {
11265
+ setIsSubmitting(false);
11266
+ return;
11267
+ }
11268
+ await confirmOrderEdit(void 0, {
11269
+ onError: (e) => {
11270
+ toast.error(e.message);
11271
+ },
11272
+ onSuccess: () => {
11273
+ handleSuccess();
11274
+ },
11275
+ onSettled: () => {
11276
+ setIsSubmitting(false);
11277
+ }
11278
+ });
11279
+ };
11280
+ if (isError) {
11281
+ throw error;
11282
+ }
11283
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11284
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11285
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11286
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11287
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11288
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11289
+ ] }),
11290
+ /* @__PURE__ */ jsx(
11291
+ Combobox,
11292
+ {
11293
+ id: "promotion-combobox",
11294
+ "aria-describedby": "promotion-combobox-hint",
11295
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11296
+ fetchNextPage: comboboxData.fetchNextPage,
11297
+ options: comboboxData.options,
11298
+ onSearchValueChange: comboboxData.onSearchValueChange,
11299
+ searchValue: comboboxData.searchValue,
11300
+ disabled: comboboxData.disabled || isAddingPromotions,
11301
+ onChange: add,
11302
+ value: comboboxValue
11303
+ }
11304
+ )
11305
+ ] }),
11306
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11307
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11308
+ PromotionItem,
11309
+ {
11310
+ promotion,
11311
+ orderId: preview.id,
11312
+ isLoading: isPending
11313
+ },
11314
+ promotion.id
11315
+ )) })
11316
+ ] }) }),
11317
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11318
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11319
+ /* @__PURE__ */ jsx(
11320
+ Button,
11321
+ {
11322
+ size: "small",
11323
+ type: "submit",
11324
+ isLoading: isSubmitting || isAddingPromotions,
11325
+ children: "Save"
11326
+ }
11327
+ )
11328
+ ] }) })
11329
+ ] });
11330
+ };
11331
+ const PromotionItem = ({
11332
+ promotion,
11333
+ orderId,
11334
+ isLoading
11335
+ }) => {
11336
+ var _a;
11337
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11338
+ const onRemove = async () => {
11339
+ removePromotions(
11340
+ {
11341
+ promo_codes: [promotion.code]
11342
+ },
11343
+ {
11344
+ onError: (e) => {
11345
+ toast.error(e.message);
11346
+ }
11347
+ }
11348
+ );
11281
11349
  };
11282
11350
  const displayValue = getDisplayValue(promotion);
11283
11351
  return /* @__PURE__ */ jsxs(
@@ -11366,9 +11434,115 @@ function getPromotionCodes(items, shippingMethods) {
11366
11434
  }
11367
11435
  return Array.from(codes);
11368
11436
  }
11369
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11370
- const Shipping = () => {
11371
- var _a;
11437
+ const SalesChannel = () => {
11438
+ const { id } = useParams();
11439
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11440
+ id,
11441
+ {
11442
+ fields: "+sales_channel_id"
11443
+ },
11444
+ {
11445
+ enabled: !!id
11446
+ }
11447
+ );
11448
+ if (isError) {
11449
+ throw error;
11450
+ }
11451
+ const ISrEADY = !!draft_order && !isPending;
11452
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11453
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11454
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11455
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11456
+ ] }),
11457
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11458
+ ] });
11459
+ };
11460
+ const SalesChannelForm = ({ order }) => {
11461
+ const form = useForm({
11462
+ defaultValues: {
11463
+ sales_channel_id: order.sales_channel_id || ""
11464
+ },
11465
+ resolver: zodResolver(schema$2)
11466
+ });
11467
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11468
+ const { handleSuccess } = useRouteModal();
11469
+ const onSubmit = form.handleSubmit(async (data) => {
11470
+ await mutateAsync(
11471
+ {
11472
+ sales_channel_id: data.sales_channel_id
11473
+ },
11474
+ {
11475
+ onSuccess: () => {
11476
+ toast.success("Sales channel updated");
11477
+ handleSuccess();
11478
+ },
11479
+ onError: (error) => {
11480
+ toast.error(error.message);
11481
+ }
11482
+ }
11483
+ );
11484
+ });
11485
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11486
+ KeyboundForm,
11487
+ {
11488
+ className: "flex flex-1 flex-col overflow-hidden",
11489
+ onSubmit,
11490
+ children: [
11491
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11492
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11493
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11494
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11495
+ ] }) })
11496
+ ]
11497
+ }
11498
+ ) });
11499
+ };
11500
+ const SalesChannelField = ({ control, order }) => {
11501
+ const salesChannels = useComboboxData({
11502
+ queryFn: async (params) => {
11503
+ return await sdk.admin.salesChannel.list(params);
11504
+ },
11505
+ queryKey: ["sales-channels"],
11506
+ getOptions: (data) => {
11507
+ return data.sales_channels.map((salesChannel) => ({
11508
+ label: salesChannel.name,
11509
+ value: salesChannel.id
11510
+ }));
11511
+ },
11512
+ defaultValue: order.sales_channel_id || void 0
11513
+ });
11514
+ return /* @__PURE__ */ jsx(
11515
+ Form$2.Field,
11516
+ {
11517
+ control,
11518
+ name: "sales_channel_id",
11519
+ render: ({ field }) => {
11520
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11521
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11522
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11523
+ Combobox,
11524
+ {
11525
+ options: salesChannels.options,
11526
+ fetchNextPage: salesChannels.fetchNextPage,
11527
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11528
+ searchValue: salesChannels.searchValue,
11529
+ onSearchValueChange: salesChannels.onSearchValueChange,
11530
+ placeholder: "Select sales channel",
11531
+ ...field
11532
+ }
11533
+ ) }),
11534
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11535
+ ] });
11536
+ }
11537
+ }
11538
+ );
11539
+ };
11540
+ const schema$2 = objectType({
11541
+ sales_channel_id: stringType().min(1)
11542
+ });
11543
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11544
+ const Shipping = () => {
11545
+ var _a;
11372
11546
  const { id } = useParams();
11373
11547
  const { order, isPending, isError, error } = useOrder(id, {
11374
11548
  fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
@@ -11744,638 +11918,435 @@ const ShippingForm = ({ preview, order }) => {
11744
11918
  },
11745
11919
  item.id
11746
11920
  ),
11747
- idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11748
- ] }, item.id);
11749
- })
11750
- ] })
11751
- ]
11752
- },
11753
- profile.id
11754
- );
11755
- }) })
11756
- ] }) })
11757
- ] }) }),
11758
- /* @__PURE__ */ jsx(
11759
- StackedFocusModal,
11760
- {
11761
- id: STACKED_FOCUS_MODAL_ID,
11762
- onOpenChangeCallback: (open) => {
11763
- if (!open) {
11764
- setData(null);
11765
- }
11766
- return open;
11767
- },
11768
- children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11769
- }
11770
- )
11771
- ] }),
11772
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11773
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11774
- /* @__PURE__ */ jsx(
11775
- Button,
11776
- {
11777
- size: "small",
11778
- type: "button",
11779
- isLoading: isSubmitting,
11780
- onClick: onSubmit,
11781
- children: "Save"
11782
- }
11783
- )
11784
- ] }) })
11785
- ] });
11786
- };
11787
- const StackedModalTrigger = ({
11788
- shippingProfileId,
11789
- shippingOption,
11790
- shippingMethod,
11791
- setData,
11792
- children
11793
- }) => {
11794
- const { setIsOpen, getIsOpen } = useStackedModal();
11795
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11796
- const onToggle = () => {
11797
- if (isOpen) {
11798
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11799
- setData(null);
11800
- } else {
11801
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11802
- setData({
11803
- shippingProfileId,
11804
- shippingOption,
11805
- shippingMethod
11806
- });
11807
- }
11808
- };
11809
- return /* @__PURE__ */ jsx(
11810
- Button,
11811
- {
11812
- size: "small",
11813
- variant: "secondary",
11814
- onClick: onToggle,
11815
- className: "text-ui-fg-primary shrink-0",
11816
- children
11817
- }
11818
- );
11819
- };
11820
- const ShippingProfileForm = ({
11821
- data,
11822
- order,
11823
- preview
11824
- }) => {
11825
- var _a, _b, _c, _d, _e, _f;
11826
- const { setIsOpen } = useStackedModal();
11827
- const form = useForm({
11828
- resolver: zodResolver(shippingMethodSchema),
11829
- defaultValues: {
11830
- 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,
11831
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11832
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11833
- }
11834
- });
11835
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11836
- const {
11837
- mutateAsync: updateShippingMethod,
11838
- isPending: isUpdatingShippingMethod
11839
- } = useDraftOrderUpdateShippingMethod(order.id);
11840
- const onSubmit = form.handleSubmit(async (values) => {
11841
- if (isEqual(values, form.formState.defaultValues)) {
11842
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11843
- return;
11844
- }
11845
- if (data.shippingMethod) {
11846
- await updateShippingMethod(
11847
- {
11848
- method_id: data.shippingMethod.id,
11849
- shipping_option_id: values.shipping_option_id,
11850
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11851
- },
11852
- {
11853
- onError: (e) => {
11854
- toast.error(e.message);
11855
- },
11856
- onSuccess: () => {
11857
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11858
- }
11859
- }
11860
- );
11861
- return;
11862
- }
11863
- await addShippingMethod(
11864
- {
11865
- shipping_option_id: values.shipping_option_id,
11866
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11867
- },
11868
- {
11869
- onError: (e) => {
11870
- toast.error(e.message);
11871
- },
11872
- onSuccess: () => {
11873
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11874
- }
11875
- }
11876
- );
11877
- });
11878
- return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
11879
- KeyboundForm,
11880
- {
11881
- className: "flex h-full flex-col overflow-hidden",
11882
- onSubmit,
11883
- children: [
11884
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11885
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11886
- /* @__PURE__ */ jsxs("div", { children: [
11887
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11888
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11889
- ] }),
11890
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11891
- /* @__PURE__ */ jsx(
11892
- LocationField,
11893
- {
11894
- control: form.control,
11895
- setValue: form.setValue
11896
- }
11897
- ),
11898
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11899
- /* @__PURE__ */ jsx(
11900
- ShippingOptionField,
11901
- {
11902
- shippingProfileId: data.shippingProfileId,
11903
- preview,
11904
- control: form.control
11905
- }
11906
- ),
11907
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11908
- /* @__PURE__ */ jsx(
11909
- CustomAmountField,
11910
- {
11911
- control: form.control,
11912
- currencyCode: order.currency_code
11913
- }
11914
- ),
11915
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11916
- /* @__PURE__ */ jsx(
11917
- ItemsPreview,
11918
- {
11919
- order,
11920
- shippingProfileId: data.shippingProfileId
11921
- }
11922
- )
11923
- ] }) }) }),
11924
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11925
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11926
- /* @__PURE__ */ jsx(
11927
- Button,
11928
- {
11929
- size: "small",
11930
- type: "submit",
11931
- isLoading: isPending || isUpdatingShippingMethod,
11932
- children: data.shippingMethod ? "Update" : "Add"
11933
- }
11934
- )
11935
- ] }) })
11936
- ]
11937
- }
11938
- ) }) });
11939
- };
11940
- const shippingMethodSchema = objectType({
11941
- location_id: stringType(),
11942
- shipping_option_id: stringType(),
11943
- custom_amount: unionType([numberType(), stringType()]).optional()
11944
- });
11945
- const ItemsPreview = ({ order, shippingProfileId }) => {
11946
- const matches = order.items.filter(
11947
- (item) => {
11948
- var _a, _b, _c;
11949
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11950
- }
11951
- );
11952
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
11953
- /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11954
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11955
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11956
- ] }) }),
11957
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11958
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11959
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
11960
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
11961
- ] }),
11962
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
11963
- "div",
11964
- {
11965
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11966
- children: [
11967
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11968
- /* @__PURE__ */ jsx(
11969
- Thumbnail,
11970
- {
11971
- thumbnail: item.thumbnail,
11972
- alt: item.product_title ?? void 0
11973
- }
11974
- ),
11975
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11976
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11977
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11978
- /* @__PURE__ */ jsxs(
11979
- Text,
11980
- {
11981
- size: "small",
11982
- leading: "compact",
11983
- className: "text-ui-fg-subtle",
11984
- children: [
11985
- "(",
11986
- item.variant_title,
11987
- ")"
11988
- ]
11989
- }
11990
- )
11991
- ] }),
11992
- /* @__PURE__ */ jsx(
11993
- Text,
11994
- {
11995
- size: "small",
11996
- leading: "compact",
11997
- className: "text-ui-fg-subtle",
11998
- children: item.variant_sku
11999
- }
12000
- )
12001
- ] })
12002
- ] }),
12003
- /* @__PURE__ */ jsxs(
12004
- Text,
12005
- {
12006
- size: "small",
12007
- leading: "compact",
12008
- className: "text-ui-fg-subtle",
12009
- children: [
12010
- item.quantity,
12011
- "x"
12012
- ]
12013
- }
12014
- )
12015
- ]
12016
- },
12017
- item.id
12018
- )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12019
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12020
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12021
- 'No items found for "',
12022
- query,
12023
- '".'
12024
- ] })
12025
- ] }) })
12026
- ] })
12027
- ] });
12028
- };
12029
- const LocationField = ({ control, setValue }) => {
12030
- const locations = useComboboxData({
12031
- queryKey: ["locations"],
12032
- queryFn: async (params) => {
12033
- return await sdk.admin.stockLocation.list(params);
12034
- },
12035
- getOptions: (data) => {
12036
- return data.stock_locations.map((location) => ({
12037
- label: location.name,
12038
- value: location.id
12039
- }));
12040
- }
12041
- });
12042
- return /* @__PURE__ */ jsx(
12043
- Form$2.Field,
12044
- {
12045
- control,
12046
- name: "location_id",
12047
- render: ({ field: { onChange, ...field } }) => {
12048
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12049
- /* @__PURE__ */ jsxs("div", { children: [
12050
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12051
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12052
- ] }),
12053
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12054
- Combobox,
12055
- {
12056
- options: locations.options,
12057
- fetchNextPage: locations.fetchNextPage,
12058
- isFetchingNextPage: locations.isFetchingNextPage,
12059
- searchValue: locations.searchValue,
12060
- onSearchValueChange: locations.onSearchValueChange,
12061
- placeholder: "Select location",
12062
- onChange: (value) => {
12063
- setValue("shipping_option_id", "", {
12064
- shouldDirty: true,
12065
- shouldTouch: true
12066
- });
12067
- onChange(value);
11921
+ idx !== items.length - 1 && /* @__PURE__ */ jsx(Divider, { variant: "dashed" })
11922
+ ] }, item.id);
11923
+ })
11924
+ ] })
11925
+ ]
12068
11926
  },
12069
- ...field
11927
+ profile.id
11928
+ );
11929
+ }) })
11930
+ ] }) })
11931
+ ] }) }),
11932
+ /* @__PURE__ */ jsx(
11933
+ StackedFocusModal,
11934
+ {
11935
+ id: STACKED_FOCUS_MODAL_ID,
11936
+ onOpenChangeCallback: (open) => {
11937
+ if (!open) {
11938
+ setData(null);
12070
11939
  }
12071
- ) })
12072
- ] }) });
12073
- }
12074
- }
12075
- );
11940
+ return open;
11941
+ },
11942
+ children: data && /* @__PURE__ */ jsx(ShippingProfileForm, { data, order, preview })
11943
+ }
11944
+ )
11945
+ ] }),
11946
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
11947
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11948
+ /* @__PURE__ */ jsx(
11949
+ Button,
11950
+ {
11951
+ size: "small",
11952
+ type: "button",
11953
+ isLoading: isSubmitting,
11954
+ onClick: onSubmit,
11955
+ children: "Save"
11956
+ }
11957
+ )
11958
+ ] }) })
11959
+ ] });
12076
11960
  };
12077
- const ShippingOptionField = ({
11961
+ const StackedModalTrigger = ({
12078
11962
  shippingProfileId,
12079
- preview,
12080
- control
11963
+ shippingOption,
11964
+ shippingMethod,
11965
+ setData,
11966
+ children
12081
11967
  }) => {
12082
- var _a;
12083
- const locationId = useWatch({ control, name: "location_id" });
12084
- const shippingOptions = useComboboxData({
12085
- queryKey: ["shipping_options", locationId, shippingProfileId],
12086
- queryFn: async (params) => {
12087
- return await sdk.admin.shippingOption.list({
12088
- ...params,
12089
- stock_location_id: locationId,
12090
- shipping_profile_id: shippingProfileId
11968
+ const { setIsOpen, getIsOpen } = useStackedModal();
11969
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11970
+ const onToggle = () => {
11971
+ if (isOpen) {
11972
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11973
+ setData(null);
11974
+ } else {
11975
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11976
+ setData({
11977
+ shippingProfileId,
11978
+ shippingOption,
11979
+ shippingMethod
12091
11980
  });
12092
- },
12093
- getOptions: (data) => {
12094
- return data.shipping_options.map((option) => {
12095
- var _a2;
12096
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12097
- (r) => r.attribute === "is_return" && r.value === "true"
12098
- )) {
12099
- return void 0;
12100
- }
12101
- return {
12102
- label: option.name,
12103
- value: option.id
12104
- };
12105
- }).filter(Boolean);
12106
- },
12107
- enabled: !!locationId && !!shippingProfileId,
12108
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12109
- });
12110
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12111
- return /* @__PURE__ */ jsx(
12112
- Form$2.Field,
12113
- {
12114
- control,
12115
- name: "shipping_option_id",
12116
- render: ({ field }) => {
12117
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12118
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12119
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12120
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12121
- ] }),
12122
- /* @__PURE__ */ jsx(
12123
- ConditionalTooltip,
12124
- {
12125
- content: tooltipContent,
12126
- showTooltip: !locationId || !shippingProfileId,
12127
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12128
- Combobox,
12129
- {
12130
- options: shippingOptions.options,
12131
- fetchNextPage: shippingOptions.fetchNextPage,
12132
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12133
- searchValue: shippingOptions.searchValue,
12134
- onSearchValueChange: shippingOptions.onSearchValueChange,
12135
- placeholder: "Select shipping option",
12136
- ...field,
12137
- disabled: !locationId || !shippingProfileId
12138
- }
12139
- ) }) })
12140
- }
12141
- )
12142
- ] }) });
12143
- }
12144
11981
  }
12145
- );
12146
- };
12147
- const CustomAmountField = ({
12148
- control,
12149
- currencyCode
12150
- }) => {
11982
+ };
12151
11983
  return /* @__PURE__ */ jsx(
12152
- Form$2.Field,
11984
+ Button,
12153
11985
  {
12154
- control,
12155
- name: "custom_amount",
12156
- render: ({ field: { onChange, ...field } }) => {
12157
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12158
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12159
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12160
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12161
- ] }),
12162
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12163
- CurrencyInput,
12164
- {
12165
- ...field,
12166
- onValueChange: (value) => onChange(value),
12167
- symbol: getNativeSymbol(currencyCode),
12168
- code: currencyCode
12169
- }
12170
- ) })
12171
- ] });
12172
- }
11986
+ size: "small",
11987
+ variant: "secondary",
11988
+ onClick: onToggle,
11989
+ className: "text-ui-fg-primary shrink-0",
11990
+ children
12173
11991
  }
12174
11992
  );
12175
11993
  };
12176
- const ShippingAddress = () => {
12177
- const { id } = useParams();
12178
- const { order, isPending, isError, error } = useOrder(id, {
12179
- fields: "+shipping_address"
12180
- });
12181
- if (isError) {
12182
- throw error;
12183
- }
12184
- const isReady = !isPending && !!order;
12185
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12186
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12187
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12188
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12189
- ] }),
12190
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12191
- ] });
12192
- };
12193
- const ShippingAddressForm = ({ order }) => {
12194
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11994
+ const ShippingProfileForm = ({
11995
+ data,
11996
+ order,
11997
+ preview
11998
+ }) => {
11999
+ var _a, _b, _c, _d, _e, _f;
12000
+ const { setIsOpen } = useStackedModal();
12195
12001
  const form = useForm({
12002
+ resolver: zodResolver(shippingMethodSchema),
12196
12003
  defaultValues: {
12197
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12198
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12199
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12200
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12201
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12202
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12203
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12204
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12205
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12206
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12207
- },
12208
- resolver: zodResolver(schema$3)
12004
+ 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,
12005
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12006
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12007
+ }
12209
12008
  });
12210
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12211
- const { handleSuccess } = useRouteModal();
12212
- const onSubmit = form.handleSubmit(async (data) => {
12213
- await mutateAsync(
12214
- {
12215
- shipping_address: {
12216
- first_name: data.first_name,
12217
- last_name: data.last_name,
12218
- company: data.company,
12219
- address_1: data.address_1,
12220
- address_2: data.address_2,
12221
- city: data.city,
12222
- province: data.province,
12223
- country_code: data.country_code,
12224
- postal_code: data.postal_code,
12225
- phone: data.phone
12009
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12010
+ const {
12011
+ mutateAsync: updateShippingMethod,
12012
+ isPending: isUpdatingShippingMethod
12013
+ } = useDraftOrderUpdateShippingMethod(order.id);
12014
+ const onSubmit = form.handleSubmit(async (values) => {
12015
+ if (isEqual(values, form.formState.defaultValues)) {
12016
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12017
+ return;
12018
+ }
12019
+ if (data.shippingMethod) {
12020
+ await updateShippingMethod(
12021
+ {
12022
+ method_id: data.shippingMethod.id,
12023
+ shipping_option_id: values.shipping_option_id,
12024
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12025
+ },
12026
+ {
12027
+ onError: (e) => {
12028
+ toast.error(e.message);
12029
+ },
12030
+ onSuccess: () => {
12031
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12032
+ }
12226
12033
  }
12034
+ );
12035
+ return;
12036
+ }
12037
+ await addShippingMethod(
12038
+ {
12039
+ shipping_option_id: values.shipping_option_id,
12040
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12227
12041
  },
12228
12042
  {
12229
- onSuccess: () => {
12230
- handleSuccess();
12043
+ onError: (e) => {
12044
+ toast.error(e.message);
12231
12045
  },
12232
- onError: (error) => {
12233
- toast.error(error.message);
12046
+ onSuccess: () => {
12047
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12234
12048
  }
12235
12049
  }
12236
12050
  );
12237
12051
  });
12238
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12052
+ return /* @__PURE__ */ jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxs(
12239
12053
  KeyboundForm,
12240
12054
  {
12241
- className: "flex flex-1 flex-col overflow-hidden",
12055
+ className: "flex h-full flex-col overflow-hidden",
12242
12056
  onSubmit,
12243
12057
  children: [
12244
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12058
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12059
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12060
+ /* @__PURE__ */ jsxs("div", { children: [
12061
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12062
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12063
+ ] }),
12064
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12245
12065
  /* @__PURE__ */ jsx(
12246
- Form$2.Field,
12066
+ LocationField,
12247
12067
  {
12248
12068
  control: form.control,
12249
- name: "country_code",
12250
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12251
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12252
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12253
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12254
- ] })
12069
+ setValue: form.setValue
12255
12070
  }
12256
12071
  ),
12257
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12258
- /* @__PURE__ */ jsx(
12259
- Form$2.Field,
12260
- {
12261
- control: form.control,
12262
- name: "first_name",
12263
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12264
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12265
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12266
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12267
- ] })
12268
- }
12269
- ),
12270
- /* @__PURE__ */ jsx(
12271
- Form$2.Field,
12272
- {
12273
- control: form.control,
12274
- name: "last_name",
12275
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12276
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12277
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12278
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12279
- ] })
12280
- }
12281
- )
12282
- ] }),
12072
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12283
12073
  /* @__PURE__ */ jsx(
12284
- Form$2.Field,
12074
+ ShippingOptionField,
12285
12075
  {
12286
- control: form.control,
12287
- name: "company",
12288
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12289
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12290
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12291
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12292
- ] })
12076
+ shippingProfileId: data.shippingProfileId,
12077
+ preview,
12078
+ control: form.control
12293
12079
  }
12294
12080
  ),
12081
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12295
12082
  /* @__PURE__ */ jsx(
12296
- Form$2.Field,
12083
+ CustomAmountField,
12297
12084
  {
12298
12085
  control: form.control,
12299
- name: "address_1",
12300
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12301
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12302
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12303
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12304
- ] })
12086
+ currencyCode: order.currency_code
12305
12087
  }
12306
12088
  ),
12089
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12307
12090
  /* @__PURE__ */ jsx(
12308
- Form$2.Field,
12091
+ ItemsPreview,
12309
12092
  {
12310
- control: form.control,
12311
- name: "address_2",
12312
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12313
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12314
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12315
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12316
- ] })
12093
+ order,
12094
+ shippingProfileId: data.shippingProfileId
12317
12095
  }
12318
- ),
12319
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12320
- /* @__PURE__ */ jsx(
12321
- Form$2.Field,
12322
- {
12323
- control: form.control,
12324
- name: "postal_code",
12325
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12326
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12327
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12328
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12329
- ] })
12330
- }
12331
- ),
12332
- /* @__PURE__ */ jsx(
12333
- Form$2.Field,
12096
+ )
12097
+ ] }) }) }),
12098
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-x-2", children: [
12099
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12100
+ /* @__PURE__ */ jsx(
12101
+ Button,
12102
+ {
12103
+ size: "small",
12104
+ type: "submit",
12105
+ isLoading: isPending || isUpdatingShippingMethod,
12106
+ children: data.shippingMethod ? "Update" : "Add"
12107
+ }
12108
+ )
12109
+ ] }) })
12110
+ ]
12111
+ }
12112
+ ) }) });
12113
+ };
12114
+ const shippingMethodSchema = objectType({
12115
+ location_id: stringType(),
12116
+ shipping_option_id: stringType(),
12117
+ custom_amount: unionType([numberType(), stringType()]).optional()
12118
+ });
12119
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12120
+ const matches = order.items.filter(
12121
+ (item) => {
12122
+ var _a, _b, _c;
12123
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12124
+ }
12125
+ );
12126
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12127
+ /* @__PURE__ */ jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12128
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12129
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12130
+ ] }) }),
12131
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12132
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12133
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12134
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12135
+ ] }),
12136
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxs(
12137
+ "div",
12138
+ {
12139
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12140
+ children: [
12141
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12142
+ /* @__PURE__ */ jsx(
12143
+ Thumbnail,
12144
+ {
12145
+ thumbnail: item.thumbnail,
12146
+ alt: item.product_title ?? void 0
12147
+ }
12148
+ ),
12149
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12150
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12151
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12152
+ /* @__PURE__ */ jsxs(
12153
+ Text,
12154
+ {
12155
+ size: "small",
12156
+ leading: "compact",
12157
+ className: "text-ui-fg-subtle",
12158
+ children: [
12159
+ "(",
12160
+ item.variant_title,
12161
+ ")"
12162
+ ]
12163
+ }
12164
+ )
12165
+ ] }),
12166
+ /* @__PURE__ */ jsx(
12167
+ Text,
12168
+ {
12169
+ size: "small",
12170
+ leading: "compact",
12171
+ className: "text-ui-fg-subtle",
12172
+ children: item.variant_sku
12173
+ }
12174
+ )
12175
+ ] })
12176
+ ] }),
12177
+ /* @__PURE__ */ jsxs(
12178
+ Text,
12334
12179
  {
12335
- control: form.control,
12336
- name: "city",
12337
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12338
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12339
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12340
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12341
- ] })
12180
+ size: "small",
12181
+ leading: "compact",
12182
+ className: "text-ui-fg-subtle",
12183
+ children: [
12184
+ item.quantity,
12185
+ "x"
12186
+ ]
12342
12187
  }
12343
12188
  )
12189
+ ]
12190
+ },
12191
+ item.id
12192
+ )) : /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12193
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12194
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12195
+ 'No items found for "',
12196
+ query,
12197
+ '".'
12198
+ ] })
12199
+ ] }) })
12200
+ ] })
12201
+ ] });
12202
+ };
12203
+ const LocationField = ({ control, setValue }) => {
12204
+ const locations = useComboboxData({
12205
+ queryKey: ["locations"],
12206
+ queryFn: async (params) => {
12207
+ return await sdk.admin.stockLocation.list(params);
12208
+ },
12209
+ getOptions: (data) => {
12210
+ return data.stock_locations.map((location) => ({
12211
+ label: location.name,
12212
+ value: location.id
12213
+ }));
12214
+ }
12215
+ });
12216
+ return /* @__PURE__ */ jsx(
12217
+ Form$2.Field,
12218
+ {
12219
+ control,
12220
+ name: "location_id",
12221
+ render: ({ field: { onChange, ...field } }) => {
12222
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12223
+ /* @__PURE__ */ jsxs("div", { children: [
12224
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Location" }),
12225
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12226
+ ] }),
12227
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12228
+ Combobox,
12229
+ {
12230
+ options: locations.options,
12231
+ fetchNextPage: locations.fetchNextPage,
12232
+ isFetchingNextPage: locations.isFetchingNextPage,
12233
+ searchValue: locations.searchValue,
12234
+ onSearchValueChange: locations.onSearchValueChange,
12235
+ placeholder: "Select location",
12236
+ onChange: (value) => {
12237
+ setValue("shipping_option_id", "", {
12238
+ shouldDirty: true,
12239
+ shouldTouch: true
12240
+ });
12241
+ onChange(value);
12242
+ },
12243
+ ...field
12244
+ }
12245
+ ) })
12246
+ ] }) });
12247
+ }
12248
+ }
12249
+ );
12250
+ };
12251
+ const ShippingOptionField = ({
12252
+ shippingProfileId,
12253
+ preview,
12254
+ control
12255
+ }) => {
12256
+ var _a;
12257
+ const locationId = useWatch({ control, name: "location_id" });
12258
+ const shippingOptions = useComboboxData({
12259
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12260
+ queryFn: async (params) => {
12261
+ return await sdk.admin.shippingOption.list({
12262
+ ...params,
12263
+ stock_location_id: locationId,
12264
+ shipping_profile_id: shippingProfileId
12265
+ });
12266
+ },
12267
+ getOptions: (data) => {
12268
+ return data.shipping_options.map((option) => {
12269
+ var _a2;
12270
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12271
+ (r) => r.attribute === "is_return" && r.value === "true"
12272
+ )) {
12273
+ return void 0;
12274
+ }
12275
+ return {
12276
+ label: option.name,
12277
+ value: option.id
12278
+ };
12279
+ }).filter(Boolean);
12280
+ },
12281
+ enabled: !!locationId && !!shippingProfileId,
12282
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12283
+ });
12284
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12285
+ return /* @__PURE__ */ jsx(
12286
+ Form$2.Field,
12287
+ {
12288
+ control,
12289
+ name: "shipping_option_id",
12290
+ render: ({ field }) => {
12291
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12292
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12293
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12294
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12344
12295
  ] }),
12345
12296
  /* @__PURE__ */ jsx(
12346
- Form$2.Field,
12297
+ ConditionalTooltip,
12347
12298
  {
12348
- control: form.control,
12349
- name: "province",
12350
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12351
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12352
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12353
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12354
- ] })
12299
+ content: tooltipContent,
12300
+ showTooltip: !locationId || !shippingProfileId,
12301
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12302
+ Combobox,
12303
+ {
12304
+ options: shippingOptions.options,
12305
+ fetchNextPage: shippingOptions.fetchNextPage,
12306
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12307
+ searchValue: shippingOptions.searchValue,
12308
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12309
+ placeholder: "Select shipping option",
12310
+ ...field,
12311
+ disabled: !locationId || !shippingProfileId
12312
+ }
12313
+ ) }) })
12355
12314
  }
12356
- ),
12357
- /* @__PURE__ */ jsx(
12358
- Form$2.Field,
12315
+ )
12316
+ ] }) });
12317
+ }
12318
+ }
12319
+ );
12320
+ };
12321
+ const CustomAmountField = ({
12322
+ control,
12323
+ currencyCode
12324
+ }) => {
12325
+ return /* @__PURE__ */ jsx(
12326
+ Form$2.Field,
12327
+ {
12328
+ control,
12329
+ name: "custom_amount",
12330
+ render: ({ field: { onChange, ...field } }) => {
12331
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12332
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12333
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12334
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12335
+ ] }),
12336
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12337
+ CurrencyInput,
12359
12338
  {
12360
- control: form.control,
12361
- name: "phone",
12362
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12363
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12364
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12365
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12366
- ] })
12339
+ ...field,
12340
+ onValueChange: (value) => onChange(value),
12341
+ symbol: getNativeSymbol(currencyCode),
12342
+ code: currencyCode
12367
12343
  }
12368
- )
12369
- ] }) }),
12370
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12371
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12372
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12373
- ] }) })
12374
- ]
12344
+ ) })
12345
+ ] });
12346
+ }
12375
12347
  }
12376
- ) });
12348
+ );
12377
12349
  };
12378
- const schema$3 = addressSchema;
12379
12350
  const TransferOwnership = () => {
12380
12351
  const { id } = useParams();
12381
12352
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12399,7 +12370,7 @@ const TransferOwnershipForm = ({ order }) => {
12399
12370
  defaultValues: {
12400
12371
  customer_id: order.customer_id || ""
12401
12372
  },
12402
- resolver: zodResolver(schema$2)
12373
+ resolver: zodResolver(schema$1)
12403
12374
  });
12404
12375
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12405
12376
  const { handleSuccess } = useRouteModal();
@@ -12802,166 +12773,60 @@ const Illustration = () => {
12802
12773
  /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12803
12774
  "rect",
12804
12775
  {
12805
- width: "12",
12806
- height: "12",
12807
- fill: "white",
12808
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12809
- }
12810
- ) }),
12811
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12812
- "rect",
12813
- {
12814
- width: "12",
12815
- height: "12",
12816
- fill: "white",
12817
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12818
- }
12819
- ) }),
12820
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12821
- "rect",
12822
- {
12823
- width: "12",
12824
- height: "12",
12825
- fill: "white",
12826
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12827
- }
12828
- ) }),
12829
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12830
- "rect",
12831
- {
12832
- width: "12",
12833
- height: "12",
12834
- fill: "white",
12835
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12836
- }
12837
- ) }),
12838
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12839
- "rect",
12840
- {
12841
- width: "12",
12842
- height: "12",
12843
- fill: "white",
12844
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12845
- }
12846
- ) })
12847
- ] })
12848
- ]
12849
- }
12850
- );
12851
- };
12852
- const schema$2 = objectType({
12853
- customer_id: stringType().min(1)
12854
- });
12855
- const SalesChannel = () => {
12856
- const { id } = useParams();
12857
- const { draft_order, isPending, isError, error } = useDraftOrder(
12858
- id,
12859
- {
12860
- fields: "+sales_channel_id"
12861
- },
12862
- {
12863
- enabled: !!id
12864
- }
12865
- );
12866
- if (isError) {
12867
- throw error;
12868
- }
12869
- const ISrEADY = !!draft_order && !isPending;
12870
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12871
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12872
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12873
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12874
- ] }),
12875
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12876
- ] });
12877
- };
12878
- const SalesChannelForm = ({ order }) => {
12879
- const form = useForm({
12880
- defaultValues: {
12881
- sales_channel_id: order.sales_channel_id || ""
12882
- },
12883
- resolver: zodResolver(schema$1)
12884
- });
12885
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12886
- const { handleSuccess } = useRouteModal();
12887
- const onSubmit = form.handleSubmit(async (data) => {
12888
- await mutateAsync(
12889
- {
12890
- sales_channel_id: data.sales_channel_id
12891
- },
12892
- {
12893
- onSuccess: () => {
12894
- toast.success("Sales channel updated");
12895
- handleSuccess();
12896
- },
12897
- onError: (error) => {
12898
- toast.error(error.message);
12899
- }
12900
- }
12901
- );
12902
- });
12903
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12904
- KeyboundForm,
12905
- {
12906
- className: "flex flex-1 flex-col overflow-hidden",
12907
- onSubmit,
12908
- children: [
12909
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12910
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12911
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12912
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12913
- ] }) })
12914
- ]
12915
- }
12916
- ) });
12917
- };
12918
- const SalesChannelField = ({ control, order }) => {
12919
- const salesChannels = useComboboxData({
12920
- queryFn: async (params) => {
12921
- return await sdk.admin.salesChannel.list(params);
12922
- },
12923
- queryKey: ["sales-channels"],
12924
- getOptions: (data) => {
12925
- return data.sales_channels.map((salesChannel) => ({
12926
- label: salesChannel.name,
12927
- value: salesChannel.id
12928
- }));
12929
- },
12930
- defaultValue: order.sales_channel_id || void 0
12931
- });
12932
- return /* @__PURE__ */ jsx(
12933
- Form$2.Field,
12934
- {
12935
- control,
12936
- name: "sales_channel_id",
12937
- render: ({ field }) => {
12938
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12940
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12941
- Combobox,
12776
+ width: "12",
12777
+ height: "12",
12778
+ fill: "white",
12779
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12780
+ }
12781
+ ) }),
12782
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12783
+ "rect",
12942
12784
  {
12943
- options: salesChannels.options,
12944
- fetchNextPage: salesChannels.fetchNextPage,
12945
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12946
- searchValue: salesChannels.searchValue,
12947
- onSearchValueChange: salesChannels.onSearchValueChange,
12948
- placeholder: "Select sales channel",
12949
- ...field
12785
+ width: "12",
12786
+ height: "12",
12787
+ fill: "white",
12788
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12950
12789
  }
12951
12790
  ) }),
12952
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
- ] });
12954
- }
12791
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
12792
+ "rect",
12793
+ {
12794
+ width: "12",
12795
+ height: "12",
12796
+ fill: "white",
12797
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12798
+ }
12799
+ ) }),
12800
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
12801
+ "rect",
12802
+ {
12803
+ width: "12",
12804
+ height: "12",
12805
+ fill: "white",
12806
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12807
+ }
12808
+ ) }),
12809
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
12810
+ "rect",
12811
+ {
12812
+ width: "12",
12813
+ height: "12",
12814
+ fill: "white",
12815
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12816
+ }
12817
+ ) })
12818
+ ] })
12819
+ ]
12955
12820
  }
12956
12821
  );
12957
12822
  };
12958
12823
  const schema$1 = objectType({
12959
- sales_channel_id: stringType().min(1)
12824
+ customer_id: stringType().min(1)
12960
12825
  });
12961
- const Email = () => {
12826
+ const ShippingAddress = () => {
12962
12827
  const { id } = useParams();
12963
12828
  const { order, isPending, isError, error } = useOrder(id, {
12964
- fields: "+email"
12829
+ fields: "+shipping_address"
12965
12830
  });
12966
12831
  if (isError) {
12967
12832
  throw error;
@@ -12969,16 +12834,26 @@ const Email = () => {
12969
12834
  const isReady = !isPending && !!order;
12970
12835
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12971
12836
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12972
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
12973
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12837
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12838
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12974
12839
  ] }),
12975
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
12840
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12976
12841
  ] });
12977
12842
  };
12978
- const EmailForm = ({ order }) => {
12843
+ const ShippingAddressForm = ({ order }) => {
12844
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12979
12845
  const form = useForm({
12980
12846
  defaultValues: {
12981
- email: order.email ?? ""
12847
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12848
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12849
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12850
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12851
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12852
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12853
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12854
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12855
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12856
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12982
12857
  },
12983
12858
  resolver: zodResolver(schema)
12984
12859
  });
@@ -12986,7 +12861,20 @@ const EmailForm = ({ order }) => {
12986
12861
  const { handleSuccess } = useRouteModal();
12987
12862
  const onSubmit = form.handleSubmit(async (data) => {
12988
12863
  await mutateAsync(
12989
- { email: data.email },
12864
+ {
12865
+ shipping_address: {
12866
+ first_name: data.first_name,
12867
+ last_name: data.last_name,
12868
+ company: data.company,
12869
+ address_1: data.address_1,
12870
+ address_2: data.address_2,
12871
+ city: data.city,
12872
+ province: data.province,
12873
+ country_code: data.country_code,
12874
+ postal_code: data.postal_code,
12875
+ phone: data.phone
12876
+ }
12877
+ },
12990
12878
  {
12991
12879
  onSuccess: () => {
12992
12880
  handleSuccess();
@@ -13003,18 +12891,132 @@ const EmailForm = ({ order }) => {
13003
12891
  className: "flex flex-1 flex-col overflow-hidden",
13004
12892
  onSubmit,
13005
12893
  children: [
13006
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
13007
- Form$2.Field,
13008
- {
13009
- control: form.control,
13010
- name: "email",
13011
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
13013
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
- ] })
13016
- }
13017
- ) }),
12894
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12895
+ /* @__PURE__ */ jsx(
12896
+ Form$2.Field,
12897
+ {
12898
+ control: form.control,
12899
+ name: "country_code",
12900
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12901
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12902
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12903
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12904
+ ] })
12905
+ }
12906
+ ),
12907
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12908
+ /* @__PURE__ */ jsx(
12909
+ Form$2.Field,
12910
+ {
12911
+ control: form.control,
12912
+ name: "first_name",
12913
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12915
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12916
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
+ ] })
12918
+ }
12919
+ ),
12920
+ /* @__PURE__ */ jsx(
12921
+ Form$2.Field,
12922
+ {
12923
+ control: form.control,
12924
+ name: "last_name",
12925
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12926
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12927
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12928
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12929
+ ] })
12930
+ }
12931
+ )
12932
+ ] }),
12933
+ /* @__PURE__ */ jsx(
12934
+ Form$2.Field,
12935
+ {
12936
+ control: form.control,
12937
+ name: "company",
12938
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12940
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
+ ] })
12943
+ }
12944
+ ),
12945
+ /* @__PURE__ */ jsx(
12946
+ Form$2.Field,
12947
+ {
12948
+ control: form.control,
12949
+ name: "address_1",
12950
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12951
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12952
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12953
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12954
+ ] })
12955
+ }
12956
+ ),
12957
+ /* @__PURE__ */ jsx(
12958
+ Form$2.Field,
12959
+ {
12960
+ control: form.control,
12961
+ name: "address_2",
12962
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12963
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12964
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12965
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12966
+ ] })
12967
+ }
12968
+ ),
12969
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12970
+ /* @__PURE__ */ jsx(
12971
+ Form$2.Field,
12972
+ {
12973
+ control: form.control,
12974
+ name: "postal_code",
12975
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12977
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
+ ] })
12980
+ }
12981
+ ),
12982
+ /* @__PURE__ */ jsx(
12983
+ Form$2.Field,
12984
+ {
12985
+ control: form.control,
12986
+ name: "city",
12987
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12988
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12989
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12990
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12991
+ ] })
12992
+ }
12993
+ )
12994
+ ] }),
12995
+ /* @__PURE__ */ jsx(
12996
+ Form$2.Field,
12997
+ {
12998
+ control: form.control,
12999
+ name: "province",
13000
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13002
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
+ ] })
13005
+ }
13006
+ ),
13007
+ /* @__PURE__ */ jsx(
13008
+ Form$2.Field,
13009
+ {
13010
+ control: form.control,
13011
+ name: "phone",
13012
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13013
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13014
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13015
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13016
+ ] })
13017
+ }
13018
+ )
13019
+ ] }) }),
13018
13020
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13019
13021
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13020
13022
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13023,9 +13025,7 @@ const EmailForm = ({ order }) => {
13023
13025
  }
13024
13026
  ) });
13025
13027
  };
13026
- const schema = objectType({
13027
- email: stringType().email()
13028
- });
13028
+ const schema = addressSchema;
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
13031
13031
  routes: [
@@ -13055,36 +13055,36 @@ const routeModule = {
13055
13055
  path: "/draft-orders/:id/custom-items"
13056
13056
  },
13057
13057
  {
13058
- Component: Metadata,
13059
- path: "/draft-orders/:id/metadata"
13058
+ Component: Email,
13059
+ path: "/draft-orders/:id/email"
13060
13060
  },
13061
13061
  {
13062
13062
  Component: Items,
13063
13063
  path: "/draft-orders/:id/items"
13064
13064
  },
13065
+ {
13066
+ Component: Metadata,
13067
+ path: "/draft-orders/:id/metadata"
13068
+ },
13065
13069
  {
13066
13070
  Component: Promotions,
13067
13071
  path: "/draft-orders/:id/promotions"
13068
13072
  },
13069
13073
  {
13070
- Component: Shipping,
13071
- path: "/draft-orders/:id/shipping"
13074
+ Component: SalesChannel,
13075
+ path: "/draft-orders/:id/sales-channel"
13072
13076
  },
13073
13077
  {
13074
- Component: ShippingAddress,
13075
- path: "/draft-orders/:id/shipping-address"
13078
+ Component: Shipping,
13079
+ path: "/draft-orders/:id/shipping"
13076
13080
  },
13077
13081
  {
13078
13082
  Component: TransferOwnership,
13079
13083
  path: "/draft-orders/:id/transfer-ownership"
13080
13084
  },
13081
13085
  {
13082
- Component: SalesChannel,
13083
- path: "/draft-orders/:id/sales-channel"
13084
- },
13085
- {
13086
- Component: Email,
13087
- path: "/draft-orders/:id/email"
13086
+ Component: ShippingAddress,
13087
+ path: "/draft-orders/:id/shipping-address"
13088
13088
  }
13089
13089
  ]
13090
13090
  }