@medusajs/draft-order 2.11.3-preview-20251105090148 → 2.11.3

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.
@@ -11171,105 +11171,77 @@ function getHasUneditableRows(metadata) {
11171
11171
  (value) => !EDITABLE_TYPES.includes(typeof value)
11172
11172
  );
11173
11173
  }
11174
- const PROMOTION_QUERY_KEY = "promotions";
11175
- const promotionsQueryKeys = {
11176
- list: (query2) => [
11177
- PROMOTION_QUERY_KEY,
11178
- query2 ? query2 : void 0
11179
- ],
11180
- detail: (id, query2) => [
11181
- PROMOTION_QUERY_KEY,
11182
- id,
11183
- query2 ? query2 : void 0
11184
- ]
11185
- };
11186
- const usePromotions = (query2, options) => {
11187
- const { data, ...rest } = reactQuery.useQuery({
11188
- queryKey: promotionsQueryKeys.list(query2),
11189
- queryFn: async () => sdk.admin.promotion.list(query2),
11190
- ...options
11191
- });
11192
- return { ...data, ...rest };
11193
- };
11194
- const Promotions = () => {
11174
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11175
+ const Shipping = () => {
11176
+ var _a;
11195
11177
  const { id } = reactRouterDom.useParams();
11178
+ const { order, isPending, isError, error } = useOrder(id, {
11179
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11180
+ });
11196
11181
  const {
11197
11182
  order: preview,
11183
+ isPending: isPreviewPending,
11198
11184
  isError: isPreviewError,
11199
11185
  error: previewError
11200
- } = useOrderPreview(id, void 0);
11186
+ } = useOrderPreview(id);
11201
11187
  useInitiateOrderEdit({ preview });
11202
11188
  const { onCancel } = useCancelOrderEdit({ preview });
11189
+ if (isError) {
11190
+ throw error;
11191
+ }
11203
11192
  if (isPreviewError) {
11204
11193
  throw previewError;
11205
11194
  }
11206
- const isReady = !!preview;
11207
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11208
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11209
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11210
- ] });
11195
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11196
+ const isReady = preview && !isPreviewPending && order && !isPending;
11197
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11198
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11199
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11200
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11201
+ /* @__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." }) })
11202
+ ] }) }) }),
11203
+ /* @__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" }) }) })
11204
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11205
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11206
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11207
+ ] }) });
11211
11208
  };
11212
- const PromotionForm = ({ preview }) => {
11213
- const { items, shipping_methods } = preview;
11209
+ const ShippingForm = ({ preview, order }) => {
11210
+ var _a;
11211
+ const { setIsOpen } = useStackedModal();
11214
11212
  const [isSubmitting, setIsSubmitting] = React.useState(false);
11215
- const [comboboxValue, setComboboxValue] = React.useState("");
11216
- const { handleSuccess } = useRouteModal();
11217
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11218
- const promoIds = getPromotionIds(items, shipping_methods);
11219
- const { promotions, isPending, isError, error } = usePromotions(
11213
+ const [data, setData] = React.useState(null);
11214
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11215
+ const { shipping_options } = useShippingOptions(
11220
11216
  {
11221
- id: promoIds
11217
+ id: appliedShippingOptionIds,
11218
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11222
11219
  },
11223
11220
  {
11224
- enabled: !!promoIds.length
11221
+ enabled: appliedShippingOptionIds.length > 0
11225
11222
  }
11226
11223
  );
11227
- const comboboxData = useComboboxData({
11228
- queryKey: ["promotions", "combobox", promoIds],
11229
- queryFn: async (params) => {
11230
- return await sdk.admin.promotion.list({
11231
- ...params,
11232
- id: {
11233
- $nin: promoIds
11234
- }
11235
- });
11236
- },
11237
- getOptions: (data) => {
11238
- return data.promotions.map((promotion) => ({
11239
- label: promotion.code,
11240
- value: promotion.code
11241
- }));
11242
- }
11243
- });
11244
- const add = async (value) => {
11245
- if (!value) {
11246
- return;
11247
- }
11248
- addPromotions(
11249
- {
11250
- promo_codes: [value]
11251
- },
11252
- {
11253
- onError: (e) => {
11254
- ui.toast.error(e.message);
11255
- comboboxData.onSearchValueChange("");
11256
- setComboboxValue("");
11257
- },
11258
- onSuccess: () => {
11259
- comboboxData.onSearchValueChange("");
11260
- setComboboxValue("");
11261
- }
11262
- }
11263
- );
11264
- };
11224
+ const uniqueShippingProfiles = React.useMemo(() => {
11225
+ const profiles = /* @__PURE__ */ new Map();
11226
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11227
+ profiles.set(profile.id, profile);
11228
+ });
11229
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11230
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11231
+ });
11232
+ return Array.from(profiles.values());
11233
+ }, [order.items, shipping_options]);
11234
+ const { handleSuccess } = useRouteModal();
11265
11235
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11266
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11236
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11237
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11238
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11267
11239
  const onSubmit = async () => {
11268
11240
  setIsSubmitting(true);
11269
11241
  let requestSucceeded = false;
11270
11242
  await requestOrderEdit(void 0, {
11271
11243
  onError: (e) => {
11272
- ui.toast.error(e.message);
11244
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11273
11245
  },
11274
11246
  onSuccess: () => {
11275
11247
  requestSucceeded = true;
@@ -11281,7 +11253,7 @@ const PromotionForm = ({ preview }) => {
11281
11253
  }
11282
11254
  await confirmOrderEdit(void 0, {
11283
11255
  onError: (e) => {
11284
- ui.toast.error(e.message);
11256
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11285
11257
  },
11286
11258
  onSuccess: () => {
11287
11259
  handleSuccess();
@@ -11291,371 +11263,16 @@ const PromotionForm = ({ preview }) => {
11291
11263
  }
11292
11264
  });
11293
11265
  };
11294
- if (isError) {
11295
- throw error;
11296
- }
11297
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11298
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11299
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11300
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11301
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11302
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11303
- ] }),
11304
- /* @__PURE__ */ jsxRuntime.jsx(
11305
- Combobox,
11306
- {
11307
- id: "promotion-combobox",
11308
- "aria-describedby": "promotion-combobox-hint",
11309
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11310
- fetchNextPage: comboboxData.fetchNextPage,
11311
- options: comboboxData.options,
11312
- onSearchValueChange: comboboxData.onSearchValueChange,
11313
- searchValue: comboboxData.searchValue,
11314
- disabled: comboboxData.disabled || isAddingPromotions,
11315
- onChange: add,
11316
- value: comboboxValue
11317
- }
11318
- )
11319
- ] }),
11320
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11321
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11322
- PromotionItem,
11323
- {
11324
- promotion,
11325
- orderId: preview.id,
11326
- isLoading: isPending
11327
- },
11328
- promotion.id
11329
- )) })
11330
- ] }) }),
11331
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11332
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11333
- /* @__PURE__ */ jsxRuntime.jsx(
11334
- ui.Button,
11335
- {
11336
- size: "small",
11337
- type: "submit",
11338
- isLoading: isSubmitting || isAddingPromotions,
11339
- children: "Save"
11340
- }
11341
- )
11342
- ] }) })
11343
- ] });
11344
- };
11345
- const PromotionItem = ({
11346
- promotion,
11347
- orderId,
11348
- isLoading
11349
- }) => {
11350
- var _a;
11351
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11352
- const onRemove = async () => {
11353
- removePromotions(
11354
- {
11355
- promo_codes: [promotion.code]
11356
- },
11357
- {
11358
- onError: (e) => {
11359
- ui.toast.error(e.message);
11266
+ const onKeydown = React.useCallback(
11267
+ (e) => {
11268
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11269
+ if (data || isSubmitting) {
11270
+ return;
11360
11271
  }
11272
+ onSubmit();
11361
11273
  }
11362
- );
11363
- };
11364
- const displayValue = getDisplayValue(promotion);
11365
- return /* @__PURE__ */ jsxRuntime.jsxs(
11366
- "div",
11367
- {
11368
- className: ui.clx(
11369
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11370
- {
11371
- "animate-pulse": isLoading
11372
- }
11373
- ),
11374
- children: [
11375
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11376
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11377
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11378
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11379
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11380
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11381
- ] }),
11382
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11383
- ] })
11384
- ] }),
11385
- /* @__PURE__ */ jsxRuntime.jsx(
11386
- ui.IconButton,
11387
- {
11388
- size: "small",
11389
- type: "button",
11390
- variant: "transparent",
11391
- onClick: onRemove,
11392
- isLoading: isPending || isLoading,
11393
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11394
- }
11395
- )
11396
- ]
11397
11274
  },
11398
- promotion.id
11399
- );
11400
- };
11401
- function getDisplayValue(promotion) {
11402
- var _a, _b, _c, _d;
11403
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11404
- if (!value) {
11405
- return null;
11406
- }
11407
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11408
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11409
- if (!currency) {
11410
- return null;
11411
- }
11412
- return getLocaleAmount(value, currency);
11413
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11414
- return formatPercentage(value);
11415
- }
11416
- return null;
11417
- }
11418
- const formatter = new Intl.NumberFormat([], {
11419
- style: "percent",
11420
- minimumFractionDigits: 2
11421
- });
11422
- const formatPercentage = (value, isPercentageValue = false) => {
11423
- let val = value || 0;
11424
- if (!isPercentageValue) {
11425
- val = val / 100;
11426
- }
11427
- return formatter.format(val);
11428
- };
11429
- function getPromotionIds(items, shippingMethods) {
11430
- const promotionIds = /* @__PURE__ */ new Set();
11431
- for (const item of items) {
11432
- if (item.adjustments) {
11433
- for (const adjustment of item.adjustments) {
11434
- if (adjustment.promotion_id) {
11435
- promotionIds.add(adjustment.promotion_id);
11436
- }
11437
- }
11438
- }
11439
- }
11440
- for (const shippingMethod of shippingMethods) {
11441
- if (shippingMethod.adjustments) {
11442
- for (const adjustment of shippingMethod.adjustments) {
11443
- if (adjustment.promotion_id) {
11444
- promotionIds.add(adjustment.promotion_id);
11445
- }
11446
- }
11447
- }
11448
- }
11449
- return Array.from(promotionIds);
11450
- }
11451
- const SalesChannel = () => {
11452
- const { id } = reactRouterDom.useParams();
11453
- const { draft_order, isPending, isError, error } = useDraftOrder(
11454
- id,
11455
- {
11456
- fields: "+sales_channel_id"
11457
- },
11458
- {
11459
- enabled: !!id
11460
- }
11461
- );
11462
- if (isError) {
11463
- throw error;
11464
- }
11465
- const ISrEADY = !!draft_order && !isPending;
11466
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11467
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11468
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11469
- /* @__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" }) })
11470
- ] }),
11471
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11472
- ] });
11473
- };
11474
- const SalesChannelForm = ({ order }) => {
11475
- const form = reactHookForm.useForm({
11476
- defaultValues: {
11477
- sales_channel_id: order.sales_channel_id || ""
11478
- },
11479
- resolver: zod.zodResolver(schema$2)
11480
- });
11481
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11482
- const { handleSuccess } = useRouteModal();
11483
- const onSubmit = form.handleSubmit(async (data) => {
11484
- await mutateAsync(
11485
- {
11486
- sales_channel_id: data.sales_channel_id
11487
- },
11488
- {
11489
- onSuccess: () => {
11490
- ui.toast.success("Sales channel updated");
11491
- handleSuccess();
11492
- },
11493
- onError: (error) => {
11494
- ui.toast.error(error.message);
11495
- }
11496
- }
11497
- );
11498
- });
11499
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11500
- KeyboundForm,
11501
- {
11502
- className: "flex flex-1 flex-col overflow-hidden",
11503
- onSubmit,
11504
- children: [
11505
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11506
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11507
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11508
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11509
- ] }) })
11510
- ]
11511
- }
11512
- ) });
11513
- };
11514
- const SalesChannelField = ({ control, order }) => {
11515
- const salesChannels = useComboboxData({
11516
- queryFn: async (params) => {
11517
- return await sdk.admin.salesChannel.list(params);
11518
- },
11519
- queryKey: ["sales-channels"],
11520
- getOptions: (data) => {
11521
- return data.sales_channels.map((salesChannel) => ({
11522
- label: salesChannel.name,
11523
- value: salesChannel.id
11524
- }));
11525
- },
11526
- defaultValue: order.sales_channel_id || void 0
11527
- });
11528
- return /* @__PURE__ */ jsxRuntime.jsx(
11529
- Form$2.Field,
11530
- {
11531
- control,
11532
- name: "sales_channel_id",
11533
- render: ({ field }) => {
11534
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11535
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11536
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11537
- Combobox,
11538
- {
11539
- options: salesChannels.options,
11540
- fetchNextPage: salesChannels.fetchNextPage,
11541
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11542
- searchValue: salesChannels.searchValue,
11543
- onSearchValueChange: salesChannels.onSearchValueChange,
11544
- placeholder: "Select sales channel",
11545
- ...field
11546
- }
11547
- ) }),
11548
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11549
- ] });
11550
- }
11551
- }
11552
- );
11553
- };
11554
- const schema$2 = objectType({
11555
- sales_channel_id: stringType().min(1)
11556
- });
11557
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11558
- const Shipping = () => {
11559
- var _a;
11560
- const { id } = reactRouterDom.useParams();
11561
- const { order, isPending, isError, error } = useOrder(id, {
11562
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11563
- });
11564
- const {
11565
- order: preview,
11566
- isPending: isPreviewPending,
11567
- isError: isPreviewError,
11568
- error: previewError
11569
- } = useOrderPreview(id);
11570
- useInitiateOrderEdit({ preview });
11571
- const { onCancel } = useCancelOrderEdit({ preview });
11572
- if (isError) {
11573
- throw error;
11574
- }
11575
- if (isPreviewError) {
11576
- throw previewError;
11577
- }
11578
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11579
- const isReady = preview && !isPreviewPending && order && !isPending;
11580
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11581
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11582
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
11583
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11584
- /* @__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." }) })
11585
- ] }) }) }),
11586
- /* @__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" }) }) })
11587
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11588
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11589
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11590
- ] }) });
11591
- };
11592
- const ShippingForm = ({ preview, order }) => {
11593
- var _a;
11594
- const { setIsOpen } = useStackedModal();
11595
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11596
- const [data, setData] = React.useState(null);
11597
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11598
- const { shipping_options } = useShippingOptions(
11599
- {
11600
- id: appliedShippingOptionIds,
11601
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11602
- },
11603
- {
11604
- enabled: appliedShippingOptionIds.length > 0
11605
- }
11606
- );
11607
- const uniqueShippingProfiles = React.useMemo(() => {
11608
- const profiles = /* @__PURE__ */ new Map();
11609
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11610
- profiles.set(profile.id, profile);
11611
- });
11612
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11613
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11614
- });
11615
- return Array.from(profiles.values());
11616
- }, [order.items, shipping_options]);
11617
- const { handleSuccess } = useRouteModal();
11618
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11619
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11620
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11621
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11622
- const onSubmit = async () => {
11623
- setIsSubmitting(true);
11624
- let requestSucceeded = false;
11625
- await requestOrderEdit(void 0, {
11626
- onError: (e) => {
11627
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11628
- },
11629
- onSuccess: () => {
11630
- requestSucceeded = true;
11631
- }
11632
- });
11633
- if (!requestSucceeded) {
11634
- setIsSubmitting(false);
11635
- return;
11636
- }
11637
- await confirmOrderEdit(void 0, {
11638
- onError: (e) => {
11639
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11640
- },
11641
- onSuccess: () => {
11642
- handleSuccess();
11643
- },
11644
- onSettled: () => {
11645
- setIsSubmitting(false);
11646
- }
11647
- });
11648
- };
11649
- const onKeydown = React.useCallback(
11650
- (e) => {
11651
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11652
- if (data || isSubmitting) {
11653
- return;
11654
- }
11655
- onSubmit();
11656
- }
11657
- },
11658
- [data, isSubmitting, onSubmit]
11275
+ [data, isSubmitting, onSubmit]
11659
11276
  );
11660
11277
  React.useEffect(() => {
11661
11278
  document.addEventListener("keydown", onKeydown);
@@ -12361,224 +11978,21 @@ const CustomAmountField = ({
12361
11978
  }
12362
11979
  );
12363
11980
  };
12364
- const ShippingAddress = () => {
11981
+ const TransferOwnership = () => {
12365
11982
  const { id } = reactRouterDom.useParams();
12366
- const { order, isPending, isError, error } = useOrder(id, {
12367
- fields: "+shipping_address"
11983
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11984
+ fields: "id,customer_id,customer.*"
12368
11985
  });
12369
11986
  if (isError) {
12370
11987
  throw error;
12371
11988
  }
12372
- const isReady = !isPending && !!order;
11989
+ const isReady = !isPending && !!draft_order;
12373
11990
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12374
11991
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12375
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12376
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11992
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11993
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12377
11994
  ] }),
12378
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12379
- ] });
12380
- };
12381
- const ShippingAddressForm = ({ order }) => {
12382
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12383
- const form = reactHookForm.useForm({
12384
- defaultValues: {
12385
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12386
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12387
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12388
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12389
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12390
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12391
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12392
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12393
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12394
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12395
- },
12396
- resolver: zod.zodResolver(schema$1)
12397
- });
12398
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12399
- const { handleSuccess } = useRouteModal();
12400
- const onSubmit = form.handleSubmit(async (data) => {
12401
- await mutateAsync(
12402
- {
12403
- shipping_address: {
12404
- first_name: data.first_name,
12405
- last_name: data.last_name,
12406
- company: data.company,
12407
- address_1: data.address_1,
12408
- address_2: data.address_2,
12409
- city: data.city,
12410
- province: data.province,
12411
- country_code: data.country_code,
12412
- postal_code: data.postal_code,
12413
- phone: data.phone
12414
- }
12415
- },
12416
- {
12417
- onSuccess: () => {
12418
- handleSuccess();
12419
- },
12420
- onError: (error) => {
12421
- ui.toast.error(error.message);
12422
- }
12423
- }
12424
- );
12425
- });
12426
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12427
- KeyboundForm,
12428
- {
12429
- className: "flex flex-1 flex-col overflow-hidden",
12430
- onSubmit,
12431
- children: [
12432
- /* @__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: [
12433
- /* @__PURE__ */ jsxRuntime.jsx(
12434
- Form$2.Field,
12435
- {
12436
- control: form.control,
12437
- name: "country_code",
12438
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12440
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12441
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12442
- ] })
12443
- }
12444
- ),
12445
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12446
- /* @__PURE__ */ jsxRuntime.jsx(
12447
- Form$2.Field,
12448
- {
12449
- control: form.control,
12450
- name: "first_name",
12451
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12452
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12453
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12454
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12455
- ] })
12456
- }
12457
- ),
12458
- /* @__PURE__ */ jsxRuntime.jsx(
12459
- Form$2.Field,
12460
- {
12461
- control: form.control,
12462
- name: "last_name",
12463
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12464
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12465
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12466
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12467
- ] })
12468
- }
12469
- )
12470
- ] }),
12471
- /* @__PURE__ */ jsxRuntime.jsx(
12472
- Form$2.Field,
12473
- {
12474
- control: form.control,
12475
- name: "company",
12476
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12477
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12478
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12479
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12480
- ] })
12481
- }
12482
- ),
12483
- /* @__PURE__ */ jsxRuntime.jsx(
12484
- Form$2.Field,
12485
- {
12486
- control: form.control,
12487
- name: "address_1",
12488
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12489
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12490
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12491
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12492
- ] })
12493
- }
12494
- ),
12495
- /* @__PURE__ */ jsxRuntime.jsx(
12496
- Form$2.Field,
12497
- {
12498
- control: form.control,
12499
- name: "address_2",
12500
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12501
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12502
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12503
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12504
- ] })
12505
- }
12506
- ),
12507
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12508
- /* @__PURE__ */ jsxRuntime.jsx(
12509
- Form$2.Field,
12510
- {
12511
- control: form.control,
12512
- name: "postal_code",
12513
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12514
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12515
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12516
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12517
- ] })
12518
- }
12519
- ),
12520
- /* @__PURE__ */ jsxRuntime.jsx(
12521
- Form$2.Field,
12522
- {
12523
- control: form.control,
12524
- name: "city",
12525
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12526
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12527
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12528
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12529
- ] })
12530
- }
12531
- )
12532
- ] }),
12533
- /* @__PURE__ */ jsxRuntime.jsx(
12534
- Form$2.Field,
12535
- {
12536
- control: form.control,
12537
- name: "province",
12538
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12539
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12541
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12542
- ] })
12543
- }
12544
- ),
12545
- /* @__PURE__ */ jsxRuntime.jsx(
12546
- Form$2.Field,
12547
- {
12548
- control: form.control,
12549
- name: "phone",
12550
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12551
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12552
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12553
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12554
- ] })
12555
- }
12556
- )
12557
- ] }) }),
12558
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12559
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12560
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12561
- ] }) })
12562
- ]
12563
- }
12564
- ) });
12565
- };
12566
- const schema$1 = addressSchema;
12567
- const TransferOwnership = () => {
12568
- const { id } = reactRouterDom.useParams();
12569
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12570
- fields: "id,customer_id,customer.*"
12571
- });
12572
- if (isError) {
12573
- throw error;
12574
- }
12575
- const isReady = !isPending && !!draft_order;
12576
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12577
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12578
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12579
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12580
- ] }),
12581
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11995
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12582
11996
  ] });
12583
11997
  };
12584
11998
  const TransferOwnershipForm = ({ order }) => {
@@ -12587,7 +12001,7 @@ const TransferOwnershipForm = ({ order }) => {
12587
12001
  defaultValues: {
12588
12002
  customer_id: order.customer_id || ""
12589
12003
  },
12590
- resolver: zod.zodResolver(schema)
12004
+ resolver: zod.zodResolver(schema$2)
12591
12005
  });
12592
12006
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12593
12007
  const { handleSuccess } = useRouteModal();
@@ -12987,59 +12401,645 @@ const Illustration = () => {
12987
12401
  transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12988
12402
  }
12989
12403
  ) }),
12990
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12991
- "rect",
12404
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12405
+ "rect",
12406
+ {
12407
+ width: "12",
12408
+ height: "12",
12409
+ fill: "white",
12410
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12411
+ }
12412
+ ) }),
12413
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12414
+ "rect",
12415
+ {
12416
+ width: "12",
12417
+ height: "12",
12418
+ fill: "white",
12419
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12420
+ }
12421
+ ) }),
12422
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12423
+ "rect",
12424
+ {
12425
+ width: "12",
12426
+ height: "12",
12427
+ fill: "white",
12428
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12429
+ }
12430
+ ) }),
12431
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12432
+ "rect",
12433
+ {
12434
+ width: "12",
12435
+ height: "12",
12436
+ fill: "white",
12437
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12438
+ }
12439
+ ) }),
12440
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12441
+ "rect",
12442
+ {
12443
+ width: "12",
12444
+ height: "12",
12445
+ fill: "white",
12446
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12447
+ }
12448
+ ) })
12449
+ ] })
12450
+ ]
12451
+ }
12452
+ );
12453
+ };
12454
+ const schema$2 = objectType({
12455
+ customer_id: stringType().min(1)
12456
+ });
12457
+ const PROMOTION_QUERY_KEY = "promotions";
12458
+ const promotionsQueryKeys = {
12459
+ list: (query2) => [
12460
+ PROMOTION_QUERY_KEY,
12461
+ query2 ? query2 : void 0
12462
+ ],
12463
+ detail: (id, query2) => [
12464
+ PROMOTION_QUERY_KEY,
12465
+ id,
12466
+ query2 ? query2 : void 0
12467
+ ]
12468
+ };
12469
+ const usePromotions = (query2, options) => {
12470
+ const { data, ...rest } = reactQuery.useQuery({
12471
+ queryKey: promotionsQueryKeys.list(query2),
12472
+ queryFn: async () => sdk.admin.promotion.list(query2),
12473
+ ...options
12474
+ });
12475
+ return { ...data, ...rest };
12476
+ };
12477
+ const Promotions = () => {
12478
+ const { id } = reactRouterDom.useParams();
12479
+ const {
12480
+ order: preview,
12481
+ isError: isPreviewError,
12482
+ error: previewError
12483
+ } = useOrderPreview(id, void 0);
12484
+ useInitiateOrderEdit({ preview });
12485
+ const { onCancel } = useCancelOrderEdit({ preview });
12486
+ if (isPreviewError) {
12487
+ throw previewError;
12488
+ }
12489
+ const isReady = !!preview;
12490
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
12491
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
12492
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
12493
+ ] });
12494
+ };
12495
+ const PromotionForm = ({ preview }) => {
12496
+ const { items, shipping_methods } = preview;
12497
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12498
+ const [comboboxValue, setComboboxValue] = React.useState("");
12499
+ const { handleSuccess } = useRouteModal();
12500
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
12501
+ const promoIds = getPromotionIds(items, shipping_methods);
12502
+ const { promotions, isPending, isError, error } = usePromotions(
12503
+ {
12504
+ id: promoIds
12505
+ },
12506
+ {
12507
+ enabled: !!promoIds.length
12508
+ }
12509
+ );
12510
+ const comboboxData = useComboboxData({
12511
+ queryKey: ["promotions", "combobox", promoIds],
12512
+ queryFn: async (params) => {
12513
+ return await sdk.admin.promotion.list({
12514
+ ...params,
12515
+ id: {
12516
+ $nin: promoIds
12517
+ }
12518
+ });
12519
+ },
12520
+ getOptions: (data) => {
12521
+ return data.promotions.map((promotion) => ({
12522
+ label: promotion.code,
12523
+ value: promotion.code
12524
+ }));
12525
+ }
12526
+ });
12527
+ const add = async (value) => {
12528
+ if (!value) {
12529
+ return;
12530
+ }
12531
+ addPromotions(
12532
+ {
12533
+ promo_codes: [value]
12534
+ },
12535
+ {
12536
+ onError: (e) => {
12537
+ ui.toast.error(e.message);
12538
+ comboboxData.onSearchValueChange("");
12539
+ setComboboxValue("");
12540
+ },
12541
+ onSuccess: () => {
12542
+ comboboxData.onSearchValueChange("");
12543
+ setComboboxValue("");
12544
+ }
12545
+ }
12546
+ );
12547
+ };
12548
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12549
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
12550
+ const onSubmit = async () => {
12551
+ setIsSubmitting(true);
12552
+ let requestSucceeded = false;
12553
+ await requestOrderEdit(void 0, {
12554
+ onError: (e) => {
12555
+ ui.toast.error(e.message);
12556
+ },
12557
+ onSuccess: () => {
12558
+ requestSucceeded = true;
12559
+ }
12560
+ });
12561
+ if (!requestSucceeded) {
12562
+ setIsSubmitting(false);
12563
+ return;
12564
+ }
12565
+ await confirmOrderEdit(void 0, {
12566
+ onError: (e) => {
12567
+ ui.toast.error(e.message);
12568
+ },
12569
+ onSuccess: () => {
12570
+ handleSuccess();
12571
+ },
12572
+ onSettled: () => {
12573
+ setIsSubmitting(false);
12574
+ }
12575
+ });
12576
+ };
12577
+ if (isError) {
12578
+ throw error;
12579
+ }
12580
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
12581
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
12582
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
12583
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12584
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
12585
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
12586
+ ] }),
12587
+ /* @__PURE__ */ jsxRuntime.jsx(
12588
+ Combobox,
12589
+ {
12590
+ id: "promotion-combobox",
12591
+ "aria-describedby": "promotion-combobox-hint",
12592
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
12593
+ fetchNextPage: comboboxData.fetchNextPage,
12594
+ options: comboboxData.options,
12595
+ onSearchValueChange: comboboxData.onSearchValueChange,
12596
+ searchValue: comboboxData.searchValue,
12597
+ disabled: comboboxData.disabled || isAddingPromotions,
12598
+ onChange: add,
12599
+ value: comboboxValue
12600
+ }
12601
+ )
12602
+ ] }),
12603
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12604
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
12605
+ PromotionItem,
12606
+ {
12607
+ promotion,
12608
+ orderId: preview.id,
12609
+ isLoading: isPending
12610
+ },
12611
+ promotion.id
12612
+ )) })
12613
+ ] }) }),
12614
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12615
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12616
+ /* @__PURE__ */ jsxRuntime.jsx(
12617
+ ui.Button,
12618
+ {
12619
+ size: "small",
12620
+ type: "submit",
12621
+ isLoading: isSubmitting || isAddingPromotions,
12622
+ children: "Save"
12623
+ }
12624
+ )
12625
+ ] }) })
12626
+ ] });
12627
+ };
12628
+ const PromotionItem = ({
12629
+ promotion,
12630
+ orderId,
12631
+ isLoading
12632
+ }) => {
12633
+ var _a;
12634
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
12635
+ const onRemove = async () => {
12636
+ removePromotions(
12637
+ {
12638
+ promo_codes: [promotion.code]
12639
+ },
12640
+ {
12641
+ onError: (e) => {
12642
+ ui.toast.error(e.message);
12643
+ }
12644
+ }
12645
+ );
12646
+ };
12647
+ const displayValue = getDisplayValue(promotion);
12648
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12649
+ "div",
12650
+ {
12651
+ className: ui.clx(
12652
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
12653
+ {
12654
+ "animate-pulse": isLoading
12655
+ }
12656
+ ),
12657
+ children: [
12658
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12659
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
12660
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
12661
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
12662
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
12663
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
12664
+ ] }),
12665
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
12666
+ ] })
12667
+ ] }),
12668
+ /* @__PURE__ */ jsxRuntime.jsx(
12669
+ ui.IconButton,
12670
+ {
12671
+ size: "small",
12672
+ type: "button",
12673
+ variant: "transparent",
12674
+ onClick: onRemove,
12675
+ isLoading: isPending || isLoading,
12676
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
12677
+ }
12678
+ )
12679
+ ]
12680
+ },
12681
+ promotion.id
12682
+ );
12683
+ };
12684
+ function getDisplayValue(promotion) {
12685
+ var _a, _b, _c, _d;
12686
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
12687
+ if (!value) {
12688
+ return null;
12689
+ }
12690
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
12691
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
12692
+ if (!currency) {
12693
+ return null;
12694
+ }
12695
+ return getLocaleAmount(value, currency);
12696
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
12697
+ return formatPercentage(value);
12698
+ }
12699
+ return null;
12700
+ }
12701
+ const formatter = new Intl.NumberFormat([], {
12702
+ style: "percent",
12703
+ minimumFractionDigits: 2
12704
+ });
12705
+ const formatPercentage = (value, isPercentageValue = false) => {
12706
+ let val = value || 0;
12707
+ if (!isPercentageValue) {
12708
+ val = val / 100;
12709
+ }
12710
+ return formatter.format(val);
12711
+ };
12712
+ function getPromotionIds(items, shippingMethods) {
12713
+ const promotionIds = /* @__PURE__ */ new Set();
12714
+ for (const item of items) {
12715
+ if (item.adjustments) {
12716
+ for (const adjustment of item.adjustments) {
12717
+ if (adjustment.promotion_id) {
12718
+ promotionIds.add(adjustment.promotion_id);
12719
+ }
12720
+ }
12721
+ }
12722
+ }
12723
+ for (const shippingMethod of shippingMethods) {
12724
+ if (shippingMethod.adjustments) {
12725
+ for (const adjustment of shippingMethod.adjustments) {
12726
+ if (adjustment.promotion_id) {
12727
+ promotionIds.add(adjustment.promotion_id);
12728
+ }
12729
+ }
12730
+ }
12731
+ }
12732
+ return Array.from(promotionIds);
12733
+ }
12734
+ const SalesChannel = () => {
12735
+ const { id } = reactRouterDom.useParams();
12736
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12737
+ id,
12738
+ {
12739
+ fields: "+sales_channel_id"
12740
+ },
12741
+ {
12742
+ enabled: !!id
12743
+ }
12744
+ );
12745
+ if (isError) {
12746
+ throw error;
12747
+ }
12748
+ const ISrEADY = !!draft_order && !isPending;
12749
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12750
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12751
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12752
+ /* @__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" }) })
12753
+ ] }),
12754
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12755
+ ] });
12756
+ };
12757
+ const SalesChannelForm = ({ order }) => {
12758
+ const form = reactHookForm.useForm({
12759
+ defaultValues: {
12760
+ sales_channel_id: order.sales_channel_id || ""
12761
+ },
12762
+ resolver: zod.zodResolver(schema$1)
12763
+ });
12764
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12765
+ const { handleSuccess } = useRouteModal();
12766
+ const onSubmit = form.handleSubmit(async (data) => {
12767
+ await mutateAsync(
12768
+ {
12769
+ sales_channel_id: data.sales_channel_id
12770
+ },
12771
+ {
12772
+ onSuccess: () => {
12773
+ ui.toast.success("Sales channel updated");
12774
+ handleSuccess();
12775
+ },
12776
+ onError: (error) => {
12777
+ ui.toast.error(error.message);
12778
+ }
12779
+ }
12780
+ );
12781
+ });
12782
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12783
+ KeyboundForm,
12784
+ {
12785
+ className: "flex flex-1 flex-col overflow-hidden",
12786
+ onSubmit,
12787
+ children: [
12788
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12789
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12790
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12791
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12792
+ ] }) })
12793
+ ]
12794
+ }
12795
+ ) });
12796
+ };
12797
+ const SalesChannelField = ({ control, order }) => {
12798
+ const salesChannels = useComboboxData({
12799
+ queryFn: async (params) => {
12800
+ return await sdk.admin.salesChannel.list(params);
12801
+ },
12802
+ queryKey: ["sales-channels"],
12803
+ getOptions: (data) => {
12804
+ return data.sales_channels.map((salesChannel) => ({
12805
+ label: salesChannel.name,
12806
+ value: salesChannel.id
12807
+ }));
12808
+ },
12809
+ defaultValue: order.sales_channel_id || void 0
12810
+ });
12811
+ return /* @__PURE__ */ jsxRuntime.jsx(
12812
+ Form$2.Field,
12813
+ {
12814
+ control,
12815
+ name: "sales_channel_id",
12816
+ render: ({ field }) => {
12817
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12818
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12819
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12820
+ Combobox,
12821
+ {
12822
+ options: salesChannels.options,
12823
+ fetchNextPage: salesChannels.fetchNextPage,
12824
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12825
+ searchValue: salesChannels.searchValue,
12826
+ onSearchValueChange: salesChannels.onSearchValueChange,
12827
+ placeholder: "Select sales channel",
12828
+ ...field
12829
+ }
12830
+ ) }),
12831
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12832
+ ] });
12833
+ }
12834
+ }
12835
+ );
12836
+ };
12837
+ const schema$1 = objectType({
12838
+ sales_channel_id: stringType().min(1)
12839
+ });
12840
+ const ShippingAddress = () => {
12841
+ const { id } = reactRouterDom.useParams();
12842
+ const { order, isPending, isError, error } = useOrder(id, {
12843
+ fields: "+shipping_address"
12844
+ });
12845
+ if (isError) {
12846
+ throw error;
12847
+ }
12848
+ const isReady = !isPending && !!order;
12849
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12850
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12851
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12852
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12853
+ ] }),
12854
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12855
+ ] });
12856
+ };
12857
+ const ShippingAddressForm = ({ order }) => {
12858
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12859
+ const form = reactHookForm.useForm({
12860
+ defaultValues: {
12861
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12862
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12863
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12864
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12865
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12866
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12867
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12868
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12869
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12870
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12871
+ },
12872
+ resolver: zod.zodResolver(schema)
12873
+ });
12874
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12875
+ const { handleSuccess } = useRouteModal();
12876
+ const onSubmit = form.handleSubmit(async (data) => {
12877
+ await mutateAsync(
12878
+ {
12879
+ shipping_address: {
12880
+ first_name: data.first_name,
12881
+ last_name: data.last_name,
12882
+ company: data.company,
12883
+ address_1: data.address_1,
12884
+ address_2: data.address_2,
12885
+ city: data.city,
12886
+ province: data.province,
12887
+ country_code: data.country_code,
12888
+ postal_code: data.postal_code,
12889
+ phone: data.phone
12890
+ }
12891
+ },
12892
+ {
12893
+ onSuccess: () => {
12894
+ handleSuccess();
12895
+ },
12896
+ onError: (error) => {
12897
+ ui.toast.error(error.message);
12898
+ }
12899
+ }
12900
+ );
12901
+ });
12902
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12903
+ KeyboundForm,
12904
+ {
12905
+ className: "flex flex-1 flex-col overflow-hidden",
12906
+ onSubmit,
12907
+ children: [
12908
+ /* @__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: [
12909
+ /* @__PURE__ */ jsxRuntime.jsx(
12910
+ Form$2.Field,
12992
12911
  {
12993
- width: "12",
12994
- height: "12",
12995
- fill: "white",
12996
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12912
+ control: form.control,
12913
+ name: "country_code",
12914
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12915
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12916
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12917
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12918
+ ] })
12997
12919
  }
12998
- ) }),
12999
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13000
- "rect",
12920
+ ),
12921
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12922
+ /* @__PURE__ */ jsxRuntime.jsx(
12923
+ Form$2.Field,
12924
+ {
12925
+ control: form.control,
12926
+ name: "first_name",
12927
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12928
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12929
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12930
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12931
+ ] })
12932
+ }
12933
+ ),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(
12935
+ Form$2.Field,
12936
+ {
12937
+ control: form.control,
12938
+ name: "last_name",
12939
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12940
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12941
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12942
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12943
+ ] })
12944
+ }
12945
+ )
12946
+ ] }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(
12948
+ Form$2.Field,
13001
12949
  {
13002
- width: "12",
13003
- height: "12",
13004
- fill: "white",
13005
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12950
+ control: form.control,
12951
+ name: "company",
12952
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12953
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12954
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12955
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12956
+ ] })
13006
12957
  }
13007
- ) }),
13008
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13009
- "rect",
12958
+ ),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(
12960
+ Form$2.Field,
13010
12961
  {
13011
- width: "12",
13012
- height: "12",
13013
- fill: "white",
13014
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12962
+ control: form.control,
12963
+ name: "address_1",
12964
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12965
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12966
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12967
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12968
+ ] })
13015
12969
  }
13016
- ) }),
13017
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13018
- "rect",
12970
+ ),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(
12972
+ Form$2.Field,
13019
12973
  {
13020
- width: "12",
13021
- height: "12",
13022
- fill: "white",
13023
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12974
+ control: form.control,
12975
+ name: "address_2",
12976
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12977
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12978
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12979
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12980
+ ] })
13024
12981
  }
13025
- ) }),
13026
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13027
- "rect",
12982
+ ),
12983
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12984
+ /* @__PURE__ */ jsxRuntime.jsx(
12985
+ Form$2.Field,
12986
+ {
12987
+ control: form.control,
12988
+ name: "postal_code",
12989
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12990
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12991
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12992
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12993
+ ] })
12994
+ }
12995
+ ),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(
12997
+ Form$2.Field,
12998
+ {
12999
+ control: form.control,
13000
+ name: "city",
13001
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13002
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13003
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13004
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13005
+ ] })
13006
+ }
13007
+ )
13008
+ ] }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(
13010
+ Form$2.Field,
13028
13011
  {
13029
- width: "12",
13030
- height: "12",
13031
- fill: "white",
13032
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13012
+ control: form.control,
13013
+ name: "province",
13014
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13015
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13016
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13017
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13018
+ ] })
13033
13019
  }
13034
- ) })
13035
- ] })
13020
+ ),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(
13022
+ Form$2.Field,
13023
+ {
13024
+ control: form.control,
13025
+ name: "phone",
13026
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13027
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13028
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13029
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13030
+ ] })
13031
+ }
13032
+ )
13033
+ ] }) }),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13035
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13036
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13037
+ ] }) })
13036
13038
  ]
13037
13039
  }
13038
- );
13040
+ ) });
13039
13041
  };
13040
- const schema = objectType({
13041
- customer_id: stringType().min(1)
13042
- });
13042
+ const schema = addressSchema;
13043
13043
  const widgetModule = { widgets: [] };
13044
13044
  const routeModule = {
13045
13045
  routes: [
@@ -13080,6 +13080,14 @@ const routeModule = {
13080
13080
  Component: Metadata,
13081
13081
  path: "/draft-orders/:id/metadata"
13082
13082
  },
13083
+ {
13084
+ Component: Shipping,
13085
+ path: "/draft-orders/:id/shipping"
13086
+ },
13087
+ {
13088
+ Component: TransferOwnership,
13089
+ path: "/draft-orders/:id/transfer-ownership"
13090
+ },
13083
13091
  {
13084
13092
  Component: Promotions,
13085
13093
  path: "/draft-orders/:id/promotions"
@@ -13088,17 +13096,9 @@ const routeModule = {
13088
13096
  Component: SalesChannel,
13089
13097
  path: "/draft-orders/:id/sales-channel"
13090
13098
  },
13091
- {
13092
- Component: Shipping,
13093
- path: "/draft-orders/:id/shipping"
13094
- },
13095
13099
  {
13096
13100
  Component: ShippingAddress,
13097
13101
  path: "/draft-orders/:id/shipping-address"
13098
- },
13099
- {
13100
- Component: TransferOwnership,
13101
- path: "/draft-orders/:id/transfer-ownership"
13102
13102
  }
13103
13103
  ]
13104
13104
  }