@medusajs/draft-order 2.10.4-snapshot-20251003132946 → 2.10.4-snapshot-20251003141424

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9573,196 +9573,6 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
- const BillingAddress = () => {
9577
- const { id } = reactRouterDom.useParams();
9578
- const { order, isPending, isError, error } = useOrder(id, {
9579
- fields: "+billing_address"
9580
- });
9581
- if (isError) {
9582
- throw error;
9583
- }
9584
- const isReady = !isPending && !!order;
9585
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9588
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9589
- ] }),
9590
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9591
- ] });
9592
- };
9593
- const BillingAddressForm = ({ order }) => {
9594
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9595
- const form = reactHookForm.useForm({
9596
- defaultValues: {
9597
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9598
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9599
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9600
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9601
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9602
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9603
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9604
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9605
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
- },
9608
- resolver: zod.zodResolver(schema$5)
9609
- });
9610
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
- const { handleSuccess } = useRouteModal();
9612
- const onSubmit = form.handleSubmit(async (data) => {
9613
- await mutateAsync(
9614
- { billing_address: data },
9615
- {
9616
- onSuccess: () => {
9617
- handleSuccess();
9618
- },
9619
- onError: (error) => {
9620
- ui.toast.error(error.message);
9621
- }
9622
- }
9623
- );
9624
- });
9625
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9626
- KeyboundForm,
9627
- {
9628
- className: "flex flex-1 flex-col overflow-hidden",
9629
- onSubmit,
9630
- children: [
9631
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9632
- /* @__PURE__ */ jsxRuntime.jsx(
9633
- Form$2.Field,
9634
- {
9635
- control: form.control,
9636
- name: "country_code",
9637
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9640
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9641
- ] })
9642
- }
9643
- ),
9644
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9645
- /* @__PURE__ */ jsxRuntime.jsx(
9646
- Form$2.Field,
9647
- {
9648
- control: form.control,
9649
- name: "first_name",
9650
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9651
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9652
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9653
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9654
- ] })
9655
- }
9656
- ),
9657
- /* @__PURE__ */ jsxRuntime.jsx(
9658
- Form$2.Field,
9659
- {
9660
- control: form.control,
9661
- name: "last_name",
9662
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9665
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9666
- ] })
9667
- }
9668
- )
9669
- ] }),
9670
- /* @__PURE__ */ jsxRuntime.jsx(
9671
- Form$2.Field,
9672
- {
9673
- control: form.control,
9674
- name: "company",
9675
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9678
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9679
- ] })
9680
- }
9681
- ),
9682
- /* @__PURE__ */ jsxRuntime.jsx(
9683
- Form$2.Field,
9684
- {
9685
- control: form.control,
9686
- name: "address_1",
9687
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9688
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9689
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9690
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9691
- ] })
9692
- }
9693
- ),
9694
- /* @__PURE__ */ jsxRuntime.jsx(
9695
- Form$2.Field,
9696
- {
9697
- control: form.control,
9698
- name: "address_2",
9699
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9702
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9703
- ] })
9704
- }
9705
- ),
9706
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9707
- /* @__PURE__ */ jsxRuntime.jsx(
9708
- Form$2.Field,
9709
- {
9710
- control: form.control,
9711
- name: "postal_code",
9712
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9713
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9714
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9715
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9716
- ] })
9717
- }
9718
- ),
9719
- /* @__PURE__ */ jsxRuntime.jsx(
9720
- Form$2.Field,
9721
- {
9722
- control: form.control,
9723
- name: "city",
9724
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9727
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
- ] })
9729
- }
9730
- )
9731
- ] }),
9732
- /* @__PURE__ */ jsxRuntime.jsx(
9733
- Form$2.Field,
9734
- {
9735
- control: form.control,
9736
- name: "province",
9737
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
- ] })
9742
- }
9743
- ),
9744
- /* @__PURE__ */ jsxRuntime.jsx(
9745
- Form$2.Field,
9746
- {
9747
- control: form.control,
9748
- name: "phone",
9749
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
- ] })
9754
- }
9755
- )
9756
- ] }) }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9760
- ] }) })
9761
- ]
9762
- }
9763
- ) });
9764
- };
9765
- const schema$5 = addressSchema;
9766
9576
  const CustomItems = () => {
9767
9577
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9768
9578
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9771,7 +9581,7 @@ const CustomItems = () => {
9771
9581
  };
9772
9582
  const CustomItemsForm = () => {
9773
9583
  const form = reactHookForm.useForm({
9774
- resolver: zod.zodResolver(schema$4)
9584
+ resolver: zod.zodResolver(schema$5)
9775
9585
  });
9776
9586
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9777
9587
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9781,7 +9591,7 @@ const CustomItemsForm = () => {
9781
9591
  ] }) })
9782
9592
  ] }) });
9783
9593
  };
9784
- const schema$4 = objectType({
9594
+ const schema$5 = objectType({
9785
9595
  email: stringType().email()
9786
9596
  });
9787
9597
  const Email = () => {
@@ -9806,7 +9616,7 @@ const EmailForm = ({ order }) => {
9806
9616
  defaultValues: {
9807
9617
  email: order.email ?? ""
9808
9618
  },
9809
- resolver: zod.zodResolver(schema$3)
9619
+ resolver: zod.zodResolver(schema$4)
9810
9620
  });
9811
9621
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9812
9622
  const { handleSuccess } = useRouteModal();
@@ -9849,269 +9659,619 @@ const EmailForm = ({ order }) => {
9849
9659
  }
9850
9660
  ) });
9851
9661
  };
9852
- const schema$3 = objectType({
9662
+ const schema$4 = objectType({
9853
9663
  email: stringType().email()
9854
9664
  });
9855
- const NumberInput = React.forwardRef(
9856
- ({
9857
- value,
9858
- onChange,
9859
- size = "base",
9860
- min = 0,
9861
- max = 100,
9862
- step = 1,
9863
- className,
9864
- disabled,
9865
- ...props
9866
- }, ref) => {
9867
- const handleChange = (event) => {
9868
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9869
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9870
- onChange(newValue);
9871
- }
9872
- };
9873
- const handleIncrement = () => {
9874
- const newValue = value + step;
9875
- if (max === void 0 || newValue <= max) {
9876
- onChange(newValue);
9877
- }
9878
- };
9879
- const handleDecrement = () => {
9880
- const newValue = value - step;
9881
- if (min === void 0 || newValue >= min) {
9882
- onChange(newValue);
9883
- }
9884
- };
9665
+ const InlineTip = React.forwardRef(
9666
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9667
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9885
9668
  return /* @__PURE__ */ jsxRuntime.jsxs(
9886
9669
  "div",
9887
9670
  {
9671
+ ref,
9888
9672
  className: ui.clx(
9889
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9890
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9891
- {
9892
- "h-7": size === "small",
9893
- "h-8": size === "base"
9894
- },
9673
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9895
9674
  className
9896
9675
  ),
9676
+ ...props,
9897
9677
  children: [
9898
9678
  /* @__PURE__ */ jsxRuntime.jsx(
9899
- "input",
9679
+ "div",
9900
9680
  {
9901
- ref,
9902
- type: "number",
9903
- value,
9904
- onChange: handleChange,
9905
- min,
9906
- max,
9907
- step,
9908
- className: ui.clx(
9909
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9910
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9911
- "placeholder:text-ui-fg-muted"
9912
- ),
9913
- ...props
9914
- }
9915
- ),
9916
- /* @__PURE__ */ jsxRuntime.jsxs(
9917
- "button",
9918
- {
9919
- className: ui.clx(
9920
- "flex items-center justify-center outline-none transition-fg",
9921
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9922
- "focus:bg-ui-bg-field-component-hover",
9923
- "hover:bg-ui-bg-field-component-hover",
9924
- {
9925
- "size-7": size === "small",
9926
- "size-8": size === "base"
9927
- }
9928
- ),
9929
- type: "button",
9930
- onClick: handleDecrement,
9931
- disabled: min !== void 0 && value <= min || disabled,
9932
- children: [
9933
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9934
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9935
- ]
9681
+ role: "presentation",
9682
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9683
+ "bg-ui-tag-orange-icon": variant === "warning"
9684
+ })
9936
9685
  }
9937
9686
  ),
9938
- /* @__PURE__ */ jsxRuntime.jsxs(
9939
- "button",
9940
- {
9941
- className: ui.clx(
9942
- "flex items-center justify-center outline-none transition-fg",
9943
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9944
- "focus:bg-ui-bg-field-hover",
9945
- "hover:bg-ui-bg-field-hover",
9946
- {
9947
- "size-7": size === "small",
9948
- "size-8": size === "base"
9949
- }
9950
- ),
9951
- type: "button",
9952
- onClick: handleIncrement,
9953
- disabled: max !== void 0 && value >= max || disabled,
9954
- children: [
9955
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9956
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9957
- ]
9958
- }
9959
- )
9687
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9688
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9689
+ labelValue,
9690
+ ":"
9691
+ ] }),
9692
+ " ",
9693
+ children
9694
+ ] })
9960
9695
  ]
9961
9696
  }
9962
9697
  );
9963
9698
  }
9964
9699
  );
9965
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9966
- const productVariantsQueryKeys = {
9967
- list: (query2) => [
9968
- PRODUCT_VARIANTS_QUERY_KEY,
9969
- query2 ? query2 : void 0
9970
- ]
9971
- };
9972
- const useProductVariants = (query2, options) => {
9973
- const { data, ...rest } = reactQuery.useQuery({
9974
- queryKey: productVariantsQueryKeys.list(query2),
9975
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9976
- ...options
9977
- });
9978
- return { ...data, ...rest };
9979
- };
9980
- const useCancelOrderEdit = ({ preview }) => {
9981
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9982
- const onCancel = React.useCallback(async () => {
9983
- if (!preview) {
9984
- return true;
9985
- }
9986
- let res = false;
9987
- await cancelOrderEdit(void 0, {
9988
- onError: (e) => {
9989
- ui.toast.error(e.message);
9990
- },
9991
- onSuccess: () => {
9992
- res = true;
9993
- }
9994
- });
9995
- return res;
9996
- }, [preview, cancelOrderEdit]);
9997
- return { onCancel };
9998
- };
9999
- let IS_REQUEST_RUNNING = false;
10000
- const useInitiateOrderEdit = ({
10001
- preview
10002
- }) => {
10003
- const navigate = reactRouterDom.useNavigate();
10004
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10005
- React.useEffect(() => {
10006
- async function run() {
10007
- if (IS_REQUEST_RUNNING || !preview) {
10008
- return;
10009
- }
10010
- if (preview.order_change) {
10011
- return;
10012
- }
10013
- IS_REQUEST_RUNNING = true;
10014
- await mutateAsync(void 0, {
10015
- onError: (e) => {
10016
- ui.toast.error(e.message);
10017
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10018
- return;
10019
- }
10020
- });
10021
- IS_REQUEST_RUNNING = false;
10022
- }
10023
- run();
10024
- }, [preview, navigate, mutateAsync]);
10025
- };
10026
- function convertNumber(value) {
10027
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10028
- }
10029
- const STACKED_MODAL_ID = "items_stacked_modal";
10030
- const Items = () => {
9700
+ InlineTip.displayName = "InlineTip";
9701
+ const MetadataFieldSchema = objectType({
9702
+ key: stringType(),
9703
+ disabled: booleanType().optional(),
9704
+ value: anyType()
9705
+ });
9706
+ const MetadataSchema = objectType({
9707
+ metadata: arrayType(MetadataFieldSchema)
9708
+ });
9709
+ const Metadata = () => {
10031
9710
  const { id } = reactRouterDom.useParams();
10032
- const {
10033
- order: preview,
10034
- isPending: isPreviewPending,
10035
- isError: isPreviewError,
10036
- error: previewError
10037
- } = useOrderPreview(id, void 0, {
10038
- placeholderData: reactQuery.keepPreviousData
9711
+ const { order, isPending, isError, error } = useOrder(id, {
9712
+ fields: "metadata"
10039
9713
  });
10040
- useInitiateOrderEdit({ preview });
10041
- const { draft_order, isPending, isError, error } = useDraftOrder(
10042
- id,
10043
- {
10044
- fields: "currency_code"
10045
- },
10046
- {
10047
- enabled: !!id
10048
- }
10049
- );
10050
- const { onCancel } = useCancelOrderEdit({ preview });
10051
9714
  if (isError) {
10052
9715
  throw error;
10053
9716
  }
10054
- if (isPreviewError) {
10055
- throw previewError;
10056
- }
10057
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10058
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10059
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10060
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10061
- ] }) });
9717
+ const isReady = !isPending && !!order;
9718
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9719
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9720
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9721
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9722
+ ] }),
9723
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9724
+ ] });
10062
9725
  };
10063
- const ItemsForm = ({ preview, currencyCode }) => {
10064
- var _a;
10065
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10066
- const [modalContent, setModalContent] = React.useState(
10067
- null
10068
- );
9726
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9727
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9728
+ const MetadataForm = ({ orderId, metadata }) => {
10069
9729
  const { handleSuccess } = useRouteModal();
10070
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10071
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10072
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10073
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10074
- const matches = React.useMemo(() => {
10075
- return matchSorter.matchSorter(preview.items, query2, {
10076
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10077
- });
10078
- }, [preview.items, query2]);
10079
- const onSubmit = async () => {
10080
- setIsSubmitting(true);
10081
- let requestSucceeded = false;
10082
- await requestOrderEdit(void 0, {
10083
- onError: (e) => {
10084
- ui.toast.error(`Failed to request order edit: ${e.message}`);
9730
+ const hasUneditableRows = getHasUneditableRows(metadata);
9731
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9732
+ const form = reactHookForm.useForm({
9733
+ defaultValues: {
9734
+ metadata: getDefaultValues(metadata)
9735
+ },
9736
+ resolver: zod.zodResolver(MetadataSchema)
9737
+ });
9738
+ const handleSubmit = form.handleSubmit(async (data) => {
9739
+ const parsedData = parseValues(data);
9740
+ await mutateAsync(
9741
+ {
9742
+ metadata: parsedData
10085
9743
  },
10086
- onSuccess: () => {
10087
- requestSucceeded = true;
9744
+ {
9745
+ onSuccess: () => {
9746
+ ui.toast.success("Metadata updated");
9747
+ handleSuccess();
9748
+ },
9749
+ onError: (error) => {
9750
+ ui.toast.error(error.message);
9751
+ }
10088
9752
  }
10089
- });
10090
- if (!requestSucceeded) {
10091
- setIsSubmitting(false);
10092
- return;
9753
+ );
9754
+ });
9755
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9756
+ control: form.control,
9757
+ name: "metadata"
9758
+ });
9759
+ function deleteRow(index) {
9760
+ remove(index);
9761
+ if (fields.length === 1) {
9762
+ insert(0, {
9763
+ key: "",
9764
+ value: "",
9765
+ disabled: false
9766
+ });
10093
9767
  }
10094
- await confirmOrderEdit(void 0, {
10095
- onError: (e) => {
10096
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10097
- },
10098
- onSuccess: () => {
10099
- handleSuccess();
10100
- },
10101
- onSettled: () => {
10102
- setIsSubmitting(false);
10103
- }
9768
+ }
9769
+ function insertRow(index, position) {
9770
+ insert(index + (position === "above" ? 0 : 1), {
9771
+ key: "",
9772
+ value: "",
9773
+ disabled: false
10104
9774
  });
10105
- };
10106
- const onKeyDown = React.useCallback(
10107
- (e) => {
10108
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10109
- if (modalContent || isSubmitting) {
10110
- return;
10111
- }
10112
- onSubmit();
10113
- }
10114
- },
9775
+ }
9776
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9777
+ KeyboundForm,
9778
+ {
9779
+ onSubmit: handleSubmit,
9780
+ className: "flex flex-1 flex-col overflow-hidden",
9781
+ children: [
9782
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9783
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9784
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9785
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9786
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9787
+ ] }),
9788
+ fields.map((field, index) => {
9789
+ const isDisabled = field.disabled || false;
9790
+ let placeholder = "-";
9791
+ if (typeof field.value === "object") {
9792
+ placeholder = "{ ... }";
9793
+ }
9794
+ if (Array.isArray(field.value)) {
9795
+ placeholder = "[ ... ]";
9796
+ }
9797
+ return /* @__PURE__ */ jsxRuntime.jsx(
9798
+ ConditionalTooltip,
9799
+ {
9800
+ showTooltip: isDisabled,
9801
+ content: "This row is disabled because it contains non-primitive data.",
9802
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9803
+ /* @__PURE__ */ jsxRuntime.jsxs(
9804
+ "div",
9805
+ {
9806
+ className: ui.clx("grid grid-cols-2 divide-x", {
9807
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9808
+ }),
9809
+ children: [
9810
+ /* @__PURE__ */ jsxRuntime.jsx(
9811
+ Form$2.Field,
9812
+ {
9813
+ control: form.control,
9814
+ name: `metadata.${index}.key`,
9815
+ render: ({ field: field2 }) => {
9816
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9817
+ GridInput,
9818
+ {
9819
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
9820
+ ...field2,
9821
+ disabled: isDisabled,
9822
+ placeholder: "Key"
9823
+ }
9824
+ ) }) });
9825
+ }
9826
+ }
9827
+ ),
9828
+ /* @__PURE__ */ jsxRuntime.jsx(
9829
+ Form$2.Field,
9830
+ {
9831
+ control: form.control,
9832
+ name: `metadata.${index}.value`,
9833
+ render: ({ field: { value, ...field2 } }) => {
9834
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9835
+ GridInput,
9836
+ {
9837
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
9838
+ ...field2,
9839
+ value: isDisabled ? placeholder : value,
9840
+ disabled: isDisabled,
9841
+ placeholder: "Value"
9842
+ }
9843
+ ) }) });
9844
+ }
9845
+ }
9846
+ )
9847
+ ]
9848
+ }
9849
+ ),
9850
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9851
+ /* @__PURE__ */ jsxRuntime.jsx(
9852
+ ui.DropdownMenu.Trigger,
9853
+ {
9854
+ className: ui.clx(
9855
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9856
+ {
9857
+ hidden: isDisabled
9858
+ }
9859
+ ),
9860
+ disabled: isDisabled,
9861
+ asChild: true,
9862
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9863
+ }
9864
+ ),
9865
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9866
+ /* @__PURE__ */ jsxRuntime.jsxs(
9867
+ ui.DropdownMenu.Item,
9868
+ {
9869
+ className: "gap-x-2",
9870
+ onClick: () => insertRow(index, "above"),
9871
+ children: [
9872
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9873
+ "Insert row above"
9874
+ ]
9875
+ }
9876
+ ),
9877
+ /* @__PURE__ */ jsxRuntime.jsxs(
9878
+ ui.DropdownMenu.Item,
9879
+ {
9880
+ className: "gap-x-2",
9881
+ onClick: () => insertRow(index, "below"),
9882
+ children: [
9883
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
9884
+ "Insert row below"
9885
+ ]
9886
+ }
9887
+ ),
9888
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
9889
+ /* @__PURE__ */ jsxRuntime.jsxs(
9890
+ ui.DropdownMenu.Item,
9891
+ {
9892
+ className: "gap-x-2",
9893
+ onClick: () => deleteRow(index),
9894
+ children: [
9895
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
9896
+ "Delete row"
9897
+ ]
9898
+ }
9899
+ )
9900
+ ] })
9901
+ ] })
9902
+ ] })
9903
+ },
9904
+ field.id
9905
+ );
9906
+ })
9907
+ ] }),
9908
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.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." })
9909
+ ] }),
9910
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9911
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9912
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9913
+ ] }) })
9914
+ ]
9915
+ }
9916
+ ) });
9917
+ };
9918
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
9919
+ return /* @__PURE__ */ jsxRuntime.jsx(
9920
+ "input",
9921
+ {
9922
+ ref,
9923
+ ...props,
9924
+ autoComplete: "off",
9925
+ className: ui.clx(
9926
+ "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",
9927
+ className
9928
+ )
9929
+ }
9930
+ );
9931
+ });
9932
+ GridInput.displayName = "MetadataForm.GridInput";
9933
+ const PlaceholderInner = () => {
9934
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9935
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9936
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9937
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
9938
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
9939
+ ] }) })
9940
+ ] });
9941
+ };
9942
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
9943
+ function getDefaultValues(metadata) {
9944
+ if (!metadata || !Object.keys(metadata).length) {
9945
+ return [
9946
+ {
9947
+ key: "",
9948
+ value: "",
9949
+ disabled: false
9950
+ }
9951
+ ];
9952
+ }
9953
+ return Object.entries(metadata).map(([key, value]) => {
9954
+ if (!EDITABLE_TYPES.includes(typeof value)) {
9955
+ return {
9956
+ key,
9957
+ value,
9958
+ disabled: true
9959
+ };
9960
+ }
9961
+ let stringValue = value;
9962
+ if (typeof value !== "string") {
9963
+ stringValue = JSON.stringify(value);
9964
+ }
9965
+ return {
9966
+ key,
9967
+ value: stringValue,
9968
+ original_key: key
9969
+ };
9970
+ });
9971
+ }
9972
+ function parseValues(values) {
9973
+ const metadata = values.metadata;
9974
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9975
+ if (isEmpty) {
9976
+ return null;
9977
+ }
9978
+ const update = {};
9979
+ metadata.forEach((field) => {
9980
+ let key = field.key;
9981
+ let value = field.value;
9982
+ const disabled = field.disabled;
9983
+ if (!key || !value) {
9984
+ return;
9985
+ }
9986
+ if (disabled) {
9987
+ update[key] = value;
9988
+ return;
9989
+ }
9990
+ key = key.trim();
9991
+ value = value.trim();
9992
+ if (value === "true") {
9993
+ update[key] = true;
9994
+ } else if (value === "false") {
9995
+ update[key] = false;
9996
+ } else {
9997
+ const parsedNumber = parseFloat(value);
9998
+ if (!isNaN(parsedNumber)) {
9999
+ update[key] = parsedNumber;
10000
+ } else {
10001
+ update[key] = value;
10002
+ }
10003
+ }
10004
+ });
10005
+ return update;
10006
+ }
10007
+ function getHasUneditableRows(metadata) {
10008
+ if (!metadata) {
10009
+ return false;
10010
+ }
10011
+ return Object.values(metadata).some(
10012
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10013
+ );
10014
+ }
10015
+ const NumberInput = React.forwardRef(
10016
+ ({
10017
+ value,
10018
+ onChange,
10019
+ size = "base",
10020
+ min = 0,
10021
+ max = 100,
10022
+ step = 1,
10023
+ className,
10024
+ disabled,
10025
+ ...props
10026
+ }, ref) => {
10027
+ const handleChange = (event) => {
10028
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10029
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10030
+ onChange(newValue);
10031
+ }
10032
+ };
10033
+ const handleIncrement = () => {
10034
+ const newValue = value + step;
10035
+ if (max === void 0 || newValue <= max) {
10036
+ onChange(newValue);
10037
+ }
10038
+ };
10039
+ const handleDecrement = () => {
10040
+ const newValue = value - step;
10041
+ if (min === void 0 || newValue >= min) {
10042
+ onChange(newValue);
10043
+ }
10044
+ };
10045
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10046
+ "div",
10047
+ {
10048
+ className: ui.clx(
10049
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10050
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10051
+ {
10052
+ "h-7": size === "small",
10053
+ "h-8": size === "base"
10054
+ },
10055
+ className
10056
+ ),
10057
+ children: [
10058
+ /* @__PURE__ */ jsxRuntime.jsx(
10059
+ "input",
10060
+ {
10061
+ ref,
10062
+ type: "number",
10063
+ value,
10064
+ onChange: handleChange,
10065
+ min,
10066
+ max,
10067
+ step,
10068
+ className: ui.clx(
10069
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10070
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10071
+ "placeholder:text-ui-fg-muted"
10072
+ ),
10073
+ ...props
10074
+ }
10075
+ ),
10076
+ /* @__PURE__ */ jsxRuntime.jsxs(
10077
+ "button",
10078
+ {
10079
+ className: ui.clx(
10080
+ "flex items-center justify-center outline-none transition-fg",
10081
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10082
+ "focus:bg-ui-bg-field-component-hover",
10083
+ "hover:bg-ui-bg-field-component-hover",
10084
+ {
10085
+ "size-7": size === "small",
10086
+ "size-8": size === "base"
10087
+ }
10088
+ ),
10089
+ type: "button",
10090
+ onClick: handleDecrement,
10091
+ disabled: min !== void 0 && value <= min || disabled,
10092
+ children: [
10093
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10094
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10095
+ ]
10096
+ }
10097
+ ),
10098
+ /* @__PURE__ */ jsxRuntime.jsxs(
10099
+ "button",
10100
+ {
10101
+ className: ui.clx(
10102
+ "flex items-center justify-center outline-none transition-fg",
10103
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10104
+ "focus:bg-ui-bg-field-hover",
10105
+ "hover:bg-ui-bg-field-hover",
10106
+ {
10107
+ "size-7": size === "small",
10108
+ "size-8": size === "base"
10109
+ }
10110
+ ),
10111
+ type: "button",
10112
+ onClick: handleIncrement,
10113
+ disabled: max !== void 0 && value >= max || disabled,
10114
+ children: [
10115
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10116
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10117
+ ]
10118
+ }
10119
+ )
10120
+ ]
10121
+ }
10122
+ );
10123
+ }
10124
+ );
10125
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10126
+ const productVariantsQueryKeys = {
10127
+ list: (query2) => [
10128
+ PRODUCT_VARIANTS_QUERY_KEY,
10129
+ query2 ? query2 : void 0
10130
+ ]
10131
+ };
10132
+ const useProductVariants = (query2, options) => {
10133
+ const { data, ...rest } = reactQuery.useQuery({
10134
+ queryKey: productVariantsQueryKeys.list(query2),
10135
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10136
+ ...options
10137
+ });
10138
+ return { ...data, ...rest };
10139
+ };
10140
+ const useCancelOrderEdit = ({ preview }) => {
10141
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10142
+ const onCancel = React.useCallback(async () => {
10143
+ if (!preview) {
10144
+ return true;
10145
+ }
10146
+ let res = false;
10147
+ await cancelOrderEdit(void 0, {
10148
+ onError: (e) => {
10149
+ ui.toast.error(e.message);
10150
+ },
10151
+ onSuccess: () => {
10152
+ res = true;
10153
+ }
10154
+ });
10155
+ return res;
10156
+ }, [preview, cancelOrderEdit]);
10157
+ return { onCancel };
10158
+ };
10159
+ let IS_REQUEST_RUNNING = false;
10160
+ const useInitiateOrderEdit = ({
10161
+ preview
10162
+ }) => {
10163
+ const navigate = reactRouterDom.useNavigate();
10164
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10165
+ React.useEffect(() => {
10166
+ async function run() {
10167
+ if (IS_REQUEST_RUNNING || !preview) {
10168
+ return;
10169
+ }
10170
+ if (preview.order_change) {
10171
+ return;
10172
+ }
10173
+ IS_REQUEST_RUNNING = true;
10174
+ await mutateAsync(void 0, {
10175
+ onError: (e) => {
10176
+ ui.toast.error(e.message);
10177
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10178
+ return;
10179
+ }
10180
+ });
10181
+ IS_REQUEST_RUNNING = false;
10182
+ }
10183
+ run();
10184
+ }, [preview, navigate, mutateAsync]);
10185
+ };
10186
+ function convertNumber(value) {
10187
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10188
+ }
10189
+ const STACKED_MODAL_ID = "items_stacked_modal";
10190
+ const Items = () => {
10191
+ const { id } = reactRouterDom.useParams();
10192
+ const {
10193
+ order: preview,
10194
+ isPending: isPreviewPending,
10195
+ isError: isPreviewError,
10196
+ error: previewError
10197
+ } = useOrderPreview(id, void 0, {
10198
+ placeholderData: reactQuery.keepPreviousData
10199
+ });
10200
+ useInitiateOrderEdit({ preview });
10201
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10202
+ id,
10203
+ {
10204
+ fields: "currency_code"
10205
+ },
10206
+ {
10207
+ enabled: !!id
10208
+ }
10209
+ );
10210
+ const { onCancel } = useCancelOrderEdit({ preview });
10211
+ if (isError) {
10212
+ throw error;
10213
+ }
10214
+ if (isPreviewError) {
10215
+ throw previewError;
10216
+ }
10217
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10218
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10219
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10220
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10221
+ ] }) });
10222
+ };
10223
+ const ItemsForm = ({ preview, currencyCode }) => {
10224
+ var _a;
10225
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10226
+ const [modalContent, setModalContent] = React.useState(
10227
+ null
10228
+ );
10229
+ const { handleSuccess } = useRouteModal();
10230
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10231
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10232
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10233
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10234
+ const matches = React.useMemo(() => {
10235
+ return matchSorter.matchSorter(preview.items, query2, {
10236
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10237
+ });
10238
+ }, [preview.items, query2]);
10239
+ const onSubmit = async () => {
10240
+ setIsSubmitting(true);
10241
+ let requestSucceeded = false;
10242
+ await requestOrderEdit(void 0, {
10243
+ onError: (e) => {
10244
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10245
+ },
10246
+ onSuccess: () => {
10247
+ requestSucceeded = true;
10248
+ }
10249
+ });
10250
+ if (!requestSucceeded) {
10251
+ setIsSubmitting(false);
10252
+ return;
10253
+ }
10254
+ await confirmOrderEdit(void 0, {
10255
+ onError: (e) => {
10256
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10257
+ },
10258
+ onSuccess: () => {
10259
+ handleSuccess();
10260
+ },
10261
+ onSettled: () => {
10262
+ setIsSubmitting(false);
10263
+ }
10264
+ });
10265
+ };
10266
+ const onKeyDown = React.useCallback(
10267
+ (e) => {
10268
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10269
+ if (modalContent || isSubmitting) {
10270
+ return;
10271
+ }
10272
+ onSubmit();
10273
+ }
10274
+ },
10115
10275
  [modalContent, isSubmitting, onSubmit]
10116
10276
  );
10117
10277
  React.useEffect(() => {
@@ -10260,165 +10420,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10260
10420
  quantity: item.quantity,
10261
10421
  unit_price: item.unit_price
10262
10422
  },
10263
- resolver: zod.zodResolver(variantItemSchema)
10264
- });
10265
- const actionId = React.useMemo(() => {
10266
- var _a, _b;
10267
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10268
- }, [item]);
10269
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10270
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10271
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10272
- const onSubmit = form.handleSubmit(async (data) => {
10273
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10274
- setEditing(false);
10275
- return;
10276
- }
10277
- if (!actionId) {
10278
- await updateOriginalItem(
10279
- {
10280
- item_id: item.id,
10281
- quantity: data.quantity,
10282
- unit_price: convertNumber(data.unit_price)
10283
- },
10284
- {
10285
- onSuccess: () => {
10286
- setEditing(false);
10287
- },
10288
- onError: (e) => {
10289
- ui.toast.error(e.message);
10290
- }
10291
- }
10292
- );
10293
- return;
10294
- }
10295
- await updateActionItem(
10296
- {
10297
- action_id: actionId,
10298
- quantity: data.quantity,
10299
- unit_price: convertNumber(data.unit_price)
10300
- },
10301
- {
10302
- onSuccess: () => {
10303
- setEditing(false);
10304
- },
10305
- onError: (e) => {
10306
- ui.toast.error(e.message);
10307
- }
10308
- }
10309
- );
10310
- });
10311
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10312
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10313
- /* @__PURE__ */ jsxRuntime.jsx(
10314
- Thumbnail,
10315
- {
10316
- thumbnail: item.thumbnail,
10317
- alt: item.product_title ?? void 0
10318
- }
10319
- ),
10320
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10321
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10322
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10323
- /* @__PURE__ */ jsxRuntime.jsxs(
10324
- ui.Text,
10325
- {
10326
- size: "small",
10327
- leading: "compact",
10328
- className: "text-ui-fg-subtle",
10329
- children: [
10330
- "(",
10331
- item.variant_title,
10332
- ")"
10333
- ]
10334
- }
10335
- )
10336
- ] }),
10337
- /* @__PURE__ */ jsxRuntime.jsx(
10338
- ui.Text,
10339
- {
10340
- size: "small",
10341
- leading: "compact",
10342
- className: "text-ui-fg-subtle",
10343
- children: item.variant_sku
10344
- }
10345
- )
10346
- ] })
10347
- ] }),
10348
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10349
- Form$2.Field,
10350
- {
10351
- control: form.control,
10352
- name: "quantity",
10353
- render: ({ field }) => {
10354
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10355
- }
10356
- }
10357
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10358
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10359
- Form$2.Field,
10360
- {
10361
- control: form.control,
10362
- name: "unit_price",
10363
- render: ({ field: { onChange, ...field } }) => {
10364
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10365
- ui.CurrencyInput,
10366
- {
10367
- ...field,
10368
- symbol: getNativeSymbol(currencyCode),
10369
- code: currencyCode,
10370
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10371
- }
10372
- ) }) });
10373
- }
10374
- }
10375
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10376
- /* @__PURE__ */ jsxRuntime.jsx(
10377
- ui.IconButton,
10378
- {
10379
- type: "button",
10380
- size: "small",
10381
- onClick: editing ? onSubmit : () => {
10382
- setEditing(true);
10383
- },
10384
- disabled: isPending,
10385
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10386
- }
10387
- )
10388
- ] }) }) });
10389
- };
10390
- const variantItemSchema = objectType({
10391
- quantity: numberType(),
10392
- unit_price: unionType([numberType(), stringType()])
10393
- });
10394
- const CustomItem = ({ item, preview, currencyCode }) => {
10395
- const [editing, setEditing] = React.useState(false);
10396
- const { quantity, unit_price, title } = item;
10397
- const form = reactHookForm.useForm({
10398
- defaultValues: {
10399
- title,
10400
- quantity,
10401
- unit_price
10402
- },
10403
- resolver: zod.zodResolver(customItemSchema)
10423
+ resolver: zod.zodResolver(variantItemSchema)
10404
10424
  });
10405
- React.useEffect(() => {
10406
- form.reset({
10407
- title,
10408
- quantity,
10409
- unit_price
10410
- });
10411
- }, [form, title, quantity, unit_price]);
10412
10425
  const actionId = React.useMemo(() => {
10413
10426
  var _a, _b;
10414
10427
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10415
10428
  }, [item]);
10416
10429
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10417
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10418
10430
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10419
10431
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10420
10432
  const onSubmit = form.handleSubmit(async (data) => {
10421
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10433
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10422
10434
  setEditing(false);
10423
10435
  return;
10424
10436
  }
@@ -10440,17 +10452,6 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10440
10452
  );
10441
10453
  return;
10442
10454
  }
10443
- if (data.quantity === 0) {
10444
- await removeActionItem(actionId, {
10445
- onSuccess: () => {
10446
- setEditing(false);
10447
- },
10448
- onError: (e) => {
10449
- ui.toast.error(e.message);
10450
- }
10451
- });
10452
- return;
10453
- }
10454
10455
  await updateActionItem(
10455
10456
  {
10456
10457
  action_id: actionId,
@@ -10468,26 +10469,43 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10468
10469
  );
10469
10470
  });
10470
10471
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10471
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10472
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10472
10473
  /* @__PURE__ */ jsxRuntime.jsx(
10473
10474
  Thumbnail,
10474
10475
  {
10475
10476
  thumbnail: item.thumbnail,
10476
- alt: item.title ?? void 0
10477
+ alt: item.product_title ?? void 0
10477
10478
  }
10478
10479
  ),
10479
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10480
- Form$2.Field,
10481
- {
10482
- control: form.control,
10483
- name: "title",
10484
- render: ({ field }) => {
10485
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10480
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10481
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10482
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10483
+ /* @__PURE__ */ jsxRuntime.jsxs(
10484
+ ui.Text,
10485
+ {
10486
+ size: "small",
10487
+ leading: "compact",
10488
+ className: "text-ui-fg-subtle",
10489
+ children: [
10490
+ "(",
10491
+ item.variant_title,
10492
+ ")"
10493
+ ]
10494
+ }
10495
+ )
10496
+ ] }),
10497
+ /* @__PURE__ */ jsxRuntime.jsx(
10498
+ ui.Text,
10499
+ {
10500
+ size: "small",
10501
+ leading: "compact",
10502
+ className: "text-ui-fg-subtle",
10503
+ children: item.variant_sku
10486
10504
  }
10487
- }
10488
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10505
+ )
10506
+ ] })
10489
10507
  ] }),
10490
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10508
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10491
10509
  Form$2.Field,
10492
10510
  {
10493
10511
  control: form.control,
@@ -10496,8 +10514,8 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10496
10514
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10497
10515
  }
10498
10516
  }
10499
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10500
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10517
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10518
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10501
10519
  Form$2.Field,
10502
10520
  {
10503
10521
  control: form.control,
@@ -10514,230 +10532,94 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10514
10532
  ) }) });
10515
10533
  }
10516
10534
  }
10517
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10535
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10518
10536
  /* @__PURE__ */ jsxRuntime.jsx(
10519
10537
  ui.IconButton,
10520
10538
  {
10521
10539
  type: "button",
10522
- size: "small",
10523
- onClick: editing ? onSubmit : () => {
10524
- setEditing(true);
10525
- },
10526
- disabled: isPending,
10527
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10528
- }
10529
- )
10530
- ] }) }) });
10531
- };
10532
- const StackedModalTrigger$1 = ({
10533
- type,
10534
- setModalContent
10535
- }) => {
10536
- const { setIsOpen } = useStackedModal();
10537
- const onClick = React.useCallback(() => {
10538
- setModalContent(type);
10539
- setIsOpen(STACKED_MODAL_ID, true);
10540
- }, [setModalContent, setIsOpen, type]);
10541
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10542
- };
10543
- const VARIANT_PREFIX = "items";
10544
- const LIMIT = 50;
10545
- const ExistingItemsForm = ({ orderId, items }) => {
10546
- const { setIsOpen } = useStackedModal();
10547
- const [rowSelection, setRowSelection] = React.useState(
10548
- items.reduce((acc, item) => {
10549
- acc[item.variant_id] = true;
10550
- return acc;
10551
- }, {})
10552
- );
10553
- React.useEffect(() => {
10554
- setRowSelection(
10555
- items.reduce((acc, item) => {
10556
- if (item.variant_id) {
10557
- acc[item.variant_id] = true;
10558
- }
10559
- return acc;
10560
- }, {})
10561
- );
10562
- }, [items]);
10563
- const { q, order, offset } = useQueryParams(
10564
- ["q", "order", "offset"],
10565
- VARIANT_PREFIX
10566
- );
10567
- const { variants, count, isPending, isError, error } = useProductVariants(
10568
- {
10569
- q,
10570
- order,
10571
- offset: offset ? parseInt(offset) : void 0,
10572
- limit: LIMIT
10573
- },
10574
- {
10575
- placeholderData: reactQuery.keepPreviousData
10576
- }
10577
- );
10578
- const columns = useColumns();
10579
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10580
- const onSubmit = async () => {
10581
- const ids = Object.keys(rowSelection).filter(
10582
- (id) => !items.find((i) => i.variant_id === id)
10583
- );
10584
- await mutateAsync(
10585
- {
10586
- items: ids.map((id) => ({
10587
- variant_id: id,
10588
- quantity: 1
10589
- }))
10590
- },
10591
- {
10592
- onSuccess: () => {
10593
- setRowSelection({});
10594
- setIsOpen(STACKED_MODAL_ID, false);
10595
- },
10596
- onError: (e) => {
10597
- ui.toast.error(e.message);
10598
- }
10599
- }
10600
- );
10601
- };
10602
- if (isError) {
10603
- throw error;
10604
- }
10605
- return /* @__PURE__ */ jsxRuntime.jsxs(
10606
- StackedFocusModal.Content,
10607
- {
10608
- onOpenAutoFocus: (e) => {
10609
- e.preventDefault();
10610
- const searchInput = document.querySelector(
10611
- "[data-modal-id='modal-search-input']"
10612
- );
10613
- if (searchInput) {
10614
- searchInput.focus();
10615
- }
10616
- },
10617
- children: [
10618
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10619
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10620
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10621
- ] }),
10622
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10623
- DataTable,
10624
- {
10625
- data: variants,
10626
- columns,
10627
- isLoading: isPending,
10628
- getRowId: (row) => row.id,
10629
- rowCount: count,
10630
- prefix: VARIANT_PREFIX,
10631
- layout: "fill",
10632
- rowSelection: {
10633
- state: rowSelection,
10634
- onRowSelectionChange: setRowSelection,
10635
- enableRowSelection: (row) => {
10636
- return !items.find((i) => i.variant_id === row.original.id);
10637
- }
10638
- },
10639
- autoFocusSearch: true
10640
- }
10641
- ) }),
10642
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10643
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10644
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10645
- ] }) })
10646
- ]
10647
- }
10648
- );
10649
- };
10650
- const columnHelper = ui.createDataTableColumnHelper();
10651
- const useColumns = () => {
10652
- return React.useMemo(() => {
10653
- return [
10654
- columnHelper.select(),
10655
- columnHelper.accessor("product.title", {
10656
- header: "Product",
10657
- cell: ({ row }) => {
10658
- var _a, _b, _c;
10659
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10660
- /* @__PURE__ */ jsxRuntime.jsx(
10661
- Thumbnail,
10662
- {
10663
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10664
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10665
- }
10666
- ),
10667
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10668
- ] });
10669
- },
10670
- enableSorting: true
10671
- }),
10672
- columnHelper.accessor("title", {
10673
- header: "Variant",
10674
- enableSorting: true
10675
- }),
10676
- columnHelper.accessor("sku", {
10677
- header: "SKU",
10678
- cell: ({ getValue }) => {
10679
- return getValue() ?? "-";
10680
- },
10681
- enableSorting: true
10682
- }),
10683
- columnHelper.accessor("updated_at", {
10684
- header: "Updated",
10685
- cell: ({ getValue }) => {
10686
- return /* @__PURE__ */ jsxRuntime.jsx(
10687
- ui.Tooltip,
10688
- {
10689
- content: getFullDate({ date: getValue(), includeTime: true }),
10690
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10691
- }
10692
- );
10693
- },
10694
- enableSorting: true,
10695
- sortAscLabel: "Oldest first",
10696
- sortDescLabel: "Newest first"
10697
- }),
10698
- columnHelper.accessor("created_at", {
10699
- header: "Created",
10700
- cell: ({ getValue }) => {
10701
- return /* @__PURE__ */ jsxRuntime.jsx(
10702
- ui.Tooltip,
10703
- {
10704
- content: getFullDate({ date: getValue(), includeTime: true }),
10705
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10706
- }
10707
- );
10540
+ size: "small",
10541
+ onClick: editing ? onSubmit : () => {
10542
+ setEditing(true);
10708
10543
  },
10709
- enableSorting: true,
10710
- sortAscLabel: "Oldest first",
10711
- sortDescLabel: "Newest first"
10712
- })
10713
- ];
10714
- }, []);
10544
+ disabled: isPending,
10545
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10546
+ }
10547
+ )
10548
+ ] }) }) });
10715
10549
  };
10716
- const CustomItemForm = ({ orderId, currencyCode }) => {
10717
- const { setIsOpen } = useStackedModal();
10718
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10550
+ const variantItemSchema = objectType({
10551
+ quantity: numberType(),
10552
+ unit_price: unionType([numberType(), stringType()])
10553
+ });
10554
+ const CustomItem = ({ item, preview, currencyCode }) => {
10555
+ const [editing, setEditing] = React.useState(false);
10556
+ const { quantity, unit_price, title } = item;
10719
10557
  const form = reactHookForm.useForm({
10720
10558
  defaultValues: {
10721
- title: "",
10722
- quantity: 1,
10723
- unit_price: ""
10559
+ title,
10560
+ quantity,
10561
+ unit_price
10724
10562
  },
10725
10563
  resolver: zod.zodResolver(customItemSchema)
10726
10564
  });
10565
+ React.useEffect(() => {
10566
+ form.reset({
10567
+ title,
10568
+ quantity,
10569
+ unit_price
10570
+ });
10571
+ }, [form, title, quantity, unit_price]);
10572
+ const actionId = React.useMemo(() => {
10573
+ var _a, _b;
10574
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10575
+ }, [item]);
10576
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10577
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10578
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10579
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10727
10580
  const onSubmit = form.handleSubmit(async (data) => {
10728
- await addItems(
10729
- {
10730
- items: [
10731
- {
10732
- title: data.title,
10733
- quantity: data.quantity,
10734
- unit_price: convertNumber(data.unit_price)
10581
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10582
+ setEditing(false);
10583
+ return;
10584
+ }
10585
+ if (!actionId) {
10586
+ await updateOriginalItem(
10587
+ {
10588
+ item_id: item.id,
10589
+ quantity: data.quantity,
10590
+ unit_price: convertNumber(data.unit_price)
10591
+ },
10592
+ {
10593
+ onSuccess: () => {
10594
+ setEditing(false);
10595
+ },
10596
+ onError: (e) => {
10597
+ ui.toast.error(e.message);
10735
10598
  }
10736
- ]
10599
+ }
10600
+ );
10601
+ return;
10602
+ }
10603
+ if (data.quantity === 0) {
10604
+ await removeActionItem(actionId, {
10605
+ onSuccess: () => {
10606
+ setEditing(false);
10607
+ },
10608
+ onError: (e) => {
10609
+ ui.toast.error(e.message);
10610
+ }
10611
+ });
10612
+ return;
10613
+ }
10614
+ await updateActionItem(
10615
+ {
10616
+ action_id: actionId,
10617
+ quantity: data.quantity,
10618
+ unit_price: convertNumber(data.unit_price)
10737
10619
  },
10738
10620
  {
10739
10621
  onSuccess: () => {
10740
- setIsOpen(STACKED_MODAL_ID, false);
10622
+ setEditing(false);
10741
10623
  },
10742
10624
  onError: (e) => {
10743
10625
  ui.toast.error(e.message);
@@ -10745,437 +10627,365 @@ const CustomItemForm = ({ orderId, currencyCode }) => {
10745
10627
  }
10746
10628
  );
10747
10629
  });
10748
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10749
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10750
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10751
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10752
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10753
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.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." }) })
10754
- ] }),
10755
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10630
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10631
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10756
10632
  /* @__PURE__ */ jsxRuntime.jsx(
10757
- Form$2.Field,
10633
+ Thumbnail,
10758
10634
  {
10759
- control: form.control,
10760
- name: "title",
10761
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10762
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10763
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10764
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10765
- ] }),
10766
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10767
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10768
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10769
- ] })
10770
- ] }) })
10635
+ thumbnail: item.thumbnail,
10636
+ alt: item.title ?? void 0
10771
10637
  }
10772
10638
  ),
10773
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10774
- /* @__PURE__ */ jsxRuntime.jsx(
10639
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10775
10640
  Form$2.Field,
10776
10641
  {
10777
10642
  control: form.control,
10778
- name: "unit_price",
10779
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10780
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10781
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10782
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10783
- ] }),
10784
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10785
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10786
- ui.CurrencyInput,
10787
- {
10788
- symbol: getNativeSymbol(currencyCode),
10789
- code: currencyCode,
10790
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10791
- ...field
10792
- }
10793
- ) }),
10794
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10795
- ] })
10796
- ] }) })
10643
+ name: "title",
10644
+ render: ({ field }) => {
10645
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10646
+ }
10797
10647
  }
10798
- ),
10799
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10800
- /* @__PURE__ */ jsxRuntime.jsx(
10801
- Form$2.Field,
10802
- {
10803
- control: form.control,
10804
- name: "quantity",
10805
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10806
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10807
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10808
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10809
- ] }),
10810
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10811
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10812
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10813
- ] })
10814
- ] }) })
10648
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10649
+ ] }),
10650
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10651
+ Form$2.Field,
10652
+ {
10653
+ control: form.control,
10654
+ name: "quantity",
10655
+ render: ({ field }) => {
10656
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10815
10657
  }
10816
- )
10817
- ] }) }) }),
10818
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10819
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10820
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10821
- ] }) })
10822
- ] }) }) });
10823
- };
10824
- const customItemSchema = objectType({
10825
- title: stringType().min(1),
10826
- quantity: numberType(),
10827
- unit_price: unionType([numberType(), stringType()])
10828
- });
10829
- const InlineTip = React.forwardRef(
10830
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10831
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10832
- return /* @__PURE__ */ jsxRuntime.jsxs(
10833
- "div",
10658
+ }
10659
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10660
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10661
+ Form$2.Field,
10834
10662
  {
10835
- ref,
10836
- className: ui.clx(
10837
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10838
- className
10839
- ),
10840
- ...props,
10841
- children: [
10842
- /* @__PURE__ */ jsxRuntime.jsx(
10843
- "div",
10663
+ control: form.control,
10664
+ name: "unit_price",
10665
+ render: ({ field: { onChange, ...field } }) => {
10666
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10667
+ ui.CurrencyInput,
10844
10668
  {
10845
- role: "presentation",
10846
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10847
- "bg-ui-tag-orange-icon": variant === "warning"
10848
- })
10669
+ ...field,
10670
+ symbol: getNativeSymbol(currencyCode),
10671
+ code: currencyCode,
10672
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10849
10673
  }
10850
- ),
10851
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10852
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10853
- labelValue,
10854
- ":"
10855
- ] }),
10856
- " ",
10857
- children
10858
- ] })
10859
- ]
10674
+ ) }) });
10675
+ }
10860
10676
  }
10861
- );
10862
- }
10863
- );
10864
- InlineTip.displayName = "InlineTip";
10865
- const MetadataFieldSchema = objectType({
10866
- key: stringType(),
10867
- disabled: booleanType().optional(),
10868
- value: anyType()
10869
- });
10870
- const MetadataSchema = objectType({
10871
- metadata: arrayType(MetadataFieldSchema)
10872
- });
10873
- const Metadata = () => {
10874
- const { id } = reactRouterDom.useParams();
10875
- const { order, isPending, isError, error } = useOrder(id, {
10876
- fields: "metadata"
10877
- });
10878
- if (isError) {
10879
- throw error;
10880
- }
10881
- const isReady = !isPending && !!order;
10882
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10883
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10884
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10885
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10886
- ] }),
10887
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10888
- ] });
10677
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10678
+ /* @__PURE__ */ jsxRuntime.jsx(
10679
+ ui.IconButton,
10680
+ {
10681
+ type: "button",
10682
+ size: "small",
10683
+ onClick: editing ? onSubmit : () => {
10684
+ setEditing(true);
10685
+ },
10686
+ disabled: isPending,
10687
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10688
+ }
10689
+ )
10690
+ ] }) }) });
10889
10691
  };
10890
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10891
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10892
- const MetadataForm = ({ orderId, metadata }) => {
10893
- const { handleSuccess } = useRouteModal();
10894
- const hasUneditableRows = getHasUneditableRows(metadata);
10895
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10896
- const form = reactHookForm.useForm({
10897
- defaultValues: {
10898
- metadata: getDefaultValues(metadata)
10692
+ const StackedModalTrigger$1 = ({
10693
+ type,
10694
+ setModalContent
10695
+ }) => {
10696
+ const { setIsOpen } = useStackedModal();
10697
+ const onClick = React.useCallback(() => {
10698
+ setModalContent(type);
10699
+ setIsOpen(STACKED_MODAL_ID, true);
10700
+ }, [setModalContent, setIsOpen, type]);
10701
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10702
+ };
10703
+ const VARIANT_PREFIX = "items";
10704
+ const LIMIT = 50;
10705
+ const ExistingItemsForm = ({ orderId, items }) => {
10706
+ const { setIsOpen } = useStackedModal();
10707
+ const [rowSelection, setRowSelection] = React.useState(
10708
+ items.reduce((acc, item) => {
10709
+ acc[item.variant_id] = true;
10710
+ return acc;
10711
+ }, {})
10712
+ );
10713
+ React.useEffect(() => {
10714
+ setRowSelection(
10715
+ items.reduce((acc, item) => {
10716
+ if (item.variant_id) {
10717
+ acc[item.variant_id] = true;
10718
+ }
10719
+ return acc;
10720
+ }, {})
10721
+ );
10722
+ }, [items]);
10723
+ const { q, order, offset } = useQueryParams(
10724
+ ["q", "order", "offset"],
10725
+ VARIANT_PREFIX
10726
+ );
10727
+ const { variants, count, isPending, isError, error } = useProductVariants(
10728
+ {
10729
+ q,
10730
+ order,
10731
+ offset: offset ? parseInt(offset) : void 0,
10732
+ limit: LIMIT
10899
10733
  },
10900
- resolver: zod.zodResolver(MetadataSchema)
10901
- });
10902
- const handleSubmit = form.handleSubmit(async (data) => {
10903
- const parsedData = parseValues(data);
10734
+ {
10735
+ placeholderData: reactQuery.keepPreviousData
10736
+ }
10737
+ );
10738
+ const columns = useColumns();
10739
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10740
+ const onSubmit = async () => {
10741
+ const ids = Object.keys(rowSelection).filter(
10742
+ (id) => !items.find((i) => i.variant_id === id)
10743
+ );
10904
10744
  await mutateAsync(
10905
10745
  {
10906
- metadata: parsedData
10746
+ items: ids.map((id) => ({
10747
+ variant_id: id,
10748
+ quantity: 1
10749
+ }))
10907
10750
  },
10908
10751
  {
10909
10752
  onSuccess: () => {
10910
- ui.toast.success("Metadata updated");
10911
- handleSuccess();
10753
+ setRowSelection({});
10754
+ setIsOpen(STACKED_MODAL_ID, false);
10912
10755
  },
10913
- onError: (error) => {
10914
- ui.toast.error(error.message);
10756
+ onError: (e) => {
10757
+ ui.toast.error(e.message);
10915
10758
  }
10916
10759
  }
10917
10760
  );
10918
- });
10919
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10920
- control: form.control,
10921
- name: "metadata"
10922
- });
10923
- function deleteRow(index) {
10924
- remove(index);
10925
- if (fields.length === 1) {
10926
- insert(0, {
10927
- key: "",
10928
- value: "",
10929
- disabled: false
10930
- });
10931
- }
10932
- }
10933
- function insertRow(index, position) {
10934
- insert(index + (position === "above" ? 0 : 1), {
10935
- key: "",
10936
- value: "",
10937
- disabled: false
10938
- });
10761
+ };
10762
+ if (isError) {
10763
+ throw error;
10939
10764
  }
10940
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10941
- KeyboundForm,
10765
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10766
+ StackedFocusModal.Content,
10942
10767
  {
10943
- onSubmit: handleSubmit,
10944
- className: "flex flex-1 flex-col overflow-hidden",
10768
+ onOpenAutoFocus: (e) => {
10769
+ e.preventDefault();
10770
+ const searchInput = document.querySelector(
10771
+ "[data-modal-id='modal-search-input']"
10772
+ );
10773
+ if (searchInput) {
10774
+ searchInput.focus();
10775
+ }
10776
+ },
10945
10777
  children: [
10946
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10947
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10948
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10949
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10950
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10951
- ] }),
10952
- fields.map((field, index) => {
10953
- const isDisabled = field.disabled || false;
10954
- let placeholder = "-";
10955
- if (typeof field.value === "object") {
10956
- placeholder = "{ ... }";
10957
- }
10958
- if (Array.isArray(field.value)) {
10959
- placeholder = "[ ... ]";
10960
- }
10961
- return /* @__PURE__ */ jsxRuntime.jsx(
10962
- ConditionalTooltip,
10963
- {
10964
- showTooltip: isDisabled,
10965
- content: "This row is disabled because it contains non-primitive data.",
10966
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10967
- /* @__PURE__ */ jsxRuntime.jsxs(
10968
- "div",
10969
- {
10970
- className: ui.clx("grid grid-cols-2 divide-x", {
10971
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10972
- }),
10973
- children: [
10974
- /* @__PURE__ */ jsxRuntime.jsx(
10975
- Form$2.Field,
10976
- {
10977
- control: form.control,
10978
- name: `metadata.${index}.key`,
10979
- render: ({ field: field2 }) => {
10980
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10981
- GridInput,
10982
- {
10983
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10984
- ...field2,
10985
- disabled: isDisabled,
10986
- placeholder: "Key"
10987
- }
10988
- ) }) });
10989
- }
10990
- }
10991
- ),
10992
- /* @__PURE__ */ jsxRuntime.jsx(
10993
- Form$2.Field,
10994
- {
10995
- control: form.control,
10996
- name: `metadata.${index}.value`,
10997
- render: ({ field: { value, ...field2 } }) => {
10998
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10999
- GridInput,
11000
- {
11001
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11002
- ...field2,
11003
- value: isDisabled ? placeholder : value,
11004
- disabled: isDisabled,
11005
- placeholder: "Value"
11006
- }
11007
- ) }) });
11008
- }
11009
- }
11010
- )
11011
- ]
11012
- }
11013
- ),
11014
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11015
- /* @__PURE__ */ jsxRuntime.jsx(
11016
- ui.DropdownMenu.Trigger,
11017
- {
11018
- className: ui.clx(
11019
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11020
- {
11021
- hidden: isDisabled
11022
- }
11023
- ),
11024
- disabled: isDisabled,
11025
- asChild: true,
11026
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11027
- }
11028
- ),
11029
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11030
- /* @__PURE__ */ jsxRuntime.jsxs(
11031
- ui.DropdownMenu.Item,
11032
- {
11033
- className: "gap-x-2",
11034
- onClick: () => insertRow(index, "above"),
11035
- children: [
11036
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11037
- "Insert row above"
11038
- ]
11039
- }
11040
- ),
11041
- /* @__PURE__ */ jsxRuntime.jsxs(
11042
- ui.DropdownMenu.Item,
11043
- {
11044
- className: "gap-x-2",
11045
- onClick: () => insertRow(index, "below"),
11046
- children: [
11047
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11048
- "Insert row below"
11049
- ]
11050
- }
11051
- ),
11052
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11053
- /* @__PURE__ */ jsxRuntime.jsxs(
11054
- ui.DropdownMenu.Item,
11055
- {
11056
- className: "gap-x-2",
11057
- onClick: () => deleteRow(index),
11058
- children: [
11059
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11060
- "Delete row"
11061
- ]
11062
- }
11063
- )
11064
- ] })
11065
- ] })
11066
- ] })
11067
- },
11068
- field.id
11069
- );
11070
- })
11071
- ] }),
11072
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.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." })
10778
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10779
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10780
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
11073
10781
  ] }),
11074
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11075
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11076
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10782
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10783
+ DataTable,
10784
+ {
10785
+ data: variants,
10786
+ columns,
10787
+ isLoading: isPending,
10788
+ getRowId: (row) => row.id,
10789
+ rowCount: count,
10790
+ prefix: VARIANT_PREFIX,
10791
+ layout: "fill",
10792
+ rowSelection: {
10793
+ state: rowSelection,
10794
+ onRowSelectionChange: setRowSelection,
10795
+ enableRowSelection: (row) => {
10796
+ return !items.find((i) => i.variant_id === row.original.id);
10797
+ }
10798
+ },
10799
+ autoFocusSearch: true
10800
+ }
10801
+ ) }),
10802
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10803
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10804
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11077
10805
  ] }) })
11078
10806
  ]
11079
10807
  }
11080
- ) });
11081
- };
11082
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11083
- return /* @__PURE__ */ jsxRuntime.jsx(
11084
- "input",
11085
- {
11086
- ref,
11087
- ...props,
11088
- autoComplete: "off",
11089
- className: ui.clx(
11090
- "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",
11091
- className
11092
- )
11093
- }
11094
10808
  );
11095
- });
11096
- GridInput.displayName = "MetadataForm.GridInput";
11097
- const PlaceholderInner = () => {
11098
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11099
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11100
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11102
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11103
- ] }) })
11104
- ] });
11105
10809
  };
11106
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11107
- function getDefaultValues(metadata) {
11108
- if (!metadata || !Object.keys(metadata).length) {
10810
+ const columnHelper = ui.createDataTableColumnHelper();
10811
+ const useColumns = () => {
10812
+ return React.useMemo(() => {
11109
10813
  return [
11110
- {
11111
- key: "",
11112
- value: "",
11113
- disabled: false
11114
- }
10814
+ columnHelper.select(),
10815
+ columnHelper.accessor("product.title", {
10816
+ header: "Product",
10817
+ cell: ({ row }) => {
10818
+ var _a, _b, _c;
10819
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10820
+ /* @__PURE__ */ jsxRuntime.jsx(
10821
+ Thumbnail,
10822
+ {
10823
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10824
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10825
+ }
10826
+ ),
10827
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10828
+ ] });
10829
+ },
10830
+ enableSorting: true
10831
+ }),
10832
+ columnHelper.accessor("title", {
10833
+ header: "Variant",
10834
+ enableSorting: true
10835
+ }),
10836
+ columnHelper.accessor("sku", {
10837
+ header: "SKU",
10838
+ cell: ({ getValue }) => {
10839
+ return getValue() ?? "-";
10840
+ },
10841
+ enableSorting: true
10842
+ }),
10843
+ columnHelper.accessor("updated_at", {
10844
+ header: "Updated",
10845
+ cell: ({ getValue }) => {
10846
+ return /* @__PURE__ */ jsxRuntime.jsx(
10847
+ ui.Tooltip,
10848
+ {
10849
+ content: getFullDate({ date: getValue(), includeTime: true }),
10850
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10851
+ }
10852
+ );
10853
+ },
10854
+ enableSorting: true,
10855
+ sortAscLabel: "Oldest first",
10856
+ sortDescLabel: "Newest first"
10857
+ }),
10858
+ columnHelper.accessor("created_at", {
10859
+ header: "Created",
10860
+ cell: ({ getValue }) => {
10861
+ return /* @__PURE__ */ jsxRuntime.jsx(
10862
+ ui.Tooltip,
10863
+ {
10864
+ content: getFullDate({ date: getValue(), includeTime: true }),
10865
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10866
+ }
10867
+ );
10868
+ },
10869
+ enableSorting: true,
10870
+ sortAscLabel: "Oldest first",
10871
+ sortDescLabel: "Newest first"
10872
+ })
11115
10873
  ];
11116
- }
11117
- return Object.entries(metadata).map(([key, value]) => {
11118
- if (!EDITABLE_TYPES.includes(typeof value)) {
11119
- return {
11120
- key,
11121
- value,
11122
- disabled: true
11123
- };
11124
- }
11125
- let stringValue = value;
11126
- if (typeof value !== "string") {
11127
- stringValue = JSON.stringify(value);
11128
- }
11129
- return {
11130
- key,
11131
- value: stringValue,
11132
- original_key: key
11133
- };
10874
+ }, []);
10875
+ };
10876
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10877
+ const { setIsOpen } = useStackedModal();
10878
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10879
+ const form = reactHookForm.useForm({
10880
+ defaultValues: {
10881
+ title: "",
10882
+ quantity: 1,
10883
+ unit_price: ""
10884
+ },
10885
+ resolver: zod.zodResolver(customItemSchema)
11134
10886
  });
11135
- }
11136
- function parseValues(values) {
11137
- const metadata = values.metadata;
11138
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11139
- if (isEmpty) {
11140
- return null;
11141
- }
11142
- const update = {};
11143
- metadata.forEach((field) => {
11144
- let key = field.key;
11145
- let value = field.value;
11146
- const disabled = field.disabled;
11147
- if (!key || !value) {
11148
- return;
11149
- }
11150
- if (disabled) {
11151
- update[key] = value;
11152
- return;
11153
- }
11154
- key = key.trim();
11155
- value = value.trim();
11156
- if (value === "true") {
11157
- update[key] = true;
11158
- } else if (value === "false") {
11159
- update[key] = false;
11160
- } else {
11161
- const parsedNumber = parseFloat(value);
11162
- if (!isNaN(parsedNumber)) {
11163
- update[key] = parsedNumber;
11164
- } else {
11165
- update[key] = value;
10887
+ const onSubmit = form.handleSubmit(async (data) => {
10888
+ await addItems(
10889
+ {
10890
+ items: [
10891
+ {
10892
+ title: data.title,
10893
+ quantity: data.quantity,
10894
+ unit_price: convertNumber(data.unit_price)
10895
+ }
10896
+ ]
10897
+ },
10898
+ {
10899
+ onSuccess: () => {
10900
+ setIsOpen(STACKED_MODAL_ID, false);
10901
+ },
10902
+ onError: (e) => {
10903
+ ui.toast.error(e.message);
10904
+ }
11166
10905
  }
11167
- }
10906
+ );
11168
10907
  });
11169
- return update;
11170
- }
11171
- function getHasUneditableRows(metadata) {
11172
- if (!metadata) {
11173
- return false;
11174
- }
11175
- return Object.values(metadata).some(
11176
- (value) => !EDITABLE_TYPES.includes(typeof value)
11177
- );
11178
- }
10908
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10909
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10910
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10911
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10912
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10913
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.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." }) })
10914
+ ] }),
10915
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10916
+ /* @__PURE__ */ jsxRuntime.jsx(
10917
+ Form$2.Field,
10918
+ {
10919
+ control: form.control,
10920
+ name: "title",
10921
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10922
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10923
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10924
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10925
+ ] }),
10926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10927
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10928
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10929
+ ] })
10930
+ ] }) })
10931
+ }
10932
+ ),
10933
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10934
+ /* @__PURE__ */ jsxRuntime.jsx(
10935
+ Form$2.Field,
10936
+ {
10937
+ control: form.control,
10938
+ name: "unit_price",
10939
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10940
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10941
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10942
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10943
+ ] }),
10944
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10946
+ ui.CurrencyInput,
10947
+ {
10948
+ symbol: getNativeSymbol(currencyCode),
10949
+ code: currencyCode,
10950
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10951
+ ...field
10952
+ }
10953
+ ) }),
10954
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10955
+ ] })
10956
+ ] }) })
10957
+ }
10958
+ ),
10959
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10960
+ /* @__PURE__ */ jsxRuntime.jsx(
10961
+ Form$2.Field,
10962
+ {
10963
+ control: form.control,
10964
+ name: "quantity",
10965
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10966
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10967
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10968
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10969
+ ] }),
10970
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10972
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10973
+ ] })
10974
+ ] }) })
10975
+ }
10976
+ )
10977
+ ] }) }) }),
10978
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10979
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10980
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10981
+ ] }) })
10982
+ ] }) }) });
10983
+ };
10984
+ const customItemSchema = objectType({
10985
+ title: stringType().min(1),
10986
+ quantity: numberType(),
10987
+ unit_price: unionType([numberType(), stringType()])
10988
+ });
11179
10989
  const PROMOTION_QUERY_KEY = "promotions";
11180
10990
  const promotionsQueryKeys = {
11181
10991
  list: (query2) => [
@@ -11481,7 +11291,7 @@ const SalesChannelForm = ({ order }) => {
11481
11291
  defaultValues: {
11482
11292
  sales_channel_id: order.sales_channel_id || ""
11483
11293
  },
11484
- resolver: zod.zodResolver(schema$2)
11294
+ resolver: zod.zodResolver(schema$3)
11485
11295
  });
11486
11296
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11487
11297
  const { handleSuccess } = useRouteModal();
@@ -11516,49 +11326,252 @@ const SalesChannelForm = ({ order }) => {
11516
11326
  }
11517
11327
  ) });
11518
11328
  };
11519
- const SalesChannelField = ({ control, order }) => {
11520
- const salesChannels = useComboboxData({
11521
- queryFn: async (params) => {
11522
- return await sdk.admin.salesChannel.list(params);
11523
- },
11524
- queryKey: ["sales-channels"],
11525
- getOptions: (data) => {
11526
- return data.sales_channels.map((salesChannel) => ({
11527
- label: salesChannel.name,
11528
- value: salesChannel.id
11529
- }));
11530
- },
11531
- defaultValue: order.sales_channel_id || void 0
11532
- });
11533
- return /* @__PURE__ */ jsxRuntime.jsx(
11534
- Form$2.Field,
11535
- {
11536
- control,
11537
- name: "sales_channel_id",
11538
- render: ({ field }) => {
11539
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11541
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11542
- Combobox,
11543
- {
11544
- options: salesChannels.options,
11545
- fetchNextPage: salesChannels.fetchNextPage,
11546
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11547
- searchValue: salesChannels.searchValue,
11548
- onSearchValueChange: salesChannels.onSearchValueChange,
11549
- placeholder: "Select sales channel",
11550
- ...field
11551
- }
11552
- ) }),
11553
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11554
- ] });
11555
- }
11556
- }
11557
- );
11558
- };
11559
- const schema$2 = objectType({
11560
- sales_channel_id: stringType().min(1)
11561
- });
11329
+ const SalesChannelField = ({ control, order }) => {
11330
+ const salesChannels = useComboboxData({
11331
+ queryFn: async (params) => {
11332
+ return await sdk.admin.salesChannel.list(params);
11333
+ },
11334
+ queryKey: ["sales-channels"],
11335
+ getOptions: (data) => {
11336
+ return data.sales_channels.map((salesChannel) => ({
11337
+ label: salesChannel.name,
11338
+ value: salesChannel.id
11339
+ }));
11340
+ },
11341
+ defaultValue: order.sales_channel_id || void 0
11342
+ });
11343
+ return /* @__PURE__ */ jsxRuntime.jsx(
11344
+ Form$2.Field,
11345
+ {
11346
+ control,
11347
+ name: "sales_channel_id",
11348
+ render: ({ field }) => {
11349
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11350
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11351
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11352
+ Combobox,
11353
+ {
11354
+ options: salesChannels.options,
11355
+ fetchNextPage: salesChannels.fetchNextPage,
11356
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11357
+ searchValue: salesChannels.searchValue,
11358
+ onSearchValueChange: salesChannels.onSearchValueChange,
11359
+ placeholder: "Select sales channel",
11360
+ ...field
11361
+ }
11362
+ ) }),
11363
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11364
+ ] });
11365
+ }
11366
+ }
11367
+ );
11368
+ };
11369
+ const schema$3 = objectType({
11370
+ sales_channel_id: stringType().min(1)
11371
+ });
11372
+ const ShippingAddress = () => {
11373
+ const { id } = reactRouterDom.useParams();
11374
+ const { order, isPending, isError, error } = useOrder(id, {
11375
+ fields: "+shipping_address"
11376
+ });
11377
+ if (isError) {
11378
+ throw error;
11379
+ }
11380
+ const isReady = !isPending && !!order;
11381
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11382
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11383
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11384
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11385
+ ] }),
11386
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11387
+ ] });
11388
+ };
11389
+ const ShippingAddressForm = ({ order }) => {
11390
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11391
+ const form = reactHookForm.useForm({
11392
+ defaultValues: {
11393
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11394
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11395
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11396
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11397
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11398
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11399
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11400
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11401
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11402
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11403
+ },
11404
+ resolver: zod.zodResolver(schema$2)
11405
+ });
11406
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11407
+ const { handleSuccess } = useRouteModal();
11408
+ const onSubmit = form.handleSubmit(async (data) => {
11409
+ await mutateAsync(
11410
+ {
11411
+ shipping_address: {
11412
+ first_name: data.first_name,
11413
+ last_name: data.last_name,
11414
+ company: data.company,
11415
+ address_1: data.address_1,
11416
+ address_2: data.address_2,
11417
+ city: data.city,
11418
+ province: data.province,
11419
+ country_code: data.country_code,
11420
+ postal_code: data.postal_code,
11421
+ phone: data.phone
11422
+ }
11423
+ },
11424
+ {
11425
+ onSuccess: () => {
11426
+ handleSuccess();
11427
+ },
11428
+ onError: (error) => {
11429
+ ui.toast.error(error.message);
11430
+ }
11431
+ }
11432
+ );
11433
+ });
11434
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11435
+ KeyboundForm,
11436
+ {
11437
+ className: "flex flex-1 flex-col overflow-hidden",
11438
+ onSubmit,
11439
+ children: [
11440
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11441
+ /* @__PURE__ */ jsxRuntime.jsx(
11442
+ Form$2.Field,
11443
+ {
11444
+ control: form.control,
11445
+ name: "country_code",
11446
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11447
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11448
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11449
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11450
+ ] })
11451
+ }
11452
+ ),
11453
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11454
+ /* @__PURE__ */ jsxRuntime.jsx(
11455
+ Form$2.Field,
11456
+ {
11457
+ control: form.control,
11458
+ name: "first_name",
11459
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11460
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11461
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11462
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11463
+ ] })
11464
+ }
11465
+ ),
11466
+ /* @__PURE__ */ jsxRuntime.jsx(
11467
+ Form$2.Field,
11468
+ {
11469
+ control: form.control,
11470
+ name: "last_name",
11471
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11473
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11474
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11475
+ ] })
11476
+ }
11477
+ )
11478
+ ] }),
11479
+ /* @__PURE__ */ jsxRuntime.jsx(
11480
+ Form$2.Field,
11481
+ {
11482
+ control: form.control,
11483
+ name: "company",
11484
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11485
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11486
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11487
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11488
+ ] })
11489
+ }
11490
+ ),
11491
+ /* @__PURE__ */ jsxRuntime.jsx(
11492
+ Form$2.Field,
11493
+ {
11494
+ control: form.control,
11495
+ name: "address_1",
11496
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11497
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11498
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11499
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11500
+ ] })
11501
+ }
11502
+ ),
11503
+ /* @__PURE__ */ jsxRuntime.jsx(
11504
+ Form$2.Field,
11505
+ {
11506
+ control: form.control,
11507
+ name: "address_2",
11508
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11509
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11510
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11512
+ ] })
11513
+ }
11514
+ ),
11515
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11516
+ /* @__PURE__ */ jsxRuntime.jsx(
11517
+ Form$2.Field,
11518
+ {
11519
+ control: form.control,
11520
+ name: "postal_code",
11521
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11522
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11523
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11524
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11525
+ ] })
11526
+ }
11527
+ ),
11528
+ /* @__PURE__ */ jsxRuntime.jsx(
11529
+ Form$2.Field,
11530
+ {
11531
+ control: form.control,
11532
+ name: "city",
11533
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11534
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11535
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11536
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11537
+ ] })
11538
+ }
11539
+ )
11540
+ ] }),
11541
+ /* @__PURE__ */ jsxRuntime.jsx(
11542
+ Form$2.Field,
11543
+ {
11544
+ control: form.control,
11545
+ name: "province",
11546
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11547
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11548
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11549
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11550
+ ] })
11551
+ }
11552
+ ),
11553
+ /* @__PURE__ */ jsxRuntime.jsx(
11554
+ Form$2.Field,
11555
+ {
11556
+ control: form.control,
11557
+ name: "phone",
11558
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11559
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11560
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11561
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11562
+ ] })
11563
+ }
11564
+ )
11565
+ ] }) }),
11566
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11567
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11568
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11569
+ ] }) })
11570
+ ]
11571
+ }
11572
+ ) });
11573
+ };
11574
+ const schema$2 = addressSchema;
11562
11575
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11563
11576
  const Shipping = () => {
11564
11577
  var _a;
@@ -12349,226 +12362,23 @@ const CustomAmountField = ({
12349
12362
  render: ({ field: { onChange, ...field } }) => {
12350
12363
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12351
12364
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12354
- ] }),
12355
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12356
- ui.CurrencyInput,
12357
- {
12358
- ...field,
12359
- onValueChange: (value) => onChange(value),
12360
- symbol: getNativeSymbol(currencyCode),
12361
- code: currencyCode
12362
- }
12363
- ) })
12364
- ] });
12365
- }
12366
- }
12367
- );
12368
- };
12369
- const ShippingAddress = () => {
12370
- const { id } = reactRouterDom.useParams();
12371
- const { order, isPending, isError, error } = useOrder(id, {
12372
- fields: "+shipping_address"
12373
- });
12374
- if (isError) {
12375
- throw error;
12376
- }
12377
- const isReady = !isPending && !!order;
12378
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12379
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12380
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12381
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12382
- ] }),
12383
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12384
- ] });
12385
- };
12386
- const ShippingAddressForm = ({ order }) => {
12387
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12388
- const form = reactHookForm.useForm({
12389
- defaultValues: {
12390
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12391
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12392
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12393
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12394
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12395
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12396
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12397
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12398
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12399
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12400
- },
12401
- resolver: zod.zodResolver(schema$1)
12402
- });
12403
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12404
- const { handleSuccess } = useRouteModal();
12405
- const onSubmit = form.handleSubmit(async (data) => {
12406
- await mutateAsync(
12407
- {
12408
- shipping_address: {
12409
- first_name: data.first_name,
12410
- last_name: data.last_name,
12411
- company: data.company,
12412
- address_1: data.address_1,
12413
- address_2: data.address_2,
12414
- city: data.city,
12415
- province: data.province,
12416
- country_code: data.country_code,
12417
- postal_code: data.postal_code,
12418
- phone: data.phone
12419
- }
12420
- },
12421
- {
12422
- onSuccess: () => {
12423
- handleSuccess();
12424
- },
12425
- onError: (error) => {
12426
- ui.toast.error(error.message);
12427
- }
12428
- }
12429
- );
12430
- });
12431
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12432
- KeyboundForm,
12433
- {
12434
- className: "flex flex-1 flex-col overflow-hidden",
12435
- onSubmit,
12436
- children: [
12437
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12438
- /* @__PURE__ */ jsxRuntime.jsx(
12439
- Form$2.Field,
12440
- {
12441
- control: form.control,
12442
- name: "country_code",
12443
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12444
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12445
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12446
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12447
- ] })
12448
- }
12449
- ),
12450
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12451
- /* @__PURE__ */ jsxRuntime.jsx(
12452
- Form$2.Field,
12453
- {
12454
- control: form.control,
12455
- name: "first_name",
12456
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12457
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12458
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12459
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12460
- ] })
12461
- }
12462
- ),
12463
- /* @__PURE__ */ jsxRuntime.jsx(
12464
- Form$2.Field,
12465
- {
12466
- control: form.control,
12467
- name: "last_name",
12468
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12469
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12470
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12471
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12472
- ] })
12473
- }
12474
- )
12475
- ] }),
12476
- /* @__PURE__ */ jsxRuntime.jsx(
12477
- Form$2.Field,
12478
- {
12479
- control: form.control,
12480
- name: "company",
12481
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12482
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12483
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12484
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12485
- ] })
12486
- }
12487
- ),
12488
- /* @__PURE__ */ jsxRuntime.jsx(
12489
- Form$2.Field,
12490
- {
12491
- control: form.control,
12492
- name: "address_1",
12493
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12494
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12495
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12496
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12497
- ] })
12498
- }
12499
- ),
12500
- /* @__PURE__ */ jsxRuntime.jsx(
12501
- Form$2.Field,
12502
- {
12503
- control: form.control,
12504
- name: "address_2",
12505
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12506
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12507
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12508
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12509
- ] })
12510
- }
12511
- ),
12512
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12513
- /* @__PURE__ */ jsxRuntime.jsx(
12514
- Form$2.Field,
12515
- {
12516
- control: form.control,
12517
- name: "postal_code",
12518
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12519
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12521
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12522
- ] })
12523
- }
12524
- ),
12525
- /* @__PURE__ */ jsxRuntime.jsx(
12526
- Form$2.Field,
12527
- {
12528
- control: form.control,
12529
- name: "city",
12530
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12534
- ] })
12535
- }
12536
- )
12365
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12366
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12537
12367
  ] }),
12538
- /* @__PURE__ */ jsxRuntime.jsx(
12539
- Form$2.Field,
12540
- {
12541
- control: form.control,
12542
- name: "province",
12543
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12546
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12547
- ] })
12548
- }
12549
- ),
12550
- /* @__PURE__ */ jsxRuntime.jsx(
12551
- Form$2.Field,
12368
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12369
+ ui.CurrencyInput,
12552
12370
  {
12553
- control: form.control,
12554
- name: "phone",
12555
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12558
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12559
- ] })
12371
+ ...field,
12372
+ onValueChange: (value) => onChange(value),
12373
+ symbol: getNativeSymbol(currencyCode),
12374
+ code: currencyCode
12560
12375
  }
12561
- )
12562
- ] }) }),
12563
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12564
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12565
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12566
- ] }) })
12567
- ]
12376
+ ) })
12377
+ ] });
12378
+ }
12568
12379
  }
12569
- ) });
12380
+ );
12570
12381
  };
12571
- const schema$1 = addressSchema;
12572
12382
  const TransferOwnership = () => {
12573
12383
  const { id } = reactRouterDom.useParams();
12574
12384
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12592,7 +12402,7 @@ const TransferOwnershipForm = ({ order }) => {
12592
12402
  defaultValues: {
12593
12403
  customer_id: order.customer_id || ""
12594
12404
  },
12595
- resolver: zod.zodResolver(schema)
12405
+ resolver: zod.zodResolver(schema$1)
12596
12406
  });
12597
12407
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12598
12408
  const { handleSuccess } = useRouteModal();
@@ -13042,9 +12852,199 @@ const Illustration = () => {
13042
12852
  }
13043
12853
  );
13044
12854
  };
13045
- const schema = objectType({
12855
+ const schema$1 = objectType({
13046
12856
  customer_id: stringType().min(1)
13047
12857
  });
12858
+ const BillingAddress = () => {
12859
+ const { id } = reactRouterDom.useParams();
12860
+ const { order, isPending, isError, error } = useOrder(id, {
12861
+ fields: "+billing_address"
12862
+ });
12863
+ if (isError) {
12864
+ throw error;
12865
+ }
12866
+ const isReady = !isPending && !!order;
12867
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12868
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12869
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12870
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12871
+ ] }),
12872
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12873
+ ] });
12874
+ };
12875
+ const BillingAddressForm = ({ order }) => {
12876
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12877
+ const form = reactHookForm.useForm({
12878
+ defaultValues: {
12879
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12880
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12881
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12882
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12883
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12884
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12885
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12886
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12887
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12888
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12889
+ },
12890
+ resolver: zod.zodResolver(schema)
12891
+ });
12892
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12893
+ const { handleSuccess } = useRouteModal();
12894
+ const onSubmit = form.handleSubmit(async (data) => {
12895
+ await mutateAsync(
12896
+ { billing_address: data },
12897
+ {
12898
+ onSuccess: () => {
12899
+ handleSuccess();
12900
+ },
12901
+ onError: (error) => {
12902
+ ui.toast.error(error.message);
12903
+ }
12904
+ }
12905
+ );
12906
+ });
12907
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12908
+ KeyboundForm,
12909
+ {
12910
+ className: "flex flex-1 flex-col overflow-hidden",
12911
+ onSubmit,
12912
+ children: [
12913
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "country_code",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12927
+ /* @__PURE__ */ jsxRuntime.jsx(
12928
+ Form$2.Field,
12929
+ {
12930
+ control: form.control,
12931
+ name: "first_name",
12932
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12935
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12936
+ ] })
12937
+ }
12938
+ ),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(
12940
+ Form$2.Field,
12941
+ {
12942
+ control: form.control,
12943
+ name: "last_name",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12949
+ }
12950
+ )
12951
+ ] }),
12952
+ /* @__PURE__ */ jsxRuntime.jsx(
12953
+ Form$2.Field,
12954
+ {
12955
+ control: form.control,
12956
+ name: "company",
12957
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12960
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12961
+ ] })
12962
+ }
12963
+ ),
12964
+ /* @__PURE__ */ jsxRuntime.jsx(
12965
+ Form$2.Field,
12966
+ {
12967
+ control: form.control,
12968
+ name: "address_1",
12969
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12972
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12973
+ ] })
12974
+ }
12975
+ ),
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "address_2",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12989
+ /* @__PURE__ */ jsxRuntime.jsx(
12990
+ Form$2.Field,
12991
+ {
12992
+ control: form.control,
12993
+ name: "postal_code",
12994
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12997
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12998
+ ] })
12999
+ }
13000
+ ),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13003
+ {
13004
+ control: form.control,
13005
+ name: "city",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13011
+ }
13012
+ )
13013
+ ] }),
13014
+ /* @__PURE__ */ jsxRuntime.jsx(
13015
+ Form$2.Field,
13016
+ {
13017
+ control: form.control,
13018
+ name: "province",
13019
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13022
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13023
+ ] })
13024
+ }
13025
+ ),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(
13027
+ Form$2.Field,
13028
+ {
13029
+ control: form.control,
13030
+ name: "phone",
13031
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13034
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13035
+ ] })
13036
+ }
13037
+ )
13038
+ ] }) }),
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13042
+ ] }) })
13043
+ ]
13044
+ }
13045
+ ) });
13046
+ };
13047
+ const schema = addressSchema;
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,10 +13065,6 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
- {
13069
- Component: BillingAddress,
13070
- path: "/draft-orders/:id/billing-address"
13071
- },
13072
13068
  {
13073
13069
  Component: CustomItems,
13074
13070
  path: "/draft-orders/:id/custom-items"
@@ -13077,14 +13073,14 @@ const routeModule = {
13077
13073
  Component: Email,
13078
13074
  path: "/draft-orders/:id/email"
13079
13075
  },
13080
- {
13081
- Component: Items,
13082
- path: "/draft-orders/:id/items"
13083
- },
13084
13076
  {
13085
13077
  Component: Metadata,
13086
13078
  path: "/draft-orders/:id/metadata"
13087
13079
  },
13080
+ {
13081
+ Component: Items,
13082
+ path: "/draft-orders/:id/items"
13083
+ },
13088
13084
  {
13089
13085
  Component: Promotions,
13090
13086
  path: "/draft-orders/:id/promotions"
@@ -13093,17 +13089,21 @@ const routeModule = {
13093
13089
  Component: SalesChannel,
13094
13090
  path: "/draft-orders/:id/sales-channel"
13095
13091
  },
13096
- {
13097
- Component: Shipping,
13098
- path: "/draft-orders/:id/shipping"
13099
- },
13100
13092
  {
13101
13093
  Component: ShippingAddress,
13102
13094
  path: "/draft-orders/:id/shipping-address"
13103
13095
  },
13096
+ {
13097
+ Component: Shipping,
13098
+ path: "/draft-orders/:id/shipping"
13099
+ },
13104
13100
  {
13105
13101
  Component: TransferOwnership,
13106
13102
  path: "/draft-orders/:id/transfer-ownership"
13103
+ },
13104
+ {
13105
+ Component: BillingAddress,
13106
+ path: "/draft-orders/:id/billing-address"
13107
13107
  }
13108
13108
  ]
13109
13109
  }