@medusajs/draft-order 2.10.1-snapshot-20250828200335 → 2.10.1-snapshot-20250828200637

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