@medusajs/draft-order 2.10.2-snapshot-20250907131935 → 2.10.2-snapshot-20250908120151

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.
@@ -9763,6 +9763,95 @@ const BillingAddressForm = ({ order }) => {
9763
9763
  ) });
9764
9764
  };
9765
9765
  const schema$5 = addressSchema;
9766
+ const CustomItems = () => {
9767
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9769
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9770
+ ] });
9771
+ };
9772
+ const CustomItemsForm = () => {
9773
+ const form = reactHookForm.useForm({
9774
+ resolver: zod.zodResolver(schema$4)
9775
+ });
9776
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9778
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9779
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9780
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9781
+ ] }) })
9782
+ ] }) });
9783
+ };
9784
+ const schema$4 = objectType({
9785
+ email: stringType().email()
9786
+ });
9787
+ const Email = () => {
9788
+ const { id } = reactRouterDom.useParams();
9789
+ const { order, isPending, isError, error } = useOrder(id, {
9790
+ fields: "+email"
9791
+ });
9792
+ if (isError) {
9793
+ throw error;
9794
+ }
9795
+ const isReady = !isPending && !!order;
9796
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9797
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9798
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9799
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9800
+ ] }),
9801
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9802
+ ] });
9803
+ };
9804
+ const EmailForm = ({ order }) => {
9805
+ const form = reactHookForm.useForm({
9806
+ defaultValues: {
9807
+ email: order.email ?? ""
9808
+ },
9809
+ resolver: zod.zodResolver(schema$3)
9810
+ });
9811
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
+ const { handleSuccess } = useRouteModal();
9813
+ const onSubmit = form.handleSubmit(async (data) => {
9814
+ await mutateAsync(
9815
+ { email: data.email },
9816
+ {
9817
+ onSuccess: () => {
9818
+ handleSuccess();
9819
+ },
9820
+ onError: (error) => {
9821
+ ui.toast.error(error.message);
9822
+ }
9823
+ }
9824
+ );
9825
+ });
9826
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9827
+ KeyboundForm,
9828
+ {
9829
+ className: "flex flex-1 flex-col overflow-hidden",
9830
+ onSubmit,
9831
+ children: [
9832
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9833
+ Form$2.Field,
9834
+ {
9835
+ control: form.control,
9836
+ name: "email",
9837
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9838
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9839
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9840
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9841
+ ] })
9842
+ }
9843
+ ) }),
9844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
+ ] }) })
9848
+ ]
9849
+ }
9850
+ ) });
9851
+ };
9852
+ const schema$3 = objectType({
9853
+ email: stringType().email()
9854
+ });
9766
9855
  const NumberInput = React.forwardRef(
9767
9856
  ({
9768
9857
  value,
@@ -10737,95 +10826,6 @@ const customItemSchema = objectType({
10737
10826
  quantity: numberType(),
10738
10827
  unit_price: unionType([numberType(), stringType()])
10739
10828
  });
10740
- const Email = () => {
10741
- const { id } = reactRouterDom.useParams();
10742
- const { order, isPending, isError, error } = useOrder(id, {
10743
- fields: "+email"
10744
- });
10745
- if (isError) {
10746
- throw error;
10747
- }
10748
- const isReady = !isPending && !!order;
10749
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10750
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10751
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10752
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10753
- ] }),
10754
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10755
- ] });
10756
- };
10757
- const EmailForm = ({ order }) => {
10758
- const form = reactHookForm.useForm({
10759
- defaultValues: {
10760
- email: order.email ?? ""
10761
- },
10762
- resolver: zod.zodResolver(schema$4)
10763
- });
10764
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10765
- const { handleSuccess } = useRouteModal();
10766
- const onSubmit = form.handleSubmit(async (data) => {
10767
- await mutateAsync(
10768
- { email: data.email },
10769
- {
10770
- onSuccess: () => {
10771
- handleSuccess();
10772
- },
10773
- onError: (error) => {
10774
- ui.toast.error(error.message);
10775
- }
10776
- }
10777
- );
10778
- });
10779
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10780
- KeyboundForm,
10781
- {
10782
- className: "flex flex-1 flex-col overflow-hidden",
10783
- onSubmit,
10784
- children: [
10785
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10786
- Form$2.Field,
10787
- {
10788
- control: form.control,
10789
- name: "email",
10790
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10791
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10792
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10793
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10794
- ] })
10795
- }
10796
- ) }),
10797
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10798
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10799
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10800
- ] }) })
10801
- ]
10802
- }
10803
- ) });
10804
- };
10805
- const schema$4 = objectType({
10806
- email: stringType().email()
10807
- });
10808
- const CustomItems = () => {
10809
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10810
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
10811
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
10812
- ] });
10813
- };
10814
- const CustomItemsForm = () => {
10815
- const form = reactHookForm.useForm({
10816
- resolver: zod.zodResolver(schema$3)
10817
- });
10818
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10819
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
10820
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10821
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10822
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
10823
- ] }) })
10824
- ] }) });
10825
- };
10826
- const schema$3 = objectType({
10827
- email: stringType().email()
10828
- });
10829
10829
  const InlineTip = React.forwardRef(
10830
10830
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10831
10831
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11176,77 +11176,105 @@ function getHasUneditableRows(metadata) {
11176
11176
  (value) => !EDITABLE_TYPES.includes(typeof value)
11177
11177
  );
11178
11178
  }
11179
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11180
- const Shipping = () => {
11181
- var _a;
11182
- const { id } = reactRouterDom.useParams();
11183
- const { order, isPending, isError, error } = useOrder(id, {
11184
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11179
+ const PROMOTION_QUERY_KEY = "promotions";
11180
+ const promotionsQueryKeys = {
11181
+ list: (query2) => [
11182
+ PROMOTION_QUERY_KEY,
11183
+ query2 ? query2 : void 0
11184
+ ],
11185
+ detail: (id, query2) => [
11186
+ PROMOTION_QUERY_KEY,
11187
+ id,
11188
+ query2 ? query2 : void 0
11189
+ ]
11190
+ };
11191
+ const usePromotions = (query2, options) => {
11192
+ const { data, ...rest } = reactQuery.useQuery({
11193
+ queryKey: promotionsQueryKeys.list(query2),
11194
+ queryFn: async () => sdk.admin.promotion.list(query2),
11195
+ ...options
11185
11196
  });
11197
+ return { ...data, ...rest };
11198
+ };
11199
+ const Promotions = () => {
11200
+ const { id } = reactRouterDom.useParams();
11186
11201
  const {
11187
11202
  order: preview,
11188
- isPending: isPreviewPending,
11189
11203
  isError: isPreviewError,
11190
11204
  error: previewError
11191
- } = useOrderPreview(id);
11205
+ } = useOrderPreview(id, void 0);
11192
11206
  useInitiateOrderEdit({ preview });
11193
11207
  const { onCancel } = useCancelOrderEdit({ preview });
11194
- if (isError) {
11195
- throw error;
11196
- }
11197
11208
  if (isPreviewError) {
11198
11209
  throw previewError;
11199
11210
  }
11200
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11201
- const isReady = preview && !isPreviewPending && order && !isPending;
11202
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11203
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11204
- /* @__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: [
11205
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11206
- /* @__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." }) })
11207
- ] }) }) }),
11208
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11209
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11210
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11211
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11212
- ] }) });
11211
+ const isReady = !!preview;
11212
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11213
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11214
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11215
+ ] });
11213
11216
  };
11214
- const ShippingForm = ({ preview, order }) => {
11215
- var _a;
11216
- const { setIsOpen } = useStackedModal();
11217
+ const PromotionForm = ({ preview }) => {
11218
+ const { items, shipping_methods } = preview;
11217
11219
  const [isSubmitting, setIsSubmitting] = React.useState(false);
11218
- const [data, setData] = React.useState(null);
11219
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11220
- const { shipping_options } = useShippingOptions(
11220
+ const [comboboxValue, setComboboxValue] = React.useState("");
11221
+ const { handleSuccess } = useRouteModal();
11222
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11223
+ const promoIds = getPromotionIds(items, shipping_methods);
11224
+ const { promotions, isPending, isError, error } = usePromotions(
11221
11225
  {
11222
- id: appliedShippingOptionIds,
11223
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11226
+ id: promoIds
11224
11227
  },
11225
11228
  {
11226
- enabled: appliedShippingOptionIds.length > 0
11229
+ enabled: !!promoIds.length
11227
11230
  }
11228
11231
  );
11229
- const uniqueShippingProfiles = React.useMemo(() => {
11230
- const profiles = /* @__PURE__ */ new Map();
11231
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11232
- profiles.set(profile.id, profile);
11233
- });
11234
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11235
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11236
- });
11237
- return Array.from(profiles.values());
11238
- }, [order.items, shipping_options]);
11239
- const { handleSuccess } = useRouteModal();
11232
+ const comboboxData = useComboboxData({
11233
+ queryKey: ["promotions", "combobox", promoIds],
11234
+ queryFn: async (params) => {
11235
+ return await sdk.admin.promotion.list({
11236
+ ...params,
11237
+ id: {
11238
+ $nin: promoIds
11239
+ }
11240
+ });
11241
+ },
11242
+ getOptions: (data) => {
11243
+ return data.promotions.map((promotion) => ({
11244
+ label: promotion.code,
11245
+ value: promotion.code
11246
+ }));
11247
+ }
11248
+ });
11249
+ const add = async (value) => {
11250
+ if (!value) {
11251
+ return;
11252
+ }
11253
+ addPromotions(
11254
+ {
11255
+ promo_codes: [value]
11256
+ },
11257
+ {
11258
+ onError: (e) => {
11259
+ ui.toast.error(e.message);
11260
+ comboboxData.onSearchValueChange("");
11261
+ setComboboxValue("");
11262
+ },
11263
+ onSuccess: () => {
11264
+ comboboxData.onSearchValueChange("");
11265
+ setComboboxValue("");
11266
+ }
11267
+ }
11268
+ );
11269
+ };
11240
11270
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11241
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11242
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11243
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11271
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11244
11272
  const onSubmit = async () => {
11245
11273
  setIsSubmitting(true);
11246
11274
  let requestSucceeded = false;
11247
11275
  await requestOrderEdit(void 0, {
11248
11276
  onError: (e) => {
11249
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11277
+ ui.toast.error(e.message);
11250
11278
  },
11251
11279
  onSuccess: () => {
11252
11280
  requestSucceeded = true;
@@ -11258,7 +11286,7 @@ const ShippingForm = ({ preview, order }) => {
11258
11286
  }
11259
11287
  await confirmOrderEdit(void 0, {
11260
11288
  onError: (e) => {
11261
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11289
+ ui.toast.error(e.message);
11262
11290
  },
11263
11291
  onSuccess: () => {
11264
11292
  handleSuccess();
@@ -11268,1307 +11296,1279 @@ const ShippingForm = ({ preview, order }) => {
11268
11296
  }
11269
11297
  });
11270
11298
  };
11271
- const onKeydown = React.useCallback(
11272
- (e) => {
11273
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11274
- if (data || isSubmitting) {
11275
- return;
11299
+ if (isError) {
11300
+ throw error;
11301
+ }
11302
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11305
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11306
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11307
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11308
+ ] }),
11309
+ /* @__PURE__ */ jsxRuntime.jsx(
11310
+ Combobox,
11311
+ {
11312
+ id: "promotion-combobox",
11313
+ "aria-describedby": "promotion-combobox-hint",
11314
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11315
+ fetchNextPage: comboboxData.fetchNextPage,
11316
+ options: comboboxData.options,
11317
+ onSearchValueChange: comboboxData.onSearchValueChange,
11318
+ searchValue: comboboxData.searchValue,
11319
+ disabled: comboboxData.disabled || isAddingPromotions,
11320
+ onChange: add,
11321
+ value: comboboxValue
11322
+ }
11323
+ )
11324
+ ] }),
11325
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11326
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11327
+ PromotionItem,
11328
+ {
11329
+ promotion,
11330
+ orderId: preview.id,
11331
+ isLoading: isPending
11332
+ },
11333
+ promotion.id
11334
+ )) })
11335
+ ] }) }),
11336
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11337
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11338
+ /* @__PURE__ */ jsxRuntime.jsx(
11339
+ ui.Button,
11340
+ {
11341
+ size: "small",
11342
+ type: "submit",
11343
+ isLoading: isSubmitting || isAddingPromotions,
11344
+ children: "Save"
11345
+ }
11346
+ )
11347
+ ] }) })
11348
+ ] });
11349
+ };
11350
+ const PromotionItem = ({
11351
+ promotion,
11352
+ orderId,
11353
+ isLoading
11354
+ }) => {
11355
+ var _a;
11356
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11357
+ const onRemove = async () => {
11358
+ removePromotions(
11359
+ {
11360
+ promo_codes: [promotion.code]
11361
+ },
11362
+ {
11363
+ onError: (e) => {
11364
+ ui.toast.error(e.message);
11276
11365
  }
11277
- onSubmit();
11278
11366
  }
11279
- },
11280
- [data, isSubmitting, onSubmit]
11281
- );
11282
- React.useEffect(() => {
11283
- document.addEventListener("keydown", onKeydown);
11284
- return () => {
11285
- document.removeEventListener("keydown", onKeydown);
11286
- };
11287
- }, [onKeydown]);
11288
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11289
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11290
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11291
- /* @__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: [
11367
+ );
11368
+ };
11369
+ const displayValue = getDisplayValue(promotion);
11370
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11371
+ "div",
11372
+ {
11373
+ className: ui.clx(
11374
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11375
+ {
11376
+ "animate-pulse": isLoading
11377
+ }
11378
+ ),
11379
+ children: [
11292
11380
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11293
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11294
- /* @__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." }) })
11381
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11382
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11383
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11384
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11385
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11386
+ ] }),
11387
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11388
+ ] })
11295
11389
  ] }),
11296
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11297
- /* @__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: [
11298
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11299
- /* @__PURE__ */ jsxRuntime.jsx(
11300
- ui.Text,
11301
- {
11302
- size: "xsmall",
11303
- weight: "plus",
11304
- className: "text-ui-fg-muted",
11305
- children: "Shipping profile"
11306
- }
11307
- ),
11308
- /* @__PURE__ */ jsxRuntime.jsx(
11309
- ui.Text,
11310
- {
11311
- size: "xsmall",
11312
- weight: "plus",
11313
- className: "text-ui-fg-muted",
11314
- children: "Action"
11315
- }
11316
- )
11317
- ] }),
11318
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11319
- var _a2, _b, _c, _d, _e, _f, _g;
11320
- const items = getItemsWithShippingProfile(
11321
- profile.id,
11322
- order.items
11323
- );
11324
- const hasItems = items.length > 0;
11325
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11326
- (option) => option.shipping_profile_id === profile.id
11327
- );
11328
- const shippingMethod = preview.shipping_methods.find(
11329
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11330
- );
11331
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11332
- (action) => action.action === "SHIPPING_ADD"
11333
- );
11334
- return /* @__PURE__ */ jsxRuntime.jsxs(
11335
- radixUi.Accordion.Item,
11336
- {
11337
- value: profile.id,
11338
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11339
- children: [
11340
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11341
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11342
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11343
- ui.IconButton,
11344
- {
11345
- size: "2xsmall",
11346
- variant: "transparent",
11347
- className: "group/trigger",
11348
- disabled: !hasItems,
11349
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11350
- }
11351
- ) }),
11352
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11353
- /* @__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" }) }) }),
11354
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11355
- /* @__PURE__ */ jsxRuntime.jsx(
11356
- ui.Text,
11357
- {
11358
- size: "small",
11359
- weight: "plus",
11360
- leading: "compact",
11361
- children: profile.name
11362
- }
11363
- ),
11364
- /* @__PURE__ */ jsxRuntime.jsxs(
11365
- ui.Text,
11366
- {
11367
- size: "small",
11368
- leading: "compact",
11369
- className: "text-ui-fg-subtle",
11370
- children: [
11371
- items.length,
11372
- " ",
11373
- pluralize(items.length, "items", "item")
11374
- ]
11375
- }
11376
- )
11377
- ] })
11378
- ] }) : /* @__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: [
11379
- /* @__PURE__ */ jsxRuntime.jsx(
11380
- ui.Tooltip,
11381
- {
11382
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11383
- var _a3, _b2, _c2;
11384
- return /* @__PURE__ */ jsxRuntime.jsx(
11385
- "li",
11386
- {
11387
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11388
- },
11389
- item.id
11390
- );
11391
- }) }),
11392
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11393
- ui.Badge,
11394
- {
11395
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11396
- size: "xsmall",
11397
- children: [
11398
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11399
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11400
- items.reduce(
11401
- (acc, item) => acc + item.quantity,
11402
- 0
11403
- ),
11404
- "x",
11405
- " ",
11406
- pluralize(items.length, "items", "item")
11407
- ] })
11408
- ]
11409
- }
11410
- )
11411
- }
11412
- ),
11413
- /* @__PURE__ */ jsxRuntime.jsx(
11414
- ui.Tooltip,
11415
- {
11416
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11417
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11418
- ui.Badge,
11419
- {
11420
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11421
- size: "xsmall",
11422
- children: [
11423
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11424
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11425
- ]
11426
- }
11427
- )
11428
- }
11429
- ),
11430
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11431
- ui.Badge,
11432
- {
11433
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11434
- size: "xsmall",
11435
- children: [
11436
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11437
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11438
- ]
11439
- }
11440
- ) })
11441
- ] })
11442
- ] }),
11443
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11444
- ActionMenu,
11445
- {
11446
- groups: [
11447
- {
11448
- actions: [
11449
- hasItems ? {
11450
- label: "Edit shipping option",
11451
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11452
- onClick: () => {
11453
- setIsOpen(
11454
- STACKED_FOCUS_MODAL_ID,
11455
- true
11456
- );
11457
- setData({
11458
- shippingProfileId: profile.id,
11459
- shippingOption,
11460
- shippingMethod
11461
- });
11462
- }
11463
- } : void 0,
11464
- {
11465
- label: "Remove shipping option",
11466
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11467
- onClick: () => {
11468
- if (shippingMethod) {
11469
- if (addShippingMethodAction) {
11470
- removeActionShippingMethod(
11471
- addShippingMethodAction.id
11472
- );
11473
- } else {
11474
- removeShippingMethod(
11475
- shippingMethod.id
11476
- );
11477
- }
11478
- }
11479
- }
11480
- }
11481
- ].filter(Boolean)
11482
- }
11483
- ]
11484
- }
11485
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11486
- StackedModalTrigger,
11487
- {
11488
- shippingProfileId: profile.id,
11489
- shippingOption,
11490
- shippingMethod,
11491
- setData,
11492
- children: "Add shipping option"
11493
- }
11494
- )
11495
- ] }),
11496
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11498
- items.map((item, idx) => {
11499
- var _a3, _b2, _c2, _d2, _e2;
11500
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11501
- /* @__PURE__ */ jsxRuntime.jsxs(
11502
- "div",
11503
- {
11504
- className: "px-3 flex items-center gap-x-3",
11505
- children: [
11506
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11507
- ui.Divider,
11508
- {
11509
- variant: "dashed",
11510
- orientation: "vertical"
11511
- }
11512
- ) }),
11513
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11514
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11515
- ui.Text,
11516
- {
11517
- size: "small",
11518
- leading: "compact",
11519
- className: "text-ui-fg-subtle",
11520
- children: [
11521
- item.quantity,
11522
- "x"
11523
- ]
11524
- }
11525
- ) }),
11526
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11527
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11528
- /* @__PURE__ */ jsxRuntime.jsxs(
11529
- ui.Text,
11530
- {
11531
- size: "small",
11532
- leading: "compact",
11533
- weight: "plus",
11534
- children: [
11535
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11536
- " (",
11537
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11538
- ")"
11539
- ]
11540
- }
11541
- ),
11542
- /* @__PURE__ */ jsxRuntime.jsx(
11543
- ui.Text,
11544
- {
11545
- size: "small",
11546
- leading: "compact",
11547
- className: "text-ui-fg-subtle",
11548
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11549
- }
11550
- )
11551
- ] })
11552
- ] })
11553
- ]
11554
- },
11555
- item.id
11556
- ),
11557
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11558
- ] }, item.id);
11559
- })
11560
- ] })
11561
- ]
11562
- },
11563
- profile.id
11564
- );
11565
- }) })
11566
- ] }) })
11567
- ] }) }),
11568
- /* @__PURE__ */ jsxRuntime.jsx(
11569
- StackedFocusModal,
11570
- {
11571
- id: STACKED_FOCUS_MODAL_ID,
11572
- onOpenChangeCallback: (open) => {
11573
- if (!open) {
11574
- setData(null);
11575
- }
11576
- return open;
11577
- },
11578
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11390
+ /* @__PURE__ */ jsxRuntime.jsx(
11391
+ ui.IconButton,
11392
+ {
11393
+ size: "small",
11394
+ type: "button",
11395
+ variant: "transparent",
11396
+ onClick: onRemove,
11397
+ isLoading: isPending || isLoading,
11398
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11399
+ }
11400
+ )
11401
+ ]
11402
+ },
11403
+ promotion.id
11404
+ );
11405
+ };
11406
+ function getDisplayValue(promotion) {
11407
+ var _a, _b, _c, _d;
11408
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11409
+ if (!value) {
11410
+ return null;
11411
+ }
11412
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11413
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11414
+ if (!currency) {
11415
+ return null;
11416
+ }
11417
+ return getLocaleAmount(value, currency);
11418
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11419
+ return formatPercentage(value);
11420
+ }
11421
+ return null;
11422
+ }
11423
+ const formatter = new Intl.NumberFormat([], {
11424
+ style: "percent",
11425
+ minimumFractionDigits: 2
11426
+ });
11427
+ const formatPercentage = (value, isPercentageValue = false) => {
11428
+ let val = value || 0;
11429
+ if (!isPercentageValue) {
11430
+ val = val / 100;
11431
+ }
11432
+ return formatter.format(val);
11433
+ };
11434
+ function getPromotionIds(items, shippingMethods) {
11435
+ const promotionIds = /* @__PURE__ */ new Set();
11436
+ for (const item of items) {
11437
+ if (item.adjustments) {
11438
+ for (const adjustment of item.adjustments) {
11439
+ if (adjustment.promotion_id) {
11440
+ promotionIds.add(adjustment.promotion_id);
11579
11441
  }
11580
- )
11581
- ] }),
11582
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11583
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11584
- /* @__PURE__ */ jsxRuntime.jsx(
11585
- ui.Button,
11586
- {
11587
- size: "small",
11588
- type: "button",
11589
- isLoading: isSubmitting,
11590
- onClick: onSubmit,
11591
- children: "Save"
11442
+ }
11443
+ }
11444
+ }
11445
+ for (const shippingMethod of shippingMethods) {
11446
+ if (shippingMethod.adjustments) {
11447
+ for (const adjustment of shippingMethod.adjustments) {
11448
+ if (adjustment.promotion_id) {
11449
+ promotionIds.add(adjustment.promotion_id);
11592
11450
  }
11593
- )
11594
- ] }) })
11595
- ] });
11596
- };
11597
- const StackedModalTrigger = ({
11598
- shippingProfileId,
11599
- shippingOption,
11600
- shippingMethod,
11601
- setData,
11602
- children
11603
- }) => {
11604
- const { setIsOpen, getIsOpen } = useStackedModal();
11605
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11606
- const onToggle = () => {
11607
- if (isOpen) {
11608
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11609
- setData(null);
11610
- } else {
11611
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11612
- setData({
11613
- shippingProfileId,
11614
- shippingOption,
11615
- shippingMethod
11616
- });
11451
+ }
11617
11452
  }
11618
- };
11619
- return /* @__PURE__ */ jsxRuntime.jsx(
11620
- ui.Button,
11453
+ }
11454
+ return Array.from(promotionIds);
11455
+ }
11456
+ const SalesChannel = () => {
11457
+ const { id } = reactRouterDom.useParams();
11458
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11459
+ id,
11621
11460
  {
11622
- size: "small",
11623
- variant: "secondary",
11624
- onClick: onToggle,
11625
- className: "text-ui-fg-primary shrink-0",
11626
- children
11461
+ fields: "+sales_channel_id"
11462
+ },
11463
+ {
11464
+ enabled: !!id
11627
11465
  }
11628
11466
  );
11467
+ if (isError) {
11468
+ throw error;
11469
+ }
11470
+ const ISrEADY = !!draft_order && !isPending;
11471
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11474
+ /* @__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" }) })
11475
+ ] }),
11476
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11477
+ ] });
11629
11478
  };
11630
- const ShippingProfileForm = ({
11631
- data,
11632
- order,
11633
- preview
11634
- }) => {
11635
- var _a, _b, _c, _d, _e, _f;
11636
- const { setIsOpen } = useStackedModal();
11479
+ const SalesChannelForm = ({ order }) => {
11637
11480
  const form = reactHookForm.useForm({
11638
- resolver: zod.zodResolver(shippingMethodSchema),
11639
11481
  defaultValues: {
11640
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11641
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11642
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11643
- }
11644
- });
11645
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11646
- const {
11647
- mutateAsync: updateShippingMethod,
11648
- isPending: isUpdatingShippingMethod
11649
- } = useDraftOrderUpdateShippingMethod(order.id);
11650
- const onSubmit = form.handleSubmit(async (values) => {
11651
- if (lodash.isEqual(values, form.formState.defaultValues)) {
11652
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11653
- return;
11654
- }
11655
- if (data.shippingMethod) {
11656
- await updateShippingMethod(
11657
- {
11658
- method_id: data.shippingMethod.id,
11659
- shipping_option_id: values.shipping_option_id,
11660
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11661
- },
11662
- {
11663
- onError: (e) => {
11664
- ui.toast.error(e.message);
11665
- },
11666
- onSuccess: () => {
11667
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11668
- }
11669
- }
11670
- );
11671
- return;
11672
- }
11673
- await addShippingMethod(
11482
+ sales_channel_id: order.sales_channel_id || ""
11483
+ },
11484
+ resolver: zod.zodResolver(schema$2)
11485
+ });
11486
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11487
+ const { handleSuccess } = useRouteModal();
11488
+ const onSubmit = form.handleSubmit(async (data) => {
11489
+ await mutateAsync(
11674
11490
  {
11675
- shipping_option_id: values.shipping_option_id,
11676
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11491
+ sales_channel_id: data.sales_channel_id
11677
11492
  },
11678
11493
  {
11679
- onError: (e) => {
11680
- ui.toast.error(e.message);
11681
- },
11682
11494
  onSuccess: () => {
11683
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11495
+ ui.toast.success("Sales channel updated");
11496
+ handleSuccess();
11497
+ },
11498
+ onError: (error) => {
11499
+ ui.toast.error(error.message);
11684
11500
  }
11685
11501
  }
11686
11502
  );
11687
11503
  });
11688
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11504
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11689
11505
  KeyboundForm,
11690
11506
  {
11691
- className: "flex h-full flex-col overflow-hidden",
11507
+ className: "flex flex-1 flex-col overflow-hidden",
11692
11508
  onSubmit,
11693
11509
  children: [
11694
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11695
- /* @__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: [
11696
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11697
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11698
- /* @__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." }) })
11699
- ] }),
11700
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11701
- /* @__PURE__ */ jsxRuntime.jsx(
11702
- LocationField,
11703
- {
11704
- control: form.control,
11705
- setValue: form.setValue
11706
- }
11707
- ),
11708
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11709
- /* @__PURE__ */ jsxRuntime.jsx(
11710
- ShippingOptionField,
11711
- {
11712
- shippingProfileId: data.shippingProfileId,
11713
- preview,
11714
- control: form.control
11715
- }
11716
- ),
11717
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11718
- /* @__PURE__ */ jsxRuntime.jsx(
11719
- CustomAmountField,
11720
- {
11721
- control: form.control,
11722
- currencyCode: order.currency_code
11723
- }
11724
- ),
11725
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11726
- /* @__PURE__ */ jsxRuntime.jsx(
11727
- ItemsPreview,
11728
- {
11729
- order,
11730
- shippingProfileId: data.shippingProfileId
11731
- }
11732
- )
11733
- ] }) }) }),
11734
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11735
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11736
- /* @__PURE__ */ jsxRuntime.jsx(
11737
- ui.Button,
11738
- {
11739
- size: "small",
11740
- type: "submit",
11741
- isLoading: isPending || isUpdatingShippingMethod,
11742
- children: data.shippingMethod ? "Update" : "Add"
11743
- }
11744
- )
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11512
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11513
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11745
11514
  ] }) })
11746
11515
  ]
11747
11516
  }
11748
- ) }) });
11517
+ ) });
11749
11518
  };
11750
- const shippingMethodSchema = objectType({
11751
- location_id: stringType(),
11752
- shipping_option_id: stringType(),
11753
- custom_amount: unionType([numberType(), stringType()]).optional()
11519
+ const SalesChannelField = ({ control, order }) => {
11520
+ const salesChannels = useComboboxData({
11521
+ queryFn: async (params) => {
11522
+ return await sdk.admin.salesChannel.list(params);
11523
+ },
11524
+ queryKey: ["sales-channels"],
11525
+ getOptions: (data) => {
11526
+ return data.sales_channels.map((salesChannel) => ({
11527
+ label: salesChannel.name,
11528
+ value: salesChannel.id
11529
+ }));
11530
+ },
11531
+ defaultValue: order.sales_channel_id || void 0
11532
+ });
11533
+ return /* @__PURE__ */ jsxRuntime.jsx(
11534
+ Form$2.Field,
11535
+ {
11536
+ control,
11537
+ name: "sales_channel_id",
11538
+ render: ({ field }) => {
11539
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11541
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11542
+ Combobox,
11543
+ {
11544
+ options: salesChannels.options,
11545
+ fetchNextPage: salesChannels.fetchNextPage,
11546
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11547
+ searchValue: salesChannels.searchValue,
11548
+ onSearchValueChange: salesChannels.onSearchValueChange,
11549
+ placeholder: "Select sales channel",
11550
+ ...field
11551
+ }
11552
+ ) }),
11553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11554
+ ] });
11555
+ }
11556
+ }
11557
+ );
11558
+ };
11559
+ const schema$2 = objectType({
11560
+ sales_channel_id: stringType().min(1)
11754
11561
  });
11755
- const ItemsPreview = ({ order, shippingProfileId }) => {
11756
- const matches = order.items.filter(
11757
- (item) => {
11758
- var _a, _b, _c;
11759
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11562
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11563
+ const Shipping = () => {
11564
+ var _a;
11565
+ const { id } = reactRouterDom.useParams();
11566
+ const { order, isPending, isError, error } = useOrder(id, {
11567
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11568
+ });
11569
+ const {
11570
+ order: preview,
11571
+ isPending: isPreviewPending,
11572
+ isError: isPreviewError,
11573
+ error: previewError
11574
+ } = useOrderPreview(id);
11575
+ useInitiateOrderEdit({ preview });
11576
+ const { onCancel } = useCancelOrderEdit({ preview });
11577
+ if (isError) {
11578
+ throw error;
11579
+ }
11580
+ if (isPreviewError) {
11581
+ throw previewError;
11582
+ }
11583
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11584
+ const isReady = preview && !isPreviewPending && order && !isPending;
11585
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11587
+ /* @__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: [
11588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11589
+ /* @__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." }) })
11590
+ ] }) }) }),
11591
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11592
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11594
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11595
+ ] }) });
11596
+ };
11597
+ const ShippingForm = ({ preview, order }) => {
11598
+ var _a;
11599
+ const { setIsOpen } = useStackedModal();
11600
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11601
+ const [data, setData] = React.useState(null);
11602
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11603
+ const { shipping_options } = useShippingOptions(
11604
+ {
11605
+ id: appliedShippingOptionIds,
11606
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11607
+ },
11608
+ {
11609
+ enabled: appliedShippingOptionIds.length > 0
11760
11610
  }
11761
11611
  );
11762
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11763
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11764
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11765
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11766
- ] }) }),
11767
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11768
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11769
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11770
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11771
- ] }),
11772
- /* @__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(
11773
- "div",
11774
- {
11775
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11776
- children: [
11777
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11778
- /* @__PURE__ */ jsxRuntime.jsx(
11779
- Thumbnail,
11780
- {
11781
- thumbnail: item.thumbnail,
11782
- alt: item.product_title ?? void 0
11783
- }
11784
- ),
11785
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11786
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11787
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11788
- /* @__PURE__ */ jsxRuntime.jsxs(
11789
- ui.Text,
11790
- {
11791
- size: "small",
11792
- leading: "compact",
11793
- className: "text-ui-fg-subtle",
11794
- children: [
11795
- "(",
11796
- item.variant_title,
11797
- ")"
11798
- ]
11799
- }
11800
- )
11801
- ] }),
11802
- /* @__PURE__ */ jsxRuntime.jsx(
11803
- ui.Text,
11804
- {
11805
- size: "small",
11806
- leading: "compact",
11807
- className: "text-ui-fg-subtle",
11808
- children: item.variant_sku
11809
- }
11810
- )
11811
- ] })
11812
- ] }),
11813
- /* @__PURE__ */ jsxRuntime.jsxs(
11612
+ const uniqueShippingProfiles = React.useMemo(() => {
11613
+ const profiles = /* @__PURE__ */ new Map();
11614
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11615
+ profiles.set(profile.id, profile);
11616
+ });
11617
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11618
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11619
+ });
11620
+ return Array.from(profiles.values());
11621
+ }, [order.items, shipping_options]);
11622
+ const { handleSuccess } = useRouteModal();
11623
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11624
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11625
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11626
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11627
+ const onSubmit = async () => {
11628
+ setIsSubmitting(true);
11629
+ let requestSucceeded = false;
11630
+ await requestOrderEdit(void 0, {
11631
+ onError: (e) => {
11632
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11633
+ },
11634
+ onSuccess: () => {
11635
+ requestSucceeded = true;
11636
+ }
11637
+ });
11638
+ if (!requestSucceeded) {
11639
+ setIsSubmitting(false);
11640
+ return;
11641
+ }
11642
+ await confirmOrderEdit(void 0, {
11643
+ onError: (e) => {
11644
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11645
+ },
11646
+ onSuccess: () => {
11647
+ handleSuccess();
11648
+ },
11649
+ onSettled: () => {
11650
+ setIsSubmitting(false);
11651
+ }
11652
+ });
11653
+ };
11654
+ const onKeydown = React.useCallback(
11655
+ (e) => {
11656
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11657
+ if (data || isSubmitting) {
11658
+ return;
11659
+ }
11660
+ onSubmit();
11661
+ }
11662
+ },
11663
+ [data, isSubmitting, onSubmit]
11664
+ );
11665
+ React.useEffect(() => {
11666
+ document.addEventListener("keydown", onKeydown);
11667
+ return () => {
11668
+ document.removeEventListener("keydown", onKeydown);
11669
+ };
11670
+ }, [onKeydown]);
11671
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11672
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11673
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11674
+ /* @__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: [
11675
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11676
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11677
+ /* @__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." }) })
11678
+ ] }),
11679
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11680
+ /* @__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: [
11681
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11682
+ /* @__PURE__ */ jsxRuntime.jsx(
11814
11683
  ui.Text,
11815
11684
  {
11816
- size: "small",
11817
- leading: "compact",
11818
- className: "text-ui-fg-subtle",
11685
+ size: "xsmall",
11686
+ weight: "plus",
11687
+ className: "text-ui-fg-muted",
11688
+ children: "Shipping profile"
11689
+ }
11690
+ ),
11691
+ /* @__PURE__ */ jsxRuntime.jsx(
11692
+ ui.Text,
11693
+ {
11694
+ size: "xsmall",
11695
+ weight: "plus",
11696
+ className: "text-ui-fg-muted",
11697
+ children: "Action"
11698
+ }
11699
+ )
11700
+ ] }),
11701
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11702
+ var _a2, _b, _c, _d, _e, _f, _g;
11703
+ const items = getItemsWithShippingProfile(
11704
+ profile.id,
11705
+ order.items
11706
+ );
11707
+ const hasItems = items.length > 0;
11708
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11709
+ (option) => option.shipping_profile_id === profile.id
11710
+ );
11711
+ const shippingMethod = preview.shipping_methods.find(
11712
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11713
+ );
11714
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11715
+ (action) => action.action === "SHIPPING_ADD"
11716
+ );
11717
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11718
+ radixUi.Accordion.Item,
11719
+ {
11720
+ value: profile.id,
11721
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11819
11722
  children: [
11820
- item.quantity,
11821
- "x"
11723
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11724
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11725
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11726
+ ui.IconButton,
11727
+ {
11728
+ size: "2xsmall",
11729
+ variant: "transparent",
11730
+ className: "group/trigger",
11731
+ disabled: !hasItems,
11732
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11733
+ }
11734
+ ) }),
11735
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11736
+ /* @__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" }) }) }),
11737
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11738
+ /* @__PURE__ */ jsxRuntime.jsx(
11739
+ ui.Text,
11740
+ {
11741
+ size: "small",
11742
+ weight: "plus",
11743
+ leading: "compact",
11744
+ children: profile.name
11745
+ }
11746
+ ),
11747
+ /* @__PURE__ */ jsxRuntime.jsxs(
11748
+ ui.Text,
11749
+ {
11750
+ size: "small",
11751
+ leading: "compact",
11752
+ className: "text-ui-fg-subtle",
11753
+ children: [
11754
+ items.length,
11755
+ " ",
11756
+ pluralize(items.length, "items", "item")
11757
+ ]
11758
+ }
11759
+ )
11760
+ ] })
11761
+ ] }) : /* @__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: [
11762
+ /* @__PURE__ */ jsxRuntime.jsx(
11763
+ ui.Tooltip,
11764
+ {
11765
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11766
+ var _a3, _b2, _c2;
11767
+ return /* @__PURE__ */ jsxRuntime.jsx(
11768
+ "li",
11769
+ {
11770
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11771
+ },
11772
+ item.id
11773
+ );
11774
+ }) }),
11775
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11776
+ ui.Badge,
11777
+ {
11778
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11779
+ size: "xsmall",
11780
+ children: [
11781
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11782
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11783
+ items.reduce(
11784
+ (acc, item) => acc + item.quantity,
11785
+ 0
11786
+ ),
11787
+ "x",
11788
+ " ",
11789
+ pluralize(items.length, "items", "item")
11790
+ ] })
11791
+ ]
11792
+ }
11793
+ )
11794
+ }
11795
+ ),
11796
+ /* @__PURE__ */ jsxRuntime.jsx(
11797
+ ui.Tooltip,
11798
+ {
11799
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11800
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11801
+ ui.Badge,
11802
+ {
11803
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11804
+ size: "xsmall",
11805
+ children: [
11806
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11807
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11808
+ ]
11809
+ }
11810
+ )
11811
+ }
11812
+ ),
11813
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11814
+ ui.Badge,
11815
+ {
11816
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11817
+ size: "xsmall",
11818
+ children: [
11819
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11820
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11821
+ ]
11822
+ }
11823
+ ) })
11824
+ ] })
11825
+ ] }),
11826
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11827
+ ActionMenu,
11828
+ {
11829
+ groups: [
11830
+ {
11831
+ actions: [
11832
+ hasItems ? {
11833
+ label: "Edit shipping option",
11834
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11835
+ onClick: () => {
11836
+ setIsOpen(
11837
+ STACKED_FOCUS_MODAL_ID,
11838
+ true
11839
+ );
11840
+ setData({
11841
+ shippingProfileId: profile.id,
11842
+ shippingOption,
11843
+ shippingMethod
11844
+ });
11845
+ }
11846
+ } : void 0,
11847
+ {
11848
+ label: "Remove shipping option",
11849
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11850
+ onClick: () => {
11851
+ if (shippingMethod) {
11852
+ if (addShippingMethodAction) {
11853
+ removeActionShippingMethod(
11854
+ addShippingMethodAction.id
11855
+ );
11856
+ } else {
11857
+ removeShippingMethod(
11858
+ shippingMethod.id
11859
+ );
11860
+ }
11861
+ }
11862
+ }
11863
+ }
11864
+ ].filter(Boolean)
11865
+ }
11866
+ ]
11867
+ }
11868
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
11869
+ StackedModalTrigger,
11870
+ {
11871
+ shippingProfileId: profile.id,
11872
+ shippingOption,
11873
+ shippingMethod,
11874
+ setData,
11875
+ children: "Add shipping option"
11876
+ }
11877
+ )
11878
+ ] }),
11879
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11880
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11881
+ items.map((item, idx) => {
11882
+ var _a3, _b2, _c2, _d2, _e2;
11883
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11884
+ /* @__PURE__ */ jsxRuntime.jsxs(
11885
+ "div",
11886
+ {
11887
+ className: "px-3 flex items-center gap-x-3",
11888
+ children: [
11889
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11890
+ ui.Divider,
11891
+ {
11892
+ variant: "dashed",
11893
+ orientation: "vertical"
11894
+ }
11895
+ ) }),
11896
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11897
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11898
+ ui.Text,
11899
+ {
11900
+ size: "small",
11901
+ leading: "compact",
11902
+ className: "text-ui-fg-subtle",
11903
+ children: [
11904
+ item.quantity,
11905
+ "x"
11906
+ ]
11907
+ }
11908
+ ) }),
11909
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11910
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11911
+ /* @__PURE__ */ jsxRuntime.jsxs(
11912
+ ui.Text,
11913
+ {
11914
+ size: "small",
11915
+ leading: "compact",
11916
+ weight: "plus",
11917
+ children: [
11918
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11919
+ " (",
11920
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
11921
+ ")"
11922
+ ]
11923
+ }
11924
+ ),
11925
+ /* @__PURE__ */ jsxRuntime.jsx(
11926
+ ui.Text,
11927
+ {
11928
+ size: "small",
11929
+ leading: "compact",
11930
+ className: "text-ui-fg-subtle",
11931
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11932
+ }
11933
+ )
11934
+ ] })
11935
+ ] })
11936
+ ]
11937
+ },
11938
+ item.id
11939
+ ),
11940
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11941
+ ] }, item.id);
11942
+ })
11943
+ ] })
11822
11944
  ]
11823
- }
11824
- )
11825
- ]
11826
- },
11827
- item.id
11828
- )) : /* @__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: [
11829
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11830
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
11831
- 'No items found for "',
11832
- query,
11833
- '".'
11834
- ] })
11835
- ] }) })
11836
- ] })
11837
- ] });
11838
- };
11839
- const LocationField = ({ control, setValue }) => {
11840
- const locations = useComboboxData({
11841
- queryKey: ["locations"],
11842
- queryFn: async (params) => {
11843
- return await sdk.admin.stockLocation.list(params);
11844
- },
11845
- getOptions: (data) => {
11846
- return data.stock_locations.map((location) => ({
11847
- label: location.name,
11848
- value: location.id
11849
- }));
11850
- }
11851
- });
11852
- return /* @__PURE__ */ jsxRuntime.jsx(
11853
- Form$2.Field,
11854
- {
11855
- control,
11856
- name: "location_id",
11857
- render: ({ field: { onChange, ...field } }) => {
11858
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11859
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11860
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
11861
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11862
- ] }),
11863
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11864
- Combobox,
11865
- {
11866
- options: locations.options,
11867
- fetchNextPage: locations.fetchNextPage,
11868
- isFetchingNextPage: locations.isFetchingNextPage,
11869
- searchValue: locations.searchValue,
11870
- onSearchValueChange: locations.onSearchValueChange,
11871
- placeholder: "Select location",
11872
- onChange: (value) => {
11873
- setValue("shipping_option_id", "", {
11874
- shouldDirty: true,
11875
- shouldTouch: true
11876
- });
11877
- onChange(value);
11878
11945
  },
11879
- ...field
11946
+ profile.id
11947
+ );
11948
+ }) })
11949
+ ] }) })
11950
+ ] }) }),
11951
+ /* @__PURE__ */ jsxRuntime.jsx(
11952
+ StackedFocusModal,
11953
+ {
11954
+ id: STACKED_FOCUS_MODAL_ID,
11955
+ onOpenChangeCallback: (open) => {
11956
+ if (!open) {
11957
+ setData(null);
11880
11958
  }
11881
- ) })
11882
- ] }) });
11883
- }
11884
- }
11885
- );
11886
- };
11887
- const ShippingOptionField = ({
11888
- shippingProfileId,
11889
- preview,
11890
- control
11891
- }) => {
11892
- var _a;
11893
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
11894
- const shippingOptions = useComboboxData({
11895
- queryKey: ["shipping_options", locationId, shippingProfileId],
11896
- queryFn: async (params) => {
11897
- return await sdk.admin.shippingOption.list({
11898
- ...params,
11899
- stock_location_id: locationId,
11900
- shipping_profile_id: shippingProfileId
11901
- });
11902
- },
11903
- getOptions: (data) => {
11904
- return data.shipping_options.map((option) => {
11905
- var _a2;
11906
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
11907
- (r) => r.attribute === "is_return" && r.value === "true"
11908
- )) {
11909
- return void 0;
11959
+ return open;
11960
+ },
11961
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11910
11962
  }
11911
- return {
11912
- label: option.name,
11913
- value: option.id
11914
- };
11915
- }).filter(Boolean);
11916
- },
11917
- enabled: !!locationId && !!shippingProfileId,
11918
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11919
- });
11920
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
11921
- return /* @__PURE__ */ jsxRuntime.jsx(
11922
- Form$2.Field,
11923
- {
11924
- control,
11925
- name: "shipping_option_id",
11926
- render: ({ field }) => {
11927
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11928
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11929
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
11930
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11931
- ] }),
11932
- /* @__PURE__ */ jsxRuntime.jsx(
11933
- ConditionalTooltip,
11934
- {
11935
- content: tooltipContent,
11936
- showTooltip: !locationId || !shippingProfileId,
11937
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11938
- Combobox,
11939
- {
11940
- options: shippingOptions.options,
11941
- fetchNextPage: shippingOptions.fetchNextPage,
11942
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
11943
- searchValue: shippingOptions.searchValue,
11944
- onSearchValueChange: shippingOptions.onSearchValueChange,
11945
- placeholder: "Select shipping option",
11946
- ...field,
11947
- disabled: !locationId || !shippingProfileId
11948
- }
11949
- ) }) })
11950
- }
11951
- )
11952
- ] }) });
11953
- }
11954
- }
11955
- );
11956
- };
11957
- const CustomAmountField = ({
11958
- control,
11959
- currencyCode
11960
- }) => {
11961
- return /* @__PURE__ */ jsxRuntime.jsx(
11962
- Form$2.Field,
11963
- {
11964
- control,
11965
- name: "custom_amount",
11966
- render: ({ field: { onChange, ...field } }) => {
11967
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11968
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
11970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11971
- ] }),
11972
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11973
- ui.CurrencyInput,
11974
- {
11975
- ...field,
11976
- onValueChange: (value) => onChange(value),
11977
- symbol: getNativeSymbol(currencyCode),
11978
- code: currencyCode
11979
- }
11980
- ) })
11981
- ] });
11982
- }
11983
- }
11984
- );
11985
- };
11986
- const SalesChannel = () => {
11987
- const { id } = reactRouterDom.useParams();
11988
- const { draft_order, isPending, isError, error } = useDraftOrder(
11989
- id,
11990
- {
11991
- fields: "+sales_channel_id"
11992
- },
11993
- {
11994
- enabled: !!id
11995
- }
11996
- );
11997
- if (isError) {
11998
- throw error;
11999
- }
12000
- const ISrEADY = !!draft_order && !isPending;
12001
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12002
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12003
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12004
- /* @__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" }) })
11963
+ )
12005
11964
  ] }),
12006
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11965
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11966
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11967
+ /* @__PURE__ */ jsxRuntime.jsx(
11968
+ ui.Button,
11969
+ {
11970
+ size: "small",
11971
+ type: "button",
11972
+ isLoading: isSubmitting,
11973
+ onClick: onSubmit,
11974
+ children: "Save"
11975
+ }
11976
+ )
11977
+ ] }) })
12007
11978
  ] });
12008
11979
  };
12009
- const SalesChannelForm = ({ order }) => {
12010
- const form = reactHookForm.useForm({
12011
- defaultValues: {
12012
- sales_channel_id: order.sales_channel_id || ""
12013
- },
12014
- resolver: zod.zodResolver(schema$2)
12015
- });
12016
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12017
- const { handleSuccess } = useRouteModal();
12018
- const onSubmit = form.handleSubmit(async (data) => {
12019
- await mutateAsync(
12020
- {
12021
- sales_channel_id: data.sales_channel_id
12022
- },
12023
- {
12024
- onSuccess: () => {
12025
- ui.toast.success("Sales channel updated");
12026
- handleSuccess();
12027
- },
12028
- onError: (error) => {
12029
- ui.toast.error(error.message);
12030
- }
12031
- }
12032
- );
12033
- });
12034
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12035
- KeyboundForm,
12036
- {
12037
- className: "flex flex-1 flex-col overflow-hidden",
12038
- onSubmit,
12039
- children: [
12040
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12041
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12042
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12043
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12044
- ] }) })
12045
- ]
11980
+ const StackedModalTrigger = ({
11981
+ shippingProfileId,
11982
+ shippingOption,
11983
+ shippingMethod,
11984
+ setData,
11985
+ children
11986
+ }) => {
11987
+ const { setIsOpen, getIsOpen } = useStackedModal();
11988
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11989
+ const onToggle = () => {
11990
+ if (isOpen) {
11991
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11992
+ setData(null);
11993
+ } else {
11994
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11995
+ setData({
11996
+ shippingProfileId,
11997
+ shippingOption,
11998
+ shippingMethod
11999
+ });
12046
12000
  }
12047
- ) });
12048
- };
12049
- const SalesChannelField = ({ control, order }) => {
12050
- const salesChannels = useComboboxData({
12051
- queryFn: async (params) => {
12052
- return await sdk.admin.salesChannel.list(params);
12053
- },
12054
- queryKey: ["sales-channels"],
12055
- getOptions: (data) => {
12056
- return data.sales_channels.map((salesChannel) => ({
12057
- label: salesChannel.name,
12058
- value: salesChannel.id
12059
- }));
12060
- },
12061
- defaultValue: order.sales_channel_id || void 0
12062
- });
12001
+ };
12063
12002
  return /* @__PURE__ */ jsxRuntime.jsx(
12064
- Form$2.Field,
12003
+ ui.Button,
12065
12004
  {
12066
- control,
12067
- name: "sales_channel_id",
12068
- render: ({ field }) => {
12069
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12070
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12071
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12072
- Combobox,
12073
- {
12074
- options: salesChannels.options,
12075
- fetchNextPage: salesChannels.fetchNextPage,
12076
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12077
- searchValue: salesChannels.searchValue,
12078
- onSearchValueChange: salesChannels.onSearchValueChange,
12079
- placeholder: "Select sales channel",
12080
- ...field
12081
- }
12082
- ) }),
12083
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12084
- ] });
12085
- }
12005
+ size: "small",
12006
+ variant: "secondary",
12007
+ onClick: onToggle,
12008
+ className: "text-ui-fg-primary shrink-0",
12009
+ children
12086
12010
  }
12087
12011
  );
12088
12012
  };
12089
- const schema$2 = objectType({
12090
- sales_channel_id: stringType().min(1)
12091
- });
12092
- const ShippingAddress = () => {
12093
- const { id } = reactRouterDom.useParams();
12094
- const { order, isPending, isError, error } = useOrder(id, {
12095
- fields: "+shipping_address"
12096
- });
12097
- if (isError) {
12098
- throw error;
12099
- }
12100
- const isReady = !isPending && !!order;
12101
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12102
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12103
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12104
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12105
- ] }),
12106
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12107
- ] });
12108
- };
12109
- const ShippingAddressForm = ({ order }) => {
12110
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12013
+ const ShippingProfileForm = ({
12014
+ data,
12015
+ order,
12016
+ preview
12017
+ }) => {
12018
+ var _a, _b, _c, _d, _e, _f;
12019
+ const { setIsOpen } = useStackedModal();
12111
12020
  const form = reactHookForm.useForm({
12021
+ resolver: zod.zodResolver(shippingMethodSchema),
12112
12022
  defaultValues: {
12113
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12114
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12115
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12116
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12117
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12118
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12119
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12120
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12121
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12122
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12123
- },
12124
- resolver: zod.zodResolver(schema$1)
12023
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12024
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12025
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12026
+ }
12125
12027
  });
12126
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12127
- const { handleSuccess } = useRouteModal();
12128
- const onSubmit = form.handleSubmit(async (data) => {
12129
- await mutateAsync(
12130
- {
12131
- shipping_address: {
12132
- first_name: data.first_name,
12133
- last_name: data.last_name,
12134
- company: data.company,
12135
- address_1: data.address_1,
12136
- address_2: data.address_2,
12137
- city: data.city,
12138
- province: data.province,
12139
- country_code: data.country_code,
12140
- postal_code: data.postal_code,
12141
- phone: data.phone
12028
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12029
+ const {
12030
+ mutateAsync: updateShippingMethod,
12031
+ isPending: isUpdatingShippingMethod
12032
+ } = useDraftOrderUpdateShippingMethod(order.id);
12033
+ const onSubmit = form.handleSubmit(async (values) => {
12034
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12035
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12036
+ return;
12037
+ }
12038
+ if (data.shippingMethod) {
12039
+ await updateShippingMethod(
12040
+ {
12041
+ method_id: data.shippingMethod.id,
12042
+ shipping_option_id: values.shipping_option_id,
12043
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12044
+ },
12045
+ {
12046
+ onError: (e) => {
12047
+ ui.toast.error(e.message);
12048
+ },
12049
+ onSuccess: () => {
12050
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12051
+ }
12142
12052
  }
12053
+ );
12054
+ return;
12055
+ }
12056
+ await addShippingMethod(
12057
+ {
12058
+ shipping_option_id: values.shipping_option_id,
12059
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12143
12060
  },
12144
12061
  {
12145
- onSuccess: () => {
12146
- handleSuccess();
12062
+ onError: (e) => {
12063
+ ui.toast.error(e.message);
12147
12064
  },
12148
- onError: (error) => {
12149
- ui.toast.error(error.message);
12065
+ onSuccess: () => {
12066
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12150
12067
  }
12151
12068
  }
12152
12069
  );
12153
12070
  });
12154
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12071
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12155
12072
  KeyboundForm,
12156
12073
  {
12157
- className: "flex flex-1 flex-col overflow-hidden",
12074
+ className: "flex h-full flex-col overflow-hidden",
12158
12075
  onSubmit,
12159
12076
  children: [
12160
- /* @__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: [
12161
- /* @__PURE__ */ jsxRuntime.jsx(
12162
- Form$2.Field,
12163
- {
12164
- control: form.control,
12165
- name: "country_code",
12166
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12167
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12168
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12169
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12170
- ] })
12171
- }
12172
- ),
12173
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12174
- /* @__PURE__ */ jsxRuntime.jsx(
12175
- Form$2.Field,
12176
- {
12177
- control: form.control,
12178
- name: "first_name",
12179
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12180
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12181
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12182
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12183
- ] })
12184
- }
12185
- ),
12186
- /* @__PURE__ */ jsxRuntime.jsx(
12187
- Form$2.Field,
12188
- {
12189
- control: form.control,
12190
- name: "last_name",
12191
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12192
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12193
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12194
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12195
- ] })
12196
- }
12197
- )
12077
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12078
+ /* @__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: [
12079
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12080
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12081
+ /* @__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." }) })
12198
12082
  ] }),
12083
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12199
12084
  /* @__PURE__ */ jsxRuntime.jsx(
12200
- Form$2.Field,
12085
+ LocationField,
12201
12086
  {
12202
12087
  control: form.control,
12203
- name: "company",
12204
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12205
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12206
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12207
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12208
- ] })
12088
+ setValue: form.setValue
12209
12089
  }
12210
12090
  ),
12091
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12211
12092
  /* @__PURE__ */ jsxRuntime.jsx(
12212
- Form$2.Field,
12093
+ ShippingOptionField,
12213
12094
  {
12214
- control: form.control,
12215
- name: "address_1",
12216
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12217
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12218
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12219
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12220
- ] })
12095
+ shippingProfileId: data.shippingProfileId,
12096
+ preview,
12097
+ control: form.control
12221
12098
  }
12222
12099
  ),
12100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12223
12101
  /* @__PURE__ */ jsxRuntime.jsx(
12224
- Form$2.Field,
12102
+ CustomAmountField,
12225
12103
  {
12226
12104
  control: form.control,
12227
- name: "address_2",
12228
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12229
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12230
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12231
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12232
- ] })
12105
+ currencyCode: order.currency_code
12233
12106
  }
12234
12107
  ),
12235
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12236
- /* @__PURE__ */ jsxRuntime.jsx(
12237
- Form$2.Field,
12238
- {
12239
- control: form.control,
12240
- name: "postal_code",
12241
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12242
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12243
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12244
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12245
- ] })
12246
- }
12247
- ),
12248
- /* @__PURE__ */ jsxRuntime.jsx(
12249
- Form$2.Field,
12250
- {
12251
- control: form.control,
12252
- name: "city",
12253
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12254
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12255
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12256
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12257
- ] })
12258
- }
12259
- )
12260
- ] }),
12108
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12261
12109
  /* @__PURE__ */ jsxRuntime.jsx(
12262
- Form$2.Field,
12110
+ ItemsPreview,
12263
12111
  {
12264
- control: form.control,
12265
- name: "province",
12266
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12267
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12268
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12269
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12270
- ] })
12112
+ order,
12113
+ shippingProfileId: data.shippingProfileId
12271
12114
  }
12272
- ),
12115
+ )
12116
+ ] }) }) }),
12117
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12118
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12273
12119
  /* @__PURE__ */ jsxRuntime.jsx(
12274
- Form$2.Field,
12120
+ ui.Button,
12275
12121
  {
12276
- control: form.control,
12277
- name: "phone",
12278
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12279
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12280
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12281
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12282
- ] })
12122
+ size: "small",
12123
+ type: "submit",
12124
+ isLoading: isPending || isUpdatingShippingMethod,
12125
+ children: data.shippingMethod ? "Update" : "Add"
12283
12126
  }
12284
12127
  )
12285
- ] }) }),
12286
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12287
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12288
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12289
12128
  ] }) })
12290
12129
  ]
12291
12130
  }
12292
- ) });
12293
- };
12294
- const schema$1 = addressSchema;
12295
- const PROMOTION_QUERY_KEY = "promotions";
12296
- const promotionsQueryKeys = {
12297
- list: (query2) => [
12298
- PROMOTION_QUERY_KEY,
12299
- query2 ? query2 : void 0
12300
- ],
12301
- detail: (id, query2) => [
12302
- PROMOTION_QUERY_KEY,
12303
- id,
12304
- query2 ? query2 : void 0
12305
- ]
12306
- };
12307
- const usePromotions = (query2, options) => {
12308
- const { data, ...rest } = reactQuery.useQuery({
12309
- queryKey: promotionsQueryKeys.list(query2),
12310
- queryFn: async () => sdk.admin.promotion.list(query2),
12311
- ...options
12312
- });
12313
- return { ...data, ...rest };
12131
+ ) }) });
12314
12132
  };
12315
- const Promotions = () => {
12316
- const { id } = reactRouterDom.useParams();
12317
- const {
12318
- order: preview,
12319
- isError: isPreviewError,
12320
- error: previewError
12321
- } = useOrderPreview(id, void 0);
12322
- useInitiateOrderEdit({ preview });
12323
- const { onCancel } = useCancelOrderEdit({ preview });
12324
- if (isPreviewError) {
12325
- throw previewError;
12326
- }
12327
- const isReady = !!preview;
12328
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12329
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12330
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12133
+ const shippingMethodSchema = objectType({
12134
+ location_id: stringType(),
12135
+ shipping_option_id: stringType(),
12136
+ custom_amount: unionType([numberType(), stringType()]).optional()
12137
+ });
12138
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12139
+ const matches = order.items.filter(
12140
+ (item) => {
12141
+ var _a, _b, _c;
12142
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12143
+ }
12144
+ );
12145
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12146
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12147
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12148
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12149
+ ] }) }),
12150
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12151
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12152
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12153
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12154
+ ] }),
12155
+ /* @__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(
12156
+ "div",
12157
+ {
12158
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12159
+ children: [
12160
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12161
+ /* @__PURE__ */ jsxRuntime.jsx(
12162
+ Thumbnail,
12163
+ {
12164
+ thumbnail: item.thumbnail,
12165
+ alt: item.product_title ?? void 0
12166
+ }
12167
+ ),
12168
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12169
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12170
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12171
+ /* @__PURE__ */ jsxRuntime.jsxs(
12172
+ ui.Text,
12173
+ {
12174
+ size: "small",
12175
+ leading: "compact",
12176
+ className: "text-ui-fg-subtle",
12177
+ children: [
12178
+ "(",
12179
+ item.variant_title,
12180
+ ")"
12181
+ ]
12182
+ }
12183
+ )
12184
+ ] }),
12185
+ /* @__PURE__ */ jsxRuntime.jsx(
12186
+ ui.Text,
12187
+ {
12188
+ size: "small",
12189
+ leading: "compact",
12190
+ className: "text-ui-fg-subtle",
12191
+ children: item.variant_sku
12192
+ }
12193
+ )
12194
+ ] })
12195
+ ] }),
12196
+ /* @__PURE__ */ jsxRuntime.jsxs(
12197
+ ui.Text,
12198
+ {
12199
+ size: "small",
12200
+ leading: "compact",
12201
+ className: "text-ui-fg-subtle",
12202
+ children: [
12203
+ item.quantity,
12204
+ "x"
12205
+ ]
12206
+ }
12207
+ )
12208
+ ]
12209
+ },
12210
+ item.id
12211
+ )) : /* @__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: [
12212
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12213
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12214
+ 'No items found for "',
12215
+ query,
12216
+ '".'
12217
+ ] })
12218
+ ] }) })
12219
+ ] })
12331
12220
  ] });
12332
12221
  };
12333
- const PromotionForm = ({ preview }) => {
12334
- const { items, shipping_methods } = preview;
12335
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12336
- const [comboboxValue, setComboboxValue] = React.useState("");
12337
- const { handleSuccess } = useRouteModal();
12338
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12339
- const promoIds = getPromotionIds(items, shipping_methods);
12340
- const { promotions, isPending, isError, error } = usePromotions(
12341
- {
12342
- id: promoIds
12222
+ const LocationField = ({ control, setValue }) => {
12223
+ const locations = useComboboxData({
12224
+ queryKey: ["locations"],
12225
+ queryFn: async (params) => {
12226
+ return await sdk.admin.stockLocation.list(params);
12343
12227
  },
12228
+ getOptions: (data) => {
12229
+ return data.stock_locations.map((location) => ({
12230
+ label: location.name,
12231
+ value: location.id
12232
+ }));
12233
+ }
12234
+ });
12235
+ return /* @__PURE__ */ jsxRuntime.jsx(
12236
+ Form$2.Field,
12344
12237
  {
12345
- enabled: !!promoIds.length
12238
+ control,
12239
+ name: "location_id",
12240
+ render: ({ field: { onChange, ...field } }) => {
12241
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12242
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12243
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12244
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12245
+ ] }),
12246
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12247
+ Combobox,
12248
+ {
12249
+ options: locations.options,
12250
+ fetchNextPage: locations.fetchNextPage,
12251
+ isFetchingNextPage: locations.isFetchingNextPage,
12252
+ searchValue: locations.searchValue,
12253
+ onSearchValueChange: locations.onSearchValueChange,
12254
+ placeholder: "Select location",
12255
+ onChange: (value) => {
12256
+ setValue("shipping_option_id", "", {
12257
+ shouldDirty: true,
12258
+ shouldTouch: true
12259
+ });
12260
+ onChange(value);
12261
+ },
12262
+ ...field
12263
+ }
12264
+ ) })
12265
+ ] }) });
12266
+ }
12346
12267
  }
12347
12268
  );
12348
- const comboboxData = useComboboxData({
12349
- queryKey: ["promotions", "combobox", promoIds],
12269
+ };
12270
+ const ShippingOptionField = ({
12271
+ shippingProfileId,
12272
+ preview,
12273
+ control
12274
+ }) => {
12275
+ var _a;
12276
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12277
+ const shippingOptions = useComboboxData({
12278
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12350
12279
  queryFn: async (params) => {
12351
- return await sdk.admin.promotion.list({
12280
+ return await sdk.admin.shippingOption.list({
12352
12281
  ...params,
12353
- id: {
12354
- $nin: promoIds
12355
- }
12282
+ stock_location_id: locationId,
12283
+ shipping_profile_id: shippingProfileId
12356
12284
  });
12357
12285
  },
12358
12286
  getOptions: (data) => {
12359
- return data.promotions.map((promotion) => ({
12360
- label: promotion.code,
12361
- value: promotion.code
12362
- }));
12363
- }
12364
- });
12365
- const add = async (value) => {
12366
- if (!value) {
12367
- return;
12368
- }
12369
- addPromotions(
12370
- {
12371
- promo_codes: [value]
12372
- },
12373
- {
12374
- onError: (e) => {
12375
- ui.toast.error(e.message);
12376
- comboboxData.onSearchValueChange("");
12377
- setComboboxValue("");
12378
- },
12379
- onSuccess: () => {
12380
- comboboxData.onSearchValueChange("");
12381
- setComboboxValue("");
12287
+ return data.shipping_options.map((option) => {
12288
+ var _a2;
12289
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12290
+ (r) => r.attribute === "is_return" && r.value === "true"
12291
+ )) {
12292
+ return void 0;
12382
12293
  }
12294
+ return {
12295
+ label: option.name,
12296
+ value: option.id
12297
+ };
12298
+ }).filter(Boolean);
12299
+ },
12300
+ enabled: !!locationId && !!shippingProfileId,
12301
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12302
+ });
12303
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12304
+ return /* @__PURE__ */ jsxRuntime.jsx(
12305
+ Form$2.Field,
12306
+ {
12307
+ control,
12308
+ name: "shipping_option_id",
12309
+ render: ({ field }) => {
12310
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12311
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12312
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12313
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12314
+ ] }),
12315
+ /* @__PURE__ */ jsxRuntime.jsx(
12316
+ ConditionalTooltip,
12317
+ {
12318
+ content: tooltipContent,
12319
+ showTooltip: !locationId || !shippingProfileId,
12320
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12321
+ Combobox,
12322
+ {
12323
+ options: shippingOptions.options,
12324
+ fetchNextPage: shippingOptions.fetchNextPage,
12325
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12326
+ searchValue: shippingOptions.searchValue,
12327
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12328
+ placeholder: "Select shipping option",
12329
+ ...field,
12330
+ disabled: !locationId || !shippingProfileId
12331
+ }
12332
+ ) }) })
12333
+ }
12334
+ )
12335
+ ] }) });
12383
12336
  }
12384
- );
12385
- };
12386
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12387
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12388
- const onSubmit = async () => {
12389
- setIsSubmitting(true);
12390
- let requestSucceeded = false;
12391
- await requestOrderEdit(void 0, {
12392
- onError: (e) => {
12393
- ui.toast.error(e.message);
12394
- },
12395
- onSuccess: () => {
12396
- requestSucceeded = true;
12397
- }
12398
- });
12399
- if (!requestSucceeded) {
12400
- setIsSubmitting(false);
12401
- return;
12402
12337
  }
12403
- await confirmOrderEdit(void 0, {
12404
- onError: (e) => {
12405
- ui.toast.error(e.message);
12406
- },
12407
- onSuccess: () => {
12408
- handleSuccess();
12409
- },
12410
- onSettled: () => {
12411
- setIsSubmitting(false);
12338
+ );
12339
+ };
12340
+ const CustomAmountField = ({
12341
+ control,
12342
+ currencyCode
12343
+ }) => {
12344
+ return /* @__PURE__ */ jsxRuntime.jsx(
12345
+ Form$2.Field,
12346
+ {
12347
+ control,
12348
+ name: "custom_amount",
12349
+ render: ({ field: { onChange, ...field } }) => {
12350
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12351
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12353
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12354
+ ] }),
12355
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12356
+ ui.CurrencyInput,
12357
+ {
12358
+ ...field,
12359
+ onValueChange: (value) => onChange(value),
12360
+ symbol: getNativeSymbol(currencyCode),
12361
+ code: currencyCode
12362
+ }
12363
+ ) })
12364
+ ] });
12412
12365
  }
12413
- });
12414
- };
12366
+ }
12367
+ );
12368
+ };
12369
+ const ShippingAddress = () => {
12370
+ const { id } = reactRouterDom.useParams();
12371
+ const { order, isPending, isError, error } = useOrder(id, {
12372
+ fields: "+shipping_address"
12373
+ });
12415
12374
  if (isError) {
12416
12375
  throw error;
12417
12376
  }
12418
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12419
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12420
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12421
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12422
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12423
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12424
- ] }),
12425
- /* @__PURE__ */ jsxRuntime.jsx(
12426
- Combobox,
12427
- {
12428
- id: "promotion-combobox",
12429
- "aria-describedby": "promotion-combobox-hint",
12430
- isFetchingNextPage: comboboxData.isFetchingNextPage,
12431
- fetchNextPage: comboboxData.fetchNextPage,
12432
- options: comboboxData.options,
12433
- onSearchValueChange: comboboxData.onSearchValueChange,
12434
- searchValue: comboboxData.searchValue,
12435
- disabled: comboboxData.disabled || isAddingPromotions,
12436
- onChange: add,
12437
- value: comboboxValue
12438
- }
12439
- )
12440
- ] }),
12441
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12442
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12443
- PromotionItem,
12444
- {
12445
- promotion,
12446
- orderId: preview.id,
12447
- isLoading: isPending
12448
- },
12449
- promotion.id
12450
- )) })
12451
- ] }) }),
12452
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12453
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12454
- /* @__PURE__ */ jsxRuntime.jsx(
12455
- ui.Button,
12456
- {
12457
- size: "small",
12458
- type: "submit",
12459
- isLoading: isSubmitting || isAddingPromotions,
12460
- children: "Save"
12461
- }
12462
- )
12463
- ] }) })
12377
+ const isReady = !isPending && !!order;
12378
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12379
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12380
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12381
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12382
+ ] }),
12383
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12464
12384
  ] });
12465
12385
  };
12466
- const PromotionItem = ({
12467
- promotion,
12468
- orderId,
12469
- isLoading
12470
- }) => {
12471
- var _a;
12472
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12473
- const onRemove = async () => {
12474
- removePromotions(
12386
+ const ShippingAddressForm = ({ order }) => {
12387
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12388
+ const form = reactHookForm.useForm({
12389
+ defaultValues: {
12390
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12391
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12392
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12393
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12394
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12395
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12396
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12397
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12398
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12399
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12400
+ },
12401
+ resolver: zod.zodResolver(schema$1)
12402
+ });
12403
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12404
+ const { handleSuccess } = useRouteModal();
12405
+ const onSubmit = form.handleSubmit(async (data) => {
12406
+ await mutateAsync(
12475
12407
  {
12476
- promo_codes: [promotion.code]
12408
+ shipping_address: {
12409
+ first_name: data.first_name,
12410
+ last_name: data.last_name,
12411
+ company: data.company,
12412
+ address_1: data.address_1,
12413
+ address_2: data.address_2,
12414
+ city: data.city,
12415
+ province: data.province,
12416
+ country_code: data.country_code,
12417
+ postal_code: data.postal_code,
12418
+ phone: data.phone
12419
+ }
12477
12420
  },
12478
12421
  {
12479
- onError: (e) => {
12480
- ui.toast.error(e.message);
12422
+ onSuccess: () => {
12423
+ handleSuccess();
12424
+ },
12425
+ onError: (error) => {
12426
+ ui.toast.error(error.message);
12481
12427
  }
12482
12428
  }
12483
12429
  );
12484
- };
12485
- const displayValue = getDisplayValue(promotion);
12486
- return /* @__PURE__ */ jsxRuntime.jsxs(
12487
- "div",
12430
+ });
12431
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12432
+ KeyboundForm,
12488
12433
  {
12489
- className: ui.clx(
12490
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12491
- {
12492
- "animate-pulse": isLoading
12493
- }
12494
- ),
12434
+ className: "flex flex-1 flex-col overflow-hidden",
12435
+ onSubmit,
12495
12436
  children: [
12496
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12497
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12498
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12499
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12500
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12501
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12502
- ] }),
12503
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12504
- ] })
12505
- ] }),
12506
- /* @__PURE__ */ jsxRuntime.jsx(
12507
- ui.IconButton,
12508
- {
12509
- size: "small",
12510
- type: "button",
12511
- variant: "transparent",
12512
- onClick: onRemove,
12513
- isLoading: isPending || isLoading,
12514
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12515
- }
12516
- )
12437
+ /* @__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: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(
12439
+ Form$2.Field,
12440
+ {
12441
+ control: form.control,
12442
+ name: "country_code",
12443
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12447
+ ] })
12448
+ }
12449
+ ),
12450
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12451
+ /* @__PURE__ */ jsxRuntime.jsx(
12452
+ Form$2.Field,
12453
+ {
12454
+ control: form.control,
12455
+ name: "first_name",
12456
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12459
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12460
+ ] })
12461
+ }
12462
+ ),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(
12464
+ Form$2.Field,
12465
+ {
12466
+ control: form.control,
12467
+ name: "last_name",
12468
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12471
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12472
+ ] })
12473
+ }
12474
+ )
12475
+ ] }),
12476
+ /* @__PURE__ */ jsxRuntime.jsx(
12477
+ Form$2.Field,
12478
+ {
12479
+ control: form.control,
12480
+ name: "company",
12481
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12484
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12485
+ ] })
12486
+ }
12487
+ ),
12488
+ /* @__PURE__ */ jsxRuntime.jsx(
12489
+ Form$2.Field,
12490
+ {
12491
+ control: form.control,
12492
+ name: "address_1",
12493
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12496
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12497
+ ] })
12498
+ }
12499
+ ),
12500
+ /* @__PURE__ */ jsxRuntime.jsx(
12501
+ Form$2.Field,
12502
+ {
12503
+ control: form.control,
12504
+ name: "address_2",
12505
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12509
+ ] })
12510
+ }
12511
+ ),
12512
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12513
+ /* @__PURE__ */ jsxRuntime.jsx(
12514
+ Form$2.Field,
12515
+ {
12516
+ control: form.control,
12517
+ name: "postal_code",
12518
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12521
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12522
+ ] })
12523
+ }
12524
+ ),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(
12526
+ Form$2.Field,
12527
+ {
12528
+ control: form.control,
12529
+ name: "city",
12530
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12534
+ ] })
12535
+ }
12536
+ )
12537
+ ] }),
12538
+ /* @__PURE__ */ jsxRuntime.jsx(
12539
+ Form$2.Field,
12540
+ {
12541
+ control: form.control,
12542
+ name: "province",
12543
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12546
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12547
+ ] })
12548
+ }
12549
+ ),
12550
+ /* @__PURE__ */ jsxRuntime.jsx(
12551
+ Form$2.Field,
12552
+ {
12553
+ control: form.control,
12554
+ name: "phone",
12555
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12559
+ ] })
12560
+ }
12561
+ )
12562
+ ] }) }),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12564
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12565
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12566
+ ] }) })
12517
12567
  ]
12518
- },
12519
- promotion.id
12520
- );
12521
- };
12522
- function getDisplayValue(promotion) {
12523
- var _a, _b, _c, _d;
12524
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12525
- if (!value) {
12526
- return null;
12527
- }
12528
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12529
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12530
- if (!currency) {
12531
- return null;
12532
12568
  }
12533
- return getLocaleAmount(value, currency);
12534
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
12535
- return formatPercentage(value);
12536
- }
12537
- return null;
12538
- }
12539
- const formatter = new Intl.NumberFormat([], {
12540
- style: "percent",
12541
- minimumFractionDigits: 2
12542
- });
12543
- const formatPercentage = (value, isPercentageValue = false) => {
12544
- let val = value || 0;
12545
- if (!isPercentageValue) {
12546
- val = val / 100;
12547
- }
12548
- return formatter.format(val);
12569
+ ) });
12549
12570
  };
12550
- function getPromotionIds(items, shippingMethods) {
12551
- const promotionIds = /* @__PURE__ */ new Set();
12552
- for (const item of items) {
12553
- if (item.adjustments) {
12554
- for (const adjustment of item.adjustments) {
12555
- if (adjustment.promotion_id) {
12556
- promotionIds.add(adjustment.promotion_id);
12557
- }
12558
- }
12559
- }
12560
- }
12561
- for (const shippingMethod of shippingMethods) {
12562
- if (shippingMethod.adjustments) {
12563
- for (const adjustment of shippingMethod.adjustments) {
12564
- if (adjustment.promotion_id) {
12565
- promotionIds.add(adjustment.promotion_id);
12566
- }
12567
- }
12568
- }
12569
- }
12570
- return Array.from(promotionIds);
12571
- }
12571
+ const schema$1 = addressSchema;
12572
12572
  const TransferOwnership = () => {
12573
12573
  const { id } = reactRouterDom.useParams();
12574
12574
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13070,36 +13070,36 @@ const routeModule = {
13070
13070
  path: "/draft-orders/:id/billing-address"
13071
13071
  },
13072
13072
  {
13073
- Component: Items,
13074
- path: "/draft-orders/:id/items"
13073
+ Component: CustomItems,
13074
+ path: "/draft-orders/:id/custom-items"
13075
13075
  },
13076
13076
  {
13077
13077
  Component: Email,
13078
13078
  path: "/draft-orders/:id/email"
13079
13079
  },
13080
13080
  {
13081
- Component: CustomItems,
13082
- path: "/draft-orders/:id/custom-items"
13081
+ Component: Items,
13082
+ path: "/draft-orders/:id/items"
13083
13083
  },
13084
13084
  {
13085
13085
  Component: Metadata,
13086
13086
  path: "/draft-orders/:id/metadata"
13087
13087
  },
13088
13088
  {
13089
- Component: Shipping,
13090
- path: "/draft-orders/:id/shipping"
13089
+ Component: Promotions,
13090
+ path: "/draft-orders/:id/promotions"
13091
13091
  },
13092
13092
  {
13093
13093
  Component: SalesChannel,
13094
13094
  path: "/draft-orders/:id/sales-channel"
13095
13095
  },
13096
13096
  {
13097
- Component: ShippingAddress,
13098
- path: "/draft-orders/:id/shipping-address"
13097
+ Component: Shipping,
13098
+ path: "/draft-orders/:id/shipping"
13099
13099
  },
13100
13100
  {
13101
- Component: Promotions,
13102
- path: "/draft-orders/:id/promotions"
13101
+ Component: ShippingAddress,
13102
+ path: "/draft-orders/:id/shipping-address"
13103
13103
  },
13104
13104
  {
13105
13105
  Component: TransferOwnership,