@medusajs/draft-order 2.11.4-preview-20251108060129 → 2.11.4-preview-20251108120149

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.
@@ -9751,6 +9751,74 @@ const BillingAddressForm = ({ order }) => {
9751
9751
  ) });
9752
9752
  };
9753
9753
  const schema$5 = addressSchema;
9754
+ const Email = () => {
9755
+ const { id } = useParams();
9756
+ const { order, isPending, isError, error } = useOrder(id, {
9757
+ fields: "+email"
9758
+ });
9759
+ if (isError) {
9760
+ throw error;
9761
+ }
9762
+ const isReady = !isPending && !!order;
9763
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9764
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9765
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9766
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9767
+ ] }),
9768
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9769
+ ] });
9770
+ };
9771
+ const EmailForm = ({ order }) => {
9772
+ const form = useForm({
9773
+ defaultValues: {
9774
+ email: order.email ?? ""
9775
+ },
9776
+ resolver: zodResolver(schema$4)
9777
+ });
9778
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9779
+ const { handleSuccess } = useRouteModal();
9780
+ const onSubmit = form.handleSubmit(async (data) => {
9781
+ await mutateAsync(
9782
+ { email: data.email },
9783
+ {
9784
+ onSuccess: () => {
9785
+ handleSuccess();
9786
+ },
9787
+ onError: (error) => {
9788
+ toast.error(error.message);
9789
+ }
9790
+ }
9791
+ );
9792
+ });
9793
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9794
+ KeyboundForm,
9795
+ {
9796
+ className: "flex flex-1 flex-col overflow-hidden",
9797
+ onSubmit,
9798
+ children: [
9799
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9800
+ Form$2.Field,
9801
+ {
9802
+ control: form.control,
9803
+ name: "email",
9804
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9805
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9806
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9807
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9808
+ ] })
9809
+ }
9810
+ ) }),
9811
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9812
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9813
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9814
+ ] }) })
9815
+ ]
9816
+ }
9817
+ ) });
9818
+ };
9819
+ const schema$4 = objectType({
9820
+ email: stringType().email()
9821
+ });
9754
9822
  const CustomItems = () => {
9755
9823
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9756
9824
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9759,7 +9827,7 @@ const CustomItems = () => {
9759
9827
  };
9760
9828
  const CustomItemsForm = () => {
9761
9829
  const form = useForm({
9762
- resolver: zodResolver(schema$4)
9830
+ resolver: zodResolver(schema$3)
9763
9831
  });
9764
9832
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9765
9833
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9769,7 +9837,7 @@ const CustomItemsForm = () => {
9769
9837
  ] }) })
9770
9838
  ] }) });
9771
9839
  };
9772
- const schema$4 = objectType({
9840
+ const schema$3 = objectType({
9773
9841
  email: stringType().email()
9774
9842
  });
9775
9843
  const NumberInput = forwardRef(
@@ -10746,74 +10814,283 @@ const customItemSchema = objectType({
10746
10814
  quantity: numberType(),
10747
10815
  unit_price: unionType([numberType(), stringType()])
10748
10816
  });
10749
- const Email = () => {
10750
- const { id } = useParams();
10751
- const { order, isPending, isError, error } = useOrder(id, {
10752
- fields: "+email"
10817
+ const PROMOTION_QUERY_KEY = "promotions";
10818
+ const promotionsQueryKeys = {
10819
+ list: (query2) => [
10820
+ PROMOTION_QUERY_KEY,
10821
+ query2 ? query2 : void 0
10822
+ ],
10823
+ detail: (id, query2) => [
10824
+ PROMOTION_QUERY_KEY,
10825
+ id,
10826
+ query2 ? query2 : void 0
10827
+ ]
10828
+ };
10829
+ const usePromotions = (query2, options) => {
10830
+ const { data, ...rest } = useQuery({
10831
+ queryKey: promotionsQueryKeys.list(query2),
10832
+ queryFn: async () => sdk.admin.promotion.list(query2),
10833
+ ...options
10753
10834
  });
10754
- if (isError) {
10755
- throw error;
10835
+ return { ...data, ...rest };
10836
+ };
10837
+ const Promotions = () => {
10838
+ const { id } = useParams();
10839
+ const {
10840
+ order: preview,
10841
+ isError: isPreviewError,
10842
+ error: previewError
10843
+ } = useOrderPreview(id, void 0);
10844
+ useInitiateOrderEdit({ preview });
10845
+ const { onCancel } = useCancelOrderEdit({ preview });
10846
+ if (isPreviewError) {
10847
+ throw previewError;
10756
10848
  }
10757
- const isReady = !isPending && !!order;
10758
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10759
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10760
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
10761
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10762
- ] }),
10763
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
10849
+ const isReady = !!preview;
10850
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10851
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10852
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10764
10853
  ] });
10765
10854
  };
10766
- const EmailForm = ({ order }) => {
10767
- const form = useForm({
10768
- defaultValues: {
10769
- email: order.email ?? ""
10855
+ const PromotionForm = ({ preview }) => {
10856
+ const { items, shipping_methods } = preview;
10857
+ const [isSubmitting, setIsSubmitting] = useState(false);
10858
+ const [comboboxValue, setComboboxValue] = useState("");
10859
+ const { handleSuccess } = useRouteModal();
10860
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10861
+ const promoIds = getPromotionIds(items, shipping_methods);
10862
+ const { promotions, isPending, isError, error } = usePromotions(
10863
+ {
10864
+ id: promoIds
10770
10865
  },
10771
- resolver: zodResolver(schema$3)
10866
+ {
10867
+ enabled: !!promoIds.length
10868
+ }
10869
+ );
10870
+ const comboboxData = useComboboxData({
10871
+ queryKey: ["promotions", "combobox", promoIds],
10872
+ queryFn: async (params) => {
10873
+ return await sdk.admin.promotion.list({
10874
+ ...params,
10875
+ id: {
10876
+ $nin: promoIds
10877
+ }
10878
+ });
10879
+ },
10880
+ getOptions: (data) => {
10881
+ return data.promotions.map((promotion) => ({
10882
+ label: promotion.code,
10883
+ value: promotion.code
10884
+ }));
10885
+ }
10772
10886
  });
10773
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10774
- const { handleSuccess } = useRouteModal();
10775
- const onSubmit = form.handleSubmit(async (data) => {
10776
- await mutateAsync(
10777
- { email: data.email },
10887
+ const add = async (value) => {
10888
+ if (!value) {
10889
+ return;
10890
+ }
10891
+ addPromotions(
10778
10892
  {
10779
- onSuccess: () => {
10780
- handleSuccess();
10893
+ promo_codes: [value]
10894
+ },
10895
+ {
10896
+ onError: (e) => {
10897
+ toast.error(e.message);
10898
+ comboboxData.onSearchValueChange("");
10899
+ setComboboxValue("");
10781
10900
  },
10782
- onError: (error) => {
10783
- toast.error(error.message);
10901
+ onSuccess: () => {
10902
+ comboboxData.onSearchValueChange("");
10903
+ setComboboxValue("");
10784
10904
  }
10785
10905
  }
10786
10906
  );
10787
- });
10788
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10789
- KeyboundForm,
10790
- {
10791
- className: "flex flex-1 flex-col overflow-hidden",
10792
- onSubmit,
10793
- children: [
10794
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
10795
- Form$2.Field,
10907
+ };
10908
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10909
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10910
+ const onSubmit = async () => {
10911
+ setIsSubmitting(true);
10912
+ let requestSucceeded = false;
10913
+ await requestOrderEdit(void 0, {
10914
+ onError: (e) => {
10915
+ toast.error(e.message);
10916
+ },
10917
+ onSuccess: () => {
10918
+ requestSucceeded = true;
10919
+ }
10920
+ });
10921
+ if (!requestSucceeded) {
10922
+ setIsSubmitting(false);
10923
+ return;
10924
+ }
10925
+ await confirmOrderEdit(void 0, {
10926
+ onError: (e) => {
10927
+ toast.error(e.message);
10928
+ },
10929
+ onSuccess: () => {
10930
+ handleSuccess();
10931
+ },
10932
+ onSettled: () => {
10933
+ setIsSubmitting(false);
10934
+ }
10935
+ });
10936
+ };
10937
+ if (isError) {
10938
+ throw error;
10939
+ }
10940
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10941
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10942
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10943
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10944
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10945
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10946
+ ] }),
10947
+ /* @__PURE__ */ jsx(
10948
+ Combobox,
10796
10949
  {
10797
- control: form.control,
10798
- name: "email",
10799
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10800
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
10801
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10802
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10803
- ] })
10950
+ id: "promotion-combobox",
10951
+ "aria-describedby": "promotion-combobox-hint",
10952
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
10953
+ fetchNextPage: comboboxData.fetchNextPage,
10954
+ options: comboboxData.options,
10955
+ onSearchValueChange: comboboxData.onSearchValueChange,
10956
+ searchValue: comboboxData.searchValue,
10957
+ disabled: comboboxData.disabled || isAddingPromotions,
10958
+ onChange: add,
10959
+ value: comboboxValue
10804
10960
  }
10805
- ) }),
10806
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10807
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10808
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10809
- ] }) })
10810
- ]
10811
- }
10812
- ) });
10813
- };
10814
- const schema$3 = objectType({
10815
- email: stringType().email()
10961
+ )
10962
+ ] }),
10963
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10964
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10965
+ PromotionItem,
10966
+ {
10967
+ promotion,
10968
+ orderId: preview.id,
10969
+ isLoading: isPending
10970
+ },
10971
+ promotion.id
10972
+ )) })
10973
+ ] }) }),
10974
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10975
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10976
+ /* @__PURE__ */ jsx(
10977
+ Button,
10978
+ {
10979
+ size: "small",
10980
+ type: "submit",
10981
+ isLoading: isSubmitting || isAddingPromotions,
10982
+ children: "Save"
10983
+ }
10984
+ )
10985
+ ] }) })
10986
+ ] });
10987
+ };
10988
+ const PromotionItem = ({
10989
+ promotion,
10990
+ orderId,
10991
+ isLoading
10992
+ }) => {
10993
+ var _a;
10994
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10995
+ const onRemove = async () => {
10996
+ removePromotions(
10997
+ {
10998
+ promo_codes: [promotion.code]
10999
+ },
11000
+ {
11001
+ onError: (e) => {
11002
+ toast.error(e.message);
11003
+ }
11004
+ }
11005
+ );
11006
+ };
11007
+ const displayValue = getDisplayValue(promotion);
11008
+ return /* @__PURE__ */ jsxs(
11009
+ "div",
11010
+ {
11011
+ className: clx(
11012
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11013
+ {
11014
+ "animate-pulse": isLoading
11015
+ }
11016
+ ),
11017
+ children: [
11018
+ /* @__PURE__ */ jsxs("div", { children: [
11019
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11020
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11021
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11022
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11023
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11024
+ ] }),
11025
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11026
+ ] })
11027
+ ] }),
11028
+ /* @__PURE__ */ jsx(
11029
+ IconButton,
11030
+ {
11031
+ size: "small",
11032
+ type: "button",
11033
+ variant: "transparent",
11034
+ onClick: onRemove,
11035
+ isLoading: isPending || isLoading,
11036
+ children: /* @__PURE__ */ jsx(XMark, {})
11037
+ }
11038
+ )
11039
+ ]
11040
+ },
11041
+ promotion.id
11042
+ );
11043
+ };
11044
+ function getDisplayValue(promotion) {
11045
+ var _a, _b, _c, _d;
11046
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11047
+ if (!value) {
11048
+ return null;
11049
+ }
11050
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11051
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11052
+ if (!currency) {
11053
+ return null;
11054
+ }
11055
+ return getLocaleAmount(value, currency);
11056
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11057
+ return formatPercentage(value);
11058
+ }
11059
+ return null;
11060
+ }
11061
+ const formatter = new Intl.NumberFormat([], {
11062
+ style: "percent",
11063
+ minimumFractionDigits: 2
10816
11064
  });
11065
+ const formatPercentage = (value, isPercentageValue = false) => {
11066
+ let val = value || 0;
11067
+ if (!isPercentageValue) {
11068
+ val = val / 100;
11069
+ }
11070
+ return formatter.format(val);
11071
+ };
11072
+ function getPromotionIds(items, shippingMethods) {
11073
+ const promotionIds = /* @__PURE__ */ new Set();
11074
+ for (const item of items) {
11075
+ if (item.adjustments) {
11076
+ for (const adjustment of item.adjustments) {
11077
+ if (adjustment.promotion_id) {
11078
+ promotionIds.add(adjustment.promotion_id);
11079
+ }
11080
+ }
11081
+ }
11082
+ }
11083
+ for (const shippingMethod of shippingMethods) {
11084
+ if (shippingMethod.adjustments) {
11085
+ for (const adjustment of shippingMethod.adjustments) {
11086
+ if (adjustment.promotion_id) {
11087
+ promotionIds.add(adjustment.promotion_id);
11088
+ }
11089
+ }
11090
+ }
11091
+ }
11092
+ return Array.from(promotionIds);
11093
+ }
10817
11094
  const InlineTip = forwardRef(
10818
11095
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10819
11096
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11124,322 +11401,45 @@ function getDefaultValues(metadata) {
11124
11401
  function parseValues(values) {
11125
11402
  const metadata = values.metadata;
11126
11403
  const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11127
- if (isEmpty) {
11128
- return null;
11129
- }
11130
- const update = {};
11131
- metadata.forEach((field) => {
11132
- let key = field.key;
11133
- let value = field.value;
11134
- const disabled = field.disabled;
11135
- if (!key || !value) {
11136
- return;
11137
- }
11138
- if (disabled) {
11139
- update[key] = value;
11140
- return;
11141
- }
11142
- key = key.trim();
11143
- value = value.trim();
11144
- if (value === "true") {
11145
- update[key] = true;
11146
- } else if (value === "false") {
11147
- update[key] = false;
11148
- } else {
11149
- const parsedNumber = parseFloat(value);
11150
- if (!isNaN(parsedNumber)) {
11151
- update[key] = parsedNumber;
11152
- } else {
11153
- update[key] = value;
11154
- }
11155
- }
11156
- });
11157
- return update;
11158
- }
11159
- function getHasUneditableRows(metadata) {
11160
- if (!metadata) {
11161
- return false;
11162
- }
11163
- return Object.values(metadata).some(
11164
- (value) => !EDITABLE_TYPES.includes(typeof value)
11165
- );
11166
- }
11167
- const PROMOTION_QUERY_KEY = "promotions";
11168
- const promotionsQueryKeys = {
11169
- list: (query2) => [
11170
- PROMOTION_QUERY_KEY,
11171
- query2 ? query2 : void 0
11172
- ],
11173
- detail: (id, query2) => [
11174
- PROMOTION_QUERY_KEY,
11175
- id,
11176
- query2 ? query2 : void 0
11177
- ]
11178
- };
11179
- const usePromotions = (query2, options) => {
11180
- const { data, ...rest } = useQuery({
11181
- queryKey: promotionsQueryKeys.list(query2),
11182
- queryFn: async () => sdk.admin.promotion.list(query2),
11183
- ...options
11184
- });
11185
- return { ...data, ...rest };
11186
- };
11187
- const Promotions = () => {
11188
- const { id } = useParams();
11189
- const {
11190
- order: preview,
11191
- isError: isPreviewError,
11192
- error: previewError
11193
- } = useOrderPreview(id, void 0);
11194
- useInitiateOrderEdit({ preview });
11195
- const { onCancel } = useCancelOrderEdit({ preview });
11196
- if (isPreviewError) {
11197
- throw previewError;
11198
- }
11199
- const isReady = !!preview;
11200
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11201
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11202
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11203
- ] });
11204
- };
11205
- const PromotionForm = ({ preview }) => {
11206
- const { items, shipping_methods } = preview;
11207
- const [isSubmitting, setIsSubmitting] = useState(false);
11208
- const [comboboxValue, setComboboxValue] = useState("");
11209
- const { handleSuccess } = useRouteModal();
11210
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11211
- const promoIds = getPromotionIds(items, shipping_methods);
11212
- const { promotions, isPending, isError, error } = usePromotions(
11213
- {
11214
- id: promoIds
11215
- },
11216
- {
11217
- enabled: !!promoIds.length
11218
- }
11219
- );
11220
- const comboboxData = useComboboxData({
11221
- queryKey: ["promotions", "combobox", promoIds],
11222
- queryFn: async (params) => {
11223
- return await sdk.admin.promotion.list({
11224
- ...params,
11225
- id: {
11226
- $nin: promoIds
11227
- }
11228
- });
11229
- },
11230
- getOptions: (data) => {
11231
- return data.promotions.map((promotion) => ({
11232
- label: promotion.code,
11233
- value: promotion.code
11234
- }));
11235
- }
11236
- });
11237
- const add = async (value) => {
11238
- if (!value) {
11239
- return;
11240
- }
11241
- addPromotions(
11242
- {
11243
- promo_codes: [value]
11244
- },
11245
- {
11246
- onError: (e) => {
11247
- toast.error(e.message);
11248
- comboboxData.onSearchValueChange("");
11249
- setComboboxValue("");
11250
- },
11251
- onSuccess: () => {
11252
- comboboxData.onSearchValueChange("");
11253
- setComboboxValue("");
11254
- }
11255
- }
11256
- );
11257
- };
11258
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11259
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11260
- const onSubmit = async () => {
11261
- setIsSubmitting(true);
11262
- let requestSucceeded = false;
11263
- await requestOrderEdit(void 0, {
11264
- onError: (e) => {
11265
- toast.error(e.message);
11266
- },
11267
- onSuccess: () => {
11268
- requestSucceeded = true;
11269
- }
11270
- });
11271
- if (!requestSucceeded) {
11272
- setIsSubmitting(false);
11273
- return;
11274
- }
11275
- await confirmOrderEdit(void 0, {
11276
- onError: (e) => {
11277
- toast.error(e.message);
11278
- },
11279
- onSuccess: () => {
11280
- handleSuccess();
11281
- },
11282
- onSettled: () => {
11283
- setIsSubmitting(false);
11284
- }
11285
- });
11286
- };
11287
- if (isError) {
11288
- throw error;
11289
- }
11290
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11291
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11292
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11293
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11294
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11295
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11296
- ] }),
11297
- /* @__PURE__ */ jsx(
11298
- Combobox,
11299
- {
11300
- id: "promotion-combobox",
11301
- "aria-describedby": "promotion-combobox-hint",
11302
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11303
- fetchNextPage: comboboxData.fetchNextPage,
11304
- options: comboboxData.options,
11305
- onSearchValueChange: comboboxData.onSearchValueChange,
11306
- searchValue: comboboxData.searchValue,
11307
- disabled: comboboxData.disabled || isAddingPromotions,
11308
- onChange: add,
11309
- value: comboboxValue
11310
- }
11311
- )
11312
- ] }),
11313
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11314
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11315
- PromotionItem,
11316
- {
11317
- promotion,
11318
- orderId: preview.id,
11319
- isLoading: isPending
11320
- },
11321
- promotion.id
11322
- )) })
11323
- ] }) }),
11324
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11325
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11326
- /* @__PURE__ */ jsx(
11327
- Button,
11328
- {
11329
- size: "small",
11330
- type: "submit",
11331
- isLoading: isSubmitting || isAddingPromotions,
11332
- children: "Save"
11333
- }
11334
- )
11335
- ] }) })
11336
- ] });
11337
- };
11338
- const PromotionItem = ({
11339
- promotion,
11340
- orderId,
11341
- isLoading
11342
- }) => {
11343
- var _a;
11344
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11345
- const onRemove = async () => {
11346
- removePromotions(
11347
- {
11348
- promo_codes: [promotion.code]
11349
- },
11350
- {
11351
- onError: (e) => {
11352
- toast.error(e.message);
11353
- }
11354
- }
11355
- );
11356
- };
11357
- const displayValue = getDisplayValue(promotion);
11358
- return /* @__PURE__ */ jsxs(
11359
- "div",
11360
- {
11361
- className: clx(
11362
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11363
- {
11364
- "animate-pulse": isLoading
11365
- }
11366
- ),
11367
- children: [
11368
- /* @__PURE__ */ jsxs("div", { children: [
11369
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11370
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11371
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11372
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11373
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11374
- ] }),
11375
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11376
- ] })
11377
- ] }),
11378
- /* @__PURE__ */ jsx(
11379
- IconButton,
11380
- {
11381
- size: "small",
11382
- type: "button",
11383
- variant: "transparent",
11384
- onClick: onRemove,
11385
- isLoading: isPending || isLoading,
11386
- children: /* @__PURE__ */ jsx(XMark, {})
11387
- }
11388
- )
11389
- ]
11390
- },
11391
- promotion.id
11392
- );
11393
- };
11394
- function getDisplayValue(promotion) {
11395
- var _a, _b, _c, _d;
11396
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11397
- if (!value) {
11404
+ if (isEmpty) {
11398
11405
  return null;
11399
11406
  }
11400
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11401
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11402
- if (!currency) {
11403
- return null;
11407
+ const update = {};
11408
+ metadata.forEach((field) => {
11409
+ let key = field.key;
11410
+ let value = field.value;
11411
+ const disabled = field.disabled;
11412
+ if (!key || !value) {
11413
+ return;
11404
11414
  }
11405
- return getLocaleAmount(value, currency);
11406
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11407
- return formatPercentage(value);
11408
- }
11409
- return null;
11410
- }
11411
- const formatter = new Intl.NumberFormat([], {
11412
- style: "percent",
11413
- minimumFractionDigits: 2
11414
- });
11415
- const formatPercentage = (value, isPercentageValue = false) => {
11416
- let val = value || 0;
11417
- if (!isPercentageValue) {
11418
- val = val / 100;
11419
- }
11420
- return formatter.format(val);
11421
- };
11422
- function getPromotionIds(items, shippingMethods) {
11423
- const promotionIds = /* @__PURE__ */ new Set();
11424
- for (const item of items) {
11425
- if (item.adjustments) {
11426
- for (const adjustment of item.adjustments) {
11427
- if (adjustment.promotion_id) {
11428
- promotionIds.add(adjustment.promotion_id);
11429
- }
11430
- }
11415
+ if (disabled) {
11416
+ update[key] = value;
11417
+ return;
11431
11418
  }
11432
- }
11433
- for (const shippingMethod of shippingMethods) {
11434
- if (shippingMethod.adjustments) {
11435
- for (const adjustment of shippingMethod.adjustments) {
11436
- if (adjustment.promotion_id) {
11437
- promotionIds.add(adjustment.promotion_id);
11438
- }
11419
+ key = key.trim();
11420
+ value = value.trim();
11421
+ if (value === "true") {
11422
+ update[key] = true;
11423
+ } else if (value === "false") {
11424
+ update[key] = false;
11425
+ } else {
11426
+ const parsedNumber = parseFloat(value);
11427
+ if (!isNaN(parsedNumber)) {
11428
+ update[key] = parsedNumber;
11429
+ } else {
11430
+ update[key] = value;
11439
11431
  }
11440
11432
  }
11433
+ });
11434
+ return update;
11435
+ }
11436
+ function getHasUneditableRows(metadata) {
11437
+ if (!metadata) {
11438
+ return false;
11441
11439
  }
11442
- return Array.from(promotionIds);
11440
+ return Object.values(metadata).some(
11441
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11442
+ );
11443
11443
  }
11444
11444
  const SalesChannel = () => {
11445
11445
  const { id } = useParams();
@@ -12343,17 +12343,220 @@ const CustomAmountField = ({
12343
12343
  /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12344
12344
  CurrencyInput,
12345
12345
  {
12346
- ...field,
12347
- onValueChange: (value) => onChange(value),
12348
- symbol: getNativeSymbol(currencyCode),
12349
- code: currencyCode
12346
+ ...field,
12347
+ onValueChange: (value) => onChange(value),
12348
+ symbol: getNativeSymbol(currencyCode),
12349
+ code: currencyCode
12350
+ }
12351
+ ) })
12352
+ ] });
12353
+ }
12354
+ }
12355
+ );
12356
+ };
12357
+ const ShippingAddress = () => {
12358
+ const { id } = useParams();
12359
+ const { order, isPending, isError, error } = useOrder(id, {
12360
+ fields: "+shipping_address"
12361
+ });
12362
+ if (isError) {
12363
+ throw error;
12364
+ }
12365
+ const isReady = !isPending && !!order;
12366
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12367
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12368
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12369
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12370
+ ] }),
12371
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12372
+ ] });
12373
+ };
12374
+ const ShippingAddressForm = ({ order }) => {
12375
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12376
+ const form = useForm({
12377
+ defaultValues: {
12378
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12379
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12380
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12381
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12382
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12383
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12384
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12385
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12386
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12387
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12388
+ },
12389
+ resolver: zodResolver(schema$1)
12390
+ });
12391
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12392
+ const { handleSuccess } = useRouteModal();
12393
+ const onSubmit = form.handleSubmit(async (data) => {
12394
+ await mutateAsync(
12395
+ {
12396
+ shipping_address: {
12397
+ first_name: data.first_name,
12398
+ last_name: data.last_name,
12399
+ company: data.company,
12400
+ address_1: data.address_1,
12401
+ address_2: data.address_2,
12402
+ city: data.city,
12403
+ province: data.province,
12404
+ country_code: data.country_code,
12405
+ postal_code: data.postal_code,
12406
+ phone: data.phone
12407
+ }
12408
+ },
12409
+ {
12410
+ onSuccess: () => {
12411
+ handleSuccess();
12412
+ },
12413
+ onError: (error) => {
12414
+ toast.error(error.message);
12415
+ }
12416
+ }
12417
+ );
12418
+ });
12419
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12420
+ KeyboundForm,
12421
+ {
12422
+ className: "flex flex-1 flex-col overflow-hidden",
12423
+ onSubmit,
12424
+ children: [
12425
+ /* @__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: [
12426
+ /* @__PURE__ */ jsx(
12427
+ Form$2.Field,
12428
+ {
12429
+ control: form.control,
12430
+ name: "country_code",
12431
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12432
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12433
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12434
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12435
+ ] })
12436
+ }
12437
+ ),
12438
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12439
+ /* @__PURE__ */ jsx(
12440
+ Form$2.Field,
12441
+ {
12442
+ control: form.control,
12443
+ name: "first_name",
12444
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12445
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12446
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12447
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12448
+ ] })
12449
+ }
12450
+ ),
12451
+ /* @__PURE__ */ jsx(
12452
+ Form$2.Field,
12453
+ {
12454
+ control: form.control,
12455
+ name: "last_name",
12456
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12457
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12458
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12459
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12460
+ ] })
12461
+ }
12462
+ )
12463
+ ] }),
12464
+ /* @__PURE__ */ jsx(
12465
+ Form$2.Field,
12466
+ {
12467
+ control: form.control,
12468
+ name: "company",
12469
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12470
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12471
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12472
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12473
+ ] })
12474
+ }
12475
+ ),
12476
+ /* @__PURE__ */ jsx(
12477
+ Form$2.Field,
12478
+ {
12479
+ control: form.control,
12480
+ name: "address_1",
12481
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12482
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12483
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12484
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12485
+ ] })
12486
+ }
12487
+ ),
12488
+ /* @__PURE__ */ jsx(
12489
+ Form$2.Field,
12490
+ {
12491
+ control: form.control,
12492
+ name: "address_2",
12493
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12494
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12495
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12496
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12497
+ ] })
12498
+ }
12499
+ ),
12500
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12501
+ /* @__PURE__ */ jsx(
12502
+ Form$2.Field,
12503
+ {
12504
+ control: form.control,
12505
+ name: "postal_code",
12506
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12507
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12508
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12509
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12510
+ ] })
12511
+ }
12512
+ ),
12513
+ /* @__PURE__ */ jsx(
12514
+ Form$2.Field,
12515
+ {
12516
+ control: form.control,
12517
+ name: "city",
12518
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12519
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12520
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12521
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12522
+ ] })
12523
+ }
12524
+ )
12525
+ ] }),
12526
+ /* @__PURE__ */ jsx(
12527
+ Form$2.Field,
12528
+ {
12529
+ control: form.control,
12530
+ name: "province",
12531
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12532
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12533
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12534
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12535
+ ] })
12536
+ }
12537
+ ),
12538
+ /* @__PURE__ */ jsx(
12539
+ Form$2.Field,
12540
+ {
12541
+ control: form.control,
12542
+ name: "phone",
12543
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12544
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12545
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12546
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12547
+ ] })
12350
12548
  }
12351
- ) })
12352
- ] });
12353
- }
12549
+ )
12550
+ ] }) }),
12551
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12552
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12553
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12554
+ ] }) })
12555
+ ]
12354
12556
  }
12355
- );
12557
+ ) });
12356
12558
  };
12559
+ const schema$1 = addressSchema;
12357
12560
  const TransferOwnership = () => {
12358
12561
  const { id } = useParams();
12359
12562
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12377,7 +12580,7 @@ const TransferOwnershipForm = ({ order }) => {
12377
12580
  defaultValues: {
12378
12581
  customer_id: order.customer_id || ""
12379
12582
  },
12380
- resolver: zodResolver(schema$1)
12583
+ resolver: zodResolver(schema)
12381
12584
  });
12382
12585
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12383
12586
  const { handleSuccess } = useRouteModal();
@@ -12827,212 +13030,9 @@ const Illustration = () => {
12827
13030
  }
12828
13031
  );
12829
13032
  };
12830
- const schema$1 = objectType({
13033
+ const schema = objectType({
12831
13034
  customer_id: stringType().min(1)
12832
13035
  });
12833
- const ShippingAddress = () => {
12834
- const { id } = useParams();
12835
- const { order, isPending, isError, error } = useOrder(id, {
12836
- fields: "+shipping_address"
12837
- });
12838
- if (isError) {
12839
- throw error;
12840
- }
12841
- const isReady = !isPending && !!order;
12842
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12843
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12844
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12845
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12846
- ] }),
12847
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12848
- ] });
12849
- };
12850
- const ShippingAddressForm = ({ order }) => {
12851
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12852
- const form = useForm({
12853
- defaultValues: {
12854
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12855
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12856
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12857
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12858
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12859
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12860
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12861
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12862
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12863
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12864
- },
12865
- resolver: zodResolver(schema)
12866
- });
12867
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12868
- const { handleSuccess } = useRouteModal();
12869
- const onSubmit = form.handleSubmit(async (data) => {
12870
- await mutateAsync(
12871
- {
12872
- shipping_address: {
12873
- first_name: data.first_name,
12874
- last_name: data.last_name,
12875
- company: data.company,
12876
- address_1: data.address_1,
12877
- address_2: data.address_2,
12878
- city: data.city,
12879
- province: data.province,
12880
- country_code: data.country_code,
12881
- postal_code: data.postal_code,
12882
- phone: data.phone
12883
- }
12884
- },
12885
- {
12886
- onSuccess: () => {
12887
- handleSuccess();
12888
- },
12889
- onError: (error) => {
12890
- toast.error(error.message);
12891
- }
12892
- }
12893
- );
12894
- });
12895
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12896
- KeyboundForm,
12897
- {
12898
- className: "flex flex-1 flex-col overflow-hidden",
12899
- onSubmit,
12900
- children: [
12901
- /* @__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: [
12902
- /* @__PURE__ */ jsx(
12903
- Form$2.Field,
12904
- {
12905
- control: form.control,
12906
- name: "country_code",
12907
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12908
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12909
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12910
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12911
- ] })
12912
- }
12913
- ),
12914
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12915
- /* @__PURE__ */ jsx(
12916
- Form$2.Field,
12917
- {
12918
- control: form.control,
12919
- name: "first_name",
12920
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12921
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12922
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12923
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12924
- ] })
12925
- }
12926
- ),
12927
- /* @__PURE__ */ jsx(
12928
- Form$2.Field,
12929
- {
12930
- control: form.control,
12931
- name: "last_name",
12932
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12933
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12934
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12935
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12936
- ] })
12937
- }
12938
- )
12939
- ] }),
12940
- /* @__PURE__ */ jsx(
12941
- Form$2.Field,
12942
- {
12943
- control: form.control,
12944
- name: "company",
12945
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12946
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12947
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12948
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12949
- ] })
12950
- }
12951
- ),
12952
- /* @__PURE__ */ jsx(
12953
- Form$2.Field,
12954
- {
12955
- control: form.control,
12956
- name: "address_1",
12957
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12958
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12959
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12960
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12961
- ] })
12962
- }
12963
- ),
12964
- /* @__PURE__ */ jsx(
12965
- Form$2.Field,
12966
- {
12967
- control: form.control,
12968
- name: "address_2",
12969
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12970
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12971
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12972
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12973
- ] })
12974
- }
12975
- ),
12976
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12977
- /* @__PURE__ */ jsx(
12978
- Form$2.Field,
12979
- {
12980
- control: form.control,
12981
- name: "postal_code",
12982
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12983
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12984
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12985
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12986
- ] })
12987
- }
12988
- ),
12989
- /* @__PURE__ */ jsx(
12990
- Form$2.Field,
12991
- {
12992
- control: form.control,
12993
- name: "city",
12994
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12995
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12996
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12997
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12998
- ] })
12999
- }
13000
- )
13001
- ] }),
13002
- /* @__PURE__ */ jsx(
13003
- Form$2.Field,
13004
- {
13005
- control: form.control,
13006
- name: "province",
13007
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13008
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13009
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13010
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13011
- ] })
13012
- }
13013
- ),
13014
- /* @__PURE__ */ jsx(
13015
- Form$2.Field,
13016
- {
13017
- control: form.control,
13018
- name: "phone",
13019
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13020
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13021
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13022
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13023
- ] })
13024
- }
13025
- )
13026
- ] }) }),
13027
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13028
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13029
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13030
- ] }) })
13031
- ]
13032
- }
13033
- ) });
13034
- };
13035
- const schema = addressSchema;
13036
13036
  const widgetModule = { widgets: [] };
13037
13037
  const routeModule = {
13038
13038
  routes: [
@@ -13057,6 +13057,10 @@ const routeModule = {
13057
13057
  Component: BillingAddress,
13058
13058
  path: "/draft-orders/:id/billing-address"
13059
13059
  },
13060
+ {
13061
+ Component: Email,
13062
+ path: "/draft-orders/:id/email"
13063
+ },
13060
13064
  {
13061
13065
  Component: CustomItems,
13062
13066
  path: "/draft-orders/:id/custom-items"
@@ -13066,17 +13070,13 @@ const routeModule = {
13066
13070
  path: "/draft-orders/:id/items"
13067
13071
  },
13068
13072
  {
13069
- Component: Email,
13070
- path: "/draft-orders/:id/email"
13073
+ Component: Promotions,
13074
+ path: "/draft-orders/:id/promotions"
13071
13075
  },
13072
13076
  {
13073
13077
  Component: Metadata,
13074
13078
  path: "/draft-orders/:id/metadata"
13075
13079
  },
13076
- {
13077
- Component: Promotions,
13078
- path: "/draft-orders/:id/promotions"
13079
- },
13080
13080
  {
13081
13081
  Component: SalesChannel,
13082
13082
  path: "/draft-orders/:id/sales-channel"
@@ -13085,13 +13085,13 @@ const routeModule = {
13085
13085
  Component: Shipping,
13086
13086
  path: "/draft-orders/:id/shipping"
13087
13087
  },
13088
- {
13089
- Component: TransferOwnership,
13090
- path: "/draft-orders/:id/transfer-ownership"
13091
- },
13092
13088
  {
13093
13089
  Component: ShippingAddress,
13094
13090
  path: "/draft-orders/:id/shipping-address"
13091
+ },
13092
+ {
13093
+ Component: TransferOwnership,
13094
+ path: "/draft-orders/:id/transfer-ownership"
13095
13095
  }
13096
13096
  ]
13097
13097
  }