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