@medusajs/draft-order 2.10.2-preview-20250909081836 → 2.10.2-preview-20250909150158

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,196 +9567,6 @@ const ID = () => {
9567
9567
  /* @__PURE__ */ jsx(Outlet, {})
9568
9568
  ] });
9569
9569
  };
9570
- const BillingAddress = () => {
9571
- const { id } = useParams();
9572
- const { order, isPending, isError, error } = useOrder(id, {
9573
- fields: "+billing_address"
9574
- });
9575
- if (isError) {
9576
- throw error;
9577
- }
9578
- const isReady = !isPending && !!order;
9579
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9580
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9581
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9582
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9583
- ] }),
9584
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9585
- ] });
9586
- };
9587
- const BillingAddressForm = ({ order }) => {
9588
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9589
- const form = useForm({
9590
- defaultValues: {
9591
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9592
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9593
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9594
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9595
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9596
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9597
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9598
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9599
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9600
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9601
- },
9602
- resolver: zodResolver(schema$5)
9603
- });
9604
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9605
- const { handleSuccess } = useRouteModal();
9606
- const onSubmit = form.handleSubmit(async (data) => {
9607
- await mutateAsync(
9608
- { billing_address: data },
9609
- {
9610
- onSuccess: () => {
9611
- handleSuccess();
9612
- },
9613
- onError: (error) => {
9614
- toast.error(error.message);
9615
- }
9616
- }
9617
- );
9618
- });
9619
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9620
- KeyboundForm,
9621
- {
9622
- className: "flex flex-1 flex-col overflow-hidden",
9623
- onSubmit,
9624
- children: [
9625
- /* @__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: [
9626
- /* @__PURE__ */ jsx(
9627
- Form$2.Field,
9628
- {
9629
- control: form.control,
9630
- name: "country_code",
9631
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9633
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9634
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
- ] })
9636
- }
9637
- ),
9638
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9639
- /* @__PURE__ */ jsx(
9640
- Form$2.Field,
9641
- {
9642
- control: form.control,
9643
- name: "first_name",
9644
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9645
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9646
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9647
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9648
- ] })
9649
- }
9650
- ),
9651
- /* @__PURE__ */ jsx(
9652
- Form$2.Field,
9653
- {
9654
- control: form.control,
9655
- name: "last_name",
9656
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9658
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
- ] })
9661
- }
9662
- )
9663
- ] }),
9664
- /* @__PURE__ */ jsx(
9665
- Form$2.Field,
9666
- {
9667
- control: form.control,
9668
- name: "company",
9669
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9670
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9671
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9672
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9673
- ] })
9674
- }
9675
- ),
9676
- /* @__PURE__ */ jsx(
9677
- Form$2.Field,
9678
- {
9679
- control: form.control,
9680
- name: "address_1",
9681
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9682
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9683
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9684
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9685
- ] })
9686
- }
9687
- ),
9688
- /* @__PURE__ */ jsx(
9689
- Form$2.Field,
9690
- {
9691
- control: form.control,
9692
- name: "address_2",
9693
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9695
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
- ] })
9698
- }
9699
- ),
9700
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9701
- /* @__PURE__ */ jsx(
9702
- Form$2.Field,
9703
- {
9704
- control: form.control,
9705
- name: "postal_code",
9706
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9707
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9708
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9709
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9710
- ] })
9711
- }
9712
- ),
9713
- /* @__PURE__ */ jsx(
9714
- Form$2.Field,
9715
- {
9716
- control: form.control,
9717
- name: "city",
9718
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9720
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
- ] })
9723
- }
9724
- )
9725
- ] }),
9726
- /* @__PURE__ */ jsx(
9727
- Form$2.Field,
9728
- {
9729
- control: form.control,
9730
- name: "province",
9731
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9732
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9733
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9734
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9735
- ] })
9736
- }
9737
- ),
9738
- /* @__PURE__ */ jsx(
9739
- Form$2.Field,
9740
- {
9741
- control: form.control,
9742
- name: "phone",
9743
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9744
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9745
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9746
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9747
- ] })
9748
- }
9749
- )
9750
- ] }) }),
9751
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9752
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9753
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9754
- ] }) })
9755
- ]
9756
- }
9757
- ) });
9758
- };
9759
- const schema$5 = addressSchema;
9760
9570
  const CustomItems = () => {
9761
9571
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
9572
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9765,7 +9575,7 @@ const CustomItems = () => {
9765
9575
  };
9766
9576
  const CustomItemsForm = () => {
9767
9577
  const form = useForm({
9768
- resolver: zodResolver(schema$4)
9578
+ resolver: zodResolver(schema$5)
9769
9579
  });
9770
9580
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
9581
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9775,7 +9585,7 @@ const CustomItemsForm = () => {
9775
9585
  ] }) })
9776
9586
  ] }) });
9777
9587
  };
9778
- const schema$4 = objectType({
9588
+ const schema$5 = objectType({
9779
9589
  email: stringType().email()
9780
9590
  });
9781
9591
  const Email = () => {
@@ -9800,7 +9610,7 @@ const EmailForm = ({ order }) => {
9800
9610
  defaultValues: {
9801
9611
  email: order.email ?? ""
9802
9612
  },
9803
- resolver: zodResolver(schema$3)
9613
+ resolver: zodResolver(schema$4)
9804
9614
  });
9805
9615
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
9616
  const { handleSuccess } = useRouteModal();
@@ -9843,7 +9653,7 @@ const EmailForm = ({ order }) => {
9843
9653
  }
9844
9654
  ) });
9845
9655
  };
9846
- const schema$3 = objectType({
9656
+ const schema$4 = objectType({
9847
9657
  email: stringType().email()
9848
9658
  });
9849
9659
  const InlineTip = forwardRef(
@@ -10547,7 +10357,7 @@ const SalesChannelForm = ({ order }) => {
10547
10357
  defaultValues: {
10548
10358
  sales_channel_id: order.sales_channel_id || ""
10549
10359
  },
10550
- resolver: zodResolver(schema$2)
10360
+ resolver: zodResolver(schema$3)
10551
10361
  });
10552
10362
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10553
10363
  const { handleSuccess } = useRouteModal();
@@ -10622,158 +10432,26 @@ const SalesChannelField = ({ control, order }) => {
10622
10432
  }
10623
10433
  );
10624
10434
  };
10625
- const schema$2 = objectType({
10435
+ const schema$3 = objectType({
10626
10436
  sales_channel_id: stringType().min(1)
10627
10437
  });
10628
- const NumberInput = forwardRef(
10629
- ({
10630
- value,
10631
- onChange,
10632
- size = "base",
10633
- min = 0,
10634
- max = 100,
10635
- step = 1,
10636
- className,
10637
- disabled,
10638
- ...props
10639
- }, ref) => {
10640
- const handleChange = (event) => {
10641
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10642
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10643
- onChange(newValue);
10644
- }
10645
- };
10646
- const handleIncrement = () => {
10647
- const newValue = value + step;
10648
- if (max === void 0 || newValue <= max) {
10649
- onChange(newValue);
10650
- }
10651
- };
10652
- const handleDecrement = () => {
10653
- const newValue = value - step;
10654
- if (min === void 0 || newValue >= min) {
10655
- onChange(newValue);
10656
- }
10657
- };
10658
- return /* @__PURE__ */ jsxs(
10659
- "div",
10660
- {
10661
- className: clx(
10662
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10663
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10664
- {
10665
- "h-7": size === "small",
10666
- "h-8": size === "base"
10667
- },
10668
- className
10669
- ),
10670
- children: [
10671
- /* @__PURE__ */ jsx(
10672
- "input",
10673
- {
10674
- ref,
10675
- type: "number",
10676
- value,
10677
- onChange: handleChange,
10678
- min,
10679
- max,
10680
- step,
10681
- className: clx(
10682
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10683
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10684
- "placeholder:text-ui-fg-muted"
10685
- ),
10686
- ...props
10687
- }
10688
- ),
10689
- /* @__PURE__ */ jsxs(
10690
- "button",
10691
- {
10692
- className: clx(
10693
- "flex items-center justify-center outline-none transition-fg",
10694
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10695
- "focus:bg-ui-bg-field-component-hover",
10696
- "hover:bg-ui-bg-field-component-hover",
10697
- {
10698
- "size-7": size === "small",
10699
- "size-8": size === "base"
10700
- }
10701
- ),
10702
- type: "button",
10703
- onClick: handleDecrement,
10704
- disabled: min !== void 0 && value <= min || disabled,
10705
- children: [
10706
- /* @__PURE__ */ jsx(Minus, {}),
10707
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10708
- ]
10709
- }
10710
- ),
10711
- /* @__PURE__ */ jsxs(
10712
- "button",
10713
- {
10714
- className: clx(
10715
- "flex items-center justify-center outline-none transition-fg",
10716
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10717
- "focus:bg-ui-bg-field-hover",
10718
- "hover:bg-ui-bg-field-hover",
10719
- {
10720
- "size-7": size === "small",
10721
- "size-8": size === "base"
10722
- }
10723
- ),
10724
- type: "button",
10725
- onClick: handleIncrement,
10726
- disabled: max !== void 0 && value >= max || disabled,
10727
- children: [
10728
- /* @__PURE__ */ jsx(Plus, {}),
10729
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10730
- ]
10731
- }
10732
- )
10733
- ]
10734
- }
10735
- );
10736
- }
10737
- );
10738
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10739
- const productVariantsQueryKeys = {
10740
- list: (query2) => [
10741
- PRODUCT_VARIANTS_QUERY_KEY,
10742
- query2 ? query2 : void 0
10743
- ]
10744
- };
10745
- const useProductVariants = (query2, options) => {
10746
- const { data, ...rest } = useQuery({
10747
- queryKey: productVariantsQueryKeys.list(query2),
10748
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10749
- ...options
10750
- });
10751
- return { ...data, ...rest };
10752
- };
10753
10438
  function convertNumber(value) {
10754
10439
  return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10755
10440
  }
10756
- const STACKED_MODAL_ID = "items_stacked_modal";
10757
- const Items = () => {
10441
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
10442
+ const Shipping = () => {
10443
+ var _a;
10758
10444
  const { id } = useParams();
10445
+ const { order, isPending, isError, error } = useOrder(id, {
10446
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
10447
+ });
10759
10448
  const {
10760
10449
  order: preview,
10761
10450
  isPending: isPreviewPending,
10762
10451
  isError: isPreviewError,
10763
10452
  error: previewError
10764
- } = useOrderPreview(id, void 0, {
10765
- placeholderData: keepPreviousData
10766
- });
10453
+ } = useOrderPreview(id);
10767
10454
  useInitiateOrderEdit({ preview });
10768
- const { draft_order, isPending, isError, error } = useDraftOrder(
10769
- id,
10770
- {
10771
- fields: "currency_code"
10772
- },
10773
- {
10774
- enabled: !!id
10775
- }
10776
- );
10777
10455
  const { onCancel } = useCancelOrderEdit({ preview });
10778
10456
  if (isError) {
10779
10457
  throw error;
@@ -10781,28 +10459,50 @@ const Items = () => {
10781
10459
  if (isPreviewError) {
10782
10460
  throw previewError;
10783
10461
  }
10784
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10785
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10786
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10462
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
10463
+ const isReady = preview && !isPreviewPending && order && !isPending;
10464
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
10465
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10466
+ /* @__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: [
10467
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
10468
+ /* @__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." }) })
10469
+ ] }) }) }),
10470
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
10471
+ ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
10472
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
10787
10473
  /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10788
10474
  ] }) });
10789
10475
  };
10790
- const ItemsForm = ({ preview, currencyCode }) => {
10476
+ const ShippingForm = ({ preview, order }) => {
10791
10477
  var _a;
10478
+ const { setIsOpen } = useStackedModal();
10792
10479
  const [isSubmitting, setIsSubmitting] = useState(false);
10793
- const [modalContent, setModalContent] = useState(
10794
- null
10480
+ const [data, setData] = useState(null);
10481
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
10482
+ const { shipping_options } = useShippingOptions(
10483
+ {
10484
+ id: appliedShippingOptionIds,
10485
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
10486
+ },
10487
+ {
10488
+ enabled: appliedShippingOptionIds.length > 0
10489
+ }
10795
10490
  );
10491
+ const uniqueShippingProfiles = useMemo(() => {
10492
+ const profiles = /* @__PURE__ */ new Map();
10493
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
10494
+ profiles.set(profile.id, profile);
10495
+ });
10496
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
10497
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
10498
+ });
10499
+ return Array.from(profiles.values());
10500
+ }, [order.items, shipping_options]);
10796
10501
  const { handleSuccess } = useRouteModal();
10797
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10798
10502
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10799
10503
  const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10800
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10801
- const matches = useMemo(() => {
10802
- return matchSorter(preview.items, query2, {
10803
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10804
- });
10805
- }, [preview.items, query2]);
10504
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
10505
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
10806
10506
  const onSubmit = async () => {
10807
10507
  setIsSubmitting(true);
10808
10508
  let requestSucceeded = false;
@@ -10830,1103 +10530,85 @@ const ItemsForm = ({ preview, currencyCode }) => {
10830
10530
  }
10831
10531
  });
10832
10532
  };
10833
- const onKeyDown = useCallback(
10533
+ const onKeydown = useCallback(
10834
10534
  (e) => {
10835
10535
  if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10836
- if (modalContent || isSubmitting) {
10536
+ if (data || isSubmitting) {
10837
10537
  return;
10838
10538
  }
10839
10539
  onSubmit();
10840
10540
  }
10841
10541
  },
10842
- [modalContent, isSubmitting, onSubmit]
10542
+ [data, isSubmitting, onSubmit]
10843
10543
  );
10844
10544
  useEffect(() => {
10845
- document.addEventListener("keydown", onKeyDown);
10545
+ document.addEventListener("keydown", onKeydown);
10846
10546
  return () => {
10847
- document.removeEventListener("keydown", onKeyDown);
10547
+ document.removeEventListener("keydown", onKeydown);
10848
10548
  };
10849
- }, [onKeyDown]);
10549
+ }, [onKeydown]);
10850
10550
  return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10851
10551
  /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
10852
- /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
10853
- StackedFocusModal,
10854
- {
10855
- id: STACKED_MODAL_ID,
10856
- onOpenChangeCallback: (open) => {
10857
- if (!open) {
10858
- setModalContent(null);
10859
- }
10860
- },
10861
- children: [
10862
- /* @__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 px-6 py-16", children: [
10863
- /* @__PURE__ */ jsxs("div", { children: [
10864
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
10865
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
10866
- ] }),
10867
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10868
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
10869
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10870
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10871
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10872
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10873
- ] }),
10874
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
10875
- /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
10876
- Input,
10877
- {
10878
- type: "search",
10879
- placeholder: "Search items",
10880
- value: searchValue,
10881
- onChange: (e) => onSearchValueChange(e.target.value)
10882
- }
10883
- ) }),
10884
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10885
- /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
10886
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10887
- /* @__PURE__ */ jsx(
10888
- StackedModalTrigger$1,
10889
- {
10890
- type: "add-items",
10891
- setModalContent
10892
- }
10893
- ),
10894
- /* @__PURE__ */ jsx(
10895
- StackedModalTrigger$1,
10552
+ /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
10553
+ /* @__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: [
10554
+ /* @__PURE__ */ jsxs("div", { children: [
10555
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
10556
+ /* @__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." }) })
10557
+ ] }),
10558
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10559
+ /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
10560
+ /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
10561
+ /* @__PURE__ */ jsx(
10562
+ Text,
10563
+ {
10564
+ size: "xsmall",
10565
+ weight: "plus",
10566
+ className: "text-ui-fg-muted",
10567
+ children: "Shipping profile"
10568
+ }
10569
+ ),
10570
+ /* @__PURE__ */ jsx(
10571
+ Text,
10572
+ {
10573
+ size: "xsmall",
10574
+ weight: "plus",
10575
+ className: "text-ui-fg-muted",
10576
+ children: "Action"
10577
+ }
10578
+ )
10579
+ ] }),
10580
+ /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
10581
+ var _a2, _b, _c, _d, _e, _f, _g;
10582
+ const items = getItemsWithShippingProfile(
10583
+ profile.id,
10584
+ order.items
10585
+ );
10586
+ const hasItems = items.length > 0;
10587
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
10588
+ (option) => option.shipping_profile_id === profile.id
10589
+ );
10590
+ const shippingMethod = preview.shipping_methods.find(
10591
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
10592
+ );
10593
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
10594
+ (action) => action.action === "SHIPPING_ADD"
10595
+ );
10596
+ return /* @__PURE__ */ jsxs(
10597
+ Accordion.Item,
10598
+ {
10599
+ value: profile.id,
10600
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
10601
+ children: [
10602
+ /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
10603
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
10604
+ /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
10605
+ IconButton,
10896
10606
  {
10897
- type: "add-custom-item",
10898
- setModalContent
10899
- }
10900
- )
10901
- ] })
10902
- ] })
10903
- ] })
10904
- ] }),
10905
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10906
- /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10907
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
10908
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10909
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
10910
- /* @__PURE__ */ jsx("div", {})
10911
- ] }) }),
10912
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10913
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10914
- /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10915
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
10916
- Item,
10917
- {
10918
- item,
10919
- preview,
10920
- currencyCode
10921
- },
10922
- item.id
10923
- )) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10924
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10925
- /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
10926
- 'No items found for "',
10927
- query2,
10928
- '".'
10929
- ] })
10930
- ] }) })
10931
- ] })
10932
- ] }),
10933
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10934
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10935
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10936
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
10937
- Text,
10938
- {
10939
- size: "small",
10940
- leading: "compact",
10941
- className: "text-ui-fg-subtle",
10942
- children: [
10943
- itemCount,
10944
- " ",
10945
- itemCount === 1 ? "item" : "items"
10946
- ]
10947
- }
10948
- ) }),
10949
- /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10950
- ] })
10951
- ] }) }),
10952
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
10953
- CustomItemForm,
10954
- {
10955
- orderId: preview.id,
10956
- currencyCode
10957
- }
10958
- ) : null)
10959
- ]
10960
- }
10961
- ) }),
10962
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10963
- /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10964
- /* @__PURE__ */ jsx(
10965
- Button,
10966
- {
10967
- size: "small",
10968
- type: "button",
10969
- onClick: onSubmit,
10970
- isLoading: isSubmitting,
10971
- children: "Save"
10972
- }
10973
- )
10974
- ] }) })
10975
- ] });
10976
- };
10977
- const Item = ({ item, preview, currencyCode }) => {
10978
- if (item.variant_id) {
10979
- return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
10980
- }
10981
- return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
10982
- };
10983
- const VariantItem = ({ item, preview, currencyCode }) => {
10984
- const [editing, setEditing] = useState(false);
10985
- const form = useForm({
10986
- defaultValues: {
10987
- quantity: item.quantity,
10988
- unit_price: item.unit_price
10989
- },
10990
- resolver: zodResolver(variantItemSchema)
10991
- });
10992
- const actionId = useMemo(() => {
10993
- var _a, _b;
10994
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10995
- }, [item]);
10996
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10997
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10998
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10999
- const onSubmit = form.handleSubmit(async (data) => {
11000
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
11001
- setEditing(false);
11002
- return;
11003
- }
11004
- if (!actionId) {
11005
- await updateOriginalItem(
11006
- {
11007
- item_id: item.id,
11008
- quantity: data.quantity,
11009
- unit_price: convertNumber(data.unit_price)
11010
- },
11011
- {
11012
- onSuccess: () => {
11013
- setEditing(false);
11014
- },
11015
- onError: (e) => {
11016
- toast.error(e.message);
11017
- }
11018
- }
11019
- );
11020
- return;
11021
- }
11022
- await updateActionItem(
11023
- {
11024
- action_id: actionId,
11025
- quantity: data.quantity,
11026
- unit_price: convertNumber(data.unit_price)
11027
- },
11028
- {
11029
- onSuccess: () => {
11030
- setEditing(false);
11031
- },
11032
- onError: (e) => {
11033
- toast.error(e.message);
11034
- }
11035
- }
11036
- );
11037
- });
11038
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
11039
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
11040
- /* @__PURE__ */ jsx(
11041
- Thumbnail,
11042
- {
11043
- thumbnail: item.thumbnail,
11044
- alt: item.product_title ?? void 0
11045
- }
11046
- ),
11047
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11048
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11049
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11050
- /* @__PURE__ */ jsxs(
11051
- Text,
11052
- {
11053
- size: "small",
11054
- leading: "compact",
11055
- className: "text-ui-fg-subtle",
11056
- children: [
11057
- "(",
11058
- item.variant_title,
11059
- ")"
11060
- ]
11061
- }
11062
- )
11063
- ] }),
11064
- /* @__PURE__ */ jsx(
11065
- Text,
11066
- {
11067
- size: "small",
11068
- leading: "compact",
11069
- className: "text-ui-fg-subtle",
11070
- children: item.variant_sku
11071
- }
11072
- )
11073
- ] })
11074
- ] }),
11075
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
11076
- Form$2.Field,
11077
- {
11078
- control: form.control,
11079
- name: "quantity",
11080
- render: ({ field }) => {
11081
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
11082
- }
11083
- }
11084
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
11085
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
11086
- Form$2.Field,
11087
- {
11088
- control: form.control,
11089
- name: "unit_price",
11090
- render: ({ field: { onChange, ...field } }) => {
11091
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11092
- CurrencyInput,
11093
- {
11094
- ...field,
11095
- symbol: getNativeSymbol(currencyCode),
11096
- code: currencyCode,
11097
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11098
- }
11099
- ) }) });
11100
- }
11101
- }
11102
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11103
- /* @__PURE__ */ jsx(
11104
- IconButton,
11105
- {
11106
- type: "button",
11107
- size: "small",
11108
- onClick: editing ? onSubmit : () => {
11109
- setEditing(true);
11110
- },
11111
- disabled: isPending,
11112
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
11113
- }
11114
- )
11115
- ] }) }) });
11116
- };
11117
- const variantItemSchema = objectType({
11118
- quantity: numberType(),
11119
- unit_price: unionType([numberType(), stringType()])
11120
- });
11121
- const CustomItem = ({ item, preview, currencyCode }) => {
11122
- const [editing, setEditing] = useState(false);
11123
- const { quantity, unit_price, title } = item;
11124
- const form = useForm({
11125
- defaultValues: {
11126
- title,
11127
- quantity,
11128
- unit_price
11129
- },
11130
- resolver: zodResolver(customItemSchema)
11131
- });
11132
- useEffect(() => {
11133
- form.reset({
11134
- title,
11135
- quantity,
11136
- unit_price
11137
- });
11138
- }, [form, title, quantity, unit_price]);
11139
- const actionId = useMemo(() => {
11140
- var _a, _b;
11141
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11142
- }, [item]);
11143
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11144
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
11145
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11146
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11147
- const onSubmit = form.handleSubmit(async (data) => {
11148
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
11149
- setEditing(false);
11150
- return;
11151
- }
11152
- if (!actionId) {
11153
- await updateOriginalItem(
11154
- {
11155
- item_id: item.id,
11156
- quantity: data.quantity,
11157
- unit_price: convertNumber(data.unit_price)
11158
- },
11159
- {
11160
- onSuccess: () => {
11161
- setEditing(false);
11162
- },
11163
- onError: (e) => {
11164
- toast.error(e.message);
11165
- }
11166
- }
11167
- );
11168
- return;
11169
- }
11170
- if (data.quantity === 0) {
11171
- await removeActionItem(actionId, {
11172
- onSuccess: () => {
11173
- setEditing(false);
11174
- },
11175
- onError: (e) => {
11176
- toast.error(e.message);
11177
- }
11178
- });
11179
- return;
11180
- }
11181
- await updateActionItem(
11182
- {
11183
- action_id: actionId,
11184
- quantity: data.quantity,
11185
- unit_price: convertNumber(data.unit_price)
11186
- },
11187
- {
11188
- onSuccess: () => {
11189
- setEditing(false);
11190
- },
11191
- onError: (e) => {
11192
- toast.error(e.message);
11193
- }
11194
- }
11195
- );
11196
- });
11197
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
11198
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11199
- /* @__PURE__ */ jsx(
11200
- Thumbnail,
11201
- {
11202
- thumbnail: item.thumbnail,
11203
- alt: item.title ?? void 0
11204
- }
11205
- ),
11206
- editing ? /* @__PURE__ */ jsx(
11207
- Form$2.Field,
11208
- {
11209
- control: form.control,
11210
- name: "title",
11211
- render: ({ field }) => {
11212
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
11213
- }
11214
- }
11215
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
11216
- ] }),
11217
- editing ? /* @__PURE__ */ jsx(
11218
- Form$2.Field,
11219
- {
11220
- control: form.control,
11221
- name: "quantity",
11222
- render: ({ field }) => {
11223
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
11224
- }
11225
- }
11226
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
11227
- editing ? /* @__PURE__ */ jsx(
11228
- Form$2.Field,
11229
- {
11230
- control: form.control,
11231
- name: "unit_price",
11232
- render: ({ field: { onChange, ...field } }) => {
11233
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11234
- CurrencyInput,
11235
- {
11236
- ...field,
11237
- symbol: getNativeSymbol(currencyCode),
11238
- code: currencyCode,
11239
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11240
- }
11241
- ) }) });
11242
- }
11243
- }
11244
- ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11245
- /* @__PURE__ */ jsx(
11246
- IconButton,
11247
- {
11248
- type: "button",
11249
- size: "small",
11250
- onClick: editing ? onSubmit : () => {
11251
- setEditing(true);
11252
- },
11253
- disabled: isPending,
11254
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
11255
- }
11256
- )
11257
- ] }) }) });
11258
- };
11259
- const StackedModalTrigger$1 = ({
11260
- type,
11261
- setModalContent
11262
- }) => {
11263
- const { setIsOpen } = useStackedModal();
11264
- const onClick = useCallback(() => {
11265
- setModalContent(type);
11266
- setIsOpen(STACKED_MODAL_ID, true);
11267
- }, [setModalContent, setIsOpen, type]);
11268
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
11269
- };
11270
- const VARIANT_PREFIX = "items";
11271
- const LIMIT = 50;
11272
- const ExistingItemsForm = ({ orderId, items }) => {
11273
- const { setIsOpen } = useStackedModal();
11274
- const [rowSelection, setRowSelection] = useState(
11275
- items.reduce((acc, item) => {
11276
- acc[item.variant_id] = true;
11277
- return acc;
11278
- }, {})
11279
- );
11280
- useEffect(() => {
11281
- setRowSelection(
11282
- items.reduce((acc, item) => {
11283
- if (item.variant_id) {
11284
- acc[item.variant_id] = true;
11285
- }
11286
- return acc;
11287
- }, {})
11288
- );
11289
- }, [items]);
11290
- const { q, order, offset } = useQueryParams(
11291
- ["q", "order", "offset"],
11292
- VARIANT_PREFIX
11293
- );
11294
- const { variants, count, isPending, isError, error } = useProductVariants(
11295
- {
11296
- q,
11297
- order,
11298
- offset: offset ? parseInt(offset) : void 0,
11299
- limit: LIMIT
11300
- },
11301
- {
11302
- placeholderData: keepPreviousData
11303
- }
11304
- );
11305
- const columns = useColumns();
11306
- const { mutateAsync } = useDraftOrderAddItems(orderId);
11307
- const onSubmit = async () => {
11308
- const ids = Object.keys(rowSelection).filter(
11309
- (id) => !items.find((i) => i.variant_id === id)
11310
- );
11311
- await mutateAsync(
11312
- {
11313
- items: ids.map((id) => ({
11314
- variant_id: id,
11315
- quantity: 1
11316
- }))
11317
- },
11318
- {
11319
- onSuccess: () => {
11320
- setRowSelection({});
11321
- setIsOpen(STACKED_MODAL_ID, false);
11322
- },
11323
- onError: (e) => {
11324
- toast.error(e.message);
11325
- }
11326
- }
11327
- );
11328
- };
11329
- if (isError) {
11330
- throw error;
11331
- }
11332
- return /* @__PURE__ */ jsxs(
11333
- StackedFocusModal.Content,
11334
- {
11335
- onOpenAutoFocus: (e) => {
11336
- e.preventDefault();
11337
- const searchInput = document.querySelector(
11338
- "[data-modal-id='modal-search-input']"
11339
- );
11340
- if (searchInput) {
11341
- searchInput.focus();
11342
- }
11343
- },
11344
- children: [
11345
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
11346
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
11347
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11348
- ] }),
11349
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
11350
- DataTable,
11351
- {
11352
- data: variants,
11353
- columns,
11354
- isLoading: isPending,
11355
- getRowId: (row) => row.id,
11356
- rowCount: count,
11357
- prefix: VARIANT_PREFIX,
11358
- layout: "fill",
11359
- rowSelection: {
11360
- state: rowSelection,
11361
- onRowSelectionChange: setRowSelection,
11362
- enableRowSelection: (row) => {
11363
- return !items.find((i) => i.variant_id === row.original.id);
11364
- }
11365
- },
11366
- autoFocusSearch: true
11367
- }
11368
- ) }),
11369
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11370
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11371
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11372
- ] }) })
11373
- ]
11374
- }
11375
- );
11376
- };
11377
- const columnHelper = createDataTableColumnHelper();
11378
- const useColumns = () => {
11379
- return useMemo(() => {
11380
- return [
11381
- columnHelper.select(),
11382
- columnHelper.accessor("product.title", {
11383
- header: "Product",
11384
- cell: ({ row }) => {
11385
- var _a, _b, _c;
11386
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
11387
- /* @__PURE__ */ jsx(
11388
- Thumbnail,
11389
- {
11390
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11391
- alt: (_b = row.original.product) == null ? void 0 : _b.title
11392
- }
11393
- ),
11394
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11395
- ] });
11396
- },
11397
- enableSorting: true
11398
- }),
11399
- columnHelper.accessor("title", {
11400
- header: "Variant",
11401
- enableSorting: true
11402
- }),
11403
- columnHelper.accessor("sku", {
11404
- header: "SKU",
11405
- cell: ({ getValue }) => {
11406
- return getValue() ?? "-";
11407
- },
11408
- enableSorting: true
11409
- }),
11410
- columnHelper.accessor("updated_at", {
11411
- header: "Updated",
11412
- cell: ({ getValue }) => {
11413
- return /* @__PURE__ */ jsx(
11414
- Tooltip,
11415
- {
11416
- content: getFullDate({ date: getValue(), includeTime: true }),
11417
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11418
- }
11419
- );
11420
- },
11421
- enableSorting: true,
11422
- sortAscLabel: "Oldest first",
11423
- sortDescLabel: "Newest first"
11424
- }),
11425
- columnHelper.accessor("created_at", {
11426
- header: "Created",
11427
- cell: ({ getValue }) => {
11428
- return /* @__PURE__ */ jsx(
11429
- Tooltip,
11430
- {
11431
- content: getFullDate({ date: getValue(), includeTime: true }),
11432
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11433
- }
11434
- );
11435
- },
11436
- enableSorting: true,
11437
- sortAscLabel: "Oldest first",
11438
- sortDescLabel: "Newest first"
11439
- })
11440
- ];
11441
- }, []);
11442
- };
11443
- const CustomItemForm = ({ orderId, currencyCode }) => {
11444
- const { setIsOpen } = useStackedModal();
11445
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11446
- const form = useForm({
11447
- defaultValues: {
11448
- title: "",
11449
- quantity: 1,
11450
- unit_price: ""
11451
- },
11452
- resolver: zodResolver(customItemSchema)
11453
- });
11454
- const onSubmit = form.handleSubmit(async (data) => {
11455
- await addItems(
11456
- {
11457
- items: [
11458
- {
11459
- title: data.title,
11460
- quantity: data.quantity,
11461
- unit_price: convertNumber(data.unit_price)
11462
- }
11463
- ]
11464
- },
11465
- {
11466
- onSuccess: () => {
11467
- setIsOpen(STACKED_MODAL_ID, false);
11468
- },
11469
- onError: (e) => {
11470
- toast.error(e.message);
11471
- }
11472
- }
11473
- );
11474
- });
11475
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
11476
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11477
- /* @__PURE__ */ jsx(StackedFocusModal.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 px-2 py-16", children: [
11478
- /* @__PURE__ */ jsxs("div", { children: [
11479
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
11480
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
11481
- ] }),
11482
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11483
- /* @__PURE__ */ jsx(
11484
- Form$2.Field,
11485
- {
11486
- control: form.control,
11487
- name: "title",
11488
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11489
- /* @__PURE__ */ jsxs("div", { children: [
11490
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
11491
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
11492
- ] }),
11493
- /* @__PURE__ */ jsxs("div", { children: [
11494
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11495
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11496
- ] })
11497
- ] }) })
11498
- }
11499
- ),
11500
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11501
- /* @__PURE__ */ jsx(
11502
- Form$2.Field,
11503
- {
11504
- control: form.control,
11505
- name: "unit_price",
11506
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11507
- /* @__PURE__ */ jsxs("div", { children: [
11508
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
11509
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11510
- ] }),
11511
- /* @__PURE__ */ jsxs("div", { children: [
11512
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11513
- CurrencyInput,
11514
- {
11515
- symbol: getNativeSymbol(currencyCode),
11516
- code: currencyCode,
11517
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11518
- ...field
11519
- }
11520
- ) }),
11521
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11522
- ] })
11523
- ] }) })
11524
- }
11525
- ),
11526
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11527
- /* @__PURE__ */ jsx(
11528
- Form$2.Field,
11529
- {
11530
- control: form.control,
11531
- name: "quantity",
11532
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11533
- /* @__PURE__ */ jsxs("div", { children: [
11534
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
11535
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11536
- ] }),
11537
- /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
11538
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11539
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11540
- ] })
11541
- ] }) })
11542
- }
11543
- )
11544
- ] }) }) }),
11545
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11546
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11547
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11548
- ] }) })
11549
- ] }) }) });
11550
- };
11551
- const customItemSchema = objectType({
11552
- title: stringType().min(1),
11553
- quantity: numberType(),
11554
- unit_price: unionType([numberType(), stringType()])
11555
- });
11556
- const ShippingAddress = () => {
11557
- const { id } = useParams();
11558
- const { order, isPending, isError, error } = useOrder(id, {
11559
- fields: "+shipping_address"
11560
- });
11561
- if (isError) {
11562
- throw error;
11563
- }
11564
- const isReady = !isPending && !!order;
11565
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11566
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11567
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11568
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11569
- ] }),
11570
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11571
- ] });
11572
- };
11573
- const ShippingAddressForm = ({ order }) => {
11574
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11575
- const form = useForm({
11576
- defaultValues: {
11577
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11578
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11579
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11580
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11581
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11582
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11583
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11584
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11585
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11586
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11587
- },
11588
- resolver: zodResolver(schema$1)
11589
- });
11590
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11591
- const { handleSuccess } = useRouteModal();
11592
- const onSubmit = form.handleSubmit(async (data) => {
11593
- await mutateAsync(
11594
- {
11595
- shipping_address: {
11596
- first_name: data.first_name,
11597
- last_name: data.last_name,
11598
- company: data.company,
11599
- address_1: data.address_1,
11600
- address_2: data.address_2,
11601
- city: data.city,
11602
- province: data.province,
11603
- country_code: data.country_code,
11604
- postal_code: data.postal_code,
11605
- phone: data.phone
11606
- }
11607
- },
11608
- {
11609
- onSuccess: () => {
11610
- handleSuccess();
11611
- },
11612
- onError: (error) => {
11613
- toast.error(error.message);
11614
- }
11615
- }
11616
- );
11617
- });
11618
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11619
- KeyboundForm,
11620
- {
11621
- className: "flex flex-1 flex-col overflow-hidden",
11622
- onSubmit,
11623
- children: [
11624
- /* @__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: [
11625
- /* @__PURE__ */ jsx(
11626
- Form$2.Field,
11627
- {
11628
- control: form.control,
11629
- name: "country_code",
11630
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11631
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11632
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11633
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11634
- ] })
11635
- }
11636
- ),
11637
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11638
- /* @__PURE__ */ jsx(
11639
- Form$2.Field,
11640
- {
11641
- control: form.control,
11642
- name: "first_name",
11643
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11644
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11645
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11646
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11647
- ] })
11648
- }
11649
- ),
11650
- /* @__PURE__ */ jsx(
11651
- Form$2.Field,
11652
- {
11653
- control: form.control,
11654
- name: "last_name",
11655
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11656
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11657
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11658
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11659
- ] })
11660
- }
11661
- )
11662
- ] }),
11663
- /* @__PURE__ */ jsx(
11664
- Form$2.Field,
11665
- {
11666
- control: form.control,
11667
- name: "company",
11668
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11669
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11670
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11671
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11672
- ] })
11673
- }
11674
- ),
11675
- /* @__PURE__ */ jsx(
11676
- Form$2.Field,
11677
- {
11678
- control: form.control,
11679
- name: "address_1",
11680
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11681
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11682
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11683
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11684
- ] })
11685
- }
11686
- ),
11687
- /* @__PURE__ */ jsx(
11688
- Form$2.Field,
11689
- {
11690
- control: form.control,
11691
- name: "address_2",
11692
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11693
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11694
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11695
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11696
- ] })
11697
- }
11698
- ),
11699
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11700
- /* @__PURE__ */ jsx(
11701
- Form$2.Field,
11702
- {
11703
- control: form.control,
11704
- name: "postal_code",
11705
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11706
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11707
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11708
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11709
- ] })
11710
- }
11711
- ),
11712
- /* @__PURE__ */ jsx(
11713
- Form$2.Field,
11714
- {
11715
- control: form.control,
11716
- name: "city",
11717
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11718
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11719
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11720
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11721
- ] })
11722
- }
11723
- )
11724
- ] }),
11725
- /* @__PURE__ */ jsx(
11726
- Form$2.Field,
11727
- {
11728
- control: form.control,
11729
- name: "province",
11730
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11731
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11732
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11733
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11734
- ] })
11735
- }
11736
- ),
11737
- /* @__PURE__ */ jsx(
11738
- Form$2.Field,
11739
- {
11740
- control: form.control,
11741
- name: "phone",
11742
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11743
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11744
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11745
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11746
- ] })
11747
- }
11748
- )
11749
- ] }) }),
11750
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11751
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11752
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11753
- ] }) })
11754
- ]
11755
- }
11756
- ) });
11757
- };
11758
- const schema$1 = addressSchema;
11759
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11760
- const Shipping = () => {
11761
- var _a;
11762
- const { id } = useParams();
11763
- const { order, isPending, isError, error } = useOrder(id, {
11764
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11765
- });
11766
- const {
11767
- order: preview,
11768
- isPending: isPreviewPending,
11769
- isError: isPreviewError,
11770
- error: previewError
11771
- } = useOrderPreview(id);
11772
- useInitiateOrderEdit({ preview });
11773
- const { onCancel } = useCancelOrderEdit({ preview });
11774
- if (isError) {
11775
- throw error;
11776
- }
11777
- if (isPreviewError) {
11778
- throw previewError;
11779
- }
11780
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11781
- const isReady = preview && !isPreviewPending && order && !isPending;
11782
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11783
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11784
- /* @__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: [
11785
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11786
- /* @__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." }) })
11787
- ] }) }) }),
11788
- /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11789
- ] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
11790
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11791
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11792
- ] }) });
11793
- };
11794
- const ShippingForm = ({ preview, order }) => {
11795
- var _a;
11796
- const { setIsOpen } = useStackedModal();
11797
- const [isSubmitting, setIsSubmitting] = useState(false);
11798
- const [data, setData] = useState(null);
11799
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11800
- const { shipping_options } = useShippingOptions(
11801
- {
11802
- id: appliedShippingOptionIds,
11803
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11804
- },
11805
- {
11806
- enabled: appliedShippingOptionIds.length > 0
11807
- }
11808
- );
11809
- const uniqueShippingProfiles = useMemo(() => {
11810
- const profiles = /* @__PURE__ */ new Map();
11811
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11812
- profiles.set(profile.id, profile);
11813
- });
11814
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11815
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11816
- });
11817
- return Array.from(profiles.values());
11818
- }, [order.items, shipping_options]);
11819
- const { handleSuccess } = useRouteModal();
11820
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11821
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11822
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11823
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11824
- const onSubmit = async () => {
11825
- setIsSubmitting(true);
11826
- let requestSucceeded = false;
11827
- await requestOrderEdit(void 0, {
11828
- onError: (e) => {
11829
- toast.error(`Failed to request order edit: ${e.message}`);
11830
- },
11831
- onSuccess: () => {
11832
- requestSucceeded = true;
11833
- }
11834
- });
11835
- if (!requestSucceeded) {
11836
- setIsSubmitting(false);
11837
- return;
11838
- }
11839
- await confirmOrderEdit(void 0, {
11840
- onError: (e) => {
11841
- toast.error(`Failed to confirm order edit: ${e.message}`);
11842
- },
11843
- onSuccess: () => {
11844
- handleSuccess();
11845
- },
11846
- onSettled: () => {
11847
- setIsSubmitting(false);
11848
- }
11849
- });
11850
- };
11851
- const onKeydown = useCallback(
11852
- (e) => {
11853
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11854
- if (data || isSubmitting) {
11855
- return;
11856
- }
11857
- onSubmit();
11858
- }
11859
- },
11860
- [data, isSubmitting, onSubmit]
11861
- );
11862
- useEffect(() => {
11863
- document.addEventListener("keydown", onKeydown);
11864
- return () => {
11865
- document.removeEventListener("keydown", onKeydown);
11866
- };
11867
- }, [onKeydown]);
11868
- return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11869
- /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
11870
- /* @__PURE__ */ jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11871
- /* @__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: [
11872
- /* @__PURE__ */ jsxs("div", { children: [
11873
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
11874
- /* @__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." }) })
11875
- ] }),
11876
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11877
- /* @__PURE__ */ jsx(Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11878
- /* @__PURE__ */ jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11879
- /* @__PURE__ */ jsx(
11880
- Text,
11881
- {
11882
- size: "xsmall",
11883
- weight: "plus",
11884
- className: "text-ui-fg-muted",
11885
- children: "Shipping profile"
11886
- }
11887
- ),
11888
- /* @__PURE__ */ jsx(
11889
- Text,
11890
- {
11891
- size: "xsmall",
11892
- weight: "plus",
11893
- className: "text-ui-fg-muted",
11894
- children: "Action"
11895
- }
11896
- )
11897
- ] }),
11898
- /* @__PURE__ */ jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11899
- var _a2, _b, _c, _d, _e, _f, _g;
11900
- const items = getItemsWithShippingProfile(
11901
- profile.id,
11902
- order.items
11903
- );
11904
- const hasItems = items.length > 0;
11905
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11906
- (option) => option.shipping_profile_id === profile.id
11907
- );
11908
- const shippingMethod = preview.shipping_methods.find(
11909
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11910
- );
11911
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11912
- (action) => action.action === "SHIPPING_ADD"
11913
- );
11914
- return /* @__PURE__ */ jsxs(
11915
- Accordion.Item,
11916
- {
11917
- value: profile.id,
11918
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11919
- children: [
11920
- /* @__PURE__ */ jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11921
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11922
- /* @__PURE__ */ jsx(Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(
11923
- IconButton,
11924
- {
11925
- size: "2xsmall",
11926
- variant: "transparent",
11927
- className: "group/trigger",
11928
- disabled: !hasItems,
11929
- children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
10607
+ size: "2xsmall",
10608
+ variant: "transparent",
10609
+ className: "group/trigger",
10610
+ disabled: !hasItems,
10611
+ children: /* @__PURE__ */ jsx(TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11930
10612
  }
11931
10613
  ) }),
11932
10614
  !shippingOption ? /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
@@ -12063,7 +10745,7 @@ const ShippingForm = ({ preview, order }) => {
12063
10745
  ]
12064
10746
  }
12065
10747
  ) : /* @__PURE__ */ jsx(
12066
- StackedModalTrigger,
10748
+ StackedModalTrigger$1,
12067
10749
  {
12068
10750
  shippingProfileId: profile.id,
12069
10751
  shippingOption,
@@ -12174,7 +10856,7 @@ const ShippingForm = ({ preview, order }) => {
12174
10856
  ] }) })
12175
10857
  ] });
12176
10858
  };
12177
- const StackedModalTrigger = ({
10859
+ const StackedModalTrigger$1 = ({
12178
10860
  shippingProfileId,
12179
10861
  shippingOption,
12180
10862
  shippingMethod,
@@ -12488,81 +11170,284 @@ const ShippingOptionField = ({
12488
11170
  )) {
12489
11171
  return void 0;
12490
11172
  }
12491
- return {
12492
- label: option.name,
12493
- value: option.id
12494
- };
12495
- }).filter(Boolean);
12496
- },
12497
- enabled: !!locationId && !!shippingProfileId,
12498
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11173
+ return {
11174
+ label: option.name,
11175
+ value: option.id
11176
+ };
11177
+ }).filter(Boolean);
11178
+ },
11179
+ enabled: !!locationId && !!shippingProfileId,
11180
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11181
+ });
11182
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
11183
+ return /* @__PURE__ */ jsx(
11184
+ Form$2.Field,
11185
+ {
11186
+ control,
11187
+ name: "shipping_option_id",
11188
+ render: ({ field }) => {
11189
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11190
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11191
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
11192
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11193
+ ] }),
11194
+ /* @__PURE__ */ jsx(
11195
+ ConditionalTooltip,
11196
+ {
11197
+ content: tooltipContent,
11198
+ showTooltip: !locationId || !shippingProfileId,
11199
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11200
+ Combobox,
11201
+ {
11202
+ options: shippingOptions.options,
11203
+ fetchNextPage: shippingOptions.fetchNextPage,
11204
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
11205
+ searchValue: shippingOptions.searchValue,
11206
+ onSearchValueChange: shippingOptions.onSearchValueChange,
11207
+ placeholder: "Select shipping option",
11208
+ ...field,
11209
+ disabled: !locationId || !shippingProfileId
11210
+ }
11211
+ ) }) })
11212
+ }
11213
+ )
11214
+ ] }) });
11215
+ }
11216
+ }
11217
+ );
11218
+ };
11219
+ const CustomAmountField = ({
11220
+ control,
11221
+ currencyCode
11222
+ }) => {
11223
+ return /* @__PURE__ */ jsx(
11224
+ Form$2.Field,
11225
+ {
11226
+ control,
11227
+ name: "custom_amount",
11228
+ render: ({ field: { onChange, ...field } }) => {
11229
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11230
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11231
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
11232
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11233
+ ] }),
11234
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11235
+ CurrencyInput,
11236
+ {
11237
+ ...field,
11238
+ onValueChange: (value) => onChange(value),
11239
+ symbol: getNativeSymbol(currencyCode),
11240
+ code: currencyCode
11241
+ }
11242
+ ) })
11243
+ ] });
11244
+ }
11245
+ }
11246
+ );
11247
+ };
11248
+ const ShippingAddress = () => {
11249
+ const { id } = useParams();
11250
+ const { order, isPending, isError, error } = useOrder(id, {
11251
+ fields: "+shipping_address"
11252
+ });
11253
+ if (isError) {
11254
+ throw error;
11255
+ }
11256
+ const isReady = !isPending && !!order;
11257
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11258
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11259
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11260
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11261
+ ] }),
11262
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11263
+ ] });
11264
+ };
11265
+ const ShippingAddressForm = ({ order }) => {
11266
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11267
+ const form = useForm({
11268
+ defaultValues: {
11269
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11270
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11271
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11272
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11273
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11274
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11275
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11276
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11277
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11278
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11279
+ },
11280
+ resolver: zodResolver(schema$2)
11281
+ });
11282
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11283
+ const { handleSuccess } = useRouteModal();
11284
+ const onSubmit = form.handleSubmit(async (data) => {
11285
+ await mutateAsync(
11286
+ {
11287
+ shipping_address: {
11288
+ first_name: data.first_name,
11289
+ last_name: data.last_name,
11290
+ company: data.company,
11291
+ address_1: data.address_1,
11292
+ address_2: data.address_2,
11293
+ city: data.city,
11294
+ province: data.province,
11295
+ country_code: data.country_code,
11296
+ postal_code: data.postal_code,
11297
+ phone: data.phone
11298
+ }
11299
+ },
11300
+ {
11301
+ onSuccess: () => {
11302
+ handleSuccess();
11303
+ },
11304
+ onError: (error) => {
11305
+ toast.error(error.message);
11306
+ }
11307
+ }
11308
+ );
12499
11309
  });
12500
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12501
- return /* @__PURE__ */ jsx(
12502
- Form$2.Field,
11310
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11311
+ KeyboundForm,
12503
11312
  {
12504
- control,
12505
- name: "shipping_option_id",
12506
- render: ({ field }) => {
12507
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12508
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12509
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12510
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11313
+ className: "flex flex-1 flex-col overflow-hidden",
11314
+ onSubmit,
11315
+ children: [
11316
+ /* @__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: [
11317
+ /* @__PURE__ */ jsx(
11318
+ Form$2.Field,
11319
+ {
11320
+ control: form.control,
11321
+ name: "country_code",
11322
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11323
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11324
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11325
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11326
+ ] })
11327
+ }
11328
+ ),
11329
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11330
+ /* @__PURE__ */ jsx(
11331
+ Form$2.Field,
11332
+ {
11333
+ control: form.control,
11334
+ name: "first_name",
11335
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11336
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11337
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11338
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11339
+ ] })
11340
+ }
11341
+ ),
11342
+ /* @__PURE__ */ jsx(
11343
+ Form$2.Field,
11344
+ {
11345
+ control: form.control,
11346
+ name: "last_name",
11347
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11348
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11349
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11350
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11351
+ ] })
11352
+ }
11353
+ )
12511
11354
  ] }),
12512
11355
  /* @__PURE__ */ jsx(
12513
- ConditionalTooltip,
11356
+ Form$2.Field,
12514
11357
  {
12515
- content: tooltipContent,
12516
- showTooltip: !locationId || !shippingProfileId,
12517
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12518
- Combobox,
12519
- {
12520
- options: shippingOptions.options,
12521
- fetchNextPage: shippingOptions.fetchNextPage,
12522
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12523
- searchValue: shippingOptions.searchValue,
12524
- onSearchValueChange: shippingOptions.onSearchValueChange,
12525
- placeholder: "Select shipping option",
12526
- ...field,
12527
- disabled: !locationId || !shippingProfileId
12528
- }
12529
- ) }) })
11358
+ control: form.control,
11359
+ name: "company",
11360
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11361
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11362
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11363
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11364
+ ] })
12530
11365
  }
12531
- )
12532
- ] }) });
12533
- }
12534
- }
12535
- );
12536
- };
12537
- const CustomAmountField = ({
12538
- control,
12539
- currencyCode
12540
- }) => {
12541
- return /* @__PURE__ */ jsx(
12542
- Form$2.Field,
12543
- {
12544
- control,
12545
- name: "custom_amount",
12546
- render: ({ field: { onChange, ...field } }) => {
12547
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12548
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12549
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12550
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11366
+ ),
11367
+ /* @__PURE__ */ jsx(
11368
+ Form$2.Field,
11369
+ {
11370
+ control: form.control,
11371
+ name: "address_1",
11372
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11373
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11374
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11375
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11376
+ ] })
11377
+ }
11378
+ ),
11379
+ /* @__PURE__ */ jsx(
11380
+ Form$2.Field,
11381
+ {
11382
+ control: form.control,
11383
+ name: "address_2",
11384
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11385
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11386
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11387
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11388
+ ] })
11389
+ }
11390
+ ),
11391
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11392
+ /* @__PURE__ */ jsx(
11393
+ Form$2.Field,
11394
+ {
11395
+ control: form.control,
11396
+ name: "postal_code",
11397
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11398
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11399
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11400
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11401
+ ] })
11402
+ }
11403
+ ),
11404
+ /* @__PURE__ */ jsx(
11405
+ Form$2.Field,
11406
+ {
11407
+ control: form.control,
11408
+ name: "city",
11409
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11410
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11411
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11412
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11413
+ ] })
11414
+ }
11415
+ )
12551
11416
  ] }),
12552
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12553
- CurrencyInput,
11417
+ /* @__PURE__ */ jsx(
11418
+ Form$2.Field,
12554
11419
  {
12555
- ...field,
12556
- onValueChange: (value) => onChange(value),
12557
- symbol: getNativeSymbol(currencyCode),
12558
- code: currencyCode
11420
+ control: form.control,
11421
+ name: "province",
11422
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11423
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11424
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11425
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11426
+ ] })
12559
11427
  }
12560
- ) })
12561
- ] });
12562
- }
11428
+ ),
11429
+ /* @__PURE__ */ jsx(
11430
+ Form$2.Field,
11431
+ {
11432
+ control: form.control,
11433
+ name: "phone",
11434
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11435
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11436
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11437
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11438
+ ] })
11439
+ }
11440
+ )
11441
+ ] }) }),
11442
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11443
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11444
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11445
+ ] }) })
11446
+ ]
12563
11447
  }
12564
- );
11448
+ ) });
12565
11449
  };
11450
+ const schema$2 = addressSchema;
12566
11451
  const TransferOwnership = () => {
12567
11452
  const { id } = useParams();
12568
11453
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12586,7 +11471,7 @@ const TransferOwnershipForm = ({ order }) => {
12586
11471
  defaultValues: {
12587
11472
  customer_id: order.customer_id || ""
12588
11473
  },
12589
- resolver: zodResolver(schema)
11474
+ resolver: zodResolver(schema$1)
12590
11475
  });
12591
11476
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
11477
  const { handleSuccess } = useRouteModal();
@@ -12908,137 +11793,1252 @@ const Illustration = () => {
12908
11793
  transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12909
11794
  fill: "#A1A1AA"
12910
11795
  }
12911
- ),
12912
- /* @__PURE__ */ jsx(
11796
+ ),
11797
+ /* @__PURE__ */ jsx(
11798
+ "path",
11799
+ {
11800
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
11801
+ fill: "#52525B"
11802
+ }
11803
+ ),
11804
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
11805
+ "path",
11806
+ {
11807
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11808
+ stroke: "#A1A1AA",
11809
+ strokeWidth: "1.5",
11810
+ strokeLinecap: "round",
11811
+ strokeLinejoin: "round"
11812
+ }
11813
+ ) }),
11814
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
11815
+ "path",
11816
+ {
11817
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11818
+ stroke: "#A1A1AA",
11819
+ strokeWidth: "1.5",
11820
+ strokeLinecap: "round",
11821
+ strokeLinejoin: "round"
11822
+ }
11823
+ ) }),
11824
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
11825
+ "path",
11826
+ {
11827
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11828
+ stroke: "#A1A1AA",
11829
+ strokeWidth: "1.5",
11830
+ strokeLinecap: "round",
11831
+ strokeLinejoin: "round"
11832
+ }
11833
+ ) }),
11834
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
11835
+ "path",
11836
+ {
11837
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11838
+ stroke: "#A1A1AA",
11839
+ strokeWidth: "1.5",
11840
+ strokeLinecap: "round",
11841
+ strokeLinejoin: "round"
11842
+ }
11843
+ ) }),
11844
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
11845
+ "path",
11846
+ {
11847
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11848
+ stroke: "#A1A1AA",
11849
+ strokeWidth: "1.5",
11850
+ strokeLinecap: "round",
11851
+ strokeLinejoin: "round"
11852
+ }
11853
+ ) }),
11854
+ /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12913
11855
  "path",
12914
11856
  {
12915
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12916
- fill: "#52525B"
11857
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11858
+ stroke: "#A1A1AA",
11859
+ strokeWidth: "1.5",
11860
+ strokeLinecap: "round",
11861
+ strokeLinejoin: "round"
11862
+ }
11863
+ ) }),
11864
+ /* @__PURE__ */ jsxs("defs", { children: [
11865
+ /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
11866
+ "rect",
11867
+ {
11868
+ width: "12",
11869
+ height: "12",
11870
+ fill: "white",
11871
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11872
+ }
11873
+ ) }),
11874
+ /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
11875
+ "rect",
11876
+ {
11877
+ width: "12",
11878
+ height: "12",
11879
+ fill: "white",
11880
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
11881
+ }
11882
+ ) }),
11883
+ /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
11884
+ "rect",
11885
+ {
11886
+ width: "12",
11887
+ height: "12",
11888
+ fill: "white",
11889
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
11890
+ }
11891
+ ) }),
11892
+ /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
11893
+ "rect",
11894
+ {
11895
+ width: "12",
11896
+ height: "12",
11897
+ fill: "white",
11898
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
11899
+ }
11900
+ ) }),
11901
+ /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
11902
+ "rect",
11903
+ {
11904
+ width: "12",
11905
+ height: "12",
11906
+ fill: "white",
11907
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
11908
+ }
11909
+ ) }),
11910
+ /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
11911
+ "rect",
11912
+ {
11913
+ width: "12",
11914
+ height: "12",
11915
+ fill: "white",
11916
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
11917
+ }
11918
+ ) })
11919
+ ] })
11920
+ ]
11921
+ }
11922
+ );
11923
+ };
11924
+ const schema$1 = objectType({
11925
+ customer_id: stringType().min(1)
11926
+ });
11927
+ const NumberInput = forwardRef(
11928
+ ({
11929
+ value,
11930
+ onChange,
11931
+ size = "base",
11932
+ min = 0,
11933
+ max = 100,
11934
+ step = 1,
11935
+ className,
11936
+ disabled,
11937
+ ...props
11938
+ }, ref) => {
11939
+ const handleChange = (event) => {
11940
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
11941
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
11942
+ onChange(newValue);
11943
+ }
11944
+ };
11945
+ const handleIncrement = () => {
11946
+ const newValue = value + step;
11947
+ if (max === void 0 || newValue <= max) {
11948
+ onChange(newValue);
11949
+ }
11950
+ };
11951
+ const handleDecrement = () => {
11952
+ const newValue = value - step;
11953
+ if (min === void 0 || newValue >= min) {
11954
+ onChange(newValue);
11955
+ }
11956
+ };
11957
+ return /* @__PURE__ */ jsxs(
11958
+ "div",
11959
+ {
11960
+ className: clx(
11961
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
11962
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
11963
+ {
11964
+ "h-7": size === "small",
11965
+ "h-8": size === "base"
11966
+ },
11967
+ className
11968
+ ),
11969
+ children: [
11970
+ /* @__PURE__ */ jsx(
11971
+ "input",
11972
+ {
11973
+ ref,
11974
+ type: "number",
11975
+ value,
11976
+ onChange: handleChange,
11977
+ min,
11978
+ max,
11979
+ step,
11980
+ className: clx(
11981
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
11982
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
11983
+ "placeholder:text-ui-fg-muted"
11984
+ ),
11985
+ ...props
11986
+ }
11987
+ ),
11988
+ /* @__PURE__ */ jsxs(
11989
+ "button",
11990
+ {
11991
+ className: clx(
11992
+ "flex items-center justify-center outline-none transition-fg",
11993
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
11994
+ "focus:bg-ui-bg-field-component-hover",
11995
+ "hover:bg-ui-bg-field-component-hover",
11996
+ {
11997
+ "size-7": size === "small",
11998
+ "size-8": size === "base"
11999
+ }
12000
+ ),
12001
+ type: "button",
12002
+ onClick: handleDecrement,
12003
+ disabled: min !== void 0 && value <= min || disabled,
12004
+ children: [
12005
+ /* @__PURE__ */ jsx(Minus, {}),
12006
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
12007
+ ]
12008
+ }
12009
+ ),
12010
+ /* @__PURE__ */ jsxs(
12011
+ "button",
12012
+ {
12013
+ className: clx(
12014
+ "flex items-center justify-center outline-none transition-fg",
12015
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
12016
+ "focus:bg-ui-bg-field-hover",
12017
+ "hover:bg-ui-bg-field-hover",
12018
+ {
12019
+ "size-7": size === "small",
12020
+ "size-8": size === "base"
12021
+ }
12022
+ ),
12023
+ type: "button",
12024
+ onClick: handleIncrement,
12025
+ disabled: max !== void 0 && value >= max || disabled,
12026
+ children: [
12027
+ /* @__PURE__ */ jsx(Plus, {}),
12028
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
12029
+ ]
12030
+ }
12031
+ )
12032
+ ]
12033
+ }
12034
+ );
12035
+ }
12036
+ );
12037
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
12038
+ const productVariantsQueryKeys = {
12039
+ list: (query2) => [
12040
+ PRODUCT_VARIANTS_QUERY_KEY,
12041
+ query2 ? query2 : void 0
12042
+ ]
12043
+ };
12044
+ const useProductVariants = (query2, options) => {
12045
+ const { data, ...rest } = useQuery({
12046
+ queryKey: productVariantsQueryKeys.list(query2),
12047
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
12048
+ ...options
12049
+ });
12050
+ return { ...data, ...rest };
12051
+ };
12052
+ const STACKED_MODAL_ID = "items_stacked_modal";
12053
+ const Items = () => {
12054
+ const { id } = useParams();
12055
+ const {
12056
+ order: preview,
12057
+ isPending: isPreviewPending,
12058
+ isError: isPreviewError,
12059
+ error: previewError
12060
+ } = useOrderPreview(id, void 0, {
12061
+ placeholderData: keepPreviousData
12062
+ });
12063
+ useInitiateOrderEdit({ preview });
12064
+ const { draft_order, isPending, isError, error } = useDraftOrder(
12065
+ id,
12066
+ {
12067
+ fields: "currency_code"
12068
+ },
12069
+ {
12070
+ enabled: !!id
12071
+ }
12072
+ );
12073
+ const { onCancel } = useCancelOrderEdit({ preview });
12074
+ if (isError) {
12075
+ throw error;
12076
+ }
12077
+ if (isPreviewError) {
12078
+ throw previewError;
12079
+ }
12080
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
12081
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
12082
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
12083
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12084
+ ] }) });
12085
+ };
12086
+ const ItemsForm = ({ preview, currencyCode }) => {
12087
+ var _a;
12088
+ const [isSubmitting, setIsSubmitting] = useState(false);
12089
+ const [modalContent, setModalContent] = useState(
12090
+ null
12091
+ );
12092
+ const { handleSuccess } = useRouteModal();
12093
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
12094
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12095
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12096
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
12097
+ const matches = useMemo(() => {
12098
+ return matchSorter(preview.items, query2, {
12099
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
12100
+ });
12101
+ }, [preview.items, query2]);
12102
+ const onSubmit = async () => {
12103
+ setIsSubmitting(true);
12104
+ let requestSucceeded = false;
12105
+ await requestOrderEdit(void 0, {
12106
+ onError: (e) => {
12107
+ toast.error(`Failed to request order edit: ${e.message}`);
12108
+ },
12109
+ onSuccess: () => {
12110
+ requestSucceeded = true;
12111
+ }
12112
+ });
12113
+ if (!requestSucceeded) {
12114
+ setIsSubmitting(false);
12115
+ return;
12116
+ }
12117
+ await confirmOrderEdit(void 0, {
12118
+ onError: (e) => {
12119
+ toast.error(`Failed to confirm order edit: ${e.message}`);
12120
+ },
12121
+ onSuccess: () => {
12122
+ handleSuccess();
12123
+ },
12124
+ onSettled: () => {
12125
+ setIsSubmitting(false);
12126
+ }
12127
+ });
12128
+ };
12129
+ const onKeyDown = useCallback(
12130
+ (e) => {
12131
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12132
+ if (modalContent || isSubmitting) {
12133
+ return;
12134
+ }
12135
+ onSubmit();
12136
+ }
12137
+ },
12138
+ [modalContent, isSubmitting, onSubmit]
12139
+ );
12140
+ useEffect(() => {
12141
+ document.addEventListener("keydown", onKeyDown);
12142
+ return () => {
12143
+ document.removeEventListener("keydown", onKeyDown);
12144
+ };
12145
+ }, [onKeyDown]);
12146
+ return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12147
+ /* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
12148
+ /* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
12149
+ StackedFocusModal,
12150
+ {
12151
+ id: STACKED_MODAL_ID,
12152
+ onOpenChangeCallback: (open) => {
12153
+ if (!open) {
12154
+ setModalContent(null);
12917
12155
  }
12918
- ),
12919
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsx(
12920
- "path",
12921
- {
12922
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12923
- stroke: "#A1A1AA",
12924
- strokeWidth: "1.5",
12925
- strokeLinecap: "round",
12926
- strokeLinejoin: "round"
12156
+ },
12157
+ children: [
12158
+ /* @__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 px-6 py-16", children: [
12159
+ /* @__PURE__ */ jsxs("div", { children: [
12160
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
12161
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
12162
+ ] }),
12163
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12164
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
12165
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
12166
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12167
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
12168
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
12169
+ ] }),
12170
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
12171
+ /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
12172
+ Input,
12173
+ {
12174
+ type: "search",
12175
+ placeholder: "Search items",
12176
+ value: searchValue,
12177
+ onChange: (e) => onSearchValueChange(e.target.value)
12178
+ }
12179
+ ) }),
12180
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
12181
+ /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
12182
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
12183
+ /* @__PURE__ */ jsx(
12184
+ StackedModalTrigger,
12185
+ {
12186
+ type: "add-items",
12187
+ setModalContent
12188
+ }
12189
+ ),
12190
+ /* @__PURE__ */ jsx(
12191
+ StackedModalTrigger,
12192
+ {
12193
+ type: "add-custom-item",
12194
+ setModalContent
12195
+ }
12196
+ )
12197
+ ] })
12198
+ ] })
12199
+ ] })
12200
+ ] }),
12201
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12202
+ /* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
12203
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
12204
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
12205
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
12206
+ /* @__PURE__ */ jsx("div", {})
12207
+ ] }) }),
12208
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12209
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
12210
+ /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
12211
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
12212
+ Item,
12213
+ {
12214
+ item,
12215
+ preview,
12216
+ currencyCode
12217
+ },
12218
+ item.id
12219
+ )) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
12220
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12221
+ /* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
12222
+ 'No items found for "',
12223
+ query2,
12224
+ '".'
12225
+ ] })
12226
+ ] }) })
12227
+ ] })
12228
+ ] }),
12229
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12230
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
12231
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
12232
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
12233
+ Text,
12234
+ {
12235
+ size: "small",
12236
+ leading: "compact",
12237
+ className: "text-ui-fg-subtle",
12238
+ children: [
12239
+ itemCount,
12240
+ " ",
12241
+ itemCount === 1 ? "item" : "items"
12242
+ ]
12243
+ }
12244
+ ) }),
12245
+ /* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
12246
+ ] })
12247
+ ] }) }),
12248
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
12249
+ CustomItemForm,
12250
+ {
12251
+ orderId: preview.id,
12252
+ currencyCode
12253
+ }
12254
+ ) : null)
12255
+ ]
12256
+ }
12257
+ ) }),
12258
+ /* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12259
+ /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12260
+ /* @__PURE__ */ jsx(
12261
+ Button,
12262
+ {
12263
+ size: "small",
12264
+ type: "button",
12265
+ onClick: onSubmit,
12266
+ isLoading: isSubmitting,
12267
+ children: "Save"
12268
+ }
12269
+ )
12270
+ ] }) })
12271
+ ] });
12272
+ };
12273
+ const Item = ({ item, preview, currencyCode }) => {
12274
+ if (item.variant_id) {
12275
+ return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
12276
+ }
12277
+ return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
12278
+ };
12279
+ const VariantItem = ({ item, preview, currencyCode }) => {
12280
+ const [editing, setEditing] = useState(false);
12281
+ const form = useForm({
12282
+ defaultValues: {
12283
+ quantity: item.quantity,
12284
+ unit_price: item.unit_price
12285
+ },
12286
+ resolver: zodResolver(variantItemSchema)
12287
+ });
12288
+ const actionId = useMemo(() => {
12289
+ var _a, _b;
12290
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12291
+ }, [item]);
12292
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12293
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12294
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12295
+ const onSubmit = form.handleSubmit(async (data) => {
12296
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
12297
+ setEditing(false);
12298
+ return;
12299
+ }
12300
+ if (!actionId) {
12301
+ await updateOriginalItem(
12302
+ {
12303
+ item_id: item.id,
12304
+ quantity: data.quantity,
12305
+ unit_price: convertNumber(data.unit_price)
12306
+ },
12307
+ {
12308
+ onSuccess: () => {
12309
+ setEditing(false);
12310
+ },
12311
+ onError: (e) => {
12312
+ toast.error(e.message);
12927
12313
  }
12928
- ) }),
12929
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsx(
12930
- "path",
12314
+ }
12315
+ );
12316
+ return;
12317
+ }
12318
+ await updateActionItem(
12319
+ {
12320
+ action_id: actionId,
12321
+ quantity: data.quantity,
12322
+ unit_price: convertNumber(data.unit_price)
12323
+ },
12324
+ {
12325
+ onSuccess: () => {
12326
+ setEditing(false);
12327
+ },
12328
+ onError: (e) => {
12329
+ toast.error(e.message);
12330
+ }
12331
+ }
12332
+ );
12333
+ });
12334
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
12335
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
12336
+ /* @__PURE__ */ jsx(
12337
+ Thumbnail,
12338
+ {
12339
+ thumbnail: item.thumbnail,
12340
+ alt: item.product_title ?? void 0
12341
+ }
12342
+ ),
12343
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
12345
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12346
+ /* @__PURE__ */ jsxs(
12347
+ Text,
12348
+ {
12349
+ size: "small",
12350
+ leading: "compact",
12351
+ className: "text-ui-fg-subtle",
12352
+ children: [
12353
+ "(",
12354
+ item.variant_title,
12355
+ ")"
12356
+ ]
12357
+ }
12358
+ )
12359
+ ] }),
12360
+ /* @__PURE__ */ jsx(
12361
+ Text,
12931
12362
  {
12932
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12933
- stroke: "#A1A1AA",
12934
- strokeWidth: "1.5",
12935
- strokeLinecap: "round",
12936
- strokeLinejoin: "round"
12363
+ size: "small",
12364
+ leading: "compact",
12365
+ className: "text-ui-fg-subtle",
12366
+ children: item.variant_sku
12937
12367
  }
12938
- ) }),
12939
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsx(
12940
- "path",
12941
- {
12942
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12943
- stroke: "#A1A1AA",
12944
- strokeWidth: "1.5",
12945
- strokeLinecap: "round",
12946
- strokeLinejoin: "round"
12368
+ )
12369
+ ] })
12370
+ ] }),
12371
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
12372
+ Form$2.Field,
12373
+ {
12374
+ control: form.control,
12375
+ name: "quantity",
12376
+ render: ({ field }) => {
12377
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12378
+ }
12379
+ }
12380
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
12381
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
12382
+ Form$2.Field,
12383
+ {
12384
+ control: form.control,
12385
+ name: "unit_price",
12386
+ render: ({ field: { onChange, ...field } }) => {
12387
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12388
+ CurrencyInput,
12389
+ {
12390
+ ...field,
12391
+ symbol: getNativeSymbol(currencyCode),
12392
+ code: currencyCode,
12393
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12394
+ }
12395
+ ) }) });
12396
+ }
12397
+ }
12398
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12399
+ /* @__PURE__ */ jsx(
12400
+ IconButton,
12401
+ {
12402
+ type: "button",
12403
+ size: "small",
12404
+ onClick: editing ? onSubmit : () => {
12405
+ setEditing(true);
12406
+ },
12407
+ disabled: isPending,
12408
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12409
+ }
12410
+ )
12411
+ ] }) }) });
12412
+ };
12413
+ const variantItemSchema = objectType({
12414
+ quantity: numberType(),
12415
+ unit_price: unionType([numberType(), stringType()])
12416
+ });
12417
+ const CustomItem = ({ item, preview, currencyCode }) => {
12418
+ const [editing, setEditing] = useState(false);
12419
+ const { quantity, unit_price, title } = item;
12420
+ const form = useForm({
12421
+ defaultValues: {
12422
+ title,
12423
+ quantity,
12424
+ unit_price
12425
+ },
12426
+ resolver: zodResolver(customItemSchema)
12427
+ });
12428
+ useEffect(() => {
12429
+ form.reset({
12430
+ title,
12431
+ quantity,
12432
+ unit_price
12433
+ });
12434
+ }, [form, title, quantity, unit_price]);
12435
+ const actionId = useMemo(() => {
12436
+ var _a, _b;
12437
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
12438
+ }, [item]);
12439
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
12440
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
12441
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
12442
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
12443
+ const onSubmit = form.handleSubmit(async (data) => {
12444
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
12445
+ setEditing(false);
12446
+ return;
12447
+ }
12448
+ if (!actionId) {
12449
+ await updateOriginalItem(
12450
+ {
12451
+ item_id: item.id,
12452
+ quantity: data.quantity,
12453
+ unit_price: convertNumber(data.unit_price)
12454
+ },
12455
+ {
12456
+ onSuccess: () => {
12457
+ setEditing(false);
12458
+ },
12459
+ onError: (e) => {
12460
+ toast.error(e.message);
12947
12461
  }
12948
- ) }),
12949
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsx(
12950
- "path",
12951
- {
12952
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12953
- stroke: "#A1A1AA",
12954
- strokeWidth: "1.5",
12955
- strokeLinecap: "round",
12956
- strokeLinejoin: "round"
12462
+ }
12463
+ );
12464
+ return;
12465
+ }
12466
+ if (data.quantity === 0) {
12467
+ await removeActionItem(actionId, {
12468
+ onSuccess: () => {
12469
+ setEditing(false);
12470
+ },
12471
+ onError: (e) => {
12472
+ toast.error(e.message);
12473
+ }
12474
+ });
12475
+ return;
12476
+ }
12477
+ await updateActionItem(
12478
+ {
12479
+ action_id: actionId,
12480
+ quantity: data.quantity,
12481
+ unit_price: convertNumber(data.unit_price)
12482
+ },
12483
+ {
12484
+ onSuccess: () => {
12485
+ setEditing(false);
12486
+ },
12487
+ onError: (e) => {
12488
+ toast.error(e.message);
12489
+ }
12490
+ }
12491
+ );
12492
+ });
12493
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
12494
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
12495
+ /* @__PURE__ */ jsx(
12496
+ Thumbnail,
12497
+ {
12498
+ thumbnail: item.thumbnail,
12499
+ alt: item.title ?? void 0
12500
+ }
12501
+ ),
12502
+ editing ? /* @__PURE__ */ jsx(
12503
+ Form$2.Field,
12504
+ {
12505
+ control: form.control,
12506
+ name: "title",
12507
+ render: ({ field }) => {
12508
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
12957
12509
  }
12958
- ) }),
12959
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsx(
12960
- "path",
12510
+ }
12511
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
12512
+ ] }),
12513
+ editing ? /* @__PURE__ */ jsx(
12514
+ Form$2.Field,
12515
+ {
12516
+ control: form.control,
12517
+ name: "quantity",
12518
+ render: ({ field }) => {
12519
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
12520
+ }
12521
+ }
12522
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
12523
+ editing ? /* @__PURE__ */ jsx(
12524
+ Form$2.Field,
12525
+ {
12526
+ control: form.control,
12527
+ name: "unit_price",
12528
+ render: ({ field: { onChange, ...field } }) => {
12529
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12530
+ CurrencyInput,
12531
+ {
12532
+ ...field,
12533
+ symbol: getNativeSymbol(currencyCode),
12534
+ code: currencyCode,
12535
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
12536
+ }
12537
+ ) }) });
12538
+ }
12539
+ }
12540
+ ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
12541
+ /* @__PURE__ */ jsx(
12542
+ IconButton,
12543
+ {
12544
+ type: "button",
12545
+ size: "small",
12546
+ onClick: editing ? onSubmit : () => {
12547
+ setEditing(true);
12548
+ },
12549
+ disabled: isPending,
12550
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
12551
+ }
12552
+ )
12553
+ ] }) }) });
12554
+ };
12555
+ const StackedModalTrigger = ({
12556
+ type,
12557
+ setModalContent
12558
+ }) => {
12559
+ const { setIsOpen } = useStackedModal();
12560
+ const onClick = useCallback(() => {
12561
+ setModalContent(type);
12562
+ setIsOpen(STACKED_MODAL_ID, true);
12563
+ }, [setModalContent, setIsOpen, type]);
12564
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
12565
+ };
12566
+ const VARIANT_PREFIX = "items";
12567
+ const LIMIT = 50;
12568
+ const ExistingItemsForm = ({ orderId, items }) => {
12569
+ const { setIsOpen } = useStackedModal();
12570
+ const [rowSelection, setRowSelection] = useState(
12571
+ items.reduce((acc, item) => {
12572
+ acc[item.variant_id] = true;
12573
+ return acc;
12574
+ }, {})
12575
+ );
12576
+ useEffect(() => {
12577
+ setRowSelection(
12578
+ items.reduce((acc, item) => {
12579
+ if (item.variant_id) {
12580
+ acc[item.variant_id] = true;
12581
+ }
12582
+ return acc;
12583
+ }, {})
12584
+ );
12585
+ }, [items]);
12586
+ const { q, order, offset } = useQueryParams(
12587
+ ["q", "order", "offset"],
12588
+ VARIANT_PREFIX
12589
+ );
12590
+ const { variants, count, isPending, isError, error } = useProductVariants(
12591
+ {
12592
+ q,
12593
+ order,
12594
+ offset: offset ? parseInt(offset) : void 0,
12595
+ limit: LIMIT
12596
+ },
12597
+ {
12598
+ placeholderData: keepPreviousData
12599
+ }
12600
+ );
12601
+ const columns = useColumns();
12602
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
12603
+ const onSubmit = async () => {
12604
+ const ids = Object.keys(rowSelection).filter(
12605
+ (id) => !items.find((i) => i.variant_id === id)
12606
+ );
12607
+ await mutateAsync(
12608
+ {
12609
+ items: ids.map((id) => ({
12610
+ variant_id: id,
12611
+ quantity: 1
12612
+ }))
12613
+ },
12614
+ {
12615
+ onSuccess: () => {
12616
+ setRowSelection({});
12617
+ setIsOpen(STACKED_MODAL_ID, false);
12618
+ },
12619
+ onError: (e) => {
12620
+ toast.error(e.message);
12621
+ }
12622
+ }
12623
+ );
12624
+ };
12625
+ if (isError) {
12626
+ throw error;
12627
+ }
12628
+ return /* @__PURE__ */ jsxs(
12629
+ StackedFocusModal.Content,
12630
+ {
12631
+ onOpenAutoFocus: (e) => {
12632
+ e.preventDefault();
12633
+ const searchInput = document.querySelector(
12634
+ "[data-modal-id='modal-search-input']"
12635
+ );
12636
+ if (searchInput) {
12637
+ searchInput.focus();
12638
+ }
12639
+ },
12640
+ children: [
12641
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
12642
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
12643
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
12644
+ ] }),
12645
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
12646
+ DataTable,
12961
12647
  {
12962
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12963
- stroke: "#A1A1AA",
12964
- strokeWidth: "1.5",
12965
- strokeLinecap: "round",
12966
- strokeLinejoin: "round"
12648
+ data: variants,
12649
+ columns,
12650
+ isLoading: isPending,
12651
+ getRowId: (row) => row.id,
12652
+ rowCount: count,
12653
+ prefix: VARIANT_PREFIX,
12654
+ layout: "fill",
12655
+ rowSelection: {
12656
+ state: rowSelection,
12657
+ onRowSelectionChange: setRowSelection,
12658
+ enableRowSelection: (row) => {
12659
+ return !items.find((i) => i.variant_id === row.original.id);
12660
+ }
12661
+ },
12662
+ autoFocusSearch: true
12967
12663
  }
12968
12664
  ) }),
12969
- /* @__PURE__ */ jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsx(
12970
- "path",
12665
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12666
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12667
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
12668
+ ] }) })
12669
+ ]
12670
+ }
12671
+ );
12672
+ };
12673
+ const columnHelper = createDataTableColumnHelper();
12674
+ const useColumns = () => {
12675
+ return useMemo(() => {
12676
+ return [
12677
+ columnHelper.select(),
12678
+ columnHelper.accessor("product.title", {
12679
+ header: "Product",
12680
+ cell: ({ row }) => {
12681
+ var _a, _b, _c;
12682
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
12683
+ /* @__PURE__ */ jsx(
12684
+ Thumbnail,
12685
+ {
12686
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
12687
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
12688
+ }
12689
+ ),
12690
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
12691
+ ] });
12692
+ },
12693
+ enableSorting: true
12694
+ }),
12695
+ columnHelper.accessor("title", {
12696
+ header: "Variant",
12697
+ enableSorting: true
12698
+ }),
12699
+ columnHelper.accessor("sku", {
12700
+ header: "SKU",
12701
+ cell: ({ getValue }) => {
12702
+ return getValue() ?? "-";
12703
+ },
12704
+ enableSorting: true
12705
+ }),
12706
+ columnHelper.accessor("updated_at", {
12707
+ header: "Updated",
12708
+ cell: ({ getValue }) => {
12709
+ return /* @__PURE__ */ jsx(
12710
+ Tooltip,
12711
+ {
12712
+ content: getFullDate({ date: getValue(), includeTime: true }),
12713
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
12714
+ }
12715
+ );
12716
+ },
12717
+ enableSorting: true,
12718
+ sortAscLabel: "Oldest first",
12719
+ sortDescLabel: "Newest first"
12720
+ }),
12721
+ columnHelper.accessor("created_at", {
12722
+ header: "Created",
12723
+ cell: ({ getValue }) => {
12724
+ return /* @__PURE__ */ jsx(
12725
+ Tooltip,
12726
+ {
12727
+ content: getFullDate({ date: getValue(), includeTime: true }),
12728
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
12729
+ }
12730
+ );
12731
+ },
12732
+ enableSorting: true,
12733
+ sortAscLabel: "Oldest first",
12734
+ sortDescLabel: "Newest first"
12735
+ })
12736
+ ];
12737
+ }, []);
12738
+ };
12739
+ const CustomItemForm = ({ orderId, currencyCode }) => {
12740
+ const { setIsOpen } = useStackedModal();
12741
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
12742
+ const form = useForm({
12743
+ defaultValues: {
12744
+ title: "",
12745
+ quantity: 1,
12746
+ unit_price: ""
12747
+ },
12748
+ resolver: zodResolver(customItemSchema)
12749
+ });
12750
+ const onSubmit = form.handleSubmit(async (data) => {
12751
+ await addItems(
12752
+ {
12753
+ items: [
12971
12754
  {
12972
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12973
- stroke: "#A1A1AA",
12974
- strokeWidth: "1.5",
12975
- strokeLinecap: "round",
12976
- strokeLinejoin: "round"
12755
+ title: data.title,
12756
+ quantity: data.quantity,
12757
+ unit_price: convertNumber(data.unit_price)
12977
12758
  }
12978
- ) }),
12979
- /* @__PURE__ */ jsxs("defs", { children: [
12980
- /* @__PURE__ */ jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsx(
12981
- "rect",
12759
+ ]
12760
+ },
12761
+ {
12762
+ onSuccess: () => {
12763
+ setIsOpen(STACKED_MODAL_ID, false);
12764
+ },
12765
+ onError: (e) => {
12766
+ toast.error(e.message);
12767
+ }
12768
+ }
12769
+ );
12770
+ });
12771
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
12772
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
12773
+ /* @__PURE__ */ jsx(StackedFocusModal.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 px-2 py-16", children: [
12774
+ /* @__PURE__ */ jsxs("div", { children: [
12775
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
12776
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
12777
+ ] }),
12778
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12779
+ /* @__PURE__ */ jsx(
12780
+ Form$2.Field,
12781
+ {
12782
+ control: form.control,
12783
+ name: "title",
12784
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12785
+ /* @__PURE__ */ jsxs("div", { children: [
12786
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
12787
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
12788
+ ] }),
12789
+ /* @__PURE__ */ jsxs("div", { children: [
12790
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12791
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12792
+ ] })
12793
+ ] }) })
12794
+ }
12795
+ ),
12796
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12797
+ /* @__PURE__ */ jsx(
12798
+ Form$2.Field,
12799
+ {
12800
+ control: form.control,
12801
+ name: "unit_price",
12802
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12803
+ /* @__PURE__ */ jsxs("div", { children: [
12804
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
12805
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
12806
+ ] }),
12807
+ /* @__PURE__ */ jsxs("div", { children: [
12808
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12809
+ CurrencyInput,
12810
+ {
12811
+ symbol: getNativeSymbol(currencyCode),
12812
+ code: currencyCode,
12813
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
12814
+ ...field
12815
+ }
12816
+ ) }),
12817
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12818
+ ] })
12819
+ ] }) })
12820
+ }
12821
+ ),
12822
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
12823
+ /* @__PURE__ */ jsx(
12824
+ Form$2.Field,
12825
+ {
12826
+ control: form.control,
12827
+ name: "quantity",
12828
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12829
+ /* @__PURE__ */ jsxs("div", { children: [
12830
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
12831
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
12832
+ ] }),
12833
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
12834
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
12835
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12836
+ ] })
12837
+ ] }) })
12838
+ }
12839
+ )
12840
+ ] }) }) }),
12841
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12842
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12843
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
12844
+ ] }) })
12845
+ ] }) }) });
12846
+ };
12847
+ const customItemSchema = objectType({
12848
+ title: stringType().min(1),
12849
+ quantity: numberType(),
12850
+ unit_price: unionType([numberType(), stringType()])
12851
+ });
12852
+ const BillingAddress = () => {
12853
+ const { id } = useParams();
12854
+ const { order, isPending, isError, error } = useOrder(id, {
12855
+ fields: "+billing_address"
12856
+ });
12857
+ if (isError) {
12858
+ throw error;
12859
+ }
12860
+ const isReady = !isPending && !!order;
12861
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12862
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12863
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12864
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12865
+ ] }),
12866
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12867
+ ] });
12868
+ };
12869
+ const BillingAddressForm = ({ order }) => {
12870
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12871
+ const form = useForm({
12872
+ defaultValues: {
12873
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12874
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12875
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12876
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12877
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12878
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12879
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12880
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12881
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12882
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12883
+ },
12884
+ resolver: zodResolver(schema)
12885
+ });
12886
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12887
+ const { handleSuccess } = useRouteModal();
12888
+ const onSubmit = form.handleSubmit(async (data) => {
12889
+ await mutateAsync(
12890
+ { billing_address: data },
12891
+ {
12892
+ onSuccess: () => {
12893
+ handleSuccess();
12894
+ },
12895
+ onError: (error) => {
12896
+ toast.error(error.message);
12897
+ }
12898
+ }
12899
+ );
12900
+ });
12901
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12902
+ KeyboundForm,
12903
+ {
12904
+ className: "flex flex-1 flex-col overflow-hidden",
12905
+ onSubmit,
12906
+ children: [
12907
+ /* @__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: [
12908
+ /* @__PURE__ */ jsx(
12909
+ Form$2.Field,
12982
12910
  {
12983
- width: "12",
12984
- height: "12",
12985
- fill: "white",
12986
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12911
+ control: form.control,
12912
+ name: "country_code",
12913
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12915
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12916
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
+ ] })
12987
12918
  }
12988
- ) }),
12989
- /* @__PURE__ */ jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsx(
12990
- "rect",
12919
+ ),
12920
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12921
+ /* @__PURE__ */ jsx(
12922
+ Form$2.Field,
12923
+ {
12924
+ control: form.control,
12925
+ name: "first_name",
12926
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12927
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12928
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12929
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12930
+ ] })
12931
+ }
12932
+ ),
12933
+ /* @__PURE__ */ jsx(
12934
+ Form$2.Field,
12935
+ {
12936
+ control: form.control,
12937
+ name: "last_name",
12938
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12940
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
+ ] })
12943
+ }
12944
+ )
12945
+ ] }),
12946
+ /* @__PURE__ */ jsx(
12947
+ Form$2.Field,
12991
12948
  {
12992
- width: "12",
12993
- height: "12",
12994
- fill: "white",
12995
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12949
+ control: form.control,
12950
+ name: "company",
12951
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12952
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12953
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12954
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12955
+ ] })
12996
12956
  }
12997
- ) }),
12998
- /* @__PURE__ */ jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsx(
12999
- "rect",
12957
+ ),
12958
+ /* @__PURE__ */ jsx(
12959
+ Form$2.Field,
13000
12960
  {
13001
- width: "12",
13002
- height: "12",
13003
- fill: "white",
13004
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12961
+ control: form.control,
12962
+ name: "address_1",
12963
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12964
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12965
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12966
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12967
+ ] })
13005
12968
  }
13006
- ) }),
13007
- /* @__PURE__ */ jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsx(
13008
- "rect",
12969
+ ),
12970
+ /* @__PURE__ */ jsx(
12971
+ Form$2.Field,
13009
12972
  {
13010
- width: "12",
13011
- height: "12",
13012
- fill: "white",
13013
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12973
+ control: form.control,
12974
+ name: "address_2",
12975
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12977
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
+ ] })
13014
12980
  }
13015
- ) }),
13016
- /* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
13017
- "rect",
12981
+ ),
12982
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12983
+ /* @__PURE__ */ jsx(
12984
+ Form$2.Field,
12985
+ {
12986
+ control: form.control,
12987
+ name: "postal_code",
12988
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12989
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12990
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12991
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12992
+ ] })
12993
+ }
12994
+ ),
12995
+ /* @__PURE__ */ jsx(
12996
+ Form$2.Field,
12997
+ {
12998
+ control: form.control,
12999
+ name: "city",
13000
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13002
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
+ ] })
13005
+ }
13006
+ )
13007
+ ] }),
13008
+ /* @__PURE__ */ jsx(
13009
+ Form$2.Field,
13018
13010
  {
13019
- width: "12",
13020
- height: "12",
13021
- fill: "white",
13022
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13011
+ control: form.control,
13012
+ name: "province",
13013
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13014
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13015
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13016
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13017
+ ] })
13023
13018
  }
13024
- ) }),
13025
- /* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
13026
- "rect",
13019
+ ),
13020
+ /* @__PURE__ */ jsx(
13021
+ Form$2.Field,
13027
13022
  {
13028
- width: "12",
13029
- height: "12",
13030
- fill: "white",
13031
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13023
+ control: form.control,
13024
+ name: "phone",
13025
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13026
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13027
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13028
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13029
+ ] })
13032
13030
  }
13033
- ) })
13034
- ] })
13031
+ )
13032
+ ] }) }),
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", isLoading: isPending, children: "Save" })
13036
+ ] }) })
13035
13037
  ]
13036
13038
  }
13037
- );
13039
+ ) });
13038
13040
  };
13039
- const schema = objectType({
13040
- customer_id: stringType().min(1)
13041
- });
13041
+ const schema = addressSchema;
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13059,10 +13059,6 @@ const routeModule = {
13059
13059
  handle,
13060
13060
  loader,
13061
13061
  children: [
13062
- {
13063
- Component: BillingAddress,
13064
- path: "/draft-orders/:id/billing-address"
13065
- },
13066
13062
  {
13067
13063
  Component: CustomItems,
13068
13064
  path: "/draft-orders/:id/custom-items"
@@ -13084,20 +13080,24 @@ const routeModule = {
13084
13080
  path: "/draft-orders/:id/sales-channel"
13085
13081
  },
13086
13082
  {
13087
- Component: Items,
13088
- path: "/draft-orders/:id/items"
13083
+ Component: Shipping,
13084
+ path: "/draft-orders/:id/shipping"
13089
13085
  },
13090
13086
  {
13091
13087
  Component: ShippingAddress,
13092
13088
  path: "/draft-orders/:id/shipping-address"
13093
13089
  },
13094
- {
13095
- Component: Shipping,
13096
- path: "/draft-orders/:id/shipping"
13097
- },
13098
13090
  {
13099
13091
  Component: TransferOwnership,
13100
13092
  path: "/draft-orders/:id/transfer-ownership"
13093
+ },
13094
+ {
13095
+ Component: Items,
13096
+ path: "/draft-orders/:id/items"
13097
+ },
13098
+ {
13099
+ Component: BillingAddress,
13100
+ path: "/draft-orders/:id/billing-address"
13101
13101
  }
13102
13102
  ]
13103
13103
  }