@medusajs/draft-order 2.10.4-preview-20250929090207 → 2.10.4-preview-20250929150148

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9573,6 +9573,196 @@ const ID = () => {
9573
9573
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9574
  ] });
9575
9575
  };
9576
+ const BillingAddress = () => {
9577
+ const { id } = reactRouterDom.useParams();
9578
+ const { order, isPending, isError, error } = useOrder(id, {
9579
+ fields: "+billing_address"
9580
+ });
9581
+ if (isError) {
9582
+ throw error;
9583
+ }
9584
+ const isReady = !isPending && !!order;
9585
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9586
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9589
+ ] }),
9590
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9591
+ ] });
9592
+ };
9593
+ const BillingAddressForm = ({ order }) => {
9594
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9595
+ const form = reactHookForm.useForm({
9596
+ defaultValues: {
9597
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9598
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9599
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9600
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9601
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9602
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9603
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9604
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9605
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9606
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9607
+ },
9608
+ resolver: zod.zodResolver(schema$5)
9609
+ });
9610
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9611
+ const { handleSuccess } = useRouteModal();
9612
+ const onSubmit = form.handleSubmit(async (data) => {
9613
+ await mutateAsync(
9614
+ { billing_address: data },
9615
+ {
9616
+ onSuccess: () => {
9617
+ handleSuccess();
9618
+ },
9619
+ onError: (error) => {
9620
+ ui.toast.error(error.message);
9621
+ }
9622
+ }
9623
+ );
9624
+ });
9625
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9626
+ KeyboundForm,
9627
+ {
9628
+ className: "flex flex-1 flex-col overflow-hidden",
9629
+ onSubmit,
9630
+ children: [
9631
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
9632
+ /* @__PURE__ */ jsxRuntime.jsx(
9633
+ Form$2.Field,
9634
+ {
9635
+ control: form.control,
9636
+ name: "country_code",
9637
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9639
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9640
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9641
+ ] })
9642
+ }
9643
+ ),
9644
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9645
+ /* @__PURE__ */ jsxRuntime.jsx(
9646
+ Form$2.Field,
9647
+ {
9648
+ control: form.control,
9649
+ name: "first_name",
9650
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9653
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9654
+ ] })
9655
+ }
9656
+ ),
9657
+ /* @__PURE__ */ jsxRuntime.jsx(
9658
+ Form$2.Field,
9659
+ {
9660
+ control: form.control,
9661
+ name: "last_name",
9662
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9664
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9665
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9666
+ ] })
9667
+ }
9668
+ )
9669
+ ] }),
9670
+ /* @__PURE__ */ jsxRuntime.jsx(
9671
+ Form$2.Field,
9672
+ {
9673
+ control: form.control,
9674
+ name: "company",
9675
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9678
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9679
+ ] })
9680
+ }
9681
+ ),
9682
+ /* @__PURE__ */ jsxRuntime.jsx(
9683
+ Form$2.Field,
9684
+ {
9685
+ control: form.control,
9686
+ name: "address_1",
9687
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9689
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9690
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9691
+ ] })
9692
+ }
9693
+ ),
9694
+ /* @__PURE__ */ jsxRuntime.jsx(
9695
+ Form$2.Field,
9696
+ {
9697
+ control: form.control,
9698
+ name: "address_2",
9699
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9702
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9703
+ ] })
9704
+ }
9705
+ ),
9706
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9707
+ /* @__PURE__ */ jsxRuntime.jsx(
9708
+ Form$2.Field,
9709
+ {
9710
+ control: form.control,
9711
+ name: "postal_code",
9712
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9715
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9716
+ ] })
9717
+ }
9718
+ ),
9719
+ /* @__PURE__ */ jsxRuntime.jsx(
9720
+ Form$2.Field,
9721
+ {
9722
+ control: form.control,
9723
+ name: "city",
9724
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9727
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
+ ] })
9729
+ }
9730
+ )
9731
+ ] }),
9732
+ /* @__PURE__ */ jsxRuntime.jsx(
9733
+ Form$2.Field,
9734
+ {
9735
+ control: form.control,
9736
+ name: "province",
9737
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
+ ] })
9742
+ }
9743
+ ),
9744
+ /* @__PURE__ */ jsxRuntime.jsx(
9745
+ Form$2.Field,
9746
+ {
9747
+ control: form.control,
9748
+ name: "phone",
9749
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
+ ] })
9754
+ }
9755
+ )
9756
+ ] }) }),
9757
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9758
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9759
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9760
+ ] }) })
9761
+ ]
9762
+ }
9763
+ ) });
9764
+ };
9765
+ const schema$5 = addressSchema;
9576
9766
  const CustomItems = () => {
9577
9767
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
9768
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
@@ -9581,7 +9771,7 @@ const CustomItems = () => {
9581
9771
  };
9582
9772
  const CustomItemsForm = () => {
9583
9773
  const form = reactHookForm.useForm({
9584
- resolver: zod.zodResolver(schema$5)
9774
+ resolver: zod.zodResolver(schema$4)
9585
9775
  });
9586
9776
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
9777
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9591,7 +9781,7 @@ const CustomItemsForm = () => {
9591
9781
  ] }) })
9592
9782
  ] }) });
9593
9783
  };
9594
- const schema$5 = objectType({
9784
+ const schema$4 = objectType({
9595
9785
  email: stringType().email()
9596
9786
  });
9597
9787
  const Email = () => {
@@ -9616,7 +9806,7 @@ const EmailForm = ({ order }) => {
9616
9806
  defaultValues: {
9617
9807
  email: order.email ?? ""
9618
9808
  },
9619
- resolver: zod.zodResolver(schema$4)
9809
+ resolver: zod.zodResolver(schema$3)
9620
9810
  });
9621
9811
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9622
9812
  const { handleSuccess } = useRouteModal();
@@ -9659,681 +9849,1031 @@ const EmailForm = ({ order }) => {
9659
9849
  }
9660
9850
  ) });
9661
9851
  };
9662
- const schema$4 = objectType({
9852
+ const schema$3 = objectType({
9663
9853
  email: stringType().email()
9664
9854
  });
9665
- const NumberInput = React.forwardRef(
9666
- ({
9667
- value,
9668
- onChange,
9669
- size = "base",
9670
- min = 0,
9671
- max = 100,
9672
- step = 1,
9673
- className,
9674
- disabled,
9675
- ...props
9676
- }, ref) => {
9677
- const handleChange = (event) => {
9678
- const newValue = event.target.value === "" ? min : Number(event.target.value);
9679
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9680
- onChange(newValue);
9681
- }
9682
- };
9683
- const handleIncrement = () => {
9684
- const newValue = value + step;
9685
- if (max === void 0 || newValue <= max) {
9686
- onChange(newValue);
9687
- }
9688
- };
9689
- const handleDecrement = () => {
9690
- const newValue = value - step;
9691
- if (min === void 0 || newValue >= min) {
9692
- onChange(newValue);
9693
- }
9694
- };
9855
+ const InlineTip = React.forwardRef(
9856
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
9857
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9695
9858
  return /* @__PURE__ */ jsxRuntime.jsxs(
9696
9859
  "div",
9697
9860
  {
9861
+ ref,
9698
9862
  className: ui.clx(
9699
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9700
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9701
- {
9702
- "h-7": size === "small",
9703
- "h-8": size === "base"
9704
- },
9863
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9705
9864
  className
9706
9865
  ),
9866
+ ...props,
9707
9867
  children: [
9708
9868
  /* @__PURE__ */ jsxRuntime.jsx(
9709
- "input",
9869
+ "div",
9710
9870
  {
9711
- ref,
9712
- type: "number",
9713
- value,
9714
- onChange: handleChange,
9715
- min,
9716
- max,
9717
- step,
9718
- className: ui.clx(
9719
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9720
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9721
- "placeholder:text-ui-fg-muted"
9722
- ),
9723
- ...props
9724
- }
9725
- ),
9726
- /* @__PURE__ */ jsxRuntime.jsxs(
9727
- "button",
9728
- {
9729
- className: ui.clx(
9730
- "flex items-center justify-center outline-none transition-fg",
9731
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9732
- "focus:bg-ui-bg-field-component-hover",
9733
- "hover:bg-ui-bg-field-component-hover",
9734
- {
9735
- "size-7": size === "small",
9736
- "size-8": size === "base"
9737
- }
9738
- ),
9739
- type: "button",
9740
- onClick: handleDecrement,
9741
- disabled: min !== void 0 && value <= min || disabled,
9742
- children: [
9743
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9744
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9745
- ]
9871
+ role: "presentation",
9872
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9873
+ "bg-ui-tag-orange-icon": variant === "warning"
9874
+ })
9746
9875
  }
9747
9876
  ),
9748
- /* @__PURE__ */ jsxRuntime.jsxs(
9749
- "button",
9750
- {
9751
- className: ui.clx(
9752
- "flex items-center justify-center outline-none transition-fg",
9753
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9754
- "focus:bg-ui-bg-field-hover",
9755
- "hover:bg-ui-bg-field-hover",
9756
- {
9757
- "size-7": size === "small",
9758
- "size-8": size === "base"
9759
- }
9760
- ),
9761
- type: "button",
9762
- onClick: handleIncrement,
9763
- disabled: max !== void 0 && value >= max || disabled,
9764
- children: [
9765
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9766
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9767
- ]
9768
- }
9769
- )
9877
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9878
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9879
+ labelValue,
9880
+ ":"
9881
+ ] }),
9882
+ " ",
9883
+ children
9884
+ ] })
9770
9885
  ]
9771
9886
  }
9772
9887
  );
9773
9888
  }
9774
9889
  );
9775
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9776
- const productVariantsQueryKeys = {
9777
- list: (query2) => [
9778
- PRODUCT_VARIANTS_QUERY_KEY,
9779
- query2 ? query2 : void 0
9780
- ]
9781
- };
9782
- const useProductVariants = (query2, options) => {
9783
- const { data, ...rest } = reactQuery.useQuery({
9784
- queryKey: productVariantsQueryKeys.list(query2),
9785
- queryFn: async () => await sdk.admin.productVariant.list(query2),
9786
- ...options
9787
- });
9788
- return { ...data, ...rest };
9789
- };
9790
- const useCancelOrderEdit = ({ preview }) => {
9791
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9792
- const onCancel = React.useCallback(async () => {
9793
- if (!preview) {
9794
- return true;
9795
- }
9796
- let res = false;
9797
- await cancelOrderEdit(void 0, {
9798
- onError: (e) => {
9799
- ui.toast.error(e.message);
9800
- },
9801
- onSuccess: () => {
9802
- res = true;
9803
- }
9804
- });
9805
- return res;
9806
- }, [preview, cancelOrderEdit]);
9807
- return { onCancel };
9808
- };
9809
- let IS_REQUEST_RUNNING = false;
9810
- const useInitiateOrderEdit = ({
9811
- preview
9812
- }) => {
9813
- const navigate = reactRouterDom.useNavigate();
9814
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9815
- React.useEffect(() => {
9816
- async function run() {
9817
- if (IS_REQUEST_RUNNING || !preview) {
9818
- return;
9819
- }
9820
- if (preview.order_change) {
9821
- return;
9822
- }
9823
- IS_REQUEST_RUNNING = true;
9824
- await mutateAsync(void 0, {
9825
- onError: (e) => {
9826
- ui.toast.error(e.message);
9827
- navigate(`/draft-orders/${preview.id}`, { replace: true });
9828
- return;
9829
- }
9830
- });
9831
- IS_REQUEST_RUNNING = false;
9832
- }
9833
- run();
9834
- }, [preview, navigate, mutateAsync]);
9835
- };
9836
- function convertNumber(value) {
9837
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
9838
- }
9839
- const STACKED_MODAL_ID = "items_stacked_modal";
9840
- const Items = () => {
9890
+ InlineTip.displayName = "InlineTip";
9891
+ const MetadataFieldSchema = objectType({
9892
+ key: stringType(),
9893
+ disabled: booleanType().optional(),
9894
+ value: anyType()
9895
+ });
9896
+ const MetadataSchema = objectType({
9897
+ metadata: arrayType(MetadataFieldSchema)
9898
+ });
9899
+ const Metadata = () => {
9841
9900
  const { id } = reactRouterDom.useParams();
9842
- const {
9843
- order: preview,
9844
- isPending: isPreviewPending,
9845
- isError: isPreviewError,
9846
- error: previewError
9847
- } = useOrderPreview(id, void 0, {
9848
- placeholderData: reactQuery.keepPreviousData
9901
+ const { order, isPending, isError, error } = useOrder(id, {
9902
+ fields: "metadata"
9849
9903
  });
9850
- useInitiateOrderEdit({ preview });
9851
- const { draft_order, isPending, isError, error } = useDraftOrder(
9852
- id,
9853
- {
9854
- fields: "currency_code"
9855
- },
9856
- {
9857
- enabled: !!id
9858
- }
9859
- );
9860
- const { onCancel } = useCancelOrderEdit({ preview });
9861
9904
  if (isError) {
9862
9905
  throw error;
9863
9906
  }
9864
- if (isPreviewError) {
9865
- throw previewError;
9866
- }
9867
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
9868
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9869
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
9870
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
9871
- ] }) });
9907
+ const isReady = !isPending && !!order;
9908
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9909
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9910
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9911
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9912
+ ] }),
9913
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9914
+ ] });
9872
9915
  };
9873
- const ItemsForm = ({ preview, currencyCode }) => {
9874
- var _a;
9875
- const [isSubmitting, setIsSubmitting] = React.useState(false);
9876
- const [modalContent, setModalContent] = React.useState(
9877
- null
9878
- );
9916
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9917
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9918
+ const MetadataForm = ({ orderId, metadata }) => {
9879
9919
  const { handleSuccess } = useRouteModal();
9880
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
9881
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
9882
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
9883
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
9884
- const matches = React.useMemo(() => {
9885
- return matchSorter.matchSorter(preview.items, query2, {
9886
- keys: ["product_title", "variant_title", "variant_sku", "title"]
9887
- });
9888
- }, [preview.items, query2]);
9889
- const onSubmit = async () => {
9890
- setIsSubmitting(true);
9891
- let requestSucceeded = false;
9892
- await requestOrderEdit(void 0, {
9893
- onError: (e) => {
9894
- ui.toast.error(`Failed to request order edit: ${e.message}`);
9920
+ const hasUneditableRows = getHasUneditableRows(metadata);
9921
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9922
+ const form = reactHookForm.useForm({
9923
+ defaultValues: {
9924
+ metadata: getDefaultValues(metadata)
9925
+ },
9926
+ resolver: zod.zodResolver(MetadataSchema)
9927
+ });
9928
+ const handleSubmit = form.handleSubmit(async (data) => {
9929
+ const parsedData = parseValues(data);
9930
+ await mutateAsync(
9931
+ {
9932
+ metadata: parsedData
9895
9933
  },
9896
- onSuccess: () => {
9897
- requestSucceeded = true;
9934
+ {
9935
+ onSuccess: () => {
9936
+ ui.toast.success("Metadata updated");
9937
+ handleSuccess();
9938
+ },
9939
+ onError: (error) => {
9940
+ ui.toast.error(error.message);
9941
+ }
9898
9942
  }
9899
- });
9900
- if (!requestSucceeded) {
9901
- setIsSubmitting(false);
9902
- return;
9943
+ );
9944
+ });
9945
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
9946
+ control: form.control,
9947
+ name: "metadata"
9948
+ });
9949
+ function deleteRow(index) {
9950
+ remove(index);
9951
+ if (fields.length === 1) {
9952
+ insert(0, {
9953
+ key: "",
9954
+ value: "",
9955
+ disabled: false
9956
+ });
9903
9957
  }
9904
- await confirmOrderEdit(void 0, {
9905
- onError: (e) => {
9906
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
9907
- },
9908
- onSuccess: () => {
9909
- handleSuccess();
9910
- },
9911
- onSettled: () => {
9912
- setIsSubmitting(false);
9913
- }
9958
+ }
9959
+ function insertRow(index, position) {
9960
+ insert(index + (position === "above" ? 0 : 1), {
9961
+ key: "",
9962
+ value: "",
9963
+ disabled: false
9914
9964
  });
9915
- };
9916
- const onKeyDown = React.useCallback(
9917
- (e) => {
9918
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
9919
- if (modalContent || isSubmitting) {
9920
- return;
9921
- }
9922
- onSubmit();
9923
- }
9924
- },
9925
- [modalContent, isSubmitting, onSubmit]
9926
- );
9927
- React.useEffect(() => {
9928
- document.addEventListener("keydown", onKeyDown);
9929
- return () => {
9930
- document.removeEventListener("keydown", onKeyDown);
9931
- };
9932
- }, [onKeyDown]);
9933
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
9934
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
9935
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
9936
- StackedFocusModal,
9937
- {
9938
- id: STACKED_MODAL_ID,
9939
- onOpenChangeCallback: (open) => {
9940
- if (!open) {
9941
- setModalContent(null);
9942
- }
9943
- },
9944
- children: [
9945
- /* @__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: [
9946
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
9947
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
9948
- /* @__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" }) })
9965
+ }
9966
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9967
+ KeyboundForm,
9968
+ {
9969
+ onSubmit: handleSubmit,
9970
+ className: "flex flex-1 flex-col overflow-hidden",
9971
+ children: [
9972
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9973
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9974
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9975
+ /* @__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" }) }),
9976
+ /* @__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" }) })
9949
9977
  ] }),
9950
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
9951
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
9952
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
9953
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
9954
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
9955
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
9956
- ] }),
9957
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
9958
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
9959
- ui.Input,
9960
- {
9961
- type: "search",
9962
- placeholder: "Search items",
9963
- value: searchValue,
9964
- onChange: (e) => onSearchValueChange(e.target.value)
9965
- }
9966
- ) }),
9967
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9968
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
9969
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9978
+ fields.map((field, index) => {
9979
+ const isDisabled = field.disabled || false;
9980
+ let placeholder = "-";
9981
+ if (typeof field.value === "object") {
9982
+ placeholder = "{ ... }";
9983
+ }
9984
+ if (Array.isArray(field.value)) {
9985
+ placeholder = "[ ... ]";
9986
+ }
9987
+ return /* @__PURE__ */ jsxRuntime.jsx(
9988
+ ConditionalTooltip,
9989
+ {
9990
+ showTooltip: isDisabled,
9991
+ content: "This row is disabled because it contains non-primitive data.",
9992
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9993
+ /* @__PURE__ */ jsxRuntime.jsxs(
9994
+ "div",
9995
+ {
9996
+ className: ui.clx("grid grid-cols-2 divide-x", {
9997
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
9998
+ }),
9999
+ children: [
10000
+ /* @__PURE__ */ jsxRuntime.jsx(
10001
+ Form$2.Field,
10002
+ {
10003
+ control: form.control,
10004
+ name: `metadata.${index}.key`,
10005
+ render: ({ field: field2 }) => {
10006
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10007
+ GridInput,
10008
+ {
10009
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10010
+ ...field2,
10011
+ disabled: isDisabled,
10012
+ placeholder: "Key"
10013
+ }
10014
+ ) }) });
10015
+ }
10016
+ }
10017
+ ),
10018
+ /* @__PURE__ */ jsxRuntime.jsx(
10019
+ Form$2.Field,
10020
+ {
10021
+ control: form.control,
10022
+ name: `metadata.${index}.value`,
10023
+ render: ({ field: { value, ...field2 } }) => {
10024
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10025
+ GridInput,
10026
+ {
10027
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10028
+ ...field2,
10029
+ value: isDisabled ? placeholder : value,
10030
+ disabled: isDisabled,
10031
+ placeholder: "Value"
10032
+ }
10033
+ ) }) });
10034
+ }
10035
+ }
10036
+ )
10037
+ ]
10038
+ }
10039
+ ),
10040
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9970
10041
  /* @__PURE__ */ jsxRuntime.jsx(
9971
- StackedModalTrigger$1,
10042
+ ui.DropdownMenu.Trigger,
9972
10043
  {
9973
- type: "add-items",
9974
- setModalContent
10044
+ className: ui.clx(
10045
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10046
+ {
10047
+ hidden: isDisabled
10048
+ }
10049
+ ),
10050
+ disabled: isDisabled,
10051
+ asChild: true,
10052
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9975
10053
  }
9976
10054
  ),
9977
- /* @__PURE__ */ jsxRuntime.jsx(
9978
- StackedModalTrigger$1,
9979
- {
9980
- type: "add-custom-item",
9981
- setModalContent
9982
- }
9983
- )
10055
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10056
+ /* @__PURE__ */ jsxRuntime.jsxs(
10057
+ ui.DropdownMenu.Item,
10058
+ {
10059
+ className: "gap-x-2",
10060
+ onClick: () => insertRow(index, "above"),
10061
+ children: [
10062
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10063
+ "Insert row above"
10064
+ ]
10065
+ }
10066
+ ),
10067
+ /* @__PURE__ */ jsxRuntime.jsxs(
10068
+ ui.DropdownMenu.Item,
10069
+ {
10070
+ className: "gap-x-2",
10071
+ onClick: () => insertRow(index, "below"),
10072
+ children: [
10073
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10074
+ "Insert row below"
10075
+ ]
10076
+ }
10077
+ ),
10078
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10079
+ /* @__PURE__ */ jsxRuntime.jsxs(
10080
+ ui.DropdownMenu.Item,
10081
+ {
10082
+ className: "gap-x-2",
10083
+ onClick: () => deleteRow(index),
10084
+ children: [
10085
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10086
+ "Delete row"
10087
+ ]
10088
+ }
10089
+ )
10090
+ ] })
9984
10091
  ] })
9985
10092
  ] })
9986
- ] })
9987
- ] }),
9988
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
9989
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
9990
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
9991
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
9992
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
9993
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
9994
- ] }) }),
9995
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
9996
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
9997
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
9998
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
9999
- Item,
10000
- {
10001
- item,
10002
- preview,
10003
- currencyCode
10004
- },
10005
- item.id
10006
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10007
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10008
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10009
- 'No items found for "',
10010
- query2,
10011
- '".'
10012
- ] })
10013
- ] }) })
10014
- ] })
10015
- ] }),
10016
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10017
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10018
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10019
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10020
- ui.Text,
10021
- {
10022
- size: "small",
10023
- leading: "compact",
10024
- className: "text-ui-fg-subtle",
10025
- children: [
10026
- itemCount,
10027
- " ",
10028
- itemCount === 1 ? "item" : "items"
10029
- ]
10030
- }
10031
- ) }),
10032
- /* @__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) }) })
10033
- ] })
10034
- ] }) }),
10035
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10036
- CustomItemForm,
10037
- {
10038
- orderId: preview.id,
10039
- currencyCode
10040
- }
10041
- ) : null)
10042
- ]
10043
- }
10044
- ) }),
10045
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10046
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10047
- /* @__PURE__ */ jsxRuntime.jsx(
10048
- ui.Button,
10049
- {
10050
- size: "small",
10051
- type: "button",
10052
- onClick: onSubmit,
10053
- isLoading: isSubmitting,
10054
- children: "Save"
10055
- }
10056
- )
10057
- ] }) })
10058
- ] });
10059
- };
10060
- const Item = ({ item, preview, currencyCode }) => {
10061
- if (item.variant_id) {
10062
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10063
- }
10064
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10065
- };
10066
- const VariantItem = ({ item, preview, currencyCode }) => {
10067
- const [editing, setEditing] = React.useState(false);
10068
- const form = reactHookForm.useForm({
10069
- defaultValues: {
10070
- quantity: item.quantity,
10071
- unit_price: item.unit_price
10072
- },
10073
- resolver: zod.zodResolver(variantItemSchema)
10093
+ },
10094
+ field.id
10095
+ );
10096
+ })
10097
+ ] }),
10098
+ 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." })
10099
+ ] }),
10100
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10101
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10102
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10103
+ ] }) })
10104
+ ]
10105
+ }
10106
+ ) });
10107
+ };
10108
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10109
+ return /* @__PURE__ */ jsxRuntime.jsx(
10110
+ "input",
10111
+ {
10112
+ ref,
10113
+ ...props,
10114
+ autoComplete: "off",
10115
+ className: ui.clx(
10116
+ "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",
10117
+ className
10118
+ )
10119
+ }
10120
+ );
10121
+ });
10122
+ GridInput.displayName = "MetadataForm.GridInput";
10123
+ const PlaceholderInner = () => {
10124
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10125
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10126
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10127
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10128
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10129
+ ] }) })
10130
+ ] });
10131
+ };
10132
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
10133
+ function getDefaultValues(metadata) {
10134
+ if (!metadata || !Object.keys(metadata).length) {
10135
+ return [
10136
+ {
10137
+ key: "",
10138
+ value: "",
10139
+ disabled: false
10140
+ }
10141
+ ];
10142
+ }
10143
+ return Object.entries(metadata).map(([key, value]) => {
10144
+ if (!EDITABLE_TYPES.includes(typeof value)) {
10145
+ return {
10146
+ key,
10147
+ value,
10148
+ disabled: true
10149
+ };
10150
+ }
10151
+ let stringValue = value;
10152
+ if (typeof value !== "string") {
10153
+ stringValue = JSON.stringify(value);
10154
+ }
10155
+ return {
10156
+ key,
10157
+ value: stringValue,
10158
+ original_key: key
10159
+ };
10074
10160
  });
10075
- const actionId = React.useMemo(() => {
10076
- var _a, _b;
10077
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10078
- }, [item]);
10079
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10080
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10081
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10082
- const onSubmit = form.handleSubmit(async (data) => {
10083
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10084
- setEditing(false);
10161
+ }
10162
+ function parseValues(values) {
10163
+ const metadata = values.metadata;
10164
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10165
+ if (isEmpty) {
10166
+ return null;
10167
+ }
10168
+ const update = {};
10169
+ metadata.forEach((field) => {
10170
+ let key = field.key;
10171
+ let value = field.value;
10172
+ const disabled = field.disabled;
10173
+ if (!key || !value) {
10085
10174
  return;
10086
10175
  }
10087
- if (!actionId) {
10088
- await updateOriginalItem(
10089
- {
10090
- item_id: item.id,
10091
- quantity: data.quantity,
10092
- unit_price: convertNumber(data.unit_price)
10093
- },
10094
- {
10095
- onSuccess: () => {
10096
- setEditing(false);
10097
- },
10098
- onError: (e) => {
10099
- ui.toast.error(e.message);
10100
- }
10101
- }
10102
- );
10176
+ if (disabled) {
10177
+ update[key] = value;
10103
10178
  return;
10104
10179
  }
10105
- await updateActionItem(
10106
- {
10107
- action_id: actionId,
10108
- quantity: data.quantity,
10109
- unit_price: convertNumber(data.unit_price)
10110
- },
10111
- {
10112
- onSuccess: () => {
10113
- setEditing(false);
10114
- },
10115
- onError: (e) => {
10116
- ui.toast.error(e.message);
10117
- }
10180
+ key = key.trim();
10181
+ value = value.trim();
10182
+ if (value === "true") {
10183
+ update[key] = true;
10184
+ } else if (value === "false") {
10185
+ update[key] = false;
10186
+ } else {
10187
+ const parsedNumber = parseFloat(value);
10188
+ if (!isNaN(parsedNumber)) {
10189
+ update[key] = parsedNumber;
10190
+ } else {
10191
+ update[key] = value;
10118
10192
  }
10119
- );
10193
+ }
10120
10194
  });
10121
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10122
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10123
- /* @__PURE__ */ jsxRuntime.jsx(
10124
- Thumbnail,
10125
- {
10126
- thumbnail: item.thumbnail,
10127
- alt: item.product_title ?? void 0
10128
- }
10129
- ),
10130
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10131
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10132
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10195
+ return update;
10196
+ }
10197
+ function getHasUneditableRows(metadata) {
10198
+ if (!metadata) {
10199
+ return false;
10200
+ }
10201
+ return Object.values(metadata).some(
10202
+ (value) => !EDITABLE_TYPES.includes(typeof value)
10203
+ );
10204
+ }
10205
+ const NumberInput = React.forwardRef(
10206
+ ({
10207
+ value,
10208
+ onChange,
10209
+ size = "base",
10210
+ min = 0,
10211
+ max = 100,
10212
+ step = 1,
10213
+ className,
10214
+ disabled,
10215
+ ...props
10216
+ }, ref) => {
10217
+ const handleChange = (event) => {
10218
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
10219
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10220
+ onChange(newValue);
10221
+ }
10222
+ };
10223
+ const handleIncrement = () => {
10224
+ const newValue = value + step;
10225
+ if (max === void 0 || newValue <= max) {
10226
+ onChange(newValue);
10227
+ }
10228
+ };
10229
+ const handleDecrement = () => {
10230
+ const newValue = value - step;
10231
+ if (min === void 0 || newValue >= min) {
10232
+ onChange(newValue);
10233
+ }
10234
+ };
10235
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10236
+ "div",
10237
+ {
10238
+ className: ui.clx(
10239
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10240
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10241
+ {
10242
+ "h-7": size === "small",
10243
+ "h-8": size === "base"
10244
+ },
10245
+ className
10246
+ ),
10247
+ children: [
10248
+ /* @__PURE__ */ jsxRuntime.jsx(
10249
+ "input",
10250
+ {
10251
+ ref,
10252
+ type: "number",
10253
+ value,
10254
+ onChange: handleChange,
10255
+ min,
10256
+ max,
10257
+ step,
10258
+ className: ui.clx(
10259
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10260
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10261
+ "placeholder:text-ui-fg-muted"
10262
+ ),
10263
+ ...props
10264
+ }
10265
+ ),
10133
10266
  /* @__PURE__ */ jsxRuntime.jsxs(
10134
- ui.Text,
10267
+ "button",
10135
10268
  {
10136
- size: "small",
10137
- leading: "compact",
10138
- className: "text-ui-fg-subtle",
10269
+ className: ui.clx(
10270
+ "flex items-center justify-center outline-none transition-fg",
10271
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10272
+ "focus:bg-ui-bg-field-component-hover",
10273
+ "hover:bg-ui-bg-field-component-hover",
10274
+ {
10275
+ "size-7": size === "small",
10276
+ "size-8": size === "base"
10277
+ }
10278
+ ),
10279
+ type: "button",
10280
+ onClick: handleDecrement,
10281
+ disabled: min !== void 0 && value <= min || disabled,
10139
10282
  children: [
10140
- "(",
10141
- item.variant_title,
10142
- ")"
10283
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10284
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10143
10285
  ]
10144
10286
  }
10145
- )
10146
- ] }),
10147
- /* @__PURE__ */ jsxRuntime.jsx(
10148
- ui.Text,
10149
- {
10150
- size: "small",
10151
- leading: "compact",
10152
- className: "text-ui-fg-subtle",
10153
- children: item.variant_sku
10154
- }
10155
- )
10156
- ] })
10157
- ] }),
10158
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10159
- Form$2.Field,
10160
- {
10161
- control: form.control,
10162
- name: "quantity",
10163
- render: ({ field }) => {
10164
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10165
- }
10166
- }
10167
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10168
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10169
- Form$2.Field,
10170
- {
10171
- control: form.control,
10172
- name: "unit_price",
10173
- render: ({ field: { onChange, ...field } }) => {
10174
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10175
- ui.CurrencyInput,
10287
+ ),
10288
+ /* @__PURE__ */ jsxRuntime.jsxs(
10289
+ "button",
10176
10290
  {
10177
- ...field,
10178
- symbol: getNativeSymbol(currencyCode),
10179
- code: currencyCode,
10180
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10291
+ className: ui.clx(
10292
+ "flex items-center justify-center outline-none transition-fg",
10293
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10294
+ "focus:bg-ui-bg-field-hover",
10295
+ "hover:bg-ui-bg-field-hover",
10296
+ {
10297
+ "size-7": size === "small",
10298
+ "size-8": size === "base"
10299
+ }
10300
+ ),
10301
+ type: "button",
10302
+ onClick: handleIncrement,
10303
+ disabled: max !== void 0 && value >= max || disabled,
10304
+ children: [
10305
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10306
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10307
+ ]
10181
10308
  }
10182
- ) }) });
10183
- }
10184
- }
10185
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10186
- /* @__PURE__ */ jsxRuntime.jsx(
10187
- ui.IconButton,
10188
- {
10189
- type: "button",
10190
- size: "small",
10191
- onClick: editing ? onSubmit : () => {
10192
- setEditing(true);
10193
- },
10194
- disabled: isPending,
10195
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10309
+ )
10310
+ ]
10196
10311
  }
10197
- )
10198
- ] }) }) });
10312
+ );
10313
+ }
10314
+ );
10315
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10316
+ const productVariantsQueryKeys = {
10317
+ list: (query2) => [
10318
+ PRODUCT_VARIANTS_QUERY_KEY,
10319
+ query2 ? query2 : void 0
10320
+ ]
10199
10321
  };
10200
- const variantItemSchema = objectType({
10201
- quantity: numberType(),
10202
- unit_price: unionType([numberType(), stringType()])
10203
- });
10204
- const CustomItem = ({ item, preview, currencyCode }) => {
10205
- const [editing, setEditing] = React.useState(false);
10206
- const { quantity, unit_price, title } = item;
10207
- const form = reactHookForm.useForm({
10208
- defaultValues: {
10209
- title,
10210
- quantity,
10211
- unit_price
10212
- },
10213
- resolver: zod.zodResolver(customItemSchema)
10322
+ const useProductVariants = (query2, options) => {
10323
+ const { data, ...rest } = reactQuery.useQuery({
10324
+ queryKey: productVariantsQueryKeys.list(query2),
10325
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
10326
+ ...options
10214
10327
  });
10215
- React.useEffect(() => {
10216
- form.reset({
10217
- title,
10218
- quantity,
10219
- unit_price
10220
- });
10221
- }, [form, title, quantity, unit_price]);
10222
- const actionId = React.useMemo(() => {
10223
- var _a, _b;
10224
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10225
- }, [item]);
10226
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10227
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10228
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10229
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10230
- const onSubmit = form.handleSubmit(async (data) => {
10231
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10232
- setEditing(false);
10233
- return;
10234
- }
10235
- if (!actionId) {
10236
- await updateOriginalItem(
10237
- {
10238
- item_id: item.id,
10239
- quantity: data.quantity,
10240
- unit_price: convertNumber(data.unit_price)
10241
- },
10242
- {
10243
- onSuccess: () => {
10244
- setEditing(false);
10245
- },
10246
- onError: (e) => {
10247
- ui.toast.error(e.message);
10248
- }
10249
- }
10250
- );
10251
- return;
10328
+ return { ...data, ...rest };
10329
+ };
10330
+ const useCancelOrderEdit = ({ preview }) => {
10331
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10332
+ const onCancel = React.useCallback(async () => {
10333
+ if (!preview) {
10334
+ return true;
10252
10335
  }
10253
- if (data.quantity === 0) {
10254
- await removeActionItem(actionId, {
10255
- onSuccess: () => {
10256
- setEditing(false);
10257
- },
10336
+ let res = false;
10337
+ await cancelOrderEdit(void 0, {
10338
+ onError: (e) => {
10339
+ ui.toast.error(e.message);
10340
+ },
10341
+ onSuccess: () => {
10342
+ res = true;
10343
+ }
10344
+ });
10345
+ return res;
10346
+ }, [preview, cancelOrderEdit]);
10347
+ return { onCancel };
10348
+ };
10349
+ let IS_REQUEST_RUNNING = false;
10350
+ const useInitiateOrderEdit = ({
10351
+ preview
10352
+ }) => {
10353
+ const navigate = reactRouterDom.useNavigate();
10354
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10355
+ React.useEffect(() => {
10356
+ async function run() {
10357
+ if (IS_REQUEST_RUNNING || !preview) {
10358
+ return;
10359
+ }
10360
+ if (preview.order_change) {
10361
+ return;
10362
+ }
10363
+ IS_REQUEST_RUNNING = true;
10364
+ await mutateAsync(void 0, {
10258
10365
  onError: (e) => {
10259
10366
  ui.toast.error(e.message);
10367
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10368
+ return;
10260
10369
  }
10261
10370
  });
10262
- return;
10371
+ IS_REQUEST_RUNNING = false;
10263
10372
  }
10264
- await updateActionItem(
10265
- {
10266
- action_id: actionId,
10267
- quantity: data.quantity,
10268
- unit_price: convertNumber(data.unit_price)
10373
+ run();
10374
+ }, [preview, navigate, mutateAsync]);
10375
+ };
10376
+ function convertNumber(value) {
10377
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10378
+ }
10379
+ const STACKED_MODAL_ID = "items_stacked_modal";
10380
+ const Items = () => {
10381
+ const { id } = reactRouterDom.useParams();
10382
+ const {
10383
+ order: preview,
10384
+ isPending: isPreviewPending,
10385
+ isError: isPreviewError,
10386
+ error: previewError
10387
+ } = useOrderPreview(id, void 0, {
10388
+ placeholderData: reactQuery.keepPreviousData
10389
+ });
10390
+ useInitiateOrderEdit({ preview });
10391
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10392
+ id,
10393
+ {
10394
+ fields: "currency_code"
10395
+ },
10396
+ {
10397
+ enabled: !!id
10398
+ }
10399
+ );
10400
+ const { onCancel } = useCancelOrderEdit({ preview });
10401
+ if (isError) {
10402
+ throw error;
10403
+ }
10404
+ if (isPreviewError) {
10405
+ throw previewError;
10406
+ }
10407
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10408
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10409
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10410
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10411
+ ] }) });
10412
+ };
10413
+ const ItemsForm = ({ preview, currencyCode }) => {
10414
+ var _a;
10415
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10416
+ const [modalContent, setModalContent] = React.useState(
10417
+ null
10418
+ );
10419
+ const { handleSuccess } = useRouteModal();
10420
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10421
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10422
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10423
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10424
+ const matches = React.useMemo(() => {
10425
+ return matchSorter.matchSorter(preview.items, query2, {
10426
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10427
+ });
10428
+ }, [preview.items, query2]);
10429
+ const onSubmit = async () => {
10430
+ setIsSubmitting(true);
10431
+ let requestSucceeded = false;
10432
+ await requestOrderEdit(void 0, {
10433
+ onError: (e) => {
10434
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10269
10435
  },
10270
- {
10271
- onSuccess: () => {
10272
- setEditing(false);
10273
- },
10274
- onError: (e) => {
10275
- ui.toast.error(e.message);
10276
- }
10436
+ onSuccess: () => {
10437
+ requestSucceeded = true;
10277
10438
  }
10278
- );
10279
- });
10280
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10281
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10282
- /* @__PURE__ */ jsxRuntime.jsx(
10283
- Thumbnail,
10439
+ });
10440
+ if (!requestSucceeded) {
10441
+ setIsSubmitting(false);
10442
+ return;
10443
+ }
10444
+ await confirmOrderEdit(void 0, {
10445
+ onError: (e) => {
10446
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10447
+ },
10448
+ onSuccess: () => {
10449
+ handleSuccess();
10450
+ },
10451
+ onSettled: () => {
10452
+ setIsSubmitting(false);
10453
+ }
10454
+ });
10455
+ };
10456
+ const onKeyDown = React.useCallback(
10457
+ (e) => {
10458
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10459
+ if (modalContent || isSubmitting) {
10460
+ return;
10461
+ }
10462
+ onSubmit();
10463
+ }
10464
+ },
10465
+ [modalContent, isSubmitting, onSubmit]
10466
+ );
10467
+ React.useEffect(() => {
10468
+ document.addEventListener("keydown", onKeyDown);
10469
+ return () => {
10470
+ document.removeEventListener("keydown", onKeyDown);
10471
+ };
10472
+ }, [onKeyDown]);
10473
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10474
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10475
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10476
+ StackedFocusModal,
10477
+ {
10478
+ id: STACKED_MODAL_ID,
10479
+ onOpenChangeCallback: (open) => {
10480
+ if (!open) {
10481
+ setModalContent(null);
10482
+ }
10483
+ },
10484
+ children: [
10485
+ /* @__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: [
10486
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10487
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10488
+ /* @__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" }) })
10489
+ ] }),
10490
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10491
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10492
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10493
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10494
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10495
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10496
+ ] }),
10497
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10498
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10499
+ ui.Input,
10500
+ {
10501
+ type: "search",
10502
+ placeholder: "Search items",
10503
+ value: searchValue,
10504
+ onChange: (e) => onSearchValueChange(e.target.value)
10505
+ }
10506
+ ) }),
10507
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10508
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10509
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10510
+ /* @__PURE__ */ jsxRuntime.jsx(
10511
+ StackedModalTrigger$1,
10512
+ {
10513
+ type: "add-items",
10514
+ setModalContent
10515
+ }
10516
+ ),
10517
+ /* @__PURE__ */ jsxRuntime.jsx(
10518
+ StackedModalTrigger$1,
10519
+ {
10520
+ type: "add-custom-item",
10521
+ setModalContent
10522
+ }
10523
+ )
10524
+ ] })
10525
+ ] })
10526
+ ] })
10527
+ ] }),
10528
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10529
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10530
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10531
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10532
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10533
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
10534
+ ] }) }),
10535
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10536
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10537
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10538
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10539
+ Item,
10540
+ {
10541
+ item,
10542
+ preview,
10543
+ currencyCode
10544
+ },
10545
+ item.id
10546
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10547
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10548
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10549
+ 'No items found for "',
10550
+ query2,
10551
+ '".'
10552
+ ] })
10553
+ ] }) })
10554
+ ] })
10555
+ ] }),
10556
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10557
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10558
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10559
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10560
+ ui.Text,
10561
+ {
10562
+ size: "small",
10563
+ leading: "compact",
10564
+ className: "text-ui-fg-subtle",
10565
+ children: [
10566
+ itemCount,
10567
+ " ",
10568
+ itemCount === 1 ? "item" : "items"
10569
+ ]
10570
+ }
10571
+ ) }),
10572
+ /* @__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) }) })
10573
+ ] })
10574
+ ] }) }),
10575
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10576
+ CustomItemForm,
10577
+ {
10578
+ orderId: preview.id,
10579
+ currencyCode
10580
+ }
10581
+ ) : null)
10582
+ ]
10583
+ }
10584
+ ) }),
10585
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10587
+ /* @__PURE__ */ jsxRuntime.jsx(
10588
+ ui.Button,
10284
10589
  {
10285
- thumbnail: item.thumbnail,
10286
- alt: item.title ?? void 0
10590
+ size: "small",
10591
+ type: "button",
10592
+ onClick: onSubmit,
10593
+ isLoading: isSubmitting,
10594
+ children: "Save"
10287
10595
  }
10288
- ),
10289
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10290
- Form$2.Field,
10596
+ )
10597
+ ] }) })
10598
+ ] });
10599
+ };
10600
+ const Item = ({ item, preview, currencyCode }) => {
10601
+ if (item.variant_id) {
10602
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10603
+ }
10604
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10605
+ };
10606
+ const VariantItem = ({ item, preview, currencyCode }) => {
10607
+ const [editing, setEditing] = React.useState(false);
10608
+ const form = reactHookForm.useForm({
10609
+ defaultValues: {
10610
+ quantity: item.quantity,
10611
+ unit_price: item.unit_price
10612
+ },
10613
+ resolver: zod.zodResolver(variantItemSchema)
10614
+ });
10615
+ const actionId = React.useMemo(() => {
10616
+ var _a, _b;
10617
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10618
+ }, [item]);
10619
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10620
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10621
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10622
+ const onSubmit = form.handleSubmit(async (data) => {
10623
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10624
+ setEditing(false);
10625
+ return;
10626
+ }
10627
+ if (!actionId) {
10628
+ await updateOriginalItem(
10291
10629
  {
10292
- control: form.control,
10293
- name: "title",
10294
- render: ({ field }) => {
10295
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10630
+ item_id: item.id,
10631
+ quantity: data.quantity,
10632
+ unit_price: convertNumber(data.unit_price)
10633
+ },
10634
+ {
10635
+ onSuccess: () => {
10636
+ setEditing(false);
10637
+ },
10638
+ onError: (e) => {
10639
+ ui.toast.error(e.message);
10296
10640
  }
10297
10641
  }
10298
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10299
- ] }),
10300
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10301
- Form$2.Field,
10642
+ );
10643
+ return;
10644
+ }
10645
+ await updateActionItem(
10302
10646
  {
10303
- control: form.control,
10304
- name: "quantity",
10305
- render: ({ field }) => {
10306
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10307
- }
10308
- }
10309
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10310
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10311
- Form$2.Field,
10647
+ action_id: actionId,
10648
+ quantity: data.quantity,
10649
+ unit_price: convertNumber(data.unit_price)
10650
+ },
10312
10651
  {
10313
- control: form.control,
10314
- name: "unit_price",
10315
- render: ({ field: { onChange, ...field } }) => {
10316
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10317
- ui.CurrencyInput,
10318
- {
10319
- ...field,
10320
- symbol: getNativeSymbol(currencyCode),
10321
- code: currencyCode,
10322
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10323
- }
10324
- ) }) });
10652
+ onSuccess: () => {
10653
+ setEditing(false);
10654
+ },
10655
+ onError: (e) => {
10656
+ ui.toast.error(e.message);
10325
10657
  }
10326
10658
  }
10327
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10328
- /* @__PURE__ */ jsxRuntime.jsx(
10329
- ui.IconButton,
10330
- {
10331
- type: "button",
10332
- size: "small",
10333
- onClick: editing ? onSubmit : () => {
10334
- setEditing(true);
10335
- },
10336
- disabled: isPending,
10659
+ );
10660
+ });
10661
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10662
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10663
+ /* @__PURE__ */ jsxRuntime.jsx(
10664
+ Thumbnail,
10665
+ {
10666
+ thumbnail: item.thumbnail,
10667
+ alt: item.product_title ?? void 0
10668
+ }
10669
+ ),
10670
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10671
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10672
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10673
+ /* @__PURE__ */ jsxRuntime.jsxs(
10674
+ ui.Text,
10675
+ {
10676
+ size: "small",
10677
+ leading: "compact",
10678
+ className: "text-ui-fg-subtle",
10679
+ children: [
10680
+ "(",
10681
+ item.variant_title,
10682
+ ")"
10683
+ ]
10684
+ }
10685
+ )
10686
+ ] }),
10687
+ /* @__PURE__ */ jsxRuntime.jsx(
10688
+ ui.Text,
10689
+ {
10690
+ size: "small",
10691
+ leading: "compact",
10692
+ className: "text-ui-fg-subtle",
10693
+ children: item.variant_sku
10694
+ }
10695
+ )
10696
+ ] })
10697
+ ] }),
10698
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10699
+ Form$2.Field,
10700
+ {
10701
+ control: form.control,
10702
+ name: "quantity",
10703
+ render: ({ field }) => {
10704
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10705
+ }
10706
+ }
10707
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10708
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10709
+ Form$2.Field,
10710
+ {
10711
+ control: form.control,
10712
+ name: "unit_price",
10713
+ render: ({ field: { onChange, ...field } }) => {
10714
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10715
+ ui.CurrencyInput,
10716
+ {
10717
+ ...field,
10718
+ symbol: getNativeSymbol(currencyCode),
10719
+ code: currencyCode,
10720
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10721
+ }
10722
+ ) }) });
10723
+ }
10724
+ }
10725
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10726
+ /* @__PURE__ */ jsxRuntime.jsx(
10727
+ ui.IconButton,
10728
+ {
10729
+ type: "button",
10730
+ size: "small",
10731
+ onClick: editing ? onSubmit : () => {
10732
+ setEditing(true);
10733
+ },
10734
+ disabled: isPending,
10735
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10736
+ }
10737
+ )
10738
+ ] }) }) });
10739
+ };
10740
+ const variantItemSchema = objectType({
10741
+ quantity: numberType(),
10742
+ unit_price: unionType([numberType(), stringType()])
10743
+ });
10744
+ const CustomItem = ({ item, preview, currencyCode }) => {
10745
+ const [editing, setEditing] = React.useState(false);
10746
+ const { quantity, unit_price, title } = item;
10747
+ const form = reactHookForm.useForm({
10748
+ defaultValues: {
10749
+ title,
10750
+ quantity,
10751
+ unit_price
10752
+ },
10753
+ resolver: zod.zodResolver(customItemSchema)
10754
+ });
10755
+ React.useEffect(() => {
10756
+ form.reset({
10757
+ title,
10758
+ quantity,
10759
+ unit_price
10760
+ });
10761
+ }, [form, title, quantity, unit_price]);
10762
+ const actionId = React.useMemo(() => {
10763
+ var _a, _b;
10764
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10765
+ }, [item]);
10766
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10767
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10768
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10769
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10770
+ const onSubmit = form.handleSubmit(async (data) => {
10771
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10772
+ setEditing(false);
10773
+ return;
10774
+ }
10775
+ if (!actionId) {
10776
+ await updateOriginalItem(
10777
+ {
10778
+ item_id: item.id,
10779
+ quantity: data.quantity,
10780
+ unit_price: convertNumber(data.unit_price)
10781
+ },
10782
+ {
10783
+ onSuccess: () => {
10784
+ setEditing(false);
10785
+ },
10786
+ onError: (e) => {
10787
+ ui.toast.error(e.message);
10788
+ }
10789
+ }
10790
+ );
10791
+ return;
10792
+ }
10793
+ if (data.quantity === 0) {
10794
+ await removeActionItem(actionId, {
10795
+ onSuccess: () => {
10796
+ setEditing(false);
10797
+ },
10798
+ onError: (e) => {
10799
+ ui.toast.error(e.message);
10800
+ }
10801
+ });
10802
+ return;
10803
+ }
10804
+ await updateActionItem(
10805
+ {
10806
+ action_id: actionId,
10807
+ quantity: data.quantity,
10808
+ unit_price: convertNumber(data.unit_price)
10809
+ },
10810
+ {
10811
+ onSuccess: () => {
10812
+ setEditing(false);
10813
+ },
10814
+ onError: (e) => {
10815
+ ui.toast.error(e.message);
10816
+ }
10817
+ }
10818
+ );
10819
+ });
10820
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10821
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10822
+ /* @__PURE__ */ jsxRuntime.jsx(
10823
+ Thumbnail,
10824
+ {
10825
+ thumbnail: item.thumbnail,
10826
+ alt: item.title ?? void 0
10827
+ }
10828
+ ),
10829
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10830
+ Form$2.Field,
10831
+ {
10832
+ control: form.control,
10833
+ name: "title",
10834
+ render: ({ field }) => {
10835
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10836
+ }
10837
+ }
10838
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10839
+ ] }),
10840
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10841
+ Form$2.Field,
10842
+ {
10843
+ control: form.control,
10844
+ name: "quantity",
10845
+ render: ({ field }) => {
10846
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10847
+ }
10848
+ }
10849
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10850
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10851
+ Form$2.Field,
10852
+ {
10853
+ control: form.control,
10854
+ name: "unit_price",
10855
+ render: ({ field: { onChange, ...field } }) => {
10856
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10857
+ ui.CurrencyInput,
10858
+ {
10859
+ ...field,
10860
+ symbol: getNativeSymbol(currencyCode),
10861
+ code: currencyCode,
10862
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10863
+ }
10864
+ ) }) });
10865
+ }
10866
+ }
10867
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10868
+ /* @__PURE__ */ jsxRuntime.jsx(
10869
+ ui.IconButton,
10870
+ {
10871
+ type: "button",
10872
+ size: "small",
10873
+ onClick: editing ? onSubmit : () => {
10874
+ setEditing(true);
10875
+ },
10876
+ disabled: isPending,
10337
10877
  children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10338
10878
  }
10339
10879
  )
@@ -10636,455 +11176,460 @@ const customItemSchema = objectType({
10636
11176
  quantity: numberType(),
10637
11177
  unit_price: unionType([numberType(), stringType()])
10638
11178
  });
10639
- const InlineTip = React.forwardRef(
10640
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10641
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10642
- return /* @__PURE__ */ jsxRuntime.jsxs(
10643
- "div",
10644
- {
10645
- ref,
10646
- className: ui.clx(
10647
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10648
- className
10649
- ),
10650
- ...props,
10651
- children: [
10652
- /* @__PURE__ */ jsxRuntime.jsx(
10653
- "div",
10654
- {
10655
- role: "presentation",
10656
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10657
- "bg-ui-tag-orange-icon": variant === "warning"
10658
- })
10659
- }
10660
- ),
10661
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10662
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10663
- labelValue,
10664
- ":"
10665
- ] }),
10666
- " ",
10667
- children
10668
- ] })
10669
- ]
10670
- }
10671
- );
10672
- }
10673
- );
10674
- InlineTip.displayName = "InlineTip";
10675
- const MetadataFieldSchema = objectType({
10676
- key: stringType(),
10677
- disabled: booleanType().optional(),
10678
- value: anyType()
10679
- });
10680
- const MetadataSchema = objectType({
10681
- metadata: arrayType(MetadataFieldSchema)
10682
- });
10683
- const Metadata = () => {
10684
- const { id } = reactRouterDom.useParams();
10685
- const { order, isPending, isError, error } = useOrder(id, {
10686
- fields: "metadata"
11179
+ const PROMOTION_QUERY_KEY = "promotions";
11180
+ const promotionsQueryKeys = {
11181
+ list: (query2) => [
11182
+ PROMOTION_QUERY_KEY,
11183
+ query2 ? query2 : void 0
11184
+ ],
11185
+ detail: (id, query2) => [
11186
+ PROMOTION_QUERY_KEY,
11187
+ id,
11188
+ query2 ? query2 : void 0
11189
+ ]
11190
+ };
11191
+ const usePromotions = (query2, options) => {
11192
+ const { data, ...rest } = reactQuery.useQuery({
11193
+ queryKey: promotionsQueryKeys.list(query2),
11194
+ queryFn: async () => sdk.admin.promotion.list(query2),
11195
+ ...options
10687
11196
  });
10688
- if (isError) {
10689
- throw error;
11197
+ return { ...data, ...rest };
11198
+ };
11199
+ const Promotions = () => {
11200
+ const { id } = reactRouterDom.useParams();
11201
+ const {
11202
+ order: preview,
11203
+ isError: isPreviewError,
11204
+ error: previewError
11205
+ } = useOrderPreview(id, void 0);
11206
+ useInitiateOrderEdit({ preview });
11207
+ const { onCancel } = useCancelOrderEdit({ preview });
11208
+ if (isPreviewError) {
11209
+ throw previewError;
10690
11210
  }
10691
- const isReady = !isPending && !!order;
10692
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10693
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10694
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10695
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10696
- ] }),
10697
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11211
+ const isReady = !!preview;
11212
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11213
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11214
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10698
11215
  ] });
10699
11216
  };
10700
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10701
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10702
- const MetadataForm = ({ orderId, metadata }) => {
11217
+ const PromotionForm = ({ preview }) => {
11218
+ const { items, shipping_methods } = preview;
11219
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11220
+ const [comboboxValue, setComboboxValue] = React.useState("");
10703
11221
  const { handleSuccess } = useRouteModal();
10704
- const hasUneditableRows = getHasUneditableRows(metadata);
10705
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10706
- const form = reactHookForm.useForm({
10707
- defaultValues: {
10708
- metadata: getDefaultValues(metadata)
11222
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11223
+ const promoIds = getPromotionIds(items, shipping_methods);
11224
+ const { promotions, isPending, isError, error } = usePromotions(
11225
+ {
11226
+ id: promoIds
10709
11227
  },
10710
- resolver: zod.zodResolver(MetadataSchema)
11228
+ {
11229
+ enabled: !!promoIds.length
11230
+ }
11231
+ );
11232
+ const comboboxData = useComboboxData({
11233
+ queryKey: ["promotions", "combobox", promoIds],
11234
+ queryFn: async (params) => {
11235
+ return await sdk.admin.promotion.list({
11236
+ ...params,
11237
+ id: {
11238
+ $nin: promoIds
11239
+ }
11240
+ });
11241
+ },
11242
+ getOptions: (data) => {
11243
+ return data.promotions.map((promotion) => ({
11244
+ label: promotion.code,
11245
+ value: promotion.code
11246
+ }));
11247
+ }
10711
11248
  });
10712
- const handleSubmit = form.handleSubmit(async (data) => {
10713
- const parsedData = parseValues(data);
10714
- await mutateAsync(
11249
+ const add = async (value) => {
11250
+ if (!value) {
11251
+ return;
11252
+ }
11253
+ addPromotions(
10715
11254
  {
10716
- metadata: parsedData
11255
+ promo_codes: [value]
10717
11256
  },
10718
11257
  {
10719
- onSuccess: () => {
10720
- ui.toast.success("Metadata updated");
10721
- handleSuccess();
11258
+ onError: (e) => {
11259
+ ui.toast.error(e.message);
11260
+ comboboxData.onSearchValueChange("");
11261
+ setComboboxValue("");
10722
11262
  },
10723
- onError: (error) => {
10724
- ui.toast.error(error.message);
11263
+ onSuccess: () => {
11264
+ comboboxData.onSearchValueChange("");
11265
+ setComboboxValue("");
10725
11266
  }
10726
11267
  }
10727
11268
  );
10728
- });
10729
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10730
- control: form.control,
10731
- name: "metadata"
10732
- });
10733
- function deleteRow(index) {
10734
- remove(index);
10735
- if (fields.length === 1) {
10736
- insert(0, {
10737
- key: "",
10738
- value: "",
10739
- disabled: false
10740
- });
11269
+ };
11270
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11271
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11272
+ const onSubmit = async () => {
11273
+ setIsSubmitting(true);
11274
+ let requestSucceeded = false;
11275
+ await requestOrderEdit(void 0, {
11276
+ onError: (e) => {
11277
+ ui.toast.error(e.message);
11278
+ },
11279
+ onSuccess: () => {
11280
+ requestSucceeded = true;
11281
+ }
11282
+ });
11283
+ if (!requestSucceeded) {
11284
+ setIsSubmitting(false);
11285
+ return;
10741
11286
  }
10742
- }
10743
- function insertRow(index, position) {
10744
- insert(index + (position === "above" ? 0 : 1), {
10745
- key: "",
10746
- value: "",
10747
- disabled: false
11287
+ await confirmOrderEdit(void 0, {
11288
+ onError: (e) => {
11289
+ ui.toast.error(e.message);
11290
+ },
11291
+ onSuccess: () => {
11292
+ handleSuccess();
11293
+ },
11294
+ onSettled: () => {
11295
+ setIsSubmitting(false);
11296
+ }
10748
11297
  });
11298
+ };
11299
+ if (isError) {
11300
+ throw error;
10749
11301
  }
10750
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10751
- KeyboundForm,
11302
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11305
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11306
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11307
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11308
+ ] }),
11309
+ /* @__PURE__ */ jsxRuntime.jsx(
11310
+ Combobox,
11311
+ {
11312
+ id: "promotion-combobox",
11313
+ "aria-describedby": "promotion-combobox-hint",
11314
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11315
+ fetchNextPage: comboboxData.fetchNextPage,
11316
+ options: comboboxData.options,
11317
+ onSearchValueChange: comboboxData.onSearchValueChange,
11318
+ searchValue: comboboxData.searchValue,
11319
+ disabled: comboboxData.disabled || isAddingPromotions,
11320
+ onChange: add,
11321
+ value: comboboxValue
11322
+ }
11323
+ )
11324
+ ] }),
11325
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11326
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11327
+ PromotionItem,
11328
+ {
11329
+ promotion,
11330
+ orderId: preview.id,
11331
+ isLoading: isPending
11332
+ },
11333
+ promotion.id
11334
+ )) })
11335
+ ] }) }),
11336
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11337
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11338
+ /* @__PURE__ */ jsxRuntime.jsx(
11339
+ ui.Button,
11340
+ {
11341
+ size: "small",
11342
+ type: "submit",
11343
+ isLoading: isSubmitting || isAddingPromotions,
11344
+ children: "Save"
11345
+ }
11346
+ )
11347
+ ] }) })
11348
+ ] });
11349
+ };
11350
+ const PromotionItem = ({
11351
+ promotion,
11352
+ orderId,
11353
+ isLoading
11354
+ }) => {
11355
+ var _a;
11356
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11357
+ const onRemove = async () => {
11358
+ removePromotions(
11359
+ {
11360
+ promo_codes: [promotion.code]
11361
+ },
11362
+ {
11363
+ onError: (e) => {
11364
+ ui.toast.error(e.message);
11365
+ }
11366
+ }
11367
+ );
11368
+ };
11369
+ const displayValue = getDisplayValue(promotion);
11370
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11371
+ "div",
10752
11372
  {
10753
- onSubmit: handleSubmit,
10754
- className: "flex flex-1 flex-col overflow-hidden",
11373
+ className: ui.clx(
11374
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11375
+ {
11376
+ "animate-pulse": isLoading
11377
+ }
11378
+ ),
10755
11379
  children: [
10756
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10757
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10758
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10759
- /* @__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" }) }),
10760
- /* @__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" }) })
11380
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11381
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11382
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11383
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11384
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11385
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10761
11386
  ] }),
10762
- fields.map((field, index) => {
10763
- const isDisabled = field.disabled || false;
10764
- let placeholder = "-";
10765
- if (typeof field.value === "object") {
10766
- placeholder = "{ ... }";
10767
- }
10768
- if (Array.isArray(field.value)) {
10769
- placeholder = "[ ... ]";
10770
- }
10771
- return /* @__PURE__ */ jsxRuntime.jsx(
10772
- ConditionalTooltip,
10773
- {
10774
- showTooltip: isDisabled,
10775
- content: "This row is disabled because it contains non-primitive data.",
10776
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10777
- /* @__PURE__ */ jsxRuntime.jsxs(
10778
- "div",
10779
- {
10780
- className: ui.clx("grid grid-cols-2 divide-x", {
10781
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10782
- }),
10783
- children: [
10784
- /* @__PURE__ */ jsxRuntime.jsx(
10785
- Form$2.Field,
10786
- {
10787
- control: form.control,
10788
- name: `metadata.${index}.key`,
10789
- render: ({ field: field2 }) => {
10790
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10791
- GridInput,
10792
- {
10793
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10794
- ...field2,
10795
- disabled: isDisabled,
10796
- placeholder: "Key"
10797
- }
10798
- ) }) });
10799
- }
10800
- }
10801
- ),
10802
- /* @__PURE__ */ jsxRuntime.jsx(
10803
- Form$2.Field,
10804
- {
10805
- control: form.control,
10806
- name: `metadata.${index}.value`,
10807
- render: ({ field: { value, ...field2 } }) => {
10808
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10809
- GridInput,
10810
- {
10811
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10812
- ...field2,
10813
- value: isDisabled ? placeholder : value,
10814
- disabled: isDisabled,
10815
- placeholder: "Value"
10816
- }
10817
- ) }) });
10818
- }
10819
- }
10820
- )
10821
- ]
10822
- }
10823
- ),
10824
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10825
- /* @__PURE__ */ jsxRuntime.jsx(
10826
- ui.DropdownMenu.Trigger,
10827
- {
10828
- className: ui.clx(
10829
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10830
- {
10831
- hidden: isDisabled
10832
- }
10833
- ),
10834
- disabled: isDisabled,
10835
- asChild: true,
10836
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10837
- }
10838
- ),
10839
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10840
- /* @__PURE__ */ jsxRuntime.jsxs(
10841
- ui.DropdownMenu.Item,
10842
- {
10843
- className: "gap-x-2",
10844
- onClick: () => insertRow(index, "above"),
10845
- children: [
10846
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10847
- "Insert row above"
10848
- ]
10849
- }
10850
- ),
10851
- /* @__PURE__ */ jsxRuntime.jsxs(
10852
- ui.DropdownMenu.Item,
10853
- {
10854
- className: "gap-x-2",
10855
- onClick: () => insertRow(index, "below"),
10856
- children: [
10857
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10858
- "Insert row below"
10859
- ]
10860
- }
10861
- ),
10862
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10863
- /* @__PURE__ */ jsxRuntime.jsxs(
10864
- ui.DropdownMenu.Item,
10865
- {
10866
- className: "gap-x-2",
10867
- onClick: () => deleteRow(index),
10868
- children: [
10869
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10870
- "Delete row"
10871
- ]
10872
- }
10873
- )
10874
- ] })
10875
- ] })
10876
- ] })
10877
- },
10878
- field.id
10879
- );
10880
- })
10881
- ] }),
10882
- 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." })
11387
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11388
+ ] })
10883
11389
  ] }),
10884
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10885
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10886
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10887
- ] }) })
11390
+ /* @__PURE__ */ jsxRuntime.jsx(
11391
+ ui.IconButton,
11392
+ {
11393
+ size: "small",
11394
+ type: "button",
11395
+ variant: "transparent",
11396
+ onClick: onRemove,
11397
+ isLoading: isPending || isLoading,
11398
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11399
+ }
11400
+ )
10888
11401
  ]
10889
- }
10890
- ) });
10891
- };
10892
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10893
- return /* @__PURE__ */ jsxRuntime.jsx(
10894
- "input",
10895
- {
10896
- ref,
10897
- ...props,
10898
- autoComplete: "off",
10899
- className: ui.clx(
10900
- "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",
10901
- className
10902
- )
10903
- }
11402
+ },
11403
+ promotion.id
10904
11404
  );
10905
- });
10906
- GridInput.displayName = "MetadataForm.GridInput";
10907
- const PlaceholderInner = () => {
10908
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10909
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10910
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10911
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10912
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10913
- ] }) })
10914
- ] });
10915
11405
  };
10916
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10917
- function getDefaultValues(metadata) {
10918
- if (!metadata || !Object.keys(metadata).length) {
10919
- return [
10920
- {
10921
- key: "",
10922
- value: "",
10923
- disabled: false
10924
- }
10925
- ];
11406
+ function getDisplayValue(promotion) {
11407
+ var _a, _b, _c, _d;
11408
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11409
+ if (!value) {
11410
+ return null;
10926
11411
  }
10927
- return Object.entries(metadata).map(([key, value]) => {
10928
- if (!EDITABLE_TYPES.includes(typeof value)) {
10929
- return {
10930
- key,
10931
- value,
10932
- disabled: true
10933
- };
10934
- }
10935
- let stringValue = value;
10936
- if (typeof value !== "string") {
10937
- stringValue = JSON.stringify(value);
11412
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11413
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11414
+ if (!currency) {
11415
+ return null;
10938
11416
  }
10939
- return {
10940
- key,
10941
- value: stringValue,
10942
- original_key: key
10943
- };
10944
- });
11417
+ return getLocaleAmount(value, currency);
11418
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11419
+ return formatPercentage(value);
11420
+ }
11421
+ return null;
10945
11422
  }
10946
- function parseValues(values) {
10947
- const metadata = values.metadata;
10948
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10949
- if (isEmpty) {
10950
- return null;
11423
+ const formatter = new Intl.NumberFormat([], {
11424
+ style: "percent",
11425
+ minimumFractionDigits: 2
11426
+ });
11427
+ const formatPercentage = (value, isPercentageValue = false) => {
11428
+ let val = value || 0;
11429
+ if (!isPercentageValue) {
11430
+ val = val / 100;
10951
11431
  }
10952
- const update = {};
10953
- metadata.forEach((field) => {
10954
- let key = field.key;
10955
- let value = field.value;
10956
- const disabled = field.disabled;
10957
- if (!key || !value) {
10958
- return;
10959
- }
10960
- if (disabled) {
10961
- update[key] = value;
10962
- return;
10963
- }
10964
- key = key.trim();
10965
- value = value.trim();
10966
- if (value === "true") {
10967
- update[key] = true;
10968
- } else if (value === "false") {
10969
- update[key] = false;
10970
- } else {
10971
- const parsedNumber = parseFloat(value);
10972
- if (!isNaN(parsedNumber)) {
10973
- update[key] = parsedNumber;
10974
- } else {
10975
- update[key] = value;
11432
+ return formatter.format(val);
11433
+ };
11434
+ function getPromotionIds(items, shippingMethods) {
11435
+ const promotionIds = /* @__PURE__ */ new Set();
11436
+ for (const item of items) {
11437
+ if (item.adjustments) {
11438
+ for (const adjustment of item.adjustments) {
11439
+ if (adjustment.promotion_id) {
11440
+ promotionIds.add(adjustment.promotion_id);
11441
+ }
10976
11442
  }
10977
11443
  }
10978
- });
10979
- return update;
10980
- }
10981
- function getHasUneditableRows(metadata) {
10982
- if (!metadata) {
10983
- return false;
10984
11444
  }
10985
- return Object.values(metadata).some(
10986
- (value) => !EDITABLE_TYPES.includes(typeof value)
10987
- );
11445
+ for (const shippingMethod of shippingMethods) {
11446
+ if (shippingMethod.adjustments) {
11447
+ for (const adjustment of shippingMethod.adjustments) {
11448
+ if (adjustment.promotion_id) {
11449
+ promotionIds.add(adjustment.promotion_id);
11450
+ }
11451
+ }
11452
+ }
11453
+ }
11454
+ return Array.from(promotionIds);
10988
11455
  }
10989
- const PROMOTION_QUERY_KEY = "promotions";
10990
- const promotionsQueryKeys = {
10991
- list: (query2) => [
10992
- PROMOTION_QUERY_KEY,
10993
- query2 ? query2 : void 0
10994
- ],
10995
- detail: (id, query2) => [
10996
- PROMOTION_QUERY_KEY,
11456
+ const SalesChannel = () => {
11457
+ const { id } = reactRouterDom.useParams();
11458
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10997
11459
  id,
10998
- query2 ? query2 : void 0
10999
- ]
11460
+ {
11461
+ fields: "+sales_channel_id"
11462
+ },
11463
+ {
11464
+ enabled: !!id
11465
+ }
11466
+ );
11467
+ if (isError) {
11468
+ throw error;
11469
+ }
11470
+ const ISrEADY = !!draft_order && !isPending;
11471
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11472
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11473
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11474
+ /* @__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" }) })
11475
+ ] }),
11476
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11477
+ ] });
11000
11478
  };
11001
- const usePromotions = (query2, options) => {
11002
- const { data, ...rest } = reactQuery.useQuery({
11003
- queryKey: promotionsQueryKeys.list(query2),
11004
- queryFn: async () => sdk.admin.promotion.list(query2),
11005
- ...options
11479
+ const SalesChannelForm = ({ order }) => {
11480
+ const form = reactHookForm.useForm({
11481
+ defaultValues: {
11482
+ sales_channel_id: order.sales_channel_id || ""
11483
+ },
11484
+ resolver: zod.zodResolver(schema$2)
11006
11485
  });
11007
- return { ...data, ...rest };
11486
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11487
+ const { handleSuccess } = useRouteModal();
11488
+ const onSubmit = form.handleSubmit(async (data) => {
11489
+ await mutateAsync(
11490
+ {
11491
+ sales_channel_id: data.sales_channel_id
11492
+ },
11493
+ {
11494
+ onSuccess: () => {
11495
+ ui.toast.success("Sales channel updated");
11496
+ handleSuccess();
11497
+ },
11498
+ onError: (error) => {
11499
+ ui.toast.error(error.message);
11500
+ }
11501
+ }
11502
+ );
11503
+ });
11504
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11505
+ KeyboundForm,
11506
+ {
11507
+ className: "flex flex-1 flex-col overflow-hidden",
11508
+ onSubmit,
11509
+ children: [
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11512
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11513
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11514
+ ] }) })
11515
+ ]
11516
+ }
11517
+ ) });
11008
11518
  };
11009
- const Promotions = () => {
11519
+ const SalesChannelField = ({ control, order }) => {
11520
+ const salesChannels = useComboboxData({
11521
+ queryFn: async (params) => {
11522
+ return await sdk.admin.salesChannel.list(params);
11523
+ },
11524
+ queryKey: ["sales-channels"],
11525
+ getOptions: (data) => {
11526
+ return data.sales_channels.map((salesChannel) => ({
11527
+ label: salesChannel.name,
11528
+ value: salesChannel.id
11529
+ }));
11530
+ },
11531
+ defaultValue: order.sales_channel_id || void 0
11532
+ });
11533
+ return /* @__PURE__ */ jsxRuntime.jsx(
11534
+ Form$2.Field,
11535
+ {
11536
+ control,
11537
+ name: "sales_channel_id",
11538
+ render: ({ field }) => {
11539
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11541
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11542
+ Combobox,
11543
+ {
11544
+ options: salesChannels.options,
11545
+ fetchNextPage: salesChannels.fetchNextPage,
11546
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11547
+ searchValue: salesChannels.searchValue,
11548
+ onSearchValueChange: salesChannels.onSearchValueChange,
11549
+ placeholder: "Select sales channel",
11550
+ ...field
11551
+ }
11552
+ ) }),
11553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11554
+ ] });
11555
+ }
11556
+ }
11557
+ );
11558
+ };
11559
+ const schema$2 = objectType({
11560
+ sales_channel_id: stringType().min(1)
11561
+ });
11562
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11563
+ const Shipping = () => {
11564
+ var _a;
11010
11565
  const { id } = reactRouterDom.useParams();
11566
+ const { order, isPending, isError, error } = useOrder(id, {
11567
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11568
+ });
11011
11569
  const {
11012
11570
  order: preview,
11571
+ isPending: isPreviewPending,
11013
11572
  isError: isPreviewError,
11014
11573
  error: previewError
11015
- } = useOrderPreview(id, void 0);
11574
+ } = useOrderPreview(id);
11016
11575
  useInitiateOrderEdit({ preview });
11017
11576
  const { onCancel } = useCancelOrderEdit({ preview });
11577
+ if (isError) {
11578
+ throw error;
11579
+ }
11018
11580
  if (isPreviewError) {
11019
11581
  throw previewError;
11020
11582
  }
11021
- const isReady = !!preview;
11022
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11023
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11024
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11025
- ] });
11583
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11584
+ const isReady = preview && !isPreviewPending && order && !isPending;
11585
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.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 py-16 px-6", children: [
11588
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11589
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11590
+ ] }) }) }),
11591
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11592
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11593
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11594
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11595
+ ] }) });
11026
11596
  };
11027
- const PromotionForm = ({ preview }) => {
11028
- const { items, shipping_methods } = preview;
11597
+ const ShippingForm = ({ preview, order }) => {
11598
+ var _a;
11599
+ const { setIsOpen } = useStackedModal();
11029
11600
  const [isSubmitting, setIsSubmitting] = React.useState(false);
11030
- const [comboboxValue, setComboboxValue] = React.useState("");
11031
- const { handleSuccess } = useRouteModal();
11032
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11033
- const promoIds = getPromotionIds(items, shipping_methods);
11034
- const { promotions, isPending, isError, error } = usePromotions(
11601
+ const [data, setData] = React.useState(null);
11602
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11603
+ const { shipping_options } = useShippingOptions(
11035
11604
  {
11036
- id: promoIds
11605
+ id: appliedShippingOptionIds,
11606
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11037
11607
  },
11038
11608
  {
11039
- enabled: !!promoIds.length
11609
+ enabled: appliedShippingOptionIds.length > 0
11040
11610
  }
11041
11611
  );
11042
- const comboboxData = useComboboxData({
11043
- queryKey: ["promotions", "combobox", promoIds],
11044
- queryFn: async (params) => {
11045
- return await sdk.admin.promotion.list({
11046
- ...params,
11047
- id: {
11048
- $nin: promoIds
11049
- }
11050
- });
11051
- },
11052
- getOptions: (data) => {
11053
- return data.promotions.map((promotion) => ({
11054
- label: promotion.code,
11055
- value: promotion.code
11056
- }));
11057
- }
11058
- });
11059
- const add = async (value) => {
11060
- if (!value) {
11061
- return;
11062
- }
11063
- addPromotions(
11064
- {
11065
- promo_codes: [value]
11066
- },
11067
- {
11068
- onError: (e) => {
11069
- ui.toast.error(e.message);
11070
- comboboxData.onSearchValueChange("");
11071
- setComboboxValue("");
11072
- },
11073
- onSuccess: () => {
11074
- comboboxData.onSearchValueChange("");
11075
- setComboboxValue("");
11076
- }
11077
- }
11078
- );
11079
- };
11612
+ const uniqueShippingProfiles = React.useMemo(() => {
11613
+ const profiles = /* @__PURE__ */ new Map();
11614
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11615
+ profiles.set(profile.id, profile);
11616
+ });
11617
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11618
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11619
+ });
11620
+ return Array.from(profiles.values());
11621
+ }, [order.items, shipping_options]);
11622
+ const { handleSuccess } = useRouteModal();
11080
11623
  const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11081
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11624
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11625
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11626
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11082
11627
  const onSubmit = async () => {
11083
11628
  setIsSubmitting(true);
11084
11629
  let requestSucceeded = false;
11085
11630
  await requestOrderEdit(void 0, {
11086
11631
  onError: (e) => {
11087
- ui.toast.error(e.message);
11632
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11088
11633
  },
11089
11634
  onSuccess: () => {
11090
11635
  requestSucceeded = true;
@@ -11096,7 +11641,7 @@ const PromotionForm = ({ preview }) => {
11096
11641
  }
11097
11642
  await confirmOrderEdit(void 0, {
11098
11643
  onError: (e) => {
11099
- ui.toast.error(e.message);
11644
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11100
11645
  },
11101
11646
  onSuccess: () => {
11102
11647
  handleSuccess();
@@ -11106,371 +11651,16 @@ const PromotionForm = ({ preview }) => {
11106
11651
  }
11107
11652
  });
11108
11653
  };
11109
- if (isError) {
11110
- throw error;
11111
- }
11112
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11113
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11114
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11115
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11116
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11117
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11118
- ] }),
11119
- /* @__PURE__ */ jsxRuntime.jsx(
11120
- Combobox,
11121
- {
11122
- id: "promotion-combobox",
11123
- "aria-describedby": "promotion-combobox-hint",
11124
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11125
- fetchNextPage: comboboxData.fetchNextPage,
11126
- options: comboboxData.options,
11127
- onSearchValueChange: comboboxData.onSearchValueChange,
11128
- searchValue: comboboxData.searchValue,
11129
- disabled: comboboxData.disabled || isAddingPromotions,
11130
- onChange: add,
11131
- value: comboboxValue
11132
- }
11133
- )
11134
- ] }),
11135
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11136
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11137
- PromotionItem,
11138
- {
11139
- promotion,
11140
- orderId: preview.id,
11141
- isLoading: isPending
11142
- },
11143
- promotion.id
11144
- )) })
11145
- ] }) }),
11146
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11147
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11148
- /* @__PURE__ */ jsxRuntime.jsx(
11149
- ui.Button,
11150
- {
11151
- size: "small",
11152
- type: "submit",
11153
- isLoading: isSubmitting || isAddingPromotions,
11154
- children: "Save"
11155
- }
11156
- )
11157
- ] }) })
11158
- ] });
11159
- };
11160
- const PromotionItem = ({
11161
- promotion,
11162
- orderId,
11163
- isLoading
11164
- }) => {
11165
- var _a;
11166
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11167
- const onRemove = async () => {
11168
- removePromotions(
11169
- {
11170
- promo_codes: [promotion.code]
11171
- },
11172
- {
11173
- onError: (e) => {
11174
- ui.toast.error(e.message);
11175
- }
11176
- }
11177
- );
11178
- };
11179
- const displayValue = getDisplayValue(promotion);
11180
- return /* @__PURE__ */ jsxRuntime.jsxs(
11181
- "div",
11182
- {
11183
- className: ui.clx(
11184
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11185
- {
11186
- "animate-pulse": isLoading
11187
- }
11188
- ),
11189
- children: [
11190
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11191
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11192
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11193
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11194
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11195
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11196
- ] }),
11197
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11198
- ] })
11199
- ] }),
11200
- /* @__PURE__ */ jsxRuntime.jsx(
11201
- ui.IconButton,
11202
- {
11203
- size: "small",
11204
- type: "button",
11205
- variant: "transparent",
11206
- onClick: onRemove,
11207
- isLoading: isPending || isLoading,
11208
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11209
- }
11210
- )
11211
- ]
11212
- },
11213
- promotion.id
11214
- );
11215
- };
11216
- function getDisplayValue(promotion) {
11217
- var _a, _b, _c, _d;
11218
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11219
- if (!value) {
11220
- return null;
11221
- }
11222
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11223
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11224
- if (!currency) {
11225
- return null;
11226
- }
11227
- return getLocaleAmount(value, currency);
11228
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11229
- return formatPercentage(value);
11230
- }
11231
- return null;
11232
- }
11233
- const formatter = new Intl.NumberFormat([], {
11234
- style: "percent",
11235
- minimumFractionDigits: 2
11236
- });
11237
- const formatPercentage = (value, isPercentageValue = false) => {
11238
- let val = value || 0;
11239
- if (!isPercentageValue) {
11240
- val = val / 100;
11241
- }
11242
- return formatter.format(val);
11243
- };
11244
- function getPromotionIds(items, shippingMethods) {
11245
- const promotionIds = /* @__PURE__ */ new Set();
11246
- for (const item of items) {
11247
- if (item.adjustments) {
11248
- for (const adjustment of item.adjustments) {
11249
- if (adjustment.promotion_id) {
11250
- promotionIds.add(adjustment.promotion_id);
11251
- }
11252
- }
11253
- }
11254
- }
11255
- for (const shippingMethod of shippingMethods) {
11256
- if (shippingMethod.adjustments) {
11257
- for (const adjustment of shippingMethod.adjustments) {
11258
- if (adjustment.promotion_id) {
11259
- promotionIds.add(adjustment.promotion_id);
11260
- }
11261
- }
11262
- }
11263
- }
11264
- return Array.from(promotionIds);
11265
- }
11266
- const SalesChannel = () => {
11267
- const { id } = reactRouterDom.useParams();
11268
- const { draft_order, isPending, isError, error } = useDraftOrder(
11269
- id,
11270
- {
11271
- fields: "+sales_channel_id"
11272
- },
11273
- {
11274
- enabled: !!id
11275
- }
11276
- );
11277
- if (isError) {
11278
- throw error;
11279
- }
11280
- const ISrEADY = !!draft_order && !isPending;
11281
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11282
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11283
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11284
- /* @__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" }) })
11285
- ] }),
11286
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11287
- ] });
11288
- };
11289
- const SalesChannelForm = ({ order }) => {
11290
- const form = reactHookForm.useForm({
11291
- defaultValues: {
11292
- sales_channel_id: order.sales_channel_id || ""
11293
- },
11294
- resolver: zod.zodResolver(schema$3)
11295
- });
11296
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11297
- const { handleSuccess } = useRouteModal();
11298
- const onSubmit = form.handleSubmit(async (data) => {
11299
- await mutateAsync(
11300
- {
11301
- sales_channel_id: data.sales_channel_id
11302
- },
11303
- {
11304
- onSuccess: () => {
11305
- ui.toast.success("Sales channel updated");
11306
- handleSuccess();
11307
- },
11308
- onError: (error) => {
11309
- ui.toast.error(error.message);
11654
+ const onKeydown = React.useCallback(
11655
+ (e) => {
11656
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11657
+ if (data || isSubmitting) {
11658
+ return;
11310
11659
  }
11660
+ onSubmit();
11311
11661
  }
11312
- );
11313
- });
11314
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
- KeyboundForm,
11316
- {
11317
- className: "flex flex-1 flex-col overflow-hidden",
11318
- onSubmit,
11319
- children: [
11320
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11321
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11322
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11323
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11324
- ] }) })
11325
- ]
11326
- }
11327
- ) });
11328
- };
11329
- const SalesChannelField = ({ control, order }) => {
11330
- const salesChannels = useComboboxData({
11331
- queryFn: async (params) => {
11332
- return await sdk.admin.salesChannel.list(params);
11333
- },
11334
- queryKey: ["sales-channels"],
11335
- getOptions: (data) => {
11336
- return data.sales_channels.map((salesChannel) => ({
11337
- label: salesChannel.name,
11338
- value: salesChannel.id
11339
- }));
11340
11662
  },
11341
- defaultValue: order.sales_channel_id || void 0
11342
- });
11343
- return /* @__PURE__ */ jsxRuntime.jsx(
11344
- Form$2.Field,
11345
- {
11346
- control,
11347
- name: "sales_channel_id",
11348
- render: ({ field }) => {
11349
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11352
- Combobox,
11353
- {
11354
- options: salesChannels.options,
11355
- fetchNextPage: salesChannels.fetchNextPage,
11356
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11357
- searchValue: salesChannels.searchValue,
11358
- onSearchValueChange: salesChannels.onSearchValueChange,
11359
- placeholder: "Select sales channel",
11360
- ...field
11361
- }
11362
- ) }),
11363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11364
- ] });
11365
- }
11366
- }
11367
- );
11368
- };
11369
- const schema$3 = objectType({
11370
- sales_channel_id: stringType().min(1)
11371
- });
11372
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11373
- const Shipping = () => {
11374
- var _a;
11375
- const { id } = reactRouterDom.useParams();
11376
- const { order, isPending, isError, error } = useOrder(id, {
11377
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11378
- });
11379
- const {
11380
- order: preview,
11381
- isPending: isPreviewPending,
11382
- isError: isPreviewError,
11383
- error: previewError
11384
- } = useOrderPreview(id);
11385
- useInitiateOrderEdit({ preview });
11386
- const { onCancel } = useCancelOrderEdit({ preview });
11387
- if (isError) {
11388
- throw error;
11389
- }
11390
- if (isPreviewError) {
11391
- throw previewError;
11392
- }
11393
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11394
- const isReady = preview && !isPreviewPending && order && !isPending;
11395
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11396
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11397
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.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 py-16 px-6", children: [
11398
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11399
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11400
- ] }) }) }),
11401
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11402
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11403
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11404
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11405
- ] }) });
11406
- };
11407
- const ShippingForm = ({ preview, order }) => {
11408
- var _a;
11409
- const { setIsOpen } = useStackedModal();
11410
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11411
- const [data, setData] = React.useState(null);
11412
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11413
- const { shipping_options } = useShippingOptions(
11414
- {
11415
- id: appliedShippingOptionIds,
11416
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11417
- },
11418
- {
11419
- enabled: appliedShippingOptionIds.length > 0
11420
- }
11421
- );
11422
- const uniqueShippingProfiles = React.useMemo(() => {
11423
- const profiles = /* @__PURE__ */ new Map();
11424
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11425
- profiles.set(profile.id, profile);
11426
- });
11427
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11428
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11429
- });
11430
- return Array.from(profiles.values());
11431
- }, [order.items, shipping_options]);
11432
- const { handleSuccess } = useRouteModal();
11433
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11434
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11435
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11436
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11437
- const onSubmit = async () => {
11438
- setIsSubmitting(true);
11439
- let requestSucceeded = false;
11440
- await requestOrderEdit(void 0, {
11441
- onError: (e) => {
11442
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11443
- },
11444
- onSuccess: () => {
11445
- requestSucceeded = true;
11446
- }
11447
- });
11448
- if (!requestSucceeded) {
11449
- setIsSubmitting(false);
11450
- return;
11451
- }
11452
- await confirmOrderEdit(void 0, {
11453
- onError: (e) => {
11454
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11455
- },
11456
- onSuccess: () => {
11457
- handleSuccess();
11458
- },
11459
- onSettled: () => {
11460
- setIsSubmitting(false);
11461
- }
11462
- });
11463
- };
11464
- const onKeydown = React.useCallback(
11465
- (e) => {
11466
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11467
- if (data || isSubmitting) {
11468
- return;
11469
- }
11470
- onSubmit();
11471
- }
11472
- },
11473
- [data, isSubmitting, onSubmit]
11663
+ [data, isSubmitting, onSubmit]
11474
11664
  );
11475
11665
  React.useEffect(() => {
11476
11666
  document.addEventListener("keydown", onKeydown);
@@ -12176,44 +12366,60 @@ const CustomAmountField = ({
12176
12366
  }
12177
12367
  );
12178
12368
  };
12179
- const TransferOwnership = () => {
12369
+ const ShippingAddress = () => {
12180
12370
  const { id } = reactRouterDom.useParams();
12181
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12182
- fields: "id,customer_id,customer.*"
12371
+ const { order, isPending, isError, error } = useOrder(id, {
12372
+ fields: "+shipping_address"
12183
12373
  });
12184
12374
  if (isError) {
12185
12375
  throw error;
12186
12376
  }
12187
- const isReady = !isPending && !!draft_order;
12377
+ const isReady = !isPending && !!order;
12188
12378
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12189
12379
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12190
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12191
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12380
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12381
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12192
12382
  ] }),
12193
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12383
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12194
12384
  ] });
12195
12385
  };
12196
- const TransferOwnershipForm = ({ order }) => {
12197
- var _a, _b;
12386
+ const ShippingAddressForm = ({ order }) => {
12387
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12198
12388
  const form = reactHookForm.useForm({
12199
12389
  defaultValues: {
12200
- customer_id: order.customer_id || ""
12390
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12391
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12392
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12393
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12394
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12395
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12396
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12397
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12398
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12399
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12201
12400
  },
12202
- resolver: zod.zodResolver(schema$2)
12401
+ resolver: zod.zodResolver(schema$1)
12203
12402
  });
12204
12403
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12205
12404
  const { handleSuccess } = useRouteModal();
12206
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12207
- const currentCustomer = order.customer ? {
12208
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12209
- value: order.customer.id
12210
- } : null;
12211
12405
  const onSubmit = form.handleSubmit(async (data) => {
12212
12406
  await mutateAsync(
12213
- { customer_id: data.customer_id },
12407
+ {
12408
+ shipping_address: {
12409
+ first_name: data.first_name,
12410
+ last_name: data.last_name,
12411
+ company: data.company,
12412
+ address_1: data.address_1,
12413
+ address_2: data.address_2,
12414
+ city: data.city,
12415
+ province: data.province,
12416
+ country_code: data.country_code,
12417
+ postal_code: data.postal_code,
12418
+ phone: data.phone
12419
+ }
12420
+ },
12214
12421
  {
12215
12422
  onSuccess: () => {
12216
- ui.toast.success("Customer updated");
12217
12423
  handleSuccess();
12218
12424
  },
12219
12425
  onError: (error) => {
@@ -12228,76 +12434,263 @@ const TransferOwnershipForm = ({ order }) => {
12228
12434
  className: "flex flex-1 flex-col overflow-hidden",
12229
12435
  onSubmit,
12230
12436
  children: [
12231
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12232
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12233
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12234
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12235
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12236
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12237
- ] }),
12238
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12239
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12240
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12241
- ] })
12437
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12438
+ /* @__PURE__ */ jsxRuntime.jsx(
12439
+ Form$2.Field,
12440
+ {
12441
+ control: form.control,
12442
+ name: "country_code",
12443
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12446
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12447
+ ] })
12448
+ }
12449
+ ),
12450
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12451
+ /* @__PURE__ */ jsxRuntime.jsx(
12452
+ Form$2.Field,
12453
+ {
12454
+ control: form.control,
12455
+ name: "first_name",
12456
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12458
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12459
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12460
+ ] })
12461
+ }
12462
+ ),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(
12464
+ Form$2.Field,
12465
+ {
12466
+ control: form.control,
12467
+ name: "last_name",
12468
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12470
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12471
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12472
+ ] })
12473
+ }
12474
+ )
12242
12475
  ] }),
12243
12476
  /* @__PURE__ */ jsxRuntime.jsx(
12244
- CustomerField,
12477
+ Form$2.Field,
12245
12478
  {
12246
12479
  control: form.control,
12247
- currentCustomerId: order.customer_id
12480
+ name: "company",
12481
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12483
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12484
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12485
+ ] })
12248
12486
  }
12249
- )
12250
- ] }),
12251
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12252
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12253
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12254
- ] }) })
12255
- ]
12256
- }
12257
- ) });
12258
- };
12259
- const CustomerField = ({ control, currentCustomerId }) => {
12260
- const customers = useComboboxData({
12261
- queryFn: async (params) => {
12262
- return await sdk.admin.customer.list({
12263
- ...params,
12264
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12265
- });
12266
- },
12267
- queryKey: ["customers"],
12268
- getOptions: (data) => {
12269
- return data.customers.map((customer) => {
12270
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12271
- return {
12272
- label: name ? `${name} (${customer.email})` : customer.email,
12273
- value: customer.id
12274
- };
12275
- });
12276
- }
12277
- });
12278
- return /* @__PURE__ */ jsxRuntime.jsx(
12279
- Form$2.Field,
12280
- {
12281
- name: "customer_id",
12282
- control,
12283
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12284
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12285
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12286
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12287
- ] }),
12288
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12289
- Combobox,
12290
- {
12291
- options: customers.options,
12292
- fetchNextPage: customers.fetchNextPage,
12293
- isFetchingNextPage: customers.isFetchingNextPage,
12294
- searchValue: customers.searchValue,
12295
- onSearchValueChange: customers.onSearchValueChange,
12296
- placeholder: "Select customer",
12297
- ...field
12298
- }
12299
- ) }),
12300
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12487
+ ),
12488
+ /* @__PURE__ */ jsxRuntime.jsx(
12489
+ Form$2.Field,
12490
+ {
12491
+ control: form.control,
12492
+ name: "address_1",
12493
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12495
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12496
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12497
+ ] })
12498
+ }
12499
+ ),
12500
+ /* @__PURE__ */ jsxRuntime.jsx(
12501
+ Form$2.Field,
12502
+ {
12503
+ control: form.control,
12504
+ name: "address_2",
12505
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12507
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12508
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12509
+ ] })
12510
+ }
12511
+ ),
12512
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12513
+ /* @__PURE__ */ jsxRuntime.jsx(
12514
+ Form$2.Field,
12515
+ {
12516
+ control: form.control,
12517
+ name: "postal_code",
12518
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12521
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12522
+ ] })
12523
+ }
12524
+ ),
12525
+ /* @__PURE__ */ jsxRuntime.jsx(
12526
+ Form$2.Field,
12527
+ {
12528
+ control: form.control,
12529
+ name: "city",
12530
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12532
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12533
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12534
+ ] })
12535
+ }
12536
+ )
12537
+ ] }),
12538
+ /* @__PURE__ */ jsxRuntime.jsx(
12539
+ Form$2.Field,
12540
+ {
12541
+ control: form.control,
12542
+ name: "province",
12543
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12545
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12546
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12547
+ ] })
12548
+ }
12549
+ ),
12550
+ /* @__PURE__ */ jsxRuntime.jsx(
12551
+ Form$2.Field,
12552
+ {
12553
+ control: form.control,
12554
+ name: "phone",
12555
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12557
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12558
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12559
+ ] })
12560
+ }
12561
+ )
12562
+ ] }) }),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12564
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12565
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12566
+ ] }) })
12567
+ ]
12568
+ }
12569
+ ) });
12570
+ };
12571
+ const schema$1 = addressSchema;
12572
+ const TransferOwnership = () => {
12573
+ const { id } = reactRouterDom.useParams();
12574
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12575
+ fields: "id,customer_id,customer.*"
12576
+ });
12577
+ if (isError) {
12578
+ throw error;
12579
+ }
12580
+ const isReady = !isPending && !!draft_order;
12581
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12582
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12583
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12584
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12585
+ ] }),
12586
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12587
+ ] });
12588
+ };
12589
+ const TransferOwnershipForm = ({ order }) => {
12590
+ var _a, _b;
12591
+ const form = reactHookForm.useForm({
12592
+ defaultValues: {
12593
+ customer_id: order.customer_id || ""
12594
+ },
12595
+ resolver: zod.zodResolver(schema)
12596
+ });
12597
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12598
+ const { handleSuccess } = useRouteModal();
12599
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12600
+ const currentCustomer = order.customer ? {
12601
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12602
+ value: order.customer.id
12603
+ } : null;
12604
+ const onSubmit = form.handleSubmit(async (data) => {
12605
+ await mutateAsync(
12606
+ { customer_id: data.customer_id },
12607
+ {
12608
+ onSuccess: () => {
12609
+ ui.toast.success("Customer updated");
12610
+ handleSuccess();
12611
+ },
12612
+ onError: (error) => {
12613
+ ui.toast.error(error.message);
12614
+ }
12615
+ }
12616
+ );
12617
+ });
12618
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12619
+ KeyboundForm,
12620
+ {
12621
+ className: "flex flex-1 flex-col overflow-hidden",
12622
+ onSubmit,
12623
+ children: [
12624
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12625
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12626
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12627
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12628
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12629
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12630
+ ] }),
12631
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12632
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12633
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12634
+ ] })
12635
+ ] }),
12636
+ /* @__PURE__ */ jsxRuntime.jsx(
12637
+ CustomerField,
12638
+ {
12639
+ control: form.control,
12640
+ currentCustomerId: order.customer_id
12641
+ }
12642
+ )
12643
+ ] }),
12644
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12645
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12646
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12647
+ ] }) })
12648
+ ]
12649
+ }
12650
+ ) });
12651
+ };
12652
+ const CustomerField = ({ control, currentCustomerId }) => {
12653
+ const customers = useComboboxData({
12654
+ queryFn: async (params) => {
12655
+ return await sdk.admin.customer.list({
12656
+ ...params,
12657
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12658
+ });
12659
+ },
12660
+ queryKey: ["customers"],
12661
+ getOptions: (data) => {
12662
+ return data.customers.map((customer) => {
12663
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12664
+ return {
12665
+ label: name ? `${name} (${customer.email})` : customer.email,
12666
+ value: customer.id
12667
+ };
12668
+ });
12669
+ }
12670
+ });
12671
+ return /* @__PURE__ */ jsxRuntime.jsx(
12672
+ Form$2.Field,
12673
+ {
12674
+ name: "customer_id",
12675
+ control,
12676
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12677
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12678
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12679
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12680
+ ] }),
12681
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12682
+ Combobox,
12683
+ {
12684
+ options: customers.options,
12685
+ fetchNextPage: customers.fetchNextPage,
12686
+ isFetchingNextPage: customers.isFetchingNextPage,
12687
+ searchValue: customers.searchValue,
12688
+ onSearchValueChange: customers.onSearchValueChange,
12689
+ placeholder: "Select customer",
12690
+ ...field
12691
+ }
12692
+ ) }),
12693
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12301
12694
  ] })
12302
12695
  }
12303
12696
  );
@@ -12516,535 +12909,142 @@ const Illustration = () => {
12516
12909
  "rect",
12517
12910
  {
12518
12911
  width: "12",
12519
- height: "3",
12520
- rx: "1.5",
12521
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12522
- fill: "#A1A1AA"
12523
- }
12524
- ),
12525
- /* @__PURE__ */ jsxRuntime.jsx(
12526
- "path",
12527
- {
12528
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12529
- fill: "#52525B"
12530
- }
12531
- ),
12532
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12533
- "path",
12534
- {
12535
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12536
- stroke: "#A1A1AA",
12537
- strokeWidth: "1.5",
12538
- strokeLinecap: "round",
12539
- strokeLinejoin: "round"
12540
- }
12541
- ) }),
12542
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12543
- "path",
12544
- {
12545
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12546
- stroke: "#A1A1AA",
12547
- strokeWidth: "1.5",
12548
- strokeLinecap: "round",
12549
- strokeLinejoin: "round"
12550
- }
12551
- ) }),
12552
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12553
- "path",
12554
- {
12555
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12556
- stroke: "#A1A1AA",
12557
- strokeWidth: "1.5",
12558
- strokeLinecap: "round",
12559
- strokeLinejoin: "round"
12560
- }
12561
- ) }),
12562
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12563
- "path",
12564
- {
12565
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12566
- stroke: "#A1A1AA",
12567
- strokeWidth: "1.5",
12568
- strokeLinecap: "round",
12569
- strokeLinejoin: "round"
12570
- }
12571
- ) }),
12572
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12573
- "path",
12574
- {
12575
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12576
- stroke: "#A1A1AA",
12577
- strokeWidth: "1.5",
12578
- strokeLinecap: "round",
12579
- strokeLinejoin: "round"
12580
- }
12581
- ) }),
12582
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12583
- "path",
12584
- {
12585
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12586
- stroke: "#A1A1AA",
12587
- strokeWidth: "1.5",
12588
- strokeLinecap: "round",
12589
- strokeLinejoin: "round"
12590
- }
12591
- ) }),
12592
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12593
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12594
- "rect",
12595
- {
12596
- width: "12",
12597
- height: "12",
12598
- fill: "white",
12599
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12600
- }
12601
- ) }),
12602
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12603
- "rect",
12604
- {
12605
- width: "12",
12606
- height: "12",
12607
- fill: "white",
12608
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12609
- }
12610
- ) }),
12611
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12612
- "rect",
12613
- {
12614
- width: "12",
12615
- height: "12",
12616
- fill: "white",
12617
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12618
- }
12619
- ) }),
12620
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12621
- "rect",
12622
- {
12623
- width: "12",
12624
- height: "12",
12625
- fill: "white",
12626
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12627
- }
12628
- ) }),
12629
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12630
- "rect",
12631
- {
12632
- width: "12",
12633
- height: "12",
12634
- fill: "white",
12635
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12636
- }
12637
- ) }),
12638
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12639
- "rect",
12640
- {
12641
- width: "12",
12642
- height: "12",
12643
- fill: "white",
12644
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12645
- }
12646
- ) })
12647
- ] })
12648
- ]
12649
- }
12650
- );
12651
- };
12652
- const schema$2 = objectType({
12653
- customer_id: stringType().min(1)
12654
- });
12655
- const ShippingAddress = () => {
12656
- const { id } = reactRouterDom.useParams();
12657
- const { order, isPending, isError, error } = useOrder(id, {
12658
- fields: "+shipping_address"
12659
- });
12660
- if (isError) {
12661
- throw error;
12662
- }
12663
- const isReady = !isPending && !!order;
12664
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12665
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12666
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12667
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12668
- ] }),
12669
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12670
- ] });
12671
- };
12672
- const ShippingAddressForm = ({ order }) => {
12673
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12674
- const form = reactHookForm.useForm({
12675
- defaultValues: {
12676
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12677
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12678
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12679
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12680
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12681
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12682
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12683
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12684
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12685
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12686
- },
12687
- resolver: zod.zodResolver(schema$1)
12688
- });
12689
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12690
- const { handleSuccess } = useRouteModal();
12691
- const onSubmit = form.handleSubmit(async (data) => {
12692
- await mutateAsync(
12693
- {
12694
- shipping_address: {
12695
- first_name: data.first_name,
12696
- last_name: data.last_name,
12697
- company: data.company,
12698
- address_1: data.address_1,
12699
- address_2: data.address_2,
12700
- city: data.city,
12701
- province: data.province,
12702
- country_code: data.country_code,
12703
- postal_code: data.postal_code,
12704
- phone: data.phone
12705
- }
12706
- },
12707
- {
12708
- onSuccess: () => {
12709
- handleSuccess();
12710
- },
12711
- onError: (error) => {
12712
- ui.toast.error(error.message);
12713
- }
12714
- }
12715
- );
12716
- });
12717
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12718
- KeyboundForm,
12719
- {
12720
- className: "flex flex-1 flex-col overflow-hidden",
12721
- onSubmit,
12722
- children: [
12723
- /* @__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: [
12724
- /* @__PURE__ */ jsxRuntime.jsx(
12725
- Form$2.Field,
12726
- {
12727
- control: form.control,
12728
- name: "country_code",
12729
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12730
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12731
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12732
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12733
- ] })
12734
- }
12735
- ),
12736
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12737
- /* @__PURE__ */ jsxRuntime.jsx(
12738
- Form$2.Field,
12739
- {
12740
- control: form.control,
12741
- name: "first_name",
12742
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12743
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12744
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12745
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12746
- ] })
12747
- }
12748
- ),
12749
- /* @__PURE__ */ jsxRuntime.jsx(
12750
- Form$2.Field,
12751
- {
12752
- control: form.control,
12753
- name: "last_name",
12754
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12755
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12756
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12757
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12758
- ] })
12759
- }
12760
- )
12761
- ] }),
12762
- /* @__PURE__ */ jsxRuntime.jsx(
12763
- Form$2.Field,
12764
- {
12765
- control: form.control,
12766
- name: "company",
12767
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12768
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12769
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12770
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12771
- ] })
12772
- }
12773
- ),
12774
- /* @__PURE__ */ jsxRuntime.jsx(
12775
- Form$2.Field,
12776
- {
12777
- control: form.control,
12778
- name: "address_1",
12779
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12780
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12781
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12782
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12783
- ] })
12784
- }
12785
- ),
12786
- /* @__PURE__ */ jsxRuntime.jsx(
12787
- Form$2.Field,
12788
- {
12789
- control: form.control,
12790
- name: "address_2",
12791
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12792
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12793
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12794
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12795
- ] })
12796
- }
12797
- ),
12798
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12799
- /* @__PURE__ */ jsxRuntime.jsx(
12800
- Form$2.Field,
12801
- {
12802
- control: form.control,
12803
- name: "postal_code",
12804
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12805
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12806
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12807
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12808
- ] })
12809
- }
12810
- ),
12811
- /* @__PURE__ */ jsxRuntime.jsx(
12812
- Form$2.Field,
12813
- {
12814
- control: form.control,
12815
- name: "city",
12816
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12817
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12818
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12819
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12820
- ] })
12821
- }
12822
- )
12823
- ] }),
12824
- /* @__PURE__ */ jsxRuntime.jsx(
12825
- Form$2.Field,
12826
- {
12827
- control: form.control,
12828
- name: "province",
12829
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12830
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12831
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12832
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12833
- ] })
12834
- }
12835
- ),
12836
- /* @__PURE__ */ jsxRuntime.jsx(
12837
- Form$2.Field,
12838
- {
12839
- control: form.control,
12840
- name: "phone",
12841
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12842
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12843
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12844
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12845
- ] })
12846
- }
12847
- )
12848
- ] }) }),
12849
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12850
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12851
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12852
- ] }) })
12853
- ]
12854
- }
12855
- ) });
12856
- };
12857
- const schema$1 = addressSchema;
12858
- const BillingAddress = () => {
12859
- const { id } = reactRouterDom.useParams();
12860
- const { order, isPending, isError, error } = useOrder(id, {
12861
- fields: "+billing_address"
12862
- });
12863
- if (isError) {
12864
- throw error;
12865
- }
12866
- const isReady = !isPending && !!order;
12867
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12868
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12869
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12870
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
12871
- ] }),
12872
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12873
- ] });
12874
- };
12875
- const BillingAddressForm = ({ order }) => {
12876
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12877
- const form = reactHookForm.useForm({
12878
- defaultValues: {
12879
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12880
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12881
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12882
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12883
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12884
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12885
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12886
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12887
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12888
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12889
- },
12890
- resolver: zod.zodResolver(schema)
12891
- });
12892
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12893
- const { handleSuccess } = useRouteModal();
12894
- const onSubmit = form.handleSubmit(async (data) => {
12895
- await mutateAsync(
12896
- { billing_address: data },
12897
- {
12898
- onSuccess: () => {
12899
- handleSuccess();
12900
- },
12901
- onError: (error) => {
12902
- ui.toast.error(error.message);
12903
- }
12904
- }
12905
- );
12906
- });
12907
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12908
- KeyboundForm,
12909
- {
12910
- className: "flex flex-1 flex-col overflow-hidden",
12911
- onSubmit,
12912
- children: [
12913
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12914
- /* @__PURE__ */ jsxRuntime.jsx(
12915
- Form$2.Field,
12912
+ height: "3",
12913
+ rx: "1.5",
12914
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12915
+ fill: "#A1A1AA"
12916
+ }
12917
+ ),
12918
+ /* @__PURE__ */ jsxRuntime.jsx(
12919
+ "path",
12920
+ {
12921
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12922
+ fill: "#52525B"
12923
+ }
12924
+ ),
12925
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12926
+ "path",
12927
+ {
12928
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12929
+ stroke: "#A1A1AA",
12930
+ strokeWidth: "1.5",
12931
+ strokeLinecap: "round",
12932
+ strokeLinejoin: "round"
12933
+ }
12934
+ ) }),
12935
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12936
+ "path",
12937
+ {
12938
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12939
+ stroke: "#A1A1AA",
12940
+ strokeWidth: "1.5",
12941
+ strokeLinecap: "round",
12942
+ strokeLinejoin: "round"
12943
+ }
12944
+ ) }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12946
+ "path",
12947
+ {
12948
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12949
+ stroke: "#A1A1AA",
12950
+ strokeWidth: "1.5",
12951
+ strokeLinecap: "round",
12952
+ strokeLinejoin: "round"
12953
+ }
12954
+ ) }),
12955
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12956
+ "path",
12957
+ {
12958
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12959
+ stroke: "#A1A1AA",
12960
+ strokeWidth: "1.5",
12961
+ strokeLinecap: "round",
12962
+ strokeLinejoin: "round"
12963
+ }
12964
+ ) }),
12965
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12966
+ "path",
12967
+ {
12968
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12969
+ stroke: "#A1A1AA",
12970
+ strokeWidth: "1.5",
12971
+ strokeLinecap: "round",
12972
+ strokeLinejoin: "round"
12973
+ }
12974
+ ) }),
12975
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12976
+ "path",
12977
+ {
12978
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12979
+ stroke: "#A1A1AA",
12980
+ strokeWidth: "1.5",
12981
+ strokeLinecap: "round",
12982
+ strokeLinejoin: "round"
12983
+ }
12984
+ ) }),
12985
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12986
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12987
+ "rect",
12916
12988
  {
12917
- control: form.control,
12918
- name: "country_code",
12919
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12921
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12922
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
- ] })
12989
+ width: "12",
12990
+ height: "12",
12991
+ fill: "white",
12992
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12924
12993
  }
12925
- ),
12926
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12927
- /* @__PURE__ */ jsxRuntime.jsx(
12928
- Form$2.Field,
12929
- {
12930
- control: form.control,
12931
- name: "first_name",
12932
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12934
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12935
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12936
- ] })
12937
- }
12938
- ),
12939
- /* @__PURE__ */ jsxRuntime.jsx(
12940
- Form$2.Field,
12941
- {
12942
- control: form.control,
12943
- name: "last_name",
12944
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12946
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
- ] })
12949
- }
12950
- )
12951
- ] }),
12952
- /* @__PURE__ */ jsxRuntime.jsx(
12953
- Form$2.Field,
12994
+ ) }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12996
+ "rect",
12954
12997
  {
12955
- control: form.control,
12956
- name: "company",
12957
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12959
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12960
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12961
- ] })
12998
+ width: "12",
12999
+ height: "12",
13000
+ fill: "white",
13001
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12962
13002
  }
12963
- ),
12964
- /* @__PURE__ */ jsxRuntime.jsx(
12965
- Form$2.Field,
13003
+ ) }),
13004
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13005
+ "rect",
12966
13006
  {
12967
- control: form.control,
12968
- name: "address_1",
12969
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12971
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12972
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12973
- ] })
13007
+ width: "12",
13008
+ height: "12",
13009
+ fill: "white",
13010
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12974
13011
  }
12975
- ),
12976
- /* @__PURE__ */ jsxRuntime.jsx(
12977
- Form$2.Field,
13012
+ ) }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13014
+ "rect",
12978
13015
  {
12979
- control: form.control,
12980
- name: "address_2",
12981
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12983
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
- ] })
13016
+ width: "12",
13017
+ height: "12",
13018
+ fill: "white",
13019
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12986
13020
  }
12987
- ),
12988
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12989
- /* @__PURE__ */ jsxRuntime.jsx(
12990
- Form$2.Field,
12991
- {
12992
- control: form.control,
12993
- name: "postal_code",
12994
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12996
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12997
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12998
- ] })
12999
- }
13000
- ),
13001
- /* @__PURE__ */ jsxRuntime.jsx(
13002
- Form$2.Field,
13003
- {
13004
- control: form.control,
13005
- name: "city",
13006
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13008
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
- ] })
13011
- }
13012
- )
13013
- ] }),
13014
- /* @__PURE__ */ jsxRuntime.jsx(
13015
- Form$2.Field,
13021
+ ) }),
13022
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13023
+ "rect",
13016
13024
  {
13017
- control: form.control,
13018
- name: "province",
13019
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13021
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13022
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13023
- ] })
13025
+ width: "12",
13026
+ height: "12",
13027
+ fill: "white",
13028
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13024
13029
  }
13025
- ),
13026
- /* @__PURE__ */ jsxRuntime.jsx(
13027
- Form$2.Field,
13030
+ ) }),
13031
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13032
+ "rect",
13028
13033
  {
13029
- control: form.control,
13030
- name: "phone",
13031
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13033
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13034
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13035
- ] })
13034
+ width: "12",
13035
+ height: "12",
13036
+ fill: "white",
13037
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13036
13038
  }
13037
- )
13038
- ] }) }),
13039
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13042
- ] }) })
13039
+ ) })
13040
+ ] })
13043
13041
  ]
13044
13042
  }
13045
- ) });
13043
+ );
13046
13044
  };
13047
- const schema = addressSchema;
13045
+ const schema = objectType({
13046
+ customer_id: stringType().min(1)
13047
+ });
13048
13048
  const widgetModule = { widgets: [] };
13049
13049
  const routeModule = {
13050
13050
  routes: [
@@ -13065,6 +13065,10 @@ const routeModule = {
13065
13065
  handle,
13066
13066
  loader,
13067
13067
  children: [
13068
+ {
13069
+ Component: BillingAddress,
13070
+ path: "/draft-orders/:id/billing-address"
13071
+ },
13068
13072
  {
13069
13073
  Component: CustomItems,
13070
13074
  path: "/draft-orders/:id/custom-items"
@@ -13073,14 +13077,14 @@ const routeModule = {
13073
13077
  Component: Email,
13074
13078
  path: "/draft-orders/:id/email"
13075
13079
  },
13076
- {
13077
- Component: Items,
13078
- path: "/draft-orders/:id/items"
13079
- },
13080
13080
  {
13081
13081
  Component: Metadata,
13082
13082
  path: "/draft-orders/:id/metadata"
13083
13083
  },
13084
+ {
13085
+ Component: Items,
13086
+ path: "/draft-orders/:id/items"
13087
+ },
13084
13088
  {
13085
13089
  Component: Promotions,
13086
13090
  path: "/draft-orders/:id/promotions"
@@ -13093,17 +13097,13 @@ const routeModule = {
13093
13097
  Component: Shipping,
13094
13098
  path: "/draft-orders/:id/shipping"
13095
13099
  },
13096
- {
13097
- Component: TransferOwnership,
13098
- path: "/draft-orders/:id/transfer-ownership"
13099
- },
13100
13100
  {
13101
13101
  Component: ShippingAddress,
13102
13102
  path: "/draft-orders/:id/shipping-address"
13103
13103
  },
13104
13104
  {
13105
- Component: BillingAddress,
13106
- path: "/draft-orders/:id/billing-address"
13105
+ Component: TransferOwnership,
13106
+ path: "/draft-orders/:id/transfer-ownership"
13107
13107
  }
13108
13108
  ]
13109
13109
  }