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

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,6 +9660,196 @@ 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;
9663
9853
  const NumberInput = React.forwardRef(
9664
9854
  ({
9665
9855
  value,
@@ -10634,942 +10824,283 @@ const customItemSchema = objectType({
10634
10824
  quantity: numberType(),
10635
10825
  unit_price: unionType([numberType(), stringType()])
10636
10826
  });
10637
- const InlineTip = React.forwardRef(
10638
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10639
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10640
- return /* @__PURE__ */ jsxRuntime.jsxs(
10641
- "div",
10642
- {
10643
- ref,
10644
- className: ui.clx(
10645
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10646
- className
10647
- ),
10648
- ...props,
10649
- children: [
10650
- /* @__PURE__ */ jsxRuntime.jsx(
10651
- "div",
10652
- {
10653
- role: "presentation",
10654
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10655
- "bg-ui-tag-orange-icon": variant === "warning"
10656
- })
10657
- }
10658
- ),
10659
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10660
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10661
- labelValue,
10662
- ":"
10663
- ] }),
10664
- " ",
10665
- children
10666
- ] })
10667
- ]
10668
- }
10669
- );
10670
- }
10671
- );
10672
- InlineTip.displayName = "InlineTip";
10673
- const MetadataFieldSchema = objectType({
10674
- key: stringType(),
10675
- disabled: booleanType().optional(),
10676
- value: anyType()
10677
- });
10678
- const MetadataSchema = objectType({
10679
- metadata: arrayType(MetadataFieldSchema)
10680
- });
10681
- const Metadata = () => {
10682
- const { id } = reactRouterDom.useParams();
10683
- const { order, isPending, isError, error } = useOrder(id, {
10684
- fields: "metadata"
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
10685
10844
  });
10686
- if (isError) {
10687
- throw error;
10845
+ return { ...data, ...rest };
10846
+ };
10847
+ const Promotions = () => {
10848
+ 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;
10688
10858
  }
10689
- const isReady = !isPending && !!order;
10690
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10691
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10692
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10693
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10694
- ] }),
10695
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
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 })
10696
10863
  ] });
10697
10864
  };
10698
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10699
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10700
- const MetadataForm = ({ orderId, metadata }) => {
10865
+ const PromotionForm = ({ preview }) => {
10866
+ const { items, shipping_methods } = preview;
10867
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10868
+ const [comboboxValue, setComboboxValue] = React.useState("");
10701
10869
  const { handleSuccess } = useRouteModal();
10702
- const hasUneditableRows = getHasUneditableRows(metadata);
10703
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10704
- const form = reactHookForm.useForm({
10705
- defaultValues: {
10706
- metadata: getDefaultValues(metadata)
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
10707
10875
  },
10708
- resolver: zod.zodResolver(MetadataSchema)
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
+ });
10889
+ },
10890
+ getOptions: (data) => {
10891
+ return data.promotions.map((promotion) => ({
10892
+ label: promotion.code,
10893
+ value: promotion.code
10894
+ }));
10895
+ }
10709
10896
  });
10710
- const handleSubmit = form.handleSubmit(async (data) => {
10711
- const parsedData = parseValues(data);
10712
- await mutateAsync(
10897
+ const add = async (value) => {
10898
+ if (!value) {
10899
+ return;
10900
+ }
10901
+ addPromotions(
10713
10902
  {
10714
- metadata: parsedData
10903
+ promo_codes: [value]
10715
10904
  },
10716
10905
  {
10717
- onSuccess: () => {
10718
- ui.toast.success("Metadata updated");
10719
- handleSuccess();
10906
+ onError: (e) => {
10907
+ ui.toast.error(e.message);
10908
+ comboboxData.onSearchValueChange("");
10909
+ setComboboxValue("");
10720
10910
  },
10721
- onError: (error) => {
10722
- ui.toast.error(error.message);
10911
+ onSuccess: () => {
10912
+ comboboxData.onSearchValueChange("");
10913
+ setComboboxValue("");
10723
10914
  }
10724
10915
  }
10725
10916
  );
10726
- });
10727
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10728
- control: form.control,
10729
- name: "metadata"
10730
- });
10731
- function deleteRow(index) {
10732
- remove(index);
10733
- if (fields.length === 1) {
10734
- insert(0, {
10735
- key: "",
10736
- value: "",
10737
- disabled: false
10738
- });
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;
10739
10934
  }
10740
- }
10741
- function insertRow(index, position) {
10742
- insert(index + (position === "above" ? 0 : 1), {
10743
- key: "",
10744
- value: "",
10745
- disabled: false
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
+ }
10746
10945
  });
10946
+ };
10947
+ if (isError) {
10948
+ throw error;
10747
10949
  }
10748
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10749
- KeyboundForm,
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
10980
+ },
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);
11013
+ }
11014
+ }
11015
+ );
11016
+ };
11017
+ const displayValue = getDisplayValue(promotion);
11018
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11019
+ "div",
10750
11020
  {
10751
- onSubmit: handleSubmit,
10752
- className: "flex flex-1 flex-col overflow-hidden",
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
+ ),
10753
11027
  children: [
10754
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10755
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10756
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10757
- /* @__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" }) }),
10758
- /* @__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" }) })
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: "·" })
10759
11034
  ] }),
10760
- fields.map((field, index) => {
10761
- const isDisabled = field.disabled || false;
10762
- let placeholder = "-";
10763
- if (typeof field.value === "object") {
10764
- placeholder = "{ ... }";
10765
- }
10766
- if (Array.isArray(field.value)) {
10767
- placeholder = "[ ... ]";
10768
- }
10769
- return /* @__PURE__ */ jsxRuntime.jsx(
10770
- ConditionalTooltip,
10771
- {
10772
- showTooltip: isDisabled,
10773
- content: "This row is disabled because it contains non-primitive data.",
10774
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10775
- /* @__PURE__ */ jsxRuntime.jsxs(
10776
- "div",
10777
- {
10778
- className: ui.clx("grid grid-cols-2 divide-x", {
10779
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10780
- }),
10781
- children: [
10782
- /* @__PURE__ */ jsxRuntime.jsx(
10783
- Form$2.Field,
10784
- {
10785
- control: form.control,
10786
- name: `metadata.${index}.key`,
10787
- render: ({ field: field2 }) => {
10788
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10789
- GridInput,
10790
- {
10791
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10792
- ...field2,
10793
- disabled: isDisabled,
10794
- placeholder: "Key"
10795
- }
10796
- ) }) });
10797
- }
10798
- }
10799
- ),
10800
- /* @__PURE__ */ jsxRuntime.jsx(
10801
- Form$2.Field,
10802
- {
10803
- control: form.control,
10804
- name: `metadata.${index}.value`,
10805
- render: ({ field: { value, ...field2 } }) => {
10806
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10807
- GridInput,
10808
- {
10809
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10810
- ...field2,
10811
- value: isDisabled ? placeholder : value,
10812
- disabled: isDisabled,
10813
- placeholder: "Value"
10814
- }
10815
- ) }) });
10816
- }
10817
- }
10818
- )
10819
- ]
10820
- }
10821
- ),
10822
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10823
- /* @__PURE__ */ jsxRuntime.jsx(
10824
- ui.DropdownMenu.Trigger,
10825
- {
10826
- className: ui.clx(
10827
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10828
- {
10829
- hidden: isDisabled
10830
- }
10831
- ),
10832
- disabled: isDisabled,
10833
- asChild: true,
10834
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10835
- }
10836
- ),
10837
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10838
- /* @__PURE__ */ jsxRuntime.jsxs(
10839
- ui.DropdownMenu.Item,
10840
- {
10841
- className: "gap-x-2",
10842
- onClick: () => insertRow(index, "above"),
10843
- children: [
10844
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10845
- "Insert row above"
10846
- ]
10847
- }
10848
- ),
10849
- /* @__PURE__ */ jsxRuntime.jsxs(
10850
- ui.DropdownMenu.Item,
10851
- {
10852
- className: "gap-x-2",
10853
- onClick: () => insertRow(index, "below"),
10854
- children: [
10855
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10856
- "Insert row below"
10857
- ]
10858
- }
10859
- ),
10860
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10861
- /* @__PURE__ */ jsxRuntime.jsxs(
10862
- ui.DropdownMenu.Item,
10863
- {
10864
- className: "gap-x-2",
10865
- onClick: () => deleteRow(index),
10866
- children: [
10867
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10868
- "Delete row"
10869
- ]
10870
- }
10871
- )
10872
- ] })
10873
- ] })
10874
- ] })
10875
- },
10876
- field.id
10877
- );
10878
- })
10879
- ] }),
10880
- 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." })
10881
- ] }),
10882
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10883
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10884
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10885
- ] }) })
10886
- ]
10887
- }
10888
- ) });
10889
- };
10890
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10891
- return /* @__PURE__ */ jsxRuntime.jsx(
10892
- "input",
10893
- {
10894
- ref,
10895
- ...props,
10896
- autoComplete: "off",
10897
- className: ui.clx(
10898
- "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",
10899
- className
10900
- )
10901
- }
10902
- );
10903
- });
10904
- GridInput.displayName = "MetadataForm.GridInput";
10905
- const PlaceholderInner = () => {
10906
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10907
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10908
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10909
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10910
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10911
- ] }) })
10912
- ] });
10913
- };
10914
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10915
- function getDefaultValues(metadata) {
10916
- if (!metadata || !Object.keys(metadata).length) {
10917
- return [
10918
- {
10919
- key: "",
10920
- value: "",
10921
- disabled: false
10922
- }
10923
- ];
10924
- }
10925
- return Object.entries(metadata).map(([key, value]) => {
10926
- if (!EDITABLE_TYPES.includes(typeof value)) {
10927
- return {
10928
- key,
10929
- value,
10930
- disabled: true
10931
- };
10932
- }
10933
- let stringValue = value;
10934
- if (typeof value !== "string") {
10935
- stringValue = JSON.stringify(value);
10936
- }
10937
- return {
10938
- key,
10939
- value: stringValue,
10940
- original_key: key
10941
- };
10942
- });
10943
- }
10944
- function parseValues(values) {
10945
- const metadata = values.metadata;
10946
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10947
- if (isEmpty) {
10948
- return null;
10949
- }
10950
- const update = {};
10951
- metadata.forEach((field) => {
10952
- let key = field.key;
10953
- let value = field.value;
10954
- const disabled = field.disabled;
10955
- if (!key || !value) {
10956
- return;
10957
- }
10958
- if (disabled) {
10959
- update[key] = value;
10960
- return;
10961
- }
10962
- key = key.trim();
10963
- value = value.trim();
10964
- if (value === "true") {
10965
- update[key] = true;
10966
- } else if (value === "false") {
10967
- update[key] = false;
10968
- } else {
10969
- const parsedNumber = parseFloat(value);
10970
- if (!isNaN(parsedNumber)) {
10971
- update[key] = parsedNumber;
10972
- } else {
10973
- update[key] = value;
10974
- }
10975
- }
10976
- });
10977
- return update;
10978
- }
10979
- function getHasUneditableRows(metadata) {
10980
- if (!metadata) {
10981
- return false;
10982
- }
10983
- return Object.values(metadata).some(
10984
- (value) => !EDITABLE_TYPES.includes(typeof value)
10985
- );
10986
- }
10987
- const PROMOTION_QUERY_KEY = "promotions";
10988
- const promotionsQueryKeys = {
10989
- list: (query2) => [
10990
- PROMOTION_QUERY_KEY,
10991
- query2 ? query2 : void 0
10992
- ],
10993
- detail: (id, query2) => [
10994
- PROMOTION_QUERY_KEY,
10995
- id,
10996
- query2 ? query2 : void 0
10997
- ]
10998
- };
10999
- const usePromotions = (query2, options) => {
11000
- const { data, ...rest } = reactQuery.useQuery({
11001
- queryKey: promotionsQueryKeys.list(query2),
11002
- queryFn: async () => sdk.admin.promotion.list(query2),
11003
- ...options
11004
- });
11005
- return { ...data, ...rest };
11006
- };
11007
- const Promotions = () => {
11008
- const { id } = reactRouterDom.useParams();
11009
- const {
11010
- order: preview,
11011
- isError: isPreviewError,
11012
- error: previewError
11013
- } = useOrderPreview(id, void 0);
11014
- useInitiateOrderEdit({ preview });
11015
- const { onCancel } = useCancelOrderEdit({ preview });
11016
- if (isPreviewError) {
11017
- throw previewError;
11018
- }
11019
- const isReady = !!preview;
11020
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11021
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11022
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11023
- ] });
11024
- };
11025
- const PromotionForm = ({ preview }) => {
11026
- const { items, shipping_methods } = preview;
11027
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11028
- const [comboboxValue, setComboboxValue] = React.useState("");
11029
- const { handleSuccess } = useRouteModal();
11030
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11031
- const promoIds = getPromotionIds(items, shipping_methods);
11032
- const { promotions, isPending, isError, error } = usePromotions(
11033
- {
11034
- id: promoIds
11035
- },
11036
- {
11037
- enabled: !!promoIds.length
11038
- }
11039
- );
11040
- const comboboxData = useComboboxData({
11041
- queryKey: ["promotions", "combobox", promoIds],
11042
- queryFn: async (params) => {
11043
- return await sdk.admin.promotion.list({
11044
- ...params,
11045
- id: {
11046
- $nin: promoIds
11047
- }
11048
- });
11049
- },
11050
- getOptions: (data) => {
11051
- return data.promotions.map((promotion) => ({
11052
- label: promotion.code,
11053
- value: promotion.code
11054
- }));
11055
- }
11056
- });
11057
- const add = async (value) => {
11058
- if (!value) {
11059
- return;
11060
- }
11061
- addPromotions(
11062
- {
11063
- promo_codes: [value]
11064
- },
11065
- {
11066
- onError: (e) => {
11067
- ui.toast.error(e.message);
11068
- comboboxData.onSearchValueChange("");
11069
- setComboboxValue("");
11070
- },
11071
- onSuccess: () => {
11072
- comboboxData.onSearchValueChange("");
11073
- setComboboxValue("");
11074
- }
11075
- }
11076
- );
11077
- };
11078
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11079
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11080
- const onSubmit = async () => {
11081
- setIsSubmitting(true);
11082
- let requestSucceeded = false;
11083
- await requestOrderEdit(void 0, {
11084
- onError: (e) => {
11085
- ui.toast.error(e.message);
11086
- },
11087
- onSuccess: () => {
11088
- requestSucceeded = true;
11089
- }
11090
- });
11091
- if (!requestSucceeded) {
11092
- setIsSubmitting(false);
11093
- return;
11094
- }
11095
- await confirmOrderEdit(void 0, {
11096
- onError: (e) => {
11097
- ui.toast.error(e.message);
11098
- },
11099
- onSuccess: () => {
11100
- handleSuccess();
11101
- },
11102
- onSettled: () => {
11103
- setIsSubmitting(false);
11104
- }
11105
- });
11106
- };
11107
- if (isError) {
11108
- throw error;
11109
- }
11110
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11111
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11112
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11113
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11114
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11115
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11116
- ] }),
11117
- /* @__PURE__ */ jsxRuntime.jsx(
11118
- Combobox,
11119
- {
11120
- id: "promotion-combobox",
11121
- "aria-describedby": "promotion-combobox-hint",
11122
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11123
- fetchNextPage: comboboxData.fetchNextPage,
11124
- options: comboboxData.options,
11125
- onSearchValueChange: comboboxData.onSearchValueChange,
11126
- searchValue: comboboxData.searchValue,
11127
- disabled: comboboxData.disabled || isAddingPromotions,
11128
- onChange: add,
11129
- value: comboboxValue
11130
- }
11131
- )
11132
- ] }),
11133
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11134
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11135
- PromotionItem,
11136
- {
11137
- promotion,
11138
- orderId: preview.id,
11139
- isLoading: isPending
11140
- },
11141
- promotion.id
11142
- )) })
11143
- ] }) }),
11144
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11145
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11146
- /* @__PURE__ */ jsxRuntime.jsx(
11147
- ui.Button,
11148
- {
11149
- size: "small",
11150
- type: "submit",
11151
- isLoading: isSubmitting || isAddingPromotions,
11152
- children: "Save"
11153
- }
11154
- )
11155
- ] }) })
11156
- ] });
11157
- };
11158
- const PromotionItem = ({
11159
- promotion,
11160
- orderId,
11161
- isLoading
11162
- }) => {
11163
- var _a;
11164
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11165
- const onRemove = async () => {
11166
- removePromotions(
11167
- {
11168
- promo_codes: [promotion.code]
11169
- },
11170
- {
11171
- onError: (e) => {
11172
- ui.toast.error(e.message);
11173
- }
11174
- }
11175
- );
11176
- };
11177
- const displayValue = getDisplayValue(promotion);
11178
- return /* @__PURE__ */ jsxRuntime.jsxs(
11179
- "div",
11180
- {
11181
- className: ui.clx(
11182
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11183
- {
11184
- "animate-pulse": isLoading
11185
- }
11186
- ),
11187
- children: [
11188
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11189
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11190
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11191
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11192
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11193
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11194
- ] }),
11195
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11196
- ] })
11197
- ] }),
11198
- /* @__PURE__ */ jsxRuntime.jsx(
11199
- ui.IconButton,
11200
- {
11201
- size: "small",
11202
- type: "button",
11203
- variant: "transparent",
11204
- onClick: onRemove,
11205
- isLoading: isPending || isLoading,
11206
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11207
- }
11208
- )
11209
- ]
11210
- },
11211
- promotion.id
11212
- );
11213
- };
11214
- function getDisplayValue(promotion) {
11215
- var _a, _b, _c, _d;
11216
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11217
- if (!value) {
11218
- return null;
11219
- }
11220
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11221
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11222
- if (!currency) {
11223
- return null;
11224
- }
11225
- return getLocaleAmount(value, currency);
11226
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11227
- return formatPercentage(value);
11228
- }
11229
- return null;
11230
- }
11231
- const formatter = new Intl.NumberFormat([], {
11232
- style: "percent",
11233
- minimumFractionDigits: 2
11234
- });
11235
- const formatPercentage = (value, isPercentageValue = false) => {
11236
- let val = value || 0;
11237
- if (!isPercentageValue) {
11238
- val = val / 100;
11239
- }
11240
- return formatter.format(val);
11241
- };
11242
- function getPromotionIds(items, shippingMethods) {
11243
- const promotionIds = /* @__PURE__ */ new Set();
11244
- for (const item of items) {
11245
- if (item.adjustments) {
11246
- for (const adjustment of item.adjustments) {
11247
- if (adjustment.promotion_id) {
11248
- promotionIds.add(adjustment.promotion_id);
11249
- }
11250
- }
11251
- }
11252
- }
11253
- for (const shippingMethod of shippingMethods) {
11254
- if (shippingMethod.adjustments) {
11255
- for (const adjustment of shippingMethod.adjustments) {
11256
- if (adjustment.promotion_id) {
11257
- promotionIds.add(adjustment.promotion_id);
11258
- }
11259
- }
11260
- }
11261
- }
11262
- return Array.from(promotionIds);
11263
- }
11264
- const SalesChannel = () => {
11265
- const { id } = reactRouterDom.useParams();
11266
- const { draft_order, isPending, isError, error } = useDraftOrder(
11267
- id,
11268
- {
11269
- fields: "+sales_channel_id"
11270
- },
11271
- {
11272
- enabled: !!id
11273
- }
11274
- );
11275
- if (isError) {
11276
- throw error;
11277
- }
11278
- const ISrEADY = !!draft_order && !isPending;
11279
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11280
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11281
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11282
- /* @__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" }) })
11283
- ] }),
11284
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11285
- ] });
11286
- };
11287
- const SalesChannelForm = ({ order }) => {
11288
- const form = reactHookForm.useForm({
11289
- defaultValues: {
11290
- sales_channel_id: order.sales_channel_id || ""
11291
- },
11292
- resolver: zod.zodResolver(schema$3)
11293
- });
11294
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11295
- const { handleSuccess } = useRouteModal();
11296
- const onSubmit = form.handleSubmit(async (data) => {
11297
- await mutateAsync(
11298
- {
11299
- sales_channel_id: data.sales_channel_id
11300
- },
11301
- {
11302
- onSuccess: () => {
11303
- ui.toast.success("Sales channel updated");
11304
- handleSuccess();
11305
- },
11306
- onError: (error) => {
11307
- ui.toast.error(error.message);
11308
- }
11309
- }
11310
- );
11311
- });
11312
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11313
- KeyboundForm,
11314
- {
11315
- className: "flex flex-1 flex-col overflow-hidden",
11316
- onSubmit,
11317
- children: [
11318
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11319
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11320
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11321
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11322
- ] }) })
11323
- ]
11324
- }
11325
- ) });
11326
- };
11327
- const SalesChannelField = ({ control, order }) => {
11328
- const salesChannels = useComboboxData({
11329
- queryFn: async (params) => {
11330
- return await sdk.admin.salesChannel.list(params);
11331
- },
11332
- queryKey: ["sales-channels"],
11333
- getOptions: (data) => {
11334
- return data.sales_channels.map((salesChannel) => ({
11335
- label: salesChannel.name,
11336
- value: salesChannel.id
11337
- }));
11338
- },
11339
- defaultValue: order.sales_channel_id || void 0
11340
- });
11341
- return /* @__PURE__ */ jsxRuntime.jsx(
11342
- Form$2.Field,
11343
- {
11344
- control,
11345
- name: "sales_channel_id",
11346
- render: ({ field }) => {
11347
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11348
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11349
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11350
- Combobox,
11351
- {
11352
- options: salesChannels.options,
11353
- fetchNextPage: salesChannels.fetchNextPage,
11354
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11355
- searchValue: salesChannels.searchValue,
11356
- onSearchValueChange: salesChannels.onSearchValueChange,
11357
- placeholder: "Select sales channel",
11358
- ...field
11359
- }
11360
- ) }),
11361
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11362
- ] });
11363
- }
11364
- }
11365
- );
11366
- };
11367
- const schema$3 = objectType({
11368
- sales_channel_id: stringType().min(1)
11369
- });
11370
- const ShippingAddress = () => {
11371
- const { id } = reactRouterDom.useParams();
11372
- const { order, isPending, isError, error } = useOrder(id, {
11373
- fields: "+shipping_address"
11374
- });
11375
- if (isError) {
11376
- throw error;
11377
- }
11378
- const isReady = !isPending && !!order;
11379
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11380
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11381
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11382
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11383
- ] }),
11384
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11385
- ] });
11386
- };
11387
- const ShippingAddressForm = ({ order }) => {
11388
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11389
- const form = reactHookForm.useForm({
11390
- defaultValues: {
11391
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11392
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11393
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11394
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11395
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11396
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11397
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11398
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11399
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11400
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11401
- },
11402
- resolver: zod.zodResolver(schema$2)
11403
- });
11404
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11405
- const { handleSuccess } = useRouteModal();
11406
- const onSubmit = form.handleSubmit(async (data) => {
11407
- await mutateAsync(
11408
- {
11409
- shipping_address: {
11410
- first_name: data.first_name,
11411
- last_name: data.last_name,
11412
- company: data.company,
11413
- address_1: data.address_1,
11414
- address_2: data.address_2,
11415
- city: data.city,
11416
- province: data.province,
11417
- country_code: data.country_code,
11418
- postal_code: data.postal_code,
11419
- phone: data.phone
11420
- }
11421
- },
11422
- {
11423
- onSuccess: () => {
11424
- handleSuccess();
11425
- },
11426
- onError: (error) => {
11427
- ui.toast.error(error.message);
11428
- }
11429
- }
11430
- );
11431
- });
11432
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11433
- KeyboundForm,
11434
- {
11435
- className: "flex flex-1 flex-col overflow-hidden",
11436
- onSubmit,
11437
- children: [
11438
- /* @__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: [
11439
- /* @__PURE__ */ jsxRuntime.jsx(
11440
- Form$2.Field,
11441
- {
11442
- control: form.control,
11443
- name: "country_code",
11444
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11445
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11446
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11448
- ] })
11449
- }
11450
- ),
11451
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11452
- /* @__PURE__ */ jsxRuntime.jsx(
11453
- Form$2.Field,
11454
- {
11455
- control: form.control,
11456
- name: "first_name",
11457
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11458
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11459
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11460
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11461
- ] })
11462
- }
11463
- ),
11464
- /* @__PURE__ */ jsxRuntime.jsx(
11465
- Form$2.Field,
11466
- {
11467
- control: form.control,
11468
- name: "last_name",
11469
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11470
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11471
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11472
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11473
- ] })
11474
- }
11475
- )
11476
- ] }),
11477
- /* @__PURE__ */ jsxRuntime.jsx(
11478
- Form$2.Field,
11479
- {
11480
- control: form.control,
11481
- name: "company",
11482
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11483
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11484
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11485
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11486
- ] })
11487
- }
11488
- ),
11489
- /* @__PURE__ */ jsxRuntime.jsx(
11490
- Form$2.Field,
11491
- {
11492
- control: form.control,
11493
- name: "address_1",
11494
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11495
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11496
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11497
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11498
- ] })
11499
- }
11500
- ),
11501
- /* @__PURE__ */ jsxRuntime.jsx(
11502
- Form$2.Field,
11503
- {
11504
- control: form.control,
11505
- name: "address_2",
11506
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11507
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11508
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11509
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11510
- ] })
11511
- }
11512
- ),
11513
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11514
- /* @__PURE__ */ jsxRuntime.jsx(
11515
- Form$2.Field,
11516
- {
11517
- control: form.control,
11518
- name: "postal_code",
11519
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11521
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11522
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11523
- ] })
11524
- }
11525
- ),
11526
- /* @__PURE__ */ jsxRuntime.jsx(
11527
- Form$2.Field,
11528
- {
11529
- control: form.control,
11530
- name: "city",
11531
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11533
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11534
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11535
- ] })
11536
- }
11537
- )
11538
- ] }),
11539
- /* @__PURE__ */ jsxRuntime.jsx(
11540
- Form$2.Field,
11541
- {
11542
- control: form.control,
11543
- name: "province",
11544
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11546
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11547
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11548
- ] })
11549
- }
11550
- ),
11551
- /* @__PURE__ */ jsxRuntime.jsx(
11552
- Form$2.Field,
11553
- {
11554
- control: form.control,
11555
- name: "phone",
11556
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11558
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11559
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11560
- ] })
11561
- }
11562
- )
11563
- ] }) }),
11564
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11565
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11566
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11567
- ] }) })
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
+ )
11568
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;
11569
11064
  }
11570
- ) });
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);
11571
11081
  };
11572
- const schema$2 = addressSchema;
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
+ }
11573
11104
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11574
11105
  const Shipping = () => {
11575
11106
  var _a;
@@ -12288,95 +11819,404 @@ const ShippingOptionField = ({
12288
11819
  const shippingOptions = useComboboxData({
12289
11820
  queryKey: ["shipping_options", locationId, shippingProfileId],
12290
11821
  queryFn: async (params) => {
12291
- return await sdk.admin.shippingOption.list({
12292
- ...params,
12293
- stock_location_id: locationId,
12294
- shipping_profile_id: shippingProfileId
12295
- });
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
+ ] }) });
11878
+ }
11879
+ }
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
+ ] });
11907
+ }
11908
+ }
11909
+ );
11910
+ };
11911
+ const SalesChannel = () => {
11912
+ const { id } = reactRouterDom.useParams();
11913
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11914
+ id,
11915
+ {
11916
+ fields: "+sales_channel_id"
11917
+ },
11918
+ {
11919
+ enabled: !!id
11920
+ }
11921
+ );
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 || ""
11938
+ },
11939
+ resolver: zod.zodResolver(schema$2)
11940
+ });
11941
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11942
+ const { handleSuccess } = useRouteModal();
11943
+ const onSubmit = form.handleSubmit(async (data) => {
11944
+ await mutateAsync(
11945
+ {
11946
+ sales_channel_id: data.sales_channel_id
11947
+ },
11948
+ {
11949
+ onSuccess: () => {
11950
+ ui.toast.success("Sales channel updated");
11951
+ handleSuccess();
11952
+ },
11953
+ onError: (error) => {
11954
+ ui.toast.error(error.message);
11955
+ }
11956
+ }
11957
+ );
11958
+ });
11959
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11960
+ KeyboundForm,
11961
+ {
11962
+ className: "flex flex-1 flex-col overflow-hidden",
11963
+ onSubmit,
11964
+ children: [
11965
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11966
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11967
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11968
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11969
+ ] }) })
11970
+ ]
11971
+ }
11972
+ ) });
11973
+ };
11974
+ const SalesChannelField = ({ control, order }) => {
11975
+ const salesChannels = useComboboxData({
11976
+ queryFn: async (params) => {
11977
+ return await sdk.admin.salesChannel.list(params);
12296
11978
  },
11979
+ queryKey: ["sales-channels"],
12297
11980
  getOptions: (data) => {
12298
- return data.shipping_options.map((option) => {
12299
- var _a2;
12300
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12301
- (r) => r.attribute === "is_return" && r.value === "true"
12302
- )) {
12303
- return void 0;
12304
- }
12305
- return {
12306
- label: option.name,
12307
- value: option.id
12308
- };
12309
- }).filter(Boolean);
11981
+ return data.sales_channels.map((salesChannel) => ({
11982
+ label: salesChannel.name,
11983
+ value: salesChannel.id
11984
+ }));
12310
11985
  },
12311
- enabled: !!locationId && !!shippingProfileId,
12312
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11986
+ defaultValue: order.sales_channel_id || void 0
12313
11987
  });
12314
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12315
11988
  return /* @__PURE__ */ jsxRuntime.jsx(
12316
11989
  Form$2.Field,
12317
11990
  {
12318
11991
  control,
12319
- name: "shipping_option_id",
11992
+ name: "sales_channel_id",
12320
11993
  render: ({ field }) => {
12321
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12322
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12323
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12324
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12325
- ] }),
12326
- /* @__PURE__ */ jsxRuntime.jsx(
12327
- ConditionalTooltip,
11994
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11997
+ Combobox,
12328
11998
  {
12329
- content: tooltipContent,
12330
- showTooltip: !locationId || !shippingProfileId,
12331
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12332
- Combobox,
12333
- {
12334
- options: shippingOptions.options,
12335
- fetchNextPage: shippingOptions.fetchNextPage,
12336
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12337
- searchValue: shippingOptions.searchValue,
12338
- onSearchValueChange: shippingOptions.onSearchValueChange,
12339
- placeholder: "Select shipping option",
12340
- ...field,
12341
- disabled: !locationId || !shippingProfileId
12342
- }
12343
- ) }) })
11999
+ options: salesChannels.options,
12000
+ fetchNextPage: salesChannels.fetchNextPage,
12001
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
12002
+ searchValue: salesChannels.searchValue,
12003
+ onSearchValueChange: salesChannels.onSearchValueChange,
12004
+ placeholder: "Select sales channel",
12005
+ ...field
12344
12006
  }
12345
- )
12346
- ] }) });
12007
+ ) }),
12008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12009
+ ] });
12347
12010
  }
12348
12011
  }
12349
12012
  );
12350
12013
  };
12351
- const CustomAmountField = ({
12352
- control,
12353
- currencyCode
12354
- }) => {
12355
- return /* @__PURE__ */ jsxRuntime.jsx(
12356
- Form$2.Field,
12014
+ const schema$2 = objectType({
12015
+ sales_channel_id: stringType().min(1)
12016
+ });
12017
+ const ShippingAddress = () => {
12018
+ const { id } = reactRouterDom.useParams();
12019
+ const { order, isPending, isError, error } = useOrder(id, {
12020
+ fields: "+shipping_address"
12021
+ });
12022
+ if (isError) {
12023
+ throw error;
12024
+ }
12025
+ const isReady = !isPending && !!order;
12026
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12027
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12028
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12029
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12030
+ ] }),
12031
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12032
+ ] });
12033
+ };
12034
+ const ShippingAddressForm = ({ order }) => {
12035
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12036
+ const form = reactHookForm.useForm({
12037
+ defaultValues: {
12038
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12039
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12040
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12041
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12042
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12043
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12044
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12045
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12046
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12047
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12048
+ },
12049
+ resolver: zod.zodResolver(schema$1)
12050
+ });
12051
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12052
+ const { handleSuccess } = useRouteModal();
12053
+ const onSubmit = form.handleSubmit(async (data) => {
12054
+ await mutateAsync(
12055
+ {
12056
+ shipping_address: {
12057
+ first_name: data.first_name,
12058
+ last_name: data.last_name,
12059
+ company: data.company,
12060
+ address_1: data.address_1,
12061
+ address_2: data.address_2,
12062
+ city: data.city,
12063
+ province: data.province,
12064
+ country_code: data.country_code,
12065
+ postal_code: data.postal_code,
12066
+ phone: data.phone
12067
+ }
12068
+ },
12069
+ {
12070
+ onSuccess: () => {
12071
+ handleSuccess();
12072
+ },
12073
+ onError: (error) => {
12074
+ ui.toast.error(error.message);
12075
+ }
12076
+ }
12077
+ );
12078
+ });
12079
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12080
+ KeyboundForm,
12357
12081
  {
12358
- control,
12359
- name: "custom_amount",
12360
- render: ({ field: { onChange, ...field } }) => {
12361
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12362
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12363
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12364
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12082
+ className: "flex flex-1 flex-col overflow-hidden",
12083
+ onSubmit,
12084
+ children: [
12085
+ /* @__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: [
12086
+ /* @__PURE__ */ jsxRuntime.jsx(
12087
+ Form$2.Field,
12088
+ {
12089
+ control: form.control,
12090
+ name: "country_code",
12091
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12092
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12093
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12094
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12095
+ ] })
12096
+ }
12097
+ ),
12098
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12099
+ /* @__PURE__ */ jsxRuntime.jsx(
12100
+ Form$2.Field,
12101
+ {
12102
+ control: form.control,
12103
+ name: "first_name",
12104
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12105
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12106
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12107
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12108
+ ] })
12109
+ }
12110
+ ),
12111
+ /* @__PURE__ */ jsxRuntime.jsx(
12112
+ Form$2.Field,
12113
+ {
12114
+ control: form.control,
12115
+ name: "last_name",
12116
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12117
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12118
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12119
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12120
+ ] })
12121
+ }
12122
+ )
12365
12123
  ] }),
12366
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12367
- ui.CurrencyInput,
12124
+ /* @__PURE__ */ jsxRuntime.jsx(
12125
+ Form$2.Field,
12126
+ {
12127
+ control: form.control,
12128
+ name: "company",
12129
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12130
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12131
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12132
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12133
+ ] })
12134
+ }
12135
+ ),
12136
+ /* @__PURE__ */ jsxRuntime.jsx(
12137
+ Form$2.Field,
12138
+ {
12139
+ control: form.control,
12140
+ name: "address_1",
12141
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12142
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12143
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12144
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12145
+ ] })
12146
+ }
12147
+ ),
12148
+ /* @__PURE__ */ jsxRuntime.jsx(
12149
+ Form$2.Field,
12150
+ {
12151
+ control: form.control,
12152
+ name: "address_2",
12153
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12154
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12155
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12156
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12157
+ ] })
12158
+ }
12159
+ ),
12160
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12161
+ /* @__PURE__ */ jsxRuntime.jsx(
12162
+ Form$2.Field,
12163
+ {
12164
+ control: form.control,
12165
+ name: "postal_code",
12166
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12167
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12168
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12169
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12170
+ ] })
12171
+ }
12172
+ ),
12173
+ /* @__PURE__ */ jsxRuntime.jsx(
12174
+ Form$2.Field,
12175
+ {
12176
+ control: form.control,
12177
+ name: "city",
12178
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12179
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12180
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12181
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12182
+ ] })
12183
+ }
12184
+ )
12185
+ ] }),
12186
+ /* @__PURE__ */ jsxRuntime.jsx(
12187
+ Form$2.Field,
12188
+ {
12189
+ control: form.control,
12190
+ name: "province",
12191
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12192
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12193
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12194
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12195
+ ] })
12196
+ }
12197
+ ),
12198
+ /* @__PURE__ */ jsxRuntime.jsx(
12199
+ Form$2.Field,
12368
12200
  {
12369
- ...field,
12370
- onValueChange: (value) => onChange(value),
12371
- symbol: getNativeSymbol(currencyCode),
12372
- code: currencyCode
12201
+ control: form.control,
12202
+ name: "phone",
12203
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12204
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12205
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12206
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12207
+ ] })
12373
12208
  }
12374
- ) })
12375
- ] });
12376
- }
12209
+ )
12210
+ ] }) }),
12211
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12212
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12213
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12214
+ ] }) })
12215
+ ]
12377
12216
  }
12378
- );
12217
+ ) });
12379
12218
  };
12219
+ const schema$1 = addressSchema;
12380
12220
  const TransferOwnership = () => {
12381
12221
  const { id } = reactRouterDom.useParams();
12382
12222
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12400,7 +12240,7 @@ const TransferOwnershipForm = ({ order }) => {
12400
12240
  defaultValues: {
12401
12241
  customer_id: order.customer_id || ""
12402
12242
  },
12403
- resolver: zod.zodResolver(schema$1)
12243
+ resolver: zod.zodResolver(schema)
12404
12244
  });
12405
12245
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12406
12246
  const { handleSuccess } = useRouteModal();
@@ -12850,13 +12690,57 @@ const Illustration = () => {
12850
12690
  }
12851
12691
  );
12852
12692
  };
12853
- const schema$1 = objectType({
12693
+ const schema = objectType({
12854
12694
  customer_id: stringType().min(1)
12855
12695
  });
12856
- const BillingAddress = () => {
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: [
12709
+ /* @__PURE__ */ jsxRuntime.jsx(
12710
+ "div",
12711
+ {
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
+ })
12716
+ }
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
+ ]
12727
+ }
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 = () => {
12857
12741
  const { id } = reactRouterDom.useParams();
12858
12742
  const { order, isPending, isError, error } = useOrder(id, {
12859
- fields: "+billing_address"
12743
+ fields: "metadata"
12860
12744
  });
12861
12745
  if (isError) {
12862
12746
  throw error;
@@ -12864,36 +12748,33 @@ const BillingAddress = () => {
12864
12748
  const isReady = !isPending && !!order;
12865
12749
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12866
12750
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12867
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Billing Address" }) }),
12868
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the billing address for the draft order" }) })
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." }) })
12869
12753
  ] }),
12870
- isReady && /* @__PURE__ */ jsxRuntime.jsx(BillingAddressForm, { order })
12754
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12871
12755
  ] });
12872
12756
  };
12873
- const BillingAddressForm = ({ order }) => {
12874
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
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);
12875
12763
  const form = reactHookForm.useForm({
12876
12764
  defaultValues: {
12877
- first_name: ((_a = order.billing_address) == null ? void 0 : _a.first_name) ?? "",
12878
- last_name: ((_b = order.billing_address) == null ? void 0 : _b.last_name) ?? "",
12879
- company: ((_c = order.billing_address) == null ? void 0 : _c.company) ?? "",
12880
- address_1: ((_d = order.billing_address) == null ? void 0 : _d.address_1) ?? "",
12881
- address_2: ((_e = order.billing_address) == null ? void 0 : _e.address_2) ?? "",
12882
- city: ((_f = order.billing_address) == null ? void 0 : _f.city) ?? "",
12883
- province: ((_g = order.billing_address) == null ? void 0 : _g.province) ?? "",
12884
- country_code: ((_h = order.billing_address) == null ? void 0 : _h.country_code) ?? "",
12885
- postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
12886
- phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
12765
+ metadata: getDefaultValues(metadata)
12887
12766
  },
12888
- resolver: zod.zodResolver(schema)
12767
+ resolver: zod.zodResolver(MetadataSchema)
12889
12768
  });
12890
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12891
- const { handleSuccess } = useRouteModal();
12892
- const onSubmit = form.handleSubmit(async (data) => {
12769
+ const handleSubmit = form.handleSubmit(async (data) => {
12770
+ const parsedData = parseValues(data);
12893
12771
  await mutateAsync(
12894
- { billing_address: data },
12772
+ {
12773
+ metadata: parsedData
12774
+ },
12895
12775
  {
12896
12776
  onSuccess: () => {
12777
+ ui.toast.success("Metadata updated");
12897
12778
  handleSuccess();
12898
12779
  },
12899
12780
  onError: (error) => {
@@ -12902,147 +12783,266 @@ const BillingAddressForm = ({ order }) => {
12902
12783
  }
12903
12784
  );
12904
12785
  });
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
+ }
12905
12807
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12906
12808
  KeyboundForm,
12907
12809
  {
12810
+ onSubmit: handleSubmit,
12908
12811
  className: "flex flex-1 flex-col overflow-hidden",
12909
- onSubmit,
12910
12812
  children: [
12911
- /* @__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: [
12912
- /* @__PURE__ */ jsxRuntime.jsx(
12913
- Form$2.Field,
12914
- {
12915
- control: form.control,
12916
- name: "country_code",
12917
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12918
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12919
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12920
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12921
- ] })
12922
- }
12923
- ),
12924
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12925
- /* @__PURE__ */ jsxRuntime.jsx(
12926
- Form$2.Field,
12927
- {
12928
- control: form.control,
12929
- name: "first_name",
12930
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12931
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12932
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12933
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12934
- ] })
12935
- }
12936
- ),
12937
- /* @__PURE__ */ jsxRuntime.jsx(
12938
- Form$2.Field,
12939
- {
12940
- control: form.control,
12941
- name: "last_name",
12942
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12943
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12944
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12946
- ] })
12947
- }
12948
- )
12949
- ] }),
12950
- /* @__PURE__ */ jsxRuntime.jsx(
12951
- Form$2.Field,
12952
- {
12953
- control: form.control,
12954
- name: "company",
12955
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12956
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12957
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
- ] })
12960
- }
12961
- ),
12962
- /* @__PURE__ */ jsxRuntime.jsx(
12963
- Form$2.Field,
12964
- {
12965
- control: form.control,
12966
- name: "address_1",
12967
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12968
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12969
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12970
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12971
- ] })
12972
- }
12973
- ),
12974
- /* @__PURE__ */ jsxRuntime.jsx(
12975
- Form$2.Field,
12976
- {
12977
- control: form.control,
12978
- name: "address_2",
12979
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12980
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12981
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12982
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12983
- ] })
12984
- }
12985
- ),
12986
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12987
- /* @__PURE__ */ jsxRuntime.jsx(
12988
- Form$2.Field,
12989
- {
12990
- control: form.control,
12991
- name: "postal_code",
12992
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12993
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12994
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12996
- ] })
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" }) })
12818
+ ] }),
12819
+ fields.map((field, index) => {
12820
+ const isDisabled = field.disabled || false;
12821
+ let placeholder = "-";
12822
+ if (typeof field.value === "object") {
12823
+ placeholder = "{ ... }";
12997
12824
  }
12998
- ),
12999
- /* @__PURE__ */ jsxRuntime.jsx(
13000
- Form$2.Field,
13001
- {
13002
- control: form.control,
13003
- name: "city",
13004
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13005
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13006
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13007
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13008
- ] })
12825
+ if (Array.isArray(field.value)) {
12826
+ placeholder = "[ ... ]";
13009
12827
  }
13010
- )
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
+ })
13011
12938
  ] }),
13012
- /* @__PURE__ */ jsxRuntime.jsx(
13013
- Form$2.Field,
13014
- {
13015
- control: form.control,
13016
- name: "province",
13017
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
- ] })
13022
- }
13023
- ),
13024
- /* @__PURE__ */ jsxRuntime.jsx(
13025
- Form$2.Field,
13026
- {
13027
- control: form.control,
13028
- name: "phone",
13029
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13030
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13031
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13032
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13033
- ] })
13034
- }
13035
- )
13036
- ] }) }),
13037
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13038
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
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." })
12940
+ ] }),
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" }) }),
13039
12943
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13040
12944
  ] }) })
13041
12945
  ]
13042
12946
  }
13043
12947
  ) });
13044
12948
  };
13045
- const schema = addressSchema;
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
+ );
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
+ };
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
+ }
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13072,17 +13072,21 @@ const routeModule = {
13072
13072
  path: "/draft-orders/:id/email"
13073
13073
  },
13074
13074
  {
13075
- Component: Items,
13076
- path: "/draft-orders/:id/items"
13075
+ Component: BillingAddress,
13076
+ path: "/draft-orders/:id/billing-address"
13077
13077
  },
13078
13078
  {
13079
- Component: Metadata,
13080
- path: "/draft-orders/:id/metadata"
13079
+ Component: Items,
13080
+ path: "/draft-orders/:id/items"
13081
13081
  },
13082
13082
  {
13083
13083
  Component: Promotions,
13084
13084
  path: "/draft-orders/:id/promotions"
13085
13085
  },
13086
+ {
13087
+ Component: Shipping,
13088
+ path: "/draft-orders/:id/shipping"
13089
+ },
13086
13090
  {
13087
13091
  Component: SalesChannel,
13088
13092
  path: "/draft-orders/:id/sales-channel"
@@ -13091,17 +13095,13 @@ const routeModule = {
13091
13095
  Component: ShippingAddress,
13092
13096
  path: "/draft-orders/:id/shipping-address"
13093
13097
  },
13094
- {
13095
- Component: Shipping,
13096
- path: "/draft-orders/:id/shipping"
13097
- },
13098
13098
  {
13099
13099
  Component: TransferOwnership,
13100
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
13101
  },
13102
13102
  {
13103
- Component: BillingAddress,
13104
- path: "/draft-orders/:id/billing-address"
13103
+ Component: Metadata,
13104
+ path: "/draft-orders/:id/metadata"
13105
13105
  }
13106
13106
  ]
13107
13107
  }