@medusajs/draft-order 2.11.2 → 2.11.3-preview-20251031150158

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.
@@ -9660,196 +9660,6 @@ const EmailForm = ({ order }) => {
9660
9660
  const schema$4 = objectType({
9661
9661
  email: stringType().email()
9662
9662
  });
9663
- const BillingAddress = () => {
9664
- const { id } = reactRouterDom.useParams();
9665
- const { order, isPending, isError, error } = useOrder(id, {
9666
- fields: "+billing_address"
9667
- });
9668
- if (isError) {
9669
- throw error;
9670
- }
9671
- const isReady = !isPending && !!order;
9672
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9673
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9674
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9675
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9676
- ] }),
9677
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9678
- ] });
9679
- };
9680
- const BillingAddressForm = ({ order }) => {
9681
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9682
- const form = reactHookForm.useForm({
9683
- defaultValues: {
9684
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9685
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9686
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9687
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9688
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9689
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9690
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9691
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9692
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9693
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9694
- },
9695
- resolver: zod.zodResolver(schema$3)
9696
- });
9697
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9698
- const { handleSuccess } = useRouteModal();
9699
- const onSubmit = form.handleSubmit(async (data) => {
9700
- await mutateAsync(
9701
- { billing_address: data },
9702
- {
9703
- onSuccess: () => {
9704
- handleSuccess();
9705
- },
9706
- onError: (error) => {
9707
- ui.toast.error(error.message);
9708
- }
9709
- }
9710
- );
9711
- });
9712
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9713
- KeyboundForm,
9714
- {
9715
- className: "flex flex-1 flex-col overflow-hidden",
9716
- onSubmit,
9717
- children: [
9718
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9719
- /* @__PURE__ */ jsxRuntime.jsx(
9720
- Form$2.Field,
9721
- {
9722
- control: form.control,
9723
- name: "country_code",
9724
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9727
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
- ] })
9729
- }
9730
- ),
9731
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9732
- /* @__PURE__ */ jsxRuntime.jsx(
9733
- Form$2.Field,
9734
- {
9735
- control: form.control,
9736
- name: "first_name",
9737
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
- ] })
9742
- }
9743
- ),
9744
- /* @__PURE__ */ jsxRuntime.jsx(
9745
- Form$2.Field,
9746
- {
9747
- control: form.control,
9748
- name: "last_name",
9749
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
- ] })
9754
- }
9755
- )
9756
- ] }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(
9758
- Form$2.Field,
9759
- {
9760
- control: form.control,
9761
- name: "company",
9762
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9763
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9764
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9765
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9766
- ] })
9767
- }
9768
- ),
9769
- /* @__PURE__ */ jsxRuntime.jsx(
9770
- Form$2.Field,
9771
- {
9772
- control: form.control,
9773
- name: "address_1",
9774
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9775
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9776
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9777
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9778
- ] })
9779
- }
9780
- ),
9781
- /* @__PURE__ */ jsxRuntime.jsx(
9782
- Form$2.Field,
9783
- {
9784
- control: form.control,
9785
- name: "address_2",
9786
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9787
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9788
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9789
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9790
- ] })
9791
- }
9792
- ),
9793
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9794
- /* @__PURE__ */ jsxRuntime.jsx(
9795
- Form$2.Field,
9796
- {
9797
- control: form.control,
9798
- name: "postal_code",
9799
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9800
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9801
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9802
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9803
- ] })
9804
- }
9805
- ),
9806
- /* @__PURE__ */ jsxRuntime.jsx(
9807
- Form$2.Field,
9808
- {
9809
- control: form.control,
9810
- name: "city",
9811
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9812
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9813
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9814
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9815
- ] })
9816
- }
9817
- )
9818
- ] }),
9819
- /* @__PURE__ */ jsxRuntime.jsx(
9820
- Form$2.Field,
9821
- {
9822
- control: form.control,
9823
- name: "province",
9824
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9825
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9826
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9827
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9828
- ] })
9829
- }
9830
- ),
9831
- /* @__PURE__ */ jsxRuntime.jsx(
9832
- Form$2.Field,
9833
- {
9834
- control: form.control,
9835
- name: "phone",
9836
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9837
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9840
- ] })
9841
- }
9842
- )
9843
- ] }) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
- ] }) })
9848
- ]
9849
- }
9850
- ) });
9851
- };
9852
- const schema$3 = addressSchema;
9853
9663
  const NumberInput = React.forwardRef(
9854
9664
  ({
9855
9665
  value,
@@ -11174,35 +10984,312 @@ function getHasUneditableRows(metadata) {
11174
10984
  (value) => !EDITABLE_TYPES.includes(typeof value)
11175
10985
  );
11176
10986
  }
11177
- const SalesChannel = () => {
11178
- const { id } = reactRouterDom.useParams();
11179
- const { draft_order, isPending, isError, error } = useDraftOrder(
10987
+ const PROMOTION_QUERY_KEY = "promotions";
10988
+ const promotionsQueryKeys = {
10989
+ list: (query2) => [
10990
+ PROMOTION_QUERY_KEY,
10991
+ query2 ? query2 : void 0
10992
+ ],
10993
+ detail: (id, query2) => [
10994
+ PROMOTION_QUERY_KEY,
11180
10995
  id,
10996
+ query2 ? query2 : void 0
10997
+ ]
10998
+ };
10999
+ const usePromotions = (query2, options) => {
11000
+ const { data, ...rest } = reactQuery.useQuery({
11001
+ queryKey: promotionsQueryKeys.list(query2),
11002
+ queryFn: async () => sdk.admin.promotion.list(query2),
11003
+ ...options
11004
+ });
11005
+ return { ...data, ...rest };
11006
+ };
11007
+ const Promotions = () => {
11008
+ const { id } = reactRouterDom.useParams();
11009
+ const {
11010
+ order: preview,
11011
+ isError: isPreviewError,
11012
+ error: previewError
11013
+ } = useOrderPreview(id, void 0);
11014
+ useInitiateOrderEdit({ preview });
11015
+ const { onCancel } = useCancelOrderEdit({ preview });
11016
+ if (isPreviewError) {
11017
+ throw previewError;
11018
+ }
11019
+ const isReady = !!preview;
11020
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11021
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11022
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11023
+ ] });
11024
+ };
11025
+ const PromotionForm = ({ preview }) => {
11026
+ const { items, shipping_methods } = preview;
11027
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11028
+ const [comboboxValue, setComboboxValue] = React.useState("");
11029
+ const { handleSuccess } = useRouteModal();
11030
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11031
+ const promoIds = getPromotionIds(items, shipping_methods);
11032
+ const { promotions, isPending, isError, error } = usePromotions(
11181
11033
  {
11182
- fields: "+sales_channel_id"
11034
+ id: promoIds
11183
11035
  },
11184
11036
  {
11185
- enabled: !!id
11037
+ enabled: !!promoIds.length
11186
11038
  }
11187
11039
  );
11188
- if (isError) {
11189
- throw error;
11190
- }
11191
- const ISrEADY = !!draft_order && !isPending;
11192
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11193
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11194
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11195
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11196
- ] }),
11197
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11198
- ] });
11199
- };
11200
- const SalesChannelForm = ({ order }) => {
11201
- const form = reactHookForm.useForm({
11202
- defaultValues: {
11040
+ const comboboxData = useComboboxData({
11041
+ queryKey: ["promotions", "combobox", promoIds],
11042
+ queryFn: async (params) => {
11043
+ return await sdk.admin.promotion.list({
11044
+ ...params,
11045
+ id: {
11046
+ $nin: promoIds
11047
+ }
11048
+ });
11049
+ },
11050
+ getOptions: (data) => {
11051
+ return data.promotions.map((promotion) => ({
11052
+ label: promotion.code,
11053
+ value: promotion.code
11054
+ }));
11055
+ }
11056
+ });
11057
+ const add = async (value) => {
11058
+ if (!value) {
11059
+ return;
11060
+ }
11061
+ addPromotions(
11062
+ {
11063
+ promo_codes: [value]
11064
+ },
11065
+ {
11066
+ onError: (e) => {
11067
+ ui.toast.error(e.message);
11068
+ comboboxData.onSearchValueChange("");
11069
+ setComboboxValue("");
11070
+ },
11071
+ onSuccess: () => {
11072
+ comboboxData.onSearchValueChange("");
11073
+ setComboboxValue("");
11074
+ }
11075
+ }
11076
+ );
11077
+ };
11078
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11079
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11080
+ const onSubmit = async () => {
11081
+ setIsSubmitting(true);
11082
+ let requestSucceeded = false;
11083
+ await requestOrderEdit(void 0, {
11084
+ onError: (e) => {
11085
+ ui.toast.error(e.message);
11086
+ },
11087
+ onSuccess: () => {
11088
+ requestSucceeded = true;
11089
+ }
11090
+ });
11091
+ if (!requestSucceeded) {
11092
+ setIsSubmitting(false);
11093
+ return;
11094
+ }
11095
+ await confirmOrderEdit(void 0, {
11096
+ onError: (e) => {
11097
+ ui.toast.error(e.message);
11098
+ },
11099
+ onSuccess: () => {
11100
+ handleSuccess();
11101
+ },
11102
+ onSettled: () => {
11103
+ setIsSubmitting(false);
11104
+ }
11105
+ });
11106
+ };
11107
+ if (isError) {
11108
+ throw error;
11109
+ }
11110
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11111
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11112
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11113
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11114
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11115
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11116
+ ] }),
11117
+ /* @__PURE__ */ jsxRuntime.jsx(
11118
+ Combobox,
11119
+ {
11120
+ id: "promotion-combobox",
11121
+ "aria-describedby": "promotion-combobox-hint",
11122
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11123
+ fetchNextPage: comboboxData.fetchNextPage,
11124
+ options: comboboxData.options,
11125
+ onSearchValueChange: comboboxData.onSearchValueChange,
11126
+ searchValue: comboboxData.searchValue,
11127
+ disabled: comboboxData.disabled || isAddingPromotions,
11128
+ onChange: add,
11129
+ value: comboboxValue
11130
+ }
11131
+ )
11132
+ ] }),
11133
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11134
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11135
+ PromotionItem,
11136
+ {
11137
+ promotion,
11138
+ orderId: preview.id,
11139
+ isLoading: isPending
11140
+ },
11141
+ promotion.id
11142
+ )) })
11143
+ ] }) }),
11144
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11145
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11146
+ /* @__PURE__ */ jsxRuntime.jsx(
11147
+ ui.Button,
11148
+ {
11149
+ size: "small",
11150
+ type: "submit",
11151
+ isLoading: isSubmitting || isAddingPromotions,
11152
+ children: "Save"
11153
+ }
11154
+ )
11155
+ ] }) })
11156
+ ] });
11157
+ };
11158
+ const PromotionItem = ({
11159
+ promotion,
11160
+ orderId,
11161
+ isLoading
11162
+ }) => {
11163
+ var _a;
11164
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11165
+ const onRemove = async () => {
11166
+ removePromotions(
11167
+ {
11168
+ promo_codes: [promotion.code]
11169
+ },
11170
+ {
11171
+ onError: (e) => {
11172
+ ui.toast.error(e.message);
11173
+ }
11174
+ }
11175
+ );
11176
+ };
11177
+ const displayValue = getDisplayValue(promotion);
11178
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11179
+ "div",
11180
+ {
11181
+ className: ui.clx(
11182
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11183
+ {
11184
+ "animate-pulse": isLoading
11185
+ }
11186
+ ),
11187
+ children: [
11188
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11189
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11190
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11191
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11192
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11193
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11194
+ ] }),
11195
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11196
+ ] })
11197
+ ] }),
11198
+ /* @__PURE__ */ jsxRuntime.jsx(
11199
+ ui.IconButton,
11200
+ {
11201
+ size: "small",
11202
+ type: "button",
11203
+ variant: "transparent",
11204
+ onClick: onRemove,
11205
+ isLoading: isPending || isLoading,
11206
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11207
+ }
11208
+ )
11209
+ ]
11210
+ },
11211
+ promotion.id
11212
+ );
11213
+ };
11214
+ function getDisplayValue(promotion) {
11215
+ var _a, _b, _c, _d;
11216
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11217
+ if (!value) {
11218
+ return null;
11219
+ }
11220
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11221
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11222
+ if (!currency) {
11223
+ return null;
11224
+ }
11225
+ return getLocaleAmount(value, currency);
11226
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11227
+ return formatPercentage(value);
11228
+ }
11229
+ return null;
11230
+ }
11231
+ const formatter = new Intl.NumberFormat([], {
11232
+ style: "percent",
11233
+ minimumFractionDigits: 2
11234
+ });
11235
+ const formatPercentage = (value, isPercentageValue = false) => {
11236
+ let val = value || 0;
11237
+ if (!isPercentageValue) {
11238
+ val = val / 100;
11239
+ }
11240
+ return formatter.format(val);
11241
+ };
11242
+ function getPromotionIds(items, shippingMethods) {
11243
+ const promotionIds = /* @__PURE__ */ new Set();
11244
+ for (const item of items) {
11245
+ if (item.adjustments) {
11246
+ for (const adjustment of item.adjustments) {
11247
+ if (adjustment.promotion_id) {
11248
+ promotionIds.add(adjustment.promotion_id);
11249
+ }
11250
+ }
11251
+ }
11252
+ }
11253
+ for (const shippingMethod of shippingMethods) {
11254
+ if (shippingMethod.adjustments) {
11255
+ for (const adjustment of shippingMethod.adjustments) {
11256
+ if (adjustment.promotion_id) {
11257
+ promotionIds.add(adjustment.promotion_id);
11258
+ }
11259
+ }
11260
+ }
11261
+ }
11262
+ return Array.from(promotionIds);
11263
+ }
11264
+ const SalesChannel = () => {
11265
+ const { id } = reactRouterDom.useParams();
11266
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11267
+ id,
11268
+ {
11269
+ fields: "+sales_channel_id"
11270
+ },
11271
+ {
11272
+ enabled: !!id
11273
+ }
11274
+ );
11275
+ if (isError) {
11276
+ throw error;
11277
+ }
11278
+ const ISrEADY = !!draft_order && !isPending;
11279
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11280
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11281
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11282
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11283
+ ] }),
11284
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11285
+ ] });
11286
+ };
11287
+ const SalesChannelForm = ({ order }) => {
11288
+ const form = reactHookForm.useForm({
11289
+ defaultValues: {
11203
11290
  sales_channel_id: order.sales_channel_id || ""
11204
11291
  },
11205
- resolver: zod.zodResolver(schema$2)
11292
+ resolver: zod.zodResolver(schema$3)
11206
11293
  });
11207
11294
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11208
11295
  const { handleSuccess } = useRouteModal();
@@ -11277,12 +11364,215 @@ const SalesChannelField = ({ control, order }) => {
11277
11364
  }
11278
11365
  );
11279
11366
  };
11280
- const schema$2 = objectType({
11367
+ const schema$3 = objectType({
11281
11368
  sales_channel_id: stringType().min(1)
11282
11369
  });
11283
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11284
- const Shipping = () => {
11285
- var _a;
11370
+ const ShippingAddress = () => {
11371
+ const { id } = reactRouterDom.useParams();
11372
+ const { order, isPending, isError, error } = useOrder(id, {
11373
+ fields: "+shipping_address"
11374
+ });
11375
+ if (isError) {
11376
+ throw error;
11377
+ }
11378
+ const isReady = !isPending && !!order;
11379
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11380
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11381
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11382
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11383
+ ] }),
11384
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11385
+ ] });
11386
+ };
11387
+ const ShippingAddressForm = ({ order }) => {
11388
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11389
+ const form = reactHookForm.useForm({
11390
+ defaultValues: {
11391
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11392
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11393
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11394
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11395
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11396
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11397
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11398
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11399
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11400
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11401
+ },
11402
+ resolver: zod.zodResolver(schema$2)
11403
+ });
11404
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11405
+ const { handleSuccess } = useRouteModal();
11406
+ const onSubmit = form.handleSubmit(async (data) => {
11407
+ await mutateAsync(
11408
+ {
11409
+ shipping_address: {
11410
+ first_name: data.first_name,
11411
+ last_name: data.last_name,
11412
+ company: data.company,
11413
+ address_1: data.address_1,
11414
+ address_2: data.address_2,
11415
+ city: data.city,
11416
+ province: data.province,
11417
+ country_code: data.country_code,
11418
+ postal_code: data.postal_code,
11419
+ phone: data.phone
11420
+ }
11421
+ },
11422
+ {
11423
+ onSuccess: () => {
11424
+ handleSuccess();
11425
+ },
11426
+ onError: (error) => {
11427
+ ui.toast.error(error.message);
11428
+ }
11429
+ }
11430
+ );
11431
+ });
11432
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11433
+ KeyboundForm,
11434
+ {
11435
+ className: "flex flex-1 flex-col overflow-hidden",
11436
+ onSubmit,
11437
+ children: [
11438
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11439
+ /* @__PURE__ */ jsxRuntime.jsx(
11440
+ Form$2.Field,
11441
+ {
11442
+ control: form.control,
11443
+ name: "country_code",
11444
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11447
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11448
+ ] })
11449
+ }
11450
+ ),
11451
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11452
+ /* @__PURE__ */ jsxRuntime.jsx(
11453
+ Form$2.Field,
11454
+ {
11455
+ control: form.control,
11456
+ name: "first_name",
11457
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11459
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11460
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11461
+ ] })
11462
+ }
11463
+ ),
11464
+ /* @__PURE__ */ jsxRuntime.jsx(
11465
+ Form$2.Field,
11466
+ {
11467
+ control: form.control,
11468
+ name: "last_name",
11469
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11471
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11472
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11473
+ ] })
11474
+ }
11475
+ )
11476
+ ] }),
11477
+ /* @__PURE__ */ jsxRuntime.jsx(
11478
+ Form$2.Field,
11479
+ {
11480
+ control: form.control,
11481
+ name: "company",
11482
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11484
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11485
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11486
+ ] })
11487
+ }
11488
+ ),
11489
+ /* @__PURE__ */ jsxRuntime.jsx(
11490
+ Form$2.Field,
11491
+ {
11492
+ control: form.control,
11493
+ name: "address_1",
11494
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11496
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11497
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11498
+ ] })
11499
+ }
11500
+ ),
11501
+ /* @__PURE__ */ jsxRuntime.jsx(
11502
+ Form$2.Field,
11503
+ {
11504
+ control: form.control,
11505
+ name: "address_2",
11506
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11509
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11510
+ ] })
11511
+ }
11512
+ ),
11513
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11514
+ /* @__PURE__ */ jsxRuntime.jsx(
11515
+ Form$2.Field,
11516
+ {
11517
+ control: form.control,
11518
+ name: "postal_code",
11519
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11521
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11522
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11523
+ ] })
11524
+ }
11525
+ ),
11526
+ /* @__PURE__ */ jsxRuntime.jsx(
11527
+ Form$2.Field,
11528
+ {
11529
+ control: form.control,
11530
+ name: "city",
11531
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11534
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11535
+ ] })
11536
+ }
11537
+ )
11538
+ ] }),
11539
+ /* @__PURE__ */ jsxRuntime.jsx(
11540
+ Form$2.Field,
11541
+ {
11542
+ control: form.control,
11543
+ name: "province",
11544
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11546
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11547
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11548
+ ] })
11549
+ }
11550
+ ),
11551
+ /* @__PURE__ */ jsxRuntime.jsx(
11552
+ Form$2.Field,
11553
+ {
11554
+ control: form.control,
11555
+ name: "phone",
11556
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11559
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11560
+ ] })
11561
+ }
11562
+ )
11563
+ ] }) }),
11564
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11565
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11566
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11567
+ ] }) })
11568
+ ]
11569
+ }
11570
+ ) });
11571
+ };
11572
+ const schema$2 = addressSchema;
11573
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11574
+ const Shipping = () => {
11575
+ var _a;
11286
11576
  const { id } = reactRouterDom.useParams();
11287
11577
  const { order, isPending, isError, error } = useOrder(id, {
11288
11578
  fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
@@ -12087,247 +12377,44 @@ const CustomAmountField = ({
12087
12377
  }
12088
12378
  );
12089
12379
  };
12090
- const ShippingAddress = () => {
12380
+ const TransferOwnership = () => {
12091
12381
  const { id } = reactRouterDom.useParams();
12092
- const { order, isPending, isError, error } = useOrder(id, {
12093
- fields: "+shipping_address"
12382
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12383
+ fields: "id,customer_id,customer.*"
12094
12384
  });
12095
12385
  if (isError) {
12096
12386
  throw error;
12097
12387
  }
12098
- const isReady = !isPending && !!order;
12388
+ const isReady = !isPending && !!draft_order;
12099
12389
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12100
12390
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12101
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12102
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12391
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12392
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12103
12393
  ] }),
12104
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12394
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12105
12395
  ] });
12106
12396
  };
12107
- const ShippingAddressForm = ({ order }) => {
12108
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12397
+ const TransferOwnershipForm = ({ order }) => {
12398
+ var _a, _b;
12109
12399
  const form = reactHookForm.useForm({
12110
12400
  defaultValues: {
12111
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12112
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12113
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12114
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12115
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12116
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12117
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12118
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12119
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12120
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12401
+ customer_id: order.customer_id || ""
12121
12402
  },
12122
12403
  resolver: zod.zodResolver(schema$1)
12123
12404
  });
12124
12405
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12125
12406
  const { handleSuccess } = useRouteModal();
12407
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12408
+ const currentCustomer = order.customer ? {
12409
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12410
+ value: order.customer.id
12411
+ } : null;
12126
12412
  const onSubmit = form.handleSubmit(async (data) => {
12127
12413
  await mutateAsync(
12128
- {
12129
- shipping_address: {
12130
- first_name: data.first_name,
12131
- last_name: data.last_name,
12132
- company: data.company,
12133
- address_1: data.address_1,
12134
- address_2: data.address_2,
12135
- city: data.city,
12136
- province: data.province,
12137
- country_code: data.country_code,
12138
- postal_code: data.postal_code,
12139
- phone: data.phone
12140
- }
12141
- },
12414
+ { customer_id: data.customer_id },
12142
12415
  {
12143
12416
  onSuccess: () => {
12144
- handleSuccess();
12145
- },
12146
- onError: (error) => {
12147
- ui.toast.error(error.message);
12148
- }
12149
- }
12150
- );
12151
- });
12152
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12153
- KeyboundForm,
12154
- {
12155
- className: "flex flex-1 flex-col overflow-hidden",
12156
- onSubmit,
12157
- children: [
12158
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12159
- /* @__PURE__ */ jsxRuntime.jsx(
12160
- Form$2.Field,
12161
- {
12162
- control: form.control,
12163
- name: "country_code",
12164
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12165
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12166
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12167
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12168
- ] })
12169
- }
12170
- ),
12171
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12172
- /* @__PURE__ */ jsxRuntime.jsx(
12173
- Form$2.Field,
12174
- {
12175
- control: form.control,
12176
- name: "first_name",
12177
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12178
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12179
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12180
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12181
- ] })
12182
- }
12183
- ),
12184
- /* @__PURE__ */ jsxRuntime.jsx(
12185
- Form$2.Field,
12186
- {
12187
- control: form.control,
12188
- name: "last_name",
12189
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12190
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12191
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12192
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12193
- ] })
12194
- }
12195
- )
12196
- ] }),
12197
- /* @__PURE__ */ jsxRuntime.jsx(
12198
- Form$2.Field,
12199
- {
12200
- control: form.control,
12201
- name: "company",
12202
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12203
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12204
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12205
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12206
- ] })
12207
- }
12208
- ),
12209
- /* @__PURE__ */ jsxRuntime.jsx(
12210
- Form$2.Field,
12211
- {
12212
- control: form.control,
12213
- name: "address_1",
12214
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12215
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12216
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12217
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12218
- ] })
12219
- }
12220
- ),
12221
- /* @__PURE__ */ jsxRuntime.jsx(
12222
- Form$2.Field,
12223
- {
12224
- control: form.control,
12225
- name: "address_2",
12226
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12227
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12228
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12229
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12230
- ] })
12231
- }
12232
- ),
12233
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12234
- /* @__PURE__ */ jsxRuntime.jsx(
12235
- Form$2.Field,
12236
- {
12237
- control: form.control,
12238
- name: "postal_code",
12239
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12240
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12241
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12242
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12243
- ] })
12244
- }
12245
- ),
12246
- /* @__PURE__ */ jsxRuntime.jsx(
12247
- Form$2.Field,
12248
- {
12249
- control: form.control,
12250
- name: "city",
12251
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12252
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12253
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12254
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12255
- ] })
12256
- }
12257
- )
12258
- ] }),
12259
- /* @__PURE__ */ jsxRuntime.jsx(
12260
- Form$2.Field,
12261
- {
12262
- control: form.control,
12263
- name: "province",
12264
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12265
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12266
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12268
- ] })
12269
- }
12270
- ),
12271
- /* @__PURE__ */ jsxRuntime.jsx(
12272
- Form$2.Field,
12273
- {
12274
- control: form.control,
12275
- name: "phone",
12276
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12277
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12278
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12280
- ] })
12281
- }
12282
- )
12283
- ] }) }),
12284
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12285
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12286
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12287
- ] }) })
12288
- ]
12289
- }
12290
- ) });
12291
- };
12292
- const schema$1 = addressSchema;
12293
- const TransferOwnership = () => {
12294
- const { id } = reactRouterDom.useParams();
12295
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12296
- fields: "id,customer_id,customer.*"
12297
- });
12298
- if (isError) {
12299
- throw error;
12300
- }
12301
- const isReady = !isPending && !!draft_order;
12302
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12303
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12304
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12305
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12306
- ] }),
12307
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12308
- ] });
12309
- };
12310
- const TransferOwnershipForm = ({ order }) => {
12311
- var _a, _b;
12312
- const form = reactHookForm.useForm({
12313
- defaultValues: {
12314
- customer_id: order.customer_id || ""
12315
- },
12316
- resolver: zod.zodResolver(schema)
12317
- });
12318
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12319
- const { handleSuccess } = useRouteModal();
12320
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12321
- const currentCustomer = order.customer ? {
12322
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12323
- value: order.customer.id
12324
- } : null;
12325
- const onSubmit = form.handleSubmit(async (data) => {
12326
- await mutateAsync(
12327
- { customer_id: data.customer_id },
12328
- {
12329
- onSuccess: () => {
12330
- ui.toast.success("Customer updated");
12417
+ ui.toast.success("Customer updated");
12331
12418
  handleSuccess();
12332
12419
  },
12333
12420
  onError: (error) => {
@@ -12763,286 +12850,199 @@ const Illustration = () => {
12763
12850
  }
12764
12851
  );
12765
12852
  };
12766
- const schema = objectType({
12853
+ const schema$1 = objectType({
12767
12854
  customer_id: stringType().min(1)
12768
12855
  });
12769
- const PROMOTION_QUERY_KEY = "promotions";
12770
- const promotionsQueryKeys = {
12771
- list: (query2) => [
12772
- PROMOTION_QUERY_KEY,
12773
- query2 ? query2 : void 0
12774
- ],
12775
- detail: (id, query2) => [
12776
- PROMOTION_QUERY_KEY,
12777
- id,
12778
- query2 ? query2 : void 0
12779
- ]
12780
- };
12781
- const usePromotions = (query2, options) => {
12782
- const { data, ...rest } = reactQuery.useQuery({
12783
- queryKey: promotionsQueryKeys.list(query2),
12784
- queryFn: async () => sdk.admin.promotion.list(query2),
12785
- ...options
12786
- });
12787
- return { ...data, ...rest };
12788
- };
12789
- const Promotions = () => {
12856
+ const BillingAddress = () => {
12790
12857
  const { id } = reactRouterDom.useParams();
12791
- const {
12792
- order: preview,
12793
- isError: isPreviewError,
12794
- error: previewError
12795
- } = useOrderPreview(id, void 0);
12796
- useInitiateOrderEdit({ preview });
12797
- const { onCancel } = useCancelOrderEdit({ preview });
12798
- if (isPreviewError) {
12799
- throw previewError;
12858
+ const { order, isPending, isError, error } = useOrder(id, {
12859
+ fields: "+billing_address"
12860
+ });
12861
+ if (isError) {
12862
+ throw error;
12800
12863
  }
12801
- const isReady = !!preview;
12802
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12803
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12804
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12864
+ const isReady = !isPending && !!order;
12865
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12866
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12867
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12868
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12869
+ ] }),
12870
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12805
12871
  ] });
12806
12872
  };
12807
- const PromotionForm = ({ preview }) => {
12808
- const { items, shipping_methods } = preview;
12809
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12810
- const [comboboxValue, setComboboxValue] = React.useState("");
12811
- const { handleSuccess } = useRouteModal();
12812
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12813
- const promoIds = getPromotionIds(items, shipping_methods);
12814
- const { promotions, isPending, isError, error } = usePromotions(
12815
- {
12816
- id: promoIds
12873
+ const BillingAddressForm = ({ order }) => {
12874
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12875
+ const form = reactHookForm.useForm({
12876
+ defaultValues: {
12877
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12878
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12879
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12880
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12881
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12882
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12883
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12884
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12885
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12886
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12817
12887
  },
12818
- {
12819
- enabled: !!promoIds.length
12820
- }
12821
- );
12822
- const comboboxData = useComboboxData({
12823
- queryKey: ["promotions", "combobox", promoIds],
12824
- queryFn: async (params) => {
12825
- return await sdk.admin.promotion.list({
12826
- ...params,
12827
- id: {
12828
- $nin: promoIds
12829
- }
12830
- });
12831
- },
12832
- getOptions: (data) => {
12833
- return data.promotions.map((promotion) => ({
12834
- label: promotion.code,
12835
- value: promotion.code
12836
- }));
12837
- }
12888
+ resolver: zod.zodResolver(schema)
12838
12889
  });
12839
- const add = async (value) => {
12840
- if (!value) {
12841
- return;
12842
- }
12843
- addPromotions(
12844
- {
12845
- promo_codes: [value]
12846
- },
12890
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12891
+ const { handleSuccess } = useRouteModal();
12892
+ const onSubmit = form.handleSubmit(async (data) => {
12893
+ await mutateAsync(
12894
+ { billing_address: data },
12847
12895
  {
12848
- onError: (e) => {
12849
- ui.toast.error(e.message);
12850
- comboboxData.onSearchValueChange("");
12851
- setComboboxValue("");
12852
- },
12853
12896
  onSuccess: () => {
12854
- comboboxData.onSearchValueChange("");
12855
- setComboboxValue("");
12856
- }
12857
- }
12858
- );
12859
- };
12860
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12861
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12862
- const onSubmit = async () => {
12863
- setIsSubmitting(true);
12864
- let requestSucceeded = false;
12865
- await requestOrderEdit(void 0, {
12866
- onError: (e) => {
12867
- ui.toast.error(e.message);
12868
- },
12869
- onSuccess: () => {
12870
- requestSucceeded = true;
12871
- }
12872
- });
12873
- if (!requestSucceeded) {
12874
- setIsSubmitting(false);
12875
- return;
12876
- }
12877
- await confirmOrderEdit(void 0, {
12878
- onError: (e) => {
12879
- ui.toast.error(e.message);
12880
- },
12881
- onSuccess: () => {
12882
- handleSuccess();
12883
- },
12884
- onSettled: () => {
12885
- setIsSubmitting(false);
12886
- }
12887
- });
12888
- };
12889
- if (isError) {
12890
- throw error;
12891
- }
12892
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12893
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12894
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12895
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12896
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12897
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12898
- ] }),
12899
- /* @__PURE__ */ jsxRuntime.jsx(
12900
- Combobox,
12901
- {
12902
- id: "promotion-combobox",
12903
- "aria-describedby": "promotion-combobox-hint",
12904
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12905
- fetchNextPage: comboboxData.fetchNextPage,
12906
- options: comboboxData.options,
12907
- onSearchValueChange: comboboxData.onSearchValueChange,
12908
- searchValue: comboboxData.searchValue,
12909
- disabled: comboboxData.disabled || isAddingPromotions,
12910
- onChange: add,
12911
- value: comboboxValue
12912
- }
12913
- )
12914
- ] }),
12915
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12916
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12917
- PromotionItem,
12918
- {
12919
- promotion,
12920
- orderId: preview.id,
12921
- isLoading: isPending
12897
+ handleSuccess();
12922
12898
  },
12923
- promotion.id
12924
- )) })
12925
- ] }) }),
12926
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12927
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12928
- /* @__PURE__ */ jsxRuntime.jsx(
12929
- ui.Button,
12930
- {
12931
- size: "small",
12932
- type: "submit",
12933
- isLoading: isSubmitting || isAddingPromotions,
12934
- children: "Save"
12935
- }
12936
- )
12937
- ] }) })
12938
- ] });
12939
- };
12940
- const PromotionItem = ({
12941
- promotion,
12942
- orderId,
12943
- isLoading
12944
- }) => {
12945
- var _a;
12946
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12947
- const onRemove = async () => {
12948
- removePromotions(
12949
- {
12950
- promo_codes: [promotion.code]
12951
- },
12952
- {
12953
- onError: (e) => {
12954
- ui.toast.error(e.message);
12899
+ onError: (error) => {
12900
+ ui.toast.error(error.message);
12955
12901
  }
12956
12902
  }
12957
12903
  );
12958
- };
12959
- const displayValue = getDisplayValue(promotion);
12960
- return /* @__PURE__ */ jsxRuntime.jsxs(
12961
- "div",
12904
+ });
12905
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12906
+ KeyboundForm,
12962
12907
  {
12963
- className: ui.clx(
12964
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12965
- {
12966
- "animate-pulse": isLoading
12967
- }
12968
- ),
12908
+ className: "flex flex-1 flex-col overflow-hidden",
12909
+ onSubmit,
12969
12910
  children: [
12970
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12971
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12973
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12974
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12975
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12976
- ] }),
12977
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12978
- ] })
12979
- ] }),
12980
- /* @__PURE__ */ jsxRuntime.jsx(
12981
- ui.IconButton,
12982
- {
12983
- size: "small",
12984
- type: "button",
12985
- variant: "transparent",
12986
- onClick: onRemove,
12987
- isLoading: isPending || isLoading,
12988
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12989
- }
12990
- )
12911
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12912
+ /* @__PURE__ */ jsxRuntime.jsx(
12913
+ Form$2.Field,
12914
+ {
12915
+ control: form.control,
12916
+ name: "country_code",
12917
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12918
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12919
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12921
+ ] })
12922
+ }
12923
+ ),
12924
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12925
+ /* @__PURE__ */ jsxRuntime.jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "first_name",
12930
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12931
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12934
+ ] })
12935
+ }
12936
+ ),
12937
+ /* @__PURE__ */ jsxRuntime.jsx(
12938
+ Form$2.Field,
12939
+ {
12940
+ control: form.control,
12941
+ name: "last_name",
12942
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12943
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12944
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12946
+ ] })
12947
+ }
12948
+ )
12949
+ ] }),
12950
+ /* @__PURE__ */ jsxRuntime.jsx(
12951
+ Form$2.Field,
12952
+ {
12953
+ control: form.control,
12954
+ name: "company",
12955
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12956
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
+ ] })
12960
+ }
12961
+ ),
12962
+ /* @__PURE__ */ jsxRuntime.jsx(
12963
+ Form$2.Field,
12964
+ {
12965
+ control: form.control,
12966
+ name: "address_1",
12967
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12968
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12971
+ ] })
12972
+ }
12973
+ ),
12974
+ /* @__PURE__ */ jsxRuntime.jsx(
12975
+ Form$2.Field,
12976
+ {
12977
+ control: form.control,
12978
+ name: "address_2",
12979
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12980
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12981
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12983
+ ] })
12984
+ }
12985
+ ),
12986
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12987
+ /* @__PURE__ */ jsxRuntime.jsx(
12988
+ Form$2.Field,
12989
+ {
12990
+ control: form.control,
12991
+ name: "postal_code",
12992
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12993
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12996
+ ] })
12997
+ }
12998
+ ),
12999
+ /* @__PURE__ */ jsxRuntime.jsx(
13000
+ Form$2.Field,
13001
+ {
13002
+ control: form.control,
13003
+ name: "city",
13004
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13005
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13006
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13008
+ ] })
13009
+ }
13010
+ )
13011
+ ] }),
13012
+ /* @__PURE__ */ jsxRuntime.jsx(
13013
+ Form$2.Field,
13014
+ {
13015
+ control: form.control,
13016
+ name: "province",
13017
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
+ ] })
13022
+ }
13023
+ ),
13024
+ /* @__PURE__ */ jsxRuntime.jsx(
13025
+ Form$2.Field,
13026
+ {
13027
+ control: form.control,
13028
+ name: "phone",
13029
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
+ ] })
13034
+ }
13035
+ )
13036
+ ] }) }),
13037
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13040
+ ] }) })
12991
13041
  ]
12992
- },
12993
- promotion.id
12994
- );
12995
- };
12996
- function getDisplayValue(promotion) {
12997
- var _a, _b, _c, _d;
12998
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12999
- if (!value) {
13000
- return null;
13001
- }
13002
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
13003
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
13004
- if (!currency) {
13005
- return null;
13006
13042
  }
13007
- return getLocaleAmount(value, currency);
13008
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13009
- return formatPercentage(value);
13010
- }
13011
- return null;
13012
- }
13013
- const formatter = new Intl.NumberFormat([], {
13014
- style: "percent",
13015
- minimumFractionDigits: 2
13016
- });
13017
- const formatPercentage = (value, isPercentageValue = false) => {
13018
- let val = value || 0;
13019
- if (!isPercentageValue) {
13020
- val = val / 100;
13021
- }
13022
- return formatter.format(val);
13043
+ ) });
13023
13044
  };
13024
- function getPromotionIds(items, shippingMethods) {
13025
- const promotionIds = /* @__PURE__ */ new Set();
13026
- for (const item of items) {
13027
- if (item.adjustments) {
13028
- for (const adjustment of item.adjustments) {
13029
- if (adjustment.promotion_id) {
13030
- promotionIds.add(adjustment.promotion_id);
13031
- }
13032
- }
13033
- }
13034
- }
13035
- for (const shippingMethod of shippingMethods) {
13036
- if (shippingMethod.adjustments) {
13037
- for (const adjustment of shippingMethod.adjustments) {
13038
- if (adjustment.promotion_id) {
13039
- promotionIds.add(adjustment.promotion_id);
13040
- }
13041
- }
13042
- }
13043
- }
13044
- return Array.from(promotionIds);
13045
- }
13045
+ const schema = addressSchema;
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13071,10 +13071,6 @@ const routeModule = {
13071
13071
  Component: Email,
13072
13072
  path: "/draft-orders/:id/email"
13073
13073
  },
13074
- {
13075
- Component: BillingAddress,
13076
- path: "/draft-orders/:id/billing-address"
13077
- },
13078
13074
  {
13079
13075
  Component: Items,
13080
13076
  path: "/draft-orders/:id/items"
@@ -13084,24 +13080,28 @@ const routeModule = {
13084
13080
  path: "/draft-orders/:id/metadata"
13085
13081
  },
13086
13082
  {
13087
- Component: SalesChannel,
13088
- path: "/draft-orders/:id/sales-channel"
13083
+ Component: Promotions,
13084
+ path: "/draft-orders/:id/promotions"
13089
13085
  },
13090
13086
  {
13091
- Component: Shipping,
13092
- path: "/draft-orders/:id/shipping"
13087
+ Component: SalesChannel,
13088
+ path: "/draft-orders/:id/sales-channel"
13093
13089
  },
13094
13090
  {
13095
13091
  Component: ShippingAddress,
13096
13092
  path: "/draft-orders/:id/shipping-address"
13097
13093
  },
13094
+ {
13095
+ Component: Shipping,
13096
+ path: "/draft-orders/:id/shipping"
13097
+ },
13098
13098
  {
13099
13099
  Component: TransferOwnership,
13100
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
13101
  },
13102
13102
  {
13103
- Component: Promotions,
13104
- path: "/draft-orders/:id/promotions"
13103
+ Component: BillingAddress,
13104
+ path: "/draft-orders/:id/billing-address"
13105
13105
  }
13106
13106
  ]
13107
13107
  }