@medusajs/draft-order 2.11.2-snapshot-20251029153127 → 2.11.2-snapshot-20251030105712

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,46 +11101,88 @@ function getPromotionIds(items, shippingMethods) {
11451
11101
  }
11452
11102
  return Array.from(promotionIds);
11453
11103
  }
11454
- const SalesChannel = () => {
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
- const { draft_order, isPending, isError, error } = useDraftOrder(
11457
- id,
11458
- {
11459
- fields: "+sales_channel_id"
11460
- },
11461
- {
11462
- enabled: !!id
11463
- }
11464
- );
11150
+ const { order, isPending, isError, error } = useOrder(id, {
11151
+ fields: "metadata"
11152
+ });
11465
11153
  if (isError) {
11466
11154
  throw error;
11467
11155
  }
11468
- const ISrEADY = !!draft_order && !isPending;
11156
+ const isReady = !isPending && !!order;
11469
11157
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11470
11158
  /* @__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" }) })
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." }) })
11473
11161
  ] }),
11474
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11162
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11475
11163
  ] });
11476
11164
  };
11477
- const SalesChannelForm = ({ order }) => {
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);
11478
11171
  const form = reactHookForm.useForm({
11479
11172
  defaultValues: {
11480
- sales_channel_id: order.sales_channel_id || ""
11173
+ metadata: getDefaultValues(metadata)
11481
11174
  },
11482
- resolver: zod.zodResolver(schema$2)
11175
+ resolver: zod.zodResolver(MetadataSchema)
11483
11176
  });
11484
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11485
- const { handleSuccess } = useRouteModal();
11486
- const onSubmit = form.handleSubmit(async (data) => {
11177
+ const handleSubmit = form.handleSubmit(async (data) => {
11178
+ const parsedData = parseValues(data);
11487
11179
  await mutateAsync(
11488
11180
  {
11489
- sales_channel_id: data.sales_channel_id
11181
+ metadata: parsedData
11490
11182
  },
11491
11183
  {
11492
11184
  onSuccess: () => {
11493
- ui.toast.success("Sales channel updated");
11185
+ ui.toast.success("Metadata updated");
11494
11186
  handleSuccess();
11495
11187
  },
11496
11188
  onError: (error) => {
@@ -11499,1209 +11191,710 @@ const SalesChannelForm = ({ order }) => {
11499
11191
  }
11500
11192
  );
11501
11193
  });
11502
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11503
- KeyboundForm,
11504
- {
11505
- className: "flex flex-1 flex-col overflow-hidden",
11506
- onSubmit,
11507
- children: [
11508
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11509
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11510
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11511
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11512
- ] }) })
11513
- ]
11514
- }
11515
- ) });
11516
- };
11517
- const SalesChannelField = ({ control, order }) => {
11518
- const salesChannels = useComboboxData({
11519
- queryFn: async (params) => {
11520
- return await sdk.admin.salesChannel.list(params);
11521
- },
11522
- queryKey: ["sales-channels"],
11523
- getOptions: (data) => {
11524
- return data.sales_channels.map((salesChannel) => ({
11525
- label: salesChannel.name,
11526
- value: salesChannel.id
11527
- }));
11528
- },
11529
- defaultValue: order.sales_channel_id || void 0
11194
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
11195
+ control: form.control,
11196
+ name: "metadata"
11530
11197
  });
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
- }
11198
+ function deleteRow(index) {
11199
+ remove(index);
11200
+ if (fields.length === 1) {
11201
+ insert(0, {
11202
+ key: "",
11203
+ value: "",
11204
+ disabled: false
11205
+ });
11554
11206
  }
11555
- );
11556
- };
11557
- const schema$2 = objectType({
11558
- sales_channel_id: stringType().min(1)
11559
- });
11560
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11561
- const Shipping = () => {
11562
- var _a;
11563
- const { id } = reactRouterDom.useParams();
11564
- const { order, isPending, isError, error } = useOrder(id, {
11565
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11566
- });
11567
- const {
11568
- order: preview,
11569
- isPending: isPreviewPending,
11570
- isError: isPreviewError,
11571
- error: previewError
11572
- } = useOrderPreview(id);
11573
- useInitiateOrderEdit({ preview });
11574
- const { onCancel } = useCancelOrderEdit({ preview });
11575
- if (isError) {
11576
- throw error;
11577
11207
  }
11578
- if (isPreviewError) {
11579
- throw previewError;
11208
+ function insertRow(index, position) {
11209
+ insert(index + (position === "above" ? 0 : 1), {
11210
+ key: "",
11211
+ value: "",
11212
+ disabled: false
11213
+ });
11580
11214
  }
11581
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11582
- const isReady = preview && !isPreviewPending && order && !isPending;
11583
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11584
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11585
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11586
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11587
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11588
- ] }) }) }),
11589
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11590
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11591
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11592
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11593
- ] }) });
11594
- };
11595
- const ShippingForm = ({ preview, order }) => {
11596
- var _a;
11597
- const { setIsOpen } = useStackedModal();
11598
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11599
- const [data, setData] = React.useState(null);
11600
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11601
- const { shipping_options } = useShippingOptions(
11215
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11216
+ KeyboundForm,
11602
11217
  {
11603
- id: appliedShippingOptionIds,
11604
- fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
11605
- },
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 = "{ ... }";
11232
+ }
11233
+ if (Array.isArray(field.value)) {
11234
+ placeholder = "[ ... ]";
11235
+ }
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
+ })
11346
+ ] }),
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",
11606
11360
  {
11607
- enabled: appliedShippingOptionIds.length > 0
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
+ )
11608
11368
  }
11609
11369
  );
11610
- const uniqueShippingProfiles = React.useMemo(() => {
11611
- const profiles = /* @__PURE__ */ new Map();
11612
- getUniqueShippingProfiles(order.items).forEach((profile) => {
11613
- profiles.set(profile.id, profile);
11614
- });
11615
- shipping_options == null ? void 0 : shipping_options.forEach((option) => {
11616
- profiles.set(option.shipping_profile_id, option.shipping_profile);
11617
- });
11618
- return Array.from(profiles.values());
11619
- }, [order.items, shipping_options]);
11620
- const { handleSuccess } = useRouteModal();
11621
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11622
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
11623
- const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
11624
- const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
11625
- const onSubmit = async () => {
11626
- setIsSubmitting(true);
11627
- let requestSucceeded = false;
11628
- await requestOrderEdit(void 0, {
11629
- onError: (e) => {
11630
- ui.toast.error(`Failed to request order edit: ${e.message}`);
11631
- },
11632
- onSuccess: () => {
11633
- requestSucceeded = true;
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
11634
11389
  }
11635
- });
11636
- if (!requestSucceeded) {
11637
- setIsSubmitting(false);
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) {
11638
11423
  return;
11639
11424
  }
11640
- await confirmOrderEdit(void 0, {
11641
- onError: (e) => {
11642
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
11643
- },
11644
- onSuccess: () => {
11645
- handleSuccess();
11646
- },
11647
- onSettled: () => {
11648
- setIsSubmitting(false);
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;
11649
11441
  }
11650
- });
11651
- };
11652
- const onKeydown = React.useCallback(
11653
- (e) => {
11654
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
11655
- if (data || isSubmitting) {
11656
- return;
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);
11657
11498
  }
11658
- onSubmit();
11659
11499
  }
11500
+ );
11501
+ });
11502
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11503
+ KeyboundForm,
11504
+ {
11505
+ className: "flex flex-1 flex-col overflow-hidden",
11506
+ onSubmit,
11507
+ children: [
11508
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11509
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11510
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11511
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11512
+ ] }) })
11513
+ ]
11514
+ }
11515
+ ) });
11516
+ };
11517
+ const SalesChannelField = ({ control, order }) => {
11518
+ const salesChannels = useComboboxData({
11519
+ queryFn: async (params) => {
11520
+ return await sdk.admin.salesChannel.list(params);
11660
11521
  },
11661
- [data, isSubmitting, onSubmit]
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
+ }
11662
11555
  );
11663
- React.useEffect(() => {
11664
- document.addEventListener("keydown", onKeydown);
11665
- return () => {
11666
- document.removeEventListener("keydown", onKeydown);
11667
- };
11668
- }, [onKeydown]);
11669
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
11670
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11671
- /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
11672
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11673
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11675
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
11676
- ] }),
11677
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11678
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
11679
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
11680
- /* @__PURE__ */ jsxRuntime.jsx(
11681
- ui.Text,
11682
- {
11683
- size: "xsmall",
11684
- weight: "plus",
11685
- className: "text-ui-fg-muted",
11686
- children: "Shipping profile"
11687
- }
11688
- ),
11689
- /* @__PURE__ */ jsxRuntime.jsx(
11690
- ui.Text,
11691
- {
11692
- size: "xsmall",
11693
- weight: "plus",
11694
- className: "text-ui-fg-muted",
11695
- children: "Action"
11696
- }
11697
- )
11698
- ] }),
11699
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
11700
- var _a2, _b, _c, _d, _e, _f, _g;
11701
- const items = getItemsWithShippingProfile(
11702
- profile.id,
11703
- order.items
11704
- );
11705
- const hasItems = items.length > 0;
11706
- const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
11707
- (option) => option.shipping_profile_id === profile.id
11708
- );
11709
- const shippingMethod = preview.shipping_methods.find(
11710
- (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
11711
- );
11712
- const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
11713
- (action) => action.action === "SHIPPING_ADD"
11714
- );
11715
- return /* @__PURE__ */ jsxRuntime.jsxs(
11716
- radixUi.Accordion.Item,
11556
+ };
11557
+ const schema$2 = objectType({
11558
+ sales_channel_id: stringType().min(1)
11559
+ });
11560
+ const ShippingAddress = () => {
11561
+ const { id } = reactRouterDom.useParams();
11562
+ const { order, isPending, isError, error } = useOrder(id, {
11563
+ fields: "+shipping_address"
11564
+ });
11565
+ if (isError) {
11566
+ throw error;
11567
+ }
11568
+ const isReady = !isPending && !!order;
11569
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11570
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11571
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11572
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11573
+ ] }),
11574
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11575
+ ] });
11576
+ };
11577
+ const ShippingAddressForm = ({ order }) => {
11578
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11579
+ const form = reactHookForm.useForm({
11580
+ defaultValues: {
11581
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11582
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11583
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11584
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11585
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11586
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11587
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11588
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11589
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11590
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11591
+ },
11592
+ resolver: zod.zodResolver(schema$1)
11593
+ });
11594
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11595
+ const { handleSuccess } = useRouteModal();
11596
+ const onSubmit = form.handleSubmit(async (data) => {
11597
+ await mutateAsync(
11598
+ {
11599
+ shipping_address: {
11600
+ first_name: data.first_name,
11601
+ last_name: data.last_name,
11602
+ company: data.company,
11603
+ address_1: data.address_1,
11604
+ address_2: data.address_2,
11605
+ city: data.city,
11606
+ province: data.province,
11607
+ country_code: data.country_code,
11608
+ postal_code: data.postal_code,
11609
+ phone: data.phone
11610
+ }
11611
+ },
11612
+ {
11613
+ onSuccess: () => {
11614
+ handleSuccess();
11615
+ },
11616
+ onError: (error) => {
11617
+ ui.toast.error(error.message);
11618
+ }
11619
+ }
11620
+ );
11621
+ });
11622
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11623
+ KeyboundForm,
11624
+ {
11625
+ className: "flex flex-1 flex-col overflow-hidden",
11626
+ onSubmit,
11627
+ children: [
11628
+ /* @__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: [
11629
+ /* @__PURE__ */ jsxRuntime.jsx(
11630
+ Form$2.Field,
11631
+ {
11632
+ control: form.control,
11633
+ name: "country_code",
11634
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11635
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11636
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11638
+ ] })
11639
+ }
11640
+ ),
11641
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11642
+ /* @__PURE__ */ jsxRuntime.jsx(
11643
+ Form$2.Field,
11717
11644
  {
11718
- value: profile.id,
11719
- className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
11720
- children: [
11721
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
11722
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
11723
- /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
11724
- ui.IconButton,
11725
- {
11726
- size: "2xsmall",
11727
- variant: "transparent",
11728
- className: "group/trigger",
11729
- disabled: !hasItems,
11730
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
11731
- }
11732
- ) }),
11733
- !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11734
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
11735
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
11736
- /* @__PURE__ */ jsxRuntime.jsx(
11737
- ui.Text,
11738
- {
11739
- size: "small",
11740
- weight: "plus",
11741
- leading: "compact",
11742
- children: profile.name
11743
- }
11744
- ),
11745
- /* @__PURE__ */ jsxRuntime.jsxs(
11746
- ui.Text,
11747
- {
11748
- size: "small",
11749
- leading: "compact",
11750
- className: "text-ui-fg-subtle",
11751
- children: [
11752
- items.length,
11753
- " ",
11754
- pluralize(items.length, "items", "item")
11755
- ]
11756
- }
11757
- )
11758
- ] })
11759
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
11760
- /* @__PURE__ */ jsxRuntime.jsx(
11761
- ui.Tooltip,
11762
- {
11763
- content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
11764
- var _a3, _b2, _c2;
11765
- return /* @__PURE__ */ jsxRuntime.jsx(
11766
- "li",
11767
- {
11768
- children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
11769
- },
11770
- item.id
11771
- );
11772
- }) }),
11773
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11774
- ui.Badge,
11775
- {
11776
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11777
- size: "xsmall",
11778
- children: [
11779
- /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
11780
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
11781
- items.reduce(
11782
- (acc, item) => acc + item.quantity,
11783
- 0
11784
- ),
11785
- "x",
11786
- " ",
11787
- pluralize(items.length, "items", "item")
11788
- ] })
11789
- ]
11790
- }
11791
- )
11792
- }
11793
- ),
11794
- /* @__PURE__ */ jsxRuntime.jsx(
11795
- ui.Tooltip,
11796
- {
11797
- content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
11798
- children: /* @__PURE__ */ jsxRuntime.jsxs(
11799
- ui.Badge,
11800
- {
11801
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11802
- size: "xsmall",
11803
- children: [
11804
- /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
11805
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
11806
- ]
11807
- }
11808
- )
11809
- }
11810
- ),
11811
- /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
11812
- ui.Badge,
11813
- {
11814
- className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
11815
- size: "xsmall",
11816
- children: [
11817
- /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
11818
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
11819
- ]
11820
- }
11821
- ) })
11822
- ] })
11823
- ] }),
11824
- shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
11825
- ActionMenu,
11826
- {
11827
- groups: [
11828
- {
11829
- actions: [
11830
- hasItems ? {
11831
- label: "Edit shipping option",
11832
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
11833
- onClick: () => {
11834
- setIsOpen(
11835
- STACKED_FOCUS_MODAL_ID,
11836
- true
11837
- );
11838
- setData({
11839
- shippingProfileId: profile.id,
11840
- shippingOption,
11841
- shippingMethod
11842
- });
11843
- }
11844
- } : void 0,
11845
- {
11846
- label: "Remove shipping option",
11847
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
11848
- onClick: () => {
11849
- if (shippingMethod) {
11850
- if (addShippingMethodAction) {
11851
- removeActionShippingMethod(
11852
- addShippingMethodAction.id
11853
- );
11854
- } else {
11855
- removeShippingMethod(
11856
- shippingMethod.id
11857
- );
11858
- }
11859
- }
11860
- }
11861
- }
11862
- ].filter(Boolean)
11863
- }
11864
- ]
11865
- }
11866
- ) : /* @__PURE__ */ jsxRuntime.jsx(
11867
- StackedModalTrigger,
11868
- {
11869
- shippingProfileId: profile.id,
11870
- shippingOption,
11871
- shippingMethod,
11872
- setData,
11873
- children: "Add shipping option"
11874
- }
11875
- )
11876
- ] }),
11877
- /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
11878
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11879
- items.map((item, idx) => {
11880
- var _a3, _b2, _c2, _d2, _e2;
11881
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11882
- /* @__PURE__ */ jsxRuntime.jsxs(
11883
- "div",
11884
- {
11885
- className: "px-3 flex items-center gap-x-3",
11886
- children: [
11887
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
11888
- ui.Divider,
11889
- {
11890
- variant: "dashed",
11891
- orientation: "vertical"
11892
- }
11893
- ) }),
11894
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
11895
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
11896
- ui.Text,
11897
- {
11898
- size: "small",
11899
- leading: "compact",
11900
- className: "text-ui-fg-subtle",
11901
- children: [
11902
- item.quantity,
11903
- "x"
11904
- ]
11905
- }
11906
- ) }),
11907
- /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
11908
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11909
- /* @__PURE__ */ jsxRuntime.jsxs(
11910
- ui.Text,
11911
- {
11912
- size: "small",
11913
- leading: "compact",
11914
- weight: "plus",
11915
- children: [
11916
- (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
11917
- " (",
11918
- (_c2 = item.variant) == null ? void 0 : _c2.title,
11919
- ")"
11920
- ]
11921
- }
11922
- ),
11923
- /* @__PURE__ */ jsxRuntime.jsx(
11924
- ui.Text,
11925
- {
11926
- size: "small",
11927
- leading: "compact",
11928
- className: "text-ui-fg-subtle",
11929
- children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
11930
- }
11931
- )
11932
- ] })
11933
- ] })
11934
- ]
11935
- },
11936
- item.id
11937
- ),
11938
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11939
- ] }, item.id);
11940
- })
11941
- ] })
11942
- ]
11943
- },
11944
- profile.id
11945
- );
11946
- }) })
11947
- ] }) })
11948
- ] }) }),
11949
- /* @__PURE__ */ jsxRuntime.jsx(
11950
- StackedFocusModal,
11951
- {
11952
- id: STACKED_FOCUS_MODAL_ID,
11953
- onOpenChangeCallback: (open) => {
11954
- if (!open) {
11955
- setData(null);
11956
- }
11957
- return open;
11958
- },
11959
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11960
- }
11961
- )
11962
- ] }),
11963
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11964
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11965
- /* @__PURE__ */ jsxRuntime.jsx(
11966
- ui.Button,
11967
- {
11968
- size: "small",
11969
- type: "button",
11970
- isLoading: isSubmitting,
11971
- onClick: onSubmit,
11972
- children: "Save"
11973
- }
11974
- )
11975
- ] }) })
11976
- ] });
11977
- };
11978
- const StackedModalTrigger = ({
11979
- shippingProfileId,
11980
- shippingOption,
11981
- shippingMethod,
11982
- setData,
11983
- children
11984
- }) => {
11985
- const { setIsOpen, getIsOpen } = useStackedModal();
11986
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11987
- const onToggle = () => {
11988
- if (isOpen) {
11989
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11990
- setData(null);
11991
- } else {
11992
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11993
- setData({
11994
- shippingProfileId,
11995
- shippingOption,
11996
- shippingMethod
11997
- });
11998
- }
11999
- };
12000
- return /* @__PURE__ */ jsxRuntime.jsx(
12001
- ui.Button,
12002
- {
12003
- size: "small",
12004
- variant: "secondary",
12005
- onClick: onToggle,
12006
- className: "text-ui-fg-primary shrink-0",
12007
- children
12008
- }
12009
- );
12010
- };
12011
- const ShippingProfileForm = ({
12012
- data,
12013
- order,
12014
- preview
12015
- }) => {
12016
- var _a, _b, _c, _d, _e, _f;
12017
- const { setIsOpen } = useStackedModal();
12018
- const form = reactHookForm.useForm({
12019
- resolver: zod.zodResolver(shippingMethodSchema),
12020
- defaultValues: {
12021
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12022
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12023
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12024
- }
12025
- });
12026
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12027
- const {
12028
- mutateAsync: updateShippingMethod,
12029
- isPending: isUpdatingShippingMethod
12030
- } = useDraftOrderUpdateShippingMethod(order.id);
12031
- const onSubmit = form.handleSubmit(async (values) => {
12032
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12033
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12034
- return;
12035
- }
12036
- if (data.shippingMethod) {
12037
- await updateShippingMethod(
12038
- {
12039
- method_id: data.shippingMethod.id,
12040
- shipping_option_id: values.shipping_option_id,
12041
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12042
- },
12043
- {
12044
- onError: (e) => {
12045
- ui.toast.error(e.message);
12046
- },
12047
- onSuccess: () => {
12048
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12049
- }
12050
- }
12051
- );
12052
- return;
12053
- }
12054
- await addShippingMethod(
12055
- {
12056
- shipping_option_id: values.shipping_option_id,
12057
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12058
- },
12059
- {
12060
- onError: (e) => {
12061
- ui.toast.error(e.message);
12062
- },
12063
- onSuccess: () => {
12064
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12065
- }
12066
- }
12067
- );
12068
- });
12069
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12070
- KeyboundForm,
12071
- {
12072
- className: "flex h-full flex-col overflow-hidden",
12073
- onSubmit,
12074
- children: [
12075
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12076
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12077
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12078
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12079
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
11645
+ control: form.control,
11646
+ name: "first_name",
11647
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11648
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11651
+ ] })
11652
+ }
11653
+ ),
11654
+ /* @__PURE__ */ jsxRuntime.jsx(
11655
+ Form$2.Field,
11656
+ {
11657
+ control: form.control,
11658
+ name: "last_name",
11659
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11660
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11663
+ ] })
11664
+ }
11665
+ )
12080
11666
  ] }),
12081
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12082
11667
  /* @__PURE__ */ jsxRuntime.jsx(
12083
- LocationField,
11668
+ Form$2.Field,
12084
11669
  {
12085
11670
  control: form.control,
12086
- setValue: form.setValue
11671
+ name: "company",
11672
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11673
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11674
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11676
+ ] })
12087
11677
  }
12088
11678
  ),
12089
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12090
11679
  /* @__PURE__ */ jsxRuntime.jsx(
12091
- ShippingOptionField,
11680
+ Form$2.Field,
12092
11681
  {
12093
- shippingProfileId: data.shippingProfileId,
12094
- preview,
12095
- control: form.control
11682
+ control: form.control,
11683
+ name: "address_1",
11684
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11685
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11686
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11688
+ ] })
12096
11689
  }
12097
11690
  ),
12098
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12099
11691
  /* @__PURE__ */ jsxRuntime.jsx(
12100
- CustomAmountField,
11692
+ Form$2.Field,
12101
11693
  {
12102
11694
  control: form.control,
12103
- currencyCode: order.currency_code
11695
+ name: "address_2",
11696
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11697
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11700
+ ] })
12104
11701
  }
12105
11702
  ),
12106
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11703
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11704
+ /* @__PURE__ */ jsxRuntime.jsx(
11705
+ Form$2.Field,
11706
+ {
11707
+ control: form.control,
11708
+ name: "postal_code",
11709
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11710
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11711
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11713
+ ] })
11714
+ }
11715
+ ),
11716
+ /* @__PURE__ */ jsxRuntime.jsx(
11717
+ Form$2.Field,
11718
+ {
11719
+ control: form.control,
11720
+ name: "city",
11721
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11722
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11723
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11725
+ ] })
11726
+ }
11727
+ )
11728
+ ] }),
12107
11729
  /* @__PURE__ */ jsxRuntime.jsx(
12108
- ItemsPreview,
11730
+ Form$2.Field,
12109
11731
  {
12110
- order,
12111
- shippingProfileId: data.shippingProfileId
11732
+ control: form.control,
11733
+ name: "province",
11734
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11735
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11736
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11738
+ ] })
12112
11739
  }
12113
- )
12114
- ] }) }) }),
12115
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12116
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11740
+ ),
12117
11741
  /* @__PURE__ */ jsxRuntime.jsx(
12118
- ui.Button,
11742
+ Form$2.Field,
12119
11743
  {
12120
- size: "small",
12121
- type: "submit",
12122
- isLoading: isPending || isUpdatingShippingMethod,
12123
- children: data.shippingMethod ? "Update" : "Add"
11744
+ control: form.control,
11745
+ name: "phone",
11746
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11747
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11748
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11750
+ ] })
12124
11751
  }
12125
11752
  )
11753
+ ] }) }),
11754
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11756
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12126
11757
  ] }) })
12127
11758
  ]
12128
11759
  }
12129
- ) }) });
11760
+ ) });
12130
11761
  };
12131
- const shippingMethodSchema = objectType({
12132
- location_id: stringType(),
12133
- shipping_option_id: stringType(),
12134
- custom_amount: unionType([numberType(), stringType()]).optional()
12135
- });
12136
- const ItemsPreview = ({ order, shippingProfileId }) => {
12137
- const matches = order.items.filter(
12138
- (item) => {
12139
- var _a, _b, _c;
12140
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12141
- }
12142
- );
12143
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12144
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12145
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12146
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12147
- ] }) }),
12148
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12149
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12150
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12151
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12152
- ] }),
12153
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12154
- "div",
12155
- {
12156
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12157
- children: [
12158
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12159
- /* @__PURE__ */ jsxRuntime.jsx(
12160
- Thumbnail,
12161
- {
12162
- thumbnail: item.thumbnail,
12163
- alt: item.product_title ?? void 0
12164
- }
12165
- ),
12166
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12167
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12168
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12169
- /* @__PURE__ */ jsxRuntime.jsxs(
12170
- ui.Text,
12171
- {
12172
- size: "small",
12173
- leading: "compact",
12174
- className: "text-ui-fg-subtle",
12175
- children: [
12176
- "(",
12177
- item.variant_title,
12178
- ")"
12179
- ]
12180
- }
12181
- )
12182
- ] }),
12183
- /* @__PURE__ */ jsxRuntime.jsx(
12184
- ui.Text,
12185
- {
12186
- size: "small",
12187
- leading: "compact",
12188
- className: "text-ui-fg-subtle",
12189
- children: item.variant_sku
12190
- }
12191
- )
12192
- ] })
12193
- ] }),
12194
- /* @__PURE__ */ jsxRuntime.jsxs(
12195
- ui.Text,
12196
- {
12197
- size: "small",
12198
- leading: "compact",
12199
- className: "text-ui-fg-subtle",
12200
- children: [
12201
- item.quantity,
12202
- "x"
12203
- ]
12204
- }
12205
- )
12206
- ]
12207
- },
12208
- item.id
12209
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12210
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12211
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12212
- 'No items found for "',
12213
- query,
12214
- '".'
12215
- ] })
12216
- ] }) })
12217
- ] })
11762
+ const schema$1 = addressSchema;
11763
+ const TransferOwnership = () => {
11764
+ const { id } = reactRouterDom.useParams();
11765
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11766
+ fields: "id,customer_id,customer.*"
11767
+ });
11768
+ if (isError) {
11769
+ throw error;
11770
+ }
11771
+ const isReady = !isPending && !!draft_order;
11772
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11773
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11774
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11775
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11776
+ ] }),
11777
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12218
11778
  ] });
12219
11779
  };
12220
- const LocationField = ({ control, setValue }) => {
12221
- const locations = useComboboxData({
12222
- queryKey: ["locations"],
12223
- queryFn: async (params) => {
12224
- return await sdk.admin.stockLocation.list(params);
11780
+ const TransferOwnershipForm = ({ order }) => {
11781
+ var _a, _b;
11782
+ const form = reactHookForm.useForm({
11783
+ defaultValues: {
11784
+ customer_id: order.customer_id || ""
12225
11785
  },
12226
- getOptions: (data) => {
12227
- return data.stock_locations.map((location) => ({
12228
- label: location.name,
12229
- value: location.id
12230
- }));
12231
- }
11786
+ resolver: zod.zodResolver(schema)
12232
11787
  });
12233
- return /* @__PURE__ */ jsxRuntime.jsx(
12234
- Form$2.Field,
11788
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11789
+ const { handleSuccess } = useRouteModal();
11790
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11791
+ const currentCustomer = order.customer ? {
11792
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
11793
+ value: order.customer.id
11794
+ } : null;
11795
+ const onSubmit = form.handleSubmit(async (data) => {
11796
+ await mutateAsync(
11797
+ { customer_id: data.customer_id },
11798
+ {
11799
+ onSuccess: () => {
11800
+ ui.toast.success("Customer updated");
11801
+ handleSuccess();
11802
+ },
11803
+ onError: (error) => {
11804
+ ui.toast.error(error.message);
11805
+ }
11806
+ }
11807
+ );
11808
+ });
11809
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11810
+ KeyboundForm,
12235
11811
  {
12236
- control,
12237
- name: "location_id",
12238
- render: ({ field: { onChange, ...field } }) => {
12239
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12240
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12241
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12242
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
11812
+ className: "flex flex-1 flex-col overflow-hidden",
11813
+ onSubmit,
11814
+ children: [
11815
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11816
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11817
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11818
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11819
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11820
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11821
+ ] }),
11822
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11823
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11824
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11825
+ ] })
12243
11826
  ] }),
12244
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12245
- Combobox,
11827
+ /* @__PURE__ */ jsxRuntime.jsx(
11828
+ CustomerField,
12246
11829
  {
12247
- options: locations.options,
12248
- fetchNextPage: locations.fetchNextPage,
12249
- isFetchingNextPage: locations.isFetchingNextPage,
12250
- searchValue: locations.searchValue,
12251
- onSearchValueChange: locations.onSearchValueChange,
12252
- placeholder: "Select location",
12253
- onChange: (value) => {
12254
- setValue("shipping_option_id", "", {
12255
- shouldDirty: true,
12256
- shouldTouch: true
12257
- });
12258
- onChange(value);
12259
- },
12260
- ...field
11830
+ control: form.control,
11831
+ currentCustomerId: order.customer_id
12261
11832
  }
12262
- ) })
12263
- ] }) });
12264
- }
11833
+ )
11834
+ ] }),
11835
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11836
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11837
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11838
+ ] }) })
11839
+ ]
12265
11840
  }
12266
- );
11841
+ ) });
12267
11842
  };
12268
- const ShippingOptionField = ({
12269
- shippingProfileId,
12270
- preview,
12271
- control
12272
- }) => {
12273
- var _a;
12274
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12275
- const shippingOptions = useComboboxData({
12276
- queryKey: ["shipping_options", locationId, shippingProfileId],
11843
+ const CustomerField = ({ control, currentCustomerId }) => {
11844
+ const customers = useComboboxData({
12277
11845
  queryFn: async (params) => {
12278
- return await sdk.admin.shippingOption.list({
11846
+ return await sdk.admin.customer.list({
12279
11847
  ...params,
12280
- stock_location_id: locationId,
12281
- shipping_profile_id: shippingProfileId
11848
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12282
11849
  });
12283
11850
  },
11851
+ queryKey: ["customers"],
12284
11852
  getOptions: (data) => {
12285
- return data.shipping_options.map((option) => {
12286
- var _a2;
12287
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12288
- (r) => r.attribute === "is_return" && r.value === "true"
12289
- )) {
12290
- return void 0;
12291
- }
11853
+ return data.customers.map((customer) => {
11854
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12292
11855
  return {
12293
- label: option.name,
12294
- value: option.id
11856
+ label: name ? `${name} (${customer.email})` : customer.email,
11857
+ value: customer.id
12295
11858
  };
12296
- }).filter(Boolean);
12297
- },
12298
- enabled: !!locationId && !!shippingProfileId,
12299
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12300
- });
12301
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12302
- return /* @__PURE__ */ jsxRuntime.jsx(
12303
- Form$2.Field,
12304
- {
12305
- control,
12306
- name: "shipping_option_id",
12307
- render: ({ field }) => {
12308
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12309
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12310
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12311
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12312
- ] }),
12313
- /* @__PURE__ */ jsxRuntime.jsx(
12314
- ConditionalTooltip,
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
- }
11859
+ });
12335
11860
  }
12336
- );
12337
- };
12338
- const CustomAmountField = ({
12339
- control,
12340
- currencyCode
12341
- }) => {
11861
+ });
12342
11862
  return /* @__PURE__ */ jsxRuntime.jsx(
12343
11863
  Form$2.Field,
12344
11864
  {
11865
+ name: "customer_id",
12345
11866
  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
- }
11867
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11868
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11869
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11870
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11871
+ ] }),
11872
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11873
+ Combobox,
11874
+ {
11875
+ options: customers.options,
11876
+ fetchNextPage: customers.fetchNextPage,
11877
+ isFetchingNextPage: customers.isFetchingNextPage,
11878
+ searchValue: customers.searchValue,
11879
+ onSearchValueChange: customers.onSearchValueChange,
11880
+ placeholder: "Select customer",
11881
+ ...field
11882
+ }
11883
+ ) }),
11884
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11885
+ ] })
12364
11886
  }
12365
11887
  );
12366
11888
  };
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,
11889
+ const Illustration = () => {
11890
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11891
+ "svg",
12431
11892
  {
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,
12488
- {
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
- ] })
12496
- }
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
- )
12535
- ] }),
12536
- /* @__PURE__ */ jsxRuntime.jsx(
12537
- Form$2.Field,
12538
- {
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
- ] })
12546
- }
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
- ]
12566
- }
12567
- ) });
12568
- };
12569
- const schema$1 = addressSchema;
12570
- const TransferOwnership = () => {
12571
- const { id } = reactRouterDom.useParams();
12572
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12573
- fields: "id,customer_id,customer.*"
12574
- });
12575
- if (isError) {
12576
- throw error;
12577
- }
12578
- const isReady = !isPending && !!draft_order;
12579
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12580
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12581
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12582
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12583
- ] }),
12584
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12585
- ] });
12586
- };
12587
- const TransferOwnershipForm = ({ order }) => {
12588
- var _a, _b;
12589
- const form = reactHookForm.useForm({
12590
- defaultValues: {
12591
- customer_id: order.customer_id || ""
12592
- },
12593
- resolver: zod.zodResolver(schema)
12594
- });
12595
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12596
- const { handleSuccess } = useRouteModal();
12597
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12598
- const currentCustomer = order.customer ? {
12599
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
12600
- value: order.customer.id
12601
- } : null;
12602
- const onSubmit = form.handleSubmit(async (data) => {
12603
- await mutateAsync(
12604
- { customer_id: data.customer_id },
12605
- {
12606
- onSuccess: () => {
12607
- ui.toast.success("Customer updated");
12608
- handleSuccess();
12609
- },
12610
- onError: (error) => {
12611
- ui.toast.error(error.message);
12612
- }
12613
- }
12614
- );
12615
- });
12616
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12617
- KeyboundForm,
12618
- {
12619
- className: "flex flex-1 flex-col overflow-hidden",
12620
- onSubmit,
12621
- children: [
12622
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12623
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12624
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12625
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12626
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12627
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12628
- ] }),
12629
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12630
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12631
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12632
- ] })
12633
- ] }),
12634
- /* @__PURE__ */ jsxRuntime.jsx(
12635
- CustomerField,
12636
- {
12637
- control: form.control,
12638
- currentCustomerId: order.customer_id
12639
- }
12640
- )
12641
- ] }),
12642
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12643
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12644
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12645
- ] }) })
12646
- ]
12647
- }
12648
- ) });
12649
- };
12650
- const CustomerField = ({ control, currentCustomerId }) => {
12651
- const customers = useComboboxData({
12652
- queryFn: async (params) => {
12653
- return await sdk.admin.customer.list({
12654
- ...params,
12655
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12656
- });
12657
- },
12658
- queryKey: ["customers"],
12659
- getOptions: (data) => {
12660
- return data.customers.map((customer) => {
12661
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12662
- return {
12663
- label: name ? `${name} (${customer.email})` : customer.email,
12664
- value: customer.id
12665
- };
12666
- });
12667
- }
12668
- });
12669
- return /* @__PURE__ */ jsxRuntime.jsx(
12670
- Form$2.Field,
12671
- {
12672
- name: "customer_id",
12673
- control,
12674
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12675
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12676
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12677
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12678
- ] }),
12679
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12680
- Combobox,
12681
- {
12682
- options: customers.options,
12683
- fetchNextPage: customers.fetchNextPage,
12684
- isFetchingNextPage: customers.isFetchingNextPage,
12685
- searchValue: customers.searchValue,
12686
- onSearchValueChange: customers.onSearchValueChange,
12687
- placeholder: "Select customer",
12688
- ...field
12689
- }
12690
- ) }),
12691
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12692
- ] })
12693
- }
12694
- );
12695
- };
12696
- const Illustration = () => {
12697
- return /* @__PURE__ */ jsxRuntime.jsxs(
12698
- "svg",
12699
- {
12700
- width: "280",
12701
- height: "180",
12702
- viewBox: "0 0 280 180",
12703
- fill: "none",
12704
- xmlns: "http://www.w3.org/2000/svg",
11893
+ width: "280",
11894
+ height: "180",
11895
+ viewBox: "0 0 280 180",
11896
+ fill: "none",
11897
+ xmlns: "http://www.w3.org/2000/svg",
12705
11898
  children: [
12706
11899
  /* @__PURE__ */ jsxRuntime.jsx(
12707
11900
  "rect",
@@ -12979,70 +12172,877 @@ const Illustration = () => {
12979
12172
  strokeLinecap: "round",
12980
12173
  strokeLinejoin: "round"
12981
12174
  }
12982
- ) }),
12983
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12984
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12985
- "rect",
12175
+ ) }),
12176
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12177
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12178
+ "rect",
12179
+ {
12180
+ width: "12",
12181
+ height: "12",
12182
+ fill: "white",
12183
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12184
+ }
12185
+ ) }),
12186
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12187
+ "rect",
12188
+ {
12189
+ width: "12",
12190
+ height: "12",
12191
+ fill: "white",
12192
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12193
+ }
12194
+ ) }),
12195
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12196
+ "rect",
12197
+ {
12198
+ width: "12",
12199
+ height: "12",
12200
+ fill: "white",
12201
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12202
+ }
12203
+ ) }),
12204
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12205
+ "rect",
12206
+ {
12207
+ width: "12",
12208
+ height: "12",
12209
+ fill: "white",
12210
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12211
+ }
12212
+ ) }),
12213
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12214
+ "rect",
12215
+ {
12216
+ width: "12",
12217
+ height: "12",
12218
+ fill: "white",
12219
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12220
+ }
12221
+ ) }),
12222
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12223
+ "rect",
12224
+ {
12225
+ width: "12",
12226
+ height: "12",
12227
+ fill: "white",
12228
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12229
+ }
12230
+ ) })
12231
+ ] })
12232
+ ]
12233
+ }
12234
+ );
12235
+ };
12236
+ const schema = objectType({
12237
+ customer_id: stringType().min(1)
12238
+ });
12239
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
12240
+ const Shipping = () => {
12241
+ var _a;
12242
+ const { id } = reactRouterDom.useParams();
12243
+ const { order, isPending, isError, error } = useOrder(id, {
12244
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12245
+ });
12246
+ const {
12247
+ order: preview,
12248
+ isPending: isPreviewPending,
12249
+ isError: isPreviewError,
12250
+ error: previewError
12251
+ } = useOrderPreview(id);
12252
+ useInitiateOrderEdit({ preview });
12253
+ const { onCancel } = useCancelOrderEdit({ preview });
12254
+ if (isError) {
12255
+ throw error;
12256
+ }
12257
+ if (isPreviewError) {
12258
+ throw previewError;
12259
+ }
12260
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12261
+ const isReady = preview && !isPreviewPending && order && !isPending;
12262
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12263
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12264
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12265
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12266
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12267
+ ] }) }) }),
12268
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12269
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12270
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12271
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12272
+ ] }) });
12273
+ };
12274
+ const ShippingForm = ({ preview, order }) => {
12275
+ var _a;
12276
+ const { setIsOpen } = useStackedModal();
12277
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
12278
+ const [data, setData] = React.useState(null);
12279
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12280
+ const { shipping_options } = useShippingOptions(
12281
+ {
12282
+ id: appliedShippingOptionIds,
12283
+ fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
12284
+ },
12285
+ {
12286
+ enabled: appliedShippingOptionIds.length > 0
12287
+ }
12288
+ );
12289
+ const uniqueShippingProfiles = React.useMemo(() => {
12290
+ const profiles = /* @__PURE__ */ new Map();
12291
+ getUniqueShippingProfiles(order.items).forEach((profile) => {
12292
+ profiles.set(profile.id, profile);
12293
+ });
12294
+ shipping_options == null ? void 0 : shipping_options.forEach((option) => {
12295
+ profiles.set(option.shipping_profile_id, option.shipping_profile);
12296
+ });
12297
+ return Array.from(profiles.values());
12298
+ }, [order.items, shipping_options]);
12299
+ const { handleSuccess } = useRouteModal();
12300
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
12301
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
12302
+ const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
12303
+ const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
12304
+ const onSubmit = async () => {
12305
+ setIsSubmitting(true);
12306
+ let requestSucceeded = false;
12307
+ await requestOrderEdit(void 0, {
12308
+ onError: (e) => {
12309
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
12310
+ },
12311
+ onSuccess: () => {
12312
+ requestSucceeded = true;
12313
+ }
12314
+ });
12315
+ if (!requestSucceeded) {
12316
+ setIsSubmitting(false);
12317
+ return;
12318
+ }
12319
+ await confirmOrderEdit(void 0, {
12320
+ onError: (e) => {
12321
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
12322
+ },
12323
+ onSuccess: () => {
12324
+ handleSuccess();
12325
+ },
12326
+ onSettled: () => {
12327
+ setIsSubmitting(false);
12328
+ }
12329
+ });
12330
+ };
12331
+ const onKeydown = React.useCallback(
12332
+ (e) => {
12333
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
12334
+ if (data || isSubmitting) {
12335
+ return;
12336
+ }
12337
+ onSubmit();
12338
+ }
12339
+ },
12340
+ [data, isSubmitting, onSubmit]
12341
+ );
12342
+ React.useEffect(() => {
12343
+ document.addEventListener("keydown", onKeydown);
12344
+ return () => {
12345
+ document.removeEventListener("keydown", onKeydown);
12346
+ };
12347
+ }, [onKeydown]);
12348
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
12349
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12350
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: [
12351
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12352
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12353
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12354
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose which shipping method(s) to use for the items in the order." }) })
12355
+ ] }),
12356
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12357
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Root, { type: "multiple", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle rounded-xl shadow-elevation-card-rest", children: [
12358
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-4 py-2 flex items-center justify-between", children: [
12359
+ /* @__PURE__ */ jsxRuntime.jsx(
12360
+ ui.Text,
12361
+ {
12362
+ size: "xsmall",
12363
+ weight: "plus",
12364
+ className: "text-ui-fg-muted",
12365
+ children: "Shipping profile"
12366
+ }
12367
+ ),
12368
+ /* @__PURE__ */ jsxRuntime.jsx(
12369
+ ui.Text,
12370
+ {
12371
+ size: "xsmall",
12372
+ weight: "plus",
12373
+ className: "text-ui-fg-muted",
12374
+ children: "Action"
12375
+ }
12376
+ )
12377
+ ] }),
12378
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px] pb-[5px]", children: uniqueShippingProfiles.map((profile) => {
12379
+ var _a2, _b, _c, _d, _e, _f, _g;
12380
+ const items = getItemsWithShippingProfile(
12381
+ profile.id,
12382
+ order.items
12383
+ );
12384
+ const hasItems = items.length > 0;
12385
+ const shippingOption = shipping_options == null ? void 0 : shipping_options.find(
12386
+ (option) => option.shipping_profile_id === profile.id
12387
+ );
12388
+ const shippingMethod = preview.shipping_methods.find(
12389
+ (method) => method.shipping_option_id === (shippingOption == null ? void 0 : shippingOption.id)
12390
+ );
12391
+ const addShippingMethodAction = (_a2 = shippingMethod == null ? void 0 : shippingMethod.actions) == null ? void 0 : _a2.find(
12392
+ (action) => action.action === "SHIPPING_ADD"
12393
+ );
12394
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12395
+ radixUi.Accordion.Item,
12396
+ {
12397
+ value: profile.id,
12398
+ className: "bg-ui-bg-base shadow-elevation-card-rest rounded-lg",
12399
+ children: [
12400
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 flex items-center justify-between gap-3", children: [
12401
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full overflow-hidden", children: [
12402
+ /* @__PURE__ */ jsxRuntime.jsx(radixUi.Accordion.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
12403
+ ui.IconButton,
12404
+ {
12405
+ size: "2xsmall",
12406
+ variant: "transparent",
12407
+ className: "group/trigger",
12408
+ disabled: !hasItems,
12409
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.TriangleRightMini, { className: "group-data-[state=open]/trigger:rotate-90 transition-transform" })
12410
+ }
12411
+ ) }),
12412
+ !shippingOption ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12413
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 rounded-md shadow-borders-base flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-6 rounded bg-ui-bg-component-hover flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "text-ui-fg-subtle" }) }) }),
12414
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col flex-1", children: [
12415
+ /* @__PURE__ */ jsxRuntime.jsx(
12416
+ ui.Text,
12417
+ {
12418
+ size: "small",
12419
+ weight: "plus",
12420
+ leading: "compact",
12421
+ children: profile.name
12422
+ }
12423
+ ),
12424
+ /* @__PURE__ */ jsxRuntime.jsxs(
12425
+ ui.Text,
12426
+ {
12427
+ size: "small",
12428
+ leading: "compact",
12429
+ className: "text-ui-fg-subtle",
12430
+ children: [
12431
+ items.length,
12432
+ " ",
12433
+ pluralize(items.length, "items", "item")
12434
+ ]
12435
+ }
12436
+ )
12437
+ ] })
12438
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-[5px] max-sm:flex-col max-sm:items-start flex-1 w-full overflow-hidden", children: [
12439
+ /* @__PURE__ */ jsxRuntime.jsx(
12440
+ ui.Tooltip,
12441
+ {
12442
+ content: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: items.map((item) => {
12443
+ var _a3, _b2, _c2;
12444
+ return /* @__PURE__ */ jsxRuntime.jsx(
12445
+ "li",
12446
+ {
12447
+ children: `${item.quantity}x ${(_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title} (${(_c2 = item.variant) == null ? void 0 : _c2.title})`
12448
+ },
12449
+ item.id
12450
+ );
12451
+ }) }),
12452
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12453
+ ui.Badge,
12454
+ {
12455
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12456
+ size: "xsmall",
12457
+ children: [
12458
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Shopping, { className: "shrink-0" }),
12459
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "truncate", children: [
12460
+ items.reduce(
12461
+ (acc, item) => acc + item.quantity,
12462
+ 0
12463
+ ),
12464
+ "x",
12465
+ " ",
12466
+ pluralize(items.length, "items", "item")
12467
+ ] })
12468
+ ]
12469
+ }
12470
+ )
12471
+ }
12472
+ ),
12473
+ /* @__PURE__ */ jsxRuntime.jsx(
12474
+ ui.Tooltip,
12475
+ {
12476
+ content: (_d = (_c = (_b = shippingOption.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.name,
12477
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
12478
+ ui.Badge,
12479
+ {
12480
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12481
+ size: "xsmall",
12482
+ children: [
12483
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Buildings, { className: "shrink-0" }),
12484
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_g = (_f = (_e = shippingOption.service_zone) == null ? void 0 : _e.fulfillment_set) == null ? void 0 : _f.location) == null ? void 0 : _g.name })
12485
+ ]
12486
+ }
12487
+ )
12488
+ }
12489
+ ),
12490
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Tooltip, { content: shippingOption.name, children: /* @__PURE__ */ jsxRuntime.jsxs(
12491
+ ui.Badge,
12492
+ {
12493
+ className: "flex items-center gap-x-[3px] overflow-hidden cursor-default",
12494
+ size: "xsmall",
12495
+ children: [
12496
+ /* @__PURE__ */ jsxRuntime.jsx(icons.TruckFast, { className: "shrink-0" }),
12497
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: shippingOption.name })
12498
+ ]
12499
+ }
12500
+ ) })
12501
+ ] })
12502
+ ] }),
12503
+ shippingOption ? /* @__PURE__ */ jsxRuntime.jsx(
12504
+ ActionMenu,
12505
+ {
12506
+ groups: [
12507
+ {
12508
+ actions: [
12509
+ hasItems ? {
12510
+ label: "Edit shipping option",
12511
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Channels, {}),
12512
+ onClick: () => {
12513
+ setIsOpen(
12514
+ STACKED_FOCUS_MODAL_ID,
12515
+ true
12516
+ );
12517
+ setData({
12518
+ shippingProfileId: profile.id,
12519
+ shippingOption,
12520
+ shippingMethod
12521
+ });
12522
+ }
12523
+ } : void 0,
12524
+ {
12525
+ label: "Remove shipping option",
12526
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, {}),
12527
+ onClick: () => {
12528
+ if (shippingMethod) {
12529
+ if (addShippingMethodAction) {
12530
+ removeActionShippingMethod(
12531
+ addShippingMethodAction.id
12532
+ );
12533
+ } else {
12534
+ removeShippingMethod(
12535
+ shippingMethod.id
12536
+ );
12537
+ }
12538
+ }
12539
+ }
12540
+ }
12541
+ ].filter(Boolean)
12542
+ }
12543
+ ]
12544
+ }
12545
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
12546
+ StackedModalTrigger,
12547
+ {
12548
+ shippingProfileId: profile.id,
12549
+ shippingOption,
12550
+ shippingMethod,
12551
+ setData,
12552
+ children: "Add shipping option"
12553
+ }
12554
+ )
12555
+ ] }),
12556
+ /* @__PURE__ */ jsxRuntime.jsxs(radixUi.Accordion.Content, { children: [
12557
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12558
+ items.map((item, idx) => {
12559
+ var _a3, _b2, _c2, _d2, _e2;
12560
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12561
+ /* @__PURE__ */ jsxRuntime.jsxs(
12562
+ "div",
12563
+ {
12564
+ className: "px-3 flex items-center gap-x-3",
12565
+ children: [
12566
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-5 h-[56px] flex flex-col justify-center items-center", children: /* @__PURE__ */ jsxRuntime.jsx(
12567
+ ui.Divider,
12568
+ {
12569
+ variant: "dashed",
12570
+ orientation: "vertical"
12571
+ }
12572
+ ) }),
12573
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-2 flex items-center gap-x-3", children: [
12574
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "size-7 flex items-center justify-center tabular-nums", children: /* @__PURE__ */ jsxRuntime.jsxs(
12575
+ ui.Text,
12576
+ {
12577
+ size: "small",
12578
+ leading: "compact",
12579
+ className: "text-ui-fg-subtle",
12580
+ children: [
12581
+ item.quantity,
12582
+ "x"
12583
+ ]
12584
+ }
12585
+ ) }),
12586
+ /* @__PURE__ */ jsxRuntime.jsx(Thumbnail, { thumbnail: item.thumbnail }),
12587
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12588
+ /* @__PURE__ */ jsxRuntime.jsxs(
12589
+ ui.Text,
12590
+ {
12591
+ size: "small",
12592
+ leading: "compact",
12593
+ weight: "plus",
12594
+ children: [
12595
+ (_b2 = (_a3 = item.variant) == null ? void 0 : _a3.product) == null ? void 0 : _b2.title,
12596
+ " (",
12597
+ (_c2 = item.variant) == null ? void 0 : _c2.title,
12598
+ ")"
12599
+ ]
12600
+ }
12601
+ ),
12602
+ /* @__PURE__ */ jsxRuntime.jsx(
12603
+ ui.Text,
12604
+ {
12605
+ size: "small",
12606
+ leading: "compact",
12607
+ className: "text-ui-fg-subtle",
12608
+ children: (_e2 = (_d2 = item.variant) == null ? void 0 : _d2.options) == null ? void 0 : _e2.map((option) => option.value).join(" · ")
12609
+ }
12610
+ )
12611
+ ] })
12612
+ ] })
12613
+ ]
12614
+ },
12615
+ item.id
12616
+ ),
12617
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
12618
+ ] }, item.id);
12619
+ })
12620
+ ] })
12621
+ ]
12622
+ },
12623
+ profile.id
12624
+ );
12625
+ }) })
12626
+ ] }) })
12627
+ ] }) }),
12628
+ /* @__PURE__ */ jsxRuntime.jsx(
12629
+ StackedFocusModal,
12630
+ {
12631
+ id: STACKED_FOCUS_MODAL_ID,
12632
+ onOpenChangeCallback: (open) => {
12633
+ if (!open) {
12634
+ setData(null);
12635
+ }
12636
+ return open;
12637
+ },
12638
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12639
+ }
12640
+ )
12641
+ ] }),
12642
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12643
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12644
+ /* @__PURE__ */ jsxRuntime.jsx(
12645
+ ui.Button,
12646
+ {
12647
+ size: "small",
12648
+ type: "button",
12649
+ isLoading: isSubmitting,
12650
+ onClick: onSubmit,
12651
+ children: "Save"
12652
+ }
12653
+ )
12654
+ ] }) })
12655
+ ] });
12656
+ };
12657
+ const StackedModalTrigger = ({
12658
+ shippingProfileId,
12659
+ shippingOption,
12660
+ shippingMethod,
12661
+ setData,
12662
+ children
12663
+ }) => {
12664
+ const { setIsOpen, getIsOpen } = useStackedModal();
12665
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12666
+ const onToggle = () => {
12667
+ if (isOpen) {
12668
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12669
+ setData(null);
12670
+ } else {
12671
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12672
+ setData({
12673
+ shippingProfileId,
12674
+ shippingOption,
12675
+ shippingMethod
12676
+ });
12677
+ }
12678
+ };
12679
+ return /* @__PURE__ */ jsxRuntime.jsx(
12680
+ ui.Button,
12681
+ {
12682
+ size: "small",
12683
+ variant: "secondary",
12684
+ onClick: onToggle,
12685
+ className: "text-ui-fg-primary shrink-0",
12686
+ children
12687
+ }
12688
+ );
12689
+ };
12690
+ const ShippingProfileForm = ({
12691
+ data,
12692
+ order,
12693
+ preview
12694
+ }) => {
12695
+ var _a, _b, _c, _d, _e, _f;
12696
+ const { setIsOpen } = useStackedModal();
12697
+ const form = reactHookForm.useForm({
12698
+ resolver: zod.zodResolver(shippingMethodSchema),
12699
+ defaultValues: {
12700
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12701
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12702
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12703
+ }
12704
+ });
12705
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12706
+ const {
12707
+ mutateAsync: updateShippingMethod,
12708
+ isPending: isUpdatingShippingMethod
12709
+ } = useDraftOrderUpdateShippingMethod(order.id);
12710
+ const onSubmit = form.handleSubmit(async (values) => {
12711
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12712
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12713
+ return;
12714
+ }
12715
+ if (data.shippingMethod) {
12716
+ await updateShippingMethod(
12717
+ {
12718
+ method_id: data.shippingMethod.id,
12719
+ shipping_option_id: values.shipping_option_id,
12720
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12721
+ },
12722
+ {
12723
+ onError: (e) => {
12724
+ ui.toast.error(e.message);
12725
+ },
12726
+ onSuccess: () => {
12727
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12728
+ }
12729
+ }
12730
+ );
12731
+ return;
12732
+ }
12733
+ await addShippingMethod(
12734
+ {
12735
+ shipping_option_id: values.shipping_option_id,
12736
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12737
+ },
12738
+ {
12739
+ onError: (e) => {
12740
+ ui.toast.error(e.message);
12741
+ },
12742
+ onSuccess: () => {
12743
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12744
+ }
12745
+ }
12746
+ );
12747
+ });
12748
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12749
+ KeyboundForm,
12750
+ {
12751
+ className: "flex h-full flex-col overflow-hidden",
12752
+ onSubmit,
12753
+ children: [
12754
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12755
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12756
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12757
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12758
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12759
+ ] }),
12760
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12761
+ /* @__PURE__ */ jsxRuntime.jsx(
12762
+ LocationField,
12986
12763
  {
12987
- width: "12",
12988
- height: "12",
12989
- fill: "white",
12990
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12764
+ control: form.control,
12765
+ setValue: form.setValue
12991
12766
  }
12992
- ) }),
12993
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12994
- "rect",
12767
+ ),
12768
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12769
+ /* @__PURE__ */ jsxRuntime.jsx(
12770
+ ShippingOptionField,
12995
12771
  {
12996
- width: "12",
12997
- height: "12",
12998
- fill: "white",
12999
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12772
+ shippingProfileId: data.shippingProfileId,
12773
+ preview,
12774
+ control: form.control
13000
12775
  }
13001
- ) }),
13002
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13003
- "rect",
12776
+ ),
12777
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12778
+ /* @__PURE__ */ jsxRuntime.jsx(
12779
+ CustomAmountField,
13004
12780
  {
13005
- width: "12",
13006
- height: "12",
13007
- fill: "white",
13008
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12781
+ control: form.control,
12782
+ currencyCode: order.currency_code
13009
12783
  }
13010
- ) }),
13011
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13012
- "rect",
12784
+ ),
12785
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12786
+ /* @__PURE__ */ jsxRuntime.jsx(
12787
+ ItemsPreview,
12788
+ {
12789
+ order,
12790
+ shippingProfileId: data.shippingProfileId
12791
+ }
12792
+ )
12793
+ ] }) }) }),
12794
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12795
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12796
+ /* @__PURE__ */ jsxRuntime.jsx(
12797
+ ui.Button,
12798
+ {
12799
+ size: "small",
12800
+ type: "submit",
12801
+ isLoading: isPending || isUpdatingShippingMethod,
12802
+ children: data.shippingMethod ? "Update" : "Add"
12803
+ }
12804
+ )
12805
+ ] }) })
12806
+ ]
12807
+ }
12808
+ ) }) });
12809
+ };
12810
+ const shippingMethodSchema = objectType({
12811
+ location_id: stringType(),
12812
+ shipping_option_id: stringType(),
12813
+ custom_amount: unionType([numberType(), stringType()]).optional()
12814
+ });
12815
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12816
+ const matches = order.items.filter(
12817
+ (item) => {
12818
+ var _a, _b, _c;
12819
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12820
+ }
12821
+ );
12822
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12823
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12824
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12825
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12826
+ ] }) }),
12827
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12828
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12829
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12830
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12831
+ ] }),
12832
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12833
+ "div",
12834
+ {
12835
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12836
+ children: [
12837
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12838
+ /* @__PURE__ */ jsxRuntime.jsx(
12839
+ Thumbnail,
12840
+ {
12841
+ thumbnail: item.thumbnail,
12842
+ alt: item.product_title ?? void 0
12843
+ }
12844
+ ),
12845
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12846
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12847
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12848
+ /* @__PURE__ */ jsxRuntime.jsxs(
12849
+ ui.Text,
12850
+ {
12851
+ size: "small",
12852
+ leading: "compact",
12853
+ className: "text-ui-fg-subtle",
12854
+ children: [
12855
+ "(",
12856
+ item.variant_title,
12857
+ ")"
12858
+ ]
12859
+ }
12860
+ )
12861
+ ] }),
12862
+ /* @__PURE__ */ jsxRuntime.jsx(
12863
+ ui.Text,
12864
+ {
12865
+ size: "small",
12866
+ leading: "compact",
12867
+ className: "text-ui-fg-subtle",
12868
+ children: item.variant_sku
12869
+ }
12870
+ )
12871
+ ] })
12872
+ ] }),
12873
+ /* @__PURE__ */ jsxRuntime.jsxs(
12874
+ ui.Text,
12875
+ {
12876
+ size: "small",
12877
+ leading: "compact",
12878
+ className: "text-ui-fg-subtle",
12879
+ children: [
12880
+ item.quantity,
12881
+ "x"
12882
+ ]
12883
+ }
12884
+ )
12885
+ ]
12886
+ },
12887
+ item.id
12888
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12889
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12890
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12891
+ 'No items found for "',
12892
+ query,
12893
+ '".'
12894
+ ] })
12895
+ ] }) })
12896
+ ] })
12897
+ ] });
12898
+ };
12899
+ const LocationField = ({ control, setValue }) => {
12900
+ const locations = useComboboxData({
12901
+ queryKey: ["locations"],
12902
+ queryFn: async (params) => {
12903
+ return await sdk.admin.stockLocation.list(params);
12904
+ },
12905
+ getOptions: (data) => {
12906
+ return data.stock_locations.map((location) => ({
12907
+ label: location.name,
12908
+ value: location.id
12909
+ }));
12910
+ }
12911
+ });
12912
+ return /* @__PURE__ */ jsxRuntime.jsx(
12913
+ Form$2.Field,
12914
+ {
12915
+ control,
12916
+ name: "location_id",
12917
+ render: ({ field: { onChange, ...field } }) => {
12918
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12919
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12922
+ ] }),
12923
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12924
+ Combobox,
13013
12925
  {
13014
- width: "12",
13015
- height: "12",
13016
- fill: "white",
13017
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12926
+ options: locations.options,
12927
+ fetchNextPage: locations.fetchNextPage,
12928
+ isFetchingNextPage: locations.isFetchingNextPage,
12929
+ searchValue: locations.searchValue,
12930
+ onSearchValueChange: locations.onSearchValueChange,
12931
+ placeholder: "Select location",
12932
+ onChange: (value) => {
12933
+ setValue("shipping_option_id", "", {
12934
+ shouldDirty: true,
12935
+ shouldTouch: true
12936
+ });
12937
+ onChange(value);
12938
+ },
12939
+ ...field
13018
12940
  }
13019
- ) }),
13020
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13021
- "rect",
12941
+ ) })
12942
+ ] }) });
12943
+ }
12944
+ }
12945
+ );
12946
+ };
12947
+ const ShippingOptionField = ({
12948
+ shippingProfileId,
12949
+ preview,
12950
+ control
12951
+ }) => {
12952
+ var _a;
12953
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12954
+ const shippingOptions = useComboboxData({
12955
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12956
+ queryFn: async (params) => {
12957
+ return await sdk.admin.shippingOption.list({
12958
+ ...params,
12959
+ stock_location_id: locationId,
12960
+ shipping_profile_id: shippingProfileId
12961
+ });
12962
+ },
12963
+ getOptions: (data) => {
12964
+ return data.shipping_options.map((option) => {
12965
+ var _a2;
12966
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12967
+ (r) => r.attribute === "is_return" && r.value === "true"
12968
+ )) {
12969
+ return void 0;
12970
+ }
12971
+ return {
12972
+ label: option.name,
12973
+ value: option.id
12974
+ };
12975
+ }).filter(Boolean);
12976
+ },
12977
+ enabled: !!locationId && !!shippingProfileId,
12978
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12979
+ });
12980
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12981
+ return /* @__PURE__ */ jsxRuntime.jsx(
12982
+ Form$2.Field,
12983
+ {
12984
+ control,
12985
+ name: "shipping_option_id",
12986
+ render: ({ field }) => {
12987
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12988
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12989
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12990
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12991
+ ] }),
12992
+ /* @__PURE__ */ jsxRuntime.jsx(
12993
+ ConditionalTooltip,
13022
12994
  {
13023
- width: "12",
13024
- height: "12",
13025
- fill: "white",
13026
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12995
+ content: tooltipContent,
12996
+ showTooltip: !locationId || !shippingProfileId,
12997
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12998
+ Combobox,
12999
+ {
13000
+ options: shippingOptions.options,
13001
+ fetchNextPage: shippingOptions.fetchNextPage,
13002
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
13003
+ searchValue: shippingOptions.searchValue,
13004
+ onSearchValueChange: shippingOptions.onSearchValueChange,
13005
+ placeholder: "Select shipping option",
13006
+ ...field,
13007
+ disabled: !locationId || !shippingProfileId
13008
+ }
13009
+ ) }) })
13027
13010
  }
13028
- ) }),
13029
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
13030
- "rect",
13011
+ )
13012
+ ] }) });
13013
+ }
13014
+ }
13015
+ );
13016
+ };
13017
+ const CustomAmountField = ({
13018
+ control,
13019
+ currencyCode
13020
+ }) => {
13021
+ return /* @__PURE__ */ jsxRuntime.jsx(
13022
+ Form$2.Field,
13023
+ {
13024
+ control,
13025
+ name: "custom_amount",
13026
+ render: ({ field: { onChange, ...field } }) => {
13027
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13028
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13029
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13030
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
13031
+ ] }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13033
+ ui.CurrencyInput,
13031
13034
  {
13032
- width: "12",
13033
- height: "12",
13034
- fill: "white",
13035
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
13035
+ ...field,
13036
+ onValueChange: (value) => onChange(value),
13037
+ symbol: getNativeSymbol(currencyCode),
13038
+ code: currencyCode
13036
13039
  }
13037
13040
  ) })
13038
- ] })
13039
- ]
13041
+ ] });
13042
+ }
13040
13043
  }
13041
13044
  );
13042
13045
  };
13043
- const schema = objectType({
13044
- customer_id: stringType().min(1)
13045
- });
13046
13046
  const widgetModule = { widgets: [] };
13047
13047
  const routeModule = {
13048
13048
  routes: [
@@ -13071,29 +13071,25 @@ 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: SalesChannel,
13092
- path: "/draft-orders/:id/sales-channel"
13087
+ Component: Metadata,
13088
+ path: "/draft-orders/:id/metadata"
13093
13089
  },
13094
13090
  {
13095
- Component: Shipping,
13096
- path: "/draft-orders/:id/shipping"
13091
+ Component: SalesChannel,
13092
+ path: "/draft-orders/:id/sales-channel"
13097
13093
  },
13098
13094
  {
13099
13095
  Component: ShippingAddress,
@@ -13102,6 +13098,10 @@ const routeModule = {
13102
13098
  {
13103
13099
  Component: TransferOwnership,
13104
13100
  path: "/draft-orders/:id/transfer-ownership"
13101
+ },
13102
+ {
13103
+ Component: Shipping,
13104
+ path: "/draft-orders/:id/shipping"
13105
13105
  }
13106
13106
  ]
13107
13107
  }