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

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.
@@ -352,7 +352,7 @@ const DataTableAction = ({
352
352
  return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { ...buttonProps, onClick: props.onClick, children: label });
353
353
  };
354
354
  const sdk = new Medusa__default.default({
355
- baseUrl: "/",
355
+ baseUrl: __BACKEND_URL__ || "/",
356
356
  auth: {
357
357
  type: "session"
358
358
  }
@@ -10805,27 +10805,6 @@ const EmailForm = ({ order }) => {
10805
10805
  const schema$4 = objectType({
10806
10806
  email: stringType().email()
10807
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
10808
  const InlineTip = React.forwardRef(
10830
10809
  ({ variant = "tip", label, className, children, ...props }, ref) => {
10831
10810
  const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
@@ -11176,1399 +11155,1217 @@ function getHasUneditableRows(metadata) {
11176
11155
  (value) => !EDITABLE_TYPES.includes(typeof value)
11177
11156
  );
11178
11157
  }
11179
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11180
- const Shipping = () => {
11181
- var _a;
11158
+ const CustomItems = () => {
11159
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11160
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
11161
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
11162
+ ] });
11163
+ };
11164
+ const CustomItemsForm = () => {
11165
+ const form = reactHookForm.useForm({
11166
+ resolver: zod.zodResolver(schema$3)
11167
+ });
11168
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11169
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
11170
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11171
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11172
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
11173
+ ] }) })
11174
+ ] }) });
11175
+ };
11176
+ const schema$3 = objectType({
11177
+ email: stringType().email()
11178
+ });
11179
+ const SalesChannel = () => {
11182
11180
  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"
11181
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11182
+ id,
11183
+ {
11184
+ fields: "+sales_channel_id"
11185
+ },
11186
+ {
11187
+ enabled: !!id
11188
+ }
11189
+ );
11190
+ if (isError) {
11191
+ throw error;
11192
+ }
11193
+ const ISrEADY = !!draft_order && !isPending;
11194
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11195
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11196
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11197
+ /* @__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" }) })
11198
+ ] }),
11199
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11200
+ ] });
11201
+ };
11202
+ const SalesChannelForm = ({ order }) => {
11203
+ const form = reactHookForm.useForm({
11204
+ defaultValues: {
11205
+ sales_channel_id: order.sales_channel_id || ""
11206
+ },
11207
+ resolver: zod.zodResolver(schema$2)
11208
+ });
11209
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11210
+ const { handleSuccess } = useRouteModal();
11211
+ const onSubmit = form.handleSubmit(async (data) => {
11212
+ await mutateAsync(
11213
+ {
11214
+ sales_channel_id: data.sales_channel_id
11215
+ },
11216
+ {
11217
+ onSuccess: () => {
11218
+ ui.toast.success("Sales channel updated");
11219
+ handleSuccess();
11220
+ },
11221
+ onError: (error) => {
11222
+ ui.toast.error(error.message);
11223
+ }
11224
+ }
11225
+ );
11226
+ });
11227
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11228
+ KeyboundForm,
11229
+ {
11230
+ className: "flex flex-1 flex-col overflow-hidden",
11231
+ onSubmit,
11232
+ children: [
11233
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11234
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11235
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11236
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11237
+ ] }) })
11238
+ ]
11239
+ }
11240
+ ) });
11241
+ };
11242
+ const SalesChannelField = ({ control, order }) => {
11243
+ const salesChannels = useComboboxData({
11244
+ queryFn: async (params) => {
11245
+ return await sdk.admin.salesChannel.list(params);
11246
+ },
11247
+ queryKey: ["sales-channels"],
11248
+ getOptions: (data) => {
11249
+ return data.sales_channels.map((salesChannel) => ({
11250
+ label: salesChannel.name,
11251
+ value: salesChannel.id
11252
+ }));
11253
+ },
11254
+ defaultValue: order.sales_channel_id || void 0
11255
+ });
11256
+ return /* @__PURE__ */ jsxRuntime.jsx(
11257
+ Form$2.Field,
11258
+ {
11259
+ control,
11260
+ name: "sales_channel_id",
11261
+ render: ({ field }) => {
11262
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11263
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11264
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11265
+ Combobox,
11266
+ {
11267
+ options: salesChannels.options,
11268
+ fetchNextPage: salesChannels.fetchNextPage,
11269
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11270
+ searchValue: salesChannels.searchValue,
11271
+ onSearchValueChange: salesChannels.onSearchValueChange,
11272
+ placeholder: "Select sales channel",
11273
+ ...field
11274
+ }
11275
+ ) }),
11276
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11277
+ ] });
11278
+ }
11279
+ }
11280
+ );
11281
+ };
11282
+ const schema$2 = objectType({
11283
+ sales_channel_id: stringType().min(1)
11284
+ });
11285
+ const PROMOTION_QUERY_KEY = "promotions";
11286
+ const promotionsQueryKeys = {
11287
+ list: (query2) => [
11288
+ PROMOTION_QUERY_KEY,
11289
+ query2 ? query2 : void 0
11290
+ ],
11291
+ detail: (id, query2) => [
11292
+ PROMOTION_QUERY_KEY,
11293
+ id,
11294
+ query2 ? query2 : void 0
11295
+ ]
11296
+ };
11297
+ const usePromotions = (query2, options) => {
11298
+ const { data, ...rest } = reactQuery.useQuery({
11299
+ queryKey: promotionsQueryKeys.list(query2),
11300
+ queryFn: async () => sdk.admin.promotion.list(query2),
11301
+ ...options
11185
11302
  });
11303
+ return { ...data, ...rest };
11304
+ };
11305
+ const Promotions = () => {
11306
+ const { id } = reactRouterDom.useParams();
11186
11307
  const {
11187
11308
  order: preview,
11188
- isPending: isPreviewPending,
11189
11309
  isError: isPreviewError,
11190
11310
  error: previewError
11191
- } = useOrderPreview(id);
11311
+ } = useOrderPreview(id, void 0);
11192
11312
  useInitiateOrderEdit({ preview });
11193
11313
  const { onCancel } = useCancelOrderEdit({ preview });
11194
- if (isError) {
11195
- throw error;
11196
- }
11197
11314
  if (isPreviewError) {
11198
11315
  throw previewError;
11199
11316
  }
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
- ] }) });
11317
+ const isReady = !!preview;
11318
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11319
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11320
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11321
+ ] });
11213
11322
  };
11214
- const ShippingForm = ({ preview, order }) => {
11215
- var _a;
11216
- const { setIsOpen } = useStackedModal();
11323
+ const PromotionForm = ({ preview }) => {
11324
+ const { items, shipping_methods } = preview;
11217
11325
  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(
11326
+ const [comboboxValue, setComboboxValue] = React.useState("");
11327
+ const { handleSuccess } = useRouteModal();
11328
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11329
+ const promoIds = getPromotionIds(items, shipping_methods);
11330
+ const { promotions, isPending, isError, error } = usePromotions(
11221
11331
  {
11222
- id: appliedShippingOptionIds,
11223
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11332
+ id: promoIds
11224
11333
  },
11225
11334
  {
11226
- enabled: appliedShippingOptionIds.length > 0
11335
+ enabled: !!promoIds.length
11227
11336
  }
11228
11337
  );
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();
11240
- 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);
11244
- const onSubmit = async () => {
11245
- setIsSubmitting(true);
11246
- let requestSucceeded = false;
11247
- await requestOrderEdit(void 0, {
11248
- onError: (e) => {
11249
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11250
- },
11251
- onSuccess: () => {
11252
- requestSucceeded = true;
11253
- }
11254
- });
11255
- if (!requestSucceeded) {
11256
- setIsSubmitting(false);
11257
- return;
11258
- }
11259
- await confirmOrderEdit(void 0, {
11260
- onError: (e) => {
11261
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11262
- },
11263
- onSuccess: () => {
11264
- handleSuccess();
11265
- },
11266
- onSettled: () => {
11267
- setIsSubmitting(false);
11268
- }
11269
- });
11338
+ const comboboxData = useComboboxData({
11339
+ queryKey: ["promotions", "combobox", promoIds],
11340
+ queryFn: async (params) => {
11341
+ return await sdk.admin.promotion.list({
11342
+ ...params,
11343
+ id: {
11344
+ $nin: promoIds
11345
+ }
11346
+ });
11347
+ },
11348
+ getOptions: (data) => {
11349
+ return data.promotions.map((promotion) => ({
11350
+ label: promotion.code,
11351
+ value: promotion.code
11352
+ }));
11353
+ }
11354
+ });
11355
+ const add = async (value) => {
11356
+ if (!value) {
11357
+ return;
11358
+ }
11359
+ addPromotions(
11360
+ {
11361
+ promo_codes: [value]
11362
+ },
11363
+ {
11364
+ onError: (e) => {
11365
+ ui.toast.error(e.message);
11366
+ comboboxData.onSearchValueChange("");
11367
+ setComboboxValue("");
11368
+ },
11369
+ onSuccess: () => {
11370
+ comboboxData.onSearchValueChange("");
11371
+ setComboboxValue("");
11372
+ }
11373
+ }
11374
+ );
11270
11375
  };
11271
- const onKeydown = React.useCallback(
11272
- (e) => {
11273
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11274
- if (data || isSubmitting) {
11275
- return;
11376
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11377
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11378
+ const onSubmit = async () => {
11379
+ setIsSubmitting(true);
11380
+ let requestSucceeded = false;
11381
+ await requestOrderEdit(void 0, {
11382
+ onError: (e) => {
11383
+ ui.toast.error(e.message);
11384
+ },
11385
+ onSuccess: () => {
11386
+ requestSucceeded = true;
11387
+ }
11388
+ });
11389
+ if (!requestSucceeded) {
11390
+ setIsSubmitting(false);
11391
+ return;
11392
+ }
11393
+ await confirmOrderEdit(void 0, {
11394
+ onError: (e) => {
11395
+ ui.toast.error(e.message);
11396
+ },
11397
+ onSuccess: () => {
11398
+ handleSuccess();
11399
+ },
11400
+ onSettled: () => {
11401
+ setIsSubmitting(false);
11402
+ }
11403
+ });
11404
+ };
11405
+ if (isError) {
11406
+ throw error;
11407
+ }
11408
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11409
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11410
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11411
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11412
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11413
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11414
+ ] }),
11415
+ /* @__PURE__ */ jsxRuntime.jsx(
11416
+ Combobox,
11417
+ {
11418
+ id: "promotion-combobox",
11419
+ "aria-describedby": "promotion-combobox-hint",
11420
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11421
+ fetchNextPage: comboboxData.fetchNextPage,
11422
+ options: comboboxData.options,
11423
+ onSearchValueChange: comboboxData.onSearchValueChange,
11424
+ searchValue: comboboxData.searchValue,
11425
+ disabled: comboboxData.disabled || isAddingPromotions,
11426
+ onChange: add,
11427
+ value: comboboxValue
11428
+ }
11429
+ )
11430
+ ] }),
11431
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11432
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11433
+ PromotionItem,
11434
+ {
11435
+ promotion,
11436
+ orderId: preview.id,
11437
+ isLoading: isPending
11438
+ },
11439
+ promotion.id
11440
+ )) })
11441
+ ] }) }),
11442
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11443
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11444
+ /* @__PURE__ */ jsxRuntime.jsx(
11445
+ ui.Button,
11446
+ {
11447
+ size: "small",
11448
+ type: "submit",
11449
+ isLoading: isSubmitting || isAddingPromotions,
11450
+ children: "Save"
11451
+ }
11452
+ )
11453
+ ] }) })
11454
+ ] });
11455
+ };
11456
+ const PromotionItem = ({
11457
+ promotion,
11458
+ orderId,
11459
+ isLoading
11460
+ }) => {
11461
+ var _a;
11462
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11463
+ const onRemove = async () => {
11464
+ removePromotions(
11465
+ {
11466
+ promo_codes: [promotion.code]
11467
+ },
11468
+ {
11469
+ onError: (e) => {
11470
+ ui.toast.error(e.message);
11276
11471
  }
11277
- onSubmit();
11278
11472
  }
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: [
11473
+ );
11474
+ };
11475
+ const displayValue = getDisplayValue(promotion);
11476
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11477
+ "div",
11478
+ {
11479
+ className: ui.clx(
11480
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11481
+ {
11482
+ "animate-pulse": isLoading
11483
+ }
11484
+ ),
11485
+ children: [
11292
11486
  /* @__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." }) })
11487
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11488
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11489
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11490
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11491
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11492
+ ] }),
11493
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11494
+ ] })
11295
11495
  ] }),
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 })
11579
- }
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"
11592
- }
11593
- )
11594
- ] }) })
11595
- ] });
11496
+ /* @__PURE__ */ jsxRuntime.jsx(
11497
+ ui.IconButton,
11498
+ {
11499
+ size: "small",
11500
+ type: "button",
11501
+ variant: "transparent",
11502
+ onClick: onRemove,
11503
+ isLoading: isPending || isLoading,
11504
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11505
+ }
11506
+ )
11507
+ ]
11508
+ },
11509
+ promotion.id
11510
+ );
11596
11511
  };
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
- });
11617
- }
11618
- };
11619
- return /* @__PURE__ */ jsxRuntime.jsx(
11620
- ui.Button,
11621
- {
11622
- size: "small",
11623
- variant: "secondary",
11624
- onClick: onToggle,
11625
- className: "text-ui-fg-primary shrink-0",
11626
- children
11512
+ function getDisplayValue(promotion) {
11513
+ var _a, _b, _c, _d;
11514
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11515
+ if (!value) {
11516
+ return null;
11517
+ }
11518
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11519
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11520
+ if (!currency) {
11521
+ return null;
11627
11522
  }
11628
- );
11523
+ return getLocaleAmount(value, currency);
11524
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11525
+ return formatPercentage(value);
11526
+ }
11527
+ return null;
11528
+ }
11529
+ const formatter = new Intl.NumberFormat([], {
11530
+ style: "percent",
11531
+ minimumFractionDigits: 2
11532
+ });
11533
+ const formatPercentage = (value, isPercentageValue = false) => {
11534
+ let val = value || 0;
11535
+ if (!isPercentageValue) {
11536
+ val = val / 100;
11537
+ }
11538
+ return formatter.format(val);
11629
11539
  };
11630
- const ShippingProfileForm = ({
11631
- data,
11632
- order,
11633
- preview
11634
- }) => {
11635
- var _a, _b, _c, _d, _e, _f;
11636
- const { setIsOpen } = useStackedModal();
11637
- const form = reactHookForm.useForm({
11638
- resolver: zod.zodResolver(shippingMethodSchema),
11639
- 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
11540
+ function getPromotionIds(items, shippingMethods) {
11541
+ const promotionIds = /* @__PURE__ */ new Set();
11542
+ for (const item of items) {
11543
+ if (item.adjustments) {
11544
+ for (const adjustment of item.adjustments) {
11545
+ if (adjustment.promotion_id) {
11546
+ promotionIds.add(adjustment.promotion_id);
11547
+ }
11548
+ }
11549
+ }
11550
+ }
11551
+ for (const shippingMethod of shippingMethods) {
11552
+ if (shippingMethod.adjustments) {
11553
+ for (const adjustment of shippingMethod.adjustments) {
11554
+ if (adjustment.promotion_id) {
11555
+ promotionIds.add(adjustment.promotion_id);
11556
+ }
11557
+ }
11643
11558
  }
11559
+ }
11560
+ return Array.from(promotionIds);
11561
+ }
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"
11644
11568
  });
11645
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11646
11569
  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;
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
11654
11610
  }
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
- );
11611
+ );
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);
11671
11640
  return;
11672
11641
  }
11673
- await addShippingMethod(
11674
- {
11675
- shipping_option_id: values.shipping_option_id,
11676
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11642
+ await confirmOrderEdit(void 0, {
11643
+ onError: (e) => {
11644
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11677
11645
  },
11678
- {
11679
- onError: (e) => {
11680
- ui.toast.error(e.message);
11681
- },
11682
- onSuccess: () => {
11683
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
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;
11684
11659
  }
11660
+ onSubmit();
11685
11661
  }
11686
- );
11687
- });
11688
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11689
- KeyboundForm,
11690
- {
11691
- className: "flex h-full flex-col overflow-hidden",
11692
- onSubmit,
11693
- 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." }) })
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(
11683
+ ui.Text,
11684
+ {
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
+ )
11699
11700
  ] }),
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
- )
11745
- ] }) })
11746
- ]
11747
- }
11748
- ) }) });
11749
- };
11750
- const shippingMethodSchema = objectType({
11751
- location_id: stringType(),
11752
- shipping_option_id: stringType(),
11753
- custom_amount: unionType([numberType(), stringType()]).optional()
11754
- });
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;
11760
- }
11761
- );
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(
11814
- ui.Text,
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,
11815
11719
  {
11816
- size: "small",
11817
- leading: "compact",
11818
- className: "text-ui-fg-subtle",
11720
+ value: profile.id,
11721
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11819
11722
  children: [
11820
- item.quantity,
11821
- "x"
11822
- ]
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
- },
11879
- ...field
11880
- }
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;
11910
- }
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" }) })
12005
- ] }),
12006
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12007
- ] });
12008
- };
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
- ]
12046
- }
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
- });
12063
- return /* @__PURE__ */ jsxRuntime.jsx(
12064
- Form$2.Field,
12065
- {
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
- }
12086
- }
12087
- );
12088
- };
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;
12111
- const form = reactHookForm.useForm({
12112
- 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)
12125
- });
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
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
+ ] })
11944
+ ]
11945
+ },
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);
11958
+ }
11959
+ return open;
11960
+ },
11961
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12142
11962
  }
12143
- },
12144
- {
12145
- onSuccess: () => {
12146
- handleSuccess();
12147
- },
12148
- onError: (error) => {
12149
- ui.toast.error(error.message);
11963
+ )
11964
+ ] }),
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"
12150
11975
  }
12151
- }
12152
- );
12153
- });
12154
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12155
- KeyboundForm,
12156
- {
12157
- className: "flex flex-1 flex-col overflow-hidden",
12158
- onSubmit,
12159
- 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
- )
12198
- ] }),
12199
- /* @__PURE__ */ jsxRuntime.jsx(
12200
- Form$2.Field,
12201
- {
12202
- 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
- ] })
12209
- }
12210
- ),
12211
- /* @__PURE__ */ jsxRuntime.jsx(
12212
- Form$2.Field,
12213
- {
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
- ] })
12221
- }
12222
- ),
12223
- /* @__PURE__ */ jsxRuntime.jsx(
12224
- Form$2.Field,
12225
- {
12226
- 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
- ] })
12233
- }
12234
- ),
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
- ] }),
12261
- /* @__PURE__ */ jsxRuntime.jsx(
12262
- Form$2.Field,
12263
- {
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
- ] })
12271
- }
12272
- ),
12273
- /* @__PURE__ */ jsxRuntime.jsx(
12274
- Form$2.Field,
12275
- {
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
- ] })
12283
- }
12284
- )
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
- ] }) })
12290
- ]
12291
- }
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 };
12314
- };
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 })
11976
+ )
11977
+ ] }) })
12331
11978
  ] });
12332
11979
  };
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
12343
- },
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
+ });
12000
+ }
12001
+ };
12002
+ return /* @__PURE__ */ jsxRuntime.jsx(
12003
+ ui.Button,
12344
12004
  {
12345
- enabled: !!promoIds.length
12005
+ size: "small",
12006
+ variant: "secondary",
12007
+ onClick: onToggle,
12008
+ className: "text-ui-fg-primary shrink-0",
12009
+ children
12346
12010
  }
12347
12011
  );
12348
- const comboboxData = useComboboxData({
12349
- queryKey: ["promotions", "combobox", promoIds],
12350
- queryFn: async (params) => {
12351
- return await sdk.admin.promotion.list({
12352
- ...params,
12353
- id: {
12354
- $nin: promoIds
12355
- }
12356
- });
12357
- },
12358
- getOptions: (data) => {
12359
- return data.promotions.map((promotion) => ({
12360
- label: promotion.code,
12361
- value: promotion.code
12362
- }));
12012
+ };
12013
+ const ShippingProfileForm = ({
12014
+ data,
12015
+ order,
12016
+ preview
12017
+ }) => {
12018
+ var _a, _b, _c, _d, _e, _f;
12019
+ const { setIsOpen } = useStackedModal();
12020
+ const form = reactHookForm.useForm({
12021
+ resolver: zod.zodResolver(shippingMethodSchema),
12022
+ defaultValues: {
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
12363
12026
  }
12364
12027
  });
12365
- const add = async (value) => {
12366
- if (!value) {
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);
12367
12036
  return;
12368
12037
  }
12369
- addPromotions(
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
+ }
12052
+ }
12053
+ );
12054
+ return;
12055
+ }
12056
+ await addShippingMethod(
12370
12057
  {
12371
- promo_codes: [value]
12058
+ shipping_option_id: values.shipping_option_id,
12059
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12372
12060
  },
12373
12061
  {
12374
12062
  onError: (e) => {
12375
12063
  ui.toast.error(e.message);
12376
- comboboxData.onSearchValueChange("");
12377
- setComboboxValue("");
12378
12064
  },
12379
12065
  onSuccess: () => {
12380
- comboboxData.onSearchValueChange("");
12381
- setComboboxValue("");
12066
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12382
12067
  }
12383
12068
  }
12384
12069
  );
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;
12070
+ });
12071
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12072
+ KeyboundForm,
12073
+ {
12074
+ className: "flex h-full flex-col overflow-hidden",
12075
+ onSubmit,
12076
+ children: [
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." }) })
12082
+ ] }),
12083
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12084
+ /* @__PURE__ */ jsxRuntime.jsx(
12085
+ LocationField,
12086
+ {
12087
+ control: form.control,
12088
+ setValue: form.setValue
12089
+ }
12090
+ ),
12091
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12092
+ /* @__PURE__ */ jsxRuntime.jsx(
12093
+ ShippingOptionField,
12094
+ {
12095
+ shippingProfileId: data.shippingProfileId,
12096
+ preview,
12097
+ control: form.control
12098
+ }
12099
+ ),
12100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12101
+ /* @__PURE__ */ jsxRuntime.jsx(
12102
+ CustomAmountField,
12103
+ {
12104
+ control: form.control,
12105
+ currencyCode: order.currency_code
12106
+ }
12107
+ ),
12108
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12109
+ /* @__PURE__ */ jsxRuntime.jsx(
12110
+ ItemsPreview,
12111
+ {
12112
+ order,
12113
+ shippingProfileId: data.shippingProfileId
12114
+ }
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" }) }),
12119
+ /* @__PURE__ */ jsxRuntime.jsx(
12120
+ ui.Button,
12121
+ {
12122
+ size: "small",
12123
+ type: "submit",
12124
+ isLoading: isPending || isUpdatingShippingMethod,
12125
+ children: data.shippingMethod ? "Update" : "Add"
12126
+ }
12127
+ )
12128
+ ] }) })
12129
+ ]
12402
12130
  }
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);
12412
- }
12413
- });
12414
- };
12415
- if (isError) {
12416
- throw error;
12417
- }
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
- )
12131
+ ) }) });
12132
+ };
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" }) })
12440
12154
  ] }),
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,
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",
12444
12157
  {
12445
- promotion,
12446
- orderId: preview.id,
12447
- isLoading: isPending
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
+ ]
12448
12209
  },
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
- ] }) })
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
+ ] })
12464
12220
  ] });
12465
12221
  };
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(
12475
- {
12476
- promo_codes: [promotion.code]
12477
- },
12478
- {
12479
- onError: (e) => {
12480
- ui.toast.error(e.message);
12481
- }
12482
- }
12483
- );
12484
- };
12485
- const displayValue = getDisplayValue(promotion);
12486
- return /* @__PURE__ */ jsxRuntime.jsxs(
12487
- "div",
12488
- {
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
- ),
12495
- 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
- )
12517
- ]
12222
+ const LocationField = ({ control, setValue }) => {
12223
+ const locations = useComboboxData({
12224
+ queryKey: ["locations"],
12225
+ queryFn: async (params) => {
12226
+ return await sdk.admin.stockLocation.list(params);
12518
12227
  },
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;
12228
+ getOptions: (data) => {
12229
+ return data.stock_locations.map((location) => ({
12230
+ label: location.name,
12231
+ value: location.id
12232
+ }));
12532
12233
  }
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);
12234
+ });
12235
+ return /* @__PURE__ */ jsxRuntime.jsx(
12236
+ Form$2.Field,
12237
+ {
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
+ }
12267
+ }
12268
+ );
12549
12269
  };
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);
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],
12279
+ queryFn: async (params) => {
12280
+ return await sdk.admin.shippingOption.list({
12281
+ ...params,
12282
+ stock_location_id: locationId,
12283
+ shipping_profile_id: shippingProfileId
12284
+ });
12285
+ },
12286
+ getOptions: (data) => {
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;
12557
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
+ ] }) });
12558
12336
  }
12559
12337
  }
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
- }
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
+ ] });
12567
12365
  }
12568
12366
  }
12569
- }
12570
- return Array.from(promotionIds);
12571
- }
12367
+ );
12368
+ };
12572
12369
  const TransferOwnership = () => {
12573
12370
  const { id } = reactRouterDom.useParams();
12574
12371
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12592,7 +12389,7 @@ const TransferOwnershipForm = ({ order }) => {
12592
12389
  defaultValues: {
12593
12390
  customer_id: order.customer_id || ""
12594
12391
  },
12595
- resolver: zod.zodResolver(schema)
12392
+ resolver: zod.zodResolver(schema$1)
12596
12393
  });
12597
12394
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12598
12395
  const { handleSuccess } = useRouteModal();
@@ -13042,9 +12839,212 @@ const Illustration = () => {
13042
12839
  }
13043
12840
  );
13044
12841
  };
13045
- const schema = objectType({
12842
+ const schema$1 = objectType({
13046
12843
  customer_id: stringType().min(1)
13047
12844
  });
12845
+ const ShippingAddress = () => {
12846
+ const { id } = reactRouterDom.useParams();
12847
+ const { order, isPending, isError, error } = useOrder(id, {
12848
+ fields: "+shipping_address"
12849
+ });
12850
+ if (isError) {
12851
+ throw error;
12852
+ }
12853
+ const isReady = !isPending && !!order;
12854
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12855
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12856
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12857
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12858
+ ] }),
12859
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12860
+ ] });
12861
+ };
12862
+ const ShippingAddressForm = ({ order }) => {
12863
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12864
+ const form = reactHookForm.useForm({
12865
+ defaultValues: {
12866
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12867
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12868
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12869
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12870
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12871
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12872
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12873
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12874
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12875
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12876
+ },
12877
+ resolver: zod.zodResolver(schema)
12878
+ });
12879
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12880
+ const { handleSuccess } = useRouteModal();
12881
+ const onSubmit = form.handleSubmit(async (data) => {
12882
+ await mutateAsync(
12883
+ {
12884
+ shipping_address: {
12885
+ first_name: data.first_name,
12886
+ last_name: data.last_name,
12887
+ company: data.company,
12888
+ address_1: data.address_1,
12889
+ address_2: data.address_2,
12890
+ city: data.city,
12891
+ province: data.province,
12892
+ country_code: data.country_code,
12893
+ postal_code: data.postal_code,
12894
+ phone: data.phone
12895
+ }
12896
+ },
12897
+ {
12898
+ onSuccess: () => {
12899
+ handleSuccess();
12900
+ },
12901
+ onError: (error) => {
12902
+ ui.toast.error(error.message);
12903
+ }
12904
+ }
12905
+ );
12906
+ });
12907
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12908
+ KeyboundForm,
12909
+ {
12910
+ className: "flex flex-1 flex-col overflow-hidden",
12911
+ onSubmit,
12912
+ children: [
12913
+ /* @__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: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "country_code",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12927
+ /* @__PURE__ */ jsxRuntime.jsx(
12928
+ Form$2.Field,
12929
+ {
12930
+ control: form.control,
12931
+ name: "first_name",
12932
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12935
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12936
+ ] })
12937
+ }
12938
+ ),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(
12940
+ Form$2.Field,
12941
+ {
12942
+ control: form.control,
12943
+ name: "last_name",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12949
+ }
12950
+ )
12951
+ ] }),
12952
+ /* @__PURE__ */ jsxRuntime.jsx(
12953
+ Form$2.Field,
12954
+ {
12955
+ control: form.control,
12956
+ name: "company",
12957
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12960
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12961
+ ] })
12962
+ }
12963
+ ),
12964
+ /* @__PURE__ */ jsxRuntime.jsx(
12965
+ Form$2.Field,
12966
+ {
12967
+ control: form.control,
12968
+ name: "address_1",
12969
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12973
+ ] })
12974
+ }
12975
+ ),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "address_2",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12989
+ /* @__PURE__ */ jsxRuntime.jsx(
12990
+ Form$2.Field,
12991
+ {
12992
+ control: form.control,
12993
+ name: "postal_code",
12994
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12998
+ ] })
12999
+ }
13000
+ ),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13003
+ {
13004
+ control: form.control,
13005
+ name: "city",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13011
+ }
13012
+ )
13013
+ ] }),
13014
+ /* @__PURE__ */ jsxRuntime.jsx(
13015
+ Form$2.Field,
13016
+ {
13017
+ control: form.control,
13018
+ name: "province",
13019
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13022
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13023
+ ] })
13024
+ }
13025
+ ),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(
13027
+ Form$2.Field,
13028
+ {
13029
+ control: form.control,
13030
+ name: "phone",
13031
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13035
+ ] })
13036
+ }
13037
+ )
13038
+ ] }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13042
+ ] }) })
13043
+ ]
13044
+ }
13045
+ ) });
13046
+ };
13047
+ const schema = addressSchema;
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13077,33 +13077,33 @@ const routeModule = {
13077
13077
  Component: Email,
13078
13078
  path: "/draft-orders/:id/email"
13079
13079
  },
13080
- {
13081
- Component: CustomItems,
13082
- path: "/draft-orders/:id/custom-items"
13083
- },
13084
13080
  {
13085
13081
  Component: Metadata,
13086
13082
  path: "/draft-orders/:id/metadata"
13087
13083
  },
13088
13084
  {
13089
- Component: Shipping,
13090
- path: "/draft-orders/:id/shipping"
13085
+ Component: CustomItems,
13086
+ path: "/draft-orders/:id/custom-items"
13091
13087
  },
13092
13088
  {
13093
13089
  Component: SalesChannel,
13094
13090
  path: "/draft-orders/:id/sales-channel"
13095
13091
  },
13096
- {
13097
- Component: ShippingAddress,
13098
- path: "/draft-orders/:id/shipping-address"
13099
- },
13100
13092
  {
13101
13093
  Component: Promotions,
13102
13094
  path: "/draft-orders/:id/promotions"
13103
13095
  },
13096
+ {
13097
+ Component: Shipping,
13098
+ path: "/draft-orders/:id/shipping"
13099
+ },
13104
13100
  {
13105
13101
  Component: TransferOwnership,
13106
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
+ },
13104
+ {
13105
+ Component: ShippingAddress,
13106
+ path: "/draft-orders/:id/shipping-address"
13107
13107
  }
13108
13108
  ]
13109
13109
  }