@medusajs/draft-order 2.11.2-snapshot-20251031090242 → 2.11.2

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.
@@ -14,15 +14,14 @@ const reactHookForm = require("react-hook-form");
14
14
  const radixUi = require("radix-ui");
15
15
  const react = require("@ariakit/react");
16
16
  const matchSorter = require("match-sorter");
17
- const debounce = require("lodash.debounce");
17
+ const debounce = require("lodash/debounce");
18
18
  const Primitive = require("@uiw/react-json-view");
19
- const isEqual = require("lodash.isequal");
19
+ const lodash = require("lodash");
20
20
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
21
21
  const React__default = /* @__PURE__ */ _interopDefault(React);
22
22
  const Medusa__default = /* @__PURE__ */ _interopDefault(Medusa);
23
23
  const debounce__default = /* @__PURE__ */ _interopDefault(debounce);
24
24
  const Primitive__default = /* @__PURE__ */ _interopDefault(Primitive);
25
- const isEqual__default = /* @__PURE__ */ _interopDefault(isEqual);
26
25
  function useQueryParams(keys, prefix) {
27
26
  const [params] = reactRouterDom.useSearchParams();
28
27
  const result = {};
@@ -9593,6 +9592,74 @@ const CustomItemsForm = () => {
9593
9592
  const schema$5 = objectType({
9594
9593
  email: stringType().email()
9595
9594
  });
9595
+ const Email = () => {
9596
+ const { id } = reactRouterDom.useParams();
9597
+ const { order, isPending, isError, error } = useOrder(id, {
9598
+ fields: "+email"
9599
+ });
9600
+ if (isError) {
9601
+ throw error;
9602
+ }
9603
+ const isReady = !isPending && !!order;
9604
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9605
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9606
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9607
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9608
+ ] }),
9609
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9610
+ ] });
9611
+ };
9612
+ const EmailForm = ({ order }) => {
9613
+ const form = reactHookForm.useForm({
9614
+ defaultValues: {
9615
+ email: order.email ?? ""
9616
+ },
9617
+ resolver: zod.zodResolver(schema$4)
9618
+ });
9619
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9620
+ const { handleSuccess } = useRouteModal();
9621
+ const onSubmit = form.handleSubmit(async (data) => {
9622
+ await mutateAsync(
9623
+ { email: data.email },
9624
+ {
9625
+ onSuccess: () => {
9626
+ handleSuccess();
9627
+ },
9628
+ onError: (error) => {
9629
+ ui.toast.error(error.message);
9630
+ }
9631
+ }
9632
+ );
9633
+ });
9634
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9635
+ KeyboundForm,
9636
+ {
9637
+ className: "flex flex-1 flex-col overflow-hidden",
9638
+ onSubmit,
9639
+ children: [
9640
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9641
+ Form$2.Field,
9642
+ {
9643
+ control: form.control,
9644
+ name: "email",
9645
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9646
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9647
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9649
+ ] })
9650
+ }
9651
+ ) }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9653
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9654
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9655
+ ] }) })
9656
+ ]
9657
+ }
9658
+ ) });
9659
+ };
9660
+ const schema$4 = objectType({
9661
+ email: stringType().email()
9662
+ });
9596
9663
  const BillingAddress = () => {
9597
9664
  const { id } = reactRouterDom.useParams();
9598
9665
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9625,7 +9692,7 @@ const BillingAddressForm = ({ order }) => {
9625
9692
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9626
9693
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9627
9694
  },
9628
- resolver: zod.zodResolver(schema$4)
9695
+ resolver: zod.zodResolver(schema$3)
9629
9696
  });
9630
9697
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9631
9698
  const { handleSuccess } = useRouteModal();
@@ -9782,7 +9849,7 @@ const BillingAddressForm = ({ order }) => {
9782
9849
  }
9783
9850
  ) });
9784
9851
  };
9785
- const schema$4 = addressSchema;
9852
+ const schema$3 = addressSchema;
9786
9853
  const NumberInput = React.forwardRef(
9787
9854
  ({
9788
9855
  value,
@@ -10757,74 +10824,6 @@ const customItemSchema = objectType({
10757
10824
  quantity: numberType(),
10758
10825
  unit_price: unionType([numberType(), stringType()])
10759
10826
  });
10760
- const Email = () => {
10761
- const { id } = reactRouterDom.useParams();
10762
- const { order, isPending, isError, error } = useOrder(id, {
10763
- fields: "+email"
10764
- });
10765
- if (isError) {
10766
- throw error;
10767
- }
10768
- const isReady = !isPending && !!order;
10769
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10770
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10771
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10772
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10773
- ] }),
10774
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10775
- ] });
10776
- };
10777
- const EmailForm = ({ order }) => {
10778
- const form = reactHookForm.useForm({
10779
- defaultValues: {
10780
- email: order.email ?? ""
10781
- },
10782
- resolver: zod.zodResolver(schema$3)
10783
- });
10784
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10785
- const { handleSuccess } = useRouteModal();
10786
- const onSubmit = form.handleSubmit(async (data) => {
10787
- await mutateAsync(
10788
- { email: data.email },
10789
- {
10790
- onSuccess: () => {
10791
- handleSuccess();
10792
- },
10793
- onError: (error) => {
10794
- ui.toast.error(error.message);
10795
- }
10796
- }
10797
- );
10798
- });
10799
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10800
- KeyboundForm,
10801
- {
10802
- className: "flex flex-1 flex-col overflow-hidden",
10803
- onSubmit,
10804
- children: [
10805
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10806
- Form$2.Field,
10807
- {
10808
- control: form.control,
10809
- name: "email",
10810
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10811
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10812
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10813
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10814
- ] })
10815
- }
10816
- ) }),
10817
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10818
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10819
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10820
- ] }) })
10821
- ]
10822
- }
10823
- ) });
10824
- };
10825
- const schema$3 = objectType({
10826
- email: stringType().email()
10827
- });
10828
10827
  const InlineTip = React.forwardRef(
10829
10828
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10830
10829
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11175,327 +11174,50 @@ function getHasUneditableRows(metadata) {
11175
11174
  (value) => !EDITABLE_TYPES.includes(typeof value)
11176
11175
  );
11177
11176
  }
11178
- const PROMOTION_QUERY_KEY = "promotions";
11179
- const promotionsQueryKeys = {
11180
- list: (query2) => [
11181
- PROMOTION_QUERY_KEY,
11182
- query2 ? query2 : void 0
11183
- ],
11184
- detail: (id, query2) => [
11185
- PROMOTION_QUERY_KEY,
11186
- id,
11187
- query2 ? query2 : void 0
11188
- ]
11189
- };
11190
- const usePromotions = (query2, options) => {
11191
- const { data, ...rest } = reactQuery.useQuery({
11192
- queryKey: promotionsQueryKeys.list(query2),
11193
- queryFn: async () => sdk.admin.promotion.list(query2),
11194
- ...options
11195
- });
11196
- return { ...data, ...rest };
11197
- };
11198
- const Promotions = () => {
11177
+ const SalesChannel = () => {
11199
11178
  const { id } = reactRouterDom.useParams();
11200
- const {
11201
- order: preview,
11202
- isError: isPreviewError,
11203
- error: previewError
11204
- } = useOrderPreview(id, void 0);
11205
- useInitiateOrderEdit({ preview });
11206
- const { onCancel } = useCancelOrderEdit({ preview });
11207
- if (isPreviewError) {
11208
- throw previewError;
11209
- }
11210
- const isReady = !!preview;
11211
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11212
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11213
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11214
- ] });
11215
- };
11216
- const PromotionForm = ({ preview }) => {
11217
- const { items, shipping_methods } = preview;
11218
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11219
- const [comboboxValue, setComboboxValue] = React.useState("");
11220
- const { handleSuccess } = useRouteModal();
11221
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11222
- const promoIds = getPromotionIds(items, shipping_methods);
11223
- const { promotions, isPending, isError, error } = usePromotions(
11179
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11180
+ id,
11224
11181
  {
11225
- id: promoIds
11182
+ fields: "+sales_channel_id"
11226
11183
  },
11227
11184
  {
11228
- enabled: !!promoIds.length
11185
+ enabled: !!id
11229
11186
  }
11230
11187
  );
11231
- const comboboxData = useComboboxData({
11232
- queryKey: ["promotions", "combobox", promoIds],
11233
- queryFn: async (params) => {
11234
- return await sdk.admin.promotion.list({
11235
- ...params,
11236
- id: {
11237
- $nin: promoIds
11238
- }
11239
- });
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: {
11203
+ sales_channel_id: order.sales_channel_id || ""
11240
11204
  },
11241
- getOptions: (data) => {
11242
- return data.promotions.map((promotion) => ({
11243
- label: promotion.code,
11244
- value: promotion.code
11245
- }));
11246
- }
11205
+ resolver: zod.zodResolver(schema$2)
11247
11206
  });
11248
- const add = async (value) => {
11249
- if (!value) {
11250
- return;
11251
- }
11252
- addPromotions(
11207
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11208
+ const { handleSuccess } = useRouteModal();
11209
+ const onSubmit = form.handleSubmit(async (data) => {
11210
+ await mutateAsync(
11253
11211
  {
11254
- promo_codes: [value]
11212
+ sales_channel_id: data.sales_channel_id
11255
11213
  },
11256
11214
  {
11257
- onError: (e) => {
11258
- ui.toast.error(e.message);
11259
- comboboxData.onSearchValueChange("");
11260
- setComboboxValue("");
11261
- },
11262
11215
  onSuccess: () => {
11263
- comboboxData.onSearchValueChange("");
11264
- setComboboxValue("");
11265
- }
11266
- }
11267
- );
11268
- };
11269
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11270
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11271
- const onSubmit = async () => {
11272
- setIsSubmitting(true);
11273
- let requestSucceeded = false;
11274
- await requestOrderEdit(void 0, {
11275
- onError: (e) => {
11276
- ui.toast.error(e.message);
11277
- },
11278
- onSuccess: () => {
11279
- requestSucceeded = true;
11280
- }
11281
- });
11282
- if (!requestSucceeded) {
11283
- setIsSubmitting(false);
11284
- return;
11285
- }
11286
- await confirmOrderEdit(void 0, {
11287
- onError: (e) => {
11288
- ui.toast.error(e.message);
11289
- },
11290
- onSuccess: () => {
11291
- handleSuccess();
11292
- },
11293
- onSettled: () => {
11294
- setIsSubmitting(false);
11295
- }
11296
- });
11297
- };
11298
- if (isError) {
11299
- throw error;
11300
- }
11301
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11302
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11304
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11305
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11306
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11307
- ] }),
11308
- /* @__PURE__ */ jsxRuntime.jsx(
11309
- Combobox,
11310
- {
11311
- id: "promotion-combobox",
11312
- "aria-describedby": "promotion-combobox-hint",
11313
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11314
- fetchNextPage: comboboxData.fetchNextPage,
11315
- options: comboboxData.options,
11316
- onSearchValueChange: comboboxData.onSearchValueChange,
11317
- searchValue: comboboxData.searchValue,
11318
- disabled: comboboxData.disabled || isAddingPromotions,
11319
- onChange: add,
11320
- value: comboboxValue
11321
- }
11322
- )
11323
- ] }),
11324
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11325
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11326
- PromotionItem,
11327
- {
11328
- promotion,
11329
- orderId: preview.id,
11330
- isLoading: isPending
11331
- },
11332
- promotion.id
11333
- )) })
11334
- ] }) }),
11335
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11336
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11337
- /* @__PURE__ */ jsxRuntime.jsx(
11338
- ui.Button,
11339
- {
11340
- size: "small",
11341
- type: "submit",
11342
- isLoading: isSubmitting || isAddingPromotions,
11343
- children: "Save"
11344
- }
11345
- )
11346
- ] }) })
11347
- ] });
11348
- };
11349
- const PromotionItem = ({
11350
- promotion,
11351
- orderId,
11352
- isLoading
11353
- }) => {
11354
- var _a;
11355
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11356
- const onRemove = async () => {
11357
- removePromotions(
11358
- {
11359
- promo_codes: [promotion.code]
11360
- },
11361
- {
11362
- onError: (e) => {
11363
- ui.toast.error(e.message);
11364
- }
11365
- }
11366
- );
11367
- };
11368
- const displayValue = getDisplayValue(promotion);
11369
- return /* @__PURE__ */ jsxRuntime.jsxs(
11370
- "div",
11371
- {
11372
- className: ui.clx(
11373
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11374
- {
11375
- "animate-pulse": isLoading
11376
- }
11377
- ),
11378
- children: [
11379
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11380
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11381
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11382
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11383
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11384
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11385
- ] }),
11386
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11387
- ] })
11388
- ] }),
11389
- /* @__PURE__ */ jsxRuntime.jsx(
11390
- ui.IconButton,
11391
- {
11392
- size: "small",
11393
- type: "button",
11394
- variant: "transparent",
11395
- onClick: onRemove,
11396
- isLoading: isPending || isLoading,
11397
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11398
- }
11399
- )
11400
- ]
11401
- },
11402
- promotion.id
11403
- );
11404
- };
11405
- function getDisplayValue(promotion) {
11406
- var _a, _b, _c, _d;
11407
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11408
- if (!value) {
11409
- return null;
11410
- }
11411
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11412
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11413
- if (!currency) {
11414
- return null;
11415
- }
11416
- return getLocaleAmount(value, currency);
11417
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11418
- return formatPercentage(value);
11419
- }
11420
- return null;
11421
- }
11422
- const formatter = new Intl.NumberFormat([], {
11423
- style: "percent",
11424
- minimumFractionDigits: 2
11425
- });
11426
- const formatPercentage = (value, isPercentageValue = false) => {
11427
- let val = value || 0;
11428
- if (!isPercentageValue) {
11429
- val = val / 100;
11430
- }
11431
- return formatter.format(val);
11432
- };
11433
- function getPromotionIds(items, shippingMethods) {
11434
- const promotionIds = /* @__PURE__ */ new Set();
11435
- for (const item of items) {
11436
- if (item.adjustments) {
11437
- for (const adjustment of item.adjustments) {
11438
- if (adjustment.promotion_id) {
11439
- promotionIds.add(adjustment.promotion_id);
11440
- }
11441
- }
11442
- }
11443
- }
11444
- for (const shippingMethod of shippingMethods) {
11445
- if (shippingMethod.adjustments) {
11446
- for (const adjustment of shippingMethod.adjustments) {
11447
- if (adjustment.promotion_id) {
11448
- promotionIds.add(adjustment.promotion_id);
11449
- }
11450
- }
11451
- }
11452
- }
11453
- return Array.from(promotionIds);
11454
- }
11455
- const SalesChannel = () => {
11456
- const { id } = reactRouterDom.useParams();
11457
- const { draft_order, isPending, isError, error } = useDraftOrder(
11458
- id,
11459
- {
11460
- fields: "+sales_channel_id"
11461
- },
11462
- {
11463
- enabled: !!id
11464
- }
11465
- );
11466
- if (isError) {
11467
- throw error;
11468
- }
11469
- const ISrEADY = !!draft_order && !isPending;
11470
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11471
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11472
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11473
- /* @__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" }) })
11474
- ] }),
11475
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11476
- ] });
11477
- };
11478
- const SalesChannelForm = ({ order }) => {
11479
- const form = reactHookForm.useForm({
11480
- defaultValues: {
11481
- sales_channel_id: order.sales_channel_id || ""
11482
- },
11483
- resolver: zod.zodResolver(schema$2)
11484
- });
11485
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11486
- const { handleSuccess } = useRouteModal();
11487
- const onSubmit = form.handleSubmit(async (data) => {
11488
- await mutateAsync(
11489
- {
11490
- sales_channel_id: data.sales_channel_id
11491
- },
11492
- {
11493
- onSuccess: () => {
11494
- ui.toast.success("Sales channel updated");
11495
- handleSuccess();
11496
- },
11497
- onError: (error) => {
11498
- ui.toast.error(error.message);
11216
+ ui.toast.success("Sales channel updated");
11217
+ handleSuccess();
11218
+ },
11219
+ onError: (error) => {
11220
+ ui.toast.error(error.message);
11499
11221
  }
11500
11222
  }
11501
11223
  );
@@ -11558,224 +11280,21 @@ const SalesChannelField = ({ control, order }) => {
11558
11280
  const schema$2 = objectType({
11559
11281
  sales_channel_id: stringType().min(1)
11560
11282
  });
11561
- const ShippingAddress = () => {
11283
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11284
+ const Shipping = () => {
11285
+ var _a;
11562
11286
  const { id } = reactRouterDom.useParams();
11563
11287
  const { order, isPending, isError, error } = useOrder(id, {
11564
- fields: "+shipping_address"
11288
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11565
11289
  });
11566
- if (isError) {
11567
- throw error;
11568
- }
11569
- const isReady = !isPending && !!order;
11570
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11571
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11572
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11573
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11574
- ] }),
11575
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11576
- ] });
11577
- };
11578
- const ShippingAddressForm = ({ order }) => {
11579
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11580
- const form = reactHookForm.useForm({
11581
- defaultValues: {
11582
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11583
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11584
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11585
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11586
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11587
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11588
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11589
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11590
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11591
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11592
- },
11593
- resolver: zod.zodResolver(schema$1)
11594
- });
11595
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11596
- const { handleSuccess } = useRouteModal();
11597
- const onSubmit = form.handleSubmit(async (data) => {
11598
- await mutateAsync(
11599
- {
11600
- shipping_address: {
11601
- first_name: data.first_name,
11602
- last_name: data.last_name,
11603
- company: data.company,
11604
- address_1: data.address_1,
11605
- address_2: data.address_2,
11606
- city: data.city,
11607
- province: data.province,
11608
- country_code: data.country_code,
11609
- postal_code: data.postal_code,
11610
- phone: data.phone
11611
- }
11612
- },
11613
- {
11614
- onSuccess: () => {
11615
- handleSuccess();
11616
- },
11617
- onError: (error) => {
11618
- ui.toast.error(error.message);
11619
- }
11620
- }
11621
- );
11622
- });
11623
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11624
- KeyboundForm,
11625
- {
11626
- className: "flex flex-1 flex-col overflow-hidden",
11627
- onSubmit,
11628
- children: [
11629
- /* @__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: [
11630
- /* @__PURE__ */ jsxRuntime.jsx(
11631
- Form$2.Field,
11632
- {
11633
- control: form.control,
11634
- name: "country_code",
11635
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11636
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11639
- ] })
11640
- }
11641
- ),
11642
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11643
- /* @__PURE__ */ jsxRuntime.jsx(
11644
- Form$2.Field,
11645
- {
11646
- control: form.control,
11647
- name: "first_name",
11648
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11649
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11650
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11652
- ] })
11653
- }
11654
- ),
11655
- /* @__PURE__ */ jsxRuntime.jsx(
11656
- Form$2.Field,
11657
- {
11658
- control: form.control,
11659
- name: "last_name",
11660
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11661
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11664
- ] })
11665
- }
11666
- )
11667
- ] }),
11668
- /* @__PURE__ */ jsxRuntime.jsx(
11669
- Form$2.Field,
11670
- {
11671
- control: form.control,
11672
- name: "company",
11673
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11675
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11677
- ] })
11678
- }
11679
- ),
11680
- /* @__PURE__ */ jsxRuntime.jsx(
11681
- Form$2.Field,
11682
- {
11683
- control: form.control,
11684
- name: "address_1",
11685
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11686
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11687
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11689
- ] })
11690
- }
11691
- ),
11692
- /* @__PURE__ */ jsxRuntime.jsx(
11693
- Form$2.Field,
11694
- {
11695
- control: form.control,
11696
- name: "address_2",
11697
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11698
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11701
- ] })
11702
- }
11703
- ),
11704
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11705
- /* @__PURE__ */ jsxRuntime.jsx(
11706
- Form$2.Field,
11707
- {
11708
- control: form.control,
11709
- name: "postal_code",
11710
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11711
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11712
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11714
- ] })
11715
- }
11716
- ),
11717
- /* @__PURE__ */ jsxRuntime.jsx(
11718
- Form$2.Field,
11719
- {
11720
- control: form.control,
11721
- name: "city",
11722
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11723
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11726
- ] })
11727
- }
11728
- )
11729
- ] }),
11730
- /* @__PURE__ */ jsxRuntime.jsx(
11731
- Form$2.Field,
11732
- {
11733
- control: form.control,
11734
- name: "province",
11735
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11736
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11737
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11739
- ] })
11740
- }
11741
- ),
11742
- /* @__PURE__ */ jsxRuntime.jsx(
11743
- Form$2.Field,
11744
- {
11745
- control: form.control,
11746
- name: "phone",
11747
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11748
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11749
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11751
- ] })
11752
- }
11753
- )
11754
- ] }) }),
11755
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11756
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11757
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11758
- ] }) })
11759
- ]
11760
- }
11761
- ) });
11762
- };
11763
- const schema$1 = addressSchema;
11764
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11765
- const Shipping = () => {
11766
- var _a;
11767
- const { id } = reactRouterDom.useParams();
11768
- const { order, isPending, isError, error } = useOrder(id, {
11769
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11770
- });
11771
- const {
11772
- order: preview,
11773
- isPending: isPreviewPending,
11774
- isError: isPreviewError,
11775
- error: previewError
11776
- } = useOrderPreview(id);
11777
- useInitiateOrderEdit({ preview });
11778
- const { onCancel } = useCancelOrderEdit({ preview });
11290
+ const {
11291
+ order: preview,
11292
+ isPending: isPreviewPending,
11293
+ isError: isPreviewError,
11294
+ error: previewError
11295
+ } = useOrderPreview(id);
11296
+ useInitiateOrderEdit({ preview });
11297
+ const { onCancel } = useCancelOrderEdit({ preview });
11779
11298
  if (isError) {
11780
11299
  throw error;
11781
11300
  }
@@ -11786,7 +11305,7 @@ const Shipping = () => {
11786
11305
  const isReady = preview && !isPreviewPending && order && !isPending;
11787
11306
  return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11788
11307
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11789
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11308
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11790
11309
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11791
11310
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11792
11311
  ] }) }) }),
@@ -11873,14 +11392,14 @@ const ShippingForm = ({ preview, order }) => {
11873
11392
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11874
11393
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11875
11394
  /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11876
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11395
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11877
11396
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11878
11397
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11879
11398
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11880
11399
  ] }),
11881
11400
  /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11882
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11883
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11401
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11402
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11884
11403
  /* @__PURE__ */ jsxRuntime.jsx(
11885
11404
  ui.Text,
11886
11405
  {
@@ -11922,8 +11441,8 @@ const ShippingForm = ({ preview, order }) => {
11922
11441
  value: profile.id,
11923
11442
  className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11924
11443
  children: [
11925
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11926
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11444
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11445
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11927
11446
  /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11928
11447
  ui.IconButton,
11929
11448
  {
@@ -11931,12 +11450,12 @@ const ShippingForm = ({ preview, order }) => {
11931
11450
  variant: "transparent",
11932
11451
  className: "group/trigger",
11933
11452
  disabled: !hasItems,
11934
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11453
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11935
11454
  }
11936
11455
  ) }),
11937
11456
  !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11938
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11939
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col", children: [
11457
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11458
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11940
11459
  /* @__PURE__ */ jsxRuntime.jsx(
11941
11460
  ui.Text,
11942
11461
  {
@@ -11960,7 +11479,7 @@ const ShippingForm = ({ preview, order }) => {
11960
11479
  }
11961
11480
  )
11962
11481
  ] })
11963
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11482
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11964
11483
  /* @__PURE__ */ jsxRuntime.jsx(
11965
11484
  ui.Tooltip,
11966
11485
  {
@@ -11977,7 +11496,7 @@ const ShippingForm = ({ preview, order }) => {
11977
11496
  children: /* @__PURE__ */ jsxRuntime.jsxs(
11978
11497
  ui.Badge,
11979
11498
  {
11980
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11499
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11981
11500
  size: "xsmall",
11982
11501
  children: [
11983
11502
  /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
@@ -12002,7 +11521,7 @@ const ShippingForm = ({ preview, order }) => {
12002
11521
  children: /* @__PURE__ */ jsxRuntime.jsxs(
12003
11522
  ui.Badge,
12004
11523
  {
12005
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11524
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12006
11525
  size: "xsmall",
12007
11526
  children: [
12008
11527
  /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
@@ -12015,7 +11534,7 @@ const ShippingForm = ({ preview, order }) => {
12015
11534
  /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12016
11535
  ui.Badge,
12017
11536
  {
12018
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11537
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12019
11538
  size: "xsmall",
12020
11539
  children: [
12021
11540
  /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
@@ -12086,17 +11605,17 @@ const ShippingForm = ({ preview, order }) => {
12086
11605
  /* @__PURE__ */ jsxRuntime.jsxs(
12087
11606
  "div",
12088
11607
  {
12089
- className: "flex items-center gap-x-3 px-3",
11608
+ className: "px-3 flex items-center gap-x-3",
12090
11609
  children: [
12091
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11610
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12092
11611
  ui.Divider,
12093
11612
  {
12094
11613
  variant: "dashed",
12095
11614
  orientation: "vertical"
12096
11615
  }
12097
11616
  ) }),
12098
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12099
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11617
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11618
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12100
11619
  ui.Text,
12101
11620
  {
12102
11621
  size: "small",
@@ -12233,7 +11752,7 @@ const ShippingProfileForm = ({
12233
11752
  isPending: isUpdatingShippingMethod
12234
11753
  } = useDraftOrderUpdateShippingMethod(order.id);
12235
11754
  const onSubmit = form.handleSubmit(async (values) => {
12236
- if (isEqual__default.default(values, form.formState.defaultValues)) {
11755
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12237
11756
  setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12238
11757
  return;
12239
11758
  }
@@ -12277,7 +11796,7 @@ const ShippingProfileForm = ({
12277
11796
  onSubmit,
12278
11797
  children: [
12279
11798
  /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12280
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11799
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12281
11800
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12282
11801
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12283
11802
  /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
@@ -12350,14 +11869,14 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12350
11869
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12351
11870
  ] }) }),
12352
11871
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12353
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
11872
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12354
11873
  /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12355
11874
  /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12356
11875
  ] }),
12357
11876
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12358
11877
  "div",
12359
11878
  {
12360
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
11879
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12361
11880
  children: [
12362
11881
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12363
11882
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -12410,7 +11929,7 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12410
11929
  ]
12411
11930
  },
12412
11931
  item.id
12413
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
11932
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12414
11933
  /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12415
11934
  /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12416
11935
  'No items found for "',
@@ -12568,44 +12087,60 @@ const CustomAmountField = ({
12568
12087
  }
12569
12088
  );
12570
12089
  };
12571
- const TransferOwnership = () => {
12090
+ const ShippingAddress = () => {
12572
12091
  const { id } = reactRouterDom.useParams();
12573
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12574
- fields: "id,customer_id,customer.*"
12092
+ const { order, isPending, isError, error } = useOrder(id, {
12093
+ fields: "+shipping_address"
12575
12094
  });
12576
12095
  if (isError) {
12577
12096
  throw error;
12578
12097
  }
12579
- const isReady = !isPending && !!draft_order;
12098
+ const isReady = !isPending && !!order;
12580
12099
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12581
12100
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12582
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12583
- /* @__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" }) })
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" }) })
12584
12103
  ] }),
12585
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12104
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12586
12105
  ] });
12587
12106
  };
12588
- const TransferOwnershipForm = ({ order }) => {
12589
- var _a, _b;
12107
+ const ShippingAddressForm = ({ order }) => {
12108
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12590
12109
  const form = reactHookForm.useForm({
12591
12110
  defaultValues: {
12592
- customer_id: order.customer_id || ""
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) ?? ""
12593
12121
  },
12594
- resolver: zod.zodResolver(schema)
12122
+ resolver: zod.zodResolver(schema$1)
12595
12123
  });
12596
12124
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12597
12125
  const { handleSuccess } = useRouteModal();
12598
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12599
- const currentCustomer = order.customer ? {
12600
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12601
- value: order.customer.id
12602
- } : null;
12603
12126
  const onSubmit = form.handleSubmit(async (data) => {
12604
12127
  await mutateAsync(
12605
- { customer_id: data.customer_id },
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
+ },
12606
12142
  {
12607
12143
  onSuccess: () => {
12608
- ui.toast.success("Customer updated");
12609
12144
  handleSuccess();
12610
12145
  },
12611
12146
  onError: (error) => {
@@ -12620,18 +12155,205 @@ const TransferOwnershipForm = ({ order }) => {
12620
12155
  className: "flex flex-1 flex-col overflow-hidden",
12621
12156
  onSubmit,
12622
12157
  children: [
12623
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12624
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12625
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12626
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12627
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12628
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12629
- ] }),
12630
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12631
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12632
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12633
- ] })
12634
- ] }),
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");
12331
+ handleSuccess();
12332
+ },
12333
+ onError: (error) => {
12334
+ ui.toast.error(error.message);
12335
+ }
12336
+ }
12337
+ );
12338
+ });
12339
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12340
+ KeyboundForm,
12341
+ {
12342
+ className: "flex flex-1 flex-col overflow-hidden",
12343
+ onSubmit,
12344
+ children: [
12345
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12346
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12347
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12348
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12349
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12350
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12351
+ ] }),
12352
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12353
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12354
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12355
+ ] })
12356
+ ] }),
12635
12357
  /* @__PURE__ */ jsxRuntime.jsx(
12636
12358
  CustomerField,
12637
12359
  {
@@ -13044,6 +12766,283 @@ const Illustration = () => {
13044
12766
  const schema = objectType({
13045
12767
  customer_id: stringType().min(1)
13046
12768
  });
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 = () => {
12790
+ 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;
12800
+ }
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 })
12805
+ ] });
12806
+ };
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
12817
+ },
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
+ }
12838
+ });
12839
+ const add = async (value) => {
12840
+ if (!value) {
12841
+ return;
12842
+ }
12843
+ addPromotions(
12844
+ {
12845
+ promo_codes: [value]
12846
+ },
12847
+ {
12848
+ onError: (e) => {
12849
+ ui.toast.error(e.message);
12850
+ comboboxData.onSearchValueChange("");
12851
+ setComboboxValue("");
12852
+ },
12853
+ 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
12922
+ },
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);
12955
+ }
12956
+ }
12957
+ );
12958
+ };
12959
+ const displayValue = getDisplayValue(promotion);
12960
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12961
+ "div",
12962
+ {
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
+ ),
12969
+ 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
+ )
12991
+ ]
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
+ }
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);
13023
+ };
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
+ }
13047
13046
  const widgetModule = { widgets: [] };
13048
13047
  const routeModule = {
13049
13048
  routes: [
@@ -13068,6 +13067,10 @@ const routeModule = {
13068
13067
  Component: CustomItems,
13069
13068
  path: "/draft-orders/:id/custom-items"
13070
13069
  },
13070
+ {
13071
+ Component: Email,
13072
+ path: "/draft-orders/:id/email"
13073
+ },
13071
13074
  {
13072
13075
  Component: BillingAddress,
13073
13076
  path: "/draft-orders/:id/billing-address"
@@ -13076,33 +13079,29 @@ const routeModule = {
13076
13079
  Component: Items,
13077
13080
  path: "/draft-orders/:id/items"
13078
13081
  },
13079
- {
13080
- Component: Email,
13081
- path: "/draft-orders/:id/email"
13082
- },
13083
13082
  {
13084
13083
  Component: Metadata,
13085
13084
  path: "/draft-orders/:id/metadata"
13086
13085
  },
13087
- {
13088
- Component: Promotions,
13089
- path: "/draft-orders/:id/promotions"
13090
- },
13091
13086
  {
13092
13087
  Component: SalesChannel,
13093
13088
  path: "/draft-orders/:id/sales-channel"
13094
13089
  },
13095
- {
13096
- Component: ShippingAddress,
13097
- path: "/draft-orders/:id/shipping-address"
13098
- },
13099
13090
  {
13100
13091
  Component: Shipping,
13101
13092
  path: "/draft-orders/:id/shipping"
13102
13093
  },
13094
+ {
13095
+ Component: ShippingAddress,
13096
+ path: "/draft-orders/:id/shipping-address"
13097
+ },
13103
13098
  {
13104
13099
  Component: TransferOwnership,
13105
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
+ },
13102
+ {
13103
+ Component: Promotions,
13104
+ path: "/draft-orders/:id/promotions"
13106
13105
  }
13107
13106
  ]
13108
13107
  }