@medusajs/draft-order 2.11.2-snapshot-20251031083831 → 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.
@@ -13,9 +13,9 @@ import { FormProvider, Controller, useFormContext, useFormState, useForm, useWat
13
13
  import { Slot, Collapsible, Accordion } from "radix-ui";
14
14
  import { ComboboxProvider, Combobox as Combobox$1, ComboboxDisclosure, ComboboxPopover, ComboboxItem, ComboboxItemCheck, ComboboxItemValue, Separator } from "@ariakit/react";
15
15
  import { matchSorter } from "match-sorter";
16
- import debounce from "lodash.debounce";
16
+ import debounce from "lodash/debounce";
17
17
  import Primitive from "@uiw/react-json-view";
18
- import isEqual from "lodash.isequal";
18
+ import { isEqual } from "lodash";
19
19
  function useQueryParams(keys, prefix) {
20
20
  const [params] = useSearchParams();
21
21
  const result = {};
@@ -9565,6 +9565,95 @@ const ID = () => {
9565
9565
  /* @__PURE__ */ jsx(Outlet, {})
9566
9566
  ] });
9567
9567
  };
9568
+ const CustomItems = () => {
9569
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9570
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9571
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9572
+ ] });
9573
+ };
9574
+ const CustomItemsForm = () => {
9575
+ const form = useForm({
9576
+ resolver: zodResolver(schema$5)
9577
+ });
9578
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9579
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9580
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9582
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9583
+ ] }) })
9584
+ ] }) });
9585
+ };
9586
+ const schema$5 = objectType({
9587
+ email: stringType().email()
9588
+ });
9589
+ const Email = () => {
9590
+ const { id } = useParams();
9591
+ const { order, isPending, isError, error } = useOrder(id, {
9592
+ fields: "+email"
9593
+ });
9594
+ if (isError) {
9595
+ throw error;
9596
+ }
9597
+ const isReady = !isPending && !!order;
9598
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9599
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9600
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9601
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9602
+ ] }),
9603
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9604
+ ] });
9605
+ };
9606
+ const EmailForm = ({ order }) => {
9607
+ const form = useForm({
9608
+ defaultValues: {
9609
+ email: order.email ?? ""
9610
+ },
9611
+ resolver: zodResolver(schema$4)
9612
+ });
9613
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9614
+ const { handleSuccess } = useRouteModal();
9615
+ const onSubmit = form.handleSubmit(async (data) => {
9616
+ await mutateAsync(
9617
+ { email: data.email },
9618
+ {
9619
+ onSuccess: () => {
9620
+ handleSuccess();
9621
+ },
9622
+ onError: (error) => {
9623
+ toast.error(error.message);
9624
+ }
9625
+ }
9626
+ );
9627
+ });
9628
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9629
+ KeyboundForm,
9630
+ {
9631
+ className: "flex flex-1 flex-col overflow-hidden",
9632
+ onSubmit,
9633
+ children: [
9634
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9635
+ Form$2.Field,
9636
+ {
9637
+ control: form.control,
9638
+ name: "email",
9639
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9640
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9641
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9642
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9643
+ ] })
9644
+ }
9645
+ ) }),
9646
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9647
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9648
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9649
+ ] }) })
9650
+ ]
9651
+ }
9652
+ ) });
9653
+ };
9654
+ const schema$4 = objectType({
9655
+ email: stringType().email()
9656
+ });
9568
9657
  const BillingAddress = () => {
9569
9658
  const { id } = useParams();
9570
9659
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9597,7 +9686,7 @@ const BillingAddressForm = ({ order }) => {
9597
9686
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9598
9687
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9599
9688
  },
9600
- resolver: zodResolver(schema$5)
9689
+ resolver: zodResolver(schema$3)
9601
9690
  });
9602
9691
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9603
9692
  const { handleSuccess } = useRouteModal();
@@ -9754,96 +9843,7 @@ const BillingAddressForm = ({ order }) => {
9754
9843
  }
9755
9844
  ) });
9756
9845
  };
9757
- const schema$5 = addressSchema;
9758
- const Email = () => {
9759
- const { id } = useParams();
9760
- const { order, isPending, isError, error } = useOrder(id, {
9761
- fields: "+email"
9762
- });
9763
- if (isError) {
9764
- throw error;
9765
- }
9766
- const isReady = !isPending && !!order;
9767
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9768
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9769
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9770
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9771
- ] }),
9772
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9773
- ] });
9774
- };
9775
- const EmailForm = ({ order }) => {
9776
- const form = useForm({
9777
- defaultValues: {
9778
- email: order.email ?? ""
9779
- },
9780
- resolver: zodResolver(schema$4)
9781
- });
9782
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9783
- const { handleSuccess } = useRouteModal();
9784
- const onSubmit = form.handleSubmit(async (data) => {
9785
- await mutateAsync(
9786
- { email: data.email },
9787
- {
9788
- onSuccess: () => {
9789
- handleSuccess();
9790
- },
9791
- onError: (error) => {
9792
- toast.error(error.message);
9793
- }
9794
- }
9795
- );
9796
- });
9797
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9798
- KeyboundForm,
9799
- {
9800
- className: "flex flex-1 flex-col overflow-hidden",
9801
- onSubmit,
9802
- children: [
9803
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9804
- Form$2.Field,
9805
- {
9806
- control: form.control,
9807
- name: "email",
9808
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9809
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9810
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9811
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9812
- ] })
9813
- }
9814
- ) }),
9815
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9816
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9817
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9818
- ] }) })
9819
- ]
9820
- }
9821
- ) });
9822
- };
9823
- const schema$4 = objectType({
9824
- email: stringType().email()
9825
- });
9826
- const CustomItems = () => {
9827
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9828
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9829
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9830
- ] });
9831
- };
9832
- const CustomItemsForm = () => {
9833
- const form = useForm({
9834
- resolver: zodResolver(schema$3)
9835
- });
9836
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9837
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9838
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9839
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9840
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9841
- ] }) })
9842
- ] }) });
9843
- };
9844
- const schema$3 = objectType({
9845
- email: stringType().email()
9846
- });
9846
+ const schema$3 = addressSchema;
9847
9847
  const NumberInput = forwardRef(
9848
9848
  ({
9849
9849
  value,
@@ -11168,310 +11168,33 @@ function getHasUneditableRows(metadata) {
11168
11168
  (value) => !EDITABLE_TYPES.includes(typeof value)
11169
11169
  );
11170
11170
  }
11171
- const PROMOTION_QUERY_KEY = "promotions";
11172
- const promotionsQueryKeys = {
11173
- list: (query2) => [
11174
- PROMOTION_QUERY_KEY,
11175
- query2 ? query2 : void 0
11176
- ],
11177
- detail: (id, query2) => [
11178
- PROMOTION_QUERY_KEY,
11179
- id,
11180
- query2 ? query2 : void 0
11181
- ]
11182
- };
11183
- const usePromotions = (query2, options) => {
11184
- const { data, ...rest } = useQuery({
11185
- queryKey: promotionsQueryKeys.list(query2),
11186
- queryFn: async () => sdk.admin.promotion.list(query2),
11187
- ...options
11188
- });
11189
- return { ...data, ...rest };
11190
- };
11191
- const Promotions = () => {
11171
+ const SalesChannel = () => {
11192
11172
  const { id } = useParams();
11193
- const {
11194
- order: preview,
11195
- isError: isPreviewError,
11196
- error: previewError
11197
- } = useOrderPreview(id, void 0);
11198
- useInitiateOrderEdit({ preview });
11199
- const { onCancel } = useCancelOrderEdit({ preview });
11200
- if (isPreviewError) {
11201
- throw previewError;
11202
- }
11203
- const isReady = !!preview;
11204
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11205
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11206
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11207
- ] });
11208
- };
11209
- const PromotionForm = ({ preview }) => {
11210
- const { items, shipping_methods } = preview;
11211
- const [isSubmitting, setIsSubmitting] = useState(false);
11212
- const [comboboxValue, setComboboxValue] = useState("");
11213
- const { handleSuccess } = useRouteModal();
11214
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11215
- const promoIds = getPromotionIds(items, shipping_methods);
11216
- const { promotions, isPending, isError, error } = usePromotions(
11173
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11174
+ id,
11217
11175
  {
11218
- id: promoIds
11176
+ fields: "+sales_channel_id"
11219
11177
  },
11220
11178
  {
11221
- enabled: !!promoIds.length
11179
+ enabled: !!id
11222
11180
  }
11223
11181
  );
11224
- const comboboxData = useComboboxData({
11225
- queryKey: ["promotions", "combobox", promoIds],
11226
- queryFn: async (params) => {
11227
- return await sdk.admin.promotion.list({
11228
- ...params,
11229
- id: {
11230
- $nin: promoIds
11231
- }
11232
- });
11233
- },
11234
- getOptions: (data) => {
11235
- return data.promotions.map((promotion) => ({
11236
- label: promotion.code,
11237
- value: promotion.code
11238
- }));
11239
- }
11240
- });
11241
- const add = async (value) => {
11242
- if (!value) {
11243
- return;
11244
- }
11245
- addPromotions(
11246
- {
11247
- promo_codes: [value]
11248
- },
11249
- {
11250
- onError: (e) => {
11251
- toast.error(e.message);
11252
- comboboxData.onSearchValueChange("");
11253
- setComboboxValue("");
11254
- },
11255
- onSuccess: () => {
11256
- comboboxData.onSearchValueChange("");
11257
- setComboboxValue("");
11258
- }
11259
- }
11260
- );
11261
- };
11262
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11263
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11264
- const onSubmit = async () => {
11265
- setIsSubmitting(true);
11266
- let requestSucceeded = false;
11267
- await requestOrderEdit(void 0, {
11268
- onError: (e) => {
11269
- toast.error(e.message);
11270
- },
11271
- onSuccess: () => {
11272
- requestSucceeded = true;
11273
- }
11274
- });
11275
- if (!requestSucceeded) {
11276
- setIsSubmitting(false);
11277
- return;
11278
- }
11279
- await confirmOrderEdit(void 0, {
11280
- onError: (e) => {
11281
- toast.error(e.message);
11282
- },
11283
- onSuccess: () => {
11284
- handleSuccess();
11285
- },
11286
- onSettled: () => {
11287
- setIsSubmitting(false);
11288
- }
11289
- });
11290
- };
11291
- if (isError) {
11292
- throw error;
11293
- }
11294
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11295
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11296
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11297
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11298
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11299
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11300
- ] }),
11301
- /* @__PURE__ */ jsx(
11302
- Combobox,
11303
- {
11304
- id: "promotion-combobox",
11305
- "aria-describedby": "promotion-combobox-hint",
11306
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11307
- fetchNextPage: comboboxData.fetchNextPage,
11308
- options: comboboxData.options,
11309
- onSearchValueChange: comboboxData.onSearchValueChange,
11310
- searchValue: comboboxData.searchValue,
11311
- disabled: comboboxData.disabled || isAddingPromotions,
11312
- onChange: add,
11313
- value: comboboxValue
11314
- }
11315
- )
11316
- ] }),
11317
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11318
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11319
- PromotionItem,
11320
- {
11321
- promotion,
11322
- orderId: preview.id,
11323
- isLoading: isPending
11324
- },
11325
- promotion.id
11326
- )) })
11327
- ] }) }),
11328
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11329
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11330
- /* @__PURE__ */ jsx(
11331
- Button,
11332
- {
11333
- size: "small",
11334
- type: "submit",
11335
- isLoading: isSubmitting || isAddingPromotions,
11336
- children: "Save"
11337
- }
11338
- )
11339
- ] }) })
11340
- ] });
11341
- };
11342
- const PromotionItem = ({
11343
- promotion,
11344
- orderId,
11345
- isLoading
11346
- }) => {
11347
- var _a;
11348
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11349
- const onRemove = async () => {
11350
- removePromotions(
11351
- {
11352
- promo_codes: [promotion.code]
11353
- },
11354
- {
11355
- onError: (e) => {
11356
- toast.error(e.message);
11357
- }
11358
- }
11359
- );
11360
- };
11361
- const displayValue = getDisplayValue(promotion);
11362
- return /* @__PURE__ */ jsxs(
11363
- "div",
11364
- {
11365
- className: clx(
11366
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11367
- {
11368
- "animate-pulse": isLoading
11369
- }
11370
- ),
11371
- children: [
11372
- /* @__PURE__ */ jsxs("div", { children: [
11373
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11374
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11375
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11376
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11377
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11378
- ] }),
11379
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11380
- ] })
11381
- ] }),
11382
- /* @__PURE__ */ jsx(
11383
- IconButton,
11384
- {
11385
- size: "small",
11386
- type: "button",
11387
- variant: "transparent",
11388
- onClick: onRemove,
11389
- isLoading: isPending || isLoading,
11390
- children: /* @__PURE__ */ jsx(XMark, {})
11391
- }
11392
- )
11393
- ]
11394
- },
11395
- promotion.id
11396
- );
11397
- };
11398
- function getDisplayValue(promotion) {
11399
- var _a, _b, _c, _d;
11400
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11401
- if (!value) {
11402
- return null;
11403
- }
11404
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11405
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11406
- if (!currency) {
11407
- return null;
11408
- }
11409
- return getLocaleAmount(value, currency);
11410
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11411
- return formatPercentage(value);
11412
- }
11413
- return null;
11414
- }
11415
- const formatter = new Intl.NumberFormat([], {
11416
- style: "percent",
11417
- minimumFractionDigits: 2
11418
- });
11419
- const formatPercentage = (value, isPercentageValue = false) => {
11420
- let val = value || 0;
11421
- if (!isPercentageValue) {
11422
- val = val / 100;
11423
- }
11424
- return formatter.format(val);
11425
- };
11426
- function getPromotionIds(items, shippingMethods) {
11427
- const promotionIds = /* @__PURE__ */ new Set();
11428
- for (const item of items) {
11429
- if (item.adjustments) {
11430
- for (const adjustment of item.adjustments) {
11431
- if (adjustment.promotion_id) {
11432
- promotionIds.add(adjustment.promotion_id);
11433
- }
11434
- }
11435
- }
11436
- }
11437
- for (const shippingMethod of shippingMethods) {
11438
- if (shippingMethod.adjustments) {
11439
- for (const adjustment of shippingMethod.adjustments) {
11440
- if (adjustment.promotion_id) {
11441
- promotionIds.add(adjustment.promotion_id);
11442
- }
11443
- }
11444
- }
11445
- }
11446
- return Array.from(promotionIds);
11447
- }
11448
- const SalesChannel = () => {
11449
- const { id } = useParams();
11450
- const { draft_order, isPending, isError, error } = useDraftOrder(
11451
- id,
11452
- {
11453
- fields: "+sales_channel_id"
11454
- },
11455
- {
11456
- enabled: !!id
11457
- }
11458
- );
11459
- if (isError) {
11460
- throw error;
11461
- }
11462
- const ISrEADY = !!draft_order && !isPending;
11463
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11464
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11465
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11467
- ] }),
11468
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11469
- ] });
11470
- };
11471
- const SalesChannelForm = ({ order }) => {
11472
- const form = useForm({
11473
- defaultValues: {
11474
- sales_channel_id: order.sales_channel_id || ""
11182
+ if (isError) {
11183
+ throw error;
11184
+ }
11185
+ const ISrEADY = !!draft_order && !isPending;
11186
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11187
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11188
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11189
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11190
+ ] }),
11191
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11192
+ ] });
11193
+ };
11194
+ const SalesChannelForm = ({ order }) => {
11195
+ const form = useForm({
11196
+ defaultValues: {
11197
+ sales_channel_id: order.sales_channel_id || ""
11475
11198
  },
11476
11199
  resolver: zodResolver(schema$2)
11477
11200
  });
@@ -11551,224 +11274,21 @@ const SalesChannelField = ({ control, order }) => {
11551
11274
  const schema$2 = objectType({
11552
11275
  sales_channel_id: stringType().min(1)
11553
11276
  });
11554
- const ShippingAddress = () => {
11277
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11278
+ const Shipping = () => {
11279
+ var _a;
11555
11280
  const { id } = useParams();
11556
11281
  const { order, isPending, isError, error } = useOrder(id, {
11557
- fields: "+shipping_address"
11282
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11558
11283
  });
11559
- if (isError) {
11560
- throw error;
11561
- }
11562
- const isReady = !isPending && !!order;
11563
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11564
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11565
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11566
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11567
- ] }),
11568
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11569
- ] });
11570
- };
11571
- const ShippingAddressForm = ({ order }) => {
11572
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11573
- const form = useForm({
11574
- defaultValues: {
11575
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11576
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11577
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11578
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11579
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11580
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11581
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11582
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11583
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11584
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11585
- },
11586
- resolver: zodResolver(schema$1)
11587
- });
11588
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11589
- const { handleSuccess } = useRouteModal();
11590
- const onSubmit = form.handleSubmit(async (data) => {
11591
- await mutateAsync(
11592
- {
11593
- shipping_address: {
11594
- first_name: data.first_name,
11595
- last_name: data.last_name,
11596
- company: data.company,
11597
- address_1: data.address_1,
11598
- address_2: data.address_2,
11599
- city: data.city,
11600
- province: data.province,
11601
- country_code: data.country_code,
11602
- postal_code: data.postal_code,
11603
- phone: data.phone
11604
- }
11605
- },
11606
- {
11607
- onSuccess: () => {
11608
- handleSuccess();
11609
- },
11610
- onError: (error) => {
11611
- toast.error(error.message);
11612
- }
11613
- }
11614
- );
11615
- });
11616
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11617
- KeyboundForm,
11618
- {
11619
- className: "flex flex-1 flex-col overflow-hidden",
11620
- onSubmit,
11621
- children: [
11622
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11623
- /* @__PURE__ */ jsx(
11624
- Form$2.Field,
11625
- {
11626
- control: form.control,
11627
- name: "country_code",
11628
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11629
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11630
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11631
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11632
- ] })
11633
- }
11634
- ),
11635
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11636
- /* @__PURE__ */ jsx(
11637
- Form$2.Field,
11638
- {
11639
- control: form.control,
11640
- name: "first_name",
11641
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11642
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11643
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11644
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11645
- ] })
11646
- }
11647
- ),
11648
- /* @__PURE__ */ jsx(
11649
- Form$2.Field,
11650
- {
11651
- control: form.control,
11652
- name: "last_name",
11653
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11654
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11655
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11656
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11657
- ] })
11658
- }
11659
- )
11660
- ] }),
11661
- /* @__PURE__ */ jsx(
11662
- Form$2.Field,
11663
- {
11664
- control: form.control,
11665
- name: "company",
11666
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11667
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11668
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11669
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11670
- ] })
11671
- }
11672
- ),
11673
- /* @__PURE__ */ jsx(
11674
- Form$2.Field,
11675
- {
11676
- control: form.control,
11677
- name: "address_1",
11678
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11679
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11680
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11681
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11682
- ] })
11683
- }
11684
- ),
11685
- /* @__PURE__ */ jsx(
11686
- Form$2.Field,
11687
- {
11688
- control: form.control,
11689
- name: "address_2",
11690
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11691
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11692
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11693
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11694
- ] })
11695
- }
11696
- ),
11697
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11698
- /* @__PURE__ */ jsx(
11699
- Form$2.Field,
11700
- {
11701
- control: form.control,
11702
- name: "postal_code",
11703
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11704
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11705
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11706
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11707
- ] })
11708
- }
11709
- ),
11710
- /* @__PURE__ */ jsx(
11711
- Form$2.Field,
11712
- {
11713
- control: form.control,
11714
- name: "city",
11715
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11716
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11717
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11718
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11719
- ] })
11720
- }
11721
- )
11722
- ] }),
11723
- /* @__PURE__ */ jsx(
11724
- Form$2.Field,
11725
- {
11726
- control: form.control,
11727
- name: "province",
11728
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11729
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11730
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11731
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11732
- ] })
11733
- }
11734
- ),
11735
- /* @__PURE__ */ jsx(
11736
- Form$2.Field,
11737
- {
11738
- control: form.control,
11739
- name: "phone",
11740
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11741
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11742
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11743
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11744
- ] })
11745
- }
11746
- )
11747
- ] }) }),
11748
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11749
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11750
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11751
- ] }) })
11752
- ]
11753
- }
11754
- ) });
11755
- };
11756
- const schema$1 = addressSchema;
11757
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11758
- const Shipping = () => {
11759
- var _a;
11760
- const { id } = useParams();
11761
- const { order, isPending, isError, error } = useOrder(id, {
11762
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11763
- });
11764
- const {
11765
- order: preview,
11766
- isPending: isPreviewPending,
11767
- isError: isPreviewError,
11768
- error: previewError
11769
- } = useOrderPreview(id);
11770
- useInitiateOrderEdit({ preview });
11771
- const { onCancel } = useCancelOrderEdit({ preview });
11284
+ const {
11285
+ order: preview,
11286
+ isPending: isPreviewPending,
11287
+ isError: isPreviewError,
11288
+ error: previewError
11289
+ } = useOrderPreview(id);
11290
+ useInitiateOrderEdit({ preview });
11291
+ const { onCancel } = useCancelOrderEdit({ preview });
11772
11292
  if (isError) {
11773
11293
  throw error;
11774
11294
  }
@@ -11779,7 +11299,7 @@ const Shipping = () => {
11779
11299
  const isReady = preview && !isPreviewPending && order && !isPending;
11780
11300
  return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11781
11301
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11782
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11302
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11783
11303
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11784
11304
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11785
11305
  ] }) }) }),
@@ -11866,14 +11386,14 @@ const ShippingForm = ({ preview, order }) => {
11866
11386
  return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11867
11387
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11868
11388
  /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11869
- /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11389
+ /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11870
11390
  /* @__PURE__ */ jsxs("div", { children: [
11871
11391
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11872
11392
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11873
11393
  ] }),
11874
11394
  /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11875
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11876
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-4 py-2", children: [
11395
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11396
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11877
11397
  /* @__PURE__ */ jsx(
11878
11398
  Text,
11879
11399
  {
@@ -11915,8 +11435,8 @@ const ShippingForm = ({ preview, order }) => {
11915
11435
  value: profile.id,
11916
11436
  className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11917
11437
  children: [
11918
- /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-3 py-2", children: [
11919
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3 overflow-hidden", children: [
11438
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11439
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11920
11440
  /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11921
11441
  IconButton,
11922
11442
  {
@@ -11924,12 +11444,12 @@ const ShippingForm = ({ preview, order }) => {
11924
11444
  variant: "transparent",
11925
11445
  className: "group/trigger",
11926
11446
  disabled: !hasItems,
11927
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "transition-transform group-data-[state=open]/trigger:rotate-90" })
11447
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11928
11448
  }
11929
11449
  ) }),
11930
11450
  !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11931
- /* @__PURE__ */ jsx("div", { className: "shadow-borders-base flex size-7 items-center justify-center rounded-md", children: /* @__PURE__ */ jsx("div", { className: "bg-ui-bg-component-hover flex size-6 items-center justify-center rounded", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11932
- /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col", children: [
11451
+ /* @__PURE__ */ jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsx(Shopping, { className: "text-ui-fg-subtle" }) }) }),
11452
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col flex-1", children: [
11933
11453
  /* @__PURE__ */ jsx(
11934
11454
  Text,
11935
11455
  {
@@ -11953,7 +11473,7 @@ const ShippingForm = ({ preview, order }) => {
11953
11473
  }
11954
11474
  )
11955
11475
  ] })
11956
- ] }) : /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-1 items-center gap-[5px] overflow-hidden max-sm:flex-col max-sm:items-start", children: [
11476
+ ] }) : /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11957
11477
  /* @__PURE__ */ jsx(
11958
11478
  Tooltip,
11959
11479
  {
@@ -11970,7 +11490,7 @@ const ShippingForm = ({ preview, order }) => {
11970
11490
  children: /* @__PURE__ */ jsxs(
11971
11491
  Badge,
11972
11492
  {
11973
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11493
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11974
11494
  size: "xsmall",
11975
11495
  children: [
11976
11496
  /* @__PURE__ */ jsx(Shopping, { className: "shrink-0" }),
@@ -11995,7 +11515,7 @@ const ShippingForm = ({ preview, order }) => {
11995
11515
  children: /* @__PURE__ */ jsxs(
11996
11516
  Badge,
11997
11517
  {
11998
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11518
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11999
11519
  size: "xsmall",
12000
11520
  children: [
12001
11521
  /* @__PURE__ */ jsx(Buildings, { className: "shrink-0" }),
@@ -12008,7 +11528,7 @@ const ShippingForm = ({ preview, order }) => {
12008
11528
  /* @__PURE__ */ jsx(Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxs(
12009
11529
  Badge,
12010
11530
  {
12011
- className: "flex cursor-default items-center gap-x-[3px] overflow-hidden",
11531
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12012
11532
  size: "xsmall",
12013
11533
  children: [
12014
11534
  /* @__PURE__ */ jsx(TruckFast, { className: "shrink-0" }),
@@ -12079,17 +11599,17 @@ const ShippingForm = ({ preview, order }) => {
12079
11599
  /* @__PURE__ */ jsxs(
12080
11600
  "div",
12081
11601
  {
12082
- className: "flex items-center gap-x-3 px-3",
11602
+ className: "px-3 flex items-center gap-x-3",
12083
11603
  children: [
12084
- /* @__PURE__ */ jsx("div", { className: "flex h-[56px] w-5 flex-col items-center justify-center", children: /* @__PURE__ */ jsx(
11604
+ /* @__PURE__ */ jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsx(
12085
11605
  Divider,
12086
11606
  {
12087
11607
  variant: "dashed",
12088
11608
  orientation: "vertical"
12089
11609
  }
12090
11610
  ) }),
12091
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 py-2", children: [
12092
- /* @__PURE__ */ jsx("div", { className: "flex size-7 items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
11611
+ /* @__PURE__ */ jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11612
+ /* @__PURE__ */ jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxs(
12093
11613
  Text,
12094
11614
  {
12095
11615
  size: "small",
@@ -12270,7 +11790,7 @@ const ShippingProfileForm = ({
12270
11790
  onSubmit,
12271
11791
  children: [
12272
11792
  /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12273
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11793
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12274
11794
  /* @__PURE__ */ jsxs("div", { children: [
12275
11795
  /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
12276
11796
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(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." }) })
@@ -12343,14 +11863,14 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12343
11863
  /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12344
11864
  ] }) }),
12345
11865
  /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12346
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-2 gap-3 px-4 py-2", children: [
11866
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12347
11867
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12348
11868
  /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) })
12349
11869
  ] }),
12350
11870
  /* @__PURE__ */ 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__ */ jsxs(
12351
11871
  "div",
12352
11872
  {
12353
- className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-2 items-center gap-3 rounded-lg px-4 py-2",
11873
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12354
11874
  children: [
12355
11875
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12356
11876
  /* @__PURE__ */ jsx(
@@ -12403,7 +11923,7 @@ const ItemsPreview = ({ order, shippingProfileId }) => {
12403
11923
  ]
12404
11924
  },
12405
11925
  item.id
12406
- )) : /* @__PURE__ */ 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: [
11926
+ )) : /* @__PURE__ */ 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: [
12407
11927
  /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12408
11928
  /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12409
11929
  'No items found for "',
@@ -12561,49 +12081,252 @@ const CustomAmountField = ({
12561
12081
  }
12562
12082
  );
12563
12083
  };
12564
- const TransferOwnership = () => {
12084
+ const ShippingAddress = () => {
12565
12085
  const { id } = useParams();
12566
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12567
- fields: "id,customer_id,customer.*"
12086
+ const { order, isPending, isError, error } = useOrder(id, {
12087
+ fields: "+shipping_address"
12568
12088
  });
12569
12089
  if (isError) {
12570
12090
  throw error;
12571
12091
  }
12572
- const isReady = !isPending && !!draft_order;
12092
+ const isReady = !isPending && !!order;
12573
12093
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12574
12094
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12575
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12576
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12095
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12096
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12577
12097
  ] }),
12578
- isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12098
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12579
12099
  ] });
12580
12100
  };
12581
- const TransferOwnershipForm = ({ order }) => {
12582
- var _a, _b;
12101
+ const ShippingAddressForm = ({ order }) => {
12102
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12583
12103
  const form = useForm({
12584
12104
  defaultValues: {
12585
- customer_id: order.customer_id || ""
12105
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12106
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12107
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12108
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12109
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12110
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12111
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12112
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12113
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12114
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12586
12115
  },
12587
- resolver: zodResolver(schema)
12116
+ resolver: zodResolver(schema$1)
12588
12117
  });
12589
12118
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12590
12119
  const { handleSuccess } = useRouteModal();
12591
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12592
- const currentCustomer = order.customer ? {
12593
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12594
- value: order.customer.id
12595
- } : null;
12596
12120
  const onSubmit = form.handleSubmit(async (data) => {
12597
12121
  await mutateAsync(
12598
- { customer_id: data.customer_id },
12599
12122
  {
12600
- onSuccess: () => {
12601
- toast.success("Customer updated");
12602
- handleSuccess();
12603
- },
12604
- onError: (error) => {
12605
- toast.error(error.message);
12606
- }
12123
+ shipping_address: {
12124
+ first_name: data.first_name,
12125
+ last_name: data.last_name,
12126
+ company: data.company,
12127
+ address_1: data.address_1,
12128
+ address_2: data.address_2,
12129
+ city: data.city,
12130
+ province: data.province,
12131
+ country_code: data.country_code,
12132
+ postal_code: data.postal_code,
12133
+ phone: data.phone
12134
+ }
12135
+ },
12136
+ {
12137
+ onSuccess: () => {
12138
+ handleSuccess();
12139
+ },
12140
+ onError: (error) => {
12141
+ toast.error(error.message);
12142
+ }
12143
+ }
12144
+ );
12145
+ });
12146
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12147
+ KeyboundForm,
12148
+ {
12149
+ className: "flex flex-1 flex-col overflow-hidden",
12150
+ onSubmit,
12151
+ children: [
12152
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12153
+ /* @__PURE__ */ jsx(
12154
+ Form$2.Field,
12155
+ {
12156
+ control: form.control,
12157
+ name: "country_code",
12158
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12159
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12160
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12161
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12162
+ ] })
12163
+ }
12164
+ ),
12165
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12166
+ /* @__PURE__ */ jsx(
12167
+ Form$2.Field,
12168
+ {
12169
+ control: form.control,
12170
+ name: "first_name",
12171
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12172
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12173
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12174
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12175
+ ] })
12176
+ }
12177
+ ),
12178
+ /* @__PURE__ */ jsx(
12179
+ Form$2.Field,
12180
+ {
12181
+ control: form.control,
12182
+ name: "last_name",
12183
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12184
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12185
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12186
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12187
+ ] })
12188
+ }
12189
+ )
12190
+ ] }),
12191
+ /* @__PURE__ */ jsx(
12192
+ Form$2.Field,
12193
+ {
12194
+ control: form.control,
12195
+ name: "company",
12196
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12197
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12198
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12199
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12200
+ ] })
12201
+ }
12202
+ ),
12203
+ /* @__PURE__ */ jsx(
12204
+ Form$2.Field,
12205
+ {
12206
+ control: form.control,
12207
+ name: "address_1",
12208
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12209
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12210
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12211
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12212
+ ] })
12213
+ }
12214
+ ),
12215
+ /* @__PURE__ */ jsx(
12216
+ Form$2.Field,
12217
+ {
12218
+ control: form.control,
12219
+ name: "address_2",
12220
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12221
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12222
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12223
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12224
+ ] })
12225
+ }
12226
+ ),
12227
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12228
+ /* @__PURE__ */ jsx(
12229
+ Form$2.Field,
12230
+ {
12231
+ control: form.control,
12232
+ name: "postal_code",
12233
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12234
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12235
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12236
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12237
+ ] })
12238
+ }
12239
+ ),
12240
+ /* @__PURE__ */ jsx(
12241
+ Form$2.Field,
12242
+ {
12243
+ control: form.control,
12244
+ name: "city",
12245
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12246
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12247
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12248
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12249
+ ] })
12250
+ }
12251
+ )
12252
+ ] }),
12253
+ /* @__PURE__ */ jsx(
12254
+ Form$2.Field,
12255
+ {
12256
+ control: form.control,
12257
+ name: "province",
12258
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12259
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12260
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12261
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12262
+ ] })
12263
+ }
12264
+ ),
12265
+ /* @__PURE__ */ jsx(
12266
+ Form$2.Field,
12267
+ {
12268
+ control: form.control,
12269
+ name: "phone",
12270
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12271
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12272
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12273
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12274
+ ] })
12275
+ }
12276
+ )
12277
+ ] }) }),
12278
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12279
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12280
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12281
+ ] }) })
12282
+ ]
12283
+ }
12284
+ ) });
12285
+ };
12286
+ const schema$1 = addressSchema;
12287
+ const TransferOwnership = () => {
12288
+ const { id } = useParams();
12289
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12290
+ fields: "id,customer_id,customer.*"
12291
+ });
12292
+ if (isError) {
12293
+ throw error;
12294
+ }
12295
+ const isReady = !isPending && !!draft_order;
12296
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12297
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12298
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Transfer Ownership" }) }),
12299
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12300
+ ] }),
12301
+ isReady && /* @__PURE__ */ jsx(TransferOwnershipForm, { order: draft_order })
12302
+ ] });
12303
+ };
12304
+ const TransferOwnershipForm = ({ order }) => {
12305
+ var _a, _b;
12306
+ const form = useForm({
12307
+ defaultValues: {
12308
+ customer_id: order.customer_id || ""
12309
+ },
12310
+ resolver: zodResolver(schema)
12311
+ });
12312
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12313
+ const { handleSuccess } = useRouteModal();
12314
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12315
+ const currentCustomer = order.customer ? {
12316
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12317
+ value: order.customer.id
12318
+ } : null;
12319
+ const onSubmit = form.handleSubmit(async (data) => {
12320
+ await mutateAsync(
12321
+ { customer_id: data.customer_id },
12322
+ {
12323
+ onSuccess: () => {
12324
+ toast.success("Customer updated");
12325
+ handleSuccess();
12326
+ },
12327
+ onError: (error) => {
12328
+ toast.error(error.message);
12329
+ }
12607
12330
  }
12608
12331
  );
12609
12332
  });
@@ -13037,6 +12760,283 @@ const Illustration = () => {
13037
12760
  const schema = objectType({
13038
12761
  customer_id: stringType().min(1)
13039
12762
  });
12763
+ const PROMOTION_QUERY_KEY = "promotions";
12764
+ const promotionsQueryKeys = {
12765
+ list: (query2) => [
12766
+ PROMOTION_QUERY_KEY,
12767
+ query2 ? query2 : void 0
12768
+ ],
12769
+ detail: (id, query2) => [
12770
+ PROMOTION_QUERY_KEY,
12771
+ id,
12772
+ query2 ? query2 : void 0
12773
+ ]
12774
+ };
12775
+ const usePromotions = (query2, options) => {
12776
+ const { data, ...rest } = useQuery({
12777
+ queryKey: promotionsQueryKeys.list(query2),
12778
+ queryFn: async () => sdk.admin.promotion.list(query2),
12779
+ ...options
12780
+ });
12781
+ return { ...data, ...rest };
12782
+ };
12783
+ const Promotions = () => {
12784
+ const { id } = useParams();
12785
+ const {
12786
+ order: preview,
12787
+ isError: isPreviewError,
12788
+ error: previewError
12789
+ } = useOrderPreview(id, void 0);
12790
+ useInitiateOrderEdit({ preview });
12791
+ const { onCancel } = useCancelOrderEdit({ preview });
12792
+ if (isPreviewError) {
12793
+ throw previewError;
12794
+ }
12795
+ const isReady = !!preview;
12796
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
12797
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
12798
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
12799
+ ] });
12800
+ };
12801
+ const PromotionForm = ({ preview }) => {
12802
+ const { items, shipping_methods } = preview;
12803
+ const [isSubmitting, setIsSubmitting] = useState(false);
12804
+ const [comboboxValue, setComboboxValue] = useState("");
12805
+ const { handleSuccess } = useRouteModal();
12806
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12807
+ const promoIds = getPromotionIds(items, shipping_methods);
12808
+ const { promotions, isPending, isError, error } = usePromotions(
12809
+ {
12810
+ id: promoIds
12811
+ },
12812
+ {
12813
+ enabled: !!promoIds.length
12814
+ }
12815
+ );
12816
+ const comboboxData = useComboboxData({
12817
+ queryKey: ["promotions", "combobox", promoIds],
12818
+ queryFn: async (params) => {
12819
+ return await sdk.admin.promotion.list({
12820
+ ...params,
12821
+ id: {
12822
+ $nin: promoIds
12823
+ }
12824
+ });
12825
+ },
12826
+ getOptions: (data) => {
12827
+ return data.promotions.map((promotion) => ({
12828
+ label: promotion.code,
12829
+ value: promotion.code
12830
+ }));
12831
+ }
12832
+ });
12833
+ const add = async (value) => {
12834
+ if (!value) {
12835
+ return;
12836
+ }
12837
+ addPromotions(
12838
+ {
12839
+ promo_codes: [value]
12840
+ },
12841
+ {
12842
+ onError: (e) => {
12843
+ toast.error(e.message);
12844
+ comboboxData.onSearchValueChange("");
12845
+ setComboboxValue("");
12846
+ },
12847
+ onSuccess: () => {
12848
+ comboboxData.onSearchValueChange("");
12849
+ setComboboxValue("");
12850
+ }
12851
+ }
12852
+ );
12853
+ };
12854
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12855
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12856
+ const onSubmit = async () => {
12857
+ setIsSubmitting(true);
12858
+ let requestSucceeded = false;
12859
+ await requestOrderEdit(void 0, {
12860
+ onError: (e) => {
12861
+ toast.error(e.message);
12862
+ },
12863
+ onSuccess: () => {
12864
+ requestSucceeded = true;
12865
+ }
12866
+ });
12867
+ if (!requestSucceeded) {
12868
+ setIsSubmitting(false);
12869
+ return;
12870
+ }
12871
+ await confirmOrderEdit(void 0, {
12872
+ onError: (e) => {
12873
+ toast.error(e.message);
12874
+ },
12875
+ onSuccess: () => {
12876
+ handleSuccess();
12877
+ },
12878
+ onSettled: () => {
12879
+ setIsSubmitting(false);
12880
+ }
12881
+ });
12882
+ };
12883
+ if (isError) {
12884
+ throw error;
12885
+ }
12886
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12887
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
12888
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
12889
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12890
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12891
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12892
+ ] }),
12893
+ /* @__PURE__ */ jsx(
12894
+ Combobox,
12895
+ {
12896
+ id: "promotion-combobox",
12897
+ "aria-describedby": "promotion-combobox-hint",
12898
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12899
+ fetchNextPage: comboboxData.fetchNextPage,
12900
+ options: comboboxData.options,
12901
+ onSearchValueChange: comboboxData.onSearchValueChange,
12902
+ searchValue: comboboxData.searchValue,
12903
+ disabled: comboboxData.disabled || isAddingPromotions,
12904
+ onChange: add,
12905
+ value: comboboxValue
12906
+ }
12907
+ )
12908
+ ] }),
12909
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12910
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
12911
+ PromotionItem,
12912
+ {
12913
+ promotion,
12914
+ orderId: preview.id,
12915
+ isLoading: isPending
12916
+ },
12917
+ promotion.id
12918
+ )) })
12919
+ ] }) }),
12920
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12921
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12922
+ /* @__PURE__ */ jsx(
12923
+ Button,
12924
+ {
12925
+ size: "small",
12926
+ type: "submit",
12927
+ isLoading: isSubmitting || isAddingPromotions,
12928
+ children: "Save"
12929
+ }
12930
+ )
12931
+ ] }) })
12932
+ ] });
12933
+ };
12934
+ const PromotionItem = ({
12935
+ promotion,
12936
+ orderId,
12937
+ isLoading
12938
+ }) => {
12939
+ var _a;
12940
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12941
+ const onRemove = async () => {
12942
+ removePromotions(
12943
+ {
12944
+ promo_codes: [promotion.code]
12945
+ },
12946
+ {
12947
+ onError: (e) => {
12948
+ toast.error(e.message);
12949
+ }
12950
+ }
12951
+ );
12952
+ };
12953
+ const displayValue = getDisplayValue(promotion);
12954
+ return /* @__PURE__ */ jsxs(
12955
+ "div",
12956
+ {
12957
+ className: clx(
12958
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12959
+ {
12960
+ "animate-pulse": isLoading
12961
+ }
12962
+ ),
12963
+ children: [
12964
+ /* @__PURE__ */ jsxs("div", { children: [
12965
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12966
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12967
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
12968
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
12969
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
12970
+ ] }),
12971
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12972
+ ] })
12973
+ ] }),
12974
+ /* @__PURE__ */ jsx(
12975
+ IconButton,
12976
+ {
12977
+ size: "small",
12978
+ type: "button",
12979
+ variant: "transparent",
12980
+ onClick: onRemove,
12981
+ isLoading: isPending || isLoading,
12982
+ children: /* @__PURE__ */ jsx(XMark, {})
12983
+ }
12984
+ )
12985
+ ]
12986
+ },
12987
+ promotion.id
12988
+ );
12989
+ };
12990
+ function getDisplayValue(promotion) {
12991
+ var _a, _b, _c, _d;
12992
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12993
+ if (!value) {
12994
+ return null;
12995
+ }
12996
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12997
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12998
+ if (!currency) {
12999
+ return null;
13000
+ }
13001
+ return getLocaleAmount(value, currency);
13002
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
13003
+ return formatPercentage(value);
13004
+ }
13005
+ return null;
13006
+ }
13007
+ const formatter = new Intl.NumberFormat([], {
13008
+ style: "percent",
13009
+ minimumFractionDigits: 2
13010
+ });
13011
+ const formatPercentage = (value, isPercentageValue = false) => {
13012
+ let val = value || 0;
13013
+ if (!isPercentageValue) {
13014
+ val = val / 100;
13015
+ }
13016
+ return formatter.format(val);
13017
+ };
13018
+ function getPromotionIds(items, shippingMethods) {
13019
+ const promotionIds = /* @__PURE__ */ new Set();
13020
+ for (const item of items) {
13021
+ if (item.adjustments) {
13022
+ for (const adjustment of item.adjustments) {
13023
+ if (adjustment.promotion_id) {
13024
+ promotionIds.add(adjustment.promotion_id);
13025
+ }
13026
+ }
13027
+ }
13028
+ }
13029
+ for (const shippingMethod of shippingMethods) {
13030
+ if (shippingMethod.adjustments) {
13031
+ for (const adjustment of shippingMethod.adjustments) {
13032
+ if (adjustment.promotion_id) {
13033
+ promotionIds.add(adjustment.promotion_id);
13034
+ }
13035
+ }
13036
+ }
13037
+ }
13038
+ return Array.from(promotionIds);
13039
+ }
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13058,16 +13058,16 @@ const routeModule = {
13058
13058
  loader,
13059
13059
  children: [
13060
13060
  {
13061
- Component: BillingAddress,
13062
- path: "/draft-orders/:id/billing-address"
13061
+ Component: CustomItems,
13062
+ path: "/draft-orders/:id/custom-items"
13063
13063
  },
13064
13064
  {
13065
13065
  Component: Email,
13066
13066
  path: "/draft-orders/:id/email"
13067
13067
  },
13068
13068
  {
13069
- Component: CustomItems,
13070
- path: "/draft-orders/:id/custom-items"
13069
+ Component: BillingAddress,
13070
+ path: "/draft-orders/:id/billing-address"
13071
13071
  },
13072
13072
  {
13073
13073
  Component: Items,
@@ -13077,25 +13077,25 @@ const routeModule = {
13077
13077
  Component: Metadata,
13078
13078
  path: "/draft-orders/:id/metadata"
13079
13079
  },
13080
- {
13081
- Component: Promotions,
13082
- path: "/draft-orders/:id/promotions"
13083
- },
13084
13080
  {
13085
13081
  Component: SalesChannel,
13086
13082
  path: "/draft-orders/:id/sales-channel"
13087
13083
  },
13088
- {
13089
- Component: ShippingAddress,
13090
- path: "/draft-orders/:id/shipping-address"
13091
- },
13092
13084
  {
13093
13085
  Component: Shipping,
13094
13086
  path: "/draft-orders/:id/shipping"
13095
13087
  },
13088
+ {
13089
+ Component: ShippingAddress,
13090
+ path: "/draft-orders/:id/shipping-address"
13091
+ },
13096
13092
  {
13097
13093
  Component: TransferOwnership,
13098
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
+ },
13096
+ {
13097
+ Component: Promotions,
13098
+ path: "/draft-orders/:id/promotions"
13099
13099
  }
13100
13100
  ]
13101
13101
  }