@medusajs/draft-order 2.10.4-preview-20250925031439 → 2.10.4-preview-20250925090152

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.
@@ -9757,6 +9757,27 @@ const BillingAddressForm = ({ order }) => {
9757
9757
  ) });
9758
9758
  };
9759
9759
  const schema$5 = addressSchema;
9760
+ const CustomItems = () => {
9761
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
+ ] });
9765
+ };
9766
+ const CustomItemsForm = () => {
9767
+ const form = useForm({
9768
+ resolver: zodResolver(schema$4)
9769
+ });
9770
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
+ ] }) })
9776
+ ] }) });
9777
+ };
9778
+ const schema$4 = objectType({
9779
+ email: stringType().email()
9780
+ });
9760
9781
  const Email = () => {
9761
9782
  const { id } = useParams();
9762
9783
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9779,7 +9800,7 @@ const EmailForm = ({ order }) => {
9779
9800
  defaultValues: {
9780
9801
  email: order.email ?? ""
9781
9802
  },
9782
- resolver: zodResolver(schema$4)
9803
+ resolver: zodResolver(schema$3)
9783
9804
  });
9784
9805
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9785
9806
  const { handleSuccess } = useRouteModal();
@@ -9822,7 +9843,7 @@ const EmailForm = ({ order }) => {
9822
9843
  }
9823
9844
  ) });
9824
9845
  };
9825
- const schema$4 = objectType({
9846
+ const schema$3 = objectType({
9826
9847
  email: stringType().email()
9827
9848
  });
9828
9849
  const NumberInput = forwardRef(
@@ -10799,148 +10820,425 @@ const customItemSchema = objectType({
10799
10820
  quantity: numberType(),
10800
10821
  unit_price: unionType([numberType(), stringType()])
10801
10822
  });
10802
- const InlineTip = forwardRef(
10803
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10804
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10805
- return /* @__PURE__ */ jsxs(
10806
- "div",
10807
- {
10808
- ref,
10809
- className: clx(
10810
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10811
- className
10812
- ),
10813
- ...props,
10814
- children: [
10815
- /* @__PURE__ */ jsx(
10816
- "div",
10817
- {
10818
- role: "presentation",
10819
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10820
- "bg-ui-tag-orange-icon": variant === "warning"
10821
- })
10822
- }
10823
- ),
10824
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10825
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10826
- labelValue,
10827
- ":"
10828
- ] }),
10829
- " ",
10830
- children
10831
- ] })
10832
- ]
10833
- }
10834
- );
10835
- }
10836
- );
10837
- InlineTip.displayName = "InlineTip";
10838
- const MetadataFieldSchema = objectType({
10839
- key: stringType(),
10840
- disabled: booleanType().optional(),
10841
- value: anyType()
10842
- });
10843
- const MetadataSchema = objectType({
10844
- metadata: arrayType(MetadataFieldSchema)
10845
- });
10846
- const Metadata = () => {
10847
- const { id } = useParams();
10848
- const { order, isPending, isError, error } = useOrder(id, {
10849
- fields: "metadata"
10823
+ const PROMOTION_QUERY_KEY = "promotions";
10824
+ const promotionsQueryKeys = {
10825
+ list: (query2) => [
10826
+ PROMOTION_QUERY_KEY,
10827
+ query2 ? query2 : void 0
10828
+ ],
10829
+ detail: (id, query2) => [
10830
+ PROMOTION_QUERY_KEY,
10831
+ id,
10832
+ query2 ? query2 : void 0
10833
+ ]
10834
+ };
10835
+ const usePromotions = (query2, options) => {
10836
+ const { data, ...rest } = useQuery({
10837
+ queryKey: promotionsQueryKeys.list(query2),
10838
+ queryFn: async () => sdk.admin.promotion.list(query2),
10839
+ ...options
10850
10840
  });
10851
- if (isError) {
10852
- throw error;
10841
+ return { ...data, ...rest };
10842
+ };
10843
+ const Promotions = () => {
10844
+ const { id } = useParams();
10845
+ const {
10846
+ order: preview,
10847
+ isError: isPreviewError,
10848
+ error: previewError
10849
+ } = useOrderPreview(id, void 0);
10850
+ useInitiateOrderEdit({ preview });
10851
+ const { onCancel } = useCancelOrderEdit({ preview });
10852
+ if (isPreviewError) {
10853
+ throw previewError;
10853
10854
  }
10854
- const isReady = !isPending && !!order;
10855
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10856
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10857
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10858
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10859
- ] }),
10860
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10855
+ const isReady = !!preview;
10856
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10857
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10858
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10861
10859
  ] });
10862
10860
  };
10863
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10864
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10865
- const MetadataForm = ({ orderId, metadata }) => {
10861
+ const PromotionForm = ({ preview }) => {
10862
+ const { items, shipping_methods } = preview;
10863
+ const [isSubmitting, setIsSubmitting] = useState(false);
10864
+ const [comboboxValue, setComboboxValue] = useState("");
10866
10865
  const { handleSuccess } = useRouteModal();
10867
- const hasUneditableRows = getHasUneditableRows(metadata);
10868
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10869
- const form = useForm({
10870
- defaultValues: {
10871
- metadata: getDefaultValues(metadata)
10866
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10867
+ const promoIds = getPromotionIds(items, shipping_methods);
10868
+ const { promotions, isPending, isError, error } = usePromotions(
10869
+ {
10870
+ id: promoIds
10872
10871
  },
10873
- resolver: zodResolver(MetadataSchema)
10872
+ {
10873
+ enabled: !!promoIds.length
10874
+ }
10875
+ );
10876
+ const comboboxData = useComboboxData({
10877
+ queryKey: ["promotions", "combobox", promoIds],
10878
+ queryFn: async (params) => {
10879
+ return await sdk.admin.promotion.list({
10880
+ ...params,
10881
+ id: {
10882
+ $nin: promoIds
10883
+ }
10884
+ });
10885
+ },
10886
+ getOptions: (data) => {
10887
+ return data.promotions.map((promotion) => ({
10888
+ label: promotion.code,
10889
+ value: promotion.code
10890
+ }));
10891
+ }
10874
10892
  });
10875
- const handleSubmit = form.handleSubmit(async (data) => {
10876
- const parsedData = parseValues(data);
10877
- await mutateAsync(
10893
+ const add = async (value) => {
10894
+ if (!value) {
10895
+ return;
10896
+ }
10897
+ addPromotions(
10878
10898
  {
10879
- metadata: parsedData
10899
+ promo_codes: [value]
10880
10900
  },
10881
10901
  {
10882
- onSuccess: () => {
10883
- toast.success("Metadata updated");
10884
- handleSuccess();
10902
+ onError: (e) => {
10903
+ toast.error(e.message);
10904
+ comboboxData.onSearchValueChange("");
10905
+ setComboboxValue("");
10885
10906
  },
10886
- onError: (error) => {
10887
- toast.error(error.message);
10907
+ onSuccess: () => {
10908
+ comboboxData.onSearchValueChange("");
10909
+ setComboboxValue("");
10888
10910
  }
10889
10911
  }
10890
10912
  );
10891
- });
10892
- const { fields, insert, remove } = useFieldArray({
10893
- control: form.control,
10894
- name: "metadata"
10895
- });
10896
- function deleteRow(index) {
10897
- remove(index);
10898
- if (fields.length === 1) {
10899
- insert(0, {
10900
- key: "",
10901
- value: "",
10902
- disabled: false
10903
- });
10913
+ };
10914
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10915
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10916
+ const onSubmit = async () => {
10917
+ setIsSubmitting(true);
10918
+ let requestSucceeded = false;
10919
+ await requestOrderEdit(void 0, {
10920
+ onError: (e) => {
10921
+ toast.error(e.message);
10922
+ },
10923
+ onSuccess: () => {
10924
+ requestSucceeded = true;
10925
+ }
10926
+ });
10927
+ if (!requestSucceeded) {
10928
+ setIsSubmitting(false);
10929
+ return;
10904
10930
  }
10905
- }
10906
- function insertRow(index, position) {
10907
- insert(index + (position === "above" ? 0 : 1), {
10908
- key: "",
10909
- value: "",
10910
- disabled: false
10931
+ await confirmOrderEdit(void 0, {
10932
+ onError: (e) => {
10933
+ toast.error(e.message);
10934
+ },
10935
+ onSuccess: () => {
10936
+ handleSuccess();
10937
+ },
10938
+ onSettled: () => {
10939
+ setIsSubmitting(false);
10940
+ }
10911
10941
  });
10942
+ };
10943
+ if (isError) {
10944
+ throw error;
10912
10945
  }
10913
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10914
- KeyboundForm,
10915
- {
10916
- onSubmit: handleSubmit,
10917
- className: "flex flex-1 flex-col overflow-hidden",
10918
- children: [
10919
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10920
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10921
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10922
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10923
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10924
- ] }),
10925
- fields.map((field, index) => {
10926
- const isDisabled = field.disabled || false;
10927
- let placeholder = "-";
10928
- if (typeof field.value === "object") {
10929
- placeholder = "{ ... }";
10930
- }
10931
- if (Array.isArray(field.value)) {
10932
- placeholder = "[ ... ]";
10933
- }
10934
- return /* @__PURE__ */ jsx(
10935
- ConditionalTooltip,
10936
- {
10937
- showTooltip: isDisabled,
10938
- content: "This row is disabled because it contains non-primitive data.",
10939
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10940
- /* @__PURE__ */ jsxs(
10941
- "div",
10942
- {
10943
- className: clx("grid grid-cols-2 divide-x", {
10946
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10947
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10948
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10949
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10950
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10951
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10952
+ ] }),
10953
+ /* @__PURE__ */ jsx(
10954
+ Combobox,
10955
+ {
10956
+ id: "promotion-combobox",
10957
+ "aria-describedby": "promotion-combobox-hint",
10958
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10959
+ fetchNextPage: comboboxData.fetchNextPage,
10960
+ options: comboboxData.options,
10961
+ onSearchValueChange: comboboxData.onSearchValueChange,
10962
+ searchValue: comboboxData.searchValue,
10963
+ disabled: comboboxData.disabled || isAddingPromotions,
10964
+ onChange: add,
10965
+ value: comboboxValue
10966
+ }
10967
+ )
10968
+ ] }),
10969
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10970
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10971
+ PromotionItem,
10972
+ {
10973
+ promotion,
10974
+ orderId: preview.id,
10975
+ isLoading: isPending
10976
+ },
10977
+ promotion.id
10978
+ )) })
10979
+ ] }) }),
10980
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10981
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10982
+ /* @__PURE__ */ jsx(
10983
+ Button,
10984
+ {
10985
+ size: "small",
10986
+ type: "submit",
10987
+ isLoading: isSubmitting || isAddingPromotions,
10988
+ children: "Save"
10989
+ }
10990
+ )
10991
+ ] }) })
10992
+ ] });
10993
+ };
10994
+ const PromotionItem = ({
10995
+ promotion,
10996
+ orderId,
10997
+ isLoading
10998
+ }) => {
10999
+ var _a;
11000
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11001
+ const onRemove = async () => {
11002
+ removePromotions(
11003
+ {
11004
+ promo_codes: [promotion.code]
11005
+ },
11006
+ {
11007
+ onError: (e) => {
11008
+ toast.error(e.message);
11009
+ }
11010
+ }
11011
+ );
11012
+ };
11013
+ const displayValue = getDisplayValue(promotion);
11014
+ return /* @__PURE__ */ jsxs(
11015
+ "div",
11016
+ {
11017
+ className: clx(
11018
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11019
+ {
11020
+ "animate-pulse": isLoading
11021
+ }
11022
+ ),
11023
+ children: [
11024
+ /* @__PURE__ */ jsxs("div", { children: [
11025
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11026
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11027
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11028
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11029
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11030
+ ] }),
11031
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11032
+ ] })
11033
+ ] }),
11034
+ /* @__PURE__ */ jsx(
11035
+ IconButton,
11036
+ {
11037
+ size: "small",
11038
+ type: "button",
11039
+ variant: "transparent",
11040
+ onClick: onRemove,
11041
+ isLoading: isPending || isLoading,
11042
+ children: /* @__PURE__ */ jsx(XMark, {})
11043
+ }
11044
+ )
11045
+ ]
11046
+ },
11047
+ promotion.id
11048
+ );
11049
+ };
11050
+ function getDisplayValue(promotion) {
11051
+ var _a, _b, _c, _d;
11052
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11053
+ if (!value) {
11054
+ return null;
11055
+ }
11056
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11057
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11058
+ if (!currency) {
11059
+ return null;
11060
+ }
11061
+ return getLocaleAmount(value, currency);
11062
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11063
+ return formatPercentage(value);
11064
+ }
11065
+ return null;
11066
+ }
11067
+ const formatter = new Intl.NumberFormat([], {
11068
+ style: "percent",
11069
+ minimumFractionDigits: 2
11070
+ });
11071
+ const formatPercentage = (value, isPercentageValue = false) => {
11072
+ let val = value || 0;
11073
+ if (!isPercentageValue) {
11074
+ val = val / 100;
11075
+ }
11076
+ return formatter.format(val);
11077
+ };
11078
+ function getPromotionIds(items, shippingMethods) {
11079
+ const promotionIds = /* @__PURE__ */ new Set();
11080
+ for (const item of items) {
11081
+ if (item.adjustments) {
11082
+ for (const adjustment of item.adjustments) {
11083
+ if (adjustment.promotion_id) {
11084
+ promotionIds.add(adjustment.promotion_id);
11085
+ }
11086
+ }
11087
+ }
11088
+ }
11089
+ for (const shippingMethod of shippingMethods) {
11090
+ if (shippingMethod.adjustments) {
11091
+ for (const adjustment of shippingMethod.adjustments) {
11092
+ if (adjustment.promotion_id) {
11093
+ promotionIds.add(adjustment.promotion_id);
11094
+ }
11095
+ }
11096
+ }
11097
+ }
11098
+ return Array.from(promotionIds);
11099
+ }
11100
+ const InlineTip = forwardRef(
11101
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11102
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11103
+ return /* @__PURE__ */ jsxs(
11104
+ "div",
11105
+ {
11106
+ ref,
11107
+ className: clx(
11108
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11109
+ className
11110
+ ),
11111
+ ...props,
11112
+ children: [
11113
+ /* @__PURE__ */ jsx(
11114
+ "div",
11115
+ {
11116
+ role: "presentation",
11117
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11118
+ "bg-ui-tag-orange-icon": variant === "warning"
11119
+ })
11120
+ }
11121
+ ),
11122
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
11123
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11124
+ labelValue,
11125
+ ":"
11126
+ ] }),
11127
+ " ",
11128
+ children
11129
+ ] })
11130
+ ]
11131
+ }
11132
+ );
11133
+ }
11134
+ );
11135
+ InlineTip.displayName = "InlineTip";
11136
+ const MetadataFieldSchema = objectType({
11137
+ key: stringType(),
11138
+ disabled: booleanType().optional(),
11139
+ value: anyType()
11140
+ });
11141
+ const MetadataSchema = objectType({
11142
+ metadata: arrayType(MetadataFieldSchema)
11143
+ });
11144
+ const Metadata = () => {
11145
+ const { id } = useParams();
11146
+ const { order, isPending, isError, error } = useOrder(id, {
11147
+ fields: "metadata"
11148
+ });
11149
+ if (isError) {
11150
+ throw error;
11151
+ }
11152
+ const isReady = !isPending && !!order;
11153
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11154
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11155
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
11156
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11157
+ ] }),
11158
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11159
+ ] });
11160
+ };
11161
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11162
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11163
+ const MetadataForm = ({ orderId, metadata }) => {
11164
+ const { handleSuccess } = useRouteModal();
11165
+ const hasUneditableRows = getHasUneditableRows(metadata);
11166
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11167
+ const form = useForm({
11168
+ defaultValues: {
11169
+ metadata: getDefaultValues(metadata)
11170
+ },
11171
+ resolver: zodResolver(MetadataSchema)
11172
+ });
11173
+ const handleSubmit = form.handleSubmit(async (data) => {
11174
+ const parsedData = parseValues(data);
11175
+ await mutateAsync(
11176
+ {
11177
+ metadata: parsedData
11178
+ },
11179
+ {
11180
+ onSuccess: () => {
11181
+ toast.success("Metadata updated");
11182
+ handleSuccess();
11183
+ },
11184
+ onError: (error) => {
11185
+ toast.error(error.message);
11186
+ }
11187
+ }
11188
+ );
11189
+ });
11190
+ const { fields, insert, remove } = useFieldArray({
11191
+ control: form.control,
11192
+ name: "metadata"
11193
+ });
11194
+ function deleteRow(index) {
11195
+ remove(index);
11196
+ if (fields.length === 1) {
11197
+ insert(0, {
11198
+ key: "",
11199
+ value: "",
11200
+ disabled: false
11201
+ });
11202
+ }
11203
+ }
11204
+ function insertRow(index, position) {
11205
+ insert(index + (position === "above" ? 0 : 1), {
11206
+ key: "",
11207
+ value: "",
11208
+ disabled: false
11209
+ });
11210
+ }
11211
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11212
+ KeyboundForm,
11213
+ {
11214
+ onSubmit: handleSubmit,
11215
+ className: "flex flex-1 flex-col overflow-hidden",
11216
+ children: [
11217
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11218
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11219
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11220
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
11221
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11222
+ ] }),
11223
+ fields.map((field, index) => {
11224
+ const isDisabled = field.disabled || false;
11225
+ let placeholder = "-";
11226
+ if (typeof field.value === "object") {
11227
+ placeholder = "{ ... }";
11228
+ }
11229
+ if (Array.isArray(field.value)) {
11230
+ placeholder = "[ ... ]";
11231
+ }
11232
+ return /* @__PURE__ */ jsx(
11233
+ ConditionalTooltip,
11234
+ {
11235
+ showTooltip: isDisabled,
11236
+ content: "This row is disabled because it contains non-primitive data.",
11237
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
11238
+ /* @__PURE__ */ jsxs(
11239
+ "div",
11240
+ {
11241
+ className: clx("grid grid-cols-2 divide-x", {
10944
11242
  "overflow-hidden rounded-b-lg": index === fields.length - 1
10945
11243
  }),
10946
11244
  children: [
@@ -11149,283 +11447,112 @@ function getHasUneditableRows(metadata) {
11149
11447
  (value) => !EDITABLE_TYPES.includes(typeof value)
11150
11448
  );
11151
11449
  }
11152
- const PROMOTION_QUERY_KEY = "promotions";
11153
- const promotionsQueryKeys = {
11154
- list: (query2) => [
11155
- PROMOTION_QUERY_KEY,
11156
- query2 ? query2 : void 0
11157
- ],
11158
- detail: (id, query2) => [
11159
- PROMOTION_QUERY_KEY,
11160
- id,
11161
- query2 ? query2 : void 0
11162
- ]
11163
- };
11164
- const usePromotions = (query2, options) => {
11165
- const { data, ...rest } = useQuery({
11166
- queryKey: promotionsQueryKeys.list(query2),
11167
- queryFn: async () => sdk.admin.promotion.list(query2),
11168
- ...options
11169
- });
11170
- return { ...data, ...rest };
11171
- };
11172
- const Promotions = () => {
11450
+ const SalesChannel = () => {
11173
11451
  const { id } = useParams();
11174
- const {
11175
- order: preview,
11176
- isError: isPreviewError,
11177
- error: previewError
11178
- } = useOrderPreview(id, void 0);
11179
- useInitiateOrderEdit({ preview });
11180
- const { onCancel } = useCancelOrderEdit({ preview });
11181
- if (isPreviewError) {
11182
- throw previewError;
11183
- }
11184
- const isReady = !!preview;
11185
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11186
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11187
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11188
- ] });
11189
- };
11190
- const PromotionForm = ({ preview }) => {
11191
- const { items, shipping_methods } = preview;
11192
- const [isSubmitting, setIsSubmitting] = useState(false);
11193
- const [comboboxValue, setComboboxValue] = useState("");
11194
- const { handleSuccess } = useRouteModal();
11195
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11196
- const promoIds = getPromotionIds(items, shipping_methods);
11197
- const { promotions, isPending, isError, error } = usePromotions(
11452
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11453
+ id,
11198
11454
  {
11199
- id: promoIds
11455
+ fields: "+sales_channel_id"
11200
11456
  },
11201
11457
  {
11202
- enabled: !!promoIds.length
11458
+ enabled: !!id
11203
11459
  }
11204
11460
  );
11205
- const comboboxData = useComboboxData({
11206
- queryKey: ["promotions", "combobox", promoIds],
11207
- queryFn: async (params) => {
11208
- return await sdk.admin.promotion.list({
11209
- ...params,
11210
- id: {
11211
- $nin: promoIds
11212
- }
11213
- });
11214
- },
11215
- getOptions: (data) => {
11216
- return data.promotions.map((promotion) => ({
11217
- label: promotion.code,
11218
- value: promotion.code
11219
- }));
11220
- }
11221
- });
11222
- const add = async (value) => {
11223
- if (!value) {
11224
- return;
11225
- }
11226
- addPromotions(
11227
- {
11228
- promo_codes: [value]
11229
- },
11230
- {
11231
- onError: (e) => {
11232
- toast.error(e.message);
11233
- comboboxData.onSearchValueChange("");
11234
- setComboboxValue("");
11235
- },
11236
- onSuccess: () => {
11237
- comboboxData.onSearchValueChange("");
11238
- setComboboxValue("");
11239
- }
11240
- }
11241
- );
11242
- };
11243
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11244
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11245
- const onSubmit = async () => {
11246
- setIsSubmitting(true);
11247
- let requestSucceeded = false;
11248
- await requestOrderEdit(void 0, {
11249
- onError: (e) => {
11250
- toast.error(e.message);
11251
- },
11252
- onSuccess: () => {
11253
- requestSucceeded = true;
11254
- }
11255
- });
11256
- if (!requestSucceeded) {
11257
- setIsSubmitting(false);
11258
- return;
11259
- }
11260
- await confirmOrderEdit(void 0, {
11261
- onError: (e) => {
11262
- toast.error(e.message);
11263
- },
11264
- onSuccess: () => {
11265
- handleSuccess();
11266
- },
11267
- onSettled: () => {
11268
- setIsSubmitting(false);
11269
- }
11270
- });
11271
- };
11272
11461
  if (isError) {
11273
- throw error;
11274
- }
11275
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11276
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11277
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11278
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11279
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11280
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11281
- ] }),
11282
- /* @__PURE__ */ jsx(
11283
- Combobox,
11284
- {
11285
- id: "promotion-combobox",
11286
- "aria-describedby": "promotion-combobox-hint",
11287
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11288
- fetchNextPage: comboboxData.fetchNextPage,
11289
- options: comboboxData.options,
11290
- onSearchValueChange: comboboxData.onSearchValueChange,
11291
- searchValue: comboboxData.searchValue,
11292
- disabled: comboboxData.disabled || isAddingPromotions,
11293
- onChange: add,
11294
- value: comboboxValue
11295
- }
11296
- )
11297
- ] }),
11298
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11299
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11300
- PromotionItem,
11301
- {
11302
- promotion,
11303
- orderId: preview.id,
11304
- isLoading: isPending
11305
- },
11306
- promotion.id
11307
- )) })
11308
- ] }) }),
11309
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11310
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11311
- /* @__PURE__ */ jsx(
11312
- Button,
11313
- {
11314
- size: "small",
11315
- type: "submit",
11316
- isLoading: isSubmitting || isAddingPromotions,
11317
- children: "Save"
11318
- }
11319
- )
11320
- ] }) })
11321
- ] });
11322
- };
11323
- const PromotionItem = ({
11324
- promotion,
11325
- orderId,
11326
- isLoading
11327
- }) => {
11328
- var _a;
11329
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11330
- const onRemove = async () => {
11331
- removePromotions(
11332
- {
11333
- promo_codes: [promotion.code]
11334
- },
11335
- {
11336
- onError: (e) => {
11337
- toast.error(e.message);
11338
- }
11339
- }
11340
- );
11341
- };
11342
- const displayValue = getDisplayValue(promotion);
11343
- return /* @__PURE__ */ jsxs(
11344
- "div",
11345
- {
11346
- className: clx(
11347
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11348
- {
11349
- "animate-pulse": isLoading
11350
- }
11351
- ),
11352
- children: [
11353
- /* @__PURE__ */ jsxs("div", { children: [
11354
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11355
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11356
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11357
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11358
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11359
- ] }),
11360
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11361
- ] })
11362
- ] }),
11363
- /* @__PURE__ */ jsx(
11364
- IconButton,
11365
- {
11366
- size: "small",
11367
- type: "button",
11368
- variant: "transparent",
11369
- onClick: onRemove,
11370
- isLoading: isPending || isLoading,
11371
- children: /* @__PURE__ */ jsx(XMark, {})
11372
- }
11373
- )
11374
- ]
11375
- },
11376
- promotion.id
11377
- );
11378
- };
11379
- function getDisplayValue(promotion) {
11380
- var _a, _b, _c, _d;
11381
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11382
- if (!value) {
11383
- return null;
11384
- }
11385
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11386
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11387
- if (!currency) {
11388
- return null;
11389
- }
11390
- return getLocaleAmount(value, currency);
11391
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11392
- return formatPercentage(value);
11393
- }
11394
- return null;
11395
- }
11396
- const formatter = new Intl.NumberFormat([], {
11397
- style: "percent",
11398
- minimumFractionDigits: 2
11399
- });
11400
- const formatPercentage = (value, isPercentageValue = false) => {
11401
- let val = value || 0;
11402
- if (!isPercentageValue) {
11403
- val = val / 100;
11462
+ throw error;
11404
11463
  }
11405
- return formatter.format(val);
11464
+ const ISrEADY = !!draft_order && !isPending;
11465
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11466
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11467
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11468
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11469
+ ] }),
11470
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11471
+ ] });
11406
11472
  };
11407
- function getPromotionIds(items, shippingMethods) {
11408
- const promotionIds = /* @__PURE__ */ new Set();
11409
- for (const item of items) {
11410
- if (item.adjustments) {
11411
- for (const adjustment of item.adjustments) {
11412
- if (adjustment.promotion_id) {
11413
- promotionIds.add(adjustment.promotion_id);
11473
+ const SalesChannelForm = ({ order }) => {
11474
+ const form = useForm({
11475
+ defaultValues: {
11476
+ sales_channel_id: order.sales_channel_id || ""
11477
+ },
11478
+ resolver: zodResolver(schema$2)
11479
+ });
11480
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11481
+ const { handleSuccess } = useRouteModal();
11482
+ const onSubmit = form.handleSubmit(async (data) => {
11483
+ await mutateAsync(
11484
+ {
11485
+ sales_channel_id: data.sales_channel_id
11486
+ },
11487
+ {
11488
+ onSuccess: () => {
11489
+ toast.success("Sales channel updated");
11490
+ handleSuccess();
11491
+ },
11492
+ onError: (error) => {
11493
+ toast.error(error.message);
11414
11494
  }
11415
11495
  }
11496
+ );
11497
+ });
11498
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11499
+ KeyboundForm,
11500
+ {
11501
+ className: "flex flex-1 flex-col overflow-hidden",
11502
+ onSubmit,
11503
+ children: [
11504
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11505
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11506
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11507
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
+ ] }) })
11509
+ ]
11416
11510
  }
11417
- }
11418
- for (const shippingMethod of shippingMethods) {
11419
- if (shippingMethod.adjustments) {
11420
- for (const adjustment of shippingMethod.adjustments) {
11421
- if (adjustment.promotion_id) {
11422
- promotionIds.add(adjustment.promotion_id);
11423
- }
11511
+ ) });
11512
+ };
11513
+ const SalesChannelField = ({ control, order }) => {
11514
+ const salesChannels = useComboboxData({
11515
+ queryFn: async (params) => {
11516
+ return await sdk.admin.salesChannel.list(params);
11517
+ },
11518
+ queryKey: ["sales-channels"],
11519
+ getOptions: (data) => {
11520
+ return data.sales_channels.map((salesChannel) => ({
11521
+ label: salesChannel.name,
11522
+ value: salesChannel.id
11523
+ }));
11524
+ },
11525
+ defaultValue: order.sales_channel_id || void 0
11526
+ });
11527
+ return /* @__PURE__ */ jsx(
11528
+ Form$2.Field,
11529
+ {
11530
+ control,
11531
+ name: "sales_channel_id",
11532
+ render: ({ field }) => {
11533
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11535
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11536
+ Combobox,
11537
+ {
11538
+ options: salesChannels.options,
11539
+ fetchNextPage: salesChannels.fetchNextPage,
11540
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11541
+ searchValue: salesChannels.searchValue,
11542
+ onSearchValueChange: salesChannels.onSearchValueChange,
11543
+ placeholder: "Select sales channel",
11544
+ ...field
11545
+ }
11546
+ ) }),
11547
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11548
+ ] });
11424
11549
  }
11425
11550
  }
11426
- }
11427
- return Array.from(promotionIds);
11428
- }
11551
+ );
11552
+ };
11553
+ const schema$2 = objectType({
11554
+ sales_channel_id: stringType().min(1)
11555
+ });
11429
11556
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11430
11557
  const Shipping = () => {
11431
11558
  var _a;
@@ -12256,7 +12383,7 @@ const TransferOwnershipForm = ({ order }) => {
12256
12383
  defaultValues: {
12257
12384
  customer_id: order.customer_id || ""
12258
12385
  },
12259
- resolver: zodResolver(schema$3)
12386
+ resolver: zodResolver(schema$1)
12260
12387
  });
12261
12388
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12262
12389
  const { handleSuccess } = useRouteModal();
@@ -12706,115 +12833,9 @@ const Illustration = () => {
12706
12833
  }
12707
12834
  );
12708
12835
  };
12709
- const schema$3 = objectType({
12836
+ const schema$1 = objectType({
12710
12837
  customer_id: stringType().min(1)
12711
12838
  });
12712
- const SalesChannel = () => {
12713
- const { id } = useParams();
12714
- const { draft_order, isPending, isError, error } = useDraftOrder(
12715
- id,
12716
- {
12717
- fields: "+sales_channel_id"
12718
- },
12719
- {
12720
- enabled: !!id
12721
- }
12722
- );
12723
- if (isError) {
12724
- throw error;
12725
- }
12726
- const ISrEADY = !!draft_order && !isPending;
12727
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12728
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12729
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
12730
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
12731
- ] }),
12732
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
12733
- ] });
12734
- };
12735
- const SalesChannelForm = ({ order }) => {
12736
- const form = useForm({
12737
- defaultValues: {
12738
- sales_channel_id: order.sales_channel_id || ""
12739
- },
12740
- resolver: zodResolver(schema$2)
12741
- });
12742
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12743
- const { handleSuccess } = useRouteModal();
12744
- const onSubmit = form.handleSubmit(async (data) => {
12745
- await mutateAsync(
12746
- {
12747
- sales_channel_id: data.sales_channel_id
12748
- },
12749
- {
12750
- onSuccess: () => {
12751
- toast.success("Sales channel updated");
12752
- handleSuccess();
12753
- },
12754
- onError: (error) => {
12755
- toast.error(error.message);
12756
- }
12757
- }
12758
- );
12759
- });
12760
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12761
- KeyboundForm,
12762
- {
12763
- className: "flex flex-1 flex-col overflow-hidden",
12764
- onSubmit,
12765
- children: [
12766
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
12767
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12768
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12769
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12770
- ] }) })
12771
- ]
12772
- }
12773
- ) });
12774
- };
12775
- const SalesChannelField = ({ control, order }) => {
12776
- const salesChannels = useComboboxData({
12777
- queryFn: async (params) => {
12778
- return await sdk.admin.salesChannel.list(params);
12779
- },
12780
- queryKey: ["sales-channels"],
12781
- getOptions: (data) => {
12782
- return data.sales_channels.map((salesChannel) => ({
12783
- label: salesChannel.name,
12784
- value: salesChannel.id
12785
- }));
12786
- },
12787
- defaultValue: order.sales_channel_id || void 0
12788
- });
12789
- return /* @__PURE__ */ jsx(
12790
- Form$2.Field,
12791
- {
12792
- control,
12793
- name: "sales_channel_id",
12794
- render: ({ field }) => {
12795
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12796
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
12797
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12798
- Combobox,
12799
- {
12800
- options: salesChannels.options,
12801
- fetchNextPage: salesChannels.fetchNextPage,
12802
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12803
- searchValue: salesChannels.searchValue,
12804
- onSearchValueChange: salesChannels.onSearchValueChange,
12805
- placeholder: "Select sales channel",
12806
- ...field
12807
- }
12808
- ) }),
12809
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12810
- ] });
12811
- }
12812
- }
12813
- );
12814
- };
12815
- const schema$2 = objectType({
12816
- sales_channel_id: stringType().min(1)
12817
- });
12818
12839
  const ShippingAddress = () => {
12819
12840
  const { id } = useParams();
12820
12841
  const { order, isPending, isError, error } = useOrder(id, {
@@ -12847,7 +12868,7 @@ const ShippingAddressForm = ({ order }) => {
12847
12868
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12848
12869
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12849
12870
  },
12850
- resolver: zodResolver(schema$1)
12871
+ resolver: zodResolver(schema)
12851
12872
  });
12852
12873
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12853
12874
  const { handleSuccess } = useRouteModal();
@@ -13017,28 +13038,7 @@ const ShippingAddressForm = ({ order }) => {
13017
13038
  }
13018
13039
  ) });
13019
13040
  };
13020
- const schema$1 = addressSchema;
13021
- const CustomItems = () => {
13022
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
13023
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
13024
- /* @__PURE__ */ jsx(CustomItemsForm, {})
13025
- ] });
13026
- };
13027
- const CustomItemsForm = () => {
13028
- const form = useForm({
13029
- resolver: zodResolver(schema)
13030
- });
13031
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13032
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
13033
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
13036
- ] }) })
13037
- ] }) });
13038
- };
13039
- const schema = objectType({
13040
- email: stringType().email()
13041
- });
13041
+ const schema = addressSchema;
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13063,6 +13063,10 @@ const routeModule = {
13063
13063
  Component: BillingAddress,
13064
13064
  path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
+ {
13067
+ Component: CustomItems,
13068
+ path: "/draft-orders/:id/custom-items"
13069
+ },
13066
13070
  {
13067
13071
  Component: Email,
13068
13072
  path: "/draft-orders/:id/email"
@@ -13071,13 +13075,17 @@ const routeModule = {
13071
13075
  Component: Items,
13072
13076
  path: "/draft-orders/:id/items"
13073
13077
  },
13078
+ {
13079
+ Component: Promotions,
13080
+ path: "/draft-orders/:id/promotions"
13081
+ },
13074
13082
  {
13075
13083
  Component: Metadata,
13076
13084
  path: "/draft-orders/:id/metadata"
13077
13085
  },
13078
13086
  {
13079
- Component: Promotions,
13080
- path: "/draft-orders/:id/promotions"
13087
+ Component: SalesChannel,
13088
+ path: "/draft-orders/:id/sales-channel"
13081
13089
  },
13082
13090
  {
13083
13091
  Component: Shipping,
@@ -13087,17 +13095,9 @@ const routeModule = {
13087
13095
  Component: TransferOwnership,
13088
13096
  path: "/draft-orders/:id/transfer-ownership"
13089
13097
  },
13090
- {
13091
- Component: SalesChannel,
13092
- path: "/draft-orders/:id/sales-channel"
13093
- },
13094
13098
  {
13095
13099
  Component: ShippingAddress,
13096
13100
  path: "/draft-orders/:id/shipping-address"
13097
- },
13098
- {
13099
- Component: CustomItems,
13100
- path: "/draft-orders/:id/custom-items"
13101
13101
  }
13102
13102
  ]
13103
13103
  }