@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.
@@ -9565,6 +9565,95 @@ const ID = () => {
9565
9565
  /* @__PURE__ */ jsx(Outlet, {})
9566
9566
  ] });
9567
9567
  };
9568
+ const CustomItems = () => {
9569
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9570
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9571
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
9572
+ ] });
9573
+ };
9574
+ const CustomItemsForm = () => {
9575
+ const form = useForm({
9576
+ resolver: zodResolver(schema$5)
9577
+ });
9578
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9579
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9580
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9581
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9582
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9583
+ ] }) })
9584
+ ] }) });
9585
+ };
9586
+ const schema$5 = objectType({
9587
+ email: stringType().email()
9588
+ });
9589
+ const Email = () => {
9590
+ const { id } = useParams();
9591
+ const { order, isPending, isError, error } = useOrder(id, {
9592
+ fields: "+email"
9593
+ });
9594
+ if (isError) {
9595
+ throw error;
9596
+ }
9597
+ const isReady = !isPending && !!order;
9598
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9599
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9600
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9601
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9602
+ ] }),
9603
+ isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9604
+ ] });
9605
+ };
9606
+ const EmailForm = ({ order }) => {
9607
+ const form = useForm({
9608
+ defaultValues: {
9609
+ email: order.email ?? ""
9610
+ },
9611
+ resolver: zodResolver(schema$4)
9612
+ });
9613
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9614
+ const { handleSuccess } = useRouteModal();
9615
+ const onSubmit = form.handleSubmit(async (data) => {
9616
+ await mutateAsync(
9617
+ { email: data.email },
9618
+ {
9619
+ onSuccess: () => {
9620
+ handleSuccess();
9621
+ },
9622
+ onError: (error) => {
9623
+ toast.error(error.message);
9624
+ }
9625
+ }
9626
+ );
9627
+ });
9628
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9629
+ KeyboundForm,
9630
+ {
9631
+ className: "flex flex-1 flex-col overflow-hidden",
9632
+ onSubmit,
9633
+ children: [
9634
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9635
+ Form$2.Field,
9636
+ {
9637
+ control: form.control,
9638
+ name: "email",
9639
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9640
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9641
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9642
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9643
+ ] })
9644
+ }
9645
+ ) }),
9646
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9647
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9648
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9649
+ ] }) })
9650
+ ]
9651
+ }
9652
+ ) });
9653
+ };
9654
+ const schema$4 = objectType({
9655
+ email: stringType().email()
9656
+ });
9568
9657
  const BillingAddress = () => {
9569
9658
  const { id } = useParams();
9570
9659
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9597,7 +9686,7 @@ const BillingAddressForm = ({ order }) => {
9597
9686
  postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
9598
9687
  phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
9599
9688
  },
9600
- resolver: zodResolver(schema$5)
9689
+ resolver: zodResolver(schema$3)
9601
9690
  });
9602
9691
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9603
9692
  const { handleSuccess } = useRouteModal();
@@ -9754,96 +9843,7 @@ const BillingAddressForm = ({ order }) => {
9754
9843
  }
9755
9844
  ) });
9756
9845
  };
9757
- const schema$5 = addressSchema;
9758
- const CustomItems = () => {
9759
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9760
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9761
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9762
- ] });
9763
- };
9764
- const CustomItemsForm = () => {
9765
- const form = useForm({
9766
- resolver: zodResolver(schema$4)
9767
- });
9768
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9769
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9770
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9772
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9773
- ] }) })
9774
- ] }) });
9775
- };
9776
- const schema$4 = objectType({
9777
- email: stringType().email()
9778
- });
9779
- const Email = () => {
9780
- const { id } = useParams();
9781
- const { order, isPending, isError, error } = useOrder(id, {
9782
- fields: "+email"
9783
- });
9784
- if (isError) {
9785
- throw error;
9786
- }
9787
- const isReady = !isPending && !!order;
9788
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9789
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9790
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Email" }) }),
9791
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9792
- ] }),
9793
- isReady && /* @__PURE__ */ jsx(EmailForm, { order })
9794
- ] });
9795
- };
9796
- const EmailForm = ({ order }) => {
9797
- const form = useForm({
9798
- defaultValues: {
9799
- email: order.email ?? ""
9800
- },
9801
- resolver: zodResolver(schema$3)
9802
- });
9803
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9804
- const { handleSuccess } = useRouteModal();
9805
- const onSubmit = form.handleSubmit(async (data) => {
9806
- await mutateAsync(
9807
- { email: data.email },
9808
- {
9809
- onSuccess: () => {
9810
- handleSuccess();
9811
- },
9812
- onError: (error) => {
9813
- toast.error(error.message);
9814
- }
9815
- }
9816
- );
9817
- });
9818
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9819
- KeyboundForm,
9820
- {
9821
- className: "flex flex-1 flex-col overflow-hidden",
9822
- onSubmit,
9823
- children: [
9824
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(
9825
- Form$2.Field,
9826
- {
9827
- control: form.control,
9828
- name: "email",
9829
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
9830
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Email" }),
9831
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
9832
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
9833
- ] })
9834
- }
9835
- ) }),
9836
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9837
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9838
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
9839
- ] }) })
9840
- ]
9841
- }
9842
- ) });
9843
- };
9844
- const schema$3 = objectType({
9845
- email: stringType().email()
9846
- });
9846
+ const schema$3 = addressSchema;
9847
9847
  const NumberInput = forwardRef(
9848
9848
  ({
9849
9849
  value,
@@ -10818,375 +10818,25 @@ const customItemSchema = objectType({
10818
10818
  quantity: numberType(),
10819
10819
  unit_price: unionType([numberType(), stringType()])
10820
10820
  });
10821
- const InlineTip = forwardRef(
10822
- ({ variant = "tip", label, className, children, ...props }, ref) => {
10823
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10824
- return /* @__PURE__ */ jsxs(
10825
- "div",
10826
- {
10827
- ref,
10828
- className: clx(
10829
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10830
- className
10831
- ),
10832
- ...props,
10833
- children: [
10834
- /* @__PURE__ */ jsx(
10835
- "div",
10836
- {
10837
- role: "presentation",
10838
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10839
- "bg-ui-tag-orange-icon": variant === "warning"
10840
- })
10841
- }
10842
- ),
10843
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10844
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10845
- labelValue,
10846
- ":"
10847
- ] }),
10848
- " ",
10849
- children
10850
- ] })
10851
- ]
10852
- }
10853
- );
10854
- }
10855
- );
10856
- InlineTip.displayName = "InlineTip";
10857
- const MetadataFieldSchema = objectType({
10858
- key: stringType(),
10859
- disabled: booleanType().optional(),
10860
- value: anyType()
10861
- });
10862
- const MetadataSchema = objectType({
10863
- metadata: arrayType(MetadataFieldSchema)
10864
- });
10865
- const Metadata = () => {
10866
- const { id } = useParams();
10867
- const { order, isPending, isError, error } = useOrder(id, {
10868
- fields: "metadata"
10821
+ const PROMOTION_QUERY_KEY = "promotions";
10822
+ const promotionsQueryKeys = {
10823
+ list: (query2) => [
10824
+ PROMOTION_QUERY_KEY,
10825
+ query2 ? query2 : void 0
10826
+ ],
10827
+ detail: (id, query2) => [
10828
+ PROMOTION_QUERY_KEY,
10829
+ id,
10830
+ query2 ? query2 : void 0
10831
+ ]
10832
+ };
10833
+ const usePromotions = (query2, options) => {
10834
+ const { data, ...rest } = useQuery({
10835
+ queryKey: promotionsQueryKeys.list(query2),
10836
+ queryFn: async () => sdk.admin.promotion.list(query2),
10837
+ ...options
10869
10838
  });
10870
- if (isError) {
10871
- throw error;
10872
- }
10873
- const isReady = !isPending && !!order;
10874
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10875
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10876
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10877
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10878
- ] }),
10879
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10880
- ] });
10881
- };
10882
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10883
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10884
- const MetadataForm = ({ orderId, metadata }) => {
10885
- const { handleSuccess } = useRouteModal();
10886
- const hasUneditableRows = getHasUneditableRows(metadata);
10887
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10888
- const form = useForm({
10889
- defaultValues: {
10890
- metadata: getDefaultValues(metadata)
10891
- },
10892
- resolver: zodResolver(MetadataSchema)
10893
- });
10894
- const handleSubmit = form.handleSubmit(async (data) => {
10895
- const parsedData = parseValues(data);
10896
- await mutateAsync(
10897
- {
10898
- metadata: parsedData
10899
- },
10900
- {
10901
- onSuccess: () => {
10902
- toast.success("Metadata updated");
10903
- handleSuccess();
10904
- },
10905
- onError: (error) => {
10906
- toast.error(error.message);
10907
- }
10908
- }
10909
- );
10910
- });
10911
- const { fields, insert, remove } = useFieldArray({
10912
- control: form.control,
10913
- name: "metadata"
10914
- });
10915
- function deleteRow(index) {
10916
- remove(index);
10917
- if (fields.length === 1) {
10918
- insert(0, {
10919
- key: "",
10920
- value: "",
10921
- disabled: false
10922
- });
10923
- }
10924
- }
10925
- function insertRow(index, position) {
10926
- insert(index + (position === "above" ? 0 : 1), {
10927
- key: "",
10928
- value: "",
10929
- disabled: false
10930
- });
10931
- }
10932
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10933
- KeyboundForm,
10934
- {
10935
- onSubmit: handleSubmit,
10936
- className: "flex flex-1 flex-col overflow-hidden",
10937
- children: [
10938
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10939
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10940
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10941
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10942
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10943
- ] }),
10944
- fields.map((field, index) => {
10945
- const isDisabled = field.disabled || false;
10946
- let placeholder = "-";
10947
- if (typeof field.value === "object") {
10948
- placeholder = "{ ... }";
10949
- }
10950
- if (Array.isArray(field.value)) {
10951
- placeholder = "[ ... ]";
10952
- }
10953
- return /* @__PURE__ */ jsx(
10954
- ConditionalTooltip,
10955
- {
10956
- showTooltip: isDisabled,
10957
- content: "This row is disabled because it contains non-primitive data.",
10958
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10959
- /* @__PURE__ */ jsxs(
10960
- "div",
10961
- {
10962
- className: clx("grid grid-cols-2 divide-x", {
10963
- "overflow-hidden rounded-b-lg": index === fields.length - 1
10964
- }),
10965
- children: [
10966
- /* @__PURE__ */ jsx(
10967
- Form$2.Field,
10968
- {
10969
- control: form.control,
10970
- name: `metadata.${index}.key`,
10971
- render: ({ field: field2 }) => {
10972
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10973
- GridInput,
10974
- {
10975
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10976
- ...field2,
10977
- disabled: isDisabled,
10978
- placeholder: "Key"
10979
- }
10980
- ) }) });
10981
- }
10982
- }
10983
- ),
10984
- /* @__PURE__ */ jsx(
10985
- Form$2.Field,
10986
- {
10987
- control: form.control,
10988
- name: `metadata.${index}.value`,
10989
- render: ({ field: { value, ...field2 } }) => {
10990
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10991
- GridInput,
10992
- {
10993
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10994
- ...field2,
10995
- value: isDisabled ? placeholder : value,
10996
- disabled: isDisabled,
10997
- placeholder: "Value"
10998
- }
10999
- ) }) });
11000
- }
11001
- }
11002
- )
11003
- ]
11004
- }
11005
- ),
11006
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
11007
- /* @__PURE__ */ jsx(
11008
- DropdownMenu.Trigger,
11009
- {
11010
- className: clx(
11011
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11012
- {
11013
- hidden: isDisabled
11014
- }
11015
- ),
11016
- disabled: isDisabled,
11017
- asChild: true,
11018
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11019
- }
11020
- ),
11021
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11022
- /* @__PURE__ */ jsxs(
11023
- DropdownMenu.Item,
11024
- {
11025
- className: "gap-x-2",
11026
- onClick: () => insertRow(index, "above"),
11027
- children: [
11028
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11029
- "Insert row above"
11030
- ]
11031
- }
11032
- ),
11033
- /* @__PURE__ */ jsxs(
11034
- DropdownMenu.Item,
11035
- {
11036
- className: "gap-x-2",
11037
- onClick: () => insertRow(index, "below"),
11038
- children: [
11039
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11040
- "Insert row below"
11041
- ]
11042
- }
11043
- ),
11044
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11045
- /* @__PURE__ */ jsxs(
11046
- DropdownMenu.Item,
11047
- {
11048
- className: "gap-x-2",
11049
- onClick: () => deleteRow(index),
11050
- children: [
11051
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11052
- "Delete row"
11053
- ]
11054
- }
11055
- )
11056
- ] })
11057
- ] })
11058
- ] })
11059
- },
11060
- field.id
11061
- );
11062
- })
11063
- ] }),
11064
- hasUneditableRows && /* @__PURE__ */ 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." })
11065
- ] }),
11066
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11067
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11068
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11069
- ] }) })
11070
- ]
11071
- }
11072
- ) });
11073
- };
11074
- const GridInput = forwardRef(({ className, ...props }, ref) => {
11075
- return /* @__PURE__ */ jsx(
11076
- "input",
11077
- {
11078
- ref,
11079
- ...props,
11080
- autoComplete: "off",
11081
- className: clx(
11082
- "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",
11083
- className
11084
- )
11085
- }
11086
- );
11087
- });
11088
- GridInput.displayName = "MetadataForm.GridInput";
11089
- const PlaceholderInner = () => {
11090
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11091
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11092
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11093
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11094
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11095
- ] }) })
11096
- ] });
11097
- };
11098
- const EDITABLE_TYPES = ["string", "number", "boolean"];
11099
- function getDefaultValues(metadata) {
11100
- if (!metadata || !Object.keys(metadata).length) {
11101
- return [
11102
- {
11103
- key: "",
11104
- value: "",
11105
- disabled: false
11106
- }
11107
- ];
11108
- }
11109
- return Object.entries(metadata).map(([key, value]) => {
11110
- if (!EDITABLE_TYPES.includes(typeof value)) {
11111
- return {
11112
- key,
11113
- value,
11114
- disabled: true
11115
- };
11116
- }
11117
- let stringValue = value;
11118
- if (typeof value !== "string") {
11119
- stringValue = JSON.stringify(value);
11120
- }
11121
- return {
11122
- key,
11123
- value: stringValue,
11124
- original_key: key
11125
- };
11126
- });
11127
- }
11128
- function parseValues(values) {
11129
- const metadata = values.metadata;
11130
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11131
- if (isEmpty) {
11132
- return null;
11133
- }
11134
- const update = {};
11135
- metadata.forEach((field) => {
11136
- let key = field.key;
11137
- let value = field.value;
11138
- const disabled = field.disabled;
11139
- if (!key || !value) {
11140
- return;
11141
- }
11142
- if (disabled) {
11143
- update[key] = value;
11144
- return;
11145
- }
11146
- key = key.trim();
11147
- value = value.trim();
11148
- if (value === "true") {
11149
- update[key] = true;
11150
- } else if (value === "false") {
11151
- update[key] = false;
11152
- } else {
11153
- const parsedNumber = parseFloat(value);
11154
- if (!isNaN(parsedNumber)) {
11155
- update[key] = parsedNumber;
11156
- } else {
11157
- update[key] = value;
11158
- }
11159
- }
11160
- });
11161
- return update;
11162
- }
11163
- function getHasUneditableRows(metadata) {
11164
- if (!metadata) {
11165
- return false;
11166
- }
11167
- return Object.values(metadata).some(
11168
- (value) => !EDITABLE_TYPES.includes(typeof value)
11169
- );
11170
- }
11171
- const PROMOTION_QUERY_KEY = "promotions";
11172
- const promotionsQueryKeys = {
11173
- list: (query2) => [
11174
- PROMOTION_QUERY_KEY,
11175
- query2 ? query2 : void 0
11176
- ],
11177
- detail: (id, query2) => [
11178
- PROMOTION_QUERY_KEY,
11179
- id,
11180
- query2 ? query2 : void 0
11181
- ]
11182
- };
11183
- const usePromotions = (query2, options) => {
11184
- const { data, ...rest } = useQuery({
11185
- queryKey: promotionsQueryKeys.list(query2),
11186
- queryFn: async () => sdk.admin.promotion.list(query2),
11187
- ...options
11188
- });
11189
- return { ...data, ...rest };
10839
+ return { ...data, ...rest };
11190
10840
  };
11191
10841
  const Promotions = () => {
11192
10842
  const { id } = useParams();
@@ -11445,112 +11095,6 @@ function getPromotionIds(items, shippingMethods) {
11445
11095
  }
11446
11096
  return Array.from(promotionIds);
11447
11097
  }
11448
- const SalesChannel = () => {
11449
- const { id } = useParams();
11450
- const { draft_order, isPending, isError, error } = useDraftOrder(
11451
- id,
11452
- {
11453
- fields: "+sales_channel_id"
11454
- },
11455
- {
11456
- enabled: !!id
11457
- }
11458
- );
11459
- if (isError) {
11460
- throw error;
11461
- }
11462
- const ISrEADY = !!draft_order && !isPending;
11463
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11464
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11465
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11466
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11467
- ] }),
11468
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11469
- ] });
11470
- };
11471
- const SalesChannelForm = ({ order }) => {
11472
- const form = useForm({
11473
- defaultValues: {
11474
- sales_channel_id: order.sales_channel_id || ""
11475
- },
11476
- resolver: zodResolver(schema$2)
11477
- });
11478
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11479
- const { handleSuccess } = useRouteModal();
11480
- const onSubmit = form.handleSubmit(async (data) => {
11481
- await mutateAsync(
11482
- {
11483
- sales_channel_id: data.sales_channel_id
11484
- },
11485
- {
11486
- onSuccess: () => {
11487
- toast.success("Sales channel updated");
11488
- handleSuccess();
11489
- },
11490
- onError: (error) => {
11491
- toast.error(error.message);
11492
- }
11493
- }
11494
- );
11495
- });
11496
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11497
- KeyboundForm,
11498
- {
11499
- className: "flex flex-1 flex-col overflow-hidden",
11500
- onSubmit,
11501
- children: [
11502
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11503
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11504
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11505
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11506
- ] }) })
11507
- ]
11508
- }
11509
- ) });
11510
- };
11511
- const SalesChannelField = ({ control, order }) => {
11512
- const salesChannels = useComboboxData({
11513
- queryFn: async (params) => {
11514
- return await sdk.admin.salesChannel.list(params);
11515
- },
11516
- queryKey: ["sales-channels"],
11517
- getOptions: (data) => {
11518
- return data.sales_channels.map((salesChannel) => ({
11519
- label: salesChannel.name,
11520
- value: salesChannel.id
11521
- }));
11522
- },
11523
- defaultValue: order.sales_channel_id || void 0
11524
- });
11525
- return /* @__PURE__ */ jsx(
11526
- Form$2.Field,
11527
- {
11528
- control,
11529
- name: "sales_channel_id",
11530
- render: ({ field }) => {
11531
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11532
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11533
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11534
- Combobox,
11535
- {
11536
- options: salesChannels.options,
11537
- fetchNextPage: salesChannels.fetchNextPage,
11538
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11539
- searchValue: salesChannels.searchValue,
11540
- onSearchValueChange: salesChannels.onSearchValueChange,
11541
- placeholder: "Select sales channel",
11542
- ...field
11543
- }
11544
- ) }),
11545
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11546
- ] });
11547
- }
11548
- }
11549
- );
11550
- };
11551
- const schema$2 = objectType({
11552
- sales_channel_id: stringType().min(1)
11553
- });
11554
11098
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11555
11099
  const Shipping = () => {
11556
11100
  var _a;
@@ -12289,75 +11833,384 @@ const ShippingOptionField = ({
12289
11833
  };
12290
11834
  }).filter(Boolean);
12291
11835
  },
12292
- enabled: !!locationId && !!shippingProfileId,
12293
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11836
+ enabled: !!locationId && !!shippingProfileId,
11837
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
11838
+ });
11839
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
11840
+ return /* @__PURE__ */ jsx(
11841
+ Form$2.Field,
11842
+ {
11843
+ control,
11844
+ name: "shipping_option_id",
11845
+ render: ({ field }) => {
11846
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11847
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11848
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
11849
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
11850
+ ] }),
11851
+ /* @__PURE__ */ jsx(
11852
+ ConditionalTooltip,
11853
+ {
11854
+ content: tooltipContent,
11855
+ showTooltip: !locationId || !shippingProfileId,
11856
+ children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11857
+ Combobox,
11858
+ {
11859
+ options: shippingOptions.options,
11860
+ fetchNextPage: shippingOptions.fetchNextPage,
11861
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
11862
+ searchValue: shippingOptions.searchValue,
11863
+ onSearchValueChange: shippingOptions.onSearchValueChange,
11864
+ placeholder: "Select shipping option",
11865
+ ...field,
11866
+ disabled: !locationId || !shippingProfileId
11867
+ }
11868
+ ) }) })
11869
+ }
11870
+ )
11871
+ ] }) });
11872
+ }
11873
+ }
11874
+ );
11875
+ };
11876
+ const CustomAmountField = ({
11877
+ control,
11878
+ currencyCode
11879
+ }) => {
11880
+ return /* @__PURE__ */ jsx(
11881
+ Form$2.Field,
11882
+ {
11883
+ control,
11884
+ name: "custom_amount",
11885
+ render: ({ field: { onChange, ...field } }) => {
11886
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11887
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11888
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
11889
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
11890
+ ] }),
11891
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11892
+ CurrencyInput,
11893
+ {
11894
+ ...field,
11895
+ onValueChange: (value) => onChange(value),
11896
+ symbol: getNativeSymbol(currencyCode),
11897
+ code: currencyCode
11898
+ }
11899
+ ) })
11900
+ ] });
11901
+ }
11902
+ }
11903
+ );
11904
+ };
11905
+ const SalesChannel = () => {
11906
+ const { id } = useParams();
11907
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11908
+ id,
11909
+ {
11910
+ fields: "+sales_channel_id"
11911
+ },
11912
+ {
11913
+ enabled: !!id
11914
+ }
11915
+ );
11916
+ if (isError) {
11917
+ throw error;
11918
+ }
11919
+ const ISrEADY = !!draft_order && !isPending;
11920
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11921
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11922
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11923
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11924
+ ] }),
11925
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11926
+ ] });
11927
+ };
11928
+ const SalesChannelForm = ({ order }) => {
11929
+ const form = useForm({
11930
+ defaultValues: {
11931
+ sales_channel_id: order.sales_channel_id || ""
11932
+ },
11933
+ resolver: zodResolver(schema$2)
11934
+ });
11935
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11936
+ const { handleSuccess } = useRouteModal();
11937
+ const onSubmit = form.handleSubmit(async (data) => {
11938
+ await mutateAsync(
11939
+ {
11940
+ sales_channel_id: data.sales_channel_id
11941
+ },
11942
+ {
11943
+ onSuccess: () => {
11944
+ toast.success("Sales channel updated");
11945
+ handleSuccess();
11946
+ },
11947
+ onError: (error) => {
11948
+ toast.error(error.message);
11949
+ }
11950
+ }
11951
+ );
11952
+ });
11953
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
11954
+ KeyboundForm,
11955
+ {
11956
+ className: "flex flex-1 flex-col overflow-hidden",
11957
+ onSubmit,
11958
+ children: [
11959
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11960
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11961
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11962
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11963
+ ] }) })
11964
+ ]
11965
+ }
11966
+ ) });
11967
+ };
11968
+ const SalesChannelField = ({ control, order }) => {
11969
+ const salesChannels = useComboboxData({
11970
+ queryFn: async (params) => {
11971
+ return await sdk.admin.salesChannel.list(params);
11972
+ },
11973
+ queryKey: ["sales-channels"],
11974
+ getOptions: (data) => {
11975
+ return data.sales_channels.map((salesChannel) => ({
11976
+ label: salesChannel.name,
11977
+ value: salesChannel.id
11978
+ }));
11979
+ },
11980
+ defaultValue: order.sales_channel_id || void 0
12294
11981
  });
12295
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12296
11982
  return /* @__PURE__ */ jsx(
12297
11983
  Form$2.Field,
12298
11984
  {
12299
11985
  control,
12300
- name: "shipping_option_id",
11986
+ name: "sales_channel_id",
12301
11987
  render: ({ field }) => {
12302
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12303
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12304
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Shipping option" }),
12305
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12306
- ] }),
12307
- /* @__PURE__ */ jsx(
12308
- ConditionalTooltip,
11988
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11989
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11990
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11991
+ Combobox,
12309
11992
  {
12310
- content: tooltipContent,
12311
- showTooltip: !locationId || !shippingProfileId,
12312
- children: /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12313
- Combobox,
12314
- {
12315
- options: shippingOptions.options,
12316
- fetchNextPage: shippingOptions.fetchNextPage,
12317
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12318
- searchValue: shippingOptions.searchValue,
12319
- onSearchValueChange: shippingOptions.onSearchValueChange,
12320
- placeholder: "Select shipping option",
12321
- ...field,
12322
- disabled: !locationId || !shippingProfileId
12323
- }
12324
- ) }) })
11993
+ options: salesChannels.options,
11994
+ fetchNextPage: salesChannels.fetchNextPage,
11995
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11996
+ searchValue: salesChannels.searchValue,
11997
+ onSearchValueChange: salesChannels.onSearchValueChange,
11998
+ placeholder: "Select sales channel",
11999
+ ...field
12325
12000
  }
12326
- )
12327
- ] }) });
12001
+ ) }),
12002
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12003
+ ] });
12328
12004
  }
12329
12005
  }
12330
12006
  );
12331
12007
  };
12332
- const CustomAmountField = ({
12333
- control,
12334
- currencyCode
12335
- }) => {
12336
- return /* @__PURE__ */ jsx(
12337
- Form$2.Field,
12008
+ const schema$2 = objectType({
12009
+ sales_channel_id: stringType().min(1)
12010
+ });
12011
+ const ShippingAddress = () => {
12012
+ const { id } = useParams();
12013
+ const { order, isPending, isError, error } = useOrder(id, {
12014
+ fields: "+shipping_address"
12015
+ });
12016
+ if (isError) {
12017
+ throw error;
12018
+ }
12019
+ const isReady = !isPending && !!order;
12020
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12021
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12022
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12023
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12024
+ ] }),
12025
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12026
+ ] });
12027
+ };
12028
+ const ShippingAddressForm = ({ order }) => {
12029
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12030
+ const form = useForm({
12031
+ defaultValues: {
12032
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12033
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12034
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12035
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12036
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12037
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12038
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12039
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12040
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12041
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12042
+ },
12043
+ resolver: zodResolver(schema$1)
12044
+ });
12045
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12046
+ const { handleSuccess } = useRouteModal();
12047
+ const onSubmit = form.handleSubmit(async (data) => {
12048
+ await mutateAsync(
12049
+ {
12050
+ shipping_address: {
12051
+ first_name: data.first_name,
12052
+ last_name: data.last_name,
12053
+ company: data.company,
12054
+ address_1: data.address_1,
12055
+ address_2: data.address_2,
12056
+ city: data.city,
12057
+ province: data.province,
12058
+ country_code: data.country_code,
12059
+ postal_code: data.postal_code,
12060
+ phone: data.phone
12061
+ }
12062
+ },
12063
+ {
12064
+ onSuccess: () => {
12065
+ handleSuccess();
12066
+ },
12067
+ onError: (error) => {
12068
+ toast.error(error.message);
12069
+ }
12070
+ }
12071
+ );
12072
+ });
12073
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12074
+ KeyboundForm,
12338
12075
  {
12339
- control,
12340
- name: "custom_amount",
12341
- render: ({ field: { onChange, ...field } }) => {
12342
- return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12343
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
12344
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12345
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12076
+ className: "flex flex-1 flex-col overflow-hidden",
12077
+ onSubmit,
12078
+ children: [
12079
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12080
+ /* @__PURE__ */ jsx(
12081
+ Form$2.Field,
12082
+ {
12083
+ control: form.control,
12084
+ name: "country_code",
12085
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12086
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12087
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12088
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12089
+ ] })
12090
+ }
12091
+ ),
12092
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12093
+ /* @__PURE__ */ jsx(
12094
+ Form$2.Field,
12095
+ {
12096
+ control: form.control,
12097
+ name: "first_name",
12098
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12099
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12100
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12101
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12102
+ ] })
12103
+ }
12104
+ ),
12105
+ /* @__PURE__ */ jsx(
12106
+ Form$2.Field,
12107
+ {
12108
+ control: form.control,
12109
+ name: "last_name",
12110
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12111
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12112
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12113
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12114
+ ] })
12115
+ }
12116
+ )
12346
12117
  ] }),
12347
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12348
- CurrencyInput,
12118
+ /* @__PURE__ */ jsx(
12119
+ Form$2.Field,
12349
12120
  {
12350
- ...field,
12351
- onValueChange: (value) => onChange(value),
12352
- symbol: getNativeSymbol(currencyCode),
12353
- code: currencyCode
12121
+ control: form.control,
12122
+ name: "company",
12123
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12124
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12125
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12126
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12127
+ ] })
12128
+ }
12129
+ ),
12130
+ /* @__PURE__ */ jsx(
12131
+ Form$2.Field,
12132
+ {
12133
+ control: form.control,
12134
+ name: "address_1",
12135
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12136
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12137
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12138
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12139
+ ] })
12140
+ }
12141
+ ),
12142
+ /* @__PURE__ */ jsx(
12143
+ Form$2.Field,
12144
+ {
12145
+ control: form.control,
12146
+ name: "address_2",
12147
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12148
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12149
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12150
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12151
+ ] })
12152
+ }
12153
+ ),
12154
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12155
+ /* @__PURE__ */ jsx(
12156
+ Form$2.Field,
12157
+ {
12158
+ control: form.control,
12159
+ name: "postal_code",
12160
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12161
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12162
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12163
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12164
+ ] })
12165
+ }
12166
+ ),
12167
+ /* @__PURE__ */ jsx(
12168
+ Form$2.Field,
12169
+ {
12170
+ control: form.control,
12171
+ name: "city",
12172
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12173
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12174
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12175
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12176
+ ] })
12177
+ }
12178
+ )
12179
+ ] }),
12180
+ /* @__PURE__ */ jsx(
12181
+ Form$2.Field,
12182
+ {
12183
+ control: form.control,
12184
+ name: "province",
12185
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12186
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12187
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12188
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12189
+ ] })
12190
+ }
12191
+ ),
12192
+ /* @__PURE__ */ jsx(
12193
+ Form$2.Field,
12194
+ {
12195
+ control: form.control,
12196
+ name: "phone",
12197
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12198
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
12199
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12200
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12201
+ ] })
12354
12202
  }
12355
- ) })
12356
- ] });
12357
- }
12203
+ )
12204
+ ] }) }),
12205
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
12206
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12207
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12208
+ ] }) })
12209
+ ]
12358
12210
  }
12359
- );
12211
+ ) });
12360
12212
  };
12213
+ const schema$1 = addressSchema;
12361
12214
  const TransferOwnership = () => {
12362
12215
  const { id } = useParams();
12363
12216
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12381,7 +12234,7 @@ const TransferOwnershipForm = ({ order }) => {
12381
12234
  defaultValues: {
12382
12235
  customer_id: order.customer_id || ""
12383
12236
  },
12384
- resolver: zodResolver(schema$1)
12237
+ resolver: zodResolver(schema)
12385
12238
  });
12386
12239
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12387
12240
  const { handleSuccess } = useRouteModal();
@@ -12831,13 +12684,57 @@ const Illustration = () => {
12831
12684
  }
12832
12685
  );
12833
12686
  };
12834
- const schema$1 = objectType({
12687
+ const schema = objectType({
12835
12688
  customer_id: stringType().min(1)
12836
12689
  });
12837
- const ShippingAddress = () => {
12690
+ const InlineTip = forwardRef(
12691
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
12692
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
12693
+ return /* @__PURE__ */ jsxs(
12694
+ "div",
12695
+ {
12696
+ ref,
12697
+ className: clx(
12698
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
12699
+ className
12700
+ ),
12701
+ ...props,
12702
+ children: [
12703
+ /* @__PURE__ */ jsx(
12704
+ "div",
12705
+ {
12706
+ role: "presentation",
12707
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
12708
+ "bg-ui-tag-orange-icon": variant === "warning"
12709
+ })
12710
+ }
12711
+ ),
12712
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
12713
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
12714
+ labelValue,
12715
+ ":"
12716
+ ] }),
12717
+ " ",
12718
+ children
12719
+ ] })
12720
+ ]
12721
+ }
12722
+ );
12723
+ }
12724
+ );
12725
+ InlineTip.displayName = "InlineTip";
12726
+ const MetadataFieldSchema = objectType({
12727
+ key: stringType(),
12728
+ disabled: booleanType().optional(),
12729
+ value: anyType()
12730
+ });
12731
+ const MetadataSchema = objectType({
12732
+ metadata: arrayType(MetadataFieldSchema)
12733
+ });
12734
+ const Metadata = () => {
12838
12735
  const { id } = useParams();
12839
12736
  const { order, isPending, isError, error } = useOrder(id, {
12840
- fields: "+shipping_address"
12737
+ fields: "metadata"
12841
12738
  });
12842
12739
  if (isError) {
12843
12740
  throw error;
@@ -12845,49 +12742,33 @@ const ShippingAddress = () => {
12845
12742
  const isReady = !isPending && !!order;
12846
12743
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12847
12744
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12848
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12849
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12745
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
12746
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
12850
12747
  ] }),
12851
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12748
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
12852
12749
  ] });
12853
12750
  };
12854
- const ShippingAddressForm = ({ order }) => {
12855
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12751
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
12752
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
12753
+ const MetadataForm = ({ orderId, metadata }) => {
12754
+ const { handleSuccess } = useRouteModal();
12755
+ const hasUneditableRows = getHasUneditableRows(metadata);
12756
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
12856
12757
  const form = useForm({
12857
12758
  defaultValues: {
12858
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12859
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12860
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12861
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12862
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12863
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12864
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12865
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12866
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12867
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12759
+ metadata: getDefaultValues(metadata)
12868
12760
  },
12869
- resolver: zodResolver(schema)
12761
+ resolver: zodResolver(MetadataSchema)
12870
12762
  });
12871
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12872
- const { handleSuccess } = useRouteModal();
12873
- const onSubmit = form.handleSubmit(async (data) => {
12763
+ const handleSubmit = form.handleSubmit(async (data) => {
12764
+ const parsedData = parseValues(data);
12874
12765
  await mutateAsync(
12875
12766
  {
12876
- shipping_address: {
12877
- first_name: data.first_name,
12878
- last_name: data.last_name,
12879
- company: data.company,
12880
- address_1: data.address_1,
12881
- address_2: data.address_2,
12882
- city: data.city,
12883
- province: data.province,
12884
- country_code: data.country_code,
12885
- postal_code: data.postal_code,
12886
- phone: data.phone
12887
- }
12767
+ metadata: parsedData
12888
12768
  },
12889
12769
  {
12890
12770
  onSuccess: () => {
12771
+ toast.success("Metadata updated");
12891
12772
  handleSuccess();
12892
12773
  },
12893
12774
  onError: (error) => {
@@ -12896,147 +12777,266 @@ const ShippingAddressForm = ({ order }) => {
12896
12777
  }
12897
12778
  );
12898
12779
  });
12780
+ const { fields, insert, remove } = useFieldArray({
12781
+ control: form.control,
12782
+ name: "metadata"
12783
+ });
12784
+ function deleteRow(index) {
12785
+ remove(index);
12786
+ if (fields.length === 1) {
12787
+ insert(0, {
12788
+ key: "",
12789
+ value: "",
12790
+ disabled: false
12791
+ });
12792
+ }
12793
+ }
12794
+ function insertRow(index, position) {
12795
+ insert(index + (position === "above" ? 0 : 1), {
12796
+ key: "",
12797
+ value: "",
12798
+ disabled: false
12799
+ });
12800
+ }
12899
12801
  return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12900
12802
  KeyboundForm,
12901
12803
  {
12804
+ onSubmit: handleSubmit,
12902
12805
  className: "flex flex-1 flex-col overflow-hidden",
12903
- onSubmit,
12904
12806
  children: [
12905
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12906
- /* @__PURE__ */ jsx(
12907
- Form$2.Field,
12908
- {
12909
- control: form.control,
12910
- name: "country_code",
12911
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12912
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12913
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12914
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12915
- ] })
12916
- }
12917
- ),
12918
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12919
- /* @__PURE__ */ jsx(
12920
- Form$2.Field,
12921
- {
12922
- control: form.control,
12923
- name: "first_name",
12924
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12925
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12926
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12927
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12928
- ] })
12929
- }
12930
- ),
12931
- /* @__PURE__ */ jsx(
12932
- Form$2.Field,
12933
- {
12934
- control: form.control,
12935
- name: "last_name",
12936
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12937
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12938
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12939
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12940
- ] })
12941
- }
12942
- )
12943
- ] }),
12944
- /* @__PURE__ */ jsx(
12945
- Form$2.Field,
12946
- {
12947
- control: form.control,
12948
- name: "company",
12949
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12950
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12951
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12952
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12953
- ] })
12954
- }
12955
- ),
12956
- /* @__PURE__ */ jsx(
12957
- Form$2.Field,
12958
- {
12959
- control: form.control,
12960
- name: "address_1",
12961
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12962
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12963
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12964
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12965
- ] })
12966
- }
12967
- ),
12968
- /* @__PURE__ */ jsx(
12969
- Form$2.Field,
12970
- {
12971
- control: form.control,
12972
- name: "address_2",
12973
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12974
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12975
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12976
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12977
- ] })
12978
- }
12979
- ),
12980
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12981
- /* @__PURE__ */ jsx(
12982
- Form$2.Field,
12983
- {
12984
- control: form.control,
12985
- name: "postal_code",
12986
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12987
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12988
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12989
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12990
- ] })
12807
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
12808
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
12809
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
12810
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
12811
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
12812
+ ] }),
12813
+ fields.map((field, index) => {
12814
+ const isDisabled = field.disabled || false;
12815
+ let placeholder = "-";
12816
+ if (typeof field.value === "object") {
12817
+ placeholder = "{ ... }";
12991
12818
  }
12992
- ),
12993
- /* @__PURE__ */ jsx(
12994
- Form$2.Field,
12995
- {
12996
- control: form.control,
12997
- name: "city",
12998
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12999
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
13000
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13001
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13002
- ] })
12819
+ if (Array.isArray(field.value)) {
12820
+ placeholder = "[ ... ]";
13003
12821
  }
13004
- )
12822
+ return /* @__PURE__ */ jsx(
12823
+ ConditionalTooltip,
12824
+ {
12825
+ showTooltip: isDisabled,
12826
+ content: "This row is disabled because it contains non-primitive data.",
12827
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
12828
+ /* @__PURE__ */ jsxs(
12829
+ "div",
12830
+ {
12831
+ className: clx("grid grid-cols-2 divide-x", {
12832
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
12833
+ }),
12834
+ children: [
12835
+ /* @__PURE__ */ jsx(
12836
+ Form$2.Field,
12837
+ {
12838
+ control: form.control,
12839
+ name: `metadata.${index}.key`,
12840
+ render: ({ field: field2 }) => {
12841
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12842
+ GridInput,
12843
+ {
12844
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
12845
+ ...field2,
12846
+ disabled: isDisabled,
12847
+ placeholder: "Key"
12848
+ }
12849
+ ) }) });
12850
+ }
12851
+ }
12852
+ ),
12853
+ /* @__PURE__ */ jsx(
12854
+ Form$2.Field,
12855
+ {
12856
+ control: form.control,
12857
+ name: `metadata.${index}.value`,
12858
+ render: ({ field: { value, ...field2 } }) => {
12859
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
12860
+ GridInput,
12861
+ {
12862
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
12863
+ ...field2,
12864
+ value: isDisabled ? placeholder : value,
12865
+ disabled: isDisabled,
12866
+ placeholder: "Value"
12867
+ }
12868
+ ) }) });
12869
+ }
12870
+ }
12871
+ )
12872
+ ]
12873
+ }
12874
+ ),
12875
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
12876
+ /* @__PURE__ */ jsx(
12877
+ DropdownMenu.Trigger,
12878
+ {
12879
+ className: clx(
12880
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
12881
+ {
12882
+ hidden: isDisabled
12883
+ }
12884
+ ),
12885
+ disabled: isDisabled,
12886
+ asChild: true,
12887
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
12888
+ }
12889
+ ),
12890
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
12891
+ /* @__PURE__ */ jsxs(
12892
+ DropdownMenu.Item,
12893
+ {
12894
+ className: "gap-x-2",
12895
+ onClick: () => insertRow(index, "above"),
12896
+ children: [
12897
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
12898
+ "Insert row above"
12899
+ ]
12900
+ }
12901
+ ),
12902
+ /* @__PURE__ */ jsxs(
12903
+ DropdownMenu.Item,
12904
+ {
12905
+ className: "gap-x-2",
12906
+ onClick: () => insertRow(index, "below"),
12907
+ children: [
12908
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
12909
+ "Insert row below"
12910
+ ]
12911
+ }
12912
+ ),
12913
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
12914
+ /* @__PURE__ */ jsxs(
12915
+ DropdownMenu.Item,
12916
+ {
12917
+ className: "gap-x-2",
12918
+ onClick: () => deleteRow(index),
12919
+ children: [
12920
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
12921
+ "Delete row"
12922
+ ]
12923
+ }
12924
+ )
12925
+ ] })
12926
+ ] })
12927
+ ] })
12928
+ },
12929
+ field.id
12930
+ );
12931
+ })
13005
12932
  ] }),
13006
- /* @__PURE__ */ jsx(
13007
- Form$2.Field,
13008
- {
13009
- control: form.control,
13010
- name: "province",
13011
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13012
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13013
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13014
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13015
- ] })
13016
- }
13017
- ),
13018
- /* @__PURE__ */ jsx(
13019
- Form$2.Field,
13020
- {
13021
- control: form.control,
13022
- name: "phone",
13023
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13024
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13025
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13026
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13027
- ] })
13028
- }
13029
- )
13030
- ] }) }),
13031
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13032
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12933
+ hasUneditableRows && /* @__PURE__ */ 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." })
12934
+ ] }),
12935
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12936
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
13033
12937
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13034
12938
  ] }) })
13035
12939
  ]
13036
12940
  }
13037
12941
  ) });
13038
12942
  };
13039
- const schema = addressSchema;
12943
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
12944
+ return /* @__PURE__ */ jsx(
12945
+ "input",
12946
+ {
12947
+ ref,
12948
+ ...props,
12949
+ autoComplete: "off",
12950
+ className: clx(
12951
+ "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",
12952
+ className
12953
+ )
12954
+ }
12955
+ );
12956
+ });
12957
+ GridInput.displayName = "MetadataForm.GridInput";
12958
+ const PlaceholderInner = () => {
12959
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
12960
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
12961
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12962
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
12963
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
12964
+ ] }) })
12965
+ ] });
12966
+ };
12967
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
12968
+ function getDefaultValues(metadata) {
12969
+ if (!metadata || !Object.keys(metadata).length) {
12970
+ return [
12971
+ {
12972
+ key: "",
12973
+ value: "",
12974
+ disabled: false
12975
+ }
12976
+ ];
12977
+ }
12978
+ return Object.entries(metadata).map(([key, value]) => {
12979
+ if (!EDITABLE_TYPES.includes(typeof value)) {
12980
+ return {
12981
+ key,
12982
+ value,
12983
+ disabled: true
12984
+ };
12985
+ }
12986
+ let stringValue = value;
12987
+ if (typeof value !== "string") {
12988
+ stringValue = JSON.stringify(value);
12989
+ }
12990
+ return {
12991
+ key,
12992
+ value: stringValue,
12993
+ original_key: key
12994
+ };
12995
+ });
12996
+ }
12997
+ function parseValues(values) {
12998
+ const metadata = values.metadata;
12999
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
13000
+ if (isEmpty) {
13001
+ return null;
13002
+ }
13003
+ const update = {};
13004
+ metadata.forEach((field) => {
13005
+ let key = field.key;
13006
+ let value = field.value;
13007
+ const disabled = field.disabled;
13008
+ if (!key || !value) {
13009
+ return;
13010
+ }
13011
+ if (disabled) {
13012
+ update[key] = value;
13013
+ return;
13014
+ }
13015
+ key = key.trim();
13016
+ value = value.trim();
13017
+ if (value === "true") {
13018
+ update[key] = true;
13019
+ } else if (value === "false") {
13020
+ update[key] = false;
13021
+ } else {
13022
+ const parsedNumber = parseFloat(value);
13023
+ if (!isNaN(parsedNumber)) {
13024
+ update[key] = parsedNumber;
13025
+ } else {
13026
+ update[key] = value;
13027
+ }
13028
+ }
13029
+ });
13030
+ return update;
13031
+ }
13032
+ function getHasUneditableRows(metadata) {
13033
+ if (!metadata) {
13034
+ return false;
13035
+ }
13036
+ return Object.values(metadata).some(
13037
+ (value) => !EDITABLE_TYPES.includes(typeof value)
13038
+ );
13039
+ }
13040
13040
  const widgetModule = { widgets: [] };
13041
13041
  const routeModule = {
13042
13042
  routes: [
@@ -13057,10 +13057,6 @@ const routeModule = {
13057
13057
  handle,
13058
13058
  loader,
13059
13059
  children: [
13060
- {
13061
- Component: BillingAddress,
13062
- path: "/draft-orders/:id/billing-address"
13063
- },
13064
13060
  {
13065
13061
  Component: CustomItems,
13066
13062
  path: "/draft-orders/:id/custom-items"
@@ -13070,32 +13066,36 @@ const routeModule = {
13070
13066
  path: "/draft-orders/:id/email"
13071
13067
  },
13072
13068
  {
13073
- Component: Items,
13074
- path: "/draft-orders/:id/items"
13069
+ Component: BillingAddress,
13070
+ path: "/draft-orders/:id/billing-address"
13075
13071
  },
13076
13072
  {
13077
- Component: Metadata,
13078
- path: "/draft-orders/:id/metadata"
13073
+ Component: Items,
13074
+ path: "/draft-orders/:id/items"
13079
13075
  },
13080
13076
  {
13081
13077
  Component: Promotions,
13082
13078
  path: "/draft-orders/:id/promotions"
13083
13079
  },
13080
+ {
13081
+ Component: Shipping,
13082
+ path: "/draft-orders/:id/shipping"
13083
+ },
13084
13084
  {
13085
13085
  Component: SalesChannel,
13086
13086
  path: "/draft-orders/:id/sales-channel"
13087
13087
  },
13088
13088
  {
13089
- Component: Shipping,
13090
- path: "/draft-orders/:id/shipping"
13089
+ Component: ShippingAddress,
13090
+ path: "/draft-orders/:id/shipping-address"
13091
13091
  },
13092
13092
  {
13093
13093
  Component: TransferOwnership,
13094
13094
  path: "/draft-orders/:id/transfer-ownership"
13095
13095
  },
13096
13096
  {
13097
- Component: ShippingAddress,
13098
- path: "/draft-orders/:id/shipping-address"
13097
+ Component: Metadata,
13098
+ path: "/draft-orders/:id/metadata"
13099
13099
  }
13100
13100
  ]
13101
13101
  }