@medusajs/draft-order 2.11.0-snapshot-20251017211629 → 2.11.0-snapshot-20251020120939

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.
@@ -7823,12 +7823,10 @@ const CustomerField$1 = ({ control, setValue }) => {
7823
7823
  (option) => option.value === value
7824
7824
  )) == null ? void 0 : _a.label;
7825
7825
  const customerEmail = ((_b = label == null ? void 0 : label.match(/\((.*@.*)\)$/)) == null ? void 0 : _b[1]) || label;
7826
- if (!email && customerEmail) {
7827
- setValue("email", customerEmail, {
7828
- shouldDirty: true,
7829
- shouldTouch: true
7830
- });
7831
- }
7826
+ setValue("email", customerEmail || "", {
7827
+ shouldDirty: true,
7828
+ shouldTouch: true
7829
+ });
7832
7830
  },
7833
7831
  [email, setValue, customers.options]
7834
7832
  );
@@ -9573,6 +9571,196 @@ const ID = () => {
9573
9571
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9574
9572
  ] });
9575
9573
  };
9574
+ const BillingAddress = () => {
9575
+ const { id } = reactRouterDom.useParams();
9576
+ const { order, isPending, isError, error } = useOrder(id, {
9577
+ fields: "+billing_address"
9578
+ });
9579
+ if (isError) {
9580
+ throw error;
9581
+ }
9582
+ const isReady = !isPending && !!order;
9583
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9584
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9585
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9587
+ ] }),
9588
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9589
+ ] });
9590
+ };
9591
+ const BillingAddressForm = ({ order }) => {
9592
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9593
+ const form = reactHookForm.useForm({
9594
+ defaultValues: {
9595
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9596
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9597
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9598
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9599
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9600
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9601
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9602
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9603
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9604
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9605
+ },
9606
+ resolver: zod.zodResolver(schema$5)
9607
+ });
9608
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9609
+ const { handleSuccess } = useRouteModal();
9610
+ const onSubmit = form.handleSubmit(async (data) => {
9611
+ await mutateAsync(
9612
+ { billing_address: data },
9613
+ {
9614
+ onSuccess: () => {
9615
+ handleSuccess();
9616
+ },
9617
+ onError: (error) => {
9618
+ ui.toast.error(error.message);
9619
+ }
9620
+ }
9621
+ );
9622
+ });
9623
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9624
+ KeyboundForm,
9625
+ {
9626
+ className: "flex flex-1 flex-col overflow-hidden",
9627
+ onSubmit,
9628
+ children: [
9629
+ /* @__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: [
9630
+ /* @__PURE__ */ jsxRuntime.jsx(
9631
+ Form$2.Field,
9632
+ {
9633
+ control: form.control,
9634
+ name: "country_code",
9635
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9636
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9639
+ ] })
9640
+ }
9641
+ ),
9642
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9643
+ /* @__PURE__ */ jsxRuntime.jsx(
9644
+ Form$2.Field,
9645
+ {
9646
+ control: form.control,
9647
+ name: "first_name",
9648
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9652
+ ] })
9653
+ }
9654
+ ),
9655
+ /* @__PURE__ */ jsxRuntime.jsx(
9656
+ Form$2.Field,
9657
+ {
9658
+ control: form.control,
9659
+ name: "last_name",
9660
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9664
+ ] })
9665
+ }
9666
+ )
9667
+ ] }),
9668
+ /* @__PURE__ */ jsxRuntime.jsx(
9669
+ Form$2.Field,
9670
+ {
9671
+ control: form.control,
9672
+ name: "company",
9673
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9674
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9677
+ ] })
9678
+ }
9679
+ ),
9680
+ /* @__PURE__ */ jsxRuntime.jsx(
9681
+ Form$2.Field,
9682
+ {
9683
+ control: form.control,
9684
+ name: "address_1",
9685
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9686
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9689
+ ] })
9690
+ }
9691
+ ),
9692
+ /* @__PURE__ */ jsxRuntime.jsx(
9693
+ Form$2.Field,
9694
+ {
9695
+ control: form.control,
9696
+ name: "address_2",
9697
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9701
+ ] })
9702
+ }
9703
+ ),
9704
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9705
+ /* @__PURE__ */ jsxRuntime.jsx(
9706
+ Form$2.Field,
9707
+ {
9708
+ control: form.control,
9709
+ name: "postal_code",
9710
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9711
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9714
+ ] })
9715
+ }
9716
+ ),
9717
+ /* @__PURE__ */ jsxRuntime.jsx(
9718
+ Form$2.Field,
9719
+ {
9720
+ control: form.control,
9721
+ name: "city",
9722
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9723
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9726
+ ] })
9727
+ }
9728
+ )
9729
+ ] }),
9730
+ /* @__PURE__ */ jsxRuntime.jsx(
9731
+ Form$2.Field,
9732
+ {
9733
+ control: form.control,
9734
+ name: "province",
9735
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9736
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9739
+ ] })
9740
+ }
9741
+ ),
9742
+ /* @__PURE__ */ jsxRuntime.jsx(
9743
+ Form$2.Field,
9744
+ {
9745
+ control: form.control,
9746
+ name: "phone",
9747
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9748
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9751
+ ] })
9752
+ }
9753
+ )
9754
+ ] }) }),
9755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9756
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9757
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9758
+ ] }) })
9759
+ ]
9760
+ }
9761
+ ) });
9762
+ };
9763
+ const schema$5 = addressSchema;
9576
9764
  const CustomItems = () => {
9577
9765
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9578
9766
  /* @__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 +9769,7 @@ const CustomItems = () => {
9581
9769
  };
9582
9770
  const CustomItemsForm = () => {
9583
9771
  const form = reactHookForm.useForm({
9584
- resolver: zod.zodResolver(schema$5)
9772
+ resolver: zod.zodResolver(schema$4)
9585
9773
  });
9586
9774
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9587
9775
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
@@ -9591,7 +9779,7 @@ const CustomItemsForm = () => {
9591
9779
  ] }) })
9592
9780
  ] }) });
9593
9781
  };
9594
- const schema$5 = objectType({
9782
+ const schema$4 = objectType({
9595
9783
  email: stringType().email()
9596
9784
  });
9597
9785
  const Email = () => {
@@ -9616,7 +9804,7 @@ const EmailForm = ({ order }) => {
9616
9804
  defaultValues: {
9617
9805
  email: order.email ?? ""
9618
9806
  },
9619
- resolver: zod.zodResolver(schema$4)
9807
+ resolver: zod.zodResolver(schema$3)
9620
9808
  });
9621
9809
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9622
9810
  const { handleSuccess } = useRouteModal();
@@ -9659,797 +9847,606 @@ const EmailForm = ({ order }) => {
9659
9847
  }
9660
9848
  ) });
9661
9849
  };
9662
- const schema$4 = objectType({
9850
+ const schema$3 = objectType({
9663
9851
  email: stringType().email()
9664
9852
  });
9665
- const InlineTip = React.forwardRef(
9666
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9667
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9853
+ const NumberInput = React.forwardRef(
9854
+ ({
9855
+ value,
9856
+ onChange,
9857
+ size = "base",
9858
+ min = 0,
9859
+ max = 100,
9860
+ step = 1,
9861
+ className,
9862
+ disabled,
9863
+ ...props
9864
+ }, ref) => {
9865
+ const handleChange = (event) => {
9866
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9867
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9868
+ onChange(newValue);
9869
+ }
9870
+ };
9871
+ const handleIncrement = () => {
9872
+ const newValue = value + step;
9873
+ if (max === void 0 || newValue <= max) {
9874
+ onChange(newValue);
9875
+ }
9876
+ };
9877
+ const handleDecrement = () => {
9878
+ const newValue = value - step;
9879
+ if (min === void 0 || newValue >= min) {
9880
+ onChange(newValue);
9881
+ }
9882
+ };
9668
9883
  return /* @__PURE__ */ jsxRuntime.jsxs(
9669
9884
  "div",
9670
9885
  {
9671
- ref,
9672
9886
  className: ui.clx(
9673
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9887
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9888
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9889
+ {
9890
+ "h-7": size === "small",
9891
+ "h-8": size === "base"
9892
+ },
9674
9893
  className
9675
9894
  ),
9676
- ...props,
9677
9895
  children: [
9678
9896
  /* @__PURE__ */ jsxRuntime.jsx(
9679
- "div",
9897
+ "input",
9680
9898
  {
9681
- role: "presentation",
9682
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9683
- "bg-ui-tag-orange-icon": variant === "warning"
9684
- })
9685
- }
9686
- ),
9687
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9688
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9689
- labelValue,
9690
- ":"
9691
- ] }),
9692
- " ",
9693
- children
9694
- ] })
9899
+ ref,
9900
+ type: "number",
9901
+ value,
9902
+ onChange: handleChange,
9903
+ min,
9904
+ max,
9905
+ step,
9906
+ className: ui.clx(
9907
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9908
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9909
+ "placeholder:text-ui-fg-muted"
9910
+ ),
9911
+ ...props
9912
+ }
9913
+ ),
9914
+ /* @__PURE__ */ jsxRuntime.jsxs(
9915
+ "button",
9916
+ {
9917
+ className: ui.clx(
9918
+ "flex items-center justify-center outline-none transition-fg",
9919
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9920
+ "focus:bg-ui-bg-field-component-hover",
9921
+ "hover:bg-ui-bg-field-component-hover",
9922
+ {
9923
+ "size-7": size === "small",
9924
+ "size-8": size === "base"
9925
+ }
9926
+ ),
9927
+ type: "button",
9928
+ onClick: handleDecrement,
9929
+ disabled: min !== void 0 && value <= min || disabled,
9930
+ children: [
9931
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9932
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9933
+ ]
9934
+ }
9935
+ ),
9936
+ /* @__PURE__ */ jsxRuntime.jsxs(
9937
+ "button",
9938
+ {
9939
+ className: ui.clx(
9940
+ "flex items-center justify-center outline-none transition-fg",
9941
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9942
+ "focus:bg-ui-bg-field-hover",
9943
+ "hover:bg-ui-bg-field-hover",
9944
+ {
9945
+ "size-7": size === "small",
9946
+ "size-8": size === "base"
9947
+ }
9948
+ ),
9949
+ type: "button",
9950
+ onClick: handleIncrement,
9951
+ disabled: max !== void 0 && value >= max || disabled,
9952
+ children: [
9953
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9954
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9955
+ ]
9956
+ }
9957
+ )
9695
9958
  ]
9696
9959
  }
9697
9960
  );
9698
9961
  }
9699
9962
  );
9700
- InlineTip.displayName = "InlineTip";
9701
- const MetadataFieldSchema = objectType({
9702
- key: stringType(),
9703
- disabled: booleanType().optional(),
9704
- value: anyType()
9705
- });
9706
- const MetadataSchema = objectType({
9707
- metadata: arrayType(MetadataFieldSchema)
9708
- });
9709
- const Metadata = () => {
9963
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9964
+ const productVariantsQueryKeys = {
9965
+ list: (query2) => [
9966
+ PRODUCT_VARIANTS_QUERY_KEY,
9967
+ query2 ? query2 : void 0
9968
+ ]
9969
+ };
9970
+ const useProductVariants = (query2, options) => {
9971
+ const { data, ...rest } = reactQuery.useQuery({
9972
+ queryKey: productVariantsQueryKeys.list(query2),
9973
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9974
+ ...options
9975
+ });
9976
+ return { ...data, ...rest };
9977
+ };
9978
+ const useCancelOrderEdit = ({ preview }) => {
9979
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9980
+ const onCancel = React.useCallback(async () => {
9981
+ if (!preview) {
9982
+ return true;
9983
+ }
9984
+ let res = false;
9985
+ await cancelOrderEdit(void 0, {
9986
+ onError: (e) => {
9987
+ ui.toast.error(e.message);
9988
+ },
9989
+ onSuccess: () => {
9990
+ res = true;
9991
+ }
9992
+ });
9993
+ return res;
9994
+ }, [preview, cancelOrderEdit]);
9995
+ return { onCancel };
9996
+ };
9997
+ let IS_REQUEST_RUNNING = false;
9998
+ const useInitiateOrderEdit = ({
9999
+ preview
10000
+ }) => {
10001
+ const navigate = reactRouterDom.useNavigate();
10002
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10003
+ React.useEffect(() => {
10004
+ async function run() {
10005
+ if (IS_REQUEST_RUNNING || !preview) {
10006
+ return;
10007
+ }
10008
+ if (preview.order_change) {
10009
+ return;
10010
+ }
10011
+ IS_REQUEST_RUNNING = true;
10012
+ await mutateAsync(void 0, {
10013
+ onError: (e) => {
10014
+ ui.toast.error(e.message);
10015
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10016
+ return;
10017
+ }
10018
+ });
10019
+ IS_REQUEST_RUNNING = false;
10020
+ }
10021
+ run();
10022
+ }, [preview, navigate, mutateAsync]);
10023
+ };
10024
+ function convertNumber(value) {
10025
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10026
+ }
10027
+ const STACKED_MODAL_ID = "items_stacked_modal";
10028
+ const Items = () => {
9710
10029
  const { id } = reactRouterDom.useParams();
9711
- const { order, isPending, isError, error } = useOrder(id, {
9712
- fields: "metadata"
10030
+ const {
10031
+ order: preview,
10032
+ isPending: isPreviewPending,
10033
+ isError: isPreviewError,
10034
+ error: previewError
10035
+ } = useOrderPreview(id, void 0, {
10036
+ placeholderData: reactQuery.keepPreviousData
9713
10037
  });
10038
+ useInitiateOrderEdit({ preview });
10039
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10040
+ id,
10041
+ {
10042
+ fields: "currency_code"
10043
+ },
10044
+ {
10045
+ enabled: !!id
10046
+ }
10047
+ );
10048
+ const { onCancel } = useCancelOrderEdit({ preview });
9714
10049
  if (isError) {
9715
10050
  throw error;
9716
10051
  }
9717
- const isReady = !isPending && !!order;
9718
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9719
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9720
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9721
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9722
- ] }),
9723
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9724
- ] });
10052
+ if (isPreviewError) {
10053
+ throw previewError;
10054
+ }
10055
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10056
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10057
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10058
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10059
+ ] }) });
9725
10060
  };
9726
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9727
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9728
- const MetadataForm = ({ orderId, metadata }) => {
10061
+ const ItemsForm = ({ preview, currencyCode }) => {
10062
+ var _a;
10063
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10064
+ const [modalContent, setModalContent] = React.useState(
10065
+ null
10066
+ );
9729
10067
  const { handleSuccess } = useRouteModal();
9730
- const hasUneditableRows = getHasUneditableRows(metadata);
9731
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9732
- const form = reactHookForm.useForm({
9733
- defaultValues: {
9734
- metadata: getDefaultValues(metadata)
9735
- },
9736
- resolver: zod.zodResolver(MetadataSchema)
9737
- });
9738
- const handleSubmit = form.handleSubmit(async (data) => {
9739
- const parsedData = parseValues(data);
9740
- await mutateAsync(
9741
- {
9742
- metadata: parsedData
10068
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10069
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10070
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10071
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10072
+ const matches = React.useMemo(() => {
10073
+ return matchSorter.matchSorter(preview.items, query2, {
10074
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10075
+ });
10076
+ }, [preview.items, query2]);
10077
+ const onSubmit = async () => {
10078
+ setIsSubmitting(true);
10079
+ let requestSucceeded = false;
10080
+ await requestOrderEdit(void 0, {
10081
+ onError: (e) => {
10082
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
9743
10083
  },
9744
- {
9745
- onSuccess: () => {
9746
- ui.toast.success("Metadata updated");
9747
- handleSuccess();
9748
- },
9749
- onError: (error) => {
9750
- ui.toast.error(error.message);
9751
- }
10084
+ onSuccess: () => {
10085
+ requestSucceeded = true;
9752
10086
  }
9753
- );
9754
- });
9755
- const { fields, insert, remove } = reactHookForm.useFieldArray({
9756
- control: form.control,
9757
- name: "metadata"
9758
- });
9759
- function deleteRow(index) {
9760
- remove(index);
9761
- if (fields.length === 1) {
9762
- insert(0, {
9763
- key: "",
9764
- value: "",
9765
- disabled: false
9766
- });
10087
+ });
10088
+ if (!requestSucceeded) {
10089
+ setIsSubmitting(false);
10090
+ return;
9767
10091
  }
9768
- }
9769
- function insertRow(index, position) {
9770
- insert(index + (position === "above" ? 0 : 1), {
9771
- key: "",
9772
- value: "",
9773
- disabled: false
10092
+ await confirmOrderEdit(void 0, {
10093
+ onError: (e) => {
10094
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10095
+ },
10096
+ onSuccess: () => {
10097
+ handleSuccess();
10098
+ },
10099
+ onSettled: () => {
10100
+ setIsSubmitting(false);
10101
+ }
9774
10102
  });
9775
- }
9776
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9777
- KeyboundForm,
9778
- {
9779
- onSubmit: handleSubmit,
9780
- className: "flex flex-1 flex-col overflow-hidden",
9781
- children: [
9782
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9783
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9784
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9785
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9786
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10103
+ };
10104
+ const onKeyDown = React.useCallback(
10105
+ (e) => {
10106
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10107
+ if (modalContent || isSubmitting) {
10108
+ return;
10109
+ }
10110
+ onSubmit();
10111
+ }
10112
+ },
10113
+ [modalContent, isSubmitting, onSubmit]
10114
+ );
10115
+ React.useEffect(() => {
10116
+ document.addEventListener("keydown", onKeyDown);
10117
+ return () => {
10118
+ document.removeEventListener("keydown", onKeyDown);
10119
+ };
10120
+ }, [onKeyDown]);
10121
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10122
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10123
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10124
+ StackedFocusModal,
10125
+ {
10126
+ id: STACKED_MODAL_ID,
10127
+ onOpenChangeCallback: (open) => {
10128
+ if (!open) {
10129
+ setModalContent(null);
10130
+ }
10131
+ },
10132
+ children: [
10133
+ /* @__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: [
10134
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10135
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10136
+ /* @__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" }) })
9787
10137
  ] }),
9788
- fields.map((field, index) => {
9789
- const isDisabled = field.disabled || false;
9790
- let placeholder = "-";
9791
- if (typeof field.value === "object") {
9792
- placeholder = "{ ... }";
9793
- }
9794
- if (Array.isArray(field.value)) {
9795
- placeholder = "[ ... ]";
9796
- }
9797
- return /* @__PURE__ */ jsxRuntime.jsx(
9798
- ConditionalTooltip,
9799
- {
9800
- showTooltip: isDisabled,
9801
- content: "This row is disabled because it contains non-primitive data.",
9802
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9803
- /* @__PURE__ */ jsxRuntime.jsxs(
9804
- "div",
9805
- {
9806
- className: ui.clx("grid grid-cols-2 divide-x", {
9807
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9808
- }),
9809
- children: [
9810
- /* @__PURE__ */ jsxRuntime.jsx(
9811
- Form$2.Field,
9812
- {
9813
- control: form.control,
9814
- name: `metadata.${index}.key`,
9815
- render: ({ field: field2 }) => {
9816
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9817
- GridInput,
9818
- {
9819
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9820
- ...field2,
9821
- disabled: isDisabled,
9822
- placeholder: "Key"
9823
- }
9824
- ) }) });
9825
- }
9826
- }
9827
- ),
9828
- /* @__PURE__ */ jsxRuntime.jsx(
9829
- Form$2.Field,
9830
- {
9831
- control: form.control,
9832
- name: `metadata.${index}.value`,
9833
- render: ({ field: { value, ...field2 } }) => {
9834
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9835
- GridInput,
9836
- {
9837
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9838
- ...field2,
9839
- value: isDisabled ? placeholder : value,
9840
- disabled: isDisabled,
9841
- placeholder: "Value"
9842
- }
9843
- ) }) });
9844
- }
9845
- }
9846
- )
9847
- ]
9848
- }
9849
- ),
9850
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10138
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10139
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10140
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10141
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10142
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10143
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10144
+ ] }),
10145
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10146
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10147
+ ui.Input,
10148
+ {
10149
+ type: "search",
10150
+ placeholder: "Search items",
10151
+ value: searchValue,
10152
+ onChange: (e) => onSearchValueChange(e.target.value)
10153
+ }
10154
+ ) }),
10155
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10156
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10157
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9851
10158
  /* @__PURE__ */ jsxRuntime.jsx(
9852
- ui.DropdownMenu.Trigger,
10159
+ StackedModalTrigger$1,
9853
10160
  {
9854
- className: ui.clx(
9855
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9856
- {
9857
- hidden: isDisabled
9858
- }
9859
- ),
9860
- disabled: isDisabled,
9861
- asChild: true,
9862
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10161
+ type: "add-items",
10162
+ setModalContent
9863
10163
  }
9864
10164
  ),
9865
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9866
- /* @__PURE__ */ jsxRuntime.jsxs(
9867
- ui.DropdownMenu.Item,
9868
- {
9869
- className: "gap-x-2",
9870
- onClick: () => insertRow(index, "above"),
9871
- children: [
9872
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9873
- "Insert row above"
9874
- ]
9875
- }
9876
- ),
9877
- /* @__PURE__ */ jsxRuntime.jsxs(
9878
- ui.DropdownMenu.Item,
9879
- {
9880
- className: "gap-x-2",
9881
- onClick: () => insertRow(index, "below"),
9882
- children: [
9883
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
9884
- "Insert row below"
9885
- ]
9886
- }
9887
- ),
9888
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
9889
- /* @__PURE__ */ jsxRuntime.jsxs(
9890
- ui.DropdownMenu.Item,
9891
- {
9892
- className: "gap-x-2",
9893
- onClick: () => deleteRow(index),
9894
- children: [
9895
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
9896
- "Delete row"
9897
- ]
9898
- }
9899
- )
9900
- ] })
10165
+ /* @__PURE__ */ jsxRuntime.jsx(
10166
+ StackedModalTrigger$1,
10167
+ {
10168
+ type: "add-custom-item",
10169
+ setModalContent
10170
+ }
10171
+ )
9901
10172
  ] })
9902
10173
  ] })
9903
- },
9904
- field.id
9905
- );
9906
- })
9907
- ] }),
9908
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
9909
- ] }),
9910
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9911
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9912
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9913
- ] }) })
9914
- ]
9915
- }
9916
- ) });
9917
- };
9918
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
9919
- return /* @__PURE__ */ jsxRuntime.jsx(
9920
- "input",
9921
- {
9922
- ref,
9923
- ...props,
9924
- autoComplete: "off",
9925
- className: ui.clx(
9926
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
9927
- className
9928
- )
9929
- }
9930
- );
9931
- });
9932
- GridInput.displayName = "MetadataForm.GridInput";
9933
- const PlaceholderInner = () => {
9934
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
9935
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
9936
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
9937
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
9938
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
9939
- ] }) })
9940
- ] });
9941
- };
9942
- const EDITABLE_TYPES = ["string", "number", "boolean"];
9943
- function getDefaultValues(metadata) {
9944
- if (!metadata || !Object.keys(metadata).length) {
9945
- return [
9946
- {
9947
- key: "",
9948
- value: "",
9949
- disabled: false
9950
- }
9951
- ];
9952
- }
9953
- return Object.entries(metadata).map(([key, value]) => {
9954
- if (!EDITABLE_TYPES.includes(typeof value)) {
9955
- return {
9956
- key,
9957
- value,
9958
- disabled: true
9959
- };
9960
- }
9961
- let stringValue = value;
9962
- if (typeof value !== "string") {
9963
- stringValue = JSON.stringify(value);
9964
- }
9965
- return {
9966
- key,
9967
- value: stringValue,
9968
- original_key: key
9969
- };
9970
- });
9971
- }
9972
- function parseValues(values) {
9973
- const metadata = values.metadata;
9974
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
9975
- if (isEmpty) {
9976
- return null;
10174
+ ] })
10175
+ ] }),
10176
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10177
+ /* @__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: [
10178
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10179
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10180
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10181
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
10182
+ ] }) }),
10183
+ /* @__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: [
10184
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10185
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10186
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10187
+ Item,
10188
+ {
10189
+ item,
10190
+ preview,
10191
+ currencyCode
10192
+ },
10193
+ item.id
10194
+ )) : /* @__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: [
10195
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10196
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10197
+ 'No items found for "',
10198
+ query2,
10199
+ '".'
10200
+ ] })
10201
+ ] }) })
10202
+ ] })
10203
+ ] }),
10204
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10205
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10206
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10207
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10208
+ ui.Text,
10209
+ {
10210
+ size: "small",
10211
+ leading: "compact",
10212
+ className: "text-ui-fg-subtle",
10213
+ children: [
10214
+ itemCount,
10215
+ " ",
10216
+ itemCount === 1 ? "item" : "items"
10217
+ ]
10218
+ }
10219
+ ) }),
10220
+ /* @__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) }) })
10221
+ ] })
10222
+ ] }) }),
10223
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10224
+ CustomItemForm,
10225
+ {
10226
+ orderId: preview.id,
10227
+ currencyCode
10228
+ }
10229
+ ) : null)
10230
+ ]
10231
+ }
10232
+ ) }),
10233
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10234
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10235
+ /* @__PURE__ */ jsxRuntime.jsx(
10236
+ ui.Button,
10237
+ {
10238
+ size: "small",
10239
+ type: "button",
10240
+ onClick: onSubmit,
10241
+ isLoading: isSubmitting,
10242
+ children: "Save"
10243
+ }
10244
+ )
10245
+ ] }) })
10246
+ ] });
10247
+ };
10248
+ const Item = ({ item, preview, currencyCode }) => {
10249
+ if (item.variant_id) {
10250
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
9977
10251
  }
9978
- const update = {};
9979
- metadata.forEach((field) => {
9980
- let key = field.key;
9981
- let value = field.value;
9982
- const disabled = field.disabled;
9983
- if (!key || !value) {
10252
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10253
+ };
10254
+ const VariantItem = ({ item, preview, currencyCode }) => {
10255
+ const [editing, setEditing] = React.useState(false);
10256
+ const form = reactHookForm.useForm({
10257
+ defaultValues: {
10258
+ quantity: item.quantity,
10259
+ unit_price: item.unit_price
10260
+ },
10261
+ resolver: zod.zodResolver(variantItemSchema)
10262
+ });
10263
+ const actionId = React.useMemo(() => {
10264
+ var _a, _b;
10265
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10266
+ }, [item]);
10267
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10268
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10269
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10270
+ const onSubmit = form.handleSubmit(async (data) => {
10271
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10272
+ setEditing(false);
9984
10273
  return;
9985
10274
  }
9986
- if (disabled) {
9987
- update[key] = value;
10275
+ if (!actionId) {
10276
+ await updateOriginalItem(
10277
+ {
10278
+ item_id: item.id,
10279
+ quantity: data.quantity,
10280
+ unit_price: convertNumber(data.unit_price)
10281
+ },
10282
+ {
10283
+ onSuccess: () => {
10284
+ setEditing(false);
10285
+ },
10286
+ onError: (e) => {
10287
+ ui.toast.error(e.message);
10288
+ }
10289
+ }
10290
+ );
9988
10291
  return;
9989
10292
  }
9990
- key = key.trim();
9991
- value = value.trim();
9992
- if (value === "true") {
9993
- update[key] = true;
9994
- } else if (value === "false") {
9995
- update[key] = false;
9996
- } else {
9997
- const parsedNumber = parseFloat(value);
9998
- if (!isNaN(parsedNumber)) {
9999
- update[key] = parsedNumber;
10000
- } else {
10001
- update[key] = value;
10293
+ await updateActionItem(
10294
+ {
10295
+ action_id: actionId,
10296
+ quantity: data.quantity,
10297
+ unit_price: convertNumber(data.unit_price)
10298
+ },
10299
+ {
10300
+ onSuccess: () => {
10301
+ setEditing(false);
10302
+ },
10303
+ onError: (e) => {
10304
+ ui.toast.error(e.message);
10305
+ }
10002
10306
  }
10003
- }
10307
+ );
10004
10308
  });
10005
- return update;
10006
- }
10007
- function getHasUneditableRows(metadata) {
10008
- if (!metadata) {
10009
- return false;
10010
- }
10011
- return Object.values(metadata).some(
10012
- (value) => !EDITABLE_TYPES.includes(typeof value)
10013
- );
10014
- }
10015
- const NumberInput = React.forwardRef(
10016
- ({
10017
- value,
10018
- onChange,
10019
- size = "base",
10020
- min = 0,
10021
- max = 100,
10022
- step = 1,
10023
- className,
10024
- disabled,
10025
- ...props
10026
- }, ref) => {
10027
- const handleChange = (event) => {
10028
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10029
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10030
- onChange(newValue);
10031
- }
10032
- };
10033
- const handleIncrement = () => {
10034
- const newValue = value + step;
10035
- if (max === void 0 || newValue <= max) {
10036
- onChange(newValue);
10037
- }
10038
- };
10039
- const handleDecrement = () => {
10040
- const newValue = value - step;
10041
- if (min === void 0 || newValue >= min) {
10042
- onChange(newValue);
10043
- }
10044
- };
10045
- return /* @__PURE__ */ jsxRuntime.jsxs(
10046
- "div",
10047
- {
10048
- className: ui.clx(
10049
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10050
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10051
- {
10052
- "h-7": size === "small",
10053
- "h-8": size === "base"
10054
- },
10055
- className
10056
- ),
10057
- children: [
10058
- /* @__PURE__ */ jsxRuntime.jsx(
10059
- "input",
10060
- {
10061
- ref,
10062
- type: "number",
10063
- value,
10064
- onChange: handleChange,
10065
- min,
10066
- max,
10067
- step,
10068
- className: ui.clx(
10069
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10070
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10071
- "placeholder:text-ui-fg-muted"
10072
- ),
10073
- ...props
10074
- }
10075
- ),
10309
+ 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: [
10310
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10311
+ /* @__PURE__ */ jsxRuntime.jsx(
10312
+ Thumbnail,
10313
+ {
10314
+ thumbnail: item.thumbnail,
10315
+ alt: item.product_title ?? void 0
10316
+ }
10317
+ ),
10318
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10319
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10320
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10076
10321
  /* @__PURE__ */ jsxRuntime.jsxs(
10077
- "button",
10322
+ ui.Text,
10078
10323
  {
10079
- className: ui.clx(
10080
- "flex items-center justify-center outline-none transition-fg",
10081
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10082
- "focus:bg-ui-bg-field-component-hover",
10083
- "hover:bg-ui-bg-field-component-hover",
10084
- {
10085
- "size-7": size === "small",
10086
- "size-8": size === "base"
10087
- }
10088
- ),
10089
- type: "button",
10090
- onClick: handleDecrement,
10091
- disabled: min !== void 0 && value <= min || disabled,
10324
+ size: "small",
10325
+ leading: "compact",
10326
+ className: "text-ui-fg-subtle",
10092
10327
  children: [
10093
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10094
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10328
+ "(",
10329
+ item.variant_title,
10330
+ ")"
10095
10331
  ]
10096
10332
  }
10097
- ),
10098
- /* @__PURE__ */ jsxRuntime.jsxs(
10099
- "button",
10333
+ )
10334
+ ] }),
10335
+ /* @__PURE__ */ jsxRuntime.jsx(
10336
+ ui.Text,
10337
+ {
10338
+ size: "small",
10339
+ leading: "compact",
10340
+ className: "text-ui-fg-subtle",
10341
+ children: item.variant_sku
10342
+ }
10343
+ )
10344
+ ] })
10345
+ ] }),
10346
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10347
+ Form$2.Field,
10348
+ {
10349
+ control: form.control,
10350
+ name: "quantity",
10351
+ render: ({ field }) => {
10352
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10353
+ }
10354
+ }
10355
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10356
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10357
+ Form$2.Field,
10358
+ {
10359
+ control: form.control,
10360
+ name: "unit_price",
10361
+ render: ({ field: { onChange, ...field } }) => {
10362
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10363
+ ui.CurrencyInput,
10100
10364
  {
10101
- className: ui.clx(
10102
- "flex items-center justify-center outline-none transition-fg",
10103
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10104
- "focus:bg-ui-bg-field-hover",
10105
- "hover:bg-ui-bg-field-hover",
10106
- {
10107
- "size-7": size === "small",
10108
- "size-8": size === "base"
10109
- }
10110
- ),
10111
- type: "button",
10112
- onClick: handleIncrement,
10113
- disabled: max !== void 0 && value >= max || disabled,
10114
- children: [
10115
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10116
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10117
- ]
10365
+ ...field,
10366
+ symbol: getNativeSymbol(currencyCode),
10367
+ code: currencyCode,
10368
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10118
10369
  }
10119
- )
10120
- ]
10370
+ ) }) });
10371
+ }
10121
10372
  }
10122
- );
10123
- }
10124
- );
10125
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10126
- const productVariantsQueryKeys = {
10127
- list: (query2) => [
10128
- PRODUCT_VARIANTS_QUERY_KEY,
10129
- query2 ? query2 : void 0
10130
- ]
10131
- };
10132
- const useProductVariants = (query2, options) => {
10133
- const { data, ...rest } = reactQuery.useQuery({
10134
- queryKey: productVariantsQueryKeys.list(query2),
10135
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10136
- ...options
10137
- });
10138
- return { ...data, ...rest };
10139
- };
10140
- const useCancelOrderEdit = ({ preview }) => {
10141
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10142
- const onCancel = React.useCallback(async () => {
10143
- if (!preview) {
10144
- return true;
10145
- }
10146
- let res = false;
10147
- await cancelOrderEdit(void 0, {
10148
- onError: (e) => {
10149
- ui.toast.error(e.message);
10150
- },
10151
- onSuccess: () => {
10152
- res = true;
10373
+ ) }) : /* @__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) }) }),
10374
+ /* @__PURE__ */ jsxRuntime.jsx(
10375
+ ui.IconButton,
10376
+ {
10377
+ type: "button",
10378
+ size: "small",
10379
+ onClick: editing ? onSubmit : () => {
10380
+ setEditing(true);
10381
+ },
10382
+ disabled: isPending,
10383
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10153
10384
  }
10154
- });
10155
- return res;
10156
- }, [preview, cancelOrderEdit]);
10157
- return { onCancel };
10385
+ )
10386
+ ] }) }) });
10158
10387
  };
10159
- let IS_REQUEST_RUNNING = false;
10160
- const useInitiateOrderEdit = ({
10161
- preview
10162
- }) => {
10163
- const navigate = reactRouterDom.useNavigate();
10164
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10388
+ const variantItemSchema = objectType({
10389
+ quantity: numberType(),
10390
+ unit_price: unionType([numberType(), stringType()])
10391
+ });
10392
+ const CustomItem = ({ item, preview, currencyCode }) => {
10393
+ const [editing, setEditing] = React.useState(false);
10394
+ const { quantity, unit_price, title } = item;
10395
+ const form = reactHookForm.useForm({
10396
+ defaultValues: {
10397
+ title,
10398
+ quantity,
10399
+ unit_price
10400
+ },
10401
+ resolver: zod.zodResolver(customItemSchema)
10402
+ });
10165
10403
  React.useEffect(() => {
10166
- async function run() {
10167
- if (IS_REQUEST_RUNNING || !preview) {
10168
- return;
10169
- }
10170
- if (preview.order_change) {
10171
- return;
10172
- }
10173
- IS_REQUEST_RUNNING = true;
10174
- await mutateAsync(void 0, {
10404
+ form.reset({
10405
+ title,
10406
+ quantity,
10407
+ unit_price
10408
+ });
10409
+ }, [form, title, quantity, unit_price]);
10410
+ const actionId = React.useMemo(() => {
10411
+ var _a, _b;
10412
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10413
+ }, [item]);
10414
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10415
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10416
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10417
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10418
+ const onSubmit = form.handleSubmit(async (data) => {
10419
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10420
+ setEditing(false);
10421
+ return;
10422
+ }
10423
+ if (!actionId) {
10424
+ await updateOriginalItem(
10425
+ {
10426
+ item_id: item.id,
10427
+ quantity: data.quantity,
10428
+ unit_price: convertNumber(data.unit_price)
10429
+ },
10430
+ {
10431
+ onSuccess: () => {
10432
+ setEditing(false);
10433
+ },
10434
+ onError: (e) => {
10435
+ ui.toast.error(e.message);
10436
+ }
10437
+ }
10438
+ );
10439
+ return;
10440
+ }
10441
+ if (data.quantity === 0) {
10442
+ await removeActionItem(actionId, {
10443
+ onSuccess: () => {
10444
+ setEditing(false);
10445
+ },
10175
10446
  onError: (e) => {
10176
10447
  ui.toast.error(e.message);
10177
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10178
- return;
10179
10448
  }
10180
10449
  });
10181
- IS_REQUEST_RUNNING = false;
10182
- }
10183
- run();
10184
- }, [preview, navigate, mutateAsync]);
10185
- };
10186
- function convertNumber(value) {
10187
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10188
- }
10189
- const STACKED_MODAL_ID = "items_stacked_modal";
10190
- const Items = () => {
10191
- const { id } = reactRouterDom.useParams();
10192
- const {
10193
- order: preview,
10194
- isPending: isPreviewPending,
10195
- isError: isPreviewError,
10196
- error: previewError
10197
- } = useOrderPreview(id, void 0, {
10198
- placeholderData: reactQuery.keepPreviousData
10199
- });
10200
- useInitiateOrderEdit({ preview });
10201
- const { draft_order, isPending, isError, error } = useDraftOrder(
10202
- id,
10203
- {
10204
- fields: "currency_code"
10205
- },
10206
- {
10207
- enabled: !!id
10208
- }
10209
- );
10210
- const { onCancel } = useCancelOrderEdit({ preview });
10211
- if (isError) {
10212
- throw error;
10213
- }
10214
- if (isPreviewError) {
10215
- throw previewError;
10216
- }
10217
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10218
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10219
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10220
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10221
- ] }) });
10222
- };
10223
- const ItemsForm = ({ preview, currencyCode }) => {
10224
- var _a;
10225
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10226
- const [modalContent, setModalContent] = React.useState(
10227
- null
10228
- );
10229
- const { handleSuccess } = useRouteModal();
10230
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10231
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10232
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10233
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10234
- const matches = React.useMemo(() => {
10235
- return matchSorter.matchSorter(preview.items, query2, {
10236
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10237
- });
10238
- }, [preview.items, query2]);
10239
- const onSubmit = async () => {
10240
- setIsSubmitting(true);
10241
- let requestSucceeded = false;
10242
- await requestOrderEdit(void 0, {
10243
- onError: (e) => {
10244
- ui.toast.error(`Failed to request order edit: ${e.message}`);
10245
- },
10246
- onSuccess: () => {
10247
- requestSucceeded = true;
10248
- }
10249
- });
10250
- if (!requestSucceeded) {
10251
- setIsSubmitting(false);
10252
- return;
10253
- }
10254
- await confirmOrderEdit(void 0, {
10255
- onError: (e) => {
10256
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10257
- },
10258
- onSuccess: () => {
10259
- handleSuccess();
10260
- },
10261
- onSettled: () => {
10262
- setIsSubmitting(false);
10263
- }
10264
- });
10265
- };
10266
- const onKeyDown = React.useCallback(
10267
- (e) => {
10268
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10269
- if (modalContent || isSubmitting) {
10270
- return;
10271
- }
10272
- onSubmit();
10273
- }
10274
- },
10275
- [modalContent, isSubmitting, onSubmit]
10276
- );
10277
- React.useEffect(() => {
10278
- document.addEventListener("keydown", onKeyDown);
10279
- return () => {
10280
- document.removeEventListener("keydown", onKeyDown);
10281
- };
10282
- }, [onKeyDown]);
10283
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10284
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10285
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10286
- StackedFocusModal,
10287
- {
10288
- id: STACKED_MODAL_ID,
10289
- onOpenChangeCallback: (open) => {
10290
- if (!open) {
10291
- setModalContent(null);
10292
- }
10293
- },
10294
- children: [
10295
- /* @__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: [
10296
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10297
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10298
- /* @__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" }) })
10299
- ] }),
10300
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10301
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10302
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10303
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10304
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10305
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10306
- ] }),
10307
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10308
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10309
- ui.Input,
10310
- {
10311
- type: "search",
10312
- placeholder: "Search items",
10313
- value: searchValue,
10314
- onChange: (e) => onSearchValueChange(e.target.value)
10315
- }
10316
- ) }),
10317
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10318
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10319
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10320
- /* @__PURE__ */ jsxRuntime.jsx(
10321
- StackedModalTrigger$1,
10322
- {
10323
- type: "add-items",
10324
- setModalContent
10325
- }
10326
- ),
10327
- /* @__PURE__ */ jsxRuntime.jsx(
10328
- StackedModalTrigger$1,
10329
- {
10330
- type: "add-custom-item",
10331
- setModalContent
10332
- }
10333
- )
10334
- ] })
10335
- ] })
10336
- ] })
10337
- ] }),
10338
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10339
- /* @__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: [
10340
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10341
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10342
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10343
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
10344
- ] }) }),
10345
- /* @__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: [
10346
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10347
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10348
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10349
- Item,
10350
- {
10351
- item,
10352
- preview,
10353
- currencyCode
10354
- },
10355
- item.id
10356
- )) : /* @__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: [
10357
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10358
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10359
- 'No items found for "',
10360
- query2,
10361
- '".'
10362
- ] })
10363
- ] }) })
10364
- ] })
10365
- ] }),
10366
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10367
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10368
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10369
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10370
- ui.Text,
10371
- {
10372
- size: "small",
10373
- leading: "compact",
10374
- className: "text-ui-fg-subtle",
10375
- children: [
10376
- itemCount,
10377
- " ",
10378
- itemCount === 1 ? "item" : "items"
10379
- ]
10380
- }
10381
- ) }),
10382
- /* @__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) }) })
10383
- ] })
10384
- ] }) }),
10385
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10386
- CustomItemForm,
10387
- {
10388
- orderId: preview.id,
10389
- currencyCode
10390
- }
10391
- ) : null)
10392
- ]
10393
- }
10394
- ) }),
10395
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10396
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10397
- /* @__PURE__ */ jsxRuntime.jsx(
10398
- ui.Button,
10399
- {
10400
- size: "small",
10401
- type: "button",
10402
- onClick: onSubmit,
10403
- isLoading: isSubmitting,
10404
- children: "Save"
10405
- }
10406
- )
10407
- ] }) })
10408
- ] });
10409
- };
10410
- const Item = ({ item, preview, currencyCode }) => {
10411
- if (item.variant_id) {
10412
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10413
- }
10414
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10415
- };
10416
- const VariantItem = ({ item, preview, currencyCode }) => {
10417
- const [editing, setEditing] = React.useState(false);
10418
- const form = reactHookForm.useForm({
10419
- defaultValues: {
10420
- quantity: item.quantity,
10421
- unit_price: item.unit_price
10422
- },
10423
- resolver: zod.zodResolver(variantItemSchema)
10424
- });
10425
- const actionId = React.useMemo(() => {
10426
- var _a, _b;
10427
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10428
- }, [item]);
10429
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10430
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10431
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10432
- const onSubmit = form.handleSubmit(async (data) => {
10433
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10434
- setEditing(false);
10435
- return;
10436
- }
10437
- if (!actionId) {
10438
- await updateOriginalItem(
10439
- {
10440
- item_id: item.id,
10441
- quantity: data.quantity,
10442
- unit_price: convertNumber(data.unit_price)
10443
- },
10444
- {
10445
- onSuccess: () => {
10446
- setEditing(false);
10447
- },
10448
- onError: (e) => {
10449
- ui.toast.error(e.message);
10450
- }
10451
- }
10452
- );
10453
10450
  return;
10454
10451
  }
10455
10452
  await updateActionItem(
@@ -10469,43 +10466,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10469
10466
  );
10470
10467
  });
10471
10468
  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: [
10472
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10469
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10473
10470
  /* @__PURE__ */ jsxRuntime.jsx(
10474
10471
  Thumbnail,
10475
10472
  {
10476
10473
  thumbnail: item.thumbnail,
10477
- alt: item.product_title ?? void 0
10474
+ alt: item.title ?? void 0
10478
10475
  }
10479
10476
  ),
10480
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10481
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10482
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10483
- /* @__PURE__ */ jsxRuntime.jsxs(
10484
- ui.Text,
10485
- {
10486
- size: "small",
10487
- leading: "compact",
10488
- className: "text-ui-fg-subtle",
10489
- children: [
10490
- "(",
10491
- item.variant_title,
10492
- ")"
10493
- ]
10494
- }
10495
- )
10496
- ] }),
10497
- /* @__PURE__ */ jsxRuntime.jsx(
10498
- ui.Text,
10499
- {
10500
- size: "small",
10501
- leading: "compact",
10502
- className: "text-ui-fg-subtle",
10503
- children: item.variant_sku
10477
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10478
+ Form$2.Field,
10479
+ {
10480
+ control: form.control,
10481
+ name: "title",
10482
+ render: ({ field }) => {
10483
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10504
10484
  }
10505
- )
10506
- ] })
10485
+ }
10486
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10507
10487
  ] }),
10508
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10488
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10509
10489
  Form$2.Field,
10510
10490
  {
10511
10491
  control: form.control,
@@ -10514,8 +10494,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10514
10494
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10515
10495
  }
10516
10496
  }
10517
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10518
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10497
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10498
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10519
10499
  Form$2.Field,
10520
10500
  {
10521
10501
  control: form.control,
@@ -10532,149 +10512,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10532
10512
  ) }) });
10533
10513
  }
10534
10514
  }
10535
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10536
- /* @__PURE__ */ jsxRuntime.jsx(
10537
- ui.IconButton,
10538
- {
10539
- type: "button",
10540
- size: "small",
10541
- onClick: editing ? onSubmit : () => {
10542
- setEditing(true);
10543
- },
10544
- disabled: isPending,
10545
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10546
- }
10547
- )
10548
- ] }) }) });
10549
- };
10550
- const variantItemSchema = objectType({
10551
- quantity: numberType(),
10552
- unit_price: unionType([numberType(), stringType()])
10553
- });
10554
- const CustomItem = ({ item, preview, currencyCode }) => {
10555
- const [editing, setEditing] = React.useState(false);
10556
- const { quantity, unit_price, title } = item;
10557
- const form = reactHookForm.useForm({
10558
- defaultValues: {
10559
- title,
10560
- quantity,
10561
- unit_price
10562
- },
10563
- resolver: zod.zodResolver(customItemSchema)
10564
- });
10565
- React.useEffect(() => {
10566
- form.reset({
10567
- title,
10568
- quantity,
10569
- unit_price
10570
- });
10571
- }, [form, title, quantity, unit_price]);
10572
- const actionId = React.useMemo(() => {
10573
- var _a, _b;
10574
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10575
- }, [item]);
10576
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10577
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10578
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10579
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10580
- const onSubmit = form.handleSubmit(async (data) => {
10581
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10582
- setEditing(false);
10583
- return;
10584
- }
10585
- if (!actionId) {
10586
- await updateOriginalItem(
10587
- {
10588
- item_id: item.id,
10589
- quantity: data.quantity,
10590
- unit_price: convertNumber(data.unit_price)
10591
- },
10592
- {
10593
- onSuccess: () => {
10594
- setEditing(false);
10595
- },
10596
- onError: (e) => {
10597
- ui.toast.error(e.message);
10598
- }
10599
- }
10600
- );
10601
- return;
10602
- }
10603
- if (data.quantity === 0) {
10604
- await removeActionItem(actionId, {
10605
- onSuccess: () => {
10606
- setEditing(false);
10607
- },
10608
- onError: (e) => {
10609
- ui.toast.error(e.message);
10610
- }
10611
- });
10612
- return;
10613
- }
10614
- await updateActionItem(
10615
- {
10616
- action_id: actionId,
10617
- quantity: data.quantity,
10618
- unit_price: convertNumber(data.unit_price)
10619
- },
10620
- {
10621
- onSuccess: () => {
10622
- setEditing(false);
10623
- },
10624
- onError: (e) => {
10625
- ui.toast.error(e.message);
10626
- }
10627
- }
10628
- );
10629
- });
10630
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10631
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10632
- /* @__PURE__ */ jsxRuntime.jsx(
10633
- Thumbnail,
10634
- {
10635
- thumbnail: item.thumbnail,
10636
- alt: item.title ?? void 0
10637
- }
10638
- ),
10639
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10640
- Form$2.Field,
10641
- {
10642
- control: form.control,
10643
- name: "title",
10644
- render: ({ field }) => {
10645
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10646
- }
10647
- }
10648
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10649
- ] }),
10650
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10651
- Form$2.Field,
10652
- {
10653
- control: form.control,
10654
- name: "quantity",
10655
- render: ({ field }) => {
10656
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10657
- }
10658
- }
10659
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10660
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10661
- Form$2.Field,
10662
- {
10663
- control: form.control,
10664
- name: "unit_price",
10665
- render: ({ field: { onChange, ...field } }) => {
10666
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10667
- ui.CurrencyInput,
10668
- {
10669
- ...field,
10670
- symbol: getNativeSymbol(currencyCode),
10671
- code: currencyCode,
10672
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10673
- }
10674
- ) }) });
10675
- }
10676
- }
10677
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10515
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10678
10516
  /* @__PURE__ */ jsxRuntime.jsx(
10679
10517
  ui.IconButton,
10680
10518
  {
@@ -11263,46 +11101,88 @@ function getPromotionIds(items, shippingMethods) {
11263
11101
  }
11264
11102
  return Array.from(promotionIds);
11265
11103
  }
11266
- const SalesChannel = () => {
11104
+ const InlineTip = React.forwardRef(
11105
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11106
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11107
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11108
+ "div",
11109
+ {
11110
+ ref,
11111
+ className: ui.clx(
11112
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11113
+ className
11114
+ ),
11115
+ ...props,
11116
+ children: [
11117
+ /* @__PURE__ */ jsxRuntime.jsx(
11118
+ "div",
11119
+ {
11120
+ role: "presentation",
11121
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11122
+ "bg-ui-tag-orange-icon": variant === "warning"
11123
+ })
11124
+ }
11125
+ ),
11126
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11127
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11128
+ labelValue,
11129
+ ":"
11130
+ ] }),
11131
+ " ",
11132
+ children
11133
+ ] })
11134
+ ]
11135
+ }
11136
+ );
11137
+ }
11138
+ );
11139
+ InlineTip.displayName = "InlineTip";
11140
+ const MetadataFieldSchema = objectType({
11141
+ key: stringType(),
11142
+ disabled: booleanType().optional(),
11143
+ value: anyType()
11144
+ });
11145
+ const MetadataSchema = objectType({
11146
+ metadata: arrayType(MetadataFieldSchema)
11147
+ });
11148
+ const Metadata = () => {
11267
11149
  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
- );
11150
+ const { order, isPending, isError, error } = useOrder(id, {
11151
+ fields: "metadata"
11152
+ });
11277
11153
  if (isError) {
11278
11154
  throw error;
11279
11155
  }
11280
- const ISrEADY = !!draft_order && !isPending;
11156
+ const isReady = !isPending && !!order;
11281
11157
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11282
11158
  /* @__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" }) })
11159
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11160
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11285
11161
  ] }),
11286
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11162
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11287
11163
  ] });
11288
11164
  };
11289
- const SalesChannelForm = ({ order }) => {
11165
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11166
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11167
+ const MetadataForm = ({ orderId, metadata }) => {
11168
+ const { handleSuccess } = useRouteModal();
11169
+ const hasUneditableRows = getHasUneditableRows(metadata);
11170
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11290
11171
  const form = reactHookForm.useForm({
11291
11172
  defaultValues: {
11292
- sales_channel_id: order.sales_channel_id || ""
11173
+ metadata: getDefaultValues(metadata)
11293
11174
  },
11294
- resolver: zod.zodResolver(schema$3)
11175
+ resolver: zod.zodResolver(MetadataSchema)
11295
11176
  });
11296
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11297
- const { handleSuccess } = useRouteModal();
11298
- const onSubmit = form.handleSubmit(async (data) => {
11177
+ const handleSubmit = form.handleSubmit(async (data) => {
11178
+ const parsedData = parseValues(data);
11299
11179
  await mutateAsync(
11300
11180
  {
11301
- sales_channel_id: data.sales_channel_id
11181
+ metadata: parsedData
11302
11182
  },
11303
11183
  {
11304
11184
  onSuccess: () => {
11305
- ui.toast.success("Sales channel updated");
11185
+ ui.toast.success("Metadata updated");
11306
11186
  handleSuccess();
11307
11187
  },
11308
11188
  onError: (error) => {
@@ -11311,305 +11191,306 @@ const SalesChannelForm = ({ order }) => {
11311
11191
  }
11312
11192
  );
11313
11193
  });
11194
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
11195
+ control: form.control,
11196
+ name: "metadata"
11197
+ });
11198
+ function deleteRow(index) {
11199
+ remove(index);
11200
+ if (fields.length === 1) {
11201
+ insert(0, {
11202
+ key: "",
11203
+ value: "",
11204
+ disabled: false
11205
+ });
11206
+ }
11207
+ }
11208
+ function insertRow(index, position) {
11209
+ insert(index + (position === "above" ? 0 : 1), {
11210
+ key: "",
11211
+ value: "",
11212
+ disabled: false
11213
+ });
11214
+ }
11314
11215
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11315
11216
  KeyboundForm,
11316
11217
  {
11218
+ onSubmit: handleSubmit,
11317
11219
  className: "flex flex-1 flex-col overflow-hidden",
11318
- onSubmit,
11319
11220
  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
- },
11341
- defaultValue: order.sales_channel_id || void 0
11342
- });
11221
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11222
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11223
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11224
+ /* @__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" }) }),
11225
+ /* @__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" }) })
11226
+ ] }),
11227
+ fields.map((field, index) => {
11228
+ const isDisabled = field.disabled || false;
11229
+ let placeholder = "-";
11230
+ if (typeof field.value === "object") {
11231
+ placeholder = "{ ... }";
11232
+ }
11233
+ if (Array.isArray(field.value)) {
11234
+ placeholder = "[ ... ]";
11235
+ }
11236
+ return /* @__PURE__ */ jsxRuntime.jsx(
11237
+ ConditionalTooltip,
11238
+ {
11239
+ showTooltip: isDisabled,
11240
+ content: "This row is disabled because it contains non-primitive data.",
11241
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11242
+ /* @__PURE__ */ jsxRuntime.jsxs(
11243
+ "div",
11244
+ {
11245
+ className: ui.clx("grid grid-cols-2 divide-x", {
11246
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11247
+ }),
11248
+ children: [
11249
+ /* @__PURE__ */ jsxRuntime.jsx(
11250
+ Form$2.Field,
11251
+ {
11252
+ control: form.control,
11253
+ name: `metadata.${index}.key`,
11254
+ render: ({ field: field2 }) => {
11255
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11256
+ GridInput,
11257
+ {
11258
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11259
+ ...field2,
11260
+ disabled: isDisabled,
11261
+ placeholder: "Key"
11262
+ }
11263
+ ) }) });
11264
+ }
11265
+ }
11266
+ ),
11267
+ /* @__PURE__ */ jsxRuntime.jsx(
11268
+ Form$2.Field,
11269
+ {
11270
+ control: form.control,
11271
+ name: `metadata.${index}.value`,
11272
+ render: ({ field: { value, ...field2 } }) => {
11273
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11274
+ GridInput,
11275
+ {
11276
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11277
+ ...field2,
11278
+ value: isDisabled ? placeholder : value,
11279
+ disabled: isDisabled,
11280
+ placeholder: "Value"
11281
+ }
11282
+ ) }) });
11283
+ }
11284
+ }
11285
+ )
11286
+ ]
11287
+ }
11288
+ ),
11289
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11290
+ /* @__PURE__ */ jsxRuntime.jsx(
11291
+ ui.DropdownMenu.Trigger,
11292
+ {
11293
+ className: ui.clx(
11294
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11295
+ {
11296
+ hidden: isDisabled
11297
+ }
11298
+ ),
11299
+ disabled: isDisabled,
11300
+ asChild: true,
11301
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11302
+ }
11303
+ ),
11304
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11305
+ /* @__PURE__ */ jsxRuntime.jsxs(
11306
+ ui.DropdownMenu.Item,
11307
+ {
11308
+ className: "gap-x-2",
11309
+ onClick: () => insertRow(index, "above"),
11310
+ children: [
11311
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11312
+ "Insert row above"
11313
+ ]
11314
+ }
11315
+ ),
11316
+ /* @__PURE__ */ jsxRuntime.jsxs(
11317
+ ui.DropdownMenu.Item,
11318
+ {
11319
+ className: "gap-x-2",
11320
+ onClick: () => insertRow(index, "below"),
11321
+ children: [
11322
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11323
+ "Insert row below"
11324
+ ]
11325
+ }
11326
+ ),
11327
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11328
+ /* @__PURE__ */ jsxRuntime.jsxs(
11329
+ ui.DropdownMenu.Item,
11330
+ {
11331
+ className: "gap-x-2",
11332
+ onClick: () => deleteRow(index),
11333
+ children: [
11334
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11335
+ "Delete row"
11336
+ ]
11337
+ }
11338
+ )
11339
+ ] })
11340
+ ] })
11341
+ ] })
11342
+ },
11343
+ field.id
11344
+ );
11345
+ })
11346
+ ] }),
11347
+ 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." })
11348
+ ] }),
11349
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11350
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11351
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11352
+ ] }) })
11353
+ ]
11354
+ }
11355
+ ) });
11356
+ };
11357
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11343
11358
  return /* @__PURE__ */ jsxRuntime.jsx(
11344
- Form$2.Field,
11359
+ "input",
11345
11360
  {
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
- }
11361
+ ref,
11362
+ ...props,
11363
+ autoComplete: "off",
11364
+ className: ui.clx(
11365
+ "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",
11366
+ className
11367
+ )
11366
11368
  }
11367
11369
  );
11368
- };
11369
- const schema$3 = objectType({
11370
- sales_channel_id: stringType().min(1)
11371
11370
  });
11372
- const ShippingAddress = () => {
11373
- const { id } = reactRouterDom.useParams();
11374
- const { order, isPending, isError, error } = useOrder(id, {
11375
- fields: "+shipping_address"
11376
- });
11377
- if (isError) {
11378
- throw error;
11379
- }
11380
- const isReady = !isPending && !!order;
11381
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11382
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11383
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11384
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11385
- ] }),
11386
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11371
+ GridInput.displayName = "MetadataForm.GridInput";
11372
+ const PlaceholderInner = () => {
11373
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11374
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11375
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11376
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11377
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11378
+ ] }) })
11387
11379
  ] });
11388
11380
  };
11389
- const ShippingAddressForm = ({ order }) => {
11390
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11391
- const form = reactHookForm.useForm({
11392
- defaultValues: {
11393
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11394
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11395
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11396
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11397
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11398
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11399
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11400
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11401
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11402
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11403
- },
11404
- resolver: zod.zodResolver(schema$2)
11405
- });
11406
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11407
- const { handleSuccess } = useRouteModal();
11408
- const onSubmit = form.handleSubmit(async (data) => {
11409
- await mutateAsync(
11410
- {
11411
- shipping_address: {
11412
- first_name: data.first_name,
11413
- last_name: data.last_name,
11414
- company: data.company,
11415
- address_1: data.address_1,
11416
- address_2: data.address_2,
11417
- city: data.city,
11418
- province: data.province,
11419
- country_code: data.country_code,
11420
- postal_code: data.postal_code,
11421
- phone: data.phone
11422
- }
11423
- },
11381
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11382
+ function getDefaultValues(metadata) {
11383
+ if (!metadata || !Object.keys(metadata).length) {
11384
+ return [
11424
11385
  {
11425
- onSuccess: () => {
11426
- handleSuccess();
11427
- },
11428
- onError: (error) => {
11429
- ui.toast.error(error.message);
11430
- }
11386
+ key: "",
11387
+ value: "",
11388
+ disabled: false
11389
+ }
11390
+ ];
11391
+ }
11392
+ return Object.entries(metadata).map(([key, value]) => {
11393
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11394
+ return {
11395
+ key,
11396
+ value,
11397
+ disabled: true
11398
+ };
11399
+ }
11400
+ let stringValue = value;
11401
+ if (typeof value !== "string") {
11402
+ stringValue = JSON.stringify(value);
11403
+ }
11404
+ return {
11405
+ key,
11406
+ value: stringValue,
11407
+ original_key: key
11408
+ };
11409
+ });
11410
+ }
11411
+ function parseValues(values) {
11412
+ const metadata = values.metadata;
11413
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11414
+ if (isEmpty) {
11415
+ return null;
11416
+ }
11417
+ const update = {};
11418
+ metadata.forEach((field) => {
11419
+ let key = field.key;
11420
+ let value = field.value;
11421
+ const disabled = field.disabled;
11422
+ if (!key || !value) {
11423
+ return;
11424
+ }
11425
+ if (disabled) {
11426
+ update[key] = value;
11427
+ return;
11428
+ }
11429
+ key = key.trim();
11430
+ value = value.trim();
11431
+ if (value === "true") {
11432
+ update[key] = true;
11433
+ } else if (value === "false") {
11434
+ update[key] = false;
11435
+ } else {
11436
+ const parsedNumber = parseFloat(value);
11437
+ if (!isNaN(parsedNumber)) {
11438
+ update[key] = parsedNumber;
11439
+ } else {
11440
+ update[key] = value;
11431
11441
  }
11432
- );
11433
- });
11434
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11435
- KeyboundForm,
11436
- {
11437
- className: "flex flex-1 flex-col overflow-hidden",
11438
- onSubmit,
11439
- children: [
11440
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11441
- /* @__PURE__ */ jsxRuntime.jsx(
11442
- Form$2.Field,
11443
- {
11444
- control: form.control,
11445
- name: "country_code",
11446
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11449
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11450
- ] })
11451
- }
11452
- ),
11453
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11454
- /* @__PURE__ */ jsxRuntime.jsx(
11455
- Form$2.Field,
11456
- {
11457
- control: form.control,
11458
- name: "first_name",
11459
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11461
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11462
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11463
- ] })
11464
- }
11465
- ),
11466
- /* @__PURE__ */ jsxRuntime.jsx(
11467
- Form$2.Field,
11468
- {
11469
- control: form.control,
11470
- name: "last_name",
11471
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11472
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11473
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11474
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11475
- ] })
11476
- }
11477
- )
11478
- ] }),
11479
- /* @__PURE__ */ jsxRuntime.jsx(
11480
- Form$2.Field,
11481
- {
11482
- control: form.control,
11483
- name: "company",
11484
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11485
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11486
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11487
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11488
- ] })
11489
- }
11490
- ),
11491
- /* @__PURE__ */ jsxRuntime.jsx(
11492
- Form$2.Field,
11493
- {
11494
- control: form.control,
11495
- name: "address_1",
11496
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11498
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11499
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11500
- ] })
11501
- }
11502
- ),
11503
- /* @__PURE__ */ jsxRuntime.jsx(
11504
- Form$2.Field,
11505
- {
11506
- control: form.control,
11507
- name: "address_2",
11508
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11509
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11510
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11511
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11512
- ] })
11513
- }
11514
- ),
11515
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11516
- /* @__PURE__ */ jsxRuntime.jsx(
11517
- Form$2.Field,
11518
- {
11519
- control: form.control,
11520
- name: "postal_code",
11521
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11522
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11523
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11524
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11525
- ] })
11526
- }
11527
- ),
11528
- /* @__PURE__ */ jsxRuntime.jsx(
11529
- Form$2.Field,
11530
- {
11531
- control: form.control,
11532
- name: "city",
11533
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11534
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11535
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11536
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11537
- ] })
11538
- }
11539
- )
11540
- ] }),
11541
- /* @__PURE__ */ jsxRuntime.jsx(
11542
- Form$2.Field,
11543
- {
11544
- control: form.control,
11545
- name: "province",
11546
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11547
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11548
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11549
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11550
- ] })
11551
- }
11552
- ),
11553
- /* @__PURE__ */ jsxRuntime.jsx(
11554
- Form$2.Field,
11555
- {
11556
- control: form.control,
11557
- name: "phone",
11558
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11559
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11560
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11561
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11562
- ] })
11563
- }
11564
- )
11565
- ] }) }),
11566
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11567
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11568
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11569
- ] }) })
11570
- ]
11571
11442
  }
11572
- ) });
11573
- };
11574
- const schema$2 = addressSchema;
11575
- const TransferOwnership = () => {
11576
- const { id } = reactRouterDom.useParams();
11577
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11578
- fields: "id,customer_id,customer.*"
11579
11443
  });
11444
+ return update;
11445
+ }
11446
+ function getHasUneditableRows(metadata) {
11447
+ if (!metadata) {
11448
+ return false;
11449
+ }
11450
+ return Object.values(metadata).some(
11451
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11452
+ );
11453
+ }
11454
+ const SalesChannel = () => {
11455
+ const { id } = reactRouterDom.useParams();
11456
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11457
+ id,
11458
+ {
11459
+ fields: "+sales_channel_id"
11460
+ },
11461
+ {
11462
+ enabled: !!id
11463
+ }
11464
+ );
11580
11465
  if (isError) {
11581
11466
  throw error;
11582
11467
  }
11583
- const isReady = !isPending && !!draft_order;
11468
+ const ISrEADY = !!draft_order && !isPending;
11584
11469
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11585
11470
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11586
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11587
- /* @__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" }) })
11471
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11472
+ /* @__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" }) })
11588
11473
  ] }),
11589
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11474
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11590
11475
  ] });
11591
11476
  };
11592
- const TransferOwnershipForm = ({ order }) => {
11593
- var _a, _b;
11477
+ const SalesChannelForm = ({ order }) => {
11594
11478
  const form = reactHookForm.useForm({
11595
11479
  defaultValues: {
11596
- customer_id: order.customer_id || ""
11480
+ sales_channel_id: order.sales_channel_id || ""
11597
11481
  },
11598
- resolver: zod.zodResolver(schema$1)
11482
+ resolver: zod.zodResolver(schema$2)
11599
11483
  });
11600
11484
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11601
11485
  const { handleSuccess } = useRouteModal();
11602
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11603
- const currentCustomer = order.customer ? {
11604
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11605
- value: order.customer.id
11606
- } : null;
11607
11486
  const onSubmit = form.handleSubmit(async (data) => {
11608
11487
  await mutateAsync(
11609
- { customer_id: data.customer_id },
11488
+ {
11489
+ sales_channel_id: data.sales_channel_id
11490
+ },
11610
11491
  {
11611
11492
  onSuccess: () => {
11612
- ui.toast.success("Customer updated");
11493
+ ui.toast.success("Sales channel updated");
11613
11494
  handleSuccess();
11614
11495
  },
11615
11496
  onError: (error) => {
@@ -11624,472 +11505,100 @@ const TransferOwnershipForm = ({ order }) => {
11624
11505
  className: "flex flex-1 flex-col overflow-hidden",
11625
11506
  onSubmit,
11626
11507
  children: [
11627
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11628
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11629
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11630
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11632
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11633
- ] }),
11634
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11635
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11636
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11637
- ] })
11638
- ] }),
11639
- /* @__PURE__ */ jsxRuntime.jsx(
11640
- CustomerField,
11641
- {
11642
- control: form.control,
11643
- currentCustomerId: order.customer_id
11644
- }
11645
- )
11646
- ] }),
11647
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11648
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11649
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11508
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11509
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11650
11512
  ] }) })
11651
11513
  ]
11652
11514
  }
11653
11515
  ) });
11654
11516
  };
11655
- const CustomerField = ({ control, currentCustomerId }) => {
11656
- const customers = useComboboxData({
11517
+ const SalesChannelField = ({ control, order }) => {
11518
+ const salesChannels = useComboboxData({
11657
11519
  queryFn: async (params) => {
11658
- return await sdk.admin.customer.list({
11659
- ...params,
11660
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11661
- });
11520
+ return await sdk.admin.salesChannel.list(params);
11662
11521
  },
11663
- queryKey: ["customers"],
11522
+ queryKey: ["sales-channels"],
11664
11523
  getOptions: (data) => {
11665
- return data.customers.map((customer) => {
11666
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11667
- return {
11668
- label: name ? `${name} (${customer.email})` : customer.email,
11669
- value: customer.id
11670
- };
11671
- });
11672
- }
11524
+ return data.sales_channels.map((salesChannel) => ({
11525
+ label: salesChannel.name,
11526
+ value: salesChannel.id
11527
+ }));
11528
+ },
11529
+ defaultValue: order.sales_channel_id || void 0
11673
11530
  });
11674
11531
  return /* @__PURE__ */ jsxRuntime.jsx(
11675
11532
  Form$2.Field,
11676
11533
  {
11677
- name: "customer_id",
11678
11534
  control,
11679
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11680
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11681
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11682
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11683
- ] }),
11684
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11685
- Combobox,
11686
- {
11687
- options: customers.options,
11688
- fetchNextPage: customers.fetchNextPage,
11689
- isFetchingNextPage: customers.isFetchingNextPage,
11690
- searchValue: customers.searchValue,
11691
- onSearchValueChange: customers.onSearchValueChange,
11692
- placeholder: "Select customer",
11693
- ...field
11694
- }
11695
- ) }),
11696
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11697
- ] })
11535
+ name: "sales_channel_id",
11536
+ render: ({ field }) => {
11537
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11538
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11539
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11540
+ Combobox,
11541
+ {
11542
+ options: salesChannels.options,
11543
+ fetchNextPage: salesChannels.fetchNextPage,
11544
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11545
+ searchValue: salesChannels.searchValue,
11546
+ onSearchValueChange: salesChannels.onSearchValueChange,
11547
+ placeholder: "Select sales channel",
11548
+ ...field
11549
+ }
11550
+ ) }),
11551
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11552
+ ] });
11553
+ }
11698
11554
  }
11699
11555
  );
11700
11556
  };
11701
- const Illustration = () => {
11702
- return /* @__PURE__ */ jsxRuntime.jsxs(
11703
- "svg",
11704
- {
11705
- width: "280",
11706
- height: "180",
11707
- viewBox: "0 0 280 180",
11708
- fill: "none",
11709
- xmlns: "http://www.w3.org/2000/svg",
11710
- children: [
11711
- /* @__PURE__ */ jsxRuntime.jsx(
11712
- "rect",
11713
- {
11714
- x: "0.00428286",
11715
- y: "-0.742904",
11716
- width: "33.5",
11717
- height: "65.5",
11718
- rx: "6.75",
11719
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11720
- fill: "#D4D4D8",
11721
- stroke: "#52525B",
11722
- strokeWidth: "1.5"
11723
- }
11724
- ),
11725
- /* @__PURE__ */ jsxRuntime.jsx(
11726
- "rect",
11727
- {
11728
- x: "0.00428286",
11729
- y: "-0.742904",
11730
- width: "33.5",
11731
- height: "65.5",
11732
- rx: "6.75",
11733
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11734
- fill: "white",
11735
- stroke: "#52525B",
11736
- strokeWidth: "1.5"
11737
- }
11738
- ),
11739
- /* @__PURE__ */ jsxRuntime.jsx(
11740
- "path",
11741
- {
11742
- d: "M180.579 107.142L179.126 107.959",
11743
- stroke: "#52525B",
11744
- strokeWidth: "1.5",
11745
- strokeLinecap: "round",
11746
- strokeLinejoin: "round"
11747
- }
11748
- ),
11749
- /* @__PURE__ */ jsxRuntime.jsx(
11750
- "path",
11751
- {
11752
- opacity: "0.88",
11753
- d: "M182.305 109.546L180.257 109.534",
11754
- stroke: "#52525B",
11755
- strokeWidth: "1.5",
11756
- strokeLinecap: "round",
11757
- strokeLinejoin: "round"
11758
- }
11759
- ),
11760
- /* @__PURE__ */ jsxRuntime.jsx(
11761
- "path",
11762
- {
11763
- opacity: "0.75",
11764
- d: "M180.551 111.93L179.108 111.096",
11765
- stroke: "#52525B",
11766
- strokeWidth: "1.5",
11767
- strokeLinecap: "round",
11768
- strokeLinejoin: "round"
11769
- }
11770
- ),
11771
- /* @__PURE__ */ jsxRuntime.jsx(
11772
- "path",
11773
- {
11774
- opacity: "0.63",
11775
- d: "M176.347 112.897L176.354 111.73",
11776
- stroke: "#52525B",
11777
- strokeWidth: "1.5",
11778
- strokeLinecap: "round",
11779
- strokeLinejoin: "round"
11780
- }
11781
- ),
11782
- /* @__PURE__ */ jsxRuntime.jsx(
11783
- "path",
11784
- {
11785
- opacity: "0.5",
11786
- d: "M172.153 111.881L173.606 111.064",
11787
- stroke: "#52525B",
11788
- strokeWidth: "1.5",
11789
- strokeLinecap: "round",
11790
- strokeLinejoin: "round"
11791
- }
11792
- ),
11793
- /* @__PURE__ */ jsxRuntime.jsx(
11794
- "path",
11795
- {
11796
- opacity: "0.38",
11797
- d: "M170.428 109.478L172.476 109.489",
11798
- stroke: "#52525B",
11799
- strokeWidth: "1.5",
11800
- strokeLinecap: "round",
11801
- strokeLinejoin: "round"
11802
- }
11803
- ),
11804
- /* @__PURE__ */ jsxRuntime.jsx(
11805
- "path",
11806
- {
11807
- opacity: "0.25",
11808
- d: "M172.181 107.094L173.624 107.928",
11809
- stroke: "#52525B",
11810
- strokeWidth: "1.5",
11811
- strokeLinecap: "round",
11812
- strokeLinejoin: "round"
11813
- }
11814
- ),
11815
- /* @__PURE__ */ jsxRuntime.jsx(
11816
- "path",
11817
- {
11818
- opacity: "0.13",
11819
- d: "M176.386 106.126L176.379 107.294",
11820
- stroke: "#52525B",
11821
- strokeWidth: "1.5",
11822
- strokeLinecap: "round",
11823
- strokeLinejoin: "round"
11824
- }
11825
- ),
11826
- /* @__PURE__ */ jsxRuntime.jsx(
11827
- "rect",
11828
- {
11829
- width: "12",
11830
- height: "3",
11831
- rx: "1.5",
11832
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
11833
- fill: "#D4D4D8"
11834
- }
11835
- ),
11836
- /* @__PURE__ */ jsxRuntime.jsx(
11837
- "rect",
11838
- {
11839
- x: "0.00428286",
11840
- y: "-0.742904",
11841
- width: "33.5",
11842
- height: "65.5",
11843
- rx: "6.75",
11844
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
11845
- fill: "#D4D4D8",
11846
- stroke: "#52525B",
11847
- strokeWidth: "1.5"
11848
- }
11849
- ),
11850
- /* @__PURE__ */ jsxRuntime.jsx(
11851
- "rect",
11852
- {
11853
- x: "0.00428286",
11854
- y: "-0.742904",
11855
- width: "33.5",
11856
- height: "65.5",
11857
- rx: "6.75",
11858
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
11859
- fill: "white",
11860
- stroke: "#52525B",
11861
- strokeWidth: "1.5"
11862
- }
11863
- ),
11864
- /* @__PURE__ */ jsxRuntime.jsx(
11865
- "rect",
11866
- {
11867
- width: "12",
11868
- height: "3",
11869
- rx: "1.5",
11870
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
11871
- fill: "#D4D4D8"
11872
- }
11873
- ),
11874
- /* @__PURE__ */ jsxRuntime.jsx(
11875
- "rect",
11876
- {
11877
- width: "17",
11878
- height: "3",
11879
- rx: "1.5",
11880
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
11881
- fill: "#D4D4D8"
11882
- }
11883
- ),
11884
- /* @__PURE__ */ jsxRuntime.jsx(
11885
- "rect",
11886
- {
11887
- width: "12",
11888
- height: "3",
11889
- rx: "1.5",
11890
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
11891
- fill: "#D4D4D8"
11892
- }
11893
- ),
11894
- /* @__PURE__ */ jsxRuntime.jsx(
11895
- "path",
11896
- {
11897
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
11898
- fill: "#A1A1AA"
11899
- }
11900
- ),
11901
- /* @__PURE__ */ jsxRuntime.jsx(
11902
- "rect",
11903
- {
11904
- width: "17",
11905
- height: "3",
11906
- rx: "1.5",
11907
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
11908
- fill: "#A1A1AA"
11909
- }
11910
- ),
11911
- /* @__PURE__ */ jsxRuntime.jsx(
11912
- "rect",
11913
- {
11914
- width: "12",
11915
- height: "3",
11916
- rx: "1.5",
11917
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
11918
- fill: "#A1A1AA"
11919
- }
11920
- ),
11921
- /* @__PURE__ */ jsxRuntime.jsx(
11922
- "path",
11923
- {
11924
- 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",
11925
- fill: "#52525B"
11926
- }
11927
- ),
11928
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11929
- "path",
11930
- {
11931
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
11932
- stroke: "#A1A1AA",
11933
- strokeWidth: "1.5",
11934
- strokeLinecap: "round",
11935
- strokeLinejoin: "round"
11936
- }
11937
- ) }),
11938
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11939
- "path",
11940
- {
11941
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
11942
- stroke: "#A1A1AA",
11943
- strokeWidth: "1.5",
11944
- strokeLinecap: "round",
11945
- strokeLinejoin: "round"
11946
- }
11947
- ) }),
11948
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11949
- "path",
11950
- {
11951
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
11952
- stroke: "#A1A1AA",
11953
- strokeWidth: "1.5",
11954
- strokeLinecap: "round",
11955
- strokeLinejoin: "round"
11956
- }
11957
- ) }),
11958
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11959
- "path",
11960
- {
11961
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
11962
- stroke: "#A1A1AA",
11963
- strokeWidth: "1.5",
11964
- strokeLinecap: "round",
11965
- strokeLinejoin: "round"
11966
- }
11967
- ) }),
11968
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11969
- "path",
11970
- {
11971
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
11972
- stroke: "#A1A1AA",
11973
- strokeWidth: "1.5",
11974
- strokeLinecap: "round",
11975
- strokeLinejoin: "round"
11976
- }
11977
- ) }),
11978
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
11979
- "path",
11980
- {
11981
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
11982
- stroke: "#A1A1AA",
11983
- strokeWidth: "1.5",
11984
- strokeLinecap: "round",
11985
- strokeLinejoin: "round"
11986
- }
11987
- ) }),
11988
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
11989
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11990
- "rect",
11991
- {
11992
- width: "12",
11993
- height: "12",
11994
- fill: "white",
11995
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
11996
- }
11997
- ) }),
11998
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
11999
- "rect",
12000
- {
12001
- width: "12",
12002
- height: "12",
12003
- fill: "white",
12004
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12005
- }
12006
- ) }),
12007
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12008
- "rect",
12009
- {
12010
- width: "12",
12011
- height: "12",
12012
- fill: "white",
12013
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12014
- }
12015
- ) }),
12016
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12017
- "rect",
12018
- {
12019
- width: "12",
12020
- height: "12",
12021
- fill: "white",
12022
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12023
- }
12024
- ) }),
12025
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12026
- "rect",
12027
- {
12028
- width: "12",
12029
- height: "12",
12030
- fill: "white",
12031
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12032
- }
12033
- ) }),
12034
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12035
- "rect",
12036
- {
12037
- width: "12",
12038
- height: "12",
12039
- fill: "white",
12040
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12041
- }
12042
- ) })
12043
- ] })
12044
- ]
12045
- }
12046
- );
12047
- };
12048
- const schema$1 = objectType({
12049
- customer_id: stringType().min(1)
12050
- });
12051
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12052
- const Shipping = () => {
12053
- var _a;
12054
- const { id } = reactRouterDom.useParams();
12055
- const { order, isPending, isError, error } = useOrder(id, {
12056
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12057
- });
12058
- const {
12059
- order: preview,
12060
- isPending: isPreviewPending,
12061
- isError: isPreviewError,
12062
- error: previewError
12063
- } = useOrderPreview(id);
12064
- useInitiateOrderEdit({ preview });
12065
- const { onCancel } = useCancelOrderEdit({ preview });
12066
- if (isError) {
12067
- throw error;
12068
- }
12069
- if (isPreviewError) {
12070
- throw previewError;
12071
- }
12072
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12073
- const isReady = preview && !isPreviewPending && order && !isPending;
12074
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12075
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12076
- /* @__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: [
12077
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12078
- /* @__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." }) })
12079
- ] }) }) }),
12080
- /* @__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" }) }) })
12081
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12082
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12083
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12084
- ] }) });
12085
- };
12086
- const ShippingForm = ({ preview, order }) => {
12087
- var _a;
12088
- const { setIsOpen } = useStackedModal();
12089
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12090
- const [data, setData] = React.useState(null);
12091
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12092
- const { shipping_options } = useShippingOptions(
11557
+ const schema$2 = objectType({
11558
+ sales_channel_id: stringType().min(1)
11559
+ });
11560
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11561
+ const Shipping = () => {
11562
+ var _a;
11563
+ const { id } = reactRouterDom.useParams();
11564
+ const { order, isPending, isError, error } = useOrder(id, {
11565
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11566
+ });
11567
+ const {
11568
+ order: preview,
11569
+ isPending: isPreviewPending,
11570
+ isError: isPreviewError,
11571
+ error: previewError
11572
+ } = useOrderPreview(id);
11573
+ useInitiateOrderEdit({ preview });
11574
+ const { onCancel } = useCancelOrderEdit({ preview });
11575
+ if (isError) {
11576
+ throw error;
11577
+ }
11578
+ if (isPreviewError) {
11579
+ throw previewError;
11580
+ }
11581
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11582
+ const isReady = preview && !isPreviewPending && order && !isPending;
11583
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11584
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11585
+ /* @__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: [
11586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11587
+ /* @__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." }) })
11588
+ ] }) }) }),
11589
+ /* @__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" }) }) })
11590
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11591
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11592
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11593
+ ] }) });
11594
+ };
11595
+ const ShippingForm = ({ preview, order }) => {
11596
+ var _a;
11597
+ const { setIsOpen } = useStackedModal();
11598
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11599
+ const [data, setData] = React.useState(null);
11600
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11601
+ const { shipping_options } = useShippingOptions(
12093
11602
  {
12094
11603
  id: appliedShippingOptionIds,
12095
11604
  fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
@@ -12855,10 +12364,10 @@ const CustomAmountField = ({
12855
12364
  }
12856
12365
  );
12857
12366
  };
12858
- const BillingAddress = () => {
12367
+ const ShippingAddress = () => {
12859
12368
  const { id } = reactRouterDom.useParams();
12860
12369
  const { order, isPending, isError, error } = useOrder(id, {
12861
- fields: "+billing_address"
12370
+ fields: "+shipping_address"
12862
12371
  });
12863
12372
  if (isError) {
12864
12373
  throw error;
@@ -12866,34 +12375,47 @@ const BillingAddress = () => {
12866
12375
  const isReady = !isPending && !!order;
12867
12376
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12868
12377
  /* @__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" }) })
12378
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12379
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12871
12380
  ] }),
12872
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12381
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12873
12382
  ] });
12874
12383
  };
12875
- const BillingAddressForm = ({ order }) => {
12384
+ const ShippingAddressForm = ({ order }) => {
12876
12385
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12877
12386
  const form = reactHookForm.useForm({
12878
12387
  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) ?? ""
12388
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12389
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12390
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12391
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12392
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12393
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12394
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12395
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12396
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12397
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12889
12398
  },
12890
- resolver: zod.zodResolver(schema)
12399
+ resolver: zod.zodResolver(schema$1)
12891
12400
  });
12892
12401
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12893
12402
  const { handleSuccess } = useRouteModal();
12894
12403
  const onSubmit = form.handleSubmit(async (data) => {
12895
12404
  await mutateAsync(
12896
- { billing_address: data },
12405
+ {
12406
+ shipping_address: {
12407
+ first_name: data.first_name,
12408
+ last_name: data.last_name,
12409
+ company: data.company,
12410
+ address_1: data.address_1,
12411
+ address_2: data.address_2,
12412
+ city: data.city,
12413
+ province: data.province,
12414
+ country_code: data.country_code,
12415
+ postal_code: data.postal_code,
12416
+ phone: data.phone
12417
+ }
12418
+ },
12897
12419
  {
12898
12420
  onSuccess: () => {
12899
12421
  handleSuccess();
@@ -12914,137 +12436,613 @@ const BillingAddressForm = ({ order }) => {
12914
12436
  /* @__PURE__ */ jsxRuntime.jsx(
12915
12437
  Form$2.Field,
12916
12438
  {
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
- ] })
12439
+ control: form.control,
12440
+ name: "country_code",
12441
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12442
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12443
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12445
+ ] })
12446
+ }
12447
+ ),
12448
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12449
+ /* @__PURE__ */ jsxRuntime.jsx(
12450
+ Form$2.Field,
12451
+ {
12452
+ control: form.control,
12453
+ name: "first_name",
12454
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12455
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12456
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12458
+ ] })
12459
+ }
12460
+ ),
12461
+ /* @__PURE__ */ jsxRuntime.jsx(
12462
+ Form$2.Field,
12463
+ {
12464
+ control: form.control,
12465
+ name: "last_name",
12466
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12467
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12468
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12470
+ ] })
12471
+ }
12472
+ )
12473
+ ] }),
12474
+ /* @__PURE__ */ jsxRuntime.jsx(
12475
+ Form$2.Field,
12476
+ {
12477
+ control: form.control,
12478
+ name: "company",
12479
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12480
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12481
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12483
+ ] })
12484
+ }
12485
+ ),
12486
+ /* @__PURE__ */ jsxRuntime.jsx(
12487
+ Form$2.Field,
12488
+ {
12489
+ control: form.control,
12490
+ name: "address_1",
12491
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12492
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12493
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12495
+ ] })
12496
+ }
12497
+ ),
12498
+ /* @__PURE__ */ jsxRuntime.jsx(
12499
+ Form$2.Field,
12500
+ {
12501
+ control: form.control,
12502
+ name: "address_2",
12503
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12504
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12505
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12507
+ ] })
12508
+ }
12509
+ ),
12510
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12511
+ /* @__PURE__ */ jsxRuntime.jsx(
12512
+ Form$2.Field,
12513
+ {
12514
+ control: form.control,
12515
+ name: "postal_code",
12516
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12517
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12518
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12520
+ ] })
12521
+ }
12522
+ ),
12523
+ /* @__PURE__ */ jsxRuntime.jsx(
12524
+ Form$2.Field,
12525
+ {
12526
+ control: form.control,
12527
+ name: "city",
12528
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12529
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12530
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12532
+ ] })
12533
+ }
12534
+ )
12535
+ ] }),
12536
+ /* @__PURE__ */ jsxRuntime.jsx(
12537
+ Form$2.Field,
12538
+ {
12539
+ control: form.control,
12540
+ name: "province",
12541
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12542
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12545
+ ] })
12546
+ }
12547
+ ),
12548
+ /* @__PURE__ */ jsxRuntime.jsx(
12549
+ Form$2.Field,
12550
+ {
12551
+ control: form.control,
12552
+ name: "phone",
12553
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12557
+ ] })
12558
+ }
12559
+ )
12560
+ ] }) }),
12561
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12562
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12564
+ ] }) })
12565
+ ]
12566
+ }
12567
+ ) });
12568
+ };
12569
+ const schema$1 = addressSchema;
12570
+ const TransferOwnership = () => {
12571
+ const { id } = reactRouterDom.useParams();
12572
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12573
+ fields: "id,customer_id,customer.*"
12574
+ });
12575
+ if (isError) {
12576
+ throw error;
12577
+ }
12578
+ const isReady = !isPending && !!draft_order;
12579
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12580
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12581
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12582
+ /* @__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" }) })
12583
+ ] }),
12584
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12585
+ ] });
12586
+ };
12587
+ const TransferOwnershipForm = ({ order }) => {
12588
+ var _a, _b;
12589
+ const form = reactHookForm.useForm({
12590
+ defaultValues: {
12591
+ customer_id: order.customer_id || ""
12592
+ },
12593
+ resolver: zod.zodResolver(schema)
12594
+ });
12595
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12596
+ const { handleSuccess } = useRouteModal();
12597
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12598
+ const currentCustomer = order.customer ? {
12599
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12600
+ value: order.customer.id
12601
+ } : null;
12602
+ const onSubmit = form.handleSubmit(async (data) => {
12603
+ await mutateAsync(
12604
+ { customer_id: data.customer_id },
12605
+ {
12606
+ onSuccess: () => {
12607
+ ui.toast.success("Customer updated");
12608
+ handleSuccess();
12609
+ },
12610
+ onError: (error) => {
12611
+ ui.toast.error(error.message);
12612
+ }
12613
+ }
12614
+ );
12615
+ });
12616
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12617
+ KeyboundForm,
12618
+ {
12619
+ className: "flex flex-1 flex-col overflow-hidden",
12620
+ onSubmit,
12621
+ children: [
12622
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12623
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12624
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12625
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12626
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12627
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12628
+ ] }),
12629
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12630
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12631
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12632
+ ] })
12633
+ ] }),
12634
+ /* @__PURE__ */ jsxRuntime.jsx(
12635
+ CustomerField,
12636
+ {
12637
+ control: form.control,
12638
+ currentCustomerId: order.customer_id
12639
+ }
12640
+ )
12641
+ ] }),
12642
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12643
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12644
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12645
+ ] }) })
12646
+ ]
12647
+ }
12648
+ ) });
12649
+ };
12650
+ const CustomerField = ({ control, currentCustomerId }) => {
12651
+ const customers = useComboboxData({
12652
+ queryFn: async (params) => {
12653
+ return await sdk.admin.customer.list({
12654
+ ...params,
12655
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12656
+ });
12657
+ },
12658
+ queryKey: ["customers"],
12659
+ getOptions: (data) => {
12660
+ return data.customers.map((customer) => {
12661
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12662
+ return {
12663
+ label: name ? `${name} (${customer.email})` : customer.email,
12664
+ value: customer.id
12665
+ };
12666
+ });
12667
+ }
12668
+ });
12669
+ return /* @__PURE__ */ jsxRuntime.jsx(
12670
+ Form$2.Field,
12671
+ {
12672
+ name: "customer_id",
12673
+ control,
12674
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12675
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12677
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12678
+ ] }),
12679
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12680
+ Combobox,
12681
+ {
12682
+ options: customers.options,
12683
+ fetchNextPage: customers.fetchNextPage,
12684
+ isFetchingNextPage: customers.isFetchingNextPage,
12685
+ searchValue: customers.searchValue,
12686
+ onSearchValueChange: customers.onSearchValueChange,
12687
+ placeholder: "Select customer",
12688
+ ...field
12689
+ }
12690
+ ) }),
12691
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12692
+ ] })
12693
+ }
12694
+ );
12695
+ };
12696
+ const Illustration = () => {
12697
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12698
+ "svg",
12699
+ {
12700
+ width: "280",
12701
+ height: "180",
12702
+ viewBox: "0 0 280 180",
12703
+ fill: "none",
12704
+ xmlns: "http://www.w3.org/2000/svg",
12705
+ children: [
12706
+ /* @__PURE__ */ jsxRuntime.jsx(
12707
+ "rect",
12708
+ {
12709
+ x: "0.00428286",
12710
+ y: "-0.742904",
12711
+ width: "33.5",
12712
+ height: "65.5",
12713
+ rx: "6.75",
12714
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12715
+ fill: "#D4D4D8",
12716
+ stroke: "#52525B",
12717
+ strokeWidth: "1.5"
12718
+ }
12719
+ ),
12720
+ /* @__PURE__ */ jsxRuntime.jsx(
12721
+ "rect",
12722
+ {
12723
+ x: "0.00428286",
12724
+ y: "-0.742904",
12725
+ width: "33.5",
12726
+ height: "65.5",
12727
+ rx: "6.75",
12728
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12729
+ fill: "white",
12730
+ stroke: "#52525B",
12731
+ strokeWidth: "1.5"
12732
+ }
12733
+ ),
12734
+ /* @__PURE__ */ jsxRuntime.jsx(
12735
+ "path",
12736
+ {
12737
+ d: "M180.579 107.142L179.126 107.959",
12738
+ stroke: "#52525B",
12739
+ strokeWidth: "1.5",
12740
+ strokeLinecap: "round",
12741
+ strokeLinejoin: "round"
12742
+ }
12743
+ ),
12744
+ /* @__PURE__ */ jsxRuntime.jsx(
12745
+ "path",
12746
+ {
12747
+ opacity: "0.88",
12748
+ d: "M182.305 109.546L180.257 109.534",
12749
+ stroke: "#52525B",
12750
+ strokeWidth: "1.5",
12751
+ strokeLinecap: "round",
12752
+ strokeLinejoin: "round"
12753
+ }
12754
+ ),
12755
+ /* @__PURE__ */ jsxRuntime.jsx(
12756
+ "path",
12757
+ {
12758
+ opacity: "0.75",
12759
+ d: "M180.551 111.93L179.108 111.096",
12760
+ stroke: "#52525B",
12761
+ strokeWidth: "1.5",
12762
+ strokeLinecap: "round",
12763
+ strokeLinejoin: "round"
12764
+ }
12765
+ ),
12766
+ /* @__PURE__ */ jsxRuntime.jsx(
12767
+ "path",
12768
+ {
12769
+ opacity: "0.63",
12770
+ d: "M176.347 112.897L176.354 111.73",
12771
+ stroke: "#52525B",
12772
+ strokeWidth: "1.5",
12773
+ strokeLinecap: "round",
12774
+ strokeLinejoin: "round"
12775
+ }
12776
+ ),
12777
+ /* @__PURE__ */ jsxRuntime.jsx(
12778
+ "path",
12779
+ {
12780
+ opacity: "0.5",
12781
+ d: "M172.153 111.881L173.606 111.064",
12782
+ stroke: "#52525B",
12783
+ strokeWidth: "1.5",
12784
+ strokeLinecap: "round",
12785
+ strokeLinejoin: "round"
12786
+ }
12787
+ ),
12788
+ /* @__PURE__ */ jsxRuntime.jsx(
12789
+ "path",
12790
+ {
12791
+ opacity: "0.38",
12792
+ d: "M170.428 109.478L172.476 109.489",
12793
+ stroke: "#52525B",
12794
+ strokeWidth: "1.5",
12795
+ strokeLinecap: "round",
12796
+ strokeLinejoin: "round"
12797
+ }
12798
+ ),
12799
+ /* @__PURE__ */ jsxRuntime.jsx(
12800
+ "path",
12801
+ {
12802
+ opacity: "0.25",
12803
+ d: "M172.181 107.094L173.624 107.928",
12804
+ stroke: "#52525B",
12805
+ strokeWidth: "1.5",
12806
+ strokeLinecap: "round",
12807
+ strokeLinejoin: "round"
12808
+ }
12809
+ ),
12810
+ /* @__PURE__ */ jsxRuntime.jsx(
12811
+ "path",
12812
+ {
12813
+ opacity: "0.13",
12814
+ d: "M176.386 106.126L176.379 107.294",
12815
+ stroke: "#52525B",
12816
+ strokeWidth: "1.5",
12817
+ strokeLinecap: "round",
12818
+ strokeLinejoin: "round"
12819
+ }
12820
+ ),
12821
+ /* @__PURE__ */ jsxRuntime.jsx(
12822
+ "rect",
12823
+ {
12824
+ width: "12",
12825
+ height: "3",
12826
+ rx: "1.5",
12827
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12828
+ fill: "#D4D4D8"
12829
+ }
12830
+ ),
12831
+ /* @__PURE__ */ jsxRuntime.jsx(
12832
+ "rect",
12833
+ {
12834
+ x: "0.00428286",
12835
+ y: "-0.742904",
12836
+ width: "33.5",
12837
+ height: "65.5",
12838
+ rx: "6.75",
12839
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12840
+ fill: "#D4D4D8",
12841
+ stroke: "#52525B",
12842
+ strokeWidth: "1.5"
12843
+ }
12844
+ ),
12845
+ /* @__PURE__ */ jsxRuntime.jsx(
12846
+ "rect",
12847
+ {
12848
+ x: "0.00428286",
12849
+ y: "-0.742904",
12850
+ width: "33.5",
12851
+ height: "65.5",
12852
+ rx: "6.75",
12853
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12854
+ fill: "white",
12855
+ stroke: "#52525B",
12856
+ strokeWidth: "1.5"
12857
+ }
12858
+ ),
12859
+ /* @__PURE__ */ jsxRuntime.jsx(
12860
+ "rect",
12861
+ {
12862
+ width: "12",
12863
+ height: "3",
12864
+ rx: "1.5",
12865
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12866
+ fill: "#D4D4D8"
12867
+ }
12868
+ ),
12869
+ /* @__PURE__ */ jsxRuntime.jsx(
12870
+ "rect",
12871
+ {
12872
+ width: "17",
12873
+ height: "3",
12874
+ rx: "1.5",
12875
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12876
+ fill: "#D4D4D8"
12877
+ }
12878
+ ),
12879
+ /* @__PURE__ */ jsxRuntime.jsx(
12880
+ "rect",
12881
+ {
12882
+ width: "12",
12883
+ height: "3",
12884
+ rx: "1.5",
12885
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12886
+ fill: "#D4D4D8"
12887
+ }
12888
+ ),
12889
+ /* @__PURE__ */ jsxRuntime.jsx(
12890
+ "path",
12891
+ {
12892
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12893
+ fill: "#A1A1AA"
12894
+ }
12895
+ ),
12896
+ /* @__PURE__ */ jsxRuntime.jsx(
12897
+ "rect",
12898
+ {
12899
+ width: "17",
12900
+ height: "3",
12901
+ rx: "1.5",
12902
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12903
+ fill: "#A1A1AA"
12904
+ }
12905
+ ),
12906
+ /* @__PURE__ */ jsxRuntime.jsx(
12907
+ "rect",
12908
+ {
12909
+ width: "12",
12910
+ height: "3",
12911
+ rx: "1.5",
12912
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12913
+ fill: "#A1A1AA"
12914
+ }
12915
+ ),
12916
+ /* @__PURE__ */ jsxRuntime.jsx(
12917
+ "path",
12918
+ {
12919
+ 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",
12920
+ fill: "#52525B"
12921
+ }
12922
+ ),
12923
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12924
+ "path",
12925
+ {
12926
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12927
+ stroke: "#A1A1AA",
12928
+ strokeWidth: "1.5",
12929
+ strokeLinecap: "round",
12930
+ strokeLinejoin: "round"
12931
+ }
12932
+ ) }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12934
+ "path",
12935
+ {
12936
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12937
+ stroke: "#A1A1AA",
12938
+ strokeWidth: "1.5",
12939
+ strokeLinecap: "round",
12940
+ strokeLinejoin: "round"
12941
+ }
12942
+ ) }),
12943
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12944
+ "path",
12945
+ {
12946
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12947
+ stroke: "#A1A1AA",
12948
+ strokeWidth: "1.5",
12949
+ strokeLinecap: "round",
12950
+ strokeLinejoin: "round"
12951
+ }
12952
+ ) }),
12953
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12954
+ "path",
12955
+ {
12956
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12957
+ stroke: "#A1A1AA",
12958
+ strokeWidth: "1.5",
12959
+ strokeLinecap: "round",
12960
+ strokeLinejoin: "round"
12961
+ }
12962
+ ) }),
12963
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12964
+ "path",
12965
+ {
12966
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12967
+ stroke: "#A1A1AA",
12968
+ strokeWidth: "1.5",
12969
+ strokeLinecap: "round",
12970
+ strokeLinejoin: "round"
12971
+ }
12972
+ ) }),
12973
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12974
+ "path",
12975
+ {
12976
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12977
+ stroke: "#A1A1AA",
12978
+ strokeWidth: "1.5",
12979
+ strokeLinecap: "round",
12980
+ strokeLinejoin: "round"
12981
+ }
12982
+ ) }),
12983
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12984
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12985
+ "rect",
12986
+ {
12987
+ width: "12",
12988
+ height: "12",
12989
+ fill: "white",
12990
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12924
12991
  }
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,
12992
+ ) }),
12993
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12994
+ "rect",
12954
12995
  {
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
- ] })
12996
+ width: "12",
12997
+ height: "12",
12998
+ fill: "white",
12999
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12962
13000
  }
12963
- ),
12964
- /* @__PURE__ */ jsxRuntime.jsx(
12965
- Form$2.Field,
13001
+ ) }),
13002
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13003
+ "rect",
12966
13004
  {
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
- ] })
13005
+ width: "12",
13006
+ height: "12",
13007
+ fill: "white",
13008
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12974
13009
  }
12975
- ),
12976
- /* @__PURE__ */ jsxRuntime.jsx(
12977
- Form$2.Field,
13010
+ ) }),
13011
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13012
+ "rect",
12978
13013
  {
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
- ] })
13014
+ width: "12",
13015
+ height: "12",
13016
+ fill: "white",
13017
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12986
13018
  }
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,
13019
+ ) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13021
+ "rect",
13016
13022
  {
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
- ] })
13023
+ width: "12",
13024
+ height: "12",
13025
+ fill: "white",
13026
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13024
13027
  }
13025
- ),
13026
- /* @__PURE__ */ jsxRuntime.jsx(
13027
- Form$2.Field,
13028
+ ) }),
13029
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13030
+ "rect",
13028
13031
  {
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
- ] })
13032
+ width: "12",
13033
+ height: "12",
13034
+ fill: "white",
13035
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13036
13036
  }
13037
- )
13038
- ] }) }),
13039
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13040
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13041
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13042
- ] }) })
13037
+ ) })
13038
+ ] })
13043
13039
  ]
13044
13040
  }
13045
- ) });
13041
+ );
13046
13042
  };
13047
- const schema = addressSchema;
13043
+ const schema = objectType({
13044
+ customer_id: stringType().min(1)
13045
+ });
13048
13046
  const widgetModule = { widgets: [] };
13049
13047
  const routeModule = {
13050
13048
  routes: [
@@ -13065,6 +13063,10 @@ const routeModule = {
13065
13063
  handle,
13066
13064
  loader,
13067
13065
  children: [
13066
+ {
13067
+ Component: BillingAddress,
13068
+ path: "/draft-orders/:id/billing-address"
13069
+ },
13068
13070
  {
13069
13071
  Component: CustomItems,
13070
13072
  path: "/draft-orders/:id/custom-items"
@@ -13073,10 +13075,6 @@ const routeModule = {
13073
13075
  Component: Email,
13074
13076
  path: "/draft-orders/:id/email"
13075
13077
  },
13076
- {
13077
- Component: Metadata,
13078
- path: "/draft-orders/:id/metadata"
13079
- },
13080
13078
  {
13081
13079
  Component: Items,
13082
13080
  path: "/draft-orders/:id/items"
@@ -13085,10 +13083,18 @@ const routeModule = {
13085
13083
  Component: Promotions,
13086
13084
  path: "/draft-orders/:id/promotions"
13087
13085
  },
13086
+ {
13087
+ Component: Metadata,
13088
+ path: "/draft-orders/:id/metadata"
13089
+ },
13088
13090
  {
13089
13091
  Component: SalesChannel,
13090
13092
  path: "/draft-orders/:id/sales-channel"
13091
13093
  },
13094
+ {
13095
+ Component: Shipping,
13096
+ path: "/draft-orders/:id/shipping"
13097
+ },
13092
13098
  {
13093
13099
  Component: ShippingAddress,
13094
13100
  path: "/draft-orders/:id/shipping-address"
@@ -13096,14 +13102,6 @@ const routeModule = {
13096
13102
  {
13097
13103
  Component: TransferOwnership,
13098
13104
  path: "/draft-orders/:id/transfer-ownership"
13099
- },
13100
- {
13101
- Component: Shipping,
13102
- path: "/draft-orders/:id/shipping"
13103
- },
13104
- {
13105
- Component: BillingAddress,
13106
- path: "/draft-orders/:id/billing-address"
13107
13105
  }
13108
13106
  ]
13109
13107
  }