@medusajs/draft-order 2.11.1-preview-20251024060204 → 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.
@@ -9571,6 +9571,95 @@ const ID = () => {
9571
9571
  /* @__PURE__ */ jsxRuntime.jsx(reactRouterDom.Outlet, {})
9572
9572
  ] });
9573
9573
  };
9574
+ const CustomItems = () => {
9575
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9576
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9577
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9578
+ ] });
9579
+ };
9580
+ const CustomItemsForm = () => {
9581
+ const form = reactHookForm.useForm({
9582
+ resolver: zod.zodResolver(schema$5)
9583
+ });
9584
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9585
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9586
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9587
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9588
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9589
+ ] }) })
9590
+ ] }) });
9591
+ };
9592
+ const schema$5 = objectType({
9593
+ email: stringType().email()
9594
+ });
9595
+ const Email = () => {
9596
+ const { id } = reactRouterDom.useParams();
9597
+ const { order, isPending, isError, error } = useOrder(id, {
9598
+ fields: "+email"
9599
+ });
9600
+ if (isError) {
9601
+ throw error;
9602
+ }
9603
+ const isReady = !isPending && !!order;
9604
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9605
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9606
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9607
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9608
+ ] }),
9609
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9610
+ ] });
9611
+ };
9612
+ const EmailForm = ({ order }) => {
9613
+ const form = reactHookForm.useForm({
9614
+ defaultValues: {
9615
+ email: order.email ?? ""
9616
+ },
9617
+ resolver: zod.zodResolver(schema$4)
9618
+ });
9619
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9620
+ const { handleSuccess } = useRouteModal();
9621
+ const onSubmit = form.handleSubmit(async (data) => {
9622
+ await mutateAsync(
9623
+ { email: data.email },
9624
+ {
9625
+ onSuccess: () => {
9626
+ handleSuccess();
9627
+ },
9628
+ onError: (error) => {
9629
+ ui.toast.error(error.message);
9630
+ }
9631
+ }
9632
+ );
9633
+ });
9634
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9635
+ KeyboundForm,
9636
+ {
9637
+ className: "flex flex-1 flex-col overflow-hidden",
9638
+ onSubmit,
9639
+ children: [
9640
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9641
+ Form$2.Field,
9642
+ {
9643
+ control: form.control,
9644
+ name: "email",
9645
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9646
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9647
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9649
+ ] })
9650
+ }
9651
+ ) }),
9652
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9653
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9654
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9655
+ ] }) })
9656
+ ]
9657
+ }
9658
+ ) });
9659
+ };
9660
+ const schema$4 = objectType({
9661
+ email: stringType().email()
9662
+ });
9574
9663
  const BillingAddress = () => {
9575
9664
  const { id } = reactRouterDom.useParams();
9576
9665
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9603,7 +9692,7 @@ const BillingAddressForm = ({ order }) => {
9603
9692
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9604
9693
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9605
9694
  },
9606
- resolver: zod.zodResolver(schema$5)
9695
+ resolver: zod.zodResolver(schema$3)
9607
9696
  });
9608
9697
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9609
9698
  const { handleSuccess } = useRouteModal();
@@ -9760,96 +9849,7 @@ const BillingAddressForm = ({ order }) => {
9760
9849
  }
9761
9850
  ) });
9762
9851
  };
9763
- const schema$5 = addressSchema;
9764
- const CustomItems = () => {
9765
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9766
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9767
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9768
- ] });
9769
- };
9770
- const CustomItemsForm = () => {
9771
- const form = reactHookForm.useForm({
9772
- resolver: zod.zodResolver(schema$4)
9773
- });
9774
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9775
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9776
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9777
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9778
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9779
- ] }) })
9780
- ] }) });
9781
- };
9782
- const schema$4 = objectType({
9783
- email: stringType().email()
9784
- });
9785
- const Email = () => {
9786
- const { id } = reactRouterDom.useParams();
9787
- const { order, isPending, isError, error } = useOrder(id, {
9788
- fields: "+email"
9789
- });
9790
- if (isError) {
9791
- throw error;
9792
- }
9793
- const isReady = !isPending && !!order;
9794
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9795
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9796
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9797
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9798
- ] }),
9799
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9800
- ] });
9801
- };
9802
- const EmailForm = ({ order }) => {
9803
- const form = reactHookForm.useForm({
9804
- defaultValues: {
9805
- email: order.email ?? ""
9806
- },
9807
- resolver: zod.zodResolver(schema$3)
9808
- });
9809
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9810
- const { handleSuccess } = useRouteModal();
9811
- const onSubmit = form.handleSubmit(async (data) => {
9812
- await mutateAsync(
9813
- { email: data.email },
9814
- {
9815
- onSuccess: () => {
9816
- handleSuccess();
9817
- },
9818
- onError: (error) => {
9819
- ui.toast.error(error.message);
9820
- }
9821
- }
9822
- );
9823
- });
9824
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9825
- KeyboundForm,
9826
- {
9827
- className: "flex flex-1 flex-col overflow-hidden",
9828
- onSubmit,
9829
- children: [
9830
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9831
- Form$2.Field,
9832
- {
9833
- control: form.control,
9834
- name: "email",
9835
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9836
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9837
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9838
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9839
- ] })
9840
- }
9841
- ) }),
9842
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9843
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9844
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9845
- ] }) })
9846
- ]
9847
- }
9848
- ) });
9849
- };
9850
- const schema$3 = objectType({
9851
- email: stringType().email()
9852
- });
9852
+ const schema$3 = addressSchema;
9853
9853
  const NumberInput = React.forwardRef(
9854
9854
  ({
9855
9855
  value,
@@ -10824,375 +10824,25 @@ const customItemSchema = objectType({
10824
10824
  quantity: numberType(),
10825
10825
  unit_price: unionType([numberType(), stringType()])
10826
10826
  });
10827
- const InlineTip = React.forwardRef(
10828
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10829
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10830
- return /* @__PURE__ */ jsxRuntime.jsxs(
10831
- "div",
10832
- {
10833
- ref,
10834
- className: ui.clx(
10835
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10836
- className
10837
- ),
10838
- ...props,
10839
- children: [
10840
- /* @__PURE__ */ jsxRuntime.jsx(
10841
- "div",
10842
- {
10843
- role: "presentation",
10844
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10845
- "bg-ui-tag-orange-icon": variant === "warning"
10846
- })
10847
- }
10848
- ),
10849
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10850
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10851
- labelValue,
10852
- ":"
10853
- ] }),
10854
- " ",
10855
- children
10856
- ] })
10857
- ]
10858
- }
10859
- );
10860
- }
10861
- );
10862
- InlineTip.displayName = "InlineTip";
10863
- const MetadataFieldSchema = objectType({
10864
- key: stringType(),
10865
- disabled: booleanType().optional(),
10866
- value: anyType()
10867
- });
10868
- const MetadataSchema = objectType({
10869
- metadata: arrayType(MetadataFieldSchema)
10870
- });
10871
- const Metadata = () => {
10872
- const { id } = reactRouterDom.useParams();
10873
- const { order, isPending, isError, error } = useOrder(id, {
10874
- fields: "metadata"
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
10875
10844
  });
10876
- if (isError) {
10877
- throw error;
10878
- }
10879
- const isReady = !isPending && !!order;
10880
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10881
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10882
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10883
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10884
- ] }),
10885
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10886
- ] });
10887
- };
10888
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10889
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10890
- const MetadataForm = ({ orderId, metadata }) => {
10891
- const { handleSuccess } = useRouteModal();
10892
- const hasUneditableRows = getHasUneditableRows(metadata);
10893
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10894
- const form = reactHookForm.useForm({
10895
- defaultValues: {
10896
- metadata: getDefaultValues(metadata)
10897
- },
10898
- resolver: zod.zodResolver(MetadataSchema)
10899
- });
10900
- const handleSubmit = form.handleSubmit(async (data) => {
10901
- const parsedData = parseValues(data);
10902
- await mutateAsync(
10903
- {
10904
- metadata: parsedData
10905
- },
10906
- {
10907
- onSuccess: () => {
10908
- ui.toast.success("Metadata updated");
10909
- handleSuccess();
10910
- },
10911
- onError: (error) => {
10912
- ui.toast.error(error.message);
10913
- }
10914
- }
10915
- );
10916
- });
10917
- const { fields, insert, remove } = reactHookForm.useFieldArray({
10918
- control: form.control,
10919
- name: "metadata"
10920
- });
10921
- function deleteRow(index) {
10922
- remove(index);
10923
- if (fields.length === 1) {
10924
- insert(0, {
10925
- key: "",
10926
- value: "",
10927
- disabled: false
10928
- });
10929
- }
10930
- }
10931
- function insertRow(index, position) {
10932
- insert(index + (position === "above" ? 0 : 1), {
10933
- key: "",
10934
- value: "",
10935
- disabled: false
10936
- });
10937
- }
10938
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10939
- KeyboundForm,
10940
- {
10941
- onSubmit: handleSubmit,
10942
- className: "flex flex-1 flex-col overflow-hidden",
10943
- children: [
10944
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10945
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10946
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10947
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10948
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10949
- ] }),
10950
- fields.map((field, index) => {
10951
- const isDisabled = field.disabled || false;
10952
- let placeholder = "-";
10953
- if (typeof field.value === "object") {
10954
- placeholder = "{ ... }";
10955
- }
10956
- if (Array.isArray(field.value)) {
10957
- placeholder = "[ ... ]";
10958
- }
10959
- return /* @__PURE__ */ jsxRuntime.jsx(
10960
- ConditionalTooltip,
10961
- {
10962
- showTooltip: isDisabled,
10963
- content: "This row is disabled because it contains non-primitive data.",
10964
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10965
- /* @__PURE__ */ jsxRuntime.jsxs(
10966
- "div",
10967
- {
10968
- className: ui.clx("grid grid-cols-2 divide-x", {
10969
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10970
- }),
10971
- children: [
10972
- /* @__PURE__ */ jsxRuntime.jsx(
10973
- Form$2.Field,
10974
- {
10975
- control: form.control,
10976
- name: `metadata.${index}.key`,
10977
- render: ({ field: field2 }) => {
10978
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10979
- GridInput,
10980
- {
10981
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10982
- ...field2,
10983
- disabled: isDisabled,
10984
- placeholder: "Key"
10985
- }
10986
- ) }) });
10987
- }
10988
- }
10989
- ),
10990
- /* @__PURE__ */ jsxRuntime.jsx(
10991
- Form$2.Field,
10992
- {
10993
- control: form.control,
10994
- name: `metadata.${index}.value`,
10995
- render: ({ field: { value, ...field2 } }) => {
10996
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10997
- GridInput,
10998
- {
10999
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
11000
- ...field2,
11001
- value: isDisabled ? placeholder : value,
11002
- disabled: isDisabled,
11003
- placeholder: "Value"
11004
- }
11005
- ) }) });
11006
- }
11007
- }
11008
- )
11009
- ]
11010
- }
11011
- ),
11012
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11013
- /* @__PURE__ */ jsxRuntime.jsx(
11014
- ui.DropdownMenu.Trigger,
11015
- {
11016
- className: ui.clx(
11017
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11018
- {
11019
- hidden: isDisabled
11020
- }
11021
- ),
11022
- disabled: isDisabled,
11023
- asChild: true,
11024
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11025
- }
11026
- ),
11027
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11028
- /* @__PURE__ */ jsxRuntime.jsxs(
11029
- ui.DropdownMenu.Item,
11030
- {
11031
- className: "gap-x-2",
11032
- onClick: () => insertRow(index, "above"),
11033
- children: [
11034
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11035
- "Insert row above"
11036
- ]
11037
- }
11038
- ),
11039
- /* @__PURE__ */ jsxRuntime.jsxs(
11040
- ui.DropdownMenu.Item,
11041
- {
11042
- className: "gap-x-2",
11043
- onClick: () => insertRow(index, "below"),
11044
- children: [
11045
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11046
- "Insert row below"
11047
- ]
11048
- }
11049
- ),
11050
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11051
- /* @__PURE__ */ jsxRuntime.jsxs(
11052
- ui.DropdownMenu.Item,
11053
- {
11054
- className: "gap-x-2",
11055
- onClick: () => deleteRow(index),
11056
- children: [
11057
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11058
- "Delete row"
11059
- ]
11060
- }
11061
- )
11062
- ] })
11063
- ] })
11064
- ] })
11065
- },
11066
- field.id
11067
- );
11068
- })
11069
- ] }),
11070
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11071
- ] }),
11072
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11073
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11074
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11075
- ] }) })
11076
- ]
11077
- }
11078
- ) });
11079
- };
11080
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11081
- return /* @__PURE__ */ jsxRuntime.jsx(
11082
- "input",
11083
- {
11084
- ref,
11085
- ...props,
11086
- autoComplete: "off",
11087
- className: ui.clx(
11088
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11089
- className
11090
- )
11091
- }
11092
- );
11093
- });
11094
- GridInput.displayName = "MetadataForm.GridInput";
11095
- const PlaceholderInner = () => {
11096
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11097
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11098
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11099
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11100
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11101
- ] }) })
11102
- ] });
11103
- };
11104
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11105
- function getDefaultValues(metadata) {
11106
- if (!metadata || !Object.keys(metadata).length) {
11107
- return [
11108
- {
11109
- key: "",
11110
- value: "",
11111
- disabled: false
11112
- }
11113
- ];
11114
- }
11115
- return Object.entries(metadata).map(([key, value]) => {
11116
- if (!EDITABLE_TYPES.includes(typeof value)) {
11117
- return {
11118
- key,
11119
- value,
11120
- disabled: true
11121
- };
11122
- }
11123
- let stringValue = value;
11124
- if (typeof value !== "string") {
11125
- stringValue = JSON.stringify(value);
11126
- }
11127
- return {
11128
- key,
11129
- value: stringValue,
11130
- original_key: key
11131
- };
11132
- });
11133
- }
11134
- function parseValues(values) {
11135
- const metadata = values.metadata;
11136
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11137
- if (isEmpty) {
11138
- return null;
11139
- }
11140
- const update = {};
11141
- metadata.forEach((field) => {
11142
- let key = field.key;
11143
- let value = field.value;
11144
- const disabled = field.disabled;
11145
- if (!key || !value) {
11146
- return;
11147
- }
11148
- if (disabled) {
11149
- update[key] = value;
11150
- return;
11151
- }
11152
- key = key.trim();
11153
- value = value.trim();
11154
- if (value === "true") {
11155
- update[key] = true;
11156
- } else if (value === "false") {
11157
- update[key] = false;
11158
- } else {
11159
- const parsedNumber = parseFloat(value);
11160
- if (!isNaN(parsedNumber)) {
11161
- update[key] = parsedNumber;
11162
- } else {
11163
- update[key] = value;
11164
- }
11165
- }
11166
- });
11167
- return update;
11168
- }
11169
- function getHasUneditableRows(metadata) {
11170
- if (!metadata) {
11171
- return false;
11172
- }
11173
- return Object.values(metadata).some(
11174
- (value) => !EDITABLE_TYPES.includes(typeof value)
11175
- );
11176
- }
11177
- const PROMOTION_QUERY_KEY = "promotions";
11178
- const promotionsQueryKeys = {
11179
- list: (query2) => [
11180
- PROMOTION_QUERY_KEY,
11181
- query2 ? query2 : void 0
11182
- ],
11183
- detail: (id, query2) => [
11184
- PROMOTION_QUERY_KEY,
11185
- id,
11186
- query2 ? query2 : void 0
11187
- ]
11188
- };
11189
- const usePromotions = (query2, options) => {
11190
- const { data, ...rest } = reactQuery.useQuery({
11191
- queryKey: promotionsQueryKeys.list(query2),
11192
- queryFn: async () => sdk.admin.promotion.list(query2),
11193
- ...options
11194
- });
11195
- return { ...data, ...rest };
10845
+ return { ...data, ...rest };
11196
10846
  };
11197
10847
  const Promotions = () => {
11198
10848
  const { id } = reactRouterDom.useParams();
@@ -11451,112 +11101,6 @@ function getPromotionIds(items, shippingMethods) {
11451
11101
  }
11452
11102
  return Array.from(promotionIds);
11453
11103
  }
11454
- const SalesChannel = () => {
11455
- const { id } = reactRouterDom.useParams();
11456
- const { draft_order, isPending, isError, error } = useDraftOrder(
11457
- id,
11458
- {
11459
- fields: "+sales_channel_id"
11460
- },
11461
- {
11462
- enabled: !!id
11463
- }
11464
- );
11465
- if (isError) {
11466
- throw error;
11467
- }
11468
- const ISrEADY = !!draft_order && !isPending;
11469
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11470
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11471
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11472
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11473
- ] }),
11474
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11475
- ] });
11476
- };
11477
- const SalesChannelForm = ({ order }) => {
11478
- const form = reactHookForm.useForm({
11479
- defaultValues: {
11480
- sales_channel_id: order.sales_channel_id || ""
11481
- },
11482
- resolver: zod.zodResolver(schema$2)
11483
- });
11484
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11485
- const { handleSuccess } = useRouteModal();
11486
- const onSubmit = form.handleSubmit(async (data) => {
11487
- await mutateAsync(
11488
- {
11489
- sales_channel_id: data.sales_channel_id
11490
- },
11491
- {
11492
- onSuccess: () => {
11493
- ui.toast.success("Sales channel updated");
11494
- handleSuccess();
11495
- },
11496
- onError: (error) => {
11497
- ui.toast.error(error.message);
11498
- }
11499
- }
11500
- );
11501
- });
11502
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11503
- KeyboundForm,
11504
- {
11505
- className: "flex flex-1 flex-col overflow-hidden",
11506
- onSubmit,
11507
- children: [
11508
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11509
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11510
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11511
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11512
- ] }) })
11513
- ]
11514
- }
11515
- ) });
11516
- };
11517
- const SalesChannelField = ({ control, order }) => {
11518
- const salesChannels = useComboboxData({
11519
- queryFn: async (params) => {
11520
- return await sdk.admin.salesChannel.list(params);
11521
- },
11522
- queryKey: ["sales-channels"],
11523
- getOptions: (data) => {
11524
- return data.sales_channels.map((salesChannel) => ({
11525
- label: salesChannel.name,
11526
- value: salesChannel.id
11527
- }));
11528
- },
11529
- defaultValue: order.sales_channel_id || void 0
11530
- });
11531
- return /* @__PURE__ */ jsxRuntime.jsx(
11532
- Form$2.Field,
11533
- {
11534
- control,
11535
- name: "sales_channel_id",
11536
- render: ({ field }) => {
11537
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11538
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11539
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11540
- Combobox,
11541
- {
11542
- options: salesChannels.options,
11543
- fetchNextPage: salesChannels.fetchNextPage,
11544
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11545
- searchValue: salesChannels.searchValue,
11546
- onSearchValueChange: salesChannels.onSearchValueChange,
11547
- placeholder: "Select sales channel",
11548
- ...field
11549
- }
11550
- ) }),
11551
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11552
- ] });
11553
- }
11554
- }
11555
- );
11556
- };
11557
- const schema$2 = objectType({
11558
- sales_channel_id: stringType().min(1)
11559
- });
11560
11104
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11561
11105
  const Shipping = () => {
11562
11106
  var _a;
@@ -12295,75 +11839,384 @@ const ShippingOptionField = ({
12295
11839
  };
12296
11840
  }).filter(Boolean);
12297
11841
  },
12298
- enabled: !!locationId && !!shippingProfileId,
12299
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
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);
11978
+ },
11979
+ queryKey: ["sales-channels"],
11980
+ getOptions: (data) => {
11981
+ return data.sales_channels.map((salesChannel) => ({
11982
+ label: salesChannel.name,
11983
+ value: salesChannel.id
11984
+ }));
11985
+ },
11986
+ defaultValue: order.sales_channel_id || void 0
12300
11987
  });
12301
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12302
11988
  return /* @__PURE__ */ jsxRuntime.jsx(
12303
11989
  Form$2.Field,
12304
11990
  {
12305
11991
  control,
12306
- name: "shipping_option_id",
11992
+ name: "sales_channel_id",
12307
11993
  render: ({ field }) => {
12308
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12309
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12310
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12311
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12312
- ] }),
12313
- /* @__PURE__ */ jsxRuntime.jsx(
12314
- 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,
12315
11998
  {
12316
- content: tooltipContent,
12317
- showTooltip: !locationId || !shippingProfileId,
12318
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12319
- Combobox,
12320
- {
12321
- options: shippingOptions.options,
12322
- fetchNextPage: shippingOptions.fetchNextPage,
12323
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12324
- searchValue: shippingOptions.searchValue,
12325
- onSearchValueChange: shippingOptions.onSearchValueChange,
12326
- placeholder: "Select shipping option",
12327
- ...field,
12328
- disabled: !locationId || !shippingProfileId
12329
- }
12330
- ) }) })
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
12331
12006
  }
12332
- )
12333
- ] }) });
12007
+ ) }),
12008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12009
+ ] });
12334
12010
  }
12335
12011
  }
12336
12012
  );
12337
12013
  };
12338
- const CustomAmountField = ({
12339
- control,
12340
- currencyCode
12341
- }) => {
12342
- return /* @__PURE__ */ jsxRuntime.jsx(
12343
- 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,
12344
12081
  {
12345
- control,
12346
- name: "custom_amount",
12347
- render: ({ field: { onChange, ...field } }) => {
12348
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12349
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12350
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12351
- /* @__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
+ )
12352
12123
  ] }),
12353
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12354
- ui.CurrencyInput,
12124
+ /* @__PURE__ */ jsxRuntime.jsx(
12125
+ Form$2.Field,
12355
12126
  {
12356
- ...field,
12357
- onValueChange: (value) => onChange(value),
12358
- symbol: getNativeSymbol(currencyCode),
12359
- code: currencyCode
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,
12200
+ {
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
+ ] })
12360
12208
  }
12361
- ) })
12362
- ] });
12363
- }
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
+ ]
12364
12216
  }
12365
- );
12217
+ ) });
12366
12218
  };
12219
+ const schema$1 = addressSchema;
12367
12220
  const TransferOwnership = () => {
12368
12221
  const { id } = reactRouterDom.useParams();
12369
12222
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12387,7 +12240,7 @@ const TransferOwnershipForm = ({ order }) => {
12387
12240
  defaultValues: {
12388
12241
  customer_id: order.customer_id || ""
12389
12242
  },
12390
- resolver: zod.zodResolver(schema$1)
12243
+ resolver: zod.zodResolver(schema)
12391
12244
  });
12392
12245
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12393
12246
  const { handleSuccess } = useRouteModal();
@@ -12837,13 +12690,57 @@ const Illustration = () => {
12837
12690
  }
12838
12691
  );
12839
12692
  };
12840
- const schema$1 = objectType({
12693
+ const schema = objectType({
12841
12694
  customer_id: stringType().min(1)
12842
12695
  });
12843
- const ShippingAddress = () => {
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 = () => {
12844
12741
  const { id } = reactRouterDom.useParams();
12845
12742
  const { order, isPending, isError, error } = useOrder(id, {
12846
- fields: "+shipping_address"
12743
+ fields: "metadata"
12847
12744
  });
12848
12745
  if (isError) {
12849
12746
  throw error;
@@ -12851,49 +12748,33 @@ const ShippingAddress = () => {
12851
12748
  const isReady = !isPending && !!order;
12852
12749
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12853
12750
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12854
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12855
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping 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." }) })
12856
12753
  ] }),
12857
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12754
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12858
12755
  ] });
12859
12756
  };
12860
- const ShippingAddressForm = ({ order }) => {
12861
- 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);
12862
12763
  const form = reactHookForm.useForm({
12863
12764
  defaultValues: {
12864
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12865
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12866
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12867
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12868
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12869
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12870
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12871
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12872
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12873
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12765
+ metadata: getDefaultValues(metadata)
12874
12766
  },
12875
- resolver: zod.zodResolver(schema)
12767
+ resolver: zod.zodResolver(MetadataSchema)
12876
12768
  });
12877
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12878
- const { handleSuccess } = useRouteModal();
12879
- const onSubmit = form.handleSubmit(async (data) => {
12769
+ const handleSubmit = form.handleSubmit(async (data) => {
12770
+ const parsedData = parseValues(data);
12880
12771
  await mutateAsync(
12881
12772
  {
12882
- shipping_address: {
12883
- first_name: data.first_name,
12884
- last_name: data.last_name,
12885
- company: data.company,
12886
- address_1: data.address_1,
12887
- address_2: data.address_2,
12888
- city: data.city,
12889
- province: data.province,
12890
- country_code: data.country_code,
12891
- postal_code: data.postal_code,
12892
- phone: data.phone
12893
- }
12773
+ metadata: parsedData
12894
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 ShippingAddressForm = ({ 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: [
@@ -13063,10 +13063,6 @@ const routeModule = {
13063
13063
  handle,
13064
13064
  loader,
13065
13065
  children: [
13066
- {
13067
- Component: BillingAddress,
13068
- path: "/draft-orders/:id/billing-address"
13069
- },
13070
13066
  {
13071
13067
  Component: CustomItems,
13072
13068
  path: "/draft-orders/:id/custom-items"
@@ -13076,32 +13072,36 @@ const routeModule = {
13076
13072
  path: "/draft-orders/:id/email"
13077
13073
  },
13078
13074
  {
13079
- Component: Items,
13080
- path: "/draft-orders/:id/items"
13075
+ Component: BillingAddress,
13076
+ path: "/draft-orders/:id/billing-address"
13081
13077
  },
13082
13078
  {
13083
- Component: Metadata,
13084
- path: "/draft-orders/:id/metadata"
13079
+ Component: Items,
13080
+ path: "/draft-orders/:id/items"
13085
13081
  },
13086
13082
  {
13087
13083
  Component: Promotions,
13088
13084
  path: "/draft-orders/:id/promotions"
13089
13085
  },
13086
+ {
13087
+ Component: Shipping,
13088
+ path: "/draft-orders/:id/shipping"
13089
+ },
13090
13090
  {
13091
13091
  Component: SalesChannel,
13092
13092
  path: "/draft-orders/:id/sales-channel"
13093
13093
  },
13094
13094
  {
13095
- Component: Shipping,
13096
- path: "/draft-orders/:id/shipping"
13095
+ Component: ShippingAddress,
13096
+ path: "/draft-orders/:id/shipping-address"
13097
13097
  },
13098
13098
  {
13099
13099
  Component: TransferOwnership,
13100
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
13101
  },
13102
13102
  {
13103
- Component: ShippingAddress,
13104
- path: "/draft-orders/:id/shipping-address"
13103
+ Component: Metadata,
13104
+ path: "/draft-orders/:id/metadata"
13105
13105
  }
13106
13106
  ]
13107
13107
  }