@medusajs/draft-order 2.10.2-snapshot-20250902104934 → 2.10.2-snapshot-20250902105826

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