@medusajs/draft-order 2.11.2-preview-20251029032258 → 2.11.2-preview-20251029090152

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.
@@ -9782,74 +9782,6 @@ const CustomItemsForm = () => {
9782
9782
  const schema$4 = objectType({
9783
9783
  email: stringType().email()
9784
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
- });
9853
9785
  const NumberInput = React.forwardRef(
9854
9786
  ({
9855
9787
  value,
@@ -10824,54 +10756,10 @@ const customItemSchema = objectType({
10824
10756
  quantity: numberType(),
10825
10757
  unit_price: unionType([numberType(), stringType()])
10826
10758
  });
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 = () => {
10759
+ const Email = () => {
10872
10760
  const { id } = reactRouterDom.useParams();
10873
10761
  const { order, isPending, isError, error } = useOrder(id, {
10874
- fields: "metadata"
10762
+ fields: "+email"
10875
10763
  });
10876
10764
  if (isError) {
10877
10765
  throw error;
@@ -10879,33 +10767,26 @@ const Metadata = () => {
10879
10767
  const isReady = !isPending && !!order;
10880
10768
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10881
10769
  /* @__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." }) })
10770
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
10771
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
10884
10772
  ] }),
10885
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10773
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
10886
10774
  ] });
10887
10775
  };
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);
10776
+ const EmailForm = ({ order }) => {
10894
10777
  const form = reactHookForm.useForm({
10895
10778
  defaultValues: {
10896
- metadata: getDefaultValues(metadata)
10779
+ email: order.email ?? ""
10897
10780
  },
10898
- resolver: zod.zodResolver(MetadataSchema)
10781
+ resolver: zod.zodResolver(schema$3)
10899
10782
  });
10900
- const handleSubmit = form.handleSubmit(async (data) => {
10901
- const parsedData = parseValues(data);
10783
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10784
+ const { handleSuccess } = useRouteModal();
10785
+ const onSubmit = form.handleSubmit(async (data) => {
10902
10786
  await mutateAsync(
10903
- {
10904
- metadata: parsedData
10905
- },
10787
+ { email: data.email },
10906
10788
  {
10907
10789
  onSuccess: () => {
10908
- ui.toast.success("Metadata updated");
10909
10790
  handleSuccess();
10910
10791
  },
10911
10792
  onError: (error) => {
@@ -10914,266 +10795,35 @@ const MetadataForm = ({ orderId, metadata }) => {
10914
10795
  }
10915
10796
  );
10916
10797
  });
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
10798
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10939
10799
  KeyboundForm,
10940
10800
  {
10941
- onSubmit: handleSubmit,
10942
10801
  className: "flex flex-1 flex-col overflow-hidden",
10802
+ onSubmit,
10943
10803
  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" }) }),
10804
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
10805
+ Form$2.Field,
10806
+ {
10807
+ control: form.control,
10808
+ name: "email",
10809
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
10810
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
10811
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10812
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10813
+ ] })
10814
+ }
10815
+ ) }),
10816
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10817
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11074
10818
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11075
10819
  ] }) })
11076
10820
  ]
11077
10821
  }
11078
10822
  ) });
11079
10823
  };
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
- );
10824
+ const schema$3 = objectType({
10825
+ email: stringType().email()
11093
10826
  });
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
10827
  const PROMOTION_QUERY_KEY = "promotions";
11178
10828
  const promotionsQueryKeys = {
11179
10829
  list: (query2) => [
@@ -11451,10 +11101,54 @@ function getPromotionIds(items, shippingMethods) {
11451
11101
  }
11452
11102
  return Array.from(promotionIds);
11453
11103
  }
11454
- const ShippingAddress = () => {
11104
+ const InlineTip = React.forwardRef(
11105
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
11106
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
11107
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11108
+ "div",
11109
+ {
11110
+ ref,
11111
+ className: ui.clx(
11112
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
11113
+ className
11114
+ ),
11115
+ ...props,
11116
+ children: [
11117
+ /* @__PURE__ */ jsxRuntime.jsx(
11118
+ "div",
11119
+ {
11120
+ role: "presentation",
11121
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
11122
+ "bg-ui-tag-orange-icon": variant === "warning"
11123
+ })
11124
+ }
11125
+ ),
11126
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
11127
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
11128
+ labelValue,
11129
+ ":"
11130
+ ] }),
11131
+ " ",
11132
+ children
11133
+ ] })
11134
+ ]
11135
+ }
11136
+ );
11137
+ }
11138
+ );
11139
+ InlineTip.displayName = "InlineTip";
11140
+ const MetadataFieldSchema = objectType({
11141
+ key: stringType(),
11142
+ disabled: booleanType().optional(),
11143
+ value: anyType()
11144
+ });
11145
+ const MetadataSchema = objectType({
11146
+ metadata: arrayType(MetadataFieldSchema)
11147
+ });
11148
+ const Metadata = () => {
11455
11149
  const { id } = reactRouterDom.useParams();
11456
11150
  const { order, isPending, isError, error } = useOrder(id, {
11457
- fields: "+shipping_address"
11151
+ fields: "metadata"
11458
11152
  });
11459
11153
  if (isError) {
11460
11154
  throw error;
@@ -11462,49 +11156,33 @@ const ShippingAddress = () => {
11462
11156
  const isReady = !isPending && !!order;
11463
11157
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11464
11158
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11465
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11466
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11159
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
11160
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
11467
11161
  ] }),
11468
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11162
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11469
11163
  ] });
11470
11164
  };
11471
- const ShippingAddressForm = ({ order }) => {
11472
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11165
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
11166
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
11167
+ const MetadataForm = ({ orderId, metadata }) => {
11168
+ const { handleSuccess } = useRouteModal();
11169
+ const hasUneditableRows = getHasUneditableRows(metadata);
11170
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11473
11171
  const form = reactHookForm.useForm({
11474
11172
  defaultValues: {
11475
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11476
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11477
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11478
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11479
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11480
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11481
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11482
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11483
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11484
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11173
+ metadata: getDefaultValues(metadata)
11485
11174
  },
11486
- resolver: zod.zodResolver(schema$2)
11175
+ resolver: zod.zodResolver(MetadataSchema)
11487
11176
  });
11488
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11489
- const { handleSuccess } = useRouteModal();
11490
- const onSubmit = form.handleSubmit(async (data) => {
11177
+ const handleSubmit = form.handleSubmit(async (data) => {
11178
+ const parsedData = parseValues(data);
11491
11179
  await mutateAsync(
11492
11180
  {
11493
- shipping_address: {
11494
- first_name: data.first_name,
11495
- last_name: data.last_name,
11496
- company: data.company,
11497
- address_1: data.address_1,
11498
- address_2: data.address_2,
11499
- city: data.city,
11500
- province: data.province,
11501
- country_code: data.country_code,
11502
- postal_code: data.postal_code,
11503
- phone: data.phone
11504
- }
11181
+ metadata: parsedData
11505
11182
  },
11506
11183
  {
11507
11184
  onSuccess: () => {
11185
+ ui.toast.success("Metadata updated");
11508
11186
  handleSuccess();
11509
11187
  },
11510
11188
  onError: (error) => {
@@ -11513,138 +11191,321 @@ const ShippingAddressForm = ({ order }) => {
11513
11191
  }
11514
11192
  );
11515
11193
  });
11516
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11517
- KeyboundForm,
11518
- {
11519
- className: "flex flex-1 flex-col overflow-hidden",
11520
- onSubmit,
11521
- children: [
11522
- /* @__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: [
11523
- /* @__PURE__ */ jsxRuntime.jsx(
11524
- Form$2.Field,
11525
- {
11526
- control: form.control,
11527
- name: "country_code",
11528
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11529
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11530
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11532
- ] })
11533
- }
11534
- ),
11535
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11536
- /* @__PURE__ */ jsxRuntime.jsx(
11537
- Form$2.Field,
11538
- {
11539
- control: form.control,
11540
- name: "first_name",
11541
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11542
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11543
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11545
- ] })
11546
- }
11547
- ),
11548
- /* @__PURE__ */ jsxRuntime.jsx(
11549
- Form$2.Field,
11550
- {
11551
- control: form.control,
11552
- name: "last_name",
11553
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11554
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11555
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11557
- ] })
11558
- }
11559
- )
11560
- ] }),
11561
- /* @__PURE__ */ jsxRuntime.jsx(
11562
- Form$2.Field,
11563
- {
11564
- control: form.control,
11565
- name: "company",
11566
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11567
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11568
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11569
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11570
- ] })
11571
- }
11572
- ),
11573
- /* @__PURE__ */ jsxRuntime.jsx(
11574
- Form$2.Field,
11575
- {
11576
- control: form.control,
11577
- name: "address_1",
11578
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11579
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11580
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11581
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11582
- ] })
11583
- }
11584
- ),
11585
- /* @__PURE__ */ jsxRuntime.jsx(
11586
- Form$2.Field,
11587
- {
11588
- control: form.control,
11589
- name: "address_2",
11590
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11591
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11592
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11593
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11594
- ] })
11595
- }
11596
- ),
11597
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11598
- /* @__PURE__ */ jsxRuntime.jsx(
11599
- Form$2.Field,
11600
- {
11601
- control: form.control,
11602
- name: "postal_code",
11603
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11604
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11605
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11606
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11607
- ] })
11194
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
11195
+ control: form.control,
11196
+ name: "metadata"
11197
+ });
11198
+ function deleteRow(index) {
11199
+ remove(index);
11200
+ if (fields.length === 1) {
11201
+ insert(0, {
11202
+ key: "",
11203
+ value: "",
11204
+ disabled: false
11205
+ });
11206
+ }
11207
+ }
11208
+ function insertRow(index, position) {
11209
+ insert(index + (position === "above" ? 0 : 1), {
11210
+ key: "",
11211
+ value: "",
11212
+ disabled: false
11213
+ });
11214
+ }
11215
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11216
+ KeyboundForm,
11217
+ {
11218
+ onSubmit: handleSubmit,
11219
+ className: "flex flex-1 flex-col overflow-hidden",
11220
+ children: [
11221
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
11222
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
11223
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
11224
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
11225
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11226
+ ] }),
11227
+ fields.map((field, index) => {
11228
+ const isDisabled = field.disabled || false;
11229
+ let placeholder = "-";
11230
+ if (typeof field.value === "object") {
11231
+ placeholder = "{ ... }";
11608
11232
  }
11609
- ),
11610
- /* @__PURE__ */ jsxRuntime.jsx(
11611
- Form$2.Field,
11612
- {
11613
- control: form.control,
11614
- name: "city",
11615
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11616
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11617
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11618
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11619
- ] })
11233
+ if (Array.isArray(field.value)) {
11234
+ placeholder = "[ ... ]";
11620
11235
  }
11621
- )
11236
+ return /* @__PURE__ */ jsxRuntime.jsx(
11237
+ ConditionalTooltip,
11238
+ {
11239
+ showTooltip: isDisabled,
11240
+ content: "This row is disabled because it contains non-primitive data.",
11241
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
11242
+ /* @__PURE__ */ jsxRuntime.jsxs(
11243
+ "div",
11244
+ {
11245
+ className: ui.clx("grid grid-cols-2 divide-x", {
11246
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
11247
+ }),
11248
+ children: [
11249
+ /* @__PURE__ */ jsxRuntime.jsx(
11250
+ Form$2.Field,
11251
+ {
11252
+ control: form.control,
11253
+ name: `metadata.${index}.key`,
11254
+ render: ({ field: field2 }) => {
11255
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11256
+ GridInput,
11257
+ {
11258
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
11259
+ ...field2,
11260
+ disabled: isDisabled,
11261
+ placeholder: "Key"
11262
+ }
11263
+ ) }) });
11264
+ }
11265
+ }
11266
+ ),
11267
+ /* @__PURE__ */ jsxRuntime.jsx(
11268
+ Form$2.Field,
11269
+ {
11270
+ control: form.control,
11271
+ name: `metadata.${index}.value`,
11272
+ render: ({ field: { value, ...field2 } }) => {
11273
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11274
+ GridInput,
11275
+ {
11276
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11277
+ ...field2,
11278
+ value: isDisabled ? placeholder : value,
11279
+ disabled: isDisabled,
11280
+ placeholder: "Value"
11281
+ }
11282
+ ) }) });
11283
+ }
11284
+ }
11285
+ )
11286
+ ]
11287
+ }
11288
+ ),
11289
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11290
+ /* @__PURE__ */ jsxRuntime.jsx(
11291
+ ui.DropdownMenu.Trigger,
11292
+ {
11293
+ className: ui.clx(
11294
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11295
+ {
11296
+ hidden: isDisabled
11297
+ }
11298
+ ),
11299
+ disabled: isDisabled,
11300
+ asChild: true,
11301
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11302
+ }
11303
+ ),
11304
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11305
+ /* @__PURE__ */ jsxRuntime.jsxs(
11306
+ ui.DropdownMenu.Item,
11307
+ {
11308
+ className: "gap-x-2",
11309
+ onClick: () => insertRow(index, "above"),
11310
+ children: [
11311
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11312
+ "Insert row above"
11313
+ ]
11314
+ }
11315
+ ),
11316
+ /* @__PURE__ */ jsxRuntime.jsxs(
11317
+ ui.DropdownMenu.Item,
11318
+ {
11319
+ className: "gap-x-2",
11320
+ onClick: () => insertRow(index, "below"),
11321
+ children: [
11322
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11323
+ "Insert row below"
11324
+ ]
11325
+ }
11326
+ ),
11327
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11328
+ /* @__PURE__ */ jsxRuntime.jsxs(
11329
+ ui.DropdownMenu.Item,
11330
+ {
11331
+ className: "gap-x-2",
11332
+ onClick: () => deleteRow(index),
11333
+ children: [
11334
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11335
+ "Delete row"
11336
+ ]
11337
+ }
11338
+ )
11339
+ ] })
11340
+ ] })
11341
+ ] })
11342
+ },
11343
+ field.id
11344
+ );
11345
+ })
11622
11346
  ] }),
11623
- /* @__PURE__ */ jsxRuntime.jsx(
11624
- Form$2.Field,
11625
- {
11626
- control: form.control,
11627
- name: "province",
11628
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11629
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11630
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11631
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11632
- ] })
11633
- }
11634
- ),
11635
- /* @__PURE__ */ jsxRuntime.jsx(
11636
- Form$2.Field,
11637
- {
11638
- control: form.control,
11639
- name: "phone",
11640
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11641
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11642
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11643
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11644
- ] })
11645
- }
11646
- )
11647
- ] }) }),
11347
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11348
+ ] }),
11349
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11350
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11351
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11352
+ ] }) })
11353
+ ]
11354
+ }
11355
+ ) });
11356
+ };
11357
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11358
+ return /* @__PURE__ */ jsxRuntime.jsx(
11359
+ "input",
11360
+ {
11361
+ ref,
11362
+ ...props,
11363
+ autoComplete: "off",
11364
+ className: ui.clx(
11365
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11366
+ className
11367
+ )
11368
+ }
11369
+ );
11370
+ });
11371
+ GridInput.displayName = "MetadataForm.GridInput";
11372
+ const PlaceholderInner = () => {
11373
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11374
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11375
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11376
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11377
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11378
+ ] }) })
11379
+ ] });
11380
+ };
11381
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11382
+ function getDefaultValues(metadata) {
11383
+ if (!metadata || !Object.keys(metadata).length) {
11384
+ return [
11385
+ {
11386
+ key: "",
11387
+ value: "",
11388
+ disabled: false
11389
+ }
11390
+ ];
11391
+ }
11392
+ return Object.entries(metadata).map(([key, value]) => {
11393
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11394
+ return {
11395
+ key,
11396
+ value,
11397
+ disabled: true
11398
+ };
11399
+ }
11400
+ let stringValue = value;
11401
+ if (typeof value !== "string") {
11402
+ stringValue = JSON.stringify(value);
11403
+ }
11404
+ return {
11405
+ key,
11406
+ value: stringValue,
11407
+ original_key: key
11408
+ };
11409
+ });
11410
+ }
11411
+ function parseValues(values) {
11412
+ const metadata = values.metadata;
11413
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11414
+ if (isEmpty) {
11415
+ return null;
11416
+ }
11417
+ const update = {};
11418
+ metadata.forEach((field) => {
11419
+ let key = field.key;
11420
+ let value = field.value;
11421
+ const disabled = field.disabled;
11422
+ if (!key || !value) {
11423
+ return;
11424
+ }
11425
+ if (disabled) {
11426
+ update[key] = value;
11427
+ return;
11428
+ }
11429
+ key = key.trim();
11430
+ value = value.trim();
11431
+ if (value === "true") {
11432
+ update[key] = true;
11433
+ } else if (value === "false") {
11434
+ update[key] = false;
11435
+ } else {
11436
+ const parsedNumber = parseFloat(value);
11437
+ if (!isNaN(parsedNumber)) {
11438
+ update[key] = parsedNumber;
11439
+ } else {
11440
+ update[key] = value;
11441
+ }
11442
+ }
11443
+ });
11444
+ return update;
11445
+ }
11446
+ function getHasUneditableRows(metadata) {
11447
+ if (!metadata) {
11448
+ return false;
11449
+ }
11450
+ return Object.values(metadata).some(
11451
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11452
+ );
11453
+ }
11454
+ const SalesChannel = () => {
11455
+ const { id } = reactRouterDom.useParams();
11456
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11457
+ id,
11458
+ {
11459
+ fields: "+sales_channel_id"
11460
+ },
11461
+ {
11462
+ enabled: !!id
11463
+ }
11464
+ );
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 }) }),
11648
11509
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11649
11510
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11650
11511
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11653,7 +11514,49 @@ const ShippingAddressForm = ({ order }) => {
11653
11514
  }
11654
11515
  ) });
11655
11516
  };
11656
- const schema$2 = addressSchema;
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
+ });
11657
11560
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11658
11561
  const Shipping = () => {
11659
11562
  var _a;
@@ -12408,59 +12311,262 @@ const ShippingOptionField = ({
12408
12311
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12409
12312
  ] }),
12410
12313
  /* @__PURE__ */ jsxRuntime.jsx(
12411
- ConditionalTooltip,
12314
+ ConditionalTooltip,
12315
+ {
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
+ ) }) })
12331
+ }
12332
+ )
12333
+ ] }) });
12334
+ }
12335
+ }
12336
+ );
12337
+ };
12338
+ const CustomAmountField = ({
12339
+ control,
12340
+ currencyCode
12341
+ }) => {
12342
+ return /* @__PURE__ */ jsxRuntime.jsx(
12343
+ Form$2.Field,
12344
+ {
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." })
12352
+ ] }),
12353
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12354
+ ui.CurrencyInput,
12355
+ {
12356
+ ...field,
12357
+ onValueChange: (value) => onChange(value),
12358
+ symbol: getNativeSymbol(currencyCode),
12359
+ code: currencyCode
12360
+ }
12361
+ ) })
12362
+ ] });
12363
+ }
12364
+ }
12365
+ );
12366
+ };
12367
+ const ShippingAddress = () => {
12368
+ const { id } = reactRouterDom.useParams();
12369
+ const { order, isPending, isError, error } = useOrder(id, {
12370
+ fields: "+shipping_address"
12371
+ });
12372
+ if (isError) {
12373
+ throw error;
12374
+ }
12375
+ const isReady = !isPending && !!order;
12376
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12377
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12378
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12379
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12380
+ ] }),
12381
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12382
+ ] });
12383
+ };
12384
+ const ShippingAddressForm = ({ order }) => {
12385
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12386
+ const form = reactHookForm.useForm({
12387
+ defaultValues: {
12388
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12389
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12390
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12391
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12392
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12393
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12394
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12395
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12396
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12397
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12398
+ },
12399
+ resolver: zod.zodResolver(schema$1)
12400
+ });
12401
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12402
+ const { handleSuccess } = useRouteModal();
12403
+ const onSubmit = form.handleSubmit(async (data) => {
12404
+ await mutateAsync(
12405
+ {
12406
+ shipping_address: {
12407
+ first_name: data.first_name,
12408
+ last_name: data.last_name,
12409
+ company: data.company,
12410
+ address_1: data.address_1,
12411
+ address_2: data.address_2,
12412
+ city: data.city,
12413
+ province: data.province,
12414
+ country_code: data.country_code,
12415
+ postal_code: data.postal_code,
12416
+ phone: data.phone
12417
+ }
12418
+ },
12419
+ {
12420
+ onSuccess: () => {
12421
+ handleSuccess();
12422
+ },
12423
+ onError: (error) => {
12424
+ ui.toast.error(error.message);
12425
+ }
12426
+ }
12427
+ );
12428
+ });
12429
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12430
+ KeyboundForm,
12431
+ {
12432
+ className: "flex flex-1 flex-col overflow-hidden",
12433
+ onSubmit,
12434
+ children: [
12435
+ /* @__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: [
12436
+ /* @__PURE__ */ jsxRuntime.jsx(
12437
+ Form$2.Field,
12438
+ {
12439
+ control: form.control,
12440
+ name: "country_code",
12441
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12442
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12443
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12444
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12445
+ ] })
12446
+ }
12447
+ ),
12448
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12449
+ /* @__PURE__ */ jsxRuntime.jsx(
12450
+ Form$2.Field,
12451
+ {
12452
+ control: form.control,
12453
+ name: "first_name",
12454
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12455
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12456
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12457
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12458
+ ] })
12459
+ }
12460
+ ),
12461
+ /* @__PURE__ */ jsxRuntime.jsx(
12462
+ Form$2.Field,
12463
+ {
12464
+ control: form.control,
12465
+ name: "last_name",
12466
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12467
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12468
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12469
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12470
+ ] })
12471
+ }
12472
+ )
12473
+ ] }),
12474
+ /* @__PURE__ */ jsxRuntime.jsx(
12475
+ Form$2.Field,
12476
+ {
12477
+ control: form.control,
12478
+ name: "company",
12479
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12480
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12481
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12482
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12483
+ ] })
12484
+ }
12485
+ ),
12486
+ /* @__PURE__ */ jsxRuntime.jsx(
12487
+ Form$2.Field,
12412
12488
  {
12413
- content: tooltipContent,
12414
- showTooltip: !locationId || !shippingProfileId,
12415
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12416
- Combobox,
12417
- {
12418
- options: shippingOptions.options,
12419
- fetchNextPage: shippingOptions.fetchNextPage,
12420
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12421
- searchValue: shippingOptions.searchValue,
12422
- onSearchValueChange: shippingOptions.onSearchValueChange,
12423
- placeholder: "Select shipping option",
12424
- ...field,
12425
- disabled: !locationId || !shippingProfileId
12426
- }
12427
- ) }) })
12489
+ control: form.control,
12490
+ name: "address_1",
12491
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12492
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12493
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12494
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12495
+ ] })
12428
12496
  }
12429
- )
12430
- ] }) });
12431
- }
12432
- }
12433
- );
12434
- };
12435
- const CustomAmountField = ({
12436
- control,
12437
- currencyCode
12438
- }) => {
12439
- return /* @__PURE__ */ jsxRuntime.jsx(
12440
- Form$2.Field,
12441
- {
12442
- control,
12443
- name: "custom_amount",
12444
- render: ({ field: { onChange, ...field } }) => {
12445
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12446
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12447
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12448
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12497
+ ),
12498
+ /* @__PURE__ */ jsxRuntime.jsx(
12499
+ Form$2.Field,
12500
+ {
12501
+ control: form.control,
12502
+ name: "address_2",
12503
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12504
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12505
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12506
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12507
+ ] })
12508
+ }
12509
+ ),
12510
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12511
+ /* @__PURE__ */ jsxRuntime.jsx(
12512
+ Form$2.Field,
12513
+ {
12514
+ control: form.control,
12515
+ name: "postal_code",
12516
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12517
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12518
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12519
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12520
+ ] })
12521
+ }
12522
+ ),
12523
+ /* @__PURE__ */ jsxRuntime.jsx(
12524
+ Form$2.Field,
12525
+ {
12526
+ control: form.control,
12527
+ name: "city",
12528
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12529
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12530
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12531
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12532
+ ] })
12533
+ }
12534
+ )
12449
12535
  ] }),
12450
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12451
- ui.CurrencyInput,
12536
+ /* @__PURE__ */ jsxRuntime.jsx(
12537
+ Form$2.Field,
12452
12538
  {
12453
- ...field,
12454
- onValueChange: (value) => onChange(value),
12455
- symbol: getNativeSymbol(currencyCode),
12456
- code: currencyCode
12539
+ control: form.control,
12540
+ name: "province",
12541
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12542
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12543
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12544
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12545
+ ] })
12457
12546
  }
12458
- ) })
12459
- ] });
12460
- }
12547
+ ),
12548
+ /* @__PURE__ */ jsxRuntime.jsx(
12549
+ Form$2.Field,
12550
+ {
12551
+ control: form.control,
12552
+ name: "phone",
12553
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12554
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12555
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12556
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12557
+ ] })
12558
+ }
12559
+ )
12560
+ ] }) }),
12561
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12562
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12564
+ ] }) })
12565
+ ]
12461
12566
  }
12462
- );
12567
+ ) });
12463
12568
  };
12569
+ const schema$1 = addressSchema;
12464
12570
  const TransferOwnership = () => {
12465
12571
  const { id } = reactRouterDom.useParams();
12466
12572
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12484,7 +12590,7 @@ const TransferOwnershipForm = ({ order }) => {
12484
12590
  defaultValues: {
12485
12591
  customer_id: order.customer_id || ""
12486
12592
  },
12487
- resolver: zod.zodResolver(schema$1)
12593
+ resolver: zod.zodResolver(schema)
12488
12594
  });
12489
12595
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12490
12596
  const { handleSuccess } = useRouteModal();
@@ -12934,114 +13040,8 @@ const Illustration = () => {
12934
13040
  }
12935
13041
  );
12936
13042
  };
12937
- const schema$1 = objectType({
12938
- customer_id: stringType().min(1)
12939
- });
12940
- const SalesChannel = () => {
12941
- const { id } = reactRouterDom.useParams();
12942
- const { draft_order, isPending, isError, error } = useDraftOrder(
12943
- id,
12944
- {
12945
- fields: "+sales_channel_id"
12946
- },
12947
- {
12948
- enabled: !!id
12949
- }
12950
- );
12951
- if (isError) {
12952
- throw error;
12953
- }
12954
- const ISrEADY = !!draft_order && !isPending;
12955
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12956
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12957
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12958
- /* @__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" }) })
12959
- ] }),
12960
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12961
- ] });
12962
- };
12963
- const SalesChannelForm = ({ order }) => {
12964
- const form = reactHookForm.useForm({
12965
- defaultValues: {
12966
- sales_channel_id: order.sales_channel_id || ""
12967
- },
12968
- resolver: zod.zodResolver(schema)
12969
- });
12970
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12971
- const { handleSuccess } = useRouteModal();
12972
- const onSubmit = form.handleSubmit(async (data) => {
12973
- await mutateAsync(
12974
- {
12975
- sales_channel_id: data.sales_channel_id
12976
- },
12977
- {
12978
- onSuccess: () => {
12979
- ui.toast.success("Sales channel updated");
12980
- handleSuccess();
12981
- },
12982
- onError: (error) => {
12983
- ui.toast.error(error.message);
12984
- }
12985
- }
12986
- );
12987
- });
12988
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12989
- KeyboundForm,
12990
- {
12991
- className: "flex flex-1 flex-col overflow-hidden",
12992
- onSubmit,
12993
- children: [
12994
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12995
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12996
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12997
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12998
- ] }) })
12999
- ]
13000
- }
13001
- ) });
13002
- };
13003
- const SalesChannelField = ({ control, order }) => {
13004
- const salesChannels = useComboboxData({
13005
- queryFn: async (params) => {
13006
- return await sdk.admin.salesChannel.list(params);
13007
- },
13008
- queryKey: ["sales-channels"],
13009
- getOptions: (data) => {
13010
- return data.sales_channels.map((salesChannel) => ({
13011
- label: salesChannel.name,
13012
- value: salesChannel.id
13013
- }));
13014
- },
13015
- defaultValue: order.sales_channel_id || void 0
13016
- });
13017
- return /* @__PURE__ */ jsxRuntime.jsx(
13018
- Form$2.Field,
13019
- {
13020
- control,
13021
- name: "sales_channel_id",
13022
- render: ({ field }) => {
13023
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13024
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
13025
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13026
- Combobox,
13027
- {
13028
- options: salesChannels.options,
13029
- fetchNextPage: salesChannels.fetchNextPage,
13030
- isFetchingNextPage: salesChannels.isFetchingNextPage,
13031
- searchValue: salesChannels.searchValue,
13032
- onSearchValueChange: salesChannels.onSearchValueChange,
13033
- placeholder: "Select sales channel",
13034
- ...field
13035
- }
13036
- ) }),
13037
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13038
- ] });
13039
- }
13040
- }
13041
- );
13042
- };
13043
13043
  const schema = objectType({
13044
- sales_channel_id: stringType().min(1)
13044
+ customer_id: stringType().min(1)
13045
13045
  });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
@@ -13071,37 +13071,37 @@ const routeModule = {
13071
13071
  Component: CustomItems,
13072
13072
  path: "/draft-orders/:id/custom-items"
13073
13073
  },
13074
- {
13075
- Component: Email,
13076
- path: "/draft-orders/:id/email"
13077
- },
13078
13074
  {
13079
13075
  Component: Items,
13080
13076
  path: "/draft-orders/:id/items"
13081
13077
  },
13082
13078
  {
13083
- Component: Metadata,
13084
- path: "/draft-orders/:id/metadata"
13079
+ Component: Email,
13080
+ path: "/draft-orders/:id/email"
13085
13081
  },
13086
13082
  {
13087
13083
  Component: Promotions,
13088
13084
  path: "/draft-orders/:id/promotions"
13089
13085
  },
13090
13086
  {
13091
- Component: ShippingAddress,
13092
- path: "/draft-orders/:id/shipping-address"
13087
+ Component: Metadata,
13088
+ path: "/draft-orders/:id/metadata"
13089
+ },
13090
+ {
13091
+ Component: SalesChannel,
13092
+ path: "/draft-orders/:id/sales-channel"
13093
13093
  },
13094
13094
  {
13095
13095
  Component: Shipping,
13096
13096
  path: "/draft-orders/:id/shipping"
13097
13097
  },
13098
13098
  {
13099
- Component: TransferOwnership,
13100
- path: "/draft-orders/:id/transfer-ownership"
13099
+ Component: ShippingAddress,
13100
+ path: "/draft-orders/:id/shipping-address"
13101
13101
  },
13102
13102
  {
13103
- Component: SalesChannel,
13104
- path: "/draft-orders/:id/sales-channel"
13103
+ Component: TransferOwnership,
13104
+ path: "/draft-orders/:id/transfer-ownership"
13105
13105
  }
13106
13106
  ]
13107
13107
  }