@medusajs/draft-order 2.10.2-preview-20250906000310 → 2.10.2-preview-20250906030932

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.
@@ -9573,70 +9573,23 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const Email = () => {
9577
- const { id } = reactRouterDom.useParams();
9578
- const { order, isPending, isError, error } = useOrder(id, {
9579
- fields: "+email"
9580
- });
9581
- if (isError) {
9582
- throw error;
9583
- }
9584
- const isReady = !isPending && !!order;
9576
+ const CustomItems = () => {
9585
9577
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9588
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9589
- ] }),
9590
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9578
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9579
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9591
9580
  ] });
9592
9581
  };
9593
- const EmailForm = ({ order }) => {
9582
+ const CustomItemsForm = () => {
9594
9583
  const form = reactHookForm.useForm({
9595
- defaultValues: {
9596
- email: order.email ?? ""
9597
- },
9598
9584
  resolver: zod.zodResolver(schema$5)
9599
9585
  });
9600
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9601
- const { handleSuccess } = useRouteModal();
9602
- const onSubmit = form.handleSubmit(async (data) => {
9603
- await mutateAsync(
9604
- { email: data.email },
9605
- {
9606
- onSuccess: () => {
9607
- handleSuccess();
9608
- },
9609
- onError: (error) => {
9610
- ui.toast.error(error.message);
9611
- }
9612
- }
9613
- );
9614
- });
9615
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9616
- KeyboundForm,
9617
- {
9618
- className: "flex flex-1 flex-col overflow-hidden",
9619
- onSubmit,
9620
- children: [
9621
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9622
- Form$2.Field,
9623
- {
9624
- control: form.control,
9625
- name: "email",
9626
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9627
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9628
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9629
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9630
- ] })
9631
- }
9632
- ) }),
9633
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9634
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9635
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9636
- ] }) })
9637
- ]
9638
- }
9639
- ) });
9586
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9590
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9591
+ ] }) })
9592
+ ] }) });
9640
9593
  };
9641
9594
  const schema$5 = objectType({
9642
9595
  email: stringType().email()
@@ -11348,331 +11301,128 @@ const SalesChannelField = ({ control, order }) => {
11348
11301
  const schema$4 = objectType({
11349
11302
  sales_channel_id: stringType().min(1)
11350
11303
  });
11351
- const ShippingAddress = () => {
11304
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11305
+ const Shipping = () => {
11306
+ var _a;
11352
11307
  const { id } = reactRouterDom.useParams();
11353
11308
  const { order, isPending, isError, error } = useOrder(id, {
11354
- fields: "+shipping_address"
11309
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11355
11310
  });
11311
+ const {
11312
+ order: preview,
11313
+ isPending: isPreviewPending,
11314
+ isError: isPreviewError,
11315
+ error: previewError
11316
+ } = useOrderPreview(id);
11317
+ useInitiateOrderEdit({ preview });
11318
+ const { onCancel } = useCancelOrderEdit({ preview });
11356
11319
  if (isError) {
11357
11320
  throw error;
11358
11321
  }
11359
- const isReady = !isPending && !!order;
11360
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11361
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11362
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11363
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11364
- ] }),
11365
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11366
- ] });
11322
+ if (isPreviewError) {
11323
+ throw previewError;
11324
+ }
11325
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11326
+ const isReady = preview && !isPreviewPending && order && !isPending;
11327
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11328
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11329
+ /* @__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: [
11330
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11331
+ /* @__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." }) })
11332
+ ] }) }) }),
11333
+ /* @__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" }) }) })
11334
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11335
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11336
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11337
+ ] }) });
11367
11338
  };
11368
- const ShippingAddressForm = ({ order }) => {
11369
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11370
- const form = reactHookForm.useForm({
11371
- defaultValues: {
11372
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11373
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11374
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11375
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11376
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11377
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11378
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11379
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11380
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11381
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11339
+ const ShippingForm = ({ preview, order }) => {
11340
+ var _a;
11341
+ const { setIsOpen } = useStackedModal();
11342
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11343
+ const [data, setData] = React.useState(null);
11344
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11345
+ const { shipping_options } = useShippingOptions(
11346
+ {
11347
+ id: appliedShippingOptionIds,
11348
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11382
11349
  },
11383
- resolver: zod.zodResolver(schema$3)
11384
- });
11385
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11350
+ {
11351
+ enabled: appliedShippingOptionIds.length > 0
11352
+ }
11353
+ );
11354
+ const uniqueShippingProfiles = React.useMemo(() => {
11355
+ const profiles = /* @__PURE__ */ new Map();
11356
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11357
+ profiles.set(profile.id, profile);
11358
+ });
11359
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11360
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11361
+ });
11362
+ return Array.from(profiles.values());
11363
+ }, [order.items, shipping_options]);
11386
11364
  const { handleSuccess } = useRouteModal();
11387
- const onSubmit = form.handleSubmit(async (data) => {
11388
- await mutateAsync(
11389
- {
11390
- shipping_address: {
11391
- first_name: data.first_name,
11392
- last_name: data.last_name,
11393
- company: data.company,
11394
- address_1: data.address_1,
11395
- address_2: data.address_2,
11396
- city: data.city,
11397
- province: data.province,
11398
- country_code: data.country_code,
11399
- postal_code: data.postal_code,
11400
- phone: data.phone
11401
- }
11365
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11366
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11367
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11368
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11369
+ const onSubmit = async () => {
11370
+ setIsSubmitting(true);
11371
+ let requestSucceeded = false;
11372
+ await requestOrderEdit(void 0, {
11373
+ onError: (e) => {
11374
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11402
11375
  },
11403
- {
11404
- onSuccess: () => {
11405
- handleSuccess();
11406
- },
11407
- onError: (error) => {
11408
- ui.toast.error(error.message);
11376
+ onSuccess: () => {
11377
+ requestSucceeded = true;
11378
+ }
11379
+ });
11380
+ if (!requestSucceeded) {
11381
+ setIsSubmitting(false);
11382
+ return;
11383
+ }
11384
+ await confirmOrderEdit(void 0, {
11385
+ onError: (e) => {
11386
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11387
+ },
11388
+ onSuccess: () => {
11389
+ handleSuccess();
11390
+ },
11391
+ onSettled: () => {
11392
+ setIsSubmitting(false);
11393
+ }
11394
+ });
11395
+ };
11396
+ const onKeydown = React.useCallback(
11397
+ (e) => {
11398
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11399
+ if (data || isSubmitting) {
11400
+ return;
11409
11401
  }
11402
+ onSubmit();
11410
11403
  }
11411
- );
11412
- });
11413
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11414
- KeyboundForm,
11415
- {
11416
- className: "flex flex-1 flex-col overflow-hidden",
11417
- onSubmit,
11418
- children: [
11419
- /* @__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: [
11420
- /* @__PURE__ */ jsxRuntime.jsx(
11421
- Form$2.Field,
11422
- {
11423
- control: form.control,
11424
- name: "country_code",
11425
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11426
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11427
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11428
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11429
- ] })
11430
- }
11431
- ),
11432
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11404
+ },
11405
+ [data, isSubmitting, onSubmit]
11406
+ );
11407
+ React.useEffect(() => {
11408
+ document.addEventListener("keydown", onKeydown);
11409
+ return () => {
11410
+ document.removeEventListener("keydown", onKeydown);
11411
+ };
11412
+ }, [onKeydown]);
11413
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11414
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11415
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11416
+ /* @__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: [
11417
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11418
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11419
+ /* @__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." }) })
11420
+ ] }),
11421
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11422
+ /* @__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: [
11423
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11433
11424
  /* @__PURE__ */ jsxRuntime.jsx(
11434
- Form$2.Field,
11435
- {
11436
- control: form.control,
11437
- name: "first_name",
11438
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11439
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11440
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11441
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11442
- ] })
11443
- }
11444
- ),
11445
- /* @__PURE__ */ jsxRuntime.jsx(
11446
- Form$2.Field,
11447
- {
11448
- control: form.control,
11449
- name: "last_name",
11450
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11451
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11452
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11453
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11454
- ] })
11455
- }
11456
- )
11457
- ] }),
11458
- /* @__PURE__ */ jsxRuntime.jsx(
11459
- Form$2.Field,
11460
- {
11461
- control: form.control,
11462
- name: "company",
11463
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11464
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11465
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11466
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11467
- ] })
11468
- }
11469
- ),
11470
- /* @__PURE__ */ jsxRuntime.jsx(
11471
- Form$2.Field,
11472
- {
11473
- control: form.control,
11474
- name: "address_1",
11475
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11476
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11477
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11478
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11479
- ] })
11480
- }
11481
- ),
11482
- /* @__PURE__ */ jsxRuntime.jsx(
11483
- Form$2.Field,
11484
- {
11485
- control: form.control,
11486
- name: "address_2",
11487
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11488
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11489
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11490
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11491
- ] })
11492
- }
11493
- ),
11494
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11495
- /* @__PURE__ */ jsxRuntime.jsx(
11496
- Form$2.Field,
11497
- {
11498
- control: form.control,
11499
- name: "postal_code",
11500
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11501
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11502
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11503
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11504
- ] })
11505
- }
11506
- ),
11507
- /* @__PURE__ */ jsxRuntime.jsx(
11508
- Form$2.Field,
11509
- {
11510
- control: form.control,
11511
- name: "city",
11512
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11513
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11514
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11515
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11516
- ] })
11517
- }
11518
- )
11519
- ] }),
11520
- /* @__PURE__ */ jsxRuntime.jsx(
11521
- Form$2.Field,
11522
- {
11523
- control: form.control,
11524
- name: "province",
11525
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11526
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11527
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11528
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11529
- ] })
11530
- }
11531
- ),
11532
- /* @__PURE__ */ jsxRuntime.jsx(
11533
- Form$2.Field,
11534
- {
11535
- control: form.control,
11536
- name: "phone",
11537
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11538
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11539
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11541
- ] })
11542
- }
11543
- )
11544
- ] }) }),
11545
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11546
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11547
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11548
- ] }) })
11549
- ]
11550
- }
11551
- ) });
11552
- };
11553
- const schema$3 = addressSchema;
11554
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11555
- const Shipping = () => {
11556
- var _a;
11557
- const { id } = reactRouterDom.useParams();
11558
- const { order, isPending, isError, error } = useOrder(id, {
11559
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11560
- });
11561
- const {
11562
- order: preview,
11563
- isPending: isPreviewPending,
11564
- isError: isPreviewError,
11565
- error: previewError
11566
- } = useOrderPreview(id);
11567
- useInitiateOrderEdit({ preview });
11568
- const { onCancel } = useCancelOrderEdit({ preview });
11569
- if (isError) {
11570
- throw error;
11571
- }
11572
- if (isPreviewError) {
11573
- throw previewError;
11574
- }
11575
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11576
- const isReady = preview && !isPreviewPending && order && !isPending;
11577
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11578
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11579
- /* @__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: [
11580
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11581
- /* @__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." }) })
11582
- ] }) }) }),
11583
- /* @__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" }) }) })
11584
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11585
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11586
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11587
- ] }) });
11588
- };
11589
- const ShippingForm = ({ preview, order }) => {
11590
- var _a;
11591
- const { setIsOpen } = useStackedModal();
11592
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11593
- const [data, setData] = React.useState(null);
11594
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11595
- const { shipping_options } = useShippingOptions(
11596
- {
11597
- id: appliedShippingOptionIds,
11598
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11599
- },
11600
- {
11601
- enabled: appliedShippingOptionIds.length > 0
11602
- }
11603
- );
11604
- const uniqueShippingProfiles = React.useMemo(() => {
11605
- const profiles = /* @__PURE__ */ new Map();
11606
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11607
- profiles.set(profile.id, profile);
11608
- });
11609
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11610
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11611
- });
11612
- return Array.from(profiles.values());
11613
- }, [order.items, shipping_options]);
11614
- const { handleSuccess } = useRouteModal();
11615
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11616
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11617
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11618
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11619
- const onSubmit = async () => {
11620
- setIsSubmitting(true);
11621
- let requestSucceeded = false;
11622
- await requestOrderEdit(void 0, {
11623
- onError: (e) => {
11624
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11625
- },
11626
- onSuccess: () => {
11627
- requestSucceeded = true;
11628
- }
11629
- });
11630
- if (!requestSucceeded) {
11631
- setIsSubmitting(false);
11632
- return;
11633
- }
11634
- await confirmOrderEdit(void 0, {
11635
- onError: (e) => {
11636
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11637
- },
11638
- onSuccess: () => {
11639
- handleSuccess();
11640
- },
11641
- onSettled: () => {
11642
- setIsSubmitting(false);
11643
- }
11644
- });
11645
- };
11646
- const onKeydown = React.useCallback(
11647
- (e) => {
11648
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11649
- if (data || isSubmitting) {
11650
- return;
11651
- }
11652
- onSubmit();
11653
- }
11654
- },
11655
- [data, isSubmitting, onSubmit]
11656
- );
11657
- React.useEffect(() => {
11658
- document.addEventListener("keydown", onKeydown);
11659
- return () => {
11660
- document.removeEventListener("keydown", onKeydown);
11661
- };
11662
- }, [onKeydown]);
11663
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11664
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11665
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11666
- /* @__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: [
11667
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11668
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11669
- /* @__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." }) })
11670
- ] }),
11671
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11672
- /* @__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: [
11673
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx(
11675
- ui.Text,
11425
+ ui.Text,
11676
11426
  {
11677
11427
  size: "xsmall",
11678
11428
  weight: "plus",
@@ -12238,126 +11988,329 @@ const LocationField = ({ control, setValue }) => {
12238
11988
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12239
11989
  Combobox,
12240
11990
  {
12241
- options: locations.options,
12242
- fetchNextPage: locations.fetchNextPage,
12243
- isFetchingNextPage: locations.isFetchingNextPage,
12244
- searchValue: locations.searchValue,
12245
- onSearchValueChange: locations.onSearchValueChange,
12246
- placeholder: "Select location",
12247
- onChange: (value) => {
12248
- setValue("shipping_option_id", "", {
12249
- shouldDirty: true,
12250
- shouldTouch: true
12251
- });
12252
- onChange(value);
12253
- },
12254
- ...field
11991
+ options: locations.options,
11992
+ fetchNextPage: locations.fetchNextPage,
11993
+ isFetchingNextPage: locations.isFetchingNextPage,
11994
+ searchValue: locations.searchValue,
11995
+ onSearchValueChange: locations.onSearchValueChange,
11996
+ placeholder: "Select location",
11997
+ onChange: (value) => {
11998
+ setValue("shipping_option_id", "", {
11999
+ shouldDirty: true,
12000
+ shouldTouch: true
12001
+ });
12002
+ onChange(value);
12003
+ },
12004
+ ...field
12005
+ }
12006
+ ) })
12007
+ ] }) });
12008
+ }
12009
+ }
12010
+ );
12011
+ };
12012
+ const ShippingOptionField = ({
12013
+ shippingProfileId,
12014
+ preview,
12015
+ control
12016
+ }) => {
12017
+ var _a;
12018
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12019
+ const shippingOptions = useComboboxData({
12020
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12021
+ queryFn: async (params) => {
12022
+ return await sdk.admin.shippingOption.list({
12023
+ ...params,
12024
+ stock_location_id: locationId,
12025
+ shipping_profile_id: shippingProfileId
12026
+ });
12027
+ },
12028
+ getOptions: (data) => {
12029
+ return data.shipping_options.map((option) => {
12030
+ var _a2;
12031
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12032
+ (r) => r.attribute === "is_return" && r.value === "true"
12033
+ )) {
12034
+ return void 0;
12035
+ }
12036
+ return {
12037
+ label: option.name,
12038
+ value: option.id
12039
+ };
12040
+ }).filter(Boolean);
12041
+ },
12042
+ enabled: !!locationId && !!shippingProfileId,
12043
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12044
+ });
12045
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12046
+ return /* @__PURE__ */ jsxRuntime.jsx(
12047
+ Form$2.Field,
12048
+ {
12049
+ control,
12050
+ name: "shipping_option_id",
12051
+ render: ({ field }) => {
12052
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12053
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12054
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12055
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12056
+ ] }),
12057
+ /* @__PURE__ */ jsxRuntime.jsx(
12058
+ ConditionalTooltip,
12059
+ {
12060
+ content: tooltipContent,
12061
+ showTooltip: !locationId || !shippingProfileId,
12062
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12063
+ Combobox,
12064
+ {
12065
+ options: shippingOptions.options,
12066
+ fetchNextPage: shippingOptions.fetchNextPage,
12067
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12068
+ searchValue: shippingOptions.searchValue,
12069
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12070
+ placeholder: "Select shipping option",
12071
+ ...field,
12072
+ disabled: !locationId || !shippingProfileId
12073
+ }
12074
+ ) }) })
12075
+ }
12076
+ )
12077
+ ] }) });
12078
+ }
12079
+ }
12080
+ );
12081
+ };
12082
+ const CustomAmountField = ({
12083
+ control,
12084
+ currencyCode
12085
+ }) => {
12086
+ return /* @__PURE__ */ jsxRuntime.jsx(
12087
+ Form$2.Field,
12088
+ {
12089
+ control,
12090
+ name: "custom_amount",
12091
+ render: ({ field: { onChange, ...field } }) => {
12092
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12093
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12094
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12095
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12096
+ ] }),
12097
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12098
+ ui.CurrencyInput,
12099
+ {
12100
+ ...field,
12101
+ onValueChange: (value) => onChange(value),
12102
+ symbol: getNativeSymbol(currencyCode),
12103
+ code: currencyCode
12104
+ }
12105
+ ) })
12106
+ ] });
12107
+ }
12108
+ }
12109
+ );
12110
+ };
12111
+ const ShippingAddress = () => {
12112
+ const { id } = reactRouterDom.useParams();
12113
+ const { order, isPending, isError, error } = useOrder(id, {
12114
+ fields: "+shipping_address"
12115
+ });
12116
+ if (isError) {
12117
+ throw error;
12118
+ }
12119
+ const isReady = !isPending && !!order;
12120
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12121
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12122
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12123
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12124
+ ] }),
12125
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12126
+ ] });
12127
+ };
12128
+ const ShippingAddressForm = ({ order }) => {
12129
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12130
+ const form = reactHookForm.useForm({
12131
+ defaultValues: {
12132
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12133
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12134
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12135
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12136
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12137
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12138
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12139
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12140
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12141
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12142
+ },
12143
+ resolver: zod.zodResolver(schema$3)
12144
+ });
12145
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12146
+ const { handleSuccess } = useRouteModal();
12147
+ const onSubmit = form.handleSubmit(async (data) => {
12148
+ await mutateAsync(
12149
+ {
12150
+ shipping_address: {
12151
+ first_name: data.first_name,
12152
+ last_name: data.last_name,
12153
+ company: data.company,
12154
+ address_1: data.address_1,
12155
+ address_2: data.address_2,
12156
+ city: data.city,
12157
+ province: data.province,
12158
+ country_code: data.country_code,
12159
+ postal_code: data.postal_code,
12160
+ phone: data.phone
12161
+ }
12162
+ },
12163
+ {
12164
+ onSuccess: () => {
12165
+ handleSuccess();
12166
+ },
12167
+ onError: (error) => {
12168
+ ui.toast.error(error.message);
12169
+ }
12170
+ }
12171
+ );
12172
+ });
12173
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12174
+ KeyboundForm,
12175
+ {
12176
+ className: "flex flex-1 flex-col overflow-hidden",
12177
+ onSubmit,
12178
+ children: [
12179
+ /* @__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: [
12180
+ /* @__PURE__ */ jsxRuntime.jsx(
12181
+ Form$2.Field,
12182
+ {
12183
+ control: form.control,
12184
+ name: "country_code",
12185
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12186
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12187
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12188
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12189
+ ] })
12190
+ }
12191
+ ),
12192
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12193
+ /* @__PURE__ */ jsxRuntime.jsx(
12194
+ Form$2.Field,
12195
+ {
12196
+ control: form.control,
12197
+ name: "first_name",
12198
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12199
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12200
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12201
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12202
+ ] })
12203
+ }
12204
+ ),
12205
+ /* @__PURE__ */ jsxRuntime.jsx(
12206
+ Form$2.Field,
12207
+ {
12208
+ control: form.control,
12209
+ name: "last_name",
12210
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12211
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12212
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12213
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12214
+ ] })
12215
+ }
12216
+ )
12217
+ ] }),
12218
+ /* @__PURE__ */ jsxRuntime.jsx(
12219
+ Form$2.Field,
12220
+ {
12221
+ control: form.control,
12222
+ name: "company",
12223
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12224
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12225
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12226
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12227
+ ] })
12228
+ }
12229
+ ),
12230
+ /* @__PURE__ */ jsxRuntime.jsx(
12231
+ Form$2.Field,
12232
+ {
12233
+ control: form.control,
12234
+ name: "address_1",
12235
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12236
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12237
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12238
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12239
+ ] })
12240
+ }
12241
+ ),
12242
+ /* @__PURE__ */ jsxRuntime.jsx(
12243
+ Form$2.Field,
12244
+ {
12245
+ control: form.control,
12246
+ name: "address_2",
12247
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12248
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12249
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12250
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12251
+ ] })
12255
12252
  }
12256
- ) })
12257
- ] }) });
12258
- }
12259
- }
12260
- );
12261
- };
12262
- const ShippingOptionField = ({
12263
- shippingProfileId,
12264
- preview,
12265
- control
12266
- }) => {
12267
- var _a;
12268
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12269
- const shippingOptions = useComboboxData({
12270
- queryKey: ["shipping_options", locationId, shippingProfileId],
12271
- queryFn: async (params) => {
12272
- return await sdk.admin.shippingOption.list({
12273
- ...params,
12274
- stock_location_id: locationId,
12275
- shipping_profile_id: shippingProfileId
12276
- });
12277
- },
12278
- getOptions: (data) => {
12279
- return data.shipping_options.map((option) => {
12280
- var _a2;
12281
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12282
- (r) => r.attribute === "is_return" && r.value === "true"
12283
- )) {
12284
- return void 0;
12285
- }
12286
- return {
12287
- label: option.name,
12288
- value: option.id
12289
- };
12290
- }).filter(Boolean);
12291
- },
12292
- enabled: !!locationId && !!shippingProfileId,
12293
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12294
- });
12295
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12296
- return /* @__PURE__ */ jsxRuntime.jsx(
12297
- Form$2.Field,
12298
- {
12299
- control,
12300
- name: "shipping_option_id",
12301
- render: ({ field }) => {
12302
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12304
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12305
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12253
+ ),
12254
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12255
+ /* @__PURE__ */ jsxRuntime.jsx(
12256
+ Form$2.Field,
12257
+ {
12258
+ control: form.control,
12259
+ name: "postal_code",
12260
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12261
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12262
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12263
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12264
+ ] })
12265
+ }
12266
+ ),
12267
+ /* @__PURE__ */ jsxRuntime.jsx(
12268
+ Form$2.Field,
12269
+ {
12270
+ control: form.control,
12271
+ name: "city",
12272
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12273
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12274
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12275
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12276
+ ] })
12277
+ }
12278
+ )
12306
12279
  ] }),
12307
12280
  /* @__PURE__ */ jsxRuntime.jsx(
12308
- ConditionalTooltip,
12281
+ Form$2.Field,
12309
12282
  {
12310
- content: tooltipContent,
12311
- showTooltip: !locationId || !shippingProfileId,
12312
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12313
- Combobox,
12314
- {
12315
- options: shippingOptions.options,
12316
- fetchNextPage: shippingOptions.fetchNextPage,
12317
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12318
- searchValue: shippingOptions.searchValue,
12319
- onSearchValueChange: shippingOptions.onSearchValueChange,
12320
- placeholder: "Select shipping option",
12321
- ...field,
12322
- disabled: !locationId || !shippingProfileId
12323
- }
12324
- ) }) })
12283
+ control: form.control,
12284
+ name: "province",
12285
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12286
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12287
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12288
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12289
+ ] })
12325
12290
  }
12326
- )
12327
- ] }) });
12328
- }
12329
- }
12330
- );
12331
- };
12332
- const CustomAmountField = ({
12333
- control,
12334
- currencyCode
12335
- }) => {
12336
- return /* @__PURE__ */ jsxRuntime.jsx(
12337
- Form$2.Field,
12338
- {
12339
- control,
12340
- name: "custom_amount",
12341
- render: ({ field: { onChange, ...field } }) => {
12342
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12343
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12344
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12345
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12346
- ] }),
12347
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12348
- ui.CurrencyInput,
12291
+ ),
12292
+ /* @__PURE__ */ jsxRuntime.jsx(
12293
+ Form$2.Field,
12349
12294
  {
12350
- ...field,
12351
- onValueChange: (value) => onChange(value),
12352
- symbol: getNativeSymbol(currencyCode),
12353
- code: currencyCode
12295
+ control: form.control,
12296
+ name: "phone",
12297
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12298
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12299
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12300
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12301
+ ] })
12354
12302
  }
12355
- ) })
12356
- ] });
12357
- }
12303
+ )
12304
+ ] }) }),
12305
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12306
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12307
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12308
+ ] }) })
12309
+ ]
12358
12310
  }
12359
- );
12311
+ ) });
12360
12312
  };
12313
+ const schema$3 = addressSchema;
12361
12314
  const TransferOwnership = () => {
12362
12315
  const { id } = reactRouterDom.useParams();
12363
12316
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13024,23 +12977,70 @@ const BillingAddressForm = ({ order }) => {
13024
12977
  ) });
13025
12978
  };
13026
12979
  const schema$1 = addressSchema;
13027
- const CustomItems = () => {
12980
+ const Email = () => {
12981
+ const { id } = reactRouterDom.useParams();
12982
+ const { order, isPending, isError, error } = useOrder(id, {
12983
+ fields: "+email"
12984
+ });
12985
+ if (isError) {
12986
+ throw error;
12987
+ }
12988
+ const isReady = !isPending && !!order;
13028
12989
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
13029
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
13030
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
12990
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12991
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12992
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12993
+ ] }),
12994
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
13031
12995
  ] });
13032
12996
  };
13033
- const CustomItemsForm = () => {
12997
+ const EmailForm = ({ order }) => {
13034
12998
  const form = reactHookForm.useForm({
12999
+ defaultValues: {
13000
+ email: order.email ?? ""
13001
+ },
13035
13002
  resolver: zod.zodResolver(schema)
13036
13003
  });
13037
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13038
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
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", children: "Save" })
13042
- ] }) })
13043
- ] }) });
13004
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
13005
+ const { handleSuccess } = useRouteModal();
13006
+ const onSubmit = form.handleSubmit(async (data) => {
13007
+ await mutateAsync(
13008
+ { email: data.email },
13009
+ {
13010
+ onSuccess: () => {
13011
+ handleSuccess();
13012
+ },
13013
+ onError: (error) => {
13014
+ ui.toast.error(error.message);
13015
+ }
13016
+ }
13017
+ );
13018
+ });
13019
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
13020
+ KeyboundForm,
13021
+ {
13022
+ className: "flex flex-1 flex-col overflow-hidden",
13023
+ onSubmit,
13024
+ children: [
13025
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Form$2.Field,
13027
+ {
13028
+ control: form.control,
13029
+ name: "email",
13030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
+ ] })
13035
+ }
13036
+ ) }),
13037
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13040
+ ] }) })
13041
+ ]
13042
+ }
13043
+ ) });
13044
13044
  };
13045
13045
  const schema = objectType({
13046
13046
  email: stringType().email()
@@ -13066,8 +13066,8 @@ const routeModule = {
13066
13066
  loader,
13067
13067
  children: [
13068
13068
  {
13069
- Component: Email,
13070
- path: "/draft-orders/:id/email"
13069
+ Component: CustomItems,
13070
+ path: "/draft-orders/:id/custom-items"
13071
13071
  },
13072
13072
  {
13073
13073
  Component: Items,
@@ -13085,14 +13085,14 @@ const routeModule = {
13085
13085
  Component: SalesChannel,
13086
13086
  path: "/draft-orders/:id/sales-channel"
13087
13087
  },
13088
- {
13089
- Component: ShippingAddress,
13090
- path: "/draft-orders/:id/shipping-address"
13091
- },
13092
13088
  {
13093
13089
  Component: Shipping,
13094
13090
  path: "/draft-orders/:id/shipping"
13095
13091
  },
13092
+ {
13093
+ Component: ShippingAddress,
13094
+ path: "/draft-orders/:id/shipping-address"
13095
+ },
13096
13096
  {
13097
13097
  Component: TransferOwnership,
13098
13098
  path: "/draft-orders/:id/transfer-ownership"
@@ -13102,8 +13102,8 @@ const routeModule = {
13102
13102
  path: "/draft-orders/:id/billing-address"
13103
13103
  },
13104
13104
  {
13105
- Component: CustomItems,
13106
- path: "/draft-orders/:id/custom-items"
13105
+ Component: Email,
13106
+ path: "/draft-orders/:id/email"
13107
13107
  }
13108
13108
  ]
13109
13109
  }