@medusajs/draft-order 2.11.1-preview-20251024090150 → 2.11.1-preview-20251024120210

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.
@@ -9660,196 +9660,6 @@ const EmailForm = ({ order }) => {
9660
9660
  const schema$4 = objectType({
9661
9661
  email: stringType().email()
9662
9662
  });
9663
- const BillingAddress = () => {
9664
- const { id } = reactRouterDom.useParams();
9665
- const { order, isPending, isError, error } = useOrder(id, {
9666
- fields: "+billing_address"
9667
- });
9668
- if (isError) {
9669
- throw error;
9670
- }
9671
- const isReady = !isPending && !!order;
9672
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9673
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9674
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
9675
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
9676
- ] }),
9677
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
9678
- ] });
9679
- };
9680
- const BillingAddressForm = ({ order }) => {
9681
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
9682
- const form = reactHookForm.useForm({
9683
- defaultValues: {
9684
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
9685
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
9686
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
9687
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
9688
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
9689
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
9690
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
9691
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
9692
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9693
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9694
- },
9695
- resolver: zod.zodResolver(schema$3)
9696
- });
9697
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9698
- const { handleSuccess } = useRouteModal();
9699
- const onSubmit = form.handleSubmit(async (data) => {
9700
- await mutateAsync(
9701
- { billing_address: data },
9702
- {
9703
- onSuccess: () => {
9704
- handleSuccess();
9705
- },
9706
- onError: (error) => {
9707
- ui.toast.error(error.message);
9708
- }
9709
- }
9710
- );
9711
- });
9712
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9713
- KeyboundForm,
9714
- {
9715
- className: "flex flex-1 flex-col overflow-hidden",
9716
- onSubmit,
9717
- children: [
9718
- /* @__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: [
9719
- /* @__PURE__ */ jsxRuntime.jsx(
9720
- Form$2.Field,
9721
- {
9722
- control: form.control,
9723
- name: "country_code",
9724
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
9726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
9727
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9728
- ] })
9729
- }
9730
- ),
9731
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9732
- /* @__PURE__ */ jsxRuntime.jsx(
9733
- Form$2.Field,
9734
- {
9735
- control: form.control,
9736
- name: "first_name",
9737
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9738
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
9739
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9740
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9741
- ] })
9742
- }
9743
- ),
9744
- /* @__PURE__ */ jsxRuntime.jsx(
9745
- Form$2.Field,
9746
- {
9747
- control: form.control,
9748
- name: "last_name",
9749
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9750
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
9751
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9752
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9753
- ] })
9754
- }
9755
- )
9756
- ] }),
9757
- /* @__PURE__ */ jsxRuntime.jsx(
9758
- Form$2.Field,
9759
- {
9760
- control: form.control,
9761
- name: "company",
9762
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9763
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
9764
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9765
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9766
- ] })
9767
- }
9768
- ),
9769
- /* @__PURE__ */ jsxRuntime.jsx(
9770
- Form$2.Field,
9771
- {
9772
- control: form.control,
9773
- name: "address_1",
9774
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9775
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
9776
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9777
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9778
- ] })
9779
- }
9780
- ),
9781
- /* @__PURE__ */ jsxRuntime.jsx(
9782
- Form$2.Field,
9783
- {
9784
- control: form.control,
9785
- name: "address_2",
9786
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9787
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
9788
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9789
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9790
- ] })
9791
- }
9792
- ),
9793
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
9794
- /* @__PURE__ */ jsxRuntime.jsx(
9795
- Form$2.Field,
9796
- {
9797
- control: form.control,
9798
- name: "postal_code",
9799
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9800
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
9801
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9802
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9803
- ] })
9804
- }
9805
- ),
9806
- /* @__PURE__ */ jsxRuntime.jsx(
9807
- Form$2.Field,
9808
- {
9809
- control: form.control,
9810
- name: "city",
9811
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9812
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
9813
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9814
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9815
- ] })
9816
- }
9817
- )
9818
- ] }),
9819
- /* @__PURE__ */ jsxRuntime.jsx(
9820
- Form$2.Field,
9821
- {
9822
- control: form.control,
9823
- name: "province",
9824
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9825
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
9826
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9827
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9828
- ] })
9829
- }
9830
- ),
9831
- /* @__PURE__ */ jsxRuntime.jsx(
9832
- Form$2.Field,
9833
- {
9834
- control: form.control,
9835
- name: "phone",
9836
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9837
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9839
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9840
- ] })
9841
- }
9842
- )
9843
- ] }) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9845
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9846
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9847
- ] }) })
9848
- ]
9849
- }
9850
- ) });
9851
- };
9852
- const schema$3 = addressSchema;
9853
9663
  const NumberInput = React.forwardRef(
9854
9664
  ({
9855
9665
  value,
@@ -10824,1122 +10634,855 @@ const customItemSchema = objectType({
10824
10634
  quantity: numberType(),
10825
10635
  unit_price: unionType([numberType(), stringType()])
10826
10636
  });
10827
- const PROMOTION_QUERY_KEY = "promotions";
10828
- const promotionsQueryKeys = {
10829
- list: (query2) => [
10830
- PROMOTION_QUERY_KEY,
10831
- query2 ? query2 : void 0
10832
- ],
10833
- detail: (id, query2) => [
10834
- PROMOTION_QUERY_KEY,
10835
- id,
10836
- query2 ? query2 : void 0
10837
- ]
10838
- };
10839
- const usePromotions = (query2, options) => {
10840
- const { data, ...rest } = reactQuery.useQuery({
10841
- queryKey: promotionsQueryKeys.list(query2),
10842
- queryFn: async () => sdk.admin.promotion.list(query2),
10843
- ...options
10844
- });
10845
- return { ...data, ...rest };
10846
- };
10847
- const Promotions = () => {
10637
+ const BillingAddress = () => {
10848
10638
  const { id } = reactRouterDom.useParams();
10849
- const {
10850
- order: preview,
10851
- isError: isPreviewError,
10852
- error: previewError
10853
- } = useOrderPreview(id, void 0);
10854
- useInitiateOrderEdit({ preview });
10855
- const { onCancel } = useCancelOrderEdit({ preview });
10856
- if (isPreviewError) {
10857
- throw previewError;
10639
+ const { order, isPending, isError, error } = useOrder(id, {
10640
+ fields: "+billing_address"
10641
+ });
10642
+ if (isError) {
10643
+ throw error;
10858
10644
  }
10859
- const isReady = !!preview;
10860
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
10861
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
10862
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10645
+ const isReady = !isPending && !!order;
10646
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10647
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10648
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
10649
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
10650
+ ] }),
10651
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
10863
10652
  ] });
10864
10653
  };
10865
- const PromotionForm = ({ preview }) => {
10866
- const { items, shipping_methods } = preview;
10867
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10868
- const [comboboxValue, setComboboxValue] = React.useState("");
10869
- const { handleSuccess } = useRouteModal();
10870
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10871
- const promoIds = getPromotionIds(items, shipping_methods);
10872
- const { promotions, isPending, isError, error } = usePromotions(
10873
- {
10874
- id: promoIds
10875
- },
10876
- {
10877
- enabled: !!promoIds.length
10878
- }
10879
- );
10880
- const comboboxData = useComboboxData({
10881
- queryKey: ["promotions", "combobox", promoIds],
10882
- queryFn: async (params) => {
10883
- return await sdk.admin.promotion.list({
10884
- ...params,
10885
- id: {
10886
- $nin: promoIds
10887
- }
10888
- });
10654
+ const BillingAddressForm = ({ order }) => {
10655
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
10656
+ const form = reactHookForm.useForm({
10657
+ defaultValues: {
10658
+ first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
10659
+ last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
10660
+ company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
10661
+ address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
10662
+ address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
10663
+ city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
10664
+ province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
10665
+ country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
10666
+ postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
10667
+ phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
10889
10668
  },
10890
- getOptions: (data) => {
10891
- return data.promotions.map((promotion) => ({
10892
- label: promotion.code,
10893
- value: promotion.code
10894
- }));
10895
- }
10669
+ resolver: zod.zodResolver(schema$3)
10896
10670
  });
10897
- const add = async (value) => {
10898
- if (!value) {
10899
- return;
10900
- }
10901
- addPromotions(
10902
- {
10903
- promo_codes: [value]
10904
- },
10671
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10672
+ const { handleSuccess } = useRouteModal();
10673
+ const onSubmit = form.handleSubmit(async (data) => {
10674
+ await mutateAsync(
10675
+ { billing_address: data },
10905
10676
  {
10906
- onError: (e) => {
10907
- ui.toast.error(e.message);
10908
- comboboxData.onSearchValueChange("");
10909
- setComboboxValue("");
10910
- },
10911
10677
  onSuccess: () => {
10912
- comboboxData.onSearchValueChange("");
10913
- setComboboxValue("");
10914
- }
10915
- }
10916
- );
10917
- };
10918
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10919
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10920
- const onSubmit = async () => {
10921
- setIsSubmitting(true);
10922
- let requestSucceeded = false;
10923
- await requestOrderEdit(void 0, {
10924
- onError: (e) => {
10925
- ui.toast.error(e.message);
10926
- },
10927
- onSuccess: () => {
10928
- requestSucceeded = true;
10929
- }
10930
- });
10931
- if (!requestSucceeded) {
10932
- setIsSubmitting(false);
10933
- return;
10934
- }
10935
- await confirmOrderEdit(void 0, {
10936
- onError: (e) => {
10937
- ui.toast.error(e.message);
10938
- },
10939
- onSuccess: () => {
10940
- handleSuccess();
10941
- },
10942
- onSettled: () => {
10943
- setIsSubmitting(false);
10944
- }
10945
- });
10946
- };
10947
- if (isError) {
10948
- throw error;
10949
- }
10950
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10951
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
10952
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
10953
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10954
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10955
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10956
- ] }),
10957
- /* @__PURE__ */ jsxRuntime.jsx(
10958
- Combobox,
10959
- {
10960
- id: "promotion-combobox",
10961
- "aria-describedby": "promotion-combobox-hint",
10962
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10963
- fetchNextPage: comboboxData.fetchNextPage,
10964
- options: comboboxData.options,
10965
- onSearchValueChange: comboboxData.onSearchValueChange,
10966
- searchValue: comboboxData.searchValue,
10967
- disabled: comboboxData.disabled || isAddingPromotions,
10968
- onChange: add,
10969
- value: comboboxValue
10970
- }
10971
- )
10972
- ] }),
10973
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10974
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
10975
- PromotionItem,
10976
- {
10977
- promotion,
10978
- orderId: preview.id,
10979
- isLoading: isPending
10678
+ handleSuccess();
10980
10679
  },
10981
- promotion.id
10982
- )) })
10983
- ] }) }),
10984
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10985
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10986
- /* @__PURE__ */ jsxRuntime.jsx(
10987
- ui.Button,
10988
- {
10989
- size: "small",
10990
- type: "submit",
10991
- isLoading: isSubmitting || isAddingPromotions,
10992
- children: "Save"
10993
- }
10994
- )
10995
- ] }) })
10996
- ] });
10997
- };
10998
- const PromotionItem = ({
10999
- promotion,
11000
- orderId,
11001
- isLoading
11002
- }) => {
11003
- var _a;
11004
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11005
- const onRemove = async () => {
11006
- removePromotions(
11007
- {
11008
- promo_codes: [promotion.code]
11009
- },
11010
- {
11011
- onError: (e) => {
11012
- ui.toast.error(e.message);
10680
+ onError: (error) => {
10681
+ ui.toast.error(error.message);
11013
10682
  }
11014
10683
  }
11015
10684
  );
11016
- };
11017
- const displayValue = getDisplayValue(promotion);
11018
- return /* @__PURE__ */ jsxRuntime.jsxs(
11019
- "div",
10685
+ });
10686
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10687
+ KeyboundForm,
11020
10688
  {
11021
- className: ui.clx(
11022
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11023
- {
11024
- "animate-pulse": isLoading
11025
- }
11026
- ),
10689
+ className: "flex flex-1 flex-col overflow-hidden",
10690
+ onSubmit,
11027
10691
  children: [
11028
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11029
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11030
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11031
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11032
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11033
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11034
- ] }),
11035
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11036
- ] })
11037
- ] }),
11038
- /* @__PURE__ */ jsxRuntime.jsx(
11039
- ui.IconButton,
11040
- {
11041
- size: "small",
11042
- type: "button",
11043
- variant: "transparent",
11044
- onClick: onRemove,
11045
- isLoading: isPending || isLoading,
11046
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11047
- }
11048
- )
11049
- ]
11050
- },
11051
- promotion.id
11052
- );
11053
- };
11054
- function getDisplayValue(promotion) {
11055
- var _a, _b, _c, _d;
11056
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11057
- if (!value) {
11058
- return null;
11059
- }
11060
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11061
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11062
- if (!currency) {
11063
- return null;
11064
- }
11065
- return getLocaleAmount(value, currency);
11066
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11067
- return formatPercentage(value);
11068
- }
11069
- return null;
11070
- }
11071
- const formatter = new Intl.NumberFormat([], {
11072
- style: "percent",
11073
- minimumFractionDigits: 2
11074
- });
11075
- const formatPercentage = (value, isPercentageValue = false) => {
11076
- let val = value || 0;
11077
- if (!isPercentageValue) {
11078
- val = val / 100;
11079
- }
11080
- return formatter.format(val);
11081
- };
11082
- function getPromotionIds(items, shippingMethods) {
11083
- const promotionIds = /* @__PURE__ */ new Set();
11084
- for (const item of items) {
11085
- if (item.adjustments) {
11086
- for (const adjustment of item.adjustments) {
11087
- if (adjustment.promotion_id) {
11088
- promotionIds.add(adjustment.promotion_id);
11089
- }
11090
- }
11091
- }
11092
- }
11093
- for (const shippingMethod of shippingMethods) {
11094
- if (shippingMethod.adjustments) {
11095
- for (const adjustment of shippingMethod.adjustments) {
11096
- if (adjustment.promotion_id) {
11097
- promotionIds.add(adjustment.promotion_id);
11098
- }
11099
- }
11100
- }
11101
- }
11102
- return Array.from(promotionIds);
11103
- }
11104
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11105
- const Shipping = () => {
11106
- var _a;
11107
- const { id } = reactRouterDom.useParams();
11108
- const { order, isPending, isError, error } = useOrder(id, {
11109
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11110
- });
11111
- const {
11112
- order: preview,
11113
- isPending: isPreviewPending,
11114
- isError: isPreviewError,
11115
- error: previewError
11116
- } = useOrderPreview(id);
11117
- useInitiateOrderEdit({ preview });
11118
- const { onCancel } = useCancelOrderEdit({ preview });
11119
- if (isError) {
11120
- throw error;
11121
- }
11122
- if (isPreviewError) {
11123
- throw previewError;
11124
- }
11125
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11126
- const isReady = preview && !isPreviewPending && order && !isPending;
11127
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11128
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11129
- /* @__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: [
11130
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11131
- /* @__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." }) })
11132
- ] }) }) }),
11133
- /* @__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" }) }) })
11134
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11135
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11136
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11137
- ] }) });
11138
- };
11139
- const ShippingForm = ({ preview, order }) => {
11140
- var _a;
11141
- const { setIsOpen } = useStackedModal();
11142
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11143
- const [data, setData] = React.useState(null);
11144
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11145
- const { shipping_options } = useShippingOptions(
11146
- {
11147
- id: appliedShippingOptionIds,
11148
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11149
- },
11150
- {
11151
- enabled: appliedShippingOptionIds.length > 0
11152
- }
11153
- );
11154
- const uniqueShippingProfiles = React.useMemo(() => {
11155
- const profiles = /* @__PURE__ */ new Map();
11156
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11157
- profiles.set(profile.id, profile);
11158
- });
11159
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11160
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11161
- });
11162
- return Array.from(profiles.values());
11163
- }, [order.items, shipping_options]);
11164
- const { handleSuccess } = useRouteModal();
11165
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11166
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11167
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11168
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11169
- const onSubmit = async () => {
11170
- setIsSubmitting(true);
11171
- let requestSucceeded = false;
11172
- await requestOrderEdit(void 0, {
11173
- onError: (e) => {
11174
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11175
- },
11176
- onSuccess: () => {
11177
- requestSucceeded = true;
11178
- }
11179
- });
11180
- if (!requestSucceeded) {
11181
- setIsSubmitting(false);
11182
- return;
11183
- }
11184
- await confirmOrderEdit(void 0, {
11185
- onError: (e) => {
11186
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11187
- },
11188
- onSuccess: () => {
11189
- handleSuccess();
11190
- },
11191
- onSettled: () => {
11192
- setIsSubmitting(false);
11193
- }
11194
- });
11195
- };
11196
- const onKeydown = React.useCallback(
11197
- (e) => {
11198
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11199
- if (data || isSubmitting) {
11200
- return;
11201
- }
11202
- onSubmit();
11203
- }
11204
- },
11205
- [data, isSubmitting, onSubmit]
11206
- );
11207
- React.useEffect(() => {
11208
- document.addEventListener("keydown", onKeydown);
11209
- return () => {
11210
- document.removeEventListener("keydown", onKeydown);
11211
- };
11212
- }, [onKeydown]);
11213
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11214
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11215
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11216
- /* @__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: [
11217
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11218
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11219
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11220
- ] }),
11221
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11222
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11223
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
10692
+ /* @__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: [
10693
+ /* @__PURE__ */ jsxRuntime.jsx(
10694
+ Form$2.Field,
10695
+ {
10696
+ control: form.control,
10697
+ name: "country_code",
10698
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
10700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
10701
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10702
+ ] })
10703
+ }
10704
+ ),
10705
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11224
10706
  /* @__PURE__ */ jsxRuntime.jsx(
11225
- ui.Text,
10707
+ Form$2.Field,
11226
10708
  {
11227
- size: "xsmall",
11228
- weight: "plus",
11229
- className: "text-ui-fg-muted",
11230
- children: "Shipping profile"
10709
+ control: form.control,
10710
+ name: "first_name",
10711
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
10713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10714
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10715
+ ] })
11231
10716
  }
11232
10717
  ),
11233
10718
  /* @__PURE__ */ jsxRuntime.jsx(
11234
- ui.Text,
10719
+ Form$2.Field,
11235
10720
  {
11236
- size: "xsmall",
11237
- weight: "plus",
11238
- className: "text-ui-fg-muted",
11239
- children: "Action"
10721
+ control: form.control,
10722
+ name: "last_name",
10723
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
10725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10726
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10727
+ ] })
11240
10728
  }
11241
10729
  )
11242
10730
  ] }),
11243
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11244
- var _a2, _b, _c, _d, _e, _f, _g;
11245
- const items = getItemsWithShippingProfile(
11246
- profile.id,
11247
- order.items
11248
- );
11249
- const hasItems = items.length > 0;
11250
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11251
- (option) => option.shipping_profile_id === profile.id
11252
- );
11253
- const shippingMethod = preview.shipping_methods.find(
11254
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11255
- );
11256
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11257
- (action) => action.action === "SHIPPING_ADD"
11258
- );
11259
- return /* @__PURE__ */ jsxRuntime.jsxs(
11260
- radixUi.Accordion.Item,
10731
+ /* @__PURE__ */ jsxRuntime.jsx(
10732
+ Form$2.Field,
10733
+ {
10734
+ control: form.control,
10735
+ name: "company",
10736
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
10738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10739
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10740
+ ] })
10741
+ }
10742
+ ),
10743
+ /* @__PURE__ */ jsxRuntime.jsx(
10744
+ Form$2.Field,
10745
+ {
10746
+ control: form.control,
10747
+ name: "address_1",
10748
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
10750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10751
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10752
+ ] })
10753
+ }
10754
+ ),
10755
+ /* @__PURE__ */ jsxRuntime.jsx(
10756
+ Form$2.Field,
10757
+ {
10758
+ control: form.control,
10759
+ name: "address_2",
10760
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10761
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
10762
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10763
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10764
+ ] })
10765
+ }
10766
+ ),
10767
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
10768
+ /* @__PURE__ */ jsxRuntime.jsx(
10769
+ Form$2.Field,
11261
10770
  {
11262
- value: profile.id,
11263
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11264
- children: [
11265
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11266
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11267
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11268
- ui.IconButton,
11269
- {
11270
- size: "2xsmall",
11271
- variant: "transparent",
11272
- className: "group/trigger",
11273
- disabled: !hasItems,
11274
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11275
- }
11276
- ) }),
11277
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11278
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11279
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11280
- /* @__PURE__ */ jsxRuntime.jsx(
11281
- ui.Text,
11282
- {
11283
- size: "small",
11284
- weight: "plus",
11285
- leading: "compact",
11286
- children: profile.name
11287
- }
11288
- ),
11289
- /* @__PURE__ */ jsxRuntime.jsxs(
11290
- ui.Text,
11291
- {
11292
- size: "small",
11293
- leading: "compact",
11294
- className: "text-ui-fg-subtle",
11295
- children: [
11296
- items.length,
11297
- " ",
11298
- pluralize(items.length, "items", "item")
11299
- ]
11300
- }
11301
- )
11302
- ] })
11303
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11304
- /* @__PURE__ */ jsxRuntime.jsx(
11305
- ui.Tooltip,
11306
- {
11307
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11308
- var _a3, _b2, _c2;
11309
- return /* @__PURE__ */ jsxRuntime.jsx(
11310
- "li",
11311
- {
11312
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11313
- },
11314
- item.id
11315
- );
11316
- }) }),
11317
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11318
- ui.Badge,
11319
- {
11320
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11321
- size: "xsmall",
11322
- children: [
11323
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11324
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11325
- items.reduce(
11326
- (acc, item) => acc + item.quantity,
11327
- 0
11328
- ),
11329
- "x",
11330
- " ",
11331
- pluralize(items.length, "items", "item")
11332
- ] })
11333
- ]
11334
- }
11335
- )
11336
- }
11337
- ),
11338
- /* @__PURE__ */ jsxRuntime.jsx(
11339
- ui.Tooltip,
11340
- {
11341
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11342
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11343
- ui.Badge,
11344
- {
11345
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11346
- size: "xsmall",
11347
- children: [
11348
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11349
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11350
- ]
11351
- }
11352
- )
11353
- }
11354
- ),
11355
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11356
- ui.Badge,
11357
- {
11358
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11359
- size: "xsmall",
11360
- children: [
11361
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11362
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11363
- ]
11364
- }
11365
- ) })
11366
- ] })
11367
- ] }),
11368
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11369
- ActionMenu,
11370
- {
11371
- groups: [
11372
- {
11373
- actions: [
11374
- hasItems ? {
11375
- label: "Edit shipping option",
11376
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11377
- onClick: () => {
11378
- setIsOpen(
11379
- STACKED_FOCUS_MODAL_ID,
11380
- true
11381
- );
11382
- setData({
11383
- shippingProfileId: profile.id,
11384
- shippingOption,
11385
- shippingMethod
11386
- });
11387
- }
11388
- } : void 0,
11389
- {
11390
- label: "Remove shipping option",
11391
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11392
- onClick: () => {
11393
- if (shippingMethod) {
11394
- if (addShippingMethodAction) {
11395
- removeActionShippingMethod(
11396
- addShippingMethodAction.id
11397
- );
11398
- } else {
11399
- removeShippingMethod(
11400
- shippingMethod.id
11401
- );
11402
- }
11403
- }
11404
- }
11405
- }
11406
- ].filter(Boolean)
11407
- }
11408
- ]
11409
- }
11410
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11411
- StackedModalTrigger,
11412
- {
11413
- shippingProfileId: profile.id,
11414
- shippingOption,
11415
- shippingMethod,
11416
- setData,
11417
- children: "Add shipping option"
11418
- }
11419
- )
11420
- ] }),
11421
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11422
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11423
- items.map((item, idx) => {
11424
- var _a3, _b2, _c2, _d2, _e2;
11425
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11426
- /* @__PURE__ */ jsxRuntime.jsxs(
11427
- "div",
11428
- {
11429
- className: "px-3 flex items-center gap-x-3",
11430
- children: [
11431
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11432
- ui.Divider,
11433
- {
11434
- variant: "dashed",
11435
- orientation: "vertical"
11436
- }
11437
- ) }),
11438
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11439
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11440
- ui.Text,
11441
- {
11442
- size: "small",
11443
- leading: "compact",
11444
- className: "text-ui-fg-subtle",
11445
- children: [
11446
- item.quantity,
11447
- "x"
11448
- ]
11449
- }
11450
- ) }),
11451
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11452
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11453
- /* @__PURE__ */ jsxRuntime.jsxs(
11454
- ui.Text,
11455
- {
11456
- size: "small",
11457
- leading: "compact",
11458
- weight: "plus",
11459
- children: [
11460
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11461
- " (",
11462
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11463
- ")"
11464
- ]
11465
- }
11466
- ),
11467
- /* @__PURE__ */ jsxRuntime.jsx(
11468
- ui.Text,
11469
- {
11470
- size: "small",
11471
- leading: "compact",
11472
- className: "text-ui-fg-subtle",
11473
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11474
- }
11475
- )
11476
- ] })
11477
- ] })
11478
- ]
11479
- },
11480
- item.id
11481
- ),
11482
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11483
- ] }, item.id);
11484
- })
11485
- ] })
11486
- ]
11487
- },
11488
- profile.id
11489
- );
11490
- }) })
11491
- ] }) })
11492
- ] }) }),
11493
- /* @__PURE__ */ jsxRuntime.jsx(
11494
- StackedFocusModal,
11495
- {
11496
- id: STACKED_FOCUS_MODAL_ID,
11497
- onOpenChangeCallback: (open) => {
11498
- if (!open) {
11499
- setData(null);
10771
+ control: form.control,
10772
+ name: "postal_code",
10773
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10774
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
10775
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10776
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10777
+ ] })
10778
+ }
10779
+ ),
10780
+ /* @__PURE__ */ jsxRuntime.jsx(
10781
+ Form$2.Field,
10782
+ {
10783
+ control: form.control,
10784
+ name: "city",
10785
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10786
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
10787
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10788
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10789
+ ] })
10790
+ }
10791
+ )
10792
+ ] }),
10793
+ /* @__PURE__ */ jsxRuntime.jsx(
10794
+ Form$2.Field,
10795
+ {
10796
+ control: form.control,
10797
+ name: "province",
10798
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10799
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
10800
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10801
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10802
+ ] })
11500
10803
  }
11501
- return open;
11502
- },
11503
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11504
- }
11505
- )
11506
- ] }),
11507
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11508
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11509
- /* @__PURE__ */ jsxRuntime.jsx(
11510
- ui.Button,
11511
- {
11512
- size: "small",
11513
- type: "button",
11514
- isLoading: isSubmitting,
11515
- onClick: onSubmit,
11516
- children: "Save"
11517
- }
11518
- )
11519
- ] }) })
11520
- ] });
10804
+ ),
10805
+ /* @__PURE__ */ jsxRuntime.jsx(
10806
+ Form$2.Field,
10807
+ {
10808
+ control: form.control,
10809
+ name: "phone",
10810
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10811
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
10812
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10813
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10814
+ ] })
10815
+ }
10816
+ )
10817
+ ] }) }),
10818
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10819
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10820
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10821
+ ] }) })
10822
+ ]
10823
+ }
10824
+ ) });
11521
10825
  };
11522
- const StackedModalTrigger = ({
11523
- shippingProfileId,
11524
- shippingOption,
11525
- shippingMethod,
11526
- setData,
11527
- children
11528
- }) => {
11529
- const { setIsOpen, getIsOpen } = useStackedModal();
11530
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11531
- const onToggle = () => {
11532
- if (isOpen) {
11533
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11534
- setData(null);
11535
- } else {
11536
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11537
- setData({
11538
- shippingProfileId,
11539
- shippingOption,
11540
- shippingMethod
11541
- });
11542
- }
11543
- };
11544
- return /* @__PURE__ */ jsxRuntime.jsx(
11545
- ui.Button,
11546
- {
11547
- size: "small",
11548
- variant: "secondary",
11549
- onClick: onToggle,
11550
- className: "text-ui-fg-primary shrink-0",
11551
- children
11552
- }
11553
- );
10826
+ const schema$3 = addressSchema;
10827
+ const InlineTip = React.forwardRef(
10828
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10829
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10830
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10831
+ "div",
10832
+ {
10833
+ ref,
10834
+ className: ui.clx(
10835
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10836
+ className
10837
+ ),
10838
+ ...props,
10839
+ children: [
10840
+ /* @__PURE__ */ jsxRuntime.jsx(
10841
+ "div",
10842
+ {
10843
+ role: "presentation",
10844
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10845
+ "bg-ui-tag-orange-icon": variant === "warning"
10846
+ })
10847
+ }
10848
+ ),
10849
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10850
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10851
+ labelValue,
10852
+ ":"
10853
+ ] }),
10854
+ " ",
10855
+ children
10856
+ ] })
10857
+ ]
10858
+ }
10859
+ );
10860
+ }
10861
+ );
10862
+ InlineTip.displayName = "InlineTip";
10863
+ const MetadataFieldSchema = objectType({
10864
+ key: stringType(),
10865
+ disabled: booleanType().optional(),
10866
+ value: anyType()
10867
+ });
10868
+ const MetadataSchema = objectType({
10869
+ metadata: arrayType(MetadataFieldSchema)
10870
+ });
10871
+ const Metadata = () => {
10872
+ const { id } = reactRouterDom.useParams();
10873
+ const { order, isPending, isError, error } = useOrder(id, {
10874
+ fields: "metadata"
10875
+ });
10876
+ if (isError) {
10877
+ throw error;
10878
+ }
10879
+ const isReady = !isPending && !!order;
10880
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10881
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10882
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10883
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10884
+ ] }),
10885
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10886
+ ] });
11554
10887
  };
11555
- const ShippingProfileForm = ({
11556
- data,
11557
- order,
11558
- preview
11559
- }) => {
11560
- var _a, _b, _c, _d, _e, _f;
11561
- const { setIsOpen } = useStackedModal();
10888
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10889
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10890
+ const MetadataForm = ({ orderId, metadata }) => {
10891
+ const { handleSuccess } = useRouteModal();
10892
+ const hasUneditableRows = getHasUneditableRows(metadata);
10893
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11562
10894
  const form = reactHookForm.useForm({
11563
- resolver: zod.zodResolver(shippingMethodSchema),
11564
10895
  defaultValues: {
11565
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
11566
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11567
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11568
- }
10896
+ metadata: getDefaultValues(metadata)
10897
+ },
10898
+ resolver: zod.zodResolver(MetadataSchema)
11569
10899
  });
11570
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11571
- const {
11572
- mutateAsync: updateShippingMethod,
11573
- isPending: isUpdatingShippingMethod
11574
- } = useDraftOrderUpdateShippingMethod(order.id);
11575
- const onSubmit = form.handleSubmit(async (values) => {
11576
- if (lodash.isEqual(values, form.formState.defaultValues)) {
11577
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11578
- return;
11579
- }
11580
- if (data.shippingMethod) {
11581
- await updateShippingMethod(
11582
- {
11583
- method_id: data.shippingMethod.id,
11584
- shipping_option_id: values.shipping_option_id,
11585
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11586
- },
11587
- {
11588
- onError: (e) => {
11589
- ui.toast.error(e.message);
11590
- },
11591
- onSuccess: () => {
11592
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11593
- }
11594
- }
11595
- );
11596
- return;
11597
- }
11598
- await addShippingMethod(
10900
+ const handleSubmit = form.handleSubmit(async (data) => {
10901
+ const parsedData = parseValues(data);
10902
+ await mutateAsync(
11599
10903
  {
11600
- shipping_option_id: values.shipping_option_id,
11601
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
10904
+ metadata: parsedData
11602
10905
  },
11603
10906
  {
11604
- onError: (e) => {
11605
- ui.toast.error(e.message);
11606
- },
11607
10907
  onSuccess: () => {
11608
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
10908
+ ui.toast.success("Metadata updated");
10909
+ handleSuccess();
10910
+ },
10911
+ onError: (error) => {
10912
+ ui.toast.error(error.message);
11609
10913
  }
11610
10914
  }
11611
10915
  );
11612
10916
  });
11613
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10917
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10918
+ control: form.control,
10919
+ name: "metadata"
10920
+ });
10921
+ function deleteRow(index) {
10922
+ remove(index);
10923
+ if (fields.length === 1) {
10924
+ insert(0, {
10925
+ key: "",
10926
+ value: "",
10927
+ disabled: false
10928
+ });
10929
+ }
10930
+ }
10931
+ function insertRow(index, position) {
10932
+ insert(index + (position === "above" ? 0 : 1), {
10933
+ key: "",
10934
+ value: "",
10935
+ disabled: false
10936
+ });
10937
+ }
10938
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11614
10939
  KeyboundForm,
11615
10940
  {
11616
- className: "flex h-full flex-col overflow-hidden",
11617
- onSubmit,
10941
+ onSubmit: handleSubmit,
10942
+ className: "flex flex-1 flex-col overflow-hidden",
11618
10943
  children: [
11619
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11620
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11621
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11622
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11623
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11624
- ] }),
11625
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11626
- /* @__PURE__ */ jsxRuntime.jsx(
11627
- LocationField,
11628
- {
11629
- control: form.control,
11630
- setValue: form.setValue
11631
- }
11632
- ),
11633
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11634
- /* @__PURE__ */ jsxRuntime.jsx(
11635
- ShippingOptionField,
11636
- {
11637
- shippingProfileId: data.shippingProfileId,
11638
- preview,
11639
- control: form.control
11640
- }
11641
- ),
11642
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11643
- /* @__PURE__ */ jsxRuntime.jsx(
11644
- CustomAmountField,
11645
- {
11646
- control: form.control,
11647
- currencyCode: order.currency_code
11648
- }
11649
- ),
11650
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11651
- /* @__PURE__ */ jsxRuntime.jsx(
11652
- ItemsPreview,
11653
- {
11654
- order,
11655
- shippingProfileId: data.shippingProfileId
11656
- }
11657
- )
11658
- ] }) }) }),
11659
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11660
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11661
- /* @__PURE__ */ jsxRuntime.jsx(
11662
- ui.Button,
11663
- {
11664
- size: "small",
11665
- type: "submit",
11666
- isLoading: isPending || isUpdatingShippingMethod,
11667
- children: data.shippingMethod ? "Update" : "Add"
11668
- }
11669
- )
11670
- ] }) })
11671
- ]
11672
- }
11673
- ) }) });
11674
- };
11675
- const shippingMethodSchema = objectType({
11676
- location_id: stringType(),
11677
- shipping_option_id: stringType(),
11678
- custom_amount: unionType([numberType(), stringType()]).optional()
11679
- });
11680
- const ItemsPreview = ({ order, shippingProfileId }) => {
11681
- const matches = order.items.filter(
11682
- (item) => {
11683
- var _a, _b, _c;
11684
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11685
- }
11686
- );
11687
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11688
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11689
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11690
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11691
- ] }) }),
11692
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11693
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11694
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11695
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11696
- ] }),
11697
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
11698
- "div",
11699
- {
11700
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11701
- children: [
11702
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11703
- /* @__PURE__ */ jsxRuntime.jsx(
11704
- Thumbnail,
11705
- {
11706
- thumbnail: item.thumbnail,
11707
- alt: item.product_title ?? void 0
11708
- }
11709
- ),
11710
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11711
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11712
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11713
- /* @__PURE__ */ jsxRuntime.jsxs(
11714
- ui.Text,
11715
- {
11716
- size: "small",
11717
- leading: "compact",
11718
- className: "text-ui-fg-subtle",
11719
- children: [
11720
- "(",
11721
- item.variant_title,
11722
- ")"
11723
- ]
11724
- }
11725
- )
11726
- ] }),
11727
- /* @__PURE__ */ jsxRuntime.jsx(
11728
- ui.Text,
11729
- {
11730
- size: "small",
11731
- leading: "compact",
11732
- className: "text-ui-fg-subtle",
11733
- children: item.variant_sku
11734
- }
11735
- )
11736
- ] })
10944
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10945
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10946
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10947
+ /* @__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" }) }),
10948
+ /* @__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" }) })
11737
10949
  ] }),
11738
- /* @__PURE__ */ jsxRuntime.jsxs(
11739
- ui.Text,
11740
- {
11741
- size: "small",
11742
- leading: "compact",
11743
- className: "text-ui-fg-subtle",
11744
- children: [
11745
- item.quantity,
11746
- "x"
11747
- ]
10950
+ fields.map((field, index) => {
10951
+ const isDisabled = field.disabled || false;
10952
+ let placeholder = "-";
10953
+ if (typeof field.value === "object") {
10954
+ placeholder = "{ ... }";
11748
10955
  }
11749
- )
11750
- ]
11751
- },
11752
- item.id
11753
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
11754
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
11755
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
11756
- 'No items found for "',
11757
- query,
11758
- '".'
11759
- ] })
11760
- ] }) })
11761
- ] })
11762
- ] });
11763
- };
11764
- const LocationField = ({ control, setValue }) => {
11765
- const locations = useComboboxData({
11766
- queryKey: ["locations"],
11767
- queryFn: async (params) => {
11768
- return await sdk.admin.stockLocation.list(params);
11769
- },
11770
- getOptions: (data) => {
11771
- return data.stock_locations.map((location) => ({
11772
- label: location.name,
11773
- value: location.id
11774
- }));
10956
+ if (Array.isArray(field.value)) {
10957
+ placeholder = "[ ... ]";
10958
+ }
10959
+ return /* @__PURE__ */ jsxRuntime.jsx(
10960
+ ConditionalTooltip,
10961
+ {
10962
+ showTooltip: isDisabled,
10963
+ content: "This row is disabled because it contains non-primitive data.",
10964
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10965
+ /* @__PURE__ */ jsxRuntime.jsxs(
10966
+ "div",
10967
+ {
10968
+ className: ui.clx("grid grid-cols-2 divide-x", {
10969
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10970
+ }),
10971
+ children: [
10972
+ /* @__PURE__ */ jsxRuntime.jsx(
10973
+ Form$2.Field,
10974
+ {
10975
+ control: form.control,
10976
+ name: `metadata.${index}.key`,
10977
+ render: ({ field: field2 }) => {
10978
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10979
+ GridInput,
10980
+ {
10981
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10982
+ ...field2,
10983
+ disabled: isDisabled,
10984
+ placeholder: "Key"
10985
+ }
10986
+ ) }) });
10987
+ }
10988
+ }
10989
+ ),
10990
+ /* @__PURE__ */ jsxRuntime.jsx(
10991
+ Form$2.Field,
10992
+ {
10993
+ control: form.control,
10994
+ name: `metadata.${index}.value`,
10995
+ render: ({ field: { value, ...field2 } }) => {
10996
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10997
+ GridInput,
10998
+ {
10999
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11000
+ ...field2,
11001
+ value: isDisabled ? placeholder : value,
11002
+ disabled: isDisabled,
11003
+ placeholder: "Value"
11004
+ }
11005
+ ) }) });
11006
+ }
11007
+ }
11008
+ )
11009
+ ]
11010
+ }
11011
+ ),
11012
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11013
+ /* @__PURE__ */ jsxRuntime.jsx(
11014
+ ui.DropdownMenu.Trigger,
11015
+ {
11016
+ className: ui.clx(
11017
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11018
+ {
11019
+ hidden: isDisabled
11020
+ }
11021
+ ),
11022
+ disabled: isDisabled,
11023
+ asChild: true,
11024
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11025
+ }
11026
+ ),
11027
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11028
+ /* @__PURE__ */ jsxRuntime.jsxs(
11029
+ ui.DropdownMenu.Item,
11030
+ {
11031
+ className: "gap-x-2",
11032
+ onClick: () => insertRow(index, "above"),
11033
+ children: [
11034
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11035
+ "Insert row above"
11036
+ ]
11037
+ }
11038
+ ),
11039
+ /* @__PURE__ */ jsxRuntime.jsxs(
11040
+ ui.DropdownMenu.Item,
11041
+ {
11042
+ className: "gap-x-2",
11043
+ onClick: () => insertRow(index, "below"),
11044
+ children: [
11045
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11046
+ "Insert row below"
11047
+ ]
11048
+ }
11049
+ ),
11050
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11051
+ /* @__PURE__ */ jsxRuntime.jsxs(
11052
+ ui.DropdownMenu.Item,
11053
+ {
11054
+ className: "gap-x-2",
11055
+ onClick: () => deleteRow(index),
11056
+ children: [
11057
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11058
+ "Delete row"
11059
+ ]
11060
+ }
11061
+ )
11062
+ ] })
11063
+ ] })
11064
+ ] })
11065
+ },
11066
+ field.id
11067
+ );
11068
+ })
11069
+ ] }),
11070
+ 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." })
11071
+ ] }),
11072
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11074
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11075
+ ] }) })
11076
+ ]
11775
11077
  }
11776
- });
11078
+ ) });
11079
+ };
11080
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11777
11081
  return /* @__PURE__ */ jsxRuntime.jsx(
11778
- Form$2.Field,
11082
+ "input",
11779
11083
  {
11780
- control,
11781
- name: "location_id",
11782
- render: ({ field: { onChange, ...field } }) => {
11783
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11784
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11785
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
11786
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11787
- ] }),
11788
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11789
- Combobox,
11790
- {
11791
- options: locations.options,
11792
- fetchNextPage: locations.fetchNextPage,
11793
- isFetchingNextPage: locations.isFetchingNextPage,
11794
- searchValue: locations.searchValue,
11795
- onSearchValueChange: locations.onSearchValueChange,
11796
- placeholder: "Select location",
11797
- onChange: (value) => {
11798
- setValue("shipping_option_id", "", {
11799
- shouldDirty: true,
11800
- shouldTouch: true
11801
- });
11802
- onChange(value);
11803
- },
11804
- ...field
11805
- }
11806
- ) })
11807
- ] }) });
11808
- }
11084
+ ref,
11085
+ ...props,
11086
+ autoComplete: "off",
11087
+ className: ui.clx(
11088
+ "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",
11089
+ className
11090
+ )
11809
11091
  }
11810
11092
  );
11811
- };
11812
- const ShippingOptionField = ({
11813
- shippingProfileId,
11814
- preview,
11815
- control
11816
- }) => {
11817
- var _a;
11818
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
11819
- const shippingOptions = useComboboxData({
11820
- queryKey: ["shipping_options", locationId, shippingProfileId],
11821
- queryFn: async (params) => {
11822
- return await sdk.admin.shippingOption.list({
11823
- ...params,
11824
- stock_location_id: locationId,
11825
- shipping_profile_id: shippingProfileId
11826
- });
11827
- },
11828
- getOptions: (data) => {
11829
- return data.shipping_options.map((option) => {
11830
- var _a2;
11831
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
11832
- (r) => r.attribute === "is_return" && r.value === "true"
11833
- )) {
11834
- return void 0;
11835
- }
11836
- return {
11837
- label: option.name,
11838
- value: option.id
11839
- };
11840
- }).filter(Boolean);
11841
- },
11842
- enabled: !!locationId && !!shippingProfileId,
11843
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11844
- });
11845
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
11846
- return /* @__PURE__ */ jsxRuntime.jsx(
11847
- Form$2.Field,
11848
- {
11849
- control,
11850
- name: "shipping_option_id",
11851
- render: ({ field }) => {
11852
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11853
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11854
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
11855
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11856
- ] }),
11857
- /* @__PURE__ */ jsxRuntime.jsx(
11858
- ConditionalTooltip,
11859
- {
11860
- content: tooltipContent,
11861
- showTooltip: !locationId || !shippingProfileId,
11862
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11863
- Combobox,
11864
- {
11865
- options: shippingOptions.options,
11866
- fetchNextPage: shippingOptions.fetchNextPage,
11867
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
11868
- searchValue: shippingOptions.searchValue,
11869
- onSearchValueChange: shippingOptions.onSearchValueChange,
11870
- placeholder: "Select shipping option",
11871
- ...field,
11872
- disabled: !locationId || !shippingProfileId
11873
- }
11874
- ) }) })
11875
- }
11876
- )
11877
- ] }) });
11093
+ });
11094
+ GridInput.displayName = "MetadataForm.GridInput";
11095
+ const PlaceholderInner = () => {
11096
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11097
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11099
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11101
+ ] }) })
11102
+ ] });
11103
+ };
11104
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11105
+ function getDefaultValues(metadata) {
11106
+ if (!metadata || !Object.keys(metadata).length) {
11107
+ return [
11108
+ {
11109
+ key: "",
11110
+ value: "",
11111
+ disabled: false
11878
11112
  }
11113
+ ];
11114
+ }
11115
+ return Object.entries(metadata).map(([key, value]) => {
11116
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11117
+ return {
11118
+ key,
11119
+ value,
11120
+ disabled: true
11121
+ };
11879
11122
  }
11880
- );
11881
- };
11882
- const CustomAmountField = ({
11883
- control,
11884
- currencyCode
11885
- }) => {
11886
- return /* @__PURE__ */ jsxRuntime.jsx(
11887
- Form$2.Field,
11888
- {
11889
- control,
11890
- name: "custom_amount",
11891
- render: ({ field: { onChange, ...field } }) => {
11892
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11893
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11894
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
11895
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11896
- ] }),
11897
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11898
- ui.CurrencyInput,
11899
- {
11900
- ...field,
11901
- onValueChange: (value) => onChange(value),
11902
- symbol: getNativeSymbol(currencyCode),
11903
- code: currencyCode
11904
- }
11905
- ) })
11906
- ] });
11123
+ let stringValue = value;
11124
+ if (typeof value !== "string") {
11125
+ stringValue = JSON.stringify(value);
11126
+ }
11127
+ return {
11128
+ key,
11129
+ value: stringValue,
11130
+ original_key: key
11131
+ };
11132
+ });
11133
+ }
11134
+ function parseValues(values) {
11135
+ const metadata = values.metadata;
11136
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11137
+ if (isEmpty) {
11138
+ return null;
11139
+ }
11140
+ const update = {};
11141
+ metadata.forEach((field) => {
11142
+ let key = field.key;
11143
+ let value = field.value;
11144
+ const disabled = field.disabled;
11145
+ if (!key || !value) {
11146
+ return;
11147
+ }
11148
+ if (disabled) {
11149
+ update[key] = value;
11150
+ return;
11151
+ }
11152
+ key = key.trim();
11153
+ value = value.trim();
11154
+ if (value === "true") {
11155
+ update[key] = true;
11156
+ } else if (value === "false") {
11157
+ update[key] = false;
11158
+ } else {
11159
+ const parsedNumber = parseFloat(value);
11160
+ if (!isNaN(parsedNumber)) {
11161
+ update[key] = parsedNumber;
11162
+ } else {
11163
+ update[key] = value;
11907
11164
  }
11908
11165
  }
11166
+ });
11167
+ return update;
11168
+ }
11169
+ function getHasUneditableRows(metadata) {
11170
+ if (!metadata) {
11171
+ return false;
11172
+ }
11173
+ return Object.values(metadata).some(
11174
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11909
11175
  );
11176
+ }
11177
+ const PROMOTION_QUERY_KEY = "promotions";
11178
+ const promotionsQueryKeys = {
11179
+ list: (query2) => [
11180
+ PROMOTION_QUERY_KEY,
11181
+ query2 ? query2 : void 0
11182
+ ],
11183
+ detail: (id, query2) => [
11184
+ PROMOTION_QUERY_KEY,
11185
+ id,
11186
+ query2 ? query2 : void 0
11187
+ ]
11910
11188
  };
11911
- const SalesChannel = () => {
11189
+ const usePromotions = (query2, options) => {
11190
+ const { data, ...rest } = reactQuery.useQuery({
11191
+ queryKey: promotionsQueryKeys.list(query2),
11192
+ queryFn: async () => sdk.admin.promotion.list(query2),
11193
+ ...options
11194
+ });
11195
+ return { ...data, ...rest };
11196
+ };
11197
+ const Promotions = () => {
11912
11198
  const { id } = reactRouterDom.useParams();
11913
- const { draft_order, isPending, isError, error } = useDraftOrder(
11914
- id,
11199
+ const {
11200
+ order: preview,
11201
+ isError: isPreviewError,
11202
+ error: previewError
11203
+ } = useOrderPreview(id, void 0);
11204
+ useInitiateOrderEdit({ preview });
11205
+ const { onCancel } = useCancelOrderEdit({ preview });
11206
+ if (isPreviewError) {
11207
+ throw previewError;
11208
+ }
11209
+ const isReady = !!preview;
11210
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11211
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11212
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11213
+ ] });
11214
+ };
11215
+ const PromotionForm = ({ preview }) => {
11216
+ const { items, shipping_methods } = preview;
11217
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11218
+ const [comboboxValue, setComboboxValue] = React.useState("");
11219
+ const { handleSuccess } = useRouteModal();
11220
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11221
+ const promoIds = getPromotionIds(items, shipping_methods);
11222
+ const { promotions, isPending, isError, error } = usePromotions(
11915
11223
  {
11916
- fields: "+sales_channel_id"
11224
+ id: promoIds
11917
11225
  },
11918
11226
  {
11919
- enabled: !!id
11227
+ enabled: !!promoIds.length
11920
11228
  }
11921
11229
  );
11922
- if (isError) {
11923
- throw error;
11924
- }
11925
- const ISrEADY = !!draft_order && !isPending;
11926
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11927
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11928
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11929
- /* @__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" }) })
11930
- ] }),
11931
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11932
- ] });
11933
- };
11934
- const SalesChannelForm = ({ order }) => {
11935
- const form = reactHookForm.useForm({
11936
- defaultValues: {
11937
- sales_channel_id: order.sales_channel_id || ""
11230
+ const comboboxData = useComboboxData({
11231
+ queryKey: ["promotions", "combobox", promoIds],
11232
+ queryFn: async (params) => {
11233
+ return await sdk.admin.promotion.list({
11234
+ ...params,
11235
+ id: {
11236
+ $nin: promoIds
11237
+ }
11238
+ });
11938
11239
  },
11939
- resolver: zod.zodResolver(schema$2)
11240
+ getOptions: (data) => {
11241
+ return data.promotions.map((promotion) => ({
11242
+ label: promotion.code,
11243
+ value: promotion.code
11244
+ }));
11245
+ }
11940
11246
  });
11941
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11942
- const { handleSuccess } = useRouteModal();
11247
+ const add = async (value) => {
11248
+ if (!value) {
11249
+ return;
11250
+ }
11251
+ addPromotions(
11252
+ {
11253
+ promo_codes: [value]
11254
+ },
11255
+ {
11256
+ onError: (e) => {
11257
+ ui.toast.error(e.message);
11258
+ comboboxData.onSearchValueChange("");
11259
+ setComboboxValue("");
11260
+ },
11261
+ onSuccess: () => {
11262
+ comboboxData.onSearchValueChange("");
11263
+ setComboboxValue("");
11264
+ }
11265
+ }
11266
+ );
11267
+ };
11268
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11269
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11270
+ const onSubmit = async () => {
11271
+ setIsSubmitting(true);
11272
+ let requestSucceeded = false;
11273
+ await requestOrderEdit(void 0, {
11274
+ onError: (e) => {
11275
+ ui.toast.error(e.message);
11276
+ },
11277
+ onSuccess: () => {
11278
+ requestSucceeded = true;
11279
+ }
11280
+ });
11281
+ if (!requestSucceeded) {
11282
+ setIsSubmitting(false);
11283
+ return;
11284
+ }
11285
+ await confirmOrderEdit(void 0, {
11286
+ onError: (e) => {
11287
+ ui.toast.error(e.message);
11288
+ },
11289
+ onSuccess: () => {
11290
+ handleSuccess();
11291
+ },
11292
+ onSettled: () => {
11293
+ setIsSubmitting(false);
11294
+ }
11295
+ });
11296
+ };
11297
+ if (isError) {
11298
+ throw error;
11299
+ }
11300
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11301
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11302
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11303
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11304
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11305
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11306
+ ] }),
11307
+ /* @__PURE__ */ jsxRuntime.jsx(
11308
+ Combobox,
11309
+ {
11310
+ id: "promotion-combobox",
11311
+ "aria-describedby": "promotion-combobox-hint",
11312
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11313
+ fetchNextPage: comboboxData.fetchNextPage,
11314
+ options: comboboxData.options,
11315
+ onSearchValueChange: comboboxData.onSearchValueChange,
11316
+ searchValue: comboboxData.searchValue,
11317
+ disabled: comboboxData.disabled || isAddingPromotions,
11318
+ onChange: add,
11319
+ value: comboboxValue
11320
+ }
11321
+ )
11322
+ ] }),
11323
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11324
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11325
+ PromotionItem,
11326
+ {
11327
+ promotion,
11328
+ orderId: preview.id,
11329
+ isLoading: isPending
11330
+ },
11331
+ promotion.id
11332
+ )) })
11333
+ ] }) }),
11334
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11335
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11336
+ /* @__PURE__ */ jsxRuntime.jsx(
11337
+ ui.Button,
11338
+ {
11339
+ size: "small",
11340
+ type: "submit",
11341
+ isLoading: isSubmitting || isAddingPromotions,
11342
+ children: "Save"
11343
+ }
11344
+ )
11345
+ ] }) })
11346
+ ] });
11347
+ };
11348
+ const PromotionItem = ({
11349
+ promotion,
11350
+ orderId,
11351
+ isLoading
11352
+ }) => {
11353
+ var _a;
11354
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11355
+ const onRemove = async () => {
11356
+ removePromotions(
11357
+ {
11358
+ promo_codes: [promotion.code]
11359
+ },
11360
+ {
11361
+ onError: (e) => {
11362
+ ui.toast.error(e.message);
11363
+ }
11364
+ }
11365
+ );
11366
+ };
11367
+ const displayValue = getDisplayValue(promotion);
11368
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11369
+ "div",
11370
+ {
11371
+ className: ui.clx(
11372
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11373
+ {
11374
+ "animate-pulse": isLoading
11375
+ }
11376
+ ),
11377
+ children: [
11378
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11379
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11380
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11381
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11382
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11383
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11384
+ ] }),
11385
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11386
+ ] })
11387
+ ] }),
11388
+ /* @__PURE__ */ jsxRuntime.jsx(
11389
+ ui.IconButton,
11390
+ {
11391
+ size: "small",
11392
+ type: "button",
11393
+ variant: "transparent",
11394
+ onClick: onRemove,
11395
+ isLoading: isPending || isLoading,
11396
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11397
+ }
11398
+ )
11399
+ ]
11400
+ },
11401
+ promotion.id
11402
+ );
11403
+ };
11404
+ function getDisplayValue(promotion) {
11405
+ var _a, _b, _c, _d;
11406
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11407
+ if (!value) {
11408
+ return null;
11409
+ }
11410
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11411
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11412
+ if (!currency) {
11413
+ return null;
11414
+ }
11415
+ return getLocaleAmount(value, currency);
11416
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11417
+ return formatPercentage(value);
11418
+ }
11419
+ return null;
11420
+ }
11421
+ const formatter = new Intl.NumberFormat([], {
11422
+ style: "percent",
11423
+ minimumFractionDigits: 2
11424
+ });
11425
+ const formatPercentage = (value, isPercentageValue = false) => {
11426
+ let val = value || 0;
11427
+ if (!isPercentageValue) {
11428
+ val = val / 100;
11429
+ }
11430
+ return formatter.format(val);
11431
+ };
11432
+ function getPromotionIds(items, shippingMethods) {
11433
+ const promotionIds = /* @__PURE__ */ new Set();
11434
+ for (const item of items) {
11435
+ if (item.adjustments) {
11436
+ for (const adjustment of item.adjustments) {
11437
+ if (adjustment.promotion_id) {
11438
+ promotionIds.add(adjustment.promotion_id);
11439
+ }
11440
+ }
11441
+ }
11442
+ }
11443
+ for (const shippingMethod of shippingMethods) {
11444
+ if (shippingMethod.adjustments) {
11445
+ for (const adjustment of shippingMethod.adjustments) {
11446
+ if (adjustment.promotion_id) {
11447
+ promotionIds.add(adjustment.promotion_id);
11448
+ }
11449
+ }
11450
+ }
11451
+ }
11452
+ return Array.from(promotionIds);
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
+ );
11465
+ if (isError) {
11466
+ throw error;
11467
+ }
11468
+ const ISrEADY = !!draft_order && !isPending;
11469
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11470
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
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" }) })
11473
+ ] }),
11474
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11475
+ ] });
11476
+ };
11477
+ const SalesChannelForm = ({ order }) => {
11478
+ const form = reactHookForm.useForm({
11479
+ defaultValues: {
11480
+ sales_channel_id: order.sales_channel_id || ""
11481
+ },
11482
+ resolver: zod.zodResolver(schema$2)
11483
+ });
11484
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11485
+ const { handleSuccess } = useRouteModal();
11943
11486
  const onSubmit = form.handleSubmit(async (data) => {
11944
11487
  await mutateAsync(
11945
11488
  {
@@ -12217,564 +11760,851 @@ const ShippingAddressForm = ({ order }) => {
12217
11760
  ) });
12218
11761
  };
12219
11762
  const schema$1 = addressSchema;
12220
- const TransferOwnership = () => {
11763
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11764
+ const Shipping = () => {
11765
+ var _a;
12221
11766
  const { id } = reactRouterDom.useParams();
12222
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12223
- fields: "id,customer_id,customer.*"
11767
+ const { order, isPending, isError, error } = useOrder(id, {
11768
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12224
11769
  });
11770
+ const {
11771
+ order: preview,
11772
+ isPending: isPreviewPending,
11773
+ isError: isPreviewError,
11774
+ error: previewError
11775
+ } = useOrderPreview(id);
11776
+ useInitiateOrderEdit({ preview });
11777
+ const { onCancel } = useCancelOrderEdit({ preview });
12225
11778
  if (isError) {
12226
11779
  throw error;
12227
11780
  }
12228
- const isReady = !isPending && !!draft_order;
12229
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12230
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12231
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12232
- /* @__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" }) })
12233
- ] }),
12234
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12235
- ] });
11781
+ if (isPreviewError) {
11782
+ throw previewError;
11783
+ }
11784
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11785
+ const isReady = preview && !isPreviewPending && order && !isPending;
11786
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11787
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11788
+ /* @__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: [
11789
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11790
+ /* @__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." }) })
11791
+ ] }) }) }),
11792
+ /* @__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" }) }) })
11793
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11794
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11795
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11796
+ ] }) });
12236
11797
  };
12237
- const TransferOwnershipForm = ({ order }) => {
12238
- var _a, _b;
12239
- const form = reactHookForm.useForm({
12240
- defaultValues: {
12241
- customer_id: order.customer_id || ""
11798
+ const ShippingForm = ({ preview, order }) => {
11799
+ var _a;
11800
+ const { setIsOpen } = useStackedModal();
11801
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11802
+ const [data, setData] = React.useState(null);
11803
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11804
+ const { shipping_options } = useShippingOptions(
11805
+ {
11806
+ id: appliedShippingOptionIds,
11807
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12242
11808
  },
12243
- resolver: zod.zodResolver(schema)
12244
- });
12245
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11809
+ {
11810
+ enabled: appliedShippingOptionIds.length > 0
11811
+ }
11812
+ );
11813
+ const uniqueShippingProfiles = React.useMemo(() => {
11814
+ const profiles = /* @__PURE__ */ new Map();
11815
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
11816
+ profiles.set(profile.id, profile);
11817
+ });
11818
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11819
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
11820
+ });
11821
+ return Array.from(profiles.values());
11822
+ }, [order.items, shipping_options]);
12246
11823
  const { handleSuccess } = useRouteModal();
12247
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12248
- const currentCustomer = order.customer ? {
12249
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12250
- value: order.customer.id
12251
- } : null;
12252
- const onSubmit = form.handleSubmit(async (data) => {
12253
- await mutateAsync(
12254
- { customer_id: data.customer_id },
12255
- {
12256
- onSuccess: () => {
12257
- ui.toast.success("Customer updated");
12258
- handleSuccess();
12259
- },
12260
- onError: (error) => {
12261
- ui.toast.error(error.message);
12262
- }
11824
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11825
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11826
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11827
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11828
+ const onSubmit = async () => {
11829
+ setIsSubmitting(true);
11830
+ let requestSucceeded = false;
11831
+ await requestOrderEdit(void 0, {
11832
+ onError: (e) => {
11833
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
11834
+ },
11835
+ onSuccess: () => {
11836
+ requestSucceeded = true;
12263
11837
  }
12264
- );
12265
- });
12266
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12267
- KeyboundForm,
12268
- {
12269
- className: "flex flex-1 flex-col overflow-hidden",
12270
- onSubmit,
12271
- children: [
12272
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12273
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12274
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12275
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12276
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12277
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12278
- ] }),
12279
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12280
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12281
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12282
- ] })
12283
- ] }),
12284
- /* @__PURE__ */ jsxRuntime.jsx(
12285
- CustomerField,
12286
- {
12287
- control: form.control,
12288
- currentCustomerId: order.customer_id
12289
- }
12290
- )
12291
- ] }),
12292
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12293
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12294
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12295
- ] }) })
12296
- ]
11838
+ });
11839
+ if (!requestSucceeded) {
11840
+ setIsSubmitting(false);
11841
+ return;
12297
11842
  }
12298
- ) });
12299
- };
12300
- const CustomerField = ({ control, currentCustomerId }) => {
12301
- const customers = useComboboxData({
12302
- queryFn: async (params) => {
12303
- return await sdk.admin.customer.list({
12304
- ...params,
12305
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12306
- });
11843
+ await confirmOrderEdit(void 0, {
11844
+ onError: (e) => {
11845
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11846
+ },
11847
+ onSuccess: () => {
11848
+ handleSuccess();
11849
+ },
11850
+ onSettled: () => {
11851
+ setIsSubmitting(false);
11852
+ }
11853
+ });
11854
+ };
11855
+ const onKeydown = React.useCallback(
11856
+ (e) => {
11857
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11858
+ if (data || isSubmitting) {
11859
+ return;
11860
+ }
11861
+ onSubmit();
11862
+ }
12307
11863
  },
12308
- queryKey: ["customers"],
12309
- getOptions: (data) => {
12310
- return data.customers.map((customer) => {
12311
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12312
- return {
12313
- label: name ? `${name} (${customer.email})` : customer.email,
12314
- value: customer.id
12315
- };
12316
- });
12317
- }
12318
- });
12319
- return /* @__PURE__ */ jsxRuntime.jsx(
12320
- Form$2.Field,
12321
- {
12322
- name: "customer_id",
12323
- control,
12324
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12325
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12326
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12327
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12328
- ] }),
12329
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12330
- Combobox,
12331
- {
12332
- options: customers.options,
12333
- fetchNextPage: customers.fetchNextPage,
12334
- isFetchingNextPage: customers.isFetchingNextPage,
12335
- searchValue: customers.searchValue,
12336
- onSearchValueChange: customers.onSearchValueChange,
12337
- placeholder: "Select customer",
12338
- ...field
12339
- }
12340
- ) }),
12341
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12342
- ] })
12343
- }
11864
+ [data, isSubmitting, onSubmit]
12344
11865
  );
12345
- };
12346
- const Illustration = () => {
12347
- return /* @__PURE__ */ jsxRuntime.jsxs(
12348
- "svg",
12349
- {
12350
- width: "280",
12351
- height: "180",
12352
- viewBox: "0 0 280 180",
12353
- fill: "none",
12354
- xmlns: "http://www.w3.org/2000/svg",
12355
- children: [
12356
- /* @__PURE__ */ jsxRuntime.jsx(
12357
- "rect",
12358
- {
12359
- x: "0.00428286",
12360
- y: "-0.742904",
12361
- width: "33.5",
12362
- height: "65.5",
12363
- rx: "6.75",
12364
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12365
- fill: "#D4D4D8",
12366
- stroke: "#52525B",
12367
- strokeWidth: "1.5"
12368
- }
12369
- ),
12370
- /* @__PURE__ */ jsxRuntime.jsx(
12371
- "rect",
12372
- {
12373
- x: "0.00428286",
12374
- y: "-0.742904",
12375
- width: "33.5",
12376
- height: "65.5",
12377
- rx: "6.75",
12378
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12379
- fill: "white",
12380
- stroke: "#52525B",
12381
- strokeWidth: "1.5"
12382
- }
12383
- ),
12384
- /* @__PURE__ */ jsxRuntime.jsx(
12385
- "path",
12386
- {
12387
- d: "M180.579 107.142L179.126 107.959",
12388
- stroke: "#52525B",
12389
- strokeWidth: "1.5",
12390
- strokeLinecap: "round",
12391
- strokeLinejoin: "round"
12392
- }
12393
- ),
12394
- /* @__PURE__ */ jsxRuntime.jsx(
12395
- "path",
12396
- {
12397
- opacity: "0.88",
12398
- d: "M182.305 109.546L180.257 109.534",
12399
- stroke: "#52525B",
12400
- strokeWidth: "1.5",
12401
- strokeLinecap: "round",
12402
- strokeLinejoin: "round"
12403
- }
12404
- ),
12405
- /* @__PURE__ */ jsxRuntime.jsx(
12406
- "path",
12407
- {
12408
- opacity: "0.75",
12409
- d: "M180.551 111.93L179.108 111.096",
12410
- stroke: "#52525B",
12411
- strokeWidth: "1.5",
12412
- strokeLinecap: "round",
12413
- strokeLinejoin: "round"
12414
- }
12415
- ),
12416
- /* @__PURE__ */ jsxRuntime.jsx(
12417
- "path",
12418
- {
12419
- opacity: "0.63",
12420
- d: "M176.347 112.897L176.354 111.73",
12421
- stroke: "#52525B",
12422
- strokeWidth: "1.5",
12423
- strokeLinecap: "round",
12424
- strokeLinejoin: "round"
12425
- }
12426
- ),
12427
- /* @__PURE__ */ jsxRuntime.jsx(
12428
- "path",
12429
- {
12430
- opacity: "0.5",
12431
- d: "M172.153 111.881L173.606 111.064",
12432
- stroke: "#52525B",
12433
- strokeWidth: "1.5",
12434
- strokeLinecap: "round",
12435
- strokeLinejoin: "round"
12436
- }
12437
- ),
12438
- /* @__PURE__ */ jsxRuntime.jsx(
12439
- "path",
12440
- {
12441
- opacity: "0.38",
12442
- d: "M170.428 109.478L172.476 109.489",
12443
- stroke: "#52525B",
12444
- strokeWidth: "1.5",
12445
- strokeLinecap: "round",
12446
- strokeLinejoin: "round"
12447
- }
12448
- ),
12449
- /* @__PURE__ */ jsxRuntime.jsx(
12450
- "path",
12451
- {
12452
- opacity: "0.25",
12453
- d: "M172.181 107.094L173.624 107.928",
12454
- stroke: "#52525B",
12455
- strokeWidth: "1.5",
12456
- strokeLinecap: "round",
12457
- strokeLinejoin: "round"
12458
- }
12459
- ),
12460
- /* @__PURE__ */ jsxRuntime.jsx(
12461
- "path",
12462
- {
12463
- opacity: "0.13",
12464
- d: "M176.386 106.126L176.379 107.294",
12465
- stroke: "#52525B",
12466
- strokeWidth: "1.5",
12467
- strokeLinecap: "round",
12468
- strokeLinejoin: "round"
12469
- }
12470
- ),
12471
- /* @__PURE__ */ jsxRuntime.jsx(
12472
- "rect",
12473
- {
12474
- width: "12",
12475
- height: "3",
12476
- rx: "1.5",
12477
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12478
- fill: "#D4D4D8"
12479
- }
12480
- ),
12481
- /* @__PURE__ */ jsxRuntime.jsx(
12482
- "rect",
12483
- {
12484
- x: "0.00428286",
12485
- y: "-0.742904",
12486
- width: "33.5",
12487
- height: "65.5",
12488
- rx: "6.75",
12489
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12490
- fill: "#D4D4D8",
12491
- stroke: "#52525B",
12492
- strokeWidth: "1.5"
12493
- }
12494
- ),
12495
- /* @__PURE__ */ jsxRuntime.jsx(
12496
- "rect",
12497
- {
12498
- x: "0.00428286",
12499
- y: "-0.742904",
12500
- width: "33.5",
12501
- height: "65.5",
12502
- rx: "6.75",
12503
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12504
- fill: "white",
12505
- stroke: "#52525B",
12506
- strokeWidth: "1.5"
12507
- }
12508
- ),
12509
- /* @__PURE__ */ jsxRuntime.jsx(
12510
- "rect",
12511
- {
12512
- width: "12",
12513
- height: "3",
12514
- rx: "1.5",
12515
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12516
- fill: "#D4D4D8"
12517
- }
12518
- ),
12519
- /* @__PURE__ */ jsxRuntime.jsx(
12520
- "rect",
12521
- {
12522
- width: "17",
12523
- height: "3",
12524
- rx: "1.5",
12525
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12526
- fill: "#D4D4D8"
12527
- }
12528
- ),
12529
- /* @__PURE__ */ jsxRuntime.jsx(
12530
- "rect",
12531
- {
12532
- width: "12",
12533
- height: "3",
12534
- rx: "1.5",
12535
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12536
- fill: "#D4D4D8"
12537
- }
12538
- ),
12539
- /* @__PURE__ */ jsxRuntime.jsx(
12540
- "path",
12541
- {
12542
- 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",
12543
- fill: "#A1A1AA"
12544
- }
12545
- ),
12546
- /* @__PURE__ */ jsxRuntime.jsx(
12547
- "rect",
12548
- {
12549
- width: "17",
12550
- height: "3",
12551
- rx: "1.5",
12552
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12553
- fill: "#A1A1AA"
12554
- }
12555
- ),
12556
- /* @__PURE__ */ jsxRuntime.jsx(
12557
- "rect",
12558
- {
12559
- width: "12",
12560
- height: "3",
12561
- rx: "1.5",
12562
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12563
- fill: "#A1A1AA"
12564
- }
12565
- ),
12566
- /* @__PURE__ */ jsxRuntime.jsx(
12567
- "path",
12568
- {
12569
- 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",
12570
- fill: "#52525B"
12571
- }
12572
- ),
12573
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12574
- "path",
12575
- {
12576
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12577
- stroke: "#A1A1AA",
12578
- strokeWidth: "1.5",
12579
- strokeLinecap: "round",
12580
- strokeLinejoin: "round"
12581
- }
12582
- ) }),
12583
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12584
- "path",
12585
- {
12586
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12587
- stroke: "#A1A1AA",
12588
- strokeWidth: "1.5",
12589
- strokeLinecap: "round",
12590
- strokeLinejoin: "round"
12591
- }
12592
- ) }),
12593
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12594
- "path",
12595
- {
12596
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12597
- stroke: "#A1A1AA",
12598
- strokeWidth: "1.5",
12599
- strokeLinecap: "round",
12600
- strokeLinejoin: "round"
12601
- }
12602
- ) }),
12603
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12604
- "path",
12605
- {
12606
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12607
- stroke: "#A1A1AA",
12608
- strokeWidth: "1.5",
12609
- strokeLinecap: "round",
12610
- strokeLinejoin: "round"
12611
- }
12612
- ) }),
12613
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12614
- "path",
12615
- {
12616
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12617
- stroke: "#A1A1AA",
12618
- strokeWidth: "1.5",
12619
- strokeLinecap: "round",
12620
- strokeLinejoin: "round"
12621
- }
12622
- ) }),
12623
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12624
- "path",
12625
- {
12626
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12627
- stroke: "#A1A1AA",
12628
- strokeWidth: "1.5",
12629
- strokeLinecap: "round",
12630
- strokeLinejoin: "round"
11866
+ React.useEffect(() => {
11867
+ document.addEventListener("keydown", onKeydown);
11868
+ return () => {
11869
+ document.removeEventListener("keydown", onKeydown);
11870
+ };
11871
+ }, [onKeydown]);
11872
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11873
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11874
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11875
+ /* @__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: [
11876
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11877
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11878
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11879
+ ] }),
11880
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11881
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11882
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11883
+ /* @__PURE__ */ jsxRuntime.jsx(
11884
+ ui.Text,
11885
+ {
11886
+ size: "xsmall",
11887
+ weight: "plus",
11888
+ className: "text-ui-fg-muted",
11889
+ children: "Shipping profile"
11890
+ }
11891
+ ),
11892
+ /* @__PURE__ */ jsxRuntime.jsx(
11893
+ ui.Text,
11894
+ {
11895
+ size: "xsmall",
11896
+ weight: "plus",
11897
+ className: "text-ui-fg-muted",
11898
+ children: "Action"
11899
+ }
11900
+ )
11901
+ ] }),
11902
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11903
+ var _a2, _b, _c, _d, _e, _f, _g;
11904
+ const items = getItemsWithShippingProfile(
11905
+ profile.id,
11906
+ order.items
11907
+ );
11908
+ const hasItems = items.length > 0;
11909
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11910
+ (option) => option.shipping_profile_id === profile.id
11911
+ );
11912
+ const shippingMethod = preview.shipping_methods.find(
11913
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11914
+ );
11915
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11916
+ (action) => action.action === "SHIPPING_ADD"
11917
+ );
11918
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11919
+ radixUi.Accordion.Item,
11920
+ {
11921
+ value: profile.id,
11922
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11923
+ children: [
11924
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11925
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11926
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11927
+ ui.IconButton,
11928
+ {
11929
+ size: "2xsmall",
11930
+ variant: "transparent",
11931
+ className: "group/trigger",
11932
+ disabled: !hasItems,
11933
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11934
+ }
11935
+ ) }),
11936
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11937
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11938
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11939
+ /* @__PURE__ */ jsxRuntime.jsx(
11940
+ ui.Text,
11941
+ {
11942
+ size: "small",
11943
+ weight: "plus",
11944
+ leading: "compact",
11945
+ children: profile.name
11946
+ }
11947
+ ),
11948
+ /* @__PURE__ */ jsxRuntime.jsxs(
11949
+ ui.Text,
11950
+ {
11951
+ size: "small",
11952
+ leading: "compact",
11953
+ className: "text-ui-fg-subtle",
11954
+ children: [
11955
+ items.length,
11956
+ " ",
11957
+ pluralize(items.length, "items", "item")
11958
+ ]
11959
+ }
11960
+ )
11961
+ ] })
11962
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11963
+ /* @__PURE__ */ jsxRuntime.jsx(
11964
+ ui.Tooltip,
11965
+ {
11966
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11967
+ var _a3, _b2, _c2;
11968
+ return /* @__PURE__ */ jsxRuntime.jsx(
11969
+ "li",
11970
+ {
11971
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11972
+ },
11973
+ item.id
11974
+ );
11975
+ }) }),
11976
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
11977
+ ui.Badge,
11978
+ {
11979
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11980
+ size: "xsmall",
11981
+ children: [
11982
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11983
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11984
+ items.reduce(
11985
+ (acc, item) => acc + item.quantity,
11986
+ 0
11987
+ ),
11988
+ "x",
11989
+ " ",
11990
+ pluralize(items.length, "items", "item")
11991
+ ] })
11992
+ ]
11993
+ }
11994
+ )
11995
+ }
11996
+ ),
11997
+ /* @__PURE__ */ jsxRuntime.jsx(
11998
+ ui.Tooltip,
11999
+ {
12000
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12001
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12002
+ ui.Badge,
12003
+ {
12004
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12005
+ size: "xsmall",
12006
+ children: [
12007
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12008
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12009
+ ]
12010
+ }
12011
+ )
12012
+ }
12013
+ ),
12014
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12015
+ ui.Badge,
12016
+ {
12017
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12018
+ size: "xsmall",
12019
+ children: [
12020
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12021
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12022
+ ]
12023
+ }
12024
+ ) })
12025
+ ] })
12026
+ ] }),
12027
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12028
+ ActionMenu,
12029
+ {
12030
+ groups: [
12031
+ {
12032
+ actions: [
12033
+ hasItems ? {
12034
+ label: "Edit shipping option",
12035
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12036
+ onClick: () => {
12037
+ setIsOpen(
12038
+ STACKED_FOCUS_MODAL_ID,
12039
+ true
12040
+ );
12041
+ setData({
12042
+ shippingProfileId: profile.id,
12043
+ shippingOption,
12044
+ shippingMethod
12045
+ });
12046
+ }
12047
+ } : void 0,
12048
+ {
12049
+ label: "Remove shipping option",
12050
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12051
+ onClick: () => {
12052
+ if (shippingMethod) {
12053
+ if (addShippingMethodAction) {
12054
+ removeActionShippingMethod(
12055
+ addShippingMethodAction.id
12056
+ );
12057
+ } else {
12058
+ removeShippingMethod(
12059
+ shippingMethod.id
12060
+ );
12061
+ }
12062
+ }
12063
+ }
12064
+ }
12065
+ ].filter(Boolean)
12066
+ }
12067
+ ]
12068
+ }
12069
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12070
+ StackedModalTrigger,
12071
+ {
12072
+ shippingProfileId: profile.id,
12073
+ shippingOption,
12074
+ shippingMethod,
12075
+ setData,
12076
+ children: "Add shipping option"
12077
+ }
12078
+ )
12079
+ ] }),
12080
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12081
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12082
+ items.map((item, idx) => {
12083
+ var _a3, _b2, _c2, _d2, _e2;
12084
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12085
+ /* @__PURE__ */ jsxRuntime.jsxs(
12086
+ "div",
12087
+ {
12088
+ className: "px-3 flex items-center gap-x-3",
12089
+ children: [
12090
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12091
+ ui.Divider,
12092
+ {
12093
+ variant: "dashed",
12094
+ orientation: "vertical"
12095
+ }
12096
+ ) }),
12097
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12098
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12099
+ ui.Text,
12100
+ {
12101
+ size: "small",
12102
+ leading: "compact",
12103
+ className: "text-ui-fg-subtle",
12104
+ children: [
12105
+ item.quantity,
12106
+ "x"
12107
+ ]
12108
+ }
12109
+ ) }),
12110
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12111
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12112
+ /* @__PURE__ */ jsxRuntime.jsxs(
12113
+ ui.Text,
12114
+ {
12115
+ size: "small",
12116
+ leading: "compact",
12117
+ weight: "plus",
12118
+ children: [
12119
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12120
+ " (",
12121
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12122
+ ")"
12123
+ ]
12124
+ }
12125
+ ),
12126
+ /* @__PURE__ */ jsxRuntime.jsx(
12127
+ ui.Text,
12128
+ {
12129
+ size: "small",
12130
+ leading: "compact",
12131
+ className: "text-ui-fg-subtle",
12132
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12133
+ }
12134
+ )
12135
+ ] })
12136
+ ] })
12137
+ ]
12138
+ },
12139
+ item.id
12140
+ ),
12141
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12142
+ ] }, item.id);
12143
+ })
12144
+ ] })
12145
+ ]
12146
+ },
12147
+ profile.id
12148
+ );
12149
+ }) })
12150
+ ] }) })
12151
+ ] }) }),
12152
+ /* @__PURE__ */ jsxRuntime.jsx(
12153
+ StackedFocusModal,
12154
+ {
12155
+ id: STACKED_FOCUS_MODAL_ID,
12156
+ onOpenChangeCallback: (open) => {
12157
+ if (!open) {
12158
+ setData(null);
12159
+ }
12160
+ return open;
12161
+ },
12162
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12163
+ }
12164
+ )
12165
+ ] }),
12166
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12167
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12168
+ /* @__PURE__ */ jsxRuntime.jsx(
12169
+ ui.Button,
12170
+ {
12171
+ size: "small",
12172
+ type: "button",
12173
+ isLoading: isSubmitting,
12174
+ onClick: onSubmit,
12175
+ children: "Save"
12176
+ }
12177
+ )
12178
+ ] }) })
12179
+ ] });
12180
+ };
12181
+ const StackedModalTrigger = ({
12182
+ shippingProfileId,
12183
+ shippingOption,
12184
+ shippingMethod,
12185
+ setData,
12186
+ children
12187
+ }) => {
12188
+ const { setIsOpen, getIsOpen } = useStackedModal();
12189
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12190
+ const onToggle = () => {
12191
+ if (isOpen) {
12192
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12193
+ setData(null);
12194
+ } else {
12195
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12196
+ setData({
12197
+ shippingProfileId,
12198
+ shippingOption,
12199
+ shippingMethod
12200
+ });
12201
+ }
12202
+ };
12203
+ return /* @__PURE__ */ jsxRuntime.jsx(
12204
+ ui.Button,
12205
+ {
12206
+ size: "small",
12207
+ variant: "secondary",
12208
+ onClick: onToggle,
12209
+ className: "text-ui-fg-primary shrink-0",
12210
+ children
12211
+ }
12212
+ );
12213
+ };
12214
+ const ShippingProfileForm = ({
12215
+ data,
12216
+ order,
12217
+ preview
12218
+ }) => {
12219
+ var _a, _b, _c, _d, _e, _f;
12220
+ const { setIsOpen } = useStackedModal();
12221
+ const form = reactHookForm.useForm({
12222
+ resolver: zod.zodResolver(shippingMethodSchema),
12223
+ defaultValues: {
12224
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12225
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12226
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12227
+ }
12228
+ });
12229
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12230
+ const {
12231
+ mutateAsync: updateShippingMethod,
12232
+ isPending: isUpdatingShippingMethod
12233
+ } = useDraftOrderUpdateShippingMethod(order.id);
12234
+ const onSubmit = form.handleSubmit(async (values) => {
12235
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12236
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12237
+ return;
12238
+ }
12239
+ if (data.shippingMethod) {
12240
+ await updateShippingMethod(
12241
+ {
12242
+ method_id: data.shippingMethod.id,
12243
+ shipping_option_id: values.shipping_option_id,
12244
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12245
+ },
12246
+ {
12247
+ onError: (e) => {
12248
+ ui.toast.error(e.message);
12249
+ },
12250
+ onSuccess: () => {
12251
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12631
12252
  }
12632
- ) }),
12633
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12634
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12635
- "rect",
12253
+ }
12254
+ );
12255
+ return;
12256
+ }
12257
+ await addShippingMethod(
12258
+ {
12259
+ shipping_option_id: values.shipping_option_id,
12260
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12261
+ },
12262
+ {
12263
+ onError: (e) => {
12264
+ ui.toast.error(e.message);
12265
+ },
12266
+ onSuccess: () => {
12267
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12268
+ }
12269
+ }
12270
+ );
12271
+ });
12272
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12273
+ KeyboundForm,
12274
+ {
12275
+ className: "flex h-full flex-col overflow-hidden",
12276
+ onSubmit,
12277
+ children: [
12278
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12279
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12280
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12281
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12282
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12283
+ ] }),
12284
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12285
+ /* @__PURE__ */ jsxRuntime.jsx(
12286
+ LocationField,
12636
12287
  {
12637
- width: "12",
12638
- height: "12",
12639
- fill: "white",
12640
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12288
+ control: form.control,
12289
+ setValue: form.setValue
12641
12290
  }
12642
- ) }),
12643
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12644
- "rect",
12291
+ ),
12292
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12293
+ /* @__PURE__ */ jsxRuntime.jsx(
12294
+ ShippingOptionField,
12645
12295
  {
12646
- width: "12",
12647
- height: "12",
12648
- fill: "white",
12649
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12296
+ shippingProfileId: data.shippingProfileId,
12297
+ preview,
12298
+ control: form.control
12650
12299
  }
12651
- ) }),
12652
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12653
- "rect",
12300
+ ),
12301
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12302
+ /* @__PURE__ */ jsxRuntime.jsx(
12303
+ CustomAmountField,
12654
12304
  {
12655
- width: "12",
12656
- height: "12",
12657
- fill: "white",
12658
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12305
+ control: form.control,
12306
+ currencyCode: order.currency_code
12659
12307
  }
12660
- ) }),
12661
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12662
- "rect",
12308
+ ),
12309
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12310
+ /* @__PURE__ */ jsxRuntime.jsx(
12311
+ ItemsPreview,
12663
12312
  {
12664
- width: "12",
12665
- height: "12",
12666
- fill: "white",
12667
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12313
+ order,
12314
+ shippingProfileId: data.shippingProfileId
12668
12315
  }
12669
- ) }),
12670
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12671
- "rect",
12316
+ )
12317
+ ] }) }) }),
12318
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12319
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12320
+ /* @__PURE__ */ jsxRuntime.jsx(
12321
+ ui.Button,
12672
12322
  {
12673
- width: "12",
12674
- height: "12",
12675
- fill: "white",
12676
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12323
+ size: "small",
12324
+ type: "submit",
12325
+ isLoading: isPending || isUpdatingShippingMethod,
12326
+ children: data.shippingMethod ? "Update" : "Add"
12677
12327
  }
12678
- ) }),
12679
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12680
- "rect",
12328
+ )
12329
+ ] }) })
12330
+ ]
12331
+ }
12332
+ ) }) });
12333
+ };
12334
+ const shippingMethodSchema = objectType({
12335
+ location_id: stringType(),
12336
+ shipping_option_id: stringType(),
12337
+ custom_amount: unionType([numberType(), stringType()]).optional()
12338
+ });
12339
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12340
+ const matches = order.items.filter(
12341
+ (item) => {
12342
+ var _a, _b, _c;
12343
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12344
+ }
12345
+ );
12346
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12347
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12348
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12349
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12350
+ ] }) }),
12351
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12352
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12353
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12354
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12355
+ ] }),
12356
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12357
+ "div",
12358
+ {
12359
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12360
+ children: [
12361
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12362
+ /* @__PURE__ */ jsxRuntime.jsx(
12363
+ Thumbnail,
12364
+ {
12365
+ thumbnail: item.thumbnail,
12366
+ alt: item.product_title ?? void 0
12367
+ }
12368
+ ),
12369
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12370
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12371
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12372
+ /* @__PURE__ */ jsxRuntime.jsxs(
12373
+ ui.Text,
12374
+ {
12375
+ size: "small",
12376
+ leading: "compact",
12377
+ className: "text-ui-fg-subtle",
12378
+ children: [
12379
+ "(",
12380
+ item.variant_title,
12381
+ ")"
12382
+ ]
12383
+ }
12384
+ )
12385
+ ] }),
12386
+ /* @__PURE__ */ jsxRuntime.jsx(
12387
+ ui.Text,
12388
+ {
12389
+ size: "small",
12390
+ leading: "compact",
12391
+ className: "text-ui-fg-subtle",
12392
+ children: item.variant_sku
12393
+ }
12394
+ )
12395
+ ] })
12396
+ ] }),
12397
+ /* @__PURE__ */ jsxRuntime.jsxs(
12398
+ ui.Text,
12399
+ {
12400
+ size: "small",
12401
+ leading: "compact",
12402
+ className: "text-ui-fg-subtle",
12403
+ children: [
12404
+ item.quantity,
12405
+ "x"
12406
+ ]
12407
+ }
12408
+ )
12409
+ ]
12410
+ },
12411
+ item.id
12412
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12413
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12414
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12415
+ 'No items found for "',
12416
+ query,
12417
+ '".'
12418
+ ] })
12419
+ ] }) })
12420
+ ] })
12421
+ ] });
12422
+ };
12423
+ const LocationField = ({ control, setValue }) => {
12424
+ const locations = useComboboxData({
12425
+ queryKey: ["locations"],
12426
+ queryFn: async (params) => {
12427
+ return await sdk.admin.stockLocation.list(params);
12428
+ },
12429
+ getOptions: (data) => {
12430
+ return data.stock_locations.map((location) => ({
12431
+ label: location.name,
12432
+ value: location.id
12433
+ }));
12434
+ }
12435
+ });
12436
+ return /* @__PURE__ */ jsxRuntime.jsx(
12437
+ Form$2.Field,
12438
+ {
12439
+ control,
12440
+ name: "location_id",
12441
+ render: ({ field: { onChange, ...field } }) => {
12442
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12443
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12445
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12446
+ ] }),
12447
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12448
+ Combobox,
12681
12449
  {
12682
- width: "12",
12683
- height: "12",
12684
- fill: "white",
12685
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12450
+ options: locations.options,
12451
+ fetchNextPage: locations.fetchNextPage,
12452
+ isFetchingNextPage: locations.isFetchingNextPage,
12453
+ searchValue: locations.searchValue,
12454
+ onSearchValueChange: locations.onSearchValueChange,
12455
+ placeholder: "Select location",
12456
+ onChange: (value) => {
12457
+ setValue("shipping_option_id", "", {
12458
+ shouldDirty: true,
12459
+ shouldTouch: true
12460
+ });
12461
+ onChange(value);
12462
+ },
12463
+ ...field
12686
12464
  }
12687
12465
  ) })
12688
- ] })
12689
- ]
12466
+ ] }) });
12467
+ }
12690
12468
  }
12691
12469
  );
12692
12470
  };
12693
- const schema = objectType({
12694
- customer_id: stringType().min(1)
12695
- });
12696
- const InlineTip = React.forwardRef(
12697
- ({ variant = "tip", label, className, children, ...props }, ref) => {
12698
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12699
- return /* @__PURE__ */ jsxRuntime.jsxs(
12700
- "div",
12701
- {
12702
- ref,
12703
- className: ui.clx(
12704
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12705
- className
12706
- ),
12707
- ...props,
12708
- children: [
12471
+ const ShippingOptionField = ({
12472
+ shippingProfileId,
12473
+ preview,
12474
+ control
12475
+ }) => {
12476
+ var _a;
12477
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12478
+ const shippingOptions = useComboboxData({
12479
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12480
+ queryFn: async (params) => {
12481
+ return await sdk.admin.shippingOption.list({
12482
+ ...params,
12483
+ stock_location_id: locationId,
12484
+ shipping_profile_id: shippingProfileId
12485
+ });
12486
+ },
12487
+ getOptions: (data) => {
12488
+ return data.shipping_options.map((option) => {
12489
+ var _a2;
12490
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12491
+ (r) => r.attribute === "is_return" && r.value === "true"
12492
+ )) {
12493
+ return void 0;
12494
+ }
12495
+ return {
12496
+ label: option.name,
12497
+ value: option.id
12498
+ };
12499
+ }).filter(Boolean);
12500
+ },
12501
+ enabled: !!locationId && !!shippingProfileId,
12502
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12503
+ });
12504
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12505
+ return /* @__PURE__ */ jsxRuntime.jsx(
12506
+ Form$2.Field,
12507
+ {
12508
+ control,
12509
+ name: "shipping_option_id",
12510
+ render: ({ field }) => {
12511
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12512
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12513
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12514
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12515
+ ] }),
12709
12516
  /* @__PURE__ */ jsxRuntime.jsx(
12710
- "div",
12517
+ ConditionalTooltip,
12518
+ {
12519
+ content: tooltipContent,
12520
+ showTooltip: !locationId || !shippingProfileId,
12521
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12522
+ Combobox,
12523
+ {
12524
+ options: shippingOptions.options,
12525
+ fetchNextPage: shippingOptions.fetchNextPage,
12526
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12527
+ searchValue: shippingOptions.searchValue,
12528
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12529
+ placeholder: "Select shipping option",
12530
+ ...field,
12531
+ disabled: !locationId || !shippingProfileId
12532
+ }
12533
+ ) }) })
12534
+ }
12535
+ )
12536
+ ] }) });
12537
+ }
12538
+ }
12539
+ );
12540
+ };
12541
+ const CustomAmountField = ({
12542
+ control,
12543
+ currencyCode
12544
+ }) => {
12545
+ return /* @__PURE__ */ jsxRuntime.jsx(
12546
+ Form$2.Field,
12547
+ {
12548
+ control,
12549
+ name: "custom_amount",
12550
+ render: ({ field: { onChange, ...field } }) => {
12551
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12552
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12553
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12555
+ ] }),
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12557
+ ui.CurrencyInput,
12711
12558
  {
12712
- role: "presentation",
12713
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12714
- "bg-ui-tag-orange-icon": variant === "warning"
12715
- })
12559
+ ...field,
12560
+ onValueChange: (value) => onChange(value),
12561
+ symbol: getNativeSymbol(currencyCode),
12562
+ code: currencyCode
12716
12563
  }
12717
- ),
12718
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
12719
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12720
- labelValue,
12721
- ":"
12722
- ] }),
12723
- " ",
12724
- children
12725
- ] })
12726
- ]
12564
+ ) })
12565
+ ] });
12727
12566
  }
12728
- );
12729
- }
12730
- );
12731
- InlineTip.displayName = "InlineTip";
12732
- const MetadataFieldSchema = objectType({
12733
- key: stringType(),
12734
- disabled: booleanType().optional(),
12735
- value: anyType()
12736
- });
12737
- const MetadataSchema = objectType({
12738
- metadata: arrayType(MetadataFieldSchema)
12739
- });
12740
- const Metadata = () => {
12567
+ }
12568
+ );
12569
+ };
12570
+ const TransferOwnership = () => {
12741
12571
  const { id } = reactRouterDom.useParams();
12742
- const { order, isPending, isError, error } = useOrder(id, {
12743
- fields: "metadata"
12572
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12573
+ fields: "id,customer_id,customer.*"
12744
12574
  });
12745
12575
  if (isError) {
12746
12576
  throw error;
12747
12577
  }
12748
- const isReady = !isPending && !!order;
12578
+ const isReady = !isPending && !!draft_order;
12749
12579
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12750
12580
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12751
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
12752
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
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" }) })
12753
12583
  ] }),
12754
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12584
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12755
12585
  ] });
12756
12586
  };
12757
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12758
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12759
- const MetadataForm = ({ orderId, metadata }) => {
12760
- const { handleSuccess } = useRouteModal();
12761
- const hasUneditableRows = getHasUneditableRows(metadata);
12762
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12587
+ const TransferOwnershipForm = ({ order }) => {
12588
+ var _a, _b;
12763
12589
  const form = reactHookForm.useForm({
12764
12590
  defaultValues: {
12765
- metadata: getDefaultValues(metadata)
12591
+ customer_id: order.customer_id || ""
12766
12592
  },
12767
- resolver: zod.zodResolver(MetadataSchema)
12593
+ resolver: zod.zodResolver(schema)
12768
12594
  });
12769
- const handleSubmit = form.handleSubmit(async (data) => {
12770
- const parsedData = parseValues(data);
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) => {
12771
12603
  await mutateAsync(
12772
- {
12773
- metadata: parsedData
12774
- },
12604
+ { customer_id: data.customer_id },
12775
12605
  {
12776
12606
  onSuccess: () => {
12777
- ui.toast.success("Metadata updated");
12607
+ ui.toast.success("Customer updated");
12778
12608
  handleSuccess();
12779
12609
  },
12780
12610
  onError: (error) => {
@@ -12783,266 +12613,436 @@ const MetadataForm = ({ orderId, metadata }) => {
12783
12613
  }
12784
12614
  );
12785
12615
  });
12786
- const { fields, insert, remove } = reactHookForm.useFieldArray({
12787
- control: form.control,
12788
- name: "metadata"
12789
- });
12790
- function deleteRow(index) {
12791
- remove(index);
12792
- if (fields.length === 1) {
12793
- insert(0, {
12794
- key: "",
12795
- value: "",
12796
- disabled: false
12797
- });
12798
- }
12799
- }
12800
- function insertRow(index, position) {
12801
- insert(index + (position === "above" ? 0 : 1), {
12802
- key: "",
12803
- value: "",
12804
- disabled: false
12805
- });
12806
- }
12807
12616
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12808
12617
  KeyboundForm,
12809
12618
  {
12810
- onSubmit: handleSubmit,
12811
12619
  className: "flex flex-1 flex-col overflow-hidden",
12620
+ onSubmit,
12812
12621
  children: [
12813
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12814
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12815
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12816
- /* @__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" }) }),
12817
- /* @__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" }) })
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." })
12818
12628
  ] }),
12819
- fields.map((field, index) => {
12820
- const isDisabled = field.disabled || false;
12821
- let placeholder = "-";
12822
- if (typeof field.value === "object") {
12823
- placeholder = "{ ... }";
12824
- }
12825
- if (Array.isArray(field.value)) {
12826
- placeholder = "[ ... ]";
12827
- }
12828
- return /* @__PURE__ */ jsxRuntime.jsx(
12829
- ConditionalTooltip,
12830
- {
12831
- showTooltip: isDisabled,
12832
- content: "This row is disabled because it contains non-primitive data.",
12833
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
12834
- /* @__PURE__ */ jsxRuntime.jsxs(
12835
- "div",
12836
- {
12837
- className: ui.clx("grid grid-cols-2 divide-x", {
12838
- "overflow-hidden rounded-b-lg": index === fields.length - 1
12839
- }),
12840
- children: [
12841
- /* @__PURE__ */ jsxRuntime.jsx(
12842
- Form$2.Field,
12843
- {
12844
- control: form.control,
12845
- name: `metadata.${index}.key`,
12846
- render: ({ field: field2 }) => {
12847
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12848
- GridInput,
12849
- {
12850
- "aria-labelledby": METADATA_KEY_LABEL_ID,
12851
- ...field2,
12852
- disabled: isDisabled,
12853
- placeholder: "Key"
12854
- }
12855
- ) }) });
12856
- }
12857
- }
12858
- ),
12859
- /* @__PURE__ */ jsxRuntime.jsx(
12860
- Form$2.Field,
12861
- {
12862
- control: form.control,
12863
- name: `metadata.${index}.value`,
12864
- render: ({ field: { value, ...field2 } }) => {
12865
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12866
- GridInput,
12867
- {
12868
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
12869
- ...field2,
12870
- value: isDisabled ? placeholder : value,
12871
- disabled: isDisabled,
12872
- placeholder: "Value"
12873
- }
12874
- ) }) });
12875
- }
12876
- }
12877
- )
12878
- ]
12879
- }
12880
- ),
12881
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
12882
- /* @__PURE__ */ jsxRuntime.jsx(
12883
- ui.DropdownMenu.Trigger,
12884
- {
12885
- className: ui.clx(
12886
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12887
- {
12888
- hidden: isDisabled
12889
- }
12890
- ),
12891
- disabled: isDisabled,
12892
- asChild: true,
12893
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
12894
- }
12895
- ),
12896
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
12897
- /* @__PURE__ */ jsxRuntime.jsxs(
12898
- ui.DropdownMenu.Item,
12899
- {
12900
- className: "gap-x-2",
12901
- onClick: () => insertRow(index, "above"),
12902
- children: [
12903
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
12904
- "Insert row above"
12905
- ]
12906
- }
12907
- ),
12908
- /* @__PURE__ */ jsxRuntime.jsxs(
12909
- ui.DropdownMenu.Item,
12910
- {
12911
- className: "gap-x-2",
12912
- onClick: () => insertRow(index, "below"),
12913
- children: [
12914
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
12915
- "Insert row below"
12916
- ]
12917
- }
12918
- ),
12919
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
12920
- /* @__PURE__ */ jsxRuntime.jsxs(
12921
- ui.DropdownMenu.Item,
12922
- {
12923
- className: "gap-x-2",
12924
- onClick: () => deleteRow(index),
12925
- children: [
12926
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
12927
- "Delete row"
12928
- ]
12929
- }
12930
- )
12931
- ] })
12932
- ] })
12933
- ] })
12934
- },
12935
- field.id
12936
- );
12937
- })
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
+ ] })
12938
12633
  ] }),
12939
- 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." })
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." })
12940
12678
  ] }),
12941
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12942
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12943
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12944
- ] }) })
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)"
12991
+ }
12992
+ ) }),
12993
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12994
+ "rect",
12995
+ {
12996
+ width: "12",
12997
+ height: "12",
12998
+ fill: "white",
12999
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
13000
+ }
13001
+ ) }),
13002
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13003
+ "rect",
13004
+ {
13005
+ width: "12",
13006
+ height: "12",
13007
+ fill: "white",
13008
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
13009
+ }
13010
+ ) }),
13011
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13012
+ "rect",
13013
+ {
13014
+ width: "12",
13015
+ height: "12",
13016
+ fill: "white",
13017
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
13018
+ }
13019
+ ) }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13021
+ "rect",
13022
+ {
13023
+ width: "12",
13024
+ height: "12",
13025
+ fill: "white",
13026
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
13027
+ }
13028
+ ) }),
13029
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13030
+ "rect",
13031
+ {
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
+ }
13037
+ ) })
13038
+ ] })
12945
13039
  ]
12946
13040
  }
12947
- ) });
12948
- };
12949
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
12950
- return /* @__PURE__ */ jsxRuntime.jsx(
12951
- "input",
12952
- {
12953
- ref,
12954
- ...props,
12955
- autoComplete: "off",
12956
- className: ui.clx(
12957
- "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",
12958
- className
12959
- )
12960
- }
12961
13041
  );
12962
- });
12963
- GridInput.displayName = "MetadataForm.GridInput";
12964
- const PlaceholderInner = () => {
12965
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12966
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12967
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12968
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
12969
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
12970
- ] }) })
12971
- ] });
12972
13042
  };
12973
- const EDITABLE_TYPES = ["string", "number", "boolean"];
12974
- function getDefaultValues(metadata) {
12975
- if (!metadata || !Object.keys(metadata).length) {
12976
- return [
12977
- {
12978
- key: "",
12979
- value: "",
12980
- disabled: false
12981
- }
12982
- ];
12983
- }
12984
- return Object.entries(metadata).map(([key, value]) => {
12985
- if (!EDITABLE_TYPES.includes(typeof value)) {
12986
- return {
12987
- key,
12988
- value,
12989
- disabled: true
12990
- };
12991
- }
12992
- let stringValue = value;
12993
- if (typeof value !== "string") {
12994
- stringValue = JSON.stringify(value);
12995
- }
12996
- return {
12997
- key,
12998
- value: stringValue,
12999
- original_key: key
13000
- };
13001
- });
13002
- }
13003
- function parseValues(values) {
13004
- const metadata = values.metadata;
13005
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
13006
- if (isEmpty) {
13007
- return null;
13008
- }
13009
- const update = {};
13010
- metadata.forEach((field) => {
13011
- let key = field.key;
13012
- let value = field.value;
13013
- const disabled = field.disabled;
13014
- if (!key || !value) {
13015
- return;
13016
- }
13017
- if (disabled) {
13018
- update[key] = value;
13019
- return;
13020
- }
13021
- key = key.trim();
13022
- value = value.trim();
13023
- if (value === "true") {
13024
- update[key] = true;
13025
- } else if (value === "false") {
13026
- update[key] = false;
13027
- } else {
13028
- const parsedNumber = parseFloat(value);
13029
- if (!isNaN(parsedNumber)) {
13030
- update[key] = parsedNumber;
13031
- } else {
13032
- update[key] = value;
13033
- }
13034
- }
13035
- });
13036
- return update;
13037
- }
13038
- function getHasUneditableRows(metadata) {
13039
- if (!metadata) {
13040
- return false;
13041
- }
13042
- return Object.values(metadata).some(
13043
- (value) => !EDITABLE_TYPES.includes(typeof value)
13044
- );
13045
- }
13043
+ const schema = objectType({
13044
+ customer_id: stringType().min(1)
13045
+ });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13071,22 +13071,22 @@ const routeModule = {
13071
13071
  Component: Email,
13072
13072
  path: "/draft-orders/:id/email"
13073
13073
  },
13074
+ {
13075
+ Component: Items,
13076
+ path: "/draft-orders/:id/items"
13077
+ },
13074
13078
  {
13075
13079
  Component: BillingAddress,
13076
13080
  path: "/draft-orders/:id/billing-address"
13077
13081
  },
13078
13082
  {
13079
- Component: Items,
13080
- path: "/draft-orders/:id/items"
13083
+ Component: Metadata,
13084
+ path: "/draft-orders/:id/metadata"
13081
13085
  },
13082
13086
  {
13083
13087
  Component: Promotions,
13084
13088
  path: "/draft-orders/:id/promotions"
13085
13089
  },
13086
- {
13087
- Component: Shipping,
13088
- path: "/draft-orders/:id/shipping"
13089
- },
13090
13090
  {
13091
13091
  Component: SalesChannel,
13092
13092
  path: "/draft-orders/:id/sales-channel"
@@ -13096,12 +13096,12 @@ const routeModule = {
13096
13096
  path: "/draft-orders/:id/shipping-address"
13097
13097
  },
13098
13098
  {
13099
- Component: TransferOwnership,
13100
- path: "/draft-orders/:id/transfer-ownership"
13099
+ Component: Shipping,
13100
+ path: "/draft-orders/:id/shipping"
13101
13101
  },
13102
13102
  {
13103
- Component: Metadata,
13104
- path: "/draft-orders/:id/metadata"
13103
+ Component: TransferOwnership,
13104
+ path: "/draft-orders/:id/transfer-ownership"
13105
13105
  }
13106
13106
  ]
13107
13107
  }