@medusajs/draft-order 2.10.2-preview-20250902180202 → 2.10.2-preview-20250902210158

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.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9554,196 +9554,6 @@ const ID = () => {
9554
9554
  /* @__PURE__ */ jsx(Outlet, {})
9555
9555
  ] });
9556
9556
  };
9557
- const BillingAddress = () => {
9558
- const { id } = useParams();
9559
- const { order, isPending, isError, error } = useOrder(id, {
9560
- fields: "+billing_address"
9561
- });
9562
- if (isError) {
9563
- throw error;
9564
- }
9565
- const isReady = !isPending && !!order;
9566
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9567
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9568
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
9569
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9570
- ] }),
9571
- isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
9572
- ] });
9573
- };
9574
- const BillingAddressForm = ({ order }) => {
9575
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9576
- const form = useForm({
9577
- defaultValues: {
9578
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9579
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9580
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9581
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9582
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9583
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9584
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9585
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9586
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9587
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9588
- },
9589
- resolver: zodResolver(schema$5)
9590
- });
9591
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9592
- const { handleSuccess } = useRouteModal();
9593
- const onSubmit = form.handleSubmit(async (data) => {
9594
- await mutateAsync(
9595
- { billing_address: data },
9596
- {
9597
- onSuccess: () => {
9598
- handleSuccess();
9599
- },
9600
- onError: (error) => {
9601
- toast.error(error.message);
9602
- }
9603
- }
9604
- );
9605
- });
9606
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9607
- KeyboundForm,
9608
- {
9609
- className: "flex flex-1 flex-col overflow-hidden",
9610
- onSubmit,
9611
- children: [
9612
- /* @__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: [
9613
- /* @__PURE__ */ jsx(
9614
- Form$2.Field,
9615
- {
9616
- control: form.control,
9617
- name: "country_code",
9618
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9619
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
9620
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
9621
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9622
- ] })
9623
- }
9624
- ),
9625
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9626
- /* @__PURE__ */ jsx(
9627
- Form$2.Field,
9628
- {
9629
- control: form.control,
9630
- name: "first_name",
9631
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9632
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
9633
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9634
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9635
- ] })
9636
- }
9637
- ),
9638
- /* @__PURE__ */ jsx(
9639
- Form$2.Field,
9640
- {
9641
- control: form.control,
9642
- name: "last_name",
9643
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9644
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
9645
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9646
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9647
- ] })
9648
- }
9649
- )
9650
- ] }),
9651
- /* @__PURE__ */ jsx(
9652
- Form$2.Field,
9653
- {
9654
- control: form.control,
9655
- name: "company",
9656
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9657
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
9658
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9659
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9660
- ] })
9661
- }
9662
- ),
9663
- /* @__PURE__ */ jsx(
9664
- Form$2.Field,
9665
- {
9666
- control: form.control,
9667
- name: "address_1",
9668
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9669
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
9670
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9671
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9672
- ] })
9673
- }
9674
- ),
9675
- /* @__PURE__ */ jsx(
9676
- Form$2.Field,
9677
- {
9678
- control: form.control,
9679
- name: "address_2",
9680
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9681
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9682
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9683
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9684
- ] })
9685
- }
9686
- ),
9687
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9688
- /* @__PURE__ */ jsx(
9689
- Form$2.Field,
9690
- {
9691
- control: form.control,
9692
- name: "postal_code",
9693
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9694
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
9695
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9696
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9697
- ] })
9698
- }
9699
- ),
9700
- /* @__PURE__ */ jsx(
9701
- Form$2.Field,
9702
- {
9703
- control: form.control,
9704
- name: "city",
9705
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9706
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
9707
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9708
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9709
- ] })
9710
- }
9711
- )
9712
- ] }),
9713
- /* @__PURE__ */ jsx(
9714
- Form$2.Field,
9715
- {
9716
- control: form.control,
9717
- name: "province",
9718
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9719
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9720
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9721
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9722
- ] })
9723
- }
9724
- ),
9725
- /* @__PURE__ */ jsx(
9726
- Form$2.Field,
9727
- {
9728
- control: form.control,
9729
- name: "phone",
9730
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9731
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
9732
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9733
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9734
- ] })
9735
- }
9736
- )
9737
- ] }) }),
9738
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9739
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9740
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9741
- ] }) })
9742
- ]
9743
- }
9744
- ) });
9745
- };
9746
- const schema$5 = addressSchema;
9747
9557
  const CustomItems = () => {
9748
9558
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9749
9559
  /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
@@ -9752,7 +9562,7 @@ const CustomItems = () => {
9752
9562
  };
9753
9563
  const CustomItemsForm = () => {
9754
9564
  const form = useForm({
9755
- resolver: zodResolver(schema$4)
9565
+ resolver: zodResolver(schema$5)
9756
9566
  });
9757
9567
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9758
9568
  /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
@@ -9762,7 +9572,7 @@ const CustomItemsForm = () => {
9762
9572
  ] }) })
9763
9573
  ] }) });
9764
9574
  };
9765
- const schema$4 = objectType({
9575
+ const schema$5 = objectType({
9766
9576
  email: stringType().email()
9767
9577
  });
9768
9578
  const Email = () => {
@@ -9787,7 +9597,7 @@ const EmailForm = ({ order }) => {
9787
9597
  defaultValues: {
9788
9598
  email: order.email ?? ""
9789
9599
  },
9790
- resolver: zodResolver(schema$3)
9600
+ resolver: zodResolver(schema$4)
9791
9601
  });
9792
9602
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9793
9603
  const { handleSuccess } = useRouteModal();
@@ -9830,269 +9640,619 @@ const EmailForm = ({ order }) => {
9830
9640
  }
9831
9641
  ) });
9832
9642
  };
9833
- const schema$3 = objectType({
9643
+ const schema$4 = objectType({
9834
9644
  email: stringType().email()
9835
9645
  });
9836
- const NumberInput = forwardRef(
9837
- ({
9838
- value,
9839
- onChange,
9840
- size = "base",
9841
- min = 0,
9842
- max = 100,
9843
- step = 1,
9844
- className,
9845
- disabled,
9846
- ...props
9847
- }, ref) => {
9848
- const handleChange = (event) => {
9849
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9850
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9851
- onChange(newValue);
9852
- }
9853
- };
9854
- const handleIncrement = () => {
9855
- const newValue = value + step;
9856
- if (max === void 0 || newValue <= max) {
9857
- onChange(newValue);
9858
- }
9859
- };
9860
- const handleDecrement = () => {
9861
- const newValue = value - step;
9862
- if (min === void 0 || newValue >= min) {
9863
- onChange(newValue);
9864
- }
9865
- };
9646
+ const InlineTip = forwardRef(
9647
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9648
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9866
9649
  return /* @__PURE__ */ jsxs(
9867
9650
  "div",
9868
9651
  {
9652
+ ref,
9869
9653
  className: clx(
9870
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9871
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9872
- {
9873
- "h-7": size === "small",
9874
- "h-8": size === "base"
9875
- },
9654
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9876
9655
  className
9877
9656
  ),
9657
+ ...props,
9878
9658
  children: [
9879
9659
  /* @__PURE__ */ jsx(
9880
- "input",
9660
+ "div",
9881
9661
  {
9882
- ref,
9883
- type: "number",
9884
- value,
9885
- onChange: handleChange,
9886
- min,
9887
- max,
9888
- step,
9889
- className: clx(
9890
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9891
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9892
- "placeholder:text-ui-fg-muted"
9893
- ),
9894
- ...props
9895
- }
9896
- ),
9897
- /* @__PURE__ */ jsxs(
9898
- "button",
9899
- {
9900
- className: clx(
9901
- "flex items-center justify-center outline-none transition-fg",
9902
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9903
- "focus:bg-ui-bg-field-component-hover",
9904
- "hover:bg-ui-bg-field-component-hover",
9905
- {
9906
- "size-7": size === "small",
9907
- "size-8": size === "base"
9908
- }
9909
- ),
9910
- type: "button",
9911
- onClick: handleDecrement,
9912
- disabled: min !== void 0 && value <= min || disabled,
9913
- children: [
9914
- /* @__PURE__ */ jsx(Minus, {}),
9915
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9916
- ]
9662
+ role: "presentation",
9663
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9664
+ "bg-ui-tag-orange-icon": variant === "warning"
9665
+ })
9917
9666
  }
9918
9667
  ),
9919
- /* @__PURE__ */ jsxs(
9920
- "button",
9921
- {
9922
- className: clx(
9923
- "flex items-center justify-center outline-none transition-fg",
9924
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9925
- "focus:bg-ui-bg-field-hover",
9926
- "hover:bg-ui-bg-field-hover",
9927
- {
9928
- "size-7": size === "small",
9929
- "size-8": size === "base"
9930
- }
9931
- ),
9932
- type: "button",
9933
- onClick: handleIncrement,
9934
- disabled: max !== void 0 && value >= max || disabled,
9935
- children: [
9936
- /* @__PURE__ */ jsx(Plus, {}),
9937
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9938
- ]
9939
- }
9940
- )
9668
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9669
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9670
+ labelValue,
9671
+ ":"
9672
+ ] }),
9673
+ " ",
9674
+ children
9675
+ ] })
9941
9676
  ]
9942
9677
  }
9943
9678
  );
9944
9679
  }
9945
9680
  );
9946
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9947
- const productVariantsQueryKeys = {
9948
- list: (query2) => [
9949
- PRODUCT_VARIANTS_QUERY_KEY,
9950
- query2 ? query2 : void 0
9951
- ]
9952
- };
9953
- const useProductVariants = (query2, options) => {
9954
- const { data, ...rest } = useQuery({
9955
- queryKey: productVariantsQueryKeys.list(query2),
9956
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9957
- ...options
9958
- });
9959
- return { ...data, ...rest };
9960
- };
9961
- const useCancelOrderEdit = ({ preview }) => {
9962
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9963
- const onCancel = useCallback(async () => {
9964
- if (!preview) {
9965
- return true;
9966
- }
9967
- let res = false;
9968
- await cancelOrderEdit(void 0, {
9969
- onError: (e) => {
9970
- toast.error(e.message);
9971
- },
9972
- onSuccess: () => {
9973
- res = true;
9974
- }
9975
- });
9976
- return res;
9977
- }, [preview, cancelOrderEdit]);
9978
- return { onCancel };
9979
- };
9980
- let IS_REQUEST_RUNNING = false;
9981
- const useInitiateOrderEdit = ({
9982
- preview
9983
- }) => {
9984
- const navigate = useNavigate();
9985
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9986
- useEffect(() => {
9987
- async function run() {
9988
- if (IS_REQUEST_RUNNING || !preview) {
9989
- return;
9990
- }
9991
- if (preview.order_change) {
9992
- return;
9993
- }
9994
- IS_REQUEST_RUNNING = true;
9995
- await mutateAsync(void 0, {
9996
- onError: (e) => {
9997
- toast.error(e.message);
9998
- navigate(`/draft-orders/${preview.id}`, { replace: true });
9999
- return;
10000
- }
10001
- });
10002
- IS_REQUEST_RUNNING = false;
10003
- }
10004
- run();
10005
- }, [preview, navigate, mutateAsync]);
10006
- };
10007
- function convertNumber(value) {
10008
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10009
- }
10010
- const STACKED_MODAL_ID = "items_stacked_modal";
10011
- const Items = () => {
9681
+ InlineTip.displayName = "InlineTip";
9682
+ const MetadataFieldSchema = objectType({
9683
+ key: stringType(),
9684
+ disabled: booleanType().optional(),
9685
+ value: anyType()
9686
+ });
9687
+ const MetadataSchema = objectType({
9688
+ metadata: arrayType(MetadataFieldSchema)
9689
+ });
9690
+ const Metadata = () => {
10012
9691
  const { id } = useParams();
10013
- const {
10014
- order: preview,
10015
- isPending: isPreviewPending,
10016
- isError: isPreviewError,
10017
- error: previewError
10018
- } = useOrderPreview(id, void 0, {
10019
- placeholderData: keepPreviousData
9692
+ const { order, isPending, isError, error } = useOrder(id, {
9693
+ fields: "metadata"
10020
9694
  });
10021
- useInitiateOrderEdit({ preview });
10022
- const { draft_order, isPending, isError, error } = useDraftOrder(
10023
- id,
10024
- {
10025
- fields: "currency_code"
10026
- },
10027
- {
10028
- enabled: !!id
10029
- }
10030
- );
10031
- const { onCancel } = useCancelOrderEdit({ preview });
10032
9695
  if (isError) {
10033
9696
  throw error;
10034
9697
  }
10035
- if (isPreviewError) {
10036
- throw previewError;
10037
- }
10038
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10039
- return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10040
- /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10041
- /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10042
- ] }) });
9698
+ const isReady = !isPending && !!order;
9699
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9700
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9701
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9702
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9703
+ ] }),
9704
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9705
+ ] });
10043
9706
  };
10044
- const ItemsForm = ({ preview, currencyCode }) => {
10045
- var _a;
10046
- const [isSubmitting, setIsSubmitting] = useState(false);
10047
- const [modalContent, setModalContent] = useState(
10048
- null
10049
- );
9707
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9708
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9709
+ const MetadataForm = ({ orderId, metadata }) => {
10050
9710
  const { handleSuccess } = useRouteModal();
10051
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10052
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10053
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10054
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10055
- const matches = useMemo(() => {
10056
- return matchSorter(preview.items, query2, {
10057
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10058
- });
10059
- }, [preview.items, query2]);
10060
- const onSubmit = async () => {
10061
- setIsSubmitting(true);
10062
- let requestSucceeded = false;
10063
- await requestOrderEdit(void 0, {
10064
- onError: (e) => {
10065
- toast.error(`Failed to request order edit: ${e.message}`);
9711
+ const hasUneditableRows = getHasUneditableRows(metadata);
9712
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9713
+ const form = useForm({
9714
+ defaultValues: {
9715
+ metadata: getDefaultValues(metadata)
9716
+ },
9717
+ resolver: zodResolver(MetadataSchema)
9718
+ });
9719
+ const handleSubmit = form.handleSubmit(async (data) => {
9720
+ const parsedData = parseValues(data);
9721
+ await mutateAsync(
9722
+ {
9723
+ metadata: parsedData
10066
9724
  },
10067
- onSuccess: () => {
10068
- requestSucceeded = true;
9725
+ {
9726
+ onSuccess: () => {
9727
+ toast.success("Metadata updated");
9728
+ handleSuccess();
9729
+ },
9730
+ onError: (error) => {
9731
+ toast.error(error.message);
9732
+ }
10069
9733
  }
10070
- });
10071
- if (!requestSucceeded) {
10072
- setIsSubmitting(false);
10073
- return;
9734
+ );
9735
+ });
9736
+ const { fields, insert, remove } = useFieldArray({
9737
+ control: form.control,
9738
+ name: "metadata"
9739
+ });
9740
+ function deleteRow(index) {
9741
+ remove(index);
9742
+ if (fields.length === 1) {
9743
+ insert(0, {
9744
+ key: "",
9745
+ value: "",
9746
+ disabled: false
9747
+ });
10074
9748
  }
10075
- await confirmOrderEdit(void 0, {
10076
- onError: (e) => {
10077
- toast.error(`Failed to confirm order edit: ${e.message}`);
10078
- },
10079
- onSuccess: () => {
10080
- handleSuccess();
10081
- },
10082
- onSettled: () => {
10083
- setIsSubmitting(false);
10084
- }
9749
+ }
9750
+ function insertRow(index, position) {
9751
+ insert(index + (position === "above" ? 0 : 1), {
9752
+ key: "",
9753
+ value: "",
9754
+ disabled: false
10085
9755
  });
10086
- };
10087
- const onKeyDown = useCallback(
10088
- (e) => {
10089
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10090
- if (modalContent || isSubmitting) {
10091
- return;
10092
- }
10093
- onSubmit();
10094
- }
10095
- },
9756
+ }
9757
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9758
+ KeyboundForm,
9759
+ {
9760
+ onSubmit: handleSubmit,
9761
+ className: "flex flex-1 flex-col overflow-hidden",
9762
+ children: [
9763
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9764
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9765
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9766
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9767
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9768
+ ] }),
9769
+ fields.map((field, index) => {
9770
+ const isDisabled = field.disabled || false;
9771
+ let placeholder = "-";
9772
+ if (typeof field.value === "object") {
9773
+ placeholder = "{ ... }";
9774
+ }
9775
+ if (Array.isArray(field.value)) {
9776
+ placeholder = "[ ... ]";
9777
+ }
9778
+ return /* @__PURE__ */ jsx(
9779
+ ConditionalTooltip,
9780
+ {
9781
+ showTooltip: isDisabled,
9782
+ content: "This row is disabled because it contains non-primitive data.",
9783
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9784
+ /* @__PURE__ */ jsxs(
9785
+ "div",
9786
+ {
9787
+ className: clx("grid grid-cols-2 divide-x", {
9788
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9789
+ }),
9790
+ children: [
9791
+ /* @__PURE__ */ jsx(
9792
+ Form$2.Field,
9793
+ {
9794
+ control: form.control,
9795
+ name: `metadata.${index}.key`,
9796
+ render: ({ field: field2 }) => {
9797
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9798
+ GridInput,
9799
+ {
9800
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9801
+ ...field2,
9802
+ disabled: isDisabled,
9803
+ placeholder: "Key"
9804
+ }
9805
+ ) }) });
9806
+ }
9807
+ }
9808
+ ),
9809
+ /* @__PURE__ */ jsx(
9810
+ Form$2.Field,
9811
+ {
9812
+ control: form.control,
9813
+ name: `metadata.${index}.value`,
9814
+ render: ({ field: { value, ...field2 } }) => {
9815
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
9816
+ GridInput,
9817
+ {
9818
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9819
+ ...field2,
9820
+ value: isDisabled ? placeholder : value,
9821
+ disabled: isDisabled,
9822
+ placeholder: "Value"
9823
+ }
9824
+ ) }) });
9825
+ }
9826
+ }
9827
+ )
9828
+ ]
9829
+ }
9830
+ ),
9831
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
9832
+ /* @__PURE__ */ jsx(
9833
+ DropdownMenu.Trigger,
9834
+ {
9835
+ className: clx(
9836
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9837
+ {
9838
+ hidden: isDisabled
9839
+ }
9840
+ ),
9841
+ disabled: isDisabled,
9842
+ asChild: true,
9843
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
9844
+ }
9845
+ ),
9846
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
9847
+ /* @__PURE__ */ jsxs(
9848
+ DropdownMenu.Item,
9849
+ {
9850
+ className: "gap-x-2",
9851
+ onClick: () => insertRow(index, "above"),
9852
+ children: [
9853
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
9854
+ "Insert row above"
9855
+ ]
9856
+ }
9857
+ ),
9858
+ /* @__PURE__ */ jsxs(
9859
+ DropdownMenu.Item,
9860
+ {
9861
+ className: "gap-x-2",
9862
+ onClick: () => insertRow(index, "below"),
9863
+ children: [
9864
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
9865
+ "Insert row below"
9866
+ ]
9867
+ }
9868
+ ),
9869
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
9870
+ /* @__PURE__ */ jsxs(
9871
+ DropdownMenu.Item,
9872
+ {
9873
+ className: "gap-x-2",
9874
+ onClick: () => deleteRow(index),
9875
+ children: [
9876
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
9877
+ "Delete row"
9878
+ ]
9879
+ }
9880
+ )
9881
+ ] })
9882
+ ] })
9883
+ ] })
9884
+ },
9885
+ field.id
9886
+ );
9887
+ })
9888
+ ] }),
9889
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
9890
+ ] }),
9891
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9892
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9893
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9894
+ ] }) })
9895
+ ]
9896
+ }
9897
+ ) });
9898
+ };
9899
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
9900
+ return /* @__PURE__ */ jsx(
9901
+ "input",
9902
+ {
9903
+ ref,
9904
+ ...props,
9905
+ autoComplete: "off",
9906
+ className: clx(
9907
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
9908
+ className
9909
+ )
9910
+ }
9911
+ );
9912
+ });
9913
+ GridInput.displayName = "MetadataForm.GridInput";
9914
+ const PlaceholderInner = () => {
9915
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9916
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9917
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9918
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
9919
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
9920
+ ] }) })
9921
+ ] });
9922
+ };
9923
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
9924
+ function getDefaultValues(metadata) {
9925
+ if (!metadata || !Object.keys(metadata).length) {
9926
+ return [
9927
+ {
9928
+ key: "",
9929
+ value: "",
9930
+ disabled: false
9931
+ }
9932
+ ];
9933
+ }
9934
+ return Object.entries(metadata).map(([key, value]) => {
9935
+ if (!EDITABLE_TYPES.includes(typeof value)) {
9936
+ return {
9937
+ key,
9938
+ value,
9939
+ disabled: true
9940
+ };
9941
+ }
9942
+ let stringValue = value;
9943
+ if (typeof value !== "string") {
9944
+ stringValue = JSON.stringify(value);
9945
+ }
9946
+ return {
9947
+ key,
9948
+ value: stringValue,
9949
+ original_key: key
9950
+ };
9951
+ });
9952
+ }
9953
+ function parseValues(values) {
9954
+ const metadata = values.metadata;
9955
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9956
+ if (isEmpty) {
9957
+ return null;
9958
+ }
9959
+ const update = {};
9960
+ metadata.forEach((field) => {
9961
+ let key = field.key;
9962
+ let value = field.value;
9963
+ const disabled = field.disabled;
9964
+ if (!key || !value) {
9965
+ return;
9966
+ }
9967
+ if (disabled) {
9968
+ update[key] = value;
9969
+ return;
9970
+ }
9971
+ key = key.trim();
9972
+ value = value.trim();
9973
+ if (value === "true") {
9974
+ update[key] = true;
9975
+ } else if (value === "false") {
9976
+ update[key] = false;
9977
+ } else {
9978
+ const parsedNumber = parseFloat(value);
9979
+ if (!isNaN(parsedNumber)) {
9980
+ update[key] = parsedNumber;
9981
+ } else {
9982
+ update[key] = value;
9983
+ }
9984
+ }
9985
+ });
9986
+ return update;
9987
+ }
9988
+ function getHasUneditableRows(metadata) {
9989
+ if (!metadata) {
9990
+ return false;
9991
+ }
9992
+ return Object.values(metadata).some(
9993
+ (value) => !EDITABLE_TYPES.includes(typeof value)
9994
+ );
9995
+ }
9996
+ const NumberInput = forwardRef(
9997
+ ({
9998
+ value,
9999
+ onChange,
10000
+ size = "base",
10001
+ min = 0,
10002
+ max = 100,
10003
+ step = 1,
10004
+ className,
10005
+ disabled,
10006
+ ...props
10007
+ }, ref) => {
10008
+ const handleChange = (event) => {
10009
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10010
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10011
+ onChange(newValue);
10012
+ }
10013
+ };
10014
+ const handleIncrement = () => {
10015
+ const newValue = value + step;
10016
+ if (max === void 0 || newValue <= max) {
10017
+ onChange(newValue);
10018
+ }
10019
+ };
10020
+ const handleDecrement = () => {
10021
+ const newValue = value - step;
10022
+ if (min === void 0 || newValue >= min) {
10023
+ onChange(newValue);
10024
+ }
10025
+ };
10026
+ return /* @__PURE__ */ jsxs(
10027
+ "div",
10028
+ {
10029
+ className: clx(
10030
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10031
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10032
+ {
10033
+ "h-7": size === "small",
10034
+ "h-8": size === "base"
10035
+ },
10036
+ className
10037
+ ),
10038
+ children: [
10039
+ /* @__PURE__ */ jsx(
10040
+ "input",
10041
+ {
10042
+ ref,
10043
+ type: "number",
10044
+ value,
10045
+ onChange: handleChange,
10046
+ min,
10047
+ max,
10048
+ step,
10049
+ className: clx(
10050
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10051
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10052
+ "placeholder:text-ui-fg-muted"
10053
+ ),
10054
+ ...props
10055
+ }
10056
+ ),
10057
+ /* @__PURE__ */ jsxs(
10058
+ "button",
10059
+ {
10060
+ className: clx(
10061
+ "flex items-center justify-center outline-none transition-fg",
10062
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10063
+ "focus:bg-ui-bg-field-component-hover",
10064
+ "hover:bg-ui-bg-field-component-hover",
10065
+ {
10066
+ "size-7": size === "small",
10067
+ "size-8": size === "base"
10068
+ }
10069
+ ),
10070
+ type: "button",
10071
+ onClick: handleDecrement,
10072
+ disabled: min !== void 0 && value <= min || disabled,
10073
+ children: [
10074
+ /* @__PURE__ */ jsx(Minus, {}),
10075
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10076
+ ]
10077
+ }
10078
+ ),
10079
+ /* @__PURE__ */ jsxs(
10080
+ "button",
10081
+ {
10082
+ className: clx(
10083
+ "flex items-center justify-center outline-none transition-fg",
10084
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10085
+ "focus:bg-ui-bg-field-hover",
10086
+ "hover:bg-ui-bg-field-hover",
10087
+ {
10088
+ "size-7": size === "small",
10089
+ "size-8": size === "base"
10090
+ }
10091
+ ),
10092
+ type: "button",
10093
+ onClick: handleIncrement,
10094
+ disabled: max !== void 0 && value >= max || disabled,
10095
+ children: [
10096
+ /* @__PURE__ */ jsx(Plus, {}),
10097
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10098
+ ]
10099
+ }
10100
+ )
10101
+ ]
10102
+ }
10103
+ );
10104
+ }
10105
+ );
10106
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10107
+ const productVariantsQueryKeys = {
10108
+ list: (query2) => [
10109
+ PRODUCT_VARIANTS_QUERY_KEY,
10110
+ query2 ? query2 : void 0
10111
+ ]
10112
+ };
10113
+ const useProductVariants = (query2, options) => {
10114
+ const { data, ...rest } = useQuery({
10115
+ queryKey: productVariantsQueryKeys.list(query2),
10116
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10117
+ ...options
10118
+ });
10119
+ return { ...data, ...rest };
10120
+ };
10121
+ const useCancelOrderEdit = ({ preview }) => {
10122
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10123
+ const onCancel = useCallback(async () => {
10124
+ if (!preview) {
10125
+ return true;
10126
+ }
10127
+ let res = false;
10128
+ await cancelOrderEdit(void 0, {
10129
+ onError: (e) => {
10130
+ toast.error(e.message);
10131
+ },
10132
+ onSuccess: () => {
10133
+ res = true;
10134
+ }
10135
+ });
10136
+ return res;
10137
+ }, [preview, cancelOrderEdit]);
10138
+ return { onCancel };
10139
+ };
10140
+ let IS_REQUEST_RUNNING = false;
10141
+ const useInitiateOrderEdit = ({
10142
+ preview
10143
+ }) => {
10144
+ const navigate = useNavigate();
10145
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10146
+ useEffect(() => {
10147
+ async function run() {
10148
+ if (IS_REQUEST_RUNNING || !preview) {
10149
+ return;
10150
+ }
10151
+ if (preview.order_change) {
10152
+ return;
10153
+ }
10154
+ IS_REQUEST_RUNNING = true;
10155
+ await mutateAsync(void 0, {
10156
+ onError: (e) => {
10157
+ toast.error(e.message);
10158
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10159
+ return;
10160
+ }
10161
+ });
10162
+ IS_REQUEST_RUNNING = false;
10163
+ }
10164
+ run();
10165
+ }, [preview, navigate, mutateAsync]);
10166
+ };
10167
+ function convertNumber(value) {
10168
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10169
+ }
10170
+ const STACKED_MODAL_ID = "items_stacked_modal";
10171
+ const Items = () => {
10172
+ const { id } = useParams();
10173
+ const {
10174
+ order: preview,
10175
+ isPending: isPreviewPending,
10176
+ isError: isPreviewError,
10177
+ error: previewError
10178
+ } = useOrderPreview(id, void 0, {
10179
+ placeholderData: keepPreviousData
10180
+ });
10181
+ useInitiateOrderEdit({ preview });
10182
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10183
+ id,
10184
+ {
10185
+ fields: "currency_code"
10186
+ },
10187
+ {
10188
+ enabled: !!id
10189
+ }
10190
+ );
10191
+ const { onCancel } = useCancelOrderEdit({ preview });
10192
+ if (isError) {
10193
+ throw error;
10194
+ }
10195
+ if (isPreviewError) {
10196
+ throw previewError;
10197
+ }
10198
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10199
+ return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
10200
+ /* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10201
+ /* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10202
+ ] }) });
10203
+ };
10204
+ const ItemsForm = ({ preview, currencyCode }) => {
10205
+ var _a;
10206
+ const [isSubmitting, setIsSubmitting] = useState(false);
10207
+ const [modalContent, setModalContent] = useState(
10208
+ null
10209
+ );
10210
+ const { handleSuccess } = useRouteModal();
10211
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10212
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10213
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10214
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10215
+ const matches = useMemo(() => {
10216
+ return matchSorter(preview.items, query2, {
10217
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10218
+ });
10219
+ }, [preview.items, query2]);
10220
+ const onSubmit = async () => {
10221
+ setIsSubmitting(true);
10222
+ let requestSucceeded = false;
10223
+ await requestOrderEdit(void 0, {
10224
+ onError: (e) => {
10225
+ toast.error(`Failed to request order edit: ${e.message}`);
10226
+ },
10227
+ onSuccess: () => {
10228
+ requestSucceeded = true;
10229
+ }
10230
+ });
10231
+ if (!requestSucceeded) {
10232
+ setIsSubmitting(false);
10233
+ return;
10234
+ }
10235
+ await confirmOrderEdit(void 0, {
10236
+ onError: (e) => {
10237
+ toast.error(`Failed to confirm order edit: ${e.message}`);
10238
+ },
10239
+ onSuccess: () => {
10240
+ handleSuccess();
10241
+ },
10242
+ onSettled: () => {
10243
+ setIsSubmitting(false);
10244
+ }
10245
+ });
10246
+ };
10247
+ const onKeyDown = useCallback(
10248
+ (e) => {
10249
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10250
+ if (modalContent || isSubmitting) {
10251
+ return;
10252
+ }
10253
+ onSubmit();
10254
+ }
10255
+ },
10096
10256
  [modalContent, isSubmitting, onSubmit]
10097
10257
  );
10098
10258
  useEffect(() => {
@@ -10251,155 +10411,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10251
10411
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10252
10412
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10253
10413
  const onSubmit = form.handleSubmit(async (data) => {
10254
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10255
- setEditing(false);
10256
- return;
10257
- }
10258
- if (!actionId) {
10259
- await updateOriginalItem(
10260
- {
10261
- item_id: item.id,
10262
- quantity: data.quantity,
10263
- unit_price: convertNumber(data.unit_price)
10264
- },
10265
- {
10266
- onSuccess: () => {
10267
- setEditing(false);
10268
- },
10269
- onError: (e) => {
10270
- toast.error(e.message);
10271
- }
10272
- }
10273
- );
10274
- return;
10275
- }
10276
- await updateActionItem(
10277
- {
10278
- action_id: actionId,
10279
- quantity: data.quantity,
10280
- unit_price: convertNumber(data.unit_price)
10281
- },
10282
- {
10283
- onSuccess: () => {
10284
- setEditing(false);
10285
- },
10286
- onError: (e) => {
10287
- toast.error(e.message);
10288
- }
10289
- }
10290
- );
10291
- });
10292
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10293
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
10294
- /* @__PURE__ */ jsx(
10295
- Thumbnail,
10296
- {
10297
- thumbnail: item.thumbnail,
10298
- alt: item.product_title ?? void 0
10299
- }
10300
- ),
10301
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10302
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10303
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10304
- /* @__PURE__ */ jsxs(
10305
- Text,
10306
- {
10307
- size: "small",
10308
- leading: "compact",
10309
- className: "text-ui-fg-subtle",
10310
- children: [
10311
- "(",
10312
- item.variant_title,
10313
- ")"
10314
- ]
10315
- }
10316
- )
10317
- ] }),
10318
- /* @__PURE__ */ jsx(
10319
- Text,
10320
- {
10321
- size: "small",
10322
- leading: "compact",
10323
- className: "text-ui-fg-subtle",
10324
- children: item.variant_sku
10325
- }
10326
- )
10327
- ] })
10328
- ] }),
10329
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10330
- Form$2.Field,
10331
- {
10332
- control: form.control,
10333
- name: "quantity",
10334
- render: ({ field }) => {
10335
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10336
- }
10337
- }
10338
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10339
- editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10340
- Form$2.Field,
10341
- {
10342
- control: form.control,
10343
- name: "unit_price",
10344
- render: ({ field: { onChange, ...field } }) => {
10345
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10346
- CurrencyInput,
10347
- {
10348
- ...field,
10349
- symbol: getNativeSymbol(currencyCode),
10350
- code: currencyCode,
10351
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10352
- }
10353
- ) }) });
10354
- }
10355
- }
10356
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10357
- /* @__PURE__ */ jsx(
10358
- IconButton,
10359
- {
10360
- type: "button",
10361
- size: "small",
10362
- onClick: editing ? onSubmit : () => {
10363
- setEditing(true);
10364
- },
10365
- disabled: isPending,
10366
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10367
- }
10368
- )
10369
- ] }) }) });
10370
- };
10371
- const variantItemSchema = objectType({
10372
- quantity: numberType(),
10373
- unit_price: unionType([numberType(), stringType()])
10374
- });
10375
- const CustomItem = ({ item, preview, currencyCode }) => {
10376
- const [editing, setEditing] = useState(false);
10377
- const { quantity, unit_price, title } = item;
10378
- const form = useForm({
10379
- defaultValues: {
10380
- title,
10381
- quantity,
10382
- unit_price
10383
- },
10384
- resolver: zodResolver(customItemSchema)
10385
- });
10386
- useEffect(() => {
10387
- form.reset({
10388
- title,
10389
- quantity,
10390
- unit_price
10391
- });
10392
- }, [form, title, quantity, unit_price]);
10393
- const actionId = useMemo(() => {
10394
- var _a, _b;
10395
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10396
- }, [item]);
10397
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10398
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10399
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10400
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10401
- const onSubmit = form.handleSubmit(async (data) => {
10402
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10414
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10403
10415
  setEditing(false);
10404
10416
  return;
10405
10417
  }
@@ -10421,17 +10433,6 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10421
10433
  );
10422
10434
  return;
10423
10435
  }
10424
- if (data.quantity === 0) {
10425
- await removeActionItem(actionId, {
10426
- onSuccess: () => {
10427
- setEditing(false);
10428
- },
10429
- onError: (e) => {
10430
- toast.error(e.message);
10431
- }
10432
- });
10433
- return;
10434
- }
10435
10436
  await updateActionItem(
10436
10437
  {
10437
10438
  action_id: actionId,
@@ -10449,26 +10450,43 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10449
10450
  );
10450
10451
  });
10451
10452
  return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10452
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10453
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
10453
10454
  /* @__PURE__ */ jsx(
10454
10455
  Thumbnail,
10455
10456
  {
10456
10457
  thumbnail: item.thumbnail,
10457
- alt: item.title ?? void 0
10458
+ alt: item.product_title ?? void 0
10458
10459
  }
10459
10460
  ),
10460
- editing ? /* @__PURE__ */ jsx(
10461
- Form$2.Field,
10462
- {
10463
- control: form.control,
10464
- name: "title",
10465
- render: ({ field }) => {
10466
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10461
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10462
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10463
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10464
+ /* @__PURE__ */ jsxs(
10465
+ Text,
10466
+ {
10467
+ size: "small",
10468
+ leading: "compact",
10469
+ className: "text-ui-fg-subtle",
10470
+ children: [
10471
+ "(",
10472
+ item.variant_title,
10473
+ ")"
10474
+ ]
10475
+ }
10476
+ )
10477
+ ] }),
10478
+ /* @__PURE__ */ jsx(
10479
+ Text,
10480
+ {
10481
+ size: "small",
10482
+ leading: "compact",
10483
+ className: "text-ui-fg-subtle",
10484
+ children: item.variant_sku
10467
10485
  }
10468
- }
10469
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10486
+ )
10487
+ ] })
10470
10488
  ] }),
10471
- editing ? /* @__PURE__ */ jsx(
10489
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10472
10490
  Form$2.Field,
10473
10491
  {
10474
10492
  control: form.control,
@@ -10477,8 +10495,8 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10477
10495
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10478
10496
  }
10479
10497
  }
10480
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10481
- editing ? /* @__PURE__ */ jsx(
10498
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10499
+ editing ? /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(
10482
10500
  Form$2.Field,
10483
10501
  {
10484
10502
  control: form.control,
@@ -10495,230 +10513,94 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10495
10513
  ) }) });
10496
10514
  }
10497
10515
  }
10498
- ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10516
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10499
10517
  /* @__PURE__ */ jsx(
10500
10518
  IconButton,
10501
- {
10502
- type: "button",
10503
- size: "small",
10504
- onClick: editing ? onSubmit : () => {
10505
- setEditing(true);
10506
- },
10507
- disabled: isPending,
10508
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10509
- }
10510
- )
10511
- ] }) }) });
10512
- };
10513
- const StackedModalTrigger$1 = ({
10514
- type,
10515
- setModalContent
10516
- }) => {
10517
- const { setIsOpen } = useStackedModal();
10518
- const onClick = useCallback(() => {
10519
- setModalContent(type);
10520
- setIsOpen(STACKED_MODAL_ID, true);
10521
- }, [setModalContent, setIsOpen, type]);
10522
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10523
- };
10524
- const VARIANT_PREFIX = "items";
10525
- const LIMIT = 50;
10526
- const ExistingItemsForm = ({ orderId, items }) => {
10527
- const { setIsOpen } = useStackedModal();
10528
- const [rowSelection, setRowSelection] = useState(
10529
- items.reduce((acc, item) => {
10530
- acc[item.variant_id] = true;
10531
- return acc;
10532
- }, {})
10533
- );
10534
- useEffect(() => {
10535
- setRowSelection(
10536
- items.reduce((acc, item) => {
10537
- if (item.variant_id) {
10538
- acc[item.variant_id] = true;
10539
- }
10540
- return acc;
10541
- }, {})
10542
- );
10543
- }, [items]);
10544
- const { q, order, offset } = useQueryParams(
10545
- ["q", "order", "offset"],
10546
- VARIANT_PREFIX
10547
- );
10548
- const { variants, count, isPending, isError, error } = useProductVariants(
10549
- {
10550
- q,
10551
- order,
10552
- offset: offset ? parseInt(offset) : void 0,
10553
- limit: LIMIT
10554
- },
10555
- {
10556
- placeholderData: keepPreviousData
10557
- }
10558
- );
10559
- const columns = useColumns();
10560
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10561
- const onSubmit = async () => {
10562
- const ids = Object.keys(rowSelection).filter(
10563
- (id) => !items.find((i) => i.variant_id === id)
10564
- );
10565
- await mutateAsync(
10566
- {
10567
- items: ids.map((id) => ({
10568
- variant_id: id,
10569
- quantity: 1
10570
- }))
10571
- },
10572
- {
10573
- onSuccess: () => {
10574
- setRowSelection({});
10575
- setIsOpen(STACKED_MODAL_ID, false);
10576
- },
10577
- onError: (e) => {
10578
- toast.error(e.message);
10579
- }
10580
- }
10581
- );
10582
- };
10583
- if (isError) {
10584
- throw error;
10585
- }
10586
- return /* @__PURE__ */ jsxs(
10587
- StackedFocusModal.Content,
10588
- {
10589
- onOpenAutoFocus: (e) => {
10590
- e.preventDefault();
10591
- const searchInput = document.querySelector(
10592
- "[data-modal-id='modal-search-input']"
10593
- );
10594
- if (searchInput) {
10595
- searchInput.focus();
10596
- }
10597
- },
10598
- children: [
10599
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10600
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10601
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10602
- ] }),
10603
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10604
- DataTable,
10605
- {
10606
- data: variants,
10607
- columns,
10608
- isLoading: isPending,
10609
- getRowId: (row) => row.id,
10610
- rowCount: count,
10611
- prefix: VARIANT_PREFIX,
10612
- layout: "fill",
10613
- rowSelection: {
10614
- state: rowSelection,
10615
- onRowSelectionChange: setRowSelection,
10616
- enableRowSelection: (row) => {
10617
- return !items.find((i) => i.variant_id === row.original.id);
10618
- }
10619
- },
10620
- autoFocusSearch: true
10621
- }
10622
- ) }),
10623
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10624
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10625
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10626
- ] }) })
10627
- ]
10628
- }
10629
- );
10630
- };
10631
- const columnHelper = createDataTableColumnHelper();
10632
- const useColumns = () => {
10633
- return useMemo(() => {
10634
- return [
10635
- columnHelper.select(),
10636
- columnHelper.accessor("product.title", {
10637
- header: "Product",
10638
- cell: ({ row }) => {
10639
- var _a, _b, _c;
10640
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10641
- /* @__PURE__ */ jsx(
10642
- Thumbnail,
10643
- {
10644
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10645
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10646
- }
10647
- ),
10648
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10649
- ] });
10650
- },
10651
- enableSorting: true
10652
- }),
10653
- columnHelper.accessor("title", {
10654
- header: "Variant",
10655
- enableSorting: true
10656
- }),
10657
- columnHelper.accessor("sku", {
10658
- header: "SKU",
10659
- cell: ({ getValue }) => {
10660
- return getValue() ?? "-";
10661
- },
10662
- enableSorting: true
10663
- }),
10664
- columnHelper.accessor("updated_at", {
10665
- header: "Updated",
10666
- cell: ({ getValue }) => {
10667
- return /* @__PURE__ */ jsx(
10668
- Tooltip,
10669
- {
10670
- content: getFullDate({ date: getValue(), includeTime: true }),
10671
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10672
- }
10673
- );
10674
- },
10675
- enableSorting: true,
10676
- sortAscLabel: "Oldest first",
10677
- sortDescLabel: "Newest first"
10678
- }),
10679
- columnHelper.accessor("created_at", {
10680
- header: "Created",
10681
- cell: ({ getValue }) => {
10682
- return /* @__PURE__ */ jsx(
10683
- Tooltip,
10684
- {
10685
- content: getFullDate({ date: getValue(), includeTime: true }),
10686
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10687
- }
10688
- );
10519
+ {
10520
+ type: "button",
10521
+ size: "small",
10522
+ onClick: editing ? onSubmit : () => {
10523
+ setEditing(true);
10689
10524
  },
10690
- enableSorting: true,
10691
- sortAscLabel: "Oldest first",
10692
- sortDescLabel: "Newest first"
10693
- })
10694
- ];
10695
- }, []);
10525
+ disabled: isPending,
10526
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10527
+ }
10528
+ )
10529
+ ] }) }) });
10696
10530
  };
10697
- const CustomItemForm = ({ orderId, currencyCode }) => {
10698
- const { setIsOpen } = useStackedModal();
10699
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10531
+ const variantItemSchema = objectType({
10532
+ quantity: numberType(),
10533
+ unit_price: unionType([numberType(), stringType()])
10534
+ });
10535
+ const CustomItem = ({ item, preview, currencyCode }) => {
10536
+ const [editing, setEditing] = useState(false);
10537
+ const { quantity, unit_price, title } = item;
10700
10538
  const form = useForm({
10701
10539
  defaultValues: {
10702
- title: "",
10703
- quantity: 1,
10704
- unit_price: ""
10540
+ title,
10541
+ quantity,
10542
+ unit_price
10705
10543
  },
10706
10544
  resolver: zodResolver(customItemSchema)
10707
10545
  });
10546
+ useEffect(() => {
10547
+ form.reset({
10548
+ title,
10549
+ quantity,
10550
+ unit_price
10551
+ });
10552
+ }, [form, title, quantity, unit_price]);
10553
+ const actionId = useMemo(() => {
10554
+ var _a, _b;
10555
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10556
+ }, [item]);
10557
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10558
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10559
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10560
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10708
10561
  const onSubmit = form.handleSubmit(async (data) => {
10709
- await addItems(
10710
- {
10711
- items: [
10712
- {
10713
- title: data.title,
10714
- quantity: data.quantity,
10715
- unit_price: convertNumber(data.unit_price)
10562
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10563
+ setEditing(false);
10564
+ return;
10565
+ }
10566
+ if (!actionId) {
10567
+ await updateOriginalItem(
10568
+ {
10569
+ item_id: item.id,
10570
+ quantity: data.quantity,
10571
+ unit_price: convertNumber(data.unit_price)
10572
+ },
10573
+ {
10574
+ onSuccess: () => {
10575
+ setEditing(false);
10576
+ },
10577
+ onError: (e) => {
10578
+ toast.error(e.message);
10716
10579
  }
10717
- ]
10580
+ }
10581
+ );
10582
+ return;
10583
+ }
10584
+ if (data.quantity === 0) {
10585
+ await removeActionItem(actionId, {
10586
+ onSuccess: () => {
10587
+ setEditing(false);
10588
+ },
10589
+ onError: (e) => {
10590
+ toast.error(e.message);
10591
+ }
10592
+ });
10593
+ return;
10594
+ }
10595
+ await updateActionItem(
10596
+ {
10597
+ action_id: actionId,
10598
+ quantity: data.quantity,
10599
+ unit_price: convertNumber(data.unit_price)
10718
10600
  },
10719
10601
  {
10720
10602
  onSuccess: () => {
10721
- setIsOpen(STACKED_MODAL_ID, false);
10603
+ setEditing(false);
10722
10604
  },
10723
10605
  onError: (e) => {
10724
10606
  toast.error(e.message);
@@ -10726,437 +10608,365 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10726
10608
  }
10727
10609
  );
10728
10610
  });
10729
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10730
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10731
- /* @__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: [
10732
- /* @__PURE__ */ jsxs("div", { children: [
10733
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10734
- /* @__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." }) })
10735
- ] }),
10736
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10611
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10612
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10737
10613
  /* @__PURE__ */ jsx(
10738
- Form$2.Field,
10614
+ Thumbnail,
10739
10615
  {
10740
- control: form.control,
10741
- name: "title",
10742
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10743
- /* @__PURE__ */ jsxs("div", { children: [
10744
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10745
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10746
- ] }),
10747
- /* @__PURE__ */ jsxs("div", { children: [
10748
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10749
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10750
- ] })
10751
- ] }) })
10616
+ thumbnail: item.thumbnail,
10617
+ alt: item.title ?? void 0
10752
10618
  }
10753
10619
  ),
10754
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10755
- /* @__PURE__ */ jsx(
10620
+ editing ? /* @__PURE__ */ jsx(
10756
10621
  Form$2.Field,
10757
10622
  {
10758
10623
  control: form.control,
10759
- name: "unit_price",
10760
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10761
- /* @__PURE__ */ jsxs("div", { children: [
10762
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10763
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10764
- ] }),
10765
- /* @__PURE__ */ jsxs("div", { children: [
10766
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10767
- CurrencyInput,
10768
- {
10769
- symbol: getNativeSymbol(currencyCode),
10770
- code: currencyCode,
10771
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10772
- ...field
10773
- }
10774
- ) }),
10775
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10776
- ] })
10777
- ] }) })
10624
+ name: "title",
10625
+ render: ({ field }) => {
10626
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
10627
+ }
10778
10628
  }
10779
- ),
10780
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10781
- /* @__PURE__ */ jsx(
10782
- Form$2.Field,
10783
- {
10784
- control: form.control,
10785
- name: "quantity",
10786
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10787
- /* @__PURE__ */ jsxs("div", { children: [
10788
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10789
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10790
- ] }),
10791
- /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
10792
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10793
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10794
- ] })
10795
- ] }) })
10629
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
10630
+ ] }),
10631
+ editing ? /* @__PURE__ */ jsx(
10632
+ Form$2.Field,
10633
+ {
10634
+ control: form.control,
10635
+ name: "quantity",
10636
+ render: ({ field }) => {
10637
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10796
10638
  }
10797
- )
10798
- ] }) }) }),
10799
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10800
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10801
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10802
- ] }) })
10803
- ] }) }) });
10804
- };
10805
- const customItemSchema = objectType({
10806
- title: stringType().min(1),
10807
- quantity: numberType(),
10808
- unit_price: unionType([numberType(), stringType()])
10809
- });
10810
- const InlineTip = forwardRef(
10811
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10812
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10813
- return /* @__PURE__ */ jsxs(
10814
- "div",
10639
+ }
10640
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10641
+ editing ? /* @__PURE__ */ jsx(
10642
+ Form$2.Field,
10815
10643
  {
10816
- ref,
10817
- className: clx(
10818
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10819
- className
10820
- ),
10821
- ...props,
10822
- children: [
10823
- /* @__PURE__ */ jsx(
10824
- "div",
10644
+ control: form.control,
10645
+ name: "unit_price",
10646
+ render: ({ field: { onChange, ...field } }) => {
10647
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10648
+ CurrencyInput,
10825
10649
  {
10826
- role: "presentation",
10827
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10828
- "bg-ui-tag-orange-icon": variant === "warning"
10829
- })
10650
+ ...field,
10651
+ symbol: getNativeSymbol(currencyCode),
10652
+ code: currencyCode,
10653
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10830
10654
  }
10831
- ),
10832
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10833
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10834
- labelValue,
10835
- ":"
10836
- ] }),
10837
- " ",
10838
- children
10839
- ] })
10840
- ]
10841
- }
10842
- );
10843
- }
10844
- );
10845
- InlineTip.displayName = "InlineTip";
10846
- const MetadataFieldSchema = objectType({
10847
- key: stringType(),
10848
- disabled: booleanType().optional(),
10849
- value: anyType()
10850
- });
10851
- const MetadataSchema = objectType({
10852
- metadata: arrayType(MetadataFieldSchema)
10853
- });
10854
- const Metadata = () => {
10855
- const { id } = useParams();
10856
- const { order, isPending, isError, error } = useOrder(id, {
10857
- fields: "metadata"
10858
- });
10859
- if (isError) {
10860
- throw error;
10861
- }
10862
- const isReady = !isPending && !!order;
10863
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10864
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10865
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10866
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10867
- ] }),
10868
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10869
- ] });
10655
+ ) }) });
10656
+ }
10657
+ }
10658
+ ) : /* @__PURE__ */ jsx("div", { className: "flex-1 flex items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10659
+ /* @__PURE__ */ jsx(
10660
+ IconButton,
10661
+ {
10662
+ type: "button",
10663
+ size: "small",
10664
+ onClick: editing ? onSubmit : () => {
10665
+ setEditing(true);
10666
+ },
10667
+ disabled: isPending,
10668
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10669
+ }
10670
+ )
10671
+ ] }) }) });
10870
10672
  };
10871
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10872
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10873
- const MetadataForm = ({ orderId, metadata }) => {
10874
- const { handleSuccess } = useRouteModal();
10875
- const hasUneditableRows = getHasUneditableRows(metadata);
10876
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10877
- const form = useForm({
10878
- defaultValues: {
10879
- metadata: getDefaultValues(metadata)
10673
+ const StackedModalTrigger$1 = ({
10674
+ type,
10675
+ setModalContent
10676
+ }) => {
10677
+ const { setIsOpen } = useStackedModal();
10678
+ const onClick = useCallback(() => {
10679
+ setModalContent(type);
10680
+ setIsOpen(STACKED_MODAL_ID, true);
10681
+ }, [setModalContent, setIsOpen, type]);
10682
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10683
+ };
10684
+ const VARIANT_PREFIX = "items";
10685
+ const LIMIT = 50;
10686
+ const ExistingItemsForm = ({ orderId, items }) => {
10687
+ const { setIsOpen } = useStackedModal();
10688
+ const [rowSelection, setRowSelection] = useState(
10689
+ items.reduce((acc, item) => {
10690
+ acc[item.variant_id] = true;
10691
+ return acc;
10692
+ }, {})
10693
+ );
10694
+ useEffect(() => {
10695
+ setRowSelection(
10696
+ items.reduce((acc, item) => {
10697
+ if (item.variant_id) {
10698
+ acc[item.variant_id] = true;
10699
+ }
10700
+ return acc;
10701
+ }, {})
10702
+ );
10703
+ }, [items]);
10704
+ const { q, order, offset } = useQueryParams(
10705
+ ["q", "order", "offset"],
10706
+ VARIANT_PREFIX
10707
+ );
10708
+ const { variants, count, isPending, isError, error } = useProductVariants(
10709
+ {
10710
+ q,
10711
+ order,
10712
+ offset: offset ? parseInt(offset) : void 0,
10713
+ limit: LIMIT
10880
10714
  },
10881
- resolver: zodResolver(MetadataSchema)
10882
- });
10883
- const handleSubmit = form.handleSubmit(async (data) => {
10884
- const parsedData = parseValues(data);
10715
+ {
10716
+ placeholderData: keepPreviousData
10717
+ }
10718
+ );
10719
+ const columns = useColumns();
10720
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10721
+ const onSubmit = async () => {
10722
+ const ids = Object.keys(rowSelection).filter(
10723
+ (id) => !items.find((i) => i.variant_id === id)
10724
+ );
10885
10725
  await mutateAsync(
10886
10726
  {
10887
- metadata: parsedData
10727
+ items: ids.map((id) => ({
10728
+ variant_id: id,
10729
+ quantity: 1
10730
+ }))
10888
10731
  },
10889
10732
  {
10890
10733
  onSuccess: () => {
10891
- toast.success("Metadata updated");
10892
- handleSuccess();
10734
+ setRowSelection({});
10735
+ setIsOpen(STACKED_MODAL_ID, false);
10893
10736
  },
10894
- onError: (error) => {
10895
- toast.error(error.message);
10737
+ onError: (e) => {
10738
+ toast.error(e.message);
10896
10739
  }
10897
10740
  }
10898
10741
  );
10899
- });
10900
- const { fields, insert, remove } = useFieldArray({
10901
- control: form.control,
10902
- name: "metadata"
10903
- });
10904
- function deleteRow(index) {
10905
- remove(index);
10906
- if (fields.length === 1) {
10907
- insert(0, {
10908
- key: "",
10909
- value: "",
10910
- disabled: false
10911
- });
10912
- }
10913
- }
10914
- function insertRow(index, position) {
10915
- insert(index + (position === "above" ? 0 : 1), {
10916
- key: "",
10917
- value: "",
10918
- disabled: false
10919
- });
10742
+ };
10743
+ if (isError) {
10744
+ throw error;
10920
10745
  }
10921
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10922
- KeyboundForm,
10746
+ return /* @__PURE__ */ jsxs(
10747
+ StackedFocusModal.Content,
10923
10748
  {
10924
- onSubmit: handleSubmit,
10925
- className: "flex flex-1 flex-col overflow-hidden",
10926
- children: [
10927
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10928
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10929
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10930
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10931
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10932
- ] }),
10933
- fields.map((field, index) => {
10934
- const isDisabled = field.disabled || false;
10935
- let placeholder = "-";
10936
- if (typeof field.value === "object") {
10937
- placeholder = "{ ... }";
10938
- }
10939
- if (Array.isArray(field.value)) {
10940
- placeholder = "[ ... ]";
10941
- }
10942
- return /* @__PURE__ */ jsx(
10943
- ConditionalTooltip,
10944
- {
10945
- showTooltip: isDisabled,
10946
- content: "This row is disabled because it contains non-primitive data.",
10947
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10948
- /* @__PURE__ */ jsxs(
10949
- "div",
10950
- {
10951
- className: clx("grid grid-cols-2 divide-x", {
10952
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10953
- }),
10954
- children: [
10955
- /* @__PURE__ */ jsx(
10956
- Form$2.Field,
10957
- {
10958
- control: form.control,
10959
- name: `metadata.${index}.key`,
10960
- render: ({ field: field2 }) => {
10961
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10962
- GridInput,
10963
- {
10964
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10965
- ...field2,
10966
- disabled: isDisabled,
10967
- placeholder: "Key"
10968
- }
10969
- ) }) });
10970
- }
10971
- }
10972
- ),
10973
- /* @__PURE__ */ jsx(
10974
- Form$2.Field,
10975
- {
10976
- control: form.control,
10977
- name: `metadata.${index}.value`,
10978
- render: ({ field: { value, ...field2 } }) => {
10979
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10980
- GridInput,
10981
- {
10982
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10983
- ...field2,
10984
- value: isDisabled ? placeholder : value,
10985
- disabled: isDisabled,
10986
- placeholder: "Value"
10987
- }
10988
- ) }) });
10989
- }
10990
- }
10991
- )
10992
- ]
10993
- }
10994
- ),
10995
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10996
- /* @__PURE__ */ jsx(
10997
- DropdownMenu.Trigger,
10998
- {
10999
- className: clx(
11000
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11001
- {
11002
- hidden: isDisabled
11003
- }
11004
- ),
11005
- disabled: isDisabled,
11006
- asChild: true,
11007
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11008
- }
11009
- ),
11010
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11011
- /* @__PURE__ */ jsxs(
11012
- DropdownMenu.Item,
11013
- {
11014
- className: "gap-x-2",
11015
- onClick: () => insertRow(index, "above"),
11016
- children: [
11017
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11018
- "Insert row above"
11019
- ]
11020
- }
11021
- ),
11022
- /* @__PURE__ */ jsxs(
11023
- DropdownMenu.Item,
11024
- {
11025
- className: "gap-x-2",
11026
- onClick: () => insertRow(index, "below"),
11027
- children: [
11028
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11029
- "Insert row below"
11030
- ]
11031
- }
11032
- ),
11033
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11034
- /* @__PURE__ */ jsxs(
11035
- DropdownMenu.Item,
11036
- {
11037
- className: "gap-x-2",
11038
- onClick: () => deleteRow(index),
11039
- children: [
11040
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11041
- "Delete row"
11042
- ]
11043
- }
11044
- )
11045
- ] })
11046
- ] })
11047
- ] })
11048
- },
11049
- field.id
11050
- );
11051
- })
11052
- ] }),
11053
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10749
+ onOpenAutoFocus: (e) => {
10750
+ e.preventDefault();
10751
+ const searchInput = document.querySelector(
10752
+ "[data-modal-id='modal-search-input']"
10753
+ );
10754
+ if (searchInput) {
10755
+ searchInput.focus();
10756
+ }
10757
+ },
10758
+ children: [
10759
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10760
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10761
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11054
10762
  ] }),
11055
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11056
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11057
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10763
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10764
+ DataTable,
10765
+ {
10766
+ data: variants,
10767
+ columns,
10768
+ isLoading: isPending,
10769
+ getRowId: (row) => row.id,
10770
+ rowCount: count,
10771
+ prefix: VARIANT_PREFIX,
10772
+ layout: "fill",
10773
+ rowSelection: {
10774
+ state: rowSelection,
10775
+ onRowSelectionChange: setRowSelection,
10776
+ enableRowSelection: (row) => {
10777
+ return !items.find((i) => i.variant_id === row.original.id);
10778
+ }
10779
+ },
10780
+ autoFocusSearch: true
10781
+ }
10782
+ ) }),
10783
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10784
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10785
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11058
10786
  ] }) })
11059
10787
  ]
11060
10788
  }
11061
- ) });
11062
- };
11063
- const GridInput = forwardRef(({ className, ...props }, ref) => {
11064
- return /* @__PURE__ */ jsx(
11065
- "input",
11066
- {
11067
- ref,
11068
- ...props,
11069
- autoComplete: "off",
11070
- className: clx(
11071
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11072
- className
11073
- )
11074
- }
11075
10789
  );
11076
- });
11077
- GridInput.displayName = "MetadataForm.GridInput";
11078
- const PlaceholderInner = () => {
11079
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11080
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11081
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11082
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11083
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11084
- ] }) })
11085
- ] });
11086
10790
  };
11087
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11088
- function getDefaultValues(metadata) {
11089
- if (!metadata || !Object.keys(metadata).length) {
10791
+ const columnHelper = createDataTableColumnHelper();
10792
+ const useColumns = () => {
10793
+ return useMemo(() => {
11090
10794
  return [
11091
- {
11092
- key: "",
11093
- value: "",
11094
- disabled: false
11095
- }
10795
+ columnHelper.select(),
10796
+ columnHelper.accessor("product.title", {
10797
+ header: "Product",
10798
+ cell: ({ row }) => {
10799
+ var _a, _b, _c;
10800
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10801
+ /* @__PURE__ */ jsx(
10802
+ Thumbnail,
10803
+ {
10804
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10805
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10806
+ }
10807
+ ),
10808
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10809
+ ] });
10810
+ },
10811
+ enableSorting: true
10812
+ }),
10813
+ columnHelper.accessor("title", {
10814
+ header: "Variant",
10815
+ enableSorting: true
10816
+ }),
10817
+ columnHelper.accessor("sku", {
10818
+ header: "SKU",
10819
+ cell: ({ getValue }) => {
10820
+ return getValue() ?? "-";
10821
+ },
10822
+ enableSorting: true
10823
+ }),
10824
+ columnHelper.accessor("updated_at", {
10825
+ header: "Updated",
10826
+ cell: ({ getValue }) => {
10827
+ return /* @__PURE__ */ jsx(
10828
+ Tooltip,
10829
+ {
10830
+ content: getFullDate({ date: getValue(), includeTime: true }),
10831
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10832
+ }
10833
+ );
10834
+ },
10835
+ enableSorting: true,
10836
+ sortAscLabel: "Oldest first",
10837
+ sortDescLabel: "Newest first"
10838
+ }),
10839
+ columnHelper.accessor("created_at", {
10840
+ header: "Created",
10841
+ cell: ({ getValue }) => {
10842
+ return /* @__PURE__ */ jsx(
10843
+ Tooltip,
10844
+ {
10845
+ content: getFullDate({ date: getValue(), includeTime: true }),
10846
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10847
+ }
10848
+ );
10849
+ },
10850
+ enableSorting: true,
10851
+ sortAscLabel: "Oldest first",
10852
+ sortDescLabel: "Newest first"
10853
+ })
11096
10854
  ];
11097
- }
11098
- return Object.entries(metadata).map(([key, value]) => {
11099
- if (!EDITABLE_TYPES.includes(typeof value)) {
11100
- return {
11101
- key,
11102
- value,
11103
- disabled: true
11104
- };
11105
- }
11106
- let stringValue = value;
11107
- if (typeof value !== "string") {
11108
- stringValue = JSON.stringify(value);
11109
- }
11110
- return {
11111
- key,
11112
- value: stringValue,
11113
- original_key: key
11114
- };
10855
+ }, []);
10856
+ };
10857
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10858
+ const { setIsOpen } = useStackedModal();
10859
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10860
+ const form = useForm({
10861
+ defaultValues: {
10862
+ title: "",
10863
+ quantity: 1,
10864
+ unit_price: ""
10865
+ },
10866
+ resolver: zodResolver(customItemSchema)
11115
10867
  });
11116
- }
11117
- function parseValues(values) {
11118
- const metadata = values.metadata;
11119
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11120
- if (isEmpty) {
11121
- return null;
11122
- }
11123
- const update = {};
11124
- metadata.forEach((field) => {
11125
- let key = field.key;
11126
- let value = field.value;
11127
- const disabled = field.disabled;
11128
- if (!key || !value) {
11129
- return;
11130
- }
11131
- if (disabled) {
11132
- update[key] = value;
11133
- return;
11134
- }
11135
- key = key.trim();
11136
- value = value.trim();
11137
- if (value === "true") {
11138
- update[key] = true;
11139
- } else if (value === "false") {
11140
- update[key] = false;
11141
- } else {
11142
- const parsedNumber = parseFloat(value);
11143
- if (!isNaN(parsedNumber)) {
11144
- update[key] = parsedNumber;
11145
- } else {
11146
- update[key] = value;
10868
+ const onSubmit = form.handleSubmit(async (data) => {
10869
+ await addItems(
10870
+ {
10871
+ items: [
10872
+ {
10873
+ title: data.title,
10874
+ quantity: data.quantity,
10875
+ unit_price: convertNumber(data.unit_price)
10876
+ }
10877
+ ]
10878
+ },
10879
+ {
10880
+ onSuccess: () => {
10881
+ setIsOpen(STACKED_MODAL_ID, false);
10882
+ },
10883
+ onError: (e) => {
10884
+ toast.error(e.message);
10885
+ }
11147
10886
  }
11148
- }
10887
+ );
11149
10888
  });
11150
- return update;
11151
- }
11152
- function getHasUneditableRows(metadata) {
11153
- if (!metadata) {
11154
- return false;
11155
- }
11156
- return Object.values(metadata).some(
11157
- (value) => !EDITABLE_TYPES.includes(typeof value)
11158
- );
11159
- }
10889
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10890
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10891
+ /* @__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: [
10892
+ /* @__PURE__ */ jsxs("div", { children: [
10893
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10894
+ /* @__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." }) })
10895
+ ] }),
10896
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10897
+ /* @__PURE__ */ jsx(
10898
+ Form$2.Field,
10899
+ {
10900
+ control: form.control,
10901
+ name: "title",
10902
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10903
+ /* @__PURE__ */ jsxs("div", { children: [
10904
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10905
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10906
+ ] }),
10907
+ /* @__PURE__ */ jsxs("div", { children: [
10908
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10909
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10910
+ ] })
10911
+ ] }) })
10912
+ }
10913
+ ),
10914
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10915
+ /* @__PURE__ */ jsx(
10916
+ Form$2.Field,
10917
+ {
10918
+ control: form.control,
10919
+ name: "unit_price",
10920
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10921
+ /* @__PURE__ */ jsxs("div", { children: [
10922
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10923
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10924
+ ] }),
10925
+ /* @__PURE__ */ jsxs("div", { children: [
10926
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10927
+ CurrencyInput,
10928
+ {
10929
+ symbol: getNativeSymbol(currencyCode),
10930
+ code: currencyCode,
10931
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10932
+ ...field
10933
+ }
10934
+ ) }),
10935
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10936
+ ] })
10937
+ ] }) })
10938
+ }
10939
+ ),
10940
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10941
+ /* @__PURE__ */ jsx(
10942
+ Form$2.Field,
10943
+ {
10944
+ control: form.control,
10945
+ name: "quantity",
10946
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10947
+ /* @__PURE__ */ jsxs("div", { children: [
10948
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10949
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10950
+ ] }),
10951
+ /* @__PURE__ */ jsxs("div", { className: "flex-1 w-full", children: [
10952
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10953
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10954
+ ] })
10955
+ ] }) })
10956
+ }
10957
+ )
10958
+ ] }) }) }),
10959
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10960
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10961
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10962
+ ] }) })
10963
+ ] }) }) });
10964
+ };
10965
+ const customItemSchema = objectType({
10966
+ title: stringType().min(1),
10967
+ quantity: numberType(),
10968
+ unit_price: unionType([numberType(), stringType()])
10969
+ });
11160
10970
  const PROMOTION_QUERY_KEY = "promotions";
11161
10971
  const promotionsQueryKeys = {
11162
10972
  list: (query2) => [
@@ -11462,7 +11272,7 @@ const SalesChannelForm = ({ order }) => {
11462
11272
  defaultValues: {
11463
11273
  sales_channel_id: order.sales_channel_id || ""
11464
11274
  },
11465
- resolver: zodResolver(schema$2)
11275
+ resolver: zodResolver(schema$3)
11466
11276
  });
11467
11277
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11468
11278
  const { handleSuccess } = useRouteModal();
@@ -11537,7 +11347,7 @@ const SalesChannelField = ({ control, order }) => {
11537
11347
  }
11538
11348
  );
11539
11349
  };
11540
- const schema$2 = objectType({
11350
+ const schema$3 = objectType({
11541
11351
  sales_channel_id: stringType().min(1)
11542
11352
  });
11543
11353
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
@@ -12379,7 +12189,7 @@ const ShippingAddressForm = ({ order }) => {
12379
12189
  postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12380
12190
  phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12381
12191
  },
12382
- resolver: zodResolver(schema$1)
12192
+ resolver: zodResolver(schema$2)
12383
12193
  });
12384
12194
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12385
12195
  const { handleSuccess } = useRouteModal();
@@ -12549,7 +12359,7 @@ const ShippingAddressForm = ({ order }) => {
12549
12359
  }
12550
12360
  ) });
12551
12361
  };
12552
- const schema$1 = addressSchema;
12362
+ const schema$2 = addressSchema;
12553
12363
  const TransferOwnership = () => {
12554
12364
  const { id } = useParams();
12555
12365
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12573,7 +12383,7 @@ const TransferOwnershipForm = ({ order }) => {
12573
12383
  defaultValues: {
12574
12384
  customer_id: order.customer_id || ""
12575
12385
  },
12576
- resolver: zodResolver(schema)
12386
+ resolver: zodResolver(schema$1)
12577
12387
  });
12578
12388
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12579
12389
  const { handleSuccess } = useRouteModal();
@@ -13023,9 +12833,199 @@ const Illustration = () => {
13023
12833
  }
13024
12834
  );
13025
12835
  };
13026
- const schema = objectType({
12836
+ const schema$1 = objectType({
13027
12837
  customer_id: stringType().min(1)
13028
12838
  });
12839
+ const BillingAddress = () => {
12840
+ const { id } = useParams();
12841
+ const { order, isPending, isError, error } = useOrder(id, {
12842
+ fields: "+billing_address"
12843
+ });
12844
+ if (isError) {
12845
+ throw error;
12846
+ }
12847
+ const isReady = !isPending && !!order;
12848
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12849
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12850
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Billing Address" }) }),
12851
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12852
+ ] }),
12853
+ isReady && /* @__PURE__ */ jsx(BillingAddressForm, { order })
12854
+ ] });
12855
+ };
12856
+ const BillingAddressForm = ({ order }) => {
12857
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12858
+ const form = useForm({
12859
+ defaultValues: {
12860
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12861
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12862
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12863
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12864
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12865
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12866
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12867
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12868
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12869
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12870
+ },
12871
+ resolver: zodResolver(schema)
12872
+ });
12873
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12874
+ const { handleSuccess } = useRouteModal();
12875
+ const onSubmit = form.handleSubmit(async (data) => {
12876
+ await mutateAsync(
12877
+ { billing_address: data },
12878
+ {
12879
+ onSuccess: () => {
12880
+ handleSuccess();
12881
+ },
12882
+ onError: (error) => {
12883
+ toast.error(error.message);
12884
+ }
12885
+ }
12886
+ );
12887
+ });
12888
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12889
+ KeyboundForm,
12890
+ {
12891
+ className: "flex flex-1 flex-col overflow-hidden",
12892
+ onSubmit,
12893
+ children: [
12894
+ /* @__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: [
12895
+ /* @__PURE__ */ jsx(
12896
+ Form$2.Field,
12897
+ {
12898
+ control: form.control,
12899
+ name: "country_code",
12900
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12901
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12902
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12903
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12904
+ ] })
12905
+ }
12906
+ ),
12907
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12908
+ /* @__PURE__ */ jsx(
12909
+ Form$2.Field,
12910
+ {
12911
+ control: form.control,
12912
+ name: "first_name",
12913
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12914
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12915
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12916
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12917
+ ] })
12918
+ }
12919
+ ),
12920
+ /* @__PURE__ */ jsx(
12921
+ Form$2.Field,
12922
+ {
12923
+ control: form.control,
12924
+ name: "last_name",
12925
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12926
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12927
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12928
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12929
+ ] })
12930
+ }
12931
+ )
12932
+ ] }),
12933
+ /* @__PURE__ */ jsx(
12934
+ Form$2.Field,
12935
+ {
12936
+ control: form.control,
12937
+ name: "company",
12938
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12939
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12940
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12941
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12942
+ ] })
12943
+ }
12944
+ ),
12945
+ /* @__PURE__ */ jsx(
12946
+ Form$2.Field,
12947
+ {
12948
+ control: form.control,
12949
+ name: "address_1",
12950
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12951
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12952
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12953
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12954
+ ] })
12955
+ }
12956
+ ),
12957
+ /* @__PURE__ */ jsx(
12958
+ Form$2.Field,
12959
+ {
12960
+ control: form.control,
12961
+ name: "address_2",
12962
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12963
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12964
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12965
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12966
+ ] })
12967
+ }
12968
+ ),
12969
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12970
+ /* @__PURE__ */ jsx(
12971
+ Form$2.Field,
12972
+ {
12973
+ control: form.control,
12974
+ name: "postal_code",
12975
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12976
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12977
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12978
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12979
+ ] })
12980
+ }
12981
+ ),
12982
+ /* @__PURE__ */ jsx(
12983
+ Form$2.Field,
12984
+ {
12985
+ control: form.control,
12986
+ name: "city",
12987
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12988
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12989
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12990
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12991
+ ] })
12992
+ }
12993
+ )
12994
+ ] }),
12995
+ /* @__PURE__ */ jsx(
12996
+ Form$2.Field,
12997
+ {
12998
+ control: form.control,
12999
+ name: "province",
13000
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13001
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13002
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13003
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13004
+ ] })
13005
+ }
13006
+ ),
13007
+ /* @__PURE__ */ jsx(
13008
+ Form$2.Field,
13009
+ {
13010
+ control: form.control,
13011
+ name: "phone",
13012
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13013
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13014
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13015
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13016
+ ] })
13017
+ }
13018
+ )
13019
+ ] }) }),
13020
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13021
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13022
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13023
+ ] }) })
13024
+ ]
13025
+ }
13026
+ ) });
13027
+ };
13028
+ const schema = addressSchema;
13029
13029
  const widgetModule = { widgets: [] };
13030
13030
  const routeModule = {
13031
13031
  routes: [
@@ -13046,10 +13046,6 @@ const routeModule = {
13046
13046
  handle,
13047
13047
  loader,
13048
13048
  children: [
13049
- {
13050
- Component: BillingAddress,
13051
- path: "/draft-orders/:id/billing-address"
13052
- },
13053
13049
  {
13054
13050
  Component: CustomItems,
13055
13051
  path: "/draft-orders/:id/custom-items"
@@ -13058,14 +13054,14 @@ const routeModule = {
13058
13054
  Component: Email,
13059
13055
  path: "/draft-orders/:id/email"
13060
13056
  },
13061
- {
13062
- Component: Items,
13063
- path: "/draft-orders/:id/items"
13064
- },
13065
13057
  {
13066
13058
  Component: Metadata,
13067
13059
  path: "/draft-orders/:id/metadata"
13068
13060
  },
13061
+ {
13062
+ Component: Items,
13063
+ path: "/draft-orders/:id/items"
13064
+ },
13069
13065
  {
13070
13066
  Component: Promotions,
13071
13067
  path: "/draft-orders/:id/promotions"
@@ -13085,6 +13081,10 @@ const routeModule = {
13085
13081
  {
13086
13082
  Component: TransferOwnership,
13087
13083
  path: "/draft-orders/:id/transfer-ownership"
13084
+ },
13085
+ {
13086
+ Component: BillingAddress,
13087
+ path: "/draft-orders/:id/billing-address"
13088
13088
  }
13089
13089
  ]
13090
13090
  }