@medusajs/draft-order 2.10.0-snapshot-20250828112445 → 2.10.0-snapshot-20250828114928

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.
@@ -9771,54 +9771,10 @@ const CustomItemsForm = () => {
9771
9771
  const schema$4 = objectType({
9772
9772
  email: stringType().email()
9773
9773
  });
9774
- const InlineTip = React.forwardRef(
9775
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9776
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9777
- return /* @__PURE__ */ jsxRuntime.jsxs(
9778
- "div",
9779
- {
9780
- ref,
9781
- className: ui.clx(
9782
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9783
- className
9784
- ),
9785
- ...props,
9786
- children: [
9787
- /* @__PURE__ */ jsxRuntime.jsx(
9788
- "div",
9789
- {
9790
- role: "presentation",
9791
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9792
- "bg-ui-tag-orange-icon": variant === "warning"
9793
- })
9794
- }
9795
- ),
9796
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9797
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9798
- labelValue,
9799
- ":"
9800
- ] }),
9801
- " ",
9802
- children
9803
- ] })
9804
- ]
9805
- }
9806
- );
9807
- }
9808
- );
9809
- InlineTip.displayName = "InlineTip";
9810
- const MetadataFieldSchema = objectType({
9811
- key: stringType(),
9812
- disabled: booleanType().optional(),
9813
- value: anyType()
9814
- });
9815
- const MetadataSchema = objectType({
9816
- metadata: arrayType(MetadataFieldSchema)
9817
- });
9818
- const Metadata = () => {
9774
+ const Email = () => {
9819
9775
  const { id } = reactRouterDom.useParams();
9820
9776
  const { order, isPending, isError, error } = useOrder(id, {
9821
- fields: "metadata"
9777
+ fields: "+email"
9822
9778
  });
9823
9779
  if (isError) {
9824
9780
  throw error;
@@ -9826,33 +9782,26 @@ const Metadata = () => {
9826
9782
  const isReady = !isPending && !!order;
9827
9783
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9828
9784
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9829
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9830
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9785
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
9786
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
9831
9787
  ] }),
9832
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9788
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
9833
9789
  ] });
9834
9790
  };
9835
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9836
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9837
- const MetadataForm = ({ orderId, metadata }) => {
9838
- const { handleSuccess } = useRouteModal();
9839
- const hasUneditableRows = getHasUneditableRows(metadata);
9840
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9791
+ const EmailForm = ({ order }) => {
9841
9792
  const form = reactHookForm.useForm({
9842
9793
  defaultValues: {
9843
- metadata: getDefaultValues(metadata)
9794
+ email: order.email ?? ""
9844
9795
  },
9845
- resolver: zod.zodResolver(MetadataSchema)
9796
+ resolver: zod.zodResolver(schema$3)
9846
9797
  });
9847
- const handleSubmit = form.handleSubmit(async (data) => {
9848
- const parsedData = parseValues(data);
9798
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9799
+ const { handleSuccess } = useRouteModal();
9800
+ const onSubmit = form.handleSubmit(async (data) => {
9849
9801
  await mutateAsync(
9850
- {
9851
- metadata: parsedData
9852
- },
9802
+ { email: data.email },
9853
9803
  {
9854
9804
  onSuccess: () => {
9855
- ui.toast.success("Metadata updated");
9856
9805
  handleSuccess();
9857
9806
  },
9858
9807
  onError: (error) => {
@@ -9861,266 +9810,35 @@ const MetadataForm = ({ orderId, metadata }) => {
9861
9810
  }
9862
9811
  );
9863
9812
  });
9864
- const { fields, insert, remove } = reactHookForm.useFieldArray({
9865
- control: form.control,
9866
- name: "metadata"
9867
- });
9868
- function deleteRow(index) {
9869
- remove(index);
9870
- if (fields.length === 1) {
9871
- insert(0, {
9872
- key: "",
9873
- value: "",
9874
- disabled: false
9875
- });
9876
- }
9877
- }
9878
- function insertRow(index, position) {
9879
- insert(index + (position === "above" ? 0 : 1), {
9880
- key: "",
9881
- value: "",
9882
- disabled: false
9883
- });
9884
- }
9885
9813
  return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9886
9814
  KeyboundForm,
9887
9815
  {
9888
- onSubmit: handleSubmit,
9889
9816
  className: "flex flex-1 flex-col overflow-hidden",
9817
+ onSubmit,
9890
9818
  children: [
9891
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9892
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9893
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9894
- /* @__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" }) }),
9895
- /* @__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" }) })
9896
- ] }),
9897
- fields.map((field, index) => {
9898
- const isDisabled = field.disabled || false;
9899
- let placeholder = "-";
9900
- if (typeof field.value === "object") {
9901
- placeholder = "{ ... }";
9902
- }
9903
- if (Array.isArray(field.value)) {
9904
- placeholder = "[ ... ]";
9905
- }
9906
- return /* @__PURE__ */ jsxRuntime.jsx(
9907
- ConditionalTooltip,
9908
- {
9909
- showTooltip: isDisabled,
9910
- content: "This row is disabled because it contains non-primitive data.",
9911
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9912
- /* @__PURE__ */ jsxRuntime.jsxs(
9913
- "div",
9914
- {
9915
- className: ui.clx("grid grid-cols-2 divide-x", {
9916
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9917
- }),
9918
- children: [
9919
- /* @__PURE__ */ jsxRuntime.jsx(
9920
- Form$2.Field,
9921
- {
9922
- control: form.control,
9923
- name: `metadata.${index}.key`,
9924
- render: ({ field: field2 }) => {
9925
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9926
- GridInput,
9927
- {
9928
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9929
- ...field2,
9930
- disabled: isDisabled,
9931
- placeholder: "Key"
9932
- }
9933
- ) }) });
9934
- }
9935
- }
9936
- ),
9937
- /* @__PURE__ */ jsxRuntime.jsx(
9938
- Form$2.Field,
9939
- {
9940
- control: form.control,
9941
- name: `metadata.${index}.value`,
9942
- render: ({ field: { value, ...field2 } }) => {
9943
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9944
- GridInput,
9945
- {
9946
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9947
- ...field2,
9948
- value: isDisabled ? placeholder : value,
9949
- disabled: isDisabled,
9950
- placeholder: "Value"
9951
- }
9952
- ) }) });
9953
- }
9954
- }
9955
- )
9956
- ]
9957
- }
9958
- ),
9959
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
9960
- /* @__PURE__ */ jsxRuntime.jsx(
9961
- ui.DropdownMenu.Trigger,
9962
- {
9963
- className: ui.clx(
9964
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
9965
- {
9966
- hidden: isDisabled
9967
- }
9968
- ),
9969
- disabled: isDisabled,
9970
- asChild: true,
9971
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
9972
- }
9973
- ),
9974
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
9975
- /* @__PURE__ */ jsxRuntime.jsxs(
9976
- ui.DropdownMenu.Item,
9977
- {
9978
- className: "gap-x-2",
9979
- onClick: () => insertRow(index, "above"),
9980
- children: [
9981
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
9982
- "Insert row above"
9983
- ]
9984
- }
9985
- ),
9986
- /* @__PURE__ */ jsxRuntime.jsxs(
9987
- ui.DropdownMenu.Item,
9988
- {
9989
- className: "gap-x-2",
9990
- onClick: () => insertRow(index, "below"),
9991
- children: [
9992
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
9993
- "Insert row below"
9994
- ]
9995
- }
9996
- ),
9997
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
9998
- /* @__PURE__ */ jsxRuntime.jsxs(
9999
- ui.DropdownMenu.Item,
10000
- {
10001
- className: "gap-x-2",
10002
- onClick: () => deleteRow(index),
10003
- children: [
10004
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10005
- "Delete row"
10006
- ]
10007
- }
10008
- )
10009
- ] })
10010
- ] })
10011
- ] })
10012
- },
10013
- field.id
10014
- );
10015
- })
10016
- ] }),
10017
- 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." })
10018
- ] }),
10019
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10020
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
9819
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
9820
+ Form$2.Field,
9821
+ {
9822
+ control: form.control,
9823
+ name: "email",
9824
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
9825
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
9826
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
9827
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
9828
+ ] })
9829
+ }
9830
+ ) }),
9831
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9832
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10021
9833
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10022
9834
  ] }) })
10023
9835
  ]
10024
9836
  }
10025
9837
  ) });
10026
9838
  };
10027
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10028
- return /* @__PURE__ */ jsxRuntime.jsx(
10029
- "input",
10030
- {
10031
- ref,
10032
- ...props,
10033
- autoComplete: "off",
10034
- className: ui.clx(
10035
- "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",
10036
- className
10037
- )
10038
- }
10039
- );
9839
+ const schema$3 = objectType({
9840
+ email: stringType().email()
10040
9841
  });
10041
- GridInput.displayName = "MetadataForm.GridInput";
10042
- const PlaceholderInner = () => {
10043
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10044
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10045
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10046
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10047
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10048
- ] }) })
10049
- ] });
10050
- };
10051
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10052
- function getDefaultValues(metadata) {
10053
- if (!metadata || !Object.keys(metadata).length) {
10054
- return [
10055
- {
10056
- key: "",
10057
- value: "",
10058
- disabled: false
10059
- }
10060
- ];
10061
- }
10062
- return Object.entries(metadata).map(([key, value]) => {
10063
- if (!EDITABLE_TYPES.includes(typeof value)) {
10064
- return {
10065
- key,
10066
- value,
10067
- disabled: true
10068
- };
10069
- }
10070
- let stringValue = value;
10071
- if (typeof value !== "string") {
10072
- stringValue = JSON.stringify(value);
10073
- }
10074
- return {
10075
- key,
10076
- value: stringValue,
10077
- original_key: key
10078
- };
10079
- });
10080
- }
10081
- function parseValues(values) {
10082
- const metadata = values.metadata;
10083
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10084
- if (isEmpty) {
10085
- return null;
10086
- }
10087
- const update = {};
10088
- metadata.forEach((field) => {
10089
- let key = field.key;
10090
- let value = field.value;
10091
- const disabled = field.disabled;
10092
- if (!key || !value) {
10093
- return;
10094
- }
10095
- if (disabled) {
10096
- update[key] = value;
10097
- return;
10098
- }
10099
- key = key.trim();
10100
- value = value.trim();
10101
- if (value === "true") {
10102
- update[key] = true;
10103
- } else if (value === "false") {
10104
- update[key] = false;
10105
- } else {
10106
- const parsedNumber = parseFloat(value);
10107
- if (!isNaN(parsedNumber)) {
10108
- update[key] = parsedNumber;
10109
- } else {
10110
- update[key] = value;
10111
- }
10112
- }
10113
- });
10114
- return update;
10115
- }
10116
- function getHasUneditableRows(metadata) {
10117
- if (!metadata) {
10118
- return false;
10119
- }
10120
- return Object.values(metadata).some(
10121
- (value) => !EDITABLE_TYPES.includes(typeof value)
10122
- );
10123
- }
10124
9842
  const NumberInput = React.forwardRef(
10125
9843
  ({
10126
9844
  value,
@@ -11095,195 +10813,545 @@ const customItemSchema = objectType({
11095
10813
  quantity: numberType(),
11096
10814
  unit_price: unionType([numberType(), stringType()])
11097
10815
  });
11098
- const PROMOTION_QUERY_KEY = "promotions";
11099
- const promotionsQueryKeys = {
11100
- list: (query2) => [
11101
- PROMOTION_QUERY_KEY,
11102
- query2 ? query2 : void 0
11103
- ],
11104
- detail: (id, query2) => [
11105
- PROMOTION_QUERY_KEY,
11106
- id,
11107
- query2 ? query2 : void 0
11108
- ]
11109
- };
11110
- const usePromotions = (query2, options) => {
11111
- const { data, ...rest } = reactQuery.useQuery({
11112
- queryKey: promotionsQueryKeys.list(query2),
11113
- queryFn: async () => sdk.admin.promotion.list(query2),
11114
- ...options
11115
- });
11116
- return { ...data, ...rest };
11117
- };
11118
- const Promotions = () => {
10816
+ const InlineTip = React.forwardRef(
10817
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10818
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10819
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10820
+ "div",
10821
+ {
10822
+ ref,
10823
+ className: ui.clx(
10824
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10825
+ className
10826
+ ),
10827
+ ...props,
10828
+ children: [
10829
+ /* @__PURE__ */ jsxRuntime.jsx(
10830
+ "div",
10831
+ {
10832
+ role: "presentation",
10833
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10834
+ "bg-ui-tag-orange-icon": variant === "warning"
10835
+ })
10836
+ }
10837
+ ),
10838
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10839
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10840
+ labelValue,
10841
+ ":"
10842
+ ] }),
10843
+ " ",
10844
+ children
10845
+ ] })
10846
+ ]
10847
+ }
10848
+ );
10849
+ }
10850
+ );
10851
+ InlineTip.displayName = "InlineTip";
10852
+ const MetadataFieldSchema = objectType({
10853
+ key: stringType(),
10854
+ disabled: booleanType().optional(),
10855
+ value: anyType()
10856
+ });
10857
+ const MetadataSchema = objectType({
10858
+ metadata: arrayType(MetadataFieldSchema)
10859
+ });
10860
+ const Metadata = () => {
11119
10861
  const { id } = reactRouterDom.useParams();
11120
- const {
11121
- order: preview,
11122
- isError: isPreviewError,
11123
- error: previewError
11124
- } = useOrderPreview(id, void 0);
11125
- useInitiateOrderEdit({ preview });
11126
- const { onCancel } = useCancelOrderEdit({ preview });
11127
- if (isPreviewError) {
11128
- throw previewError;
10862
+ const { order, isPending, isError, error } = useOrder(id, {
10863
+ fields: "metadata"
10864
+ });
10865
+ if (isError) {
10866
+ throw error;
11129
10867
  }
11130
- const isReady = !!preview;
11131
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11132
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11133
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
10868
+ const isReady = !isPending && !!order;
10869
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10870
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10871
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10872
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10873
+ ] }),
10874
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11134
10875
  ] });
11135
10876
  };
11136
- const PromotionForm = ({ preview }) => {
11137
- const { items, shipping_methods } = preview;
11138
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11139
- const [comboboxValue, setComboboxValue] = React.useState("");
10877
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10878
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10879
+ const MetadataForm = ({ orderId, metadata }) => {
11140
10880
  const { handleSuccess } = useRouteModal();
11141
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11142
- const promoCodes = getPromotionCodes(items, shipping_methods);
11143
- const { promotions, isPending, isError, error } = usePromotions(
11144
- {
11145
- code: promoCodes
11146
- },
11147
- {
11148
- enabled: !!promoCodes.length
11149
- }
11150
- );
11151
- const comboboxData = useComboboxData({
11152
- queryKey: ["promotions", "combobox", promoCodes],
11153
- queryFn: async (params) => {
11154
- return await sdk.admin.promotion.list({
11155
- ...params,
11156
- code: {
11157
- $nin: promoCodes
11158
- }
11159
- });
10881
+ const hasUneditableRows = getHasUneditableRows(metadata);
10882
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10883
+ const form = reactHookForm.useForm({
10884
+ defaultValues: {
10885
+ metadata: getDefaultValues(metadata)
11160
10886
  },
11161
- getOptions: (data) => {
11162
- return data.promotions.map((promotion) => ({
11163
- label: promotion.code,
11164
- value: promotion.code
11165
- }));
11166
- }
10887
+ resolver: zod.zodResolver(MetadataSchema)
11167
10888
  });
11168
- const add = async (value) => {
11169
- if (!value) {
11170
- return;
11171
- }
11172
- addPromotions(
10889
+ const handleSubmit = form.handleSubmit(async (data) => {
10890
+ const parsedData = parseValues(data);
10891
+ await mutateAsync(
11173
10892
  {
11174
- promo_codes: [value]
10893
+ metadata: parsedData
11175
10894
  },
11176
10895
  {
11177
- onError: (e) => {
11178
- ui.toast.error(e.message);
11179
- comboboxData.onSearchValueChange("");
11180
- setComboboxValue("");
11181
- },
11182
10896
  onSuccess: () => {
11183
- comboboxData.onSearchValueChange("");
11184
- setComboboxValue("");
10897
+ ui.toast.success("Metadata updated");
10898
+ handleSuccess();
10899
+ },
10900
+ onError: (error) => {
10901
+ ui.toast.error(error.message);
11185
10902
  }
11186
10903
  }
11187
10904
  );
11188
- };
11189
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11190
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11191
- const onSubmit = async () => {
11192
- setIsSubmitting(true);
11193
- let requestSucceeded = false;
11194
- await requestOrderEdit(void 0, {
11195
- onError: (e) => {
11196
- ui.toast.error(e.message);
11197
- },
11198
- onSuccess: () => {
11199
- requestSucceeded = true;
11200
- }
11201
- });
11202
- if (!requestSucceeded) {
11203
- setIsSubmitting(false);
11204
- return;
11205
- }
11206
- await confirmOrderEdit(void 0, {
11207
- onError: (e) => {
11208
- ui.toast.error(e.message);
11209
- },
11210
- onSuccess: () => {
11211
- handleSuccess();
11212
- },
11213
- onSettled: () => {
11214
- setIsSubmitting(false);
11215
- }
10905
+ });
10906
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10907
+ control: form.control,
10908
+ name: "metadata"
10909
+ });
10910
+ function deleteRow(index) {
10911
+ remove(index);
10912
+ if (fields.length === 1) {
10913
+ insert(0, {
10914
+ key: "",
10915
+ value: "",
10916
+ disabled: false
10917
+ });
10918
+ }
10919
+ }
10920
+ function insertRow(index, position) {
10921
+ insert(index + (position === "above" ? 0 : 1), {
10922
+ key: "",
10923
+ value: "",
10924
+ disabled: false
11216
10925
  });
11217
- };
11218
- if (isError) {
11219
- throw error;
11220
10926
  }
11221
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11222
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11223
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11224
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11225
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11226
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10927
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10928
+ KeyboundForm,
10929
+ {
10930
+ onSubmit: handleSubmit,
10931
+ className: "flex flex-1 flex-col overflow-hidden",
10932
+ children: [
10933
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10934
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10935
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10936
+ /* @__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" }) }),
10937
+ /* @__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" }) })
10938
+ ] }),
10939
+ fields.map((field, index) => {
10940
+ const isDisabled = field.disabled || false;
10941
+ let placeholder = "-";
10942
+ if (typeof field.value === "object") {
10943
+ placeholder = "{ ... }";
10944
+ }
10945
+ if (Array.isArray(field.value)) {
10946
+ placeholder = "[ ... ]";
10947
+ }
10948
+ return /* @__PURE__ */ jsxRuntime.jsx(
10949
+ ConditionalTooltip,
10950
+ {
10951
+ showTooltip: isDisabled,
10952
+ content: "This row is disabled because it contains non-primitive data.",
10953
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10954
+ /* @__PURE__ */ jsxRuntime.jsxs(
10955
+ "div",
10956
+ {
10957
+ className: ui.clx("grid grid-cols-2 divide-x", {
10958
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10959
+ }),
10960
+ children: [
10961
+ /* @__PURE__ */ jsxRuntime.jsx(
10962
+ Form$2.Field,
10963
+ {
10964
+ control: form.control,
10965
+ name: `metadata.${index}.key`,
10966
+ render: ({ field: field2 }) => {
10967
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10968
+ GridInput,
10969
+ {
10970
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10971
+ ...field2,
10972
+ disabled: isDisabled,
10973
+ placeholder: "Key"
10974
+ }
10975
+ ) }) });
10976
+ }
10977
+ }
10978
+ ),
10979
+ /* @__PURE__ */ jsxRuntime.jsx(
10980
+ Form$2.Field,
10981
+ {
10982
+ control: form.control,
10983
+ name: `metadata.${index}.value`,
10984
+ render: ({ field: { value, ...field2 } }) => {
10985
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10986
+ GridInput,
10987
+ {
10988
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10989
+ ...field2,
10990
+ value: isDisabled ? placeholder : value,
10991
+ disabled: isDisabled,
10992
+ placeholder: "Value"
10993
+ }
10994
+ ) }) });
10995
+ }
10996
+ }
10997
+ )
10998
+ ]
10999
+ }
11000
+ ),
11001
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11002
+ /* @__PURE__ */ jsxRuntime.jsx(
11003
+ ui.DropdownMenu.Trigger,
11004
+ {
11005
+ className: ui.clx(
11006
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11007
+ {
11008
+ hidden: isDisabled
11009
+ }
11010
+ ),
11011
+ disabled: isDisabled,
11012
+ asChild: true,
11013
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11014
+ }
11015
+ ),
11016
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11017
+ /* @__PURE__ */ jsxRuntime.jsxs(
11018
+ ui.DropdownMenu.Item,
11019
+ {
11020
+ className: "gap-x-2",
11021
+ onClick: () => insertRow(index, "above"),
11022
+ children: [
11023
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11024
+ "Insert row above"
11025
+ ]
11026
+ }
11027
+ ),
11028
+ /* @__PURE__ */ jsxRuntime.jsxs(
11029
+ ui.DropdownMenu.Item,
11030
+ {
11031
+ className: "gap-x-2",
11032
+ onClick: () => insertRow(index, "below"),
11033
+ children: [
11034
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11035
+ "Insert row below"
11036
+ ]
11037
+ }
11038
+ ),
11039
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11040
+ /* @__PURE__ */ jsxRuntime.jsxs(
11041
+ ui.DropdownMenu.Item,
11042
+ {
11043
+ className: "gap-x-2",
11044
+ onClick: () => deleteRow(index),
11045
+ children: [
11046
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11047
+ "Delete row"
11048
+ ]
11049
+ }
11050
+ )
11051
+ ] })
11052
+ ] })
11053
+ ] })
11054
+ },
11055
+ field.id
11056
+ );
11057
+ })
11058
+ ] }),
11059
+ 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." })
11227
11060
  ] }),
11228
- /* @__PURE__ */ jsxRuntime.jsx(
11229
- Combobox,
11230
- {
11231
- id: "promotion-combobox",
11232
- "aria-describedby": "promotion-combobox-hint",
11233
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11234
- fetchNextPage: comboboxData.fetchNextPage,
11235
- options: comboboxData.options,
11236
- onSearchValueChange: comboboxData.onSearchValueChange,
11237
- searchValue: comboboxData.searchValue,
11238
- disabled: comboboxData.disabled || isAddingPromotions,
11239
- onChange: add,
11240
- value: comboboxValue
11241
- }
11242
- )
11243
- ] }),
11244
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11245
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11246
- PromotionItem,
11247
- {
11248
- promotion,
11249
- orderId: preview.id,
11250
- isLoading: isPending
11251
- },
11252
- promotion.id
11253
- )) })
11254
- ] }) }),
11255
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11256
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11257
- /* @__PURE__ */ jsxRuntime.jsx(
11258
- ui.Button,
11259
- {
11260
- size: "small",
11261
- type: "submit",
11262
- isLoading: isSubmitting || isAddingPromotions,
11263
- children: "Save"
11264
- }
11061
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11062
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11063
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11064
+ ] }) })
11065
+ ]
11066
+ }
11067
+ ) });
11068
+ };
11069
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11070
+ return /* @__PURE__ */ jsxRuntime.jsx(
11071
+ "input",
11072
+ {
11073
+ ref,
11074
+ ...props,
11075
+ autoComplete: "off",
11076
+ className: ui.clx(
11077
+ "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",
11078
+ className
11265
11079
  )
11080
+ }
11081
+ );
11082
+ });
11083
+ GridInput.displayName = "MetadataForm.GridInput";
11084
+ const PlaceholderInner = () => {
11085
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11086
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11087
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11088
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11089
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11266
11090
  ] }) })
11267
11091
  ] });
11268
11092
  };
11269
- const PromotionItem = ({
11270
- promotion,
11271
- orderId,
11272
- isLoading
11273
- }) => {
11274
- var _a;
11275
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11276
- const onRemove = async () => {
11277
- removePromotions(
11278
- {
11279
- promo_codes: [promotion.code]
11280
- },
11093
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11094
+ function getDefaultValues(metadata) {
11095
+ if (!metadata || !Object.keys(metadata).length) {
11096
+ return [
11281
11097
  {
11282
- onError: (e) => {
11283
- ui.toast.error(e.message);
11284
- }
11098
+ key: "",
11099
+ value: "",
11100
+ disabled: false
11285
11101
  }
11286
- );
11102
+ ];
11103
+ }
11104
+ return Object.entries(metadata).map(([key, value]) => {
11105
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11106
+ return {
11107
+ key,
11108
+ value,
11109
+ disabled: true
11110
+ };
11111
+ }
11112
+ let stringValue = value;
11113
+ if (typeof value !== "string") {
11114
+ stringValue = JSON.stringify(value);
11115
+ }
11116
+ return {
11117
+ key,
11118
+ value: stringValue,
11119
+ original_key: key
11120
+ };
11121
+ });
11122
+ }
11123
+ function parseValues(values) {
11124
+ const metadata = values.metadata;
11125
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11126
+ if (isEmpty) {
11127
+ return null;
11128
+ }
11129
+ const update = {};
11130
+ metadata.forEach((field) => {
11131
+ let key = field.key;
11132
+ let value = field.value;
11133
+ const disabled = field.disabled;
11134
+ if (!key || !value) {
11135
+ return;
11136
+ }
11137
+ if (disabled) {
11138
+ update[key] = value;
11139
+ return;
11140
+ }
11141
+ key = key.trim();
11142
+ value = value.trim();
11143
+ if (value === "true") {
11144
+ update[key] = true;
11145
+ } else if (value === "false") {
11146
+ update[key] = false;
11147
+ } else {
11148
+ const parsedNumber = parseFloat(value);
11149
+ if (!isNaN(parsedNumber)) {
11150
+ update[key] = parsedNumber;
11151
+ } else {
11152
+ update[key] = value;
11153
+ }
11154
+ }
11155
+ });
11156
+ return update;
11157
+ }
11158
+ function getHasUneditableRows(metadata) {
11159
+ if (!metadata) {
11160
+ return false;
11161
+ }
11162
+ return Object.values(metadata).some(
11163
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11164
+ );
11165
+ }
11166
+ const PROMOTION_QUERY_KEY = "promotions";
11167
+ const promotionsQueryKeys = {
11168
+ list: (query2) => [
11169
+ PROMOTION_QUERY_KEY,
11170
+ query2 ? query2 : void 0
11171
+ ],
11172
+ detail: (id, query2) => [
11173
+ PROMOTION_QUERY_KEY,
11174
+ id,
11175
+ query2 ? query2 : void 0
11176
+ ]
11177
+ };
11178
+ const usePromotions = (query2, options) => {
11179
+ const { data, ...rest } = reactQuery.useQuery({
11180
+ queryKey: promotionsQueryKeys.list(query2),
11181
+ queryFn: async () => sdk.admin.promotion.list(query2),
11182
+ ...options
11183
+ });
11184
+ return { ...data, ...rest };
11185
+ };
11186
+ const Promotions = () => {
11187
+ const { id } = reactRouterDom.useParams();
11188
+ const {
11189
+ order: preview,
11190
+ isError: isPreviewError,
11191
+ error: previewError
11192
+ } = useOrderPreview(id, void 0);
11193
+ useInitiateOrderEdit({ preview });
11194
+ const { onCancel } = useCancelOrderEdit({ preview });
11195
+ if (isPreviewError) {
11196
+ throw previewError;
11197
+ }
11198
+ const isReady = !!preview;
11199
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11200
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11201
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11202
+ ] });
11203
+ };
11204
+ const PromotionForm = ({ preview }) => {
11205
+ const { items, shipping_methods } = preview;
11206
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11207
+ const [comboboxValue, setComboboxValue] = React.useState("");
11208
+ const { handleSuccess } = useRouteModal();
11209
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11210
+ const promoCodes = getPromotionCodes(items, shipping_methods);
11211
+ const { promotions, isPending, isError, error } = usePromotions(
11212
+ {
11213
+ code: promoCodes
11214
+ },
11215
+ {
11216
+ enabled: !!promoCodes.length
11217
+ }
11218
+ );
11219
+ const comboboxData = useComboboxData({
11220
+ queryKey: ["promotions", "combobox", promoCodes],
11221
+ queryFn: async (params) => {
11222
+ return await sdk.admin.promotion.list({
11223
+ ...params,
11224
+ code: {
11225
+ $nin: promoCodes
11226
+ }
11227
+ });
11228
+ },
11229
+ getOptions: (data) => {
11230
+ return data.promotions.map((promotion) => ({
11231
+ label: promotion.code,
11232
+ value: promotion.code
11233
+ }));
11234
+ }
11235
+ });
11236
+ const add = async (value) => {
11237
+ if (!value) {
11238
+ return;
11239
+ }
11240
+ addPromotions(
11241
+ {
11242
+ promo_codes: [value]
11243
+ },
11244
+ {
11245
+ onError: (e) => {
11246
+ ui.toast.error(e.message);
11247
+ comboboxData.onSearchValueChange("");
11248
+ setComboboxValue("");
11249
+ },
11250
+ onSuccess: () => {
11251
+ comboboxData.onSearchValueChange("");
11252
+ setComboboxValue("");
11253
+ }
11254
+ }
11255
+ );
11256
+ };
11257
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11258
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11259
+ const onSubmit = async () => {
11260
+ setIsSubmitting(true);
11261
+ let requestSucceeded = false;
11262
+ await requestOrderEdit(void 0, {
11263
+ onError: (e) => {
11264
+ ui.toast.error(e.message);
11265
+ },
11266
+ onSuccess: () => {
11267
+ requestSucceeded = true;
11268
+ }
11269
+ });
11270
+ if (!requestSucceeded) {
11271
+ setIsSubmitting(false);
11272
+ return;
11273
+ }
11274
+ await confirmOrderEdit(void 0, {
11275
+ onError: (e) => {
11276
+ ui.toast.error(e.message);
11277
+ },
11278
+ onSuccess: () => {
11279
+ handleSuccess();
11280
+ },
11281
+ onSettled: () => {
11282
+ setIsSubmitting(false);
11283
+ }
11284
+ });
11285
+ };
11286
+ if (isError) {
11287
+ throw error;
11288
+ }
11289
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11290
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11291
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11292
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11293
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11294
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11295
+ ] }),
11296
+ /* @__PURE__ */ jsxRuntime.jsx(
11297
+ Combobox,
11298
+ {
11299
+ id: "promotion-combobox",
11300
+ "aria-describedby": "promotion-combobox-hint",
11301
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11302
+ fetchNextPage: comboboxData.fetchNextPage,
11303
+ options: comboboxData.options,
11304
+ onSearchValueChange: comboboxData.onSearchValueChange,
11305
+ searchValue: comboboxData.searchValue,
11306
+ disabled: comboboxData.disabled || isAddingPromotions,
11307
+ onChange: add,
11308
+ value: comboboxValue
11309
+ }
11310
+ )
11311
+ ] }),
11312
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11313
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11314
+ PromotionItem,
11315
+ {
11316
+ promotion,
11317
+ orderId: preview.id,
11318
+ isLoading: isPending
11319
+ },
11320
+ promotion.id
11321
+ )) })
11322
+ ] }) }),
11323
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11324
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11325
+ /* @__PURE__ */ jsxRuntime.jsx(
11326
+ ui.Button,
11327
+ {
11328
+ size: "small",
11329
+ type: "submit",
11330
+ isLoading: isSubmitting || isAddingPromotions,
11331
+ children: "Save"
11332
+ }
11333
+ )
11334
+ ] }) })
11335
+ ] });
11336
+ };
11337
+ const PromotionItem = ({
11338
+ promotion,
11339
+ orderId,
11340
+ isLoading
11341
+ }) => {
11342
+ var _a;
11343
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11344
+ const onRemove = async () => {
11345
+ removePromotions(
11346
+ {
11347
+ promo_codes: [promotion.code]
11348
+ },
11349
+ {
11350
+ onError: (e) => {
11351
+ ui.toast.error(e.message);
11352
+ }
11353
+ }
11354
+ );
11287
11355
  };
11288
11356
  const displayValue = getDisplayValue(promotion);
11289
11357
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -11372,9 +11440,115 @@ function getPromotionCodes(items, shippingMethods) {
11372
11440
  }
11373
11441
  return Array.from(codes);
11374
11442
  }
11375
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
11376
- const Shipping = () => {
11377
- var _a;
11443
+ const SalesChannel = () => {
11444
+ const { id } = reactRouterDom.useParams();
11445
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11446
+ id,
11447
+ {
11448
+ fields: "+sales_channel_id"
11449
+ },
11450
+ {
11451
+ enabled: !!id
11452
+ }
11453
+ );
11454
+ if (isError) {
11455
+ throw error;
11456
+ }
11457
+ const ISrEADY = !!draft_order && !isPending;
11458
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11459
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11460
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11461
+ /* @__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" }) })
11462
+ ] }),
11463
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11464
+ ] });
11465
+ };
11466
+ const SalesChannelForm = ({ order }) => {
11467
+ const form = reactHookForm.useForm({
11468
+ defaultValues: {
11469
+ sales_channel_id: order.sales_channel_id || ""
11470
+ },
11471
+ resolver: zod.zodResolver(schema$2)
11472
+ });
11473
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11474
+ const { handleSuccess } = useRouteModal();
11475
+ const onSubmit = form.handleSubmit(async (data) => {
11476
+ await mutateAsync(
11477
+ {
11478
+ sales_channel_id: data.sales_channel_id
11479
+ },
11480
+ {
11481
+ onSuccess: () => {
11482
+ ui.toast.success("Sales channel updated");
11483
+ handleSuccess();
11484
+ },
11485
+ onError: (error) => {
11486
+ ui.toast.error(error.message);
11487
+ }
11488
+ }
11489
+ );
11490
+ });
11491
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11492
+ KeyboundForm,
11493
+ {
11494
+ className: "flex flex-1 flex-col overflow-hidden",
11495
+ onSubmit,
11496
+ children: [
11497
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11498
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11499
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11500
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11501
+ ] }) })
11502
+ ]
11503
+ }
11504
+ ) });
11505
+ };
11506
+ const SalesChannelField = ({ control, order }) => {
11507
+ const salesChannels = useComboboxData({
11508
+ queryFn: async (params) => {
11509
+ return await sdk.admin.salesChannel.list(params);
11510
+ },
11511
+ queryKey: ["sales-channels"],
11512
+ getOptions: (data) => {
11513
+ return data.sales_channels.map((salesChannel) => ({
11514
+ label: salesChannel.name,
11515
+ value: salesChannel.id
11516
+ }));
11517
+ },
11518
+ defaultValue: order.sales_channel_id || void 0
11519
+ });
11520
+ return /* @__PURE__ */ jsxRuntime.jsx(
11521
+ Form$2.Field,
11522
+ {
11523
+ control,
11524
+ name: "sales_channel_id",
11525
+ render: ({ field }) => {
11526
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11527
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11528
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11529
+ Combobox,
11530
+ {
11531
+ options: salesChannels.options,
11532
+ fetchNextPage: salesChannels.fetchNextPage,
11533
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11534
+ searchValue: salesChannels.searchValue,
11535
+ onSearchValueChange: salesChannels.onSearchValueChange,
11536
+ placeholder: "Select sales channel",
11537
+ ...field
11538
+ }
11539
+ ) }),
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11541
+ ] });
11542
+ }
11543
+ }
11544
+ );
11545
+ };
11546
+ const schema$2 = objectType({
11547
+ sales_channel_id: stringType().min(1)
11548
+ });
11549
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11550
+ const Shipping = () => {
11551
+ var _a;
11378
11552
  const { id } = reactRouterDom.useParams();
11379
11553
  const { order, isPending, isError, error } = useOrder(id, {
11380
11554
  fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
@@ -11750,638 +11924,435 @@ const ShippingForm = ({ preview, order }) => {
11750
11924
  },
11751
11925
  item.id
11752
11926
  ),
11753
- idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11754
- ] }, item.id);
11755
- })
11756
- ] })
11757
- ]
11758
- },
11759
- profile.id
11760
- );
11761
- }) })
11762
- ] }) })
11763
- ] }) }),
11764
- /* @__PURE__ */ jsxRuntime.jsx(
11765
- StackedFocusModal,
11766
- {
11767
- id: STACKED_FOCUS_MODAL_ID,
11768
- onOpenChangeCallback: (open) => {
11769
- if (!open) {
11770
- setData(null);
11771
- }
11772
- return open;
11773
- },
11774
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11775
- }
11776
- )
11777
- ] }),
11778
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11779
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11780
- /* @__PURE__ */ jsxRuntime.jsx(
11781
- ui.Button,
11782
- {
11783
- size: "small",
11784
- type: "button",
11785
- isLoading: isSubmitting,
11786
- onClick: onSubmit,
11787
- children: "Save"
11788
- }
11789
- )
11790
- ] }) })
11791
- ] });
11792
- };
11793
- const StackedModalTrigger = ({
11794
- shippingProfileId,
11795
- shippingOption,
11796
- shippingMethod,
11797
- setData,
11798
- children
11799
- }) => {
11800
- const { setIsOpen, getIsOpen } = useStackedModal();
11801
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11802
- const onToggle = () => {
11803
- if (isOpen) {
11804
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11805
- setData(null);
11806
- } else {
11807
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11808
- setData({
11809
- shippingProfileId,
11810
- shippingOption,
11811
- shippingMethod
11812
- });
11813
- }
11814
- };
11815
- return /* @__PURE__ */ jsxRuntime.jsx(
11816
- ui.Button,
11817
- {
11818
- size: "small",
11819
- variant: "secondary",
11820
- onClick: onToggle,
11821
- className: "text-ui-fg-primary shrink-0",
11822
- children
11823
- }
11824
- );
11825
- };
11826
- const ShippingProfileForm = ({
11827
- data,
11828
- order,
11829
- preview
11830
- }) => {
11831
- var _a, _b, _c, _d, _e, _f;
11832
- const { setIsOpen } = useStackedModal();
11833
- const form = reactHookForm.useForm({
11834
- resolver: zod.zodResolver(shippingMethodSchema),
11835
- defaultValues: {
11836
- 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,
11837
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
11838
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
11839
- }
11840
- });
11841
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
11842
- const {
11843
- mutateAsync: updateShippingMethod,
11844
- isPending: isUpdatingShippingMethod
11845
- } = useDraftOrderUpdateShippingMethod(order.id);
11846
- const onSubmit = form.handleSubmit(async (values) => {
11847
- if (lodash.isEqual(values, form.formState.defaultValues)) {
11848
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11849
- return;
11850
- }
11851
- if (data.shippingMethod) {
11852
- await updateShippingMethod(
11853
- {
11854
- method_id: data.shippingMethod.id,
11855
- shipping_option_id: values.shipping_option_id,
11856
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11857
- },
11858
- {
11859
- onError: (e) => {
11860
- ui.toast.error(e.message);
11861
- },
11862
- onSuccess: () => {
11863
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11864
- }
11865
- }
11866
- );
11867
- return;
11868
- }
11869
- await addShippingMethod(
11870
- {
11871
- shipping_option_id: values.shipping_option_id,
11872
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
11873
- },
11874
- {
11875
- onError: (e) => {
11876
- ui.toast.error(e.message);
11877
- },
11878
- onSuccess: () => {
11879
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11880
- }
11881
- }
11882
- );
11883
- });
11884
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11885
- KeyboundForm,
11886
- {
11887
- className: "flex h-full flex-col overflow-hidden",
11888
- onSubmit,
11889
- children: [
11890
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11891
- /* @__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: [
11892
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11893
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11894
- /* @__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." }) })
11895
- ] }),
11896
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11897
- /* @__PURE__ */ jsxRuntime.jsx(
11898
- LocationField,
11899
- {
11900
- control: form.control,
11901
- setValue: form.setValue
11902
- }
11903
- ),
11904
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11905
- /* @__PURE__ */ jsxRuntime.jsx(
11906
- ShippingOptionField,
11907
- {
11908
- shippingProfileId: data.shippingProfileId,
11909
- preview,
11910
- control: form.control
11911
- }
11912
- ),
11913
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11914
- /* @__PURE__ */ jsxRuntime.jsx(
11915
- CustomAmountField,
11916
- {
11917
- control: form.control,
11918
- currencyCode: order.currency_code
11919
- }
11920
- ),
11921
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11922
- /* @__PURE__ */ jsxRuntime.jsx(
11923
- ItemsPreview,
11924
- {
11925
- order,
11926
- shippingProfileId: data.shippingProfileId
11927
- }
11928
- )
11929
- ] }) }) }),
11930
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11931
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11932
- /* @__PURE__ */ jsxRuntime.jsx(
11933
- ui.Button,
11934
- {
11935
- size: "small",
11936
- type: "submit",
11937
- isLoading: isPending || isUpdatingShippingMethod,
11938
- children: data.shippingMethod ? "Update" : "Add"
11939
- }
11940
- )
11941
- ] }) })
11942
- ]
11943
- }
11944
- ) }) });
11945
- };
11946
- const shippingMethodSchema = objectType({
11947
- location_id: stringType(),
11948
- shipping_option_id: stringType(),
11949
- custom_amount: unionType([numberType(), stringType()]).optional()
11950
- });
11951
- const ItemsPreview = ({ order, shippingProfileId }) => {
11952
- const matches = order.items.filter(
11953
- (item) => {
11954
- var _a, _b, _c;
11955
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
11956
- }
11957
- );
11958
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
11959
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11960
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
11961
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
11962
- ] }) }),
11963
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
11964
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
11965
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
11966
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
11967
- ] }),
11968
- /* @__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(
11969
- "div",
11970
- {
11971
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
11972
- children: [
11973
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
11974
- /* @__PURE__ */ jsxRuntime.jsx(
11975
- Thumbnail,
11976
- {
11977
- thumbnail: item.thumbnail,
11978
- alt: item.product_title ?? void 0
11979
- }
11980
- ),
11981
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11982
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
11983
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11984
- /* @__PURE__ */ jsxRuntime.jsxs(
11985
- ui.Text,
11986
- {
11987
- size: "small",
11988
- leading: "compact",
11989
- className: "text-ui-fg-subtle",
11990
- children: [
11991
- "(",
11992
- item.variant_title,
11993
- ")"
11994
- ]
11995
- }
11996
- )
11997
- ] }),
11998
- /* @__PURE__ */ jsxRuntime.jsx(
11999
- ui.Text,
12000
- {
12001
- size: "small",
12002
- leading: "compact",
12003
- className: "text-ui-fg-subtle",
12004
- children: item.variant_sku
12005
- }
12006
- )
12007
- ] })
12008
- ] }),
12009
- /* @__PURE__ */ jsxRuntime.jsxs(
12010
- ui.Text,
12011
- {
12012
- size: "small",
12013
- leading: "compact",
12014
- className: "text-ui-fg-subtle",
12015
- children: [
12016
- item.quantity,
12017
- "x"
12018
- ]
12019
- }
12020
- )
12021
- ]
12022
- },
12023
- item.id
12024
- )) : /* @__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: [
12025
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12026
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12027
- 'No items found for "',
12028
- query,
12029
- '".'
12030
- ] })
12031
- ] }) })
12032
- ] })
12033
- ] });
12034
- };
12035
- const LocationField = ({ control, setValue }) => {
12036
- const locations = useComboboxData({
12037
- queryKey: ["locations"],
12038
- queryFn: async (params) => {
12039
- return await sdk.admin.stockLocation.list(params);
12040
- },
12041
- getOptions: (data) => {
12042
- return data.stock_locations.map((location) => ({
12043
- label: location.name,
12044
- value: location.id
12045
- }));
12046
- }
12047
- });
12048
- return /* @__PURE__ */ jsxRuntime.jsx(
12049
- Form$2.Field,
12050
- {
12051
- control,
12052
- name: "location_id",
12053
- render: ({ field: { onChange, ...field } }) => {
12054
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12055
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12056
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12057
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12058
- ] }),
12059
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12060
- Combobox,
12061
- {
12062
- options: locations.options,
12063
- fetchNextPage: locations.fetchNextPage,
12064
- isFetchingNextPage: locations.isFetchingNextPage,
12065
- searchValue: locations.searchValue,
12066
- onSearchValueChange: locations.onSearchValueChange,
12067
- placeholder: "Select location",
12068
- onChange: (value) => {
12069
- setValue("shipping_option_id", "", {
12070
- shouldDirty: true,
12071
- shouldTouch: true
12072
- });
12073
- onChange(value);
11927
+ idx !== items.length - 1 && /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" })
11928
+ ] }, item.id);
11929
+ })
11930
+ ] })
11931
+ ]
12074
11932
  },
12075
- ...field
11933
+ profile.id
11934
+ );
11935
+ }) })
11936
+ ] }) })
11937
+ ] }) }),
11938
+ /* @__PURE__ */ jsxRuntime.jsx(
11939
+ StackedFocusModal,
11940
+ {
11941
+ id: STACKED_FOCUS_MODAL_ID,
11942
+ onOpenChangeCallback: (open) => {
11943
+ if (!open) {
11944
+ setData(null);
12076
11945
  }
12077
- ) })
12078
- ] }) });
12079
- }
12080
- }
12081
- );
11946
+ return open;
11947
+ },
11948
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11949
+ }
11950
+ )
11951
+ ] }),
11952
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11953
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11954
+ /* @__PURE__ */ jsxRuntime.jsx(
11955
+ ui.Button,
11956
+ {
11957
+ size: "small",
11958
+ type: "button",
11959
+ isLoading: isSubmitting,
11960
+ onClick: onSubmit,
11961
+ children: "Save"
11962
+ }
11963
+ )
11964
+ ] }) })
11965
+ ] });
12082
11966
  };
12083
- const ShippingOptionField = ({
11967
+ const StackedModalTrigger = ({
12084
11968
  shippingProfileId,
12085
- preview,
12086
- control
11969
+ shippingOption,
11970
+ shippingMethod,
11971
+ setData,
11972
+ children
12087
11973
  }) => {
12088
- var _a;
12089
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12090
- const shippingOptions = useComboboxData({
12091
- queryKey: ["shipping_options", locationId, shippingProfileId],
12092
- queryFn: async (params) => {
12093
- return await sdk.admin.shippingOption.list({
12094
- ...params,
12095
- stock_location_id: locationId,
12096
- shipping_profile_id: shippingProfileId
11974
+ const { setIsOpen, getIsOpen } = useStackedModal();
11975
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11976
+ const onToggle = () => {
11977
+ if (isOpen) {
11978
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11979
+ setData(null);
11980
+ } else {
11981
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11982
+ setData({
11983
+ shippingProfileId,
11984
+ shippingOption,
11985
+ shippingMethod
12097
11986
  });
12098
- },
12099
- getOptions: (data) => {
12100
- return data.shipping_options.map((option) => {
12101
- var _a2;
12102
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12103
- (r) => r.attribute === "is_return" && r.value === "true"
12104
- )) {
12105
- return void 0;
12106
- }
12107
- return {
12108
- label: option.name,
12109
- value: option.id
12110
- };
12111
- }).filter(Boolean);
12112
- },
12113
- enabled: !!locationId && !!shippingProfileId,
12114
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12115
- });
12116
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12117
- return /* @__PURE__ */ jsxRuntime.jsx(
12118
- Form$2.Field,
12119
- {
12120
- control,
12121
- name: "shipping_option_id",
12122
- render: ({ field }) => {
12123
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12124
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12125
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12126
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12127
- ] }),
12128
- /* @__PURE__ */ jsxRuntime.jsx(
12129
- ConditionalTooltip,
12130
- {
12131
- content: tooltipContent,
12132
- showTooltip: !locationId || !shippingProfileId,
12133
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12134
- Combobox,
12135
- {
12136
- options: shippingOptions.options,
12137
- fetchNextPage: shippingOptions.fetchNextPage,
12138
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12139
- searchValue: shippingOptions.searchValue,
12140
- onSearchValueChange: shippingOptions.onSearchValueChange,
12141
- placeholder: "Select shipping option",
12142
- ...field,
12143
- disabled: !locationId || !shippingProfileId
12144
- }
12145
- ) }) })
12146
- }
12147
- )
12148
- ] }) });
12149
- }
12150
11987
  }
12151
- );
12152
- };
12153
- const CustomAmountField = ({
12154
- control,
12155
- currencyCode
12156
- }) => {
11988
+ };
12157
11989
  return /* @__PURE__ */ jsxRuntime.jsx(
12158
- Form$2.Field,
11990
+ ui.Button,
12159
11991
  {
12160
- control,
12161
- name: "custom_amount",
12162
- render: ({ field: { onChange, ...field } }) => {
12163
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12164
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12165
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12166
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12167
- ] }),
12168
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12169
- ui.CurrencyInput,
12170
- {
12171
- ...field,
12172
- onValueChange: (value) => onChange(value),
12173
- symbol: getNativeSymbol(currencyCode),
12174
- code: currencyCode
12175
- }
12176
- ) })
12177
- ] });
12178
- }
11992
+ size: "small",
11993
+ variant: "secondary",
11994
+ onClick: onToggle,
11995
+ className: "text-ui-fg-primary shrink-0",
11996
+ children
12179
11997
  }
12180
11998
  );
12181
11999
  };
12182
- const ShippingAddress = () => {
12183
- const { id } = reactRouterDom.useParams();
12184
- const { order, isPending, isError, error } = useOrder(id, {
12185
- fields: "+shipping_address"
12186
- });
12187
- if (isError) {
12188
- throw error;
12189
- }
12190
- const isReady = !isPending && !!order;
12191
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12192
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12193
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12194
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12195
- ] }),
12196
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12197
- ] });
12198
- };
12199
- const ShippingAddressForm = ({ order }) => {
12200
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12000
+ const ShippingProfileForm = ({
12001
+ data,
12002
+ order,
12003
+ preview
12004
+ }) => {
12005
+ var _a, _b, _c, _d, _e, _f;
12006
+ const { setIsOpen } = useStackedModal();
12201
12007
  const form = reactHookForm.useForm({
12008
+ resolver: zod.zodResolver(shippingMethodSchema),
12202
12009
  defaultValues: {
12203
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12204
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12205
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12206
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12207
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12208
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12209
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12210
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12211
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12212
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12213
- },
12214
- resolver: zod.zodResolver(schema$3)
12010
+ 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,
12011
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12012
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12013
+ }
12215
12014
  });
12216
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12217
- const { handleSuccess } = useRouteModal();
12218
- const onSubmit = form.handleSubmit(async (data) => {
12219
- await mutateAsync(
12220
- {
12221
- shipping_address: {
12222
- first_name: data.first_name,
12223
- last_name: data.last_name,
12224
- company: data.company,
12225
- address_1: data.address_1,
12226
- address_2: data.address_2,
12227
- city: data.city,
12228
- province: data.province,
12229
- country_code: data.country_code,
12230
- postal_code: data.postal_code,
12231
- phone: data.phone
12015
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12016
+ const {
12017
+ mutateAsync: updateShippingMethod,
12018
+ isPending: isUpdatingShippingMethod
12019
+ } = useDraftOrderUpdateShippingMethod(order.id);
12020
+ const onSubmit = form.handleSubmit(async (values) => {
12021
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12022
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12023
+ return;
12024
+ }
12025
+ if (data.shippingMethod) {
12026
+ await updateShippingMethod(
12027
+ {
12028
+ method_id: data.shippingMethod.id,
12029
+ shipping_option_id: values.shipping_option_id,
12030
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12031
+ },
12032
+ {
12033
+ onError: (e) => {
12034
+ ui.toast.error(e.message);
12035
+ },
12036
+ onSuccess: () => {
12037
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12038
+ }
12232
12039
  }
12040
+ );
12041
+ return;
12042
+ }
12043
+ await addShippingMethod(
12044
+ {
12045
+ shipping_option_id: values.shipping_option_id,
12046
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12233
12047
  },
12234
12048
  {
12235
- onSuccess: () => {
12236
- handleSuccess();
12049
+ onError: (e) => {
12050
+ ui.toast.error(e.message);
12237
12051
  },
12238
- onError: (error) => {
12239
- ui.toast.error(error.message);
12052
+ onSuccess: () => {
12053
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12240
12054
  }
12241
12055
  }
12242
12056
  );
12243
12057
  });
12244
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12058
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12245
12059
  KeyboundForm,
12246
12060
  {
12247
- className: "flex flex-1 flex-col overflow-hidden",
12061
+ className: "flex h-full flex-col overflow-hidden",
12248
12062
  onSubmit,
12249
12063
  children: [
12250
- /* @__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: [
12064
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12065
+ /* @__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: [
12066
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12067
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12068
+ /* @__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." }) })
12069
+ ] }),
12070
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12251
12071
  /* @__PURE__ */ jsxRuntime.jsx(
12252
- Form$2.Field,
12072
+ LocationField,
12253
12073
  {
12254
12074
  control: form.control,
12255
- name: "country_code",
12256
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12257
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12258
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12259
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12260
- ] })
12075
+ setValue: form.setValue
12261
12076
  }
12262
12077
  ),
12263
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12264
- /* @__PURE__ */ jsxRuntime.jsx(
12265
- Form$2.Field,
12266
- {
12267
- control: form.control,
12268
- name: "first_name",
12269
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12270
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12271
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12272
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12273
- ] })
12274
- }
12275
- ),
12276
- /* @__PURE__ */ jsxRuntime.jsx(
12277
- Form$2.Field,
12278
- {
12279
- control: form.control,
12280
- name: "last_name",
12281
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12282
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12283
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12284
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12285
- ] })
12286
- }
12287
- )
12288
- ] }),
12078
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12289
12079
  /* @__PURE__ */ jsxRuntime.jsx(
12290
- Form$2.Field,
12080
+ ShippingOptionField,
12291
12081
  {
12292
- control: form.control,
12293
- name: "company",
12294
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12295
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12296
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12297
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12298
- ] })
12082
+ shippingProfileId: data.shippingProfileId,
12083
+ preview,
12084
+ control: form.control
12299
12085
  }
12300
12086
  ),
12087
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12301
12088
  /* @__PURE__ */ jsxRuntime.jsx(
12302
- Form$2.Field,
12089
+ CustomAmountField,
12303
12090
  {
12304
12091
  control: form.control,
12305
- name: "address_1",
12306
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12307
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12308
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12309
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12310
- ] })
12092
+ currencyCode: order.currency_code
12311
12093
  }
12312
12094
  ),
12095
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12313
12096
  /* @__PURE__ */ jsxRuntime.jsx(
12314
- Form$2.Field,
12097
+ ItemsPreview,
12315
12098
  {
12316
- control: form.control,
12317
- name: "address_2",
12318
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12319
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12320
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12321
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12322
- ] })
12099
+ order,
12100
+ shippingProfileId: data.shippingProfileId
12323
12101
  }
12324
- ),
12325
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12326
- /* @__PURE__ */ jsxRuntime.jsx(
12327
- Form$2.Field,
12328
- {
12329
- control: form.control,
12330
- name: "postal_code",
12331
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12332
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12333
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12334
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12335
- ] })
12336
- }
12337
- ),
12338
- /* @__PURE__ */ jsxRuntime.jsx(
12339
- Form$2.Field,
12102
+ )
12103
+ ] }) }) }),
12104
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12105
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12106
+ /* @__PURE__ */ jsxRuntime.jsx(
12107
+ ui.Button,
12108
+ {
12109
+ size: "small",
12110
+ type: "submit",
12111
+ isLoading: isPending || isUpdatingShippingMethod,
12112
+ children: data.shippingMethod ? "Update" : "Add"
12113
+ }
12114
+ )
12115
+ ] }) })
12116
+ ]
12117
+ }
12118
+ ) }) });
12119
+ };
12120
+ const shippingMethodSchema = objectType({
12121
+ location_id: stringType(),
12122
+ shipping_option_id: stringType(),
12123
+ custom_amount: unionType([numberType(), stringType()]).optional()
12124
+ });
12125
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12126
+ const matches = order.items.filter(
12127
+ (item) => {
12128
+ var _a, _b, _c;
12129
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12130
+ }
12131
+ );
12132
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12133
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12134
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12135
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12136
+ ] }) }),
12137
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12138
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12139
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12140
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12141
+ ] }),
12142
+ /* @__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(
12143
+ "div",
12144
+ {
12145
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12146
+ children: [
12147
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12148
+ /* @__PURE__ */ jsxRuntime.jsx(
12149
+ Thumbnail,
12150
+ {
12151
+ thumbnail: item.thumbnail,
12152
+ alt: item.product_title ?? void 0
12153
+ }
12154
+ ),
12155
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12156
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12157
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12158
+ /* @__PURE__ */ jsxRuntime.jsxs(
12159
+ ui.Text,
12160
+ {
12161
+ size: "small",
12162
+ leading: "compact",
12163
+ className: "text-ui-fg-subtle",
12164
+ children: [
12165
+ "(",
12166
+ item.variant_title,
12167
+ ")"
12168
+ ]
12169
+ }
12170
+ )
12171
+ ] }),
12172
+ /* @__PURE__ */ jsxRuntime.jsx(
12173
+ ui.Text,
12174
+ {
12175
+ size: "small",
12176
+ leading: "compact",
12177
+ className: "text-ui-fg-subtle",
12178
+ children: item.variant_sku
12179
+ }
12180
+ )
12181
+ ] })
12182
+ ] }),
12183
+ /* @__PURE__ */ jsxRuntime.jsxs(
12184
+ ui.Text,
12340
12185
  {
12341
- control: form.control,
12342
- name: "city",
12343
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12344
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12345
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12346
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12347
- ] })
12186
+ size: "small",
12187
+ leading: "compact",
12188
+ className: "text-ui-fg-subtle",
12189
+ children: [
12190
+ item.quantity,
12191
+ "x"
12192
+ ]
12348
12193
  }
12349
12194
  )
12195
+ ]
12196
+ },
12197
+ item.id
12198
+ )) : /* @__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: [
12199
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12200
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12201
+ 'No items found for "',
12202
+ query,
12203
+ '".'
12204
+ ] })
12205
+ ] }) })
12206
+ ] })
12207
+ ] });
12208
+ };
12209
+ const LocationField = ({ control, setValue }) => {
12210
+ const locations = useComboboxData({
12211
+ queryKey: ["locations"],
12212
+ queryFn: async (params) => {
12213
+ return await sdk.admin.stockLocation.list(params);
12214
+ },
12215
+ getOptions: (data) => {
12216
+ return data.stock_locations.map((location) => ({
12217
+ label: location.name,
12218
+ value: location.id
12219
+ }));
12220
+ }
12221
+ });
12222
+ return /* @__PURE__ */ jsxRuntime.jsx(
12223
+ Form$2.Field,
12224
+ {
12225
+ control,
12226
+ name: "location_id",
12227
+ render: ({ field: { onChange, ...field } }) => {
12228
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12229
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12230
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12231
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12232
+ ] }),
12233
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12234
+ Combobox,
12235
+ {
12236
+ options: locations.options,
12237
+ fetchNextPage: locations.fetchNextPage,
12238
+ isFetchingNextPage: locations.isFetchingNextPage,
12239
+ searchValue: locations.searchValue,
12240
+ onSearchValueChange: locations.onSearchValueChange,
12241
+ placeholder: "Select location",
12242
+ onChange: (value) => {
12243
+ setValue("shipping_option_id", "", {
12244
+ shouldDirty: true,
12245
+ shouldTouch: true
12246
+ });
12247
+ onChange(value);
12248
+ },
12249
+ ...field
12250
+ }
12251
+ ) })
12252
+ ] }) });
12253
+ }
12254
+ }
12255
+ );
12256
+ };
12257
+ const ShippingOptionField = ({
12258
+ shippingProfileId,
12259
+ preview,
12260
+ control
12261
+ }) => {
12262
+ var _a;
12263
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12264
+ const shippingOptions = useComboboxData({
12265
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12266
+ queryFn: async (params) => {
12267
+ return await sdk.admin.shippingOption.list({
12268
+ ...params,
12269
+ stock_location_id: locationId,
12270
+ shipping_profile_id: shippingProfileId
12271
+ });
12272
+ },
12273
+ getOptions: (data) => {
12274
+ return data.shipping_options.map((option) => {
12275
+ var _a2;
12276
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12277
+ (r) => r.attribute === "is_return" && r.value === "true"
12278
+ )) {
12279
+ return void 0;
12280
+ }
12281
+ return {
12282
+ label: option.name,
12283
+ value: option.id
12284
+ };
12285
+ }).filter(Boolean);
12286
+ },
12287
+ enabled: !!locationId && !!shippingProfileId,
12288
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12289
+ });
12290
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12291
+ return /* @__PURE__ */ jsxRuntime.jsx(
12292
+ Form$2.Field,
12293
+ {
12294
+ control,
12295
+ name: "shipping_option_id",
12296
+ render: ({ field }) => {
12297
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12298
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12299
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12300
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12350
12301
  ] }),
12351
12302
  /* @__PURE__ */ jsxRuntime.jsx(
12352
- Form$2.Field,
12303
+ ConditionalTooltip,
12353
12304
  {
12354
- control: form.control,
12355
- name: "province",
12356
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12357
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12358
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12359
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12360
- ] })
12305
+ content: tooltipContent,
12306
+ showTooltip: !locationId || !shippingProfileId,
12307
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12308
+ Combobox,
12309
+ {
12310
+ options: shippingOptions.options,
12311
+ fetchNextPage: shippingOptions.fetchNextPage,
12312
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12313
+ searchValue: shippingOptions.searchValue,
12314
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12315
+ placeholder: "Select shipping option",
12316
+ ...field,
12317
+ disabled: !locationId || !shippingProfileId
12318
+ }
12319
+ ) }) })
12361
12320
  }
12362
- ),
12363
- /* @__PURE__ */ jsxRuntime.jsx(
12364
- Form$2.Field,
12321
+ )
12322
+ ] }) });
12323
+ }
12324
+ }
12325
+ );
12326
+ };
12327
+ const CustomAmountField = ({
12328
+ control,
12329
+ currencyCode
12330
+ }) => {
12331
+ return /* @__PURE__ */ jsxRuntime.jsx(
12332
+ Form$2.Field,
12333
+ {
12334
+ control,
12335
+ name: "custom_amount",
12336
+ render: ({ field: { onChange, ...field } }) => {
12337
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12338
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12339
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12340
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12341
+ ] }),
12342
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12343
+ ui.CurrencyInput,
12365
12344
  {
12366
- control: form.control,
12367
- name: "phone",
12368
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12369
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12370
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12371
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12372
- ] })
12345
+ ...field,
12346
+ onValueChange: (value) => onChange(value),
12347
+ symbol: getNativeSymbol(currencyCode),
12348
+ code: currencyCode
12373
12349
  }
12374
- )
12375
- ] }) }),
12376
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12377
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12378
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12379
- ] }) })
12380
- ]
12350
+ ) })
12351
+ ] });
12352
+ }
12381
12353
  }
12382
- ) });
12354
+ );
12383
12355
  };
12384
- const schema$3 = addressSchema;
12385
12356
  const TransferOwnership = () => {
12386
12357
  const { id } = reactRouterDom.useParams();
12387
12358
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12405,7 +12376,7 @@ const TransferOwnershipForm = ({ order }) => {
12405
12376
  defaultValues: {
12406
12377
  customer_id: order.customer_id || ""
12407
12378
  },
12408
- resolver: zod.zodResolver(schema$2)
12379
+ resolver: zod.zodResolver(schema$1)
12409
12380
  });
12410
12381
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12411
12382
  const { handleSuccess } = useRouteModal();
@@ -12808,166 +12779,60 @@ const Illustration = () => {
12808
12779
  /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12809
12780
  "rect",
12810
12781
  {
12811
- width: "12",
12812
- height: "12",
12813
- fill: "white",
12814
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12815
- }
12816
- ) }),
12817
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12818
- "rect",
12819
- {
12820
- width: "12",
12821
- height: "12",
12822
- fill: "white",
12823
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12824
- }
12825
- ) }),
12826
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12827
- "rect",
12828
- {
12829
- width: "12",
12830
- height: "12",
12831
- fill: "white",
12832
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12833
- }
12834
- ) }),
12835
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12836
- "rect",
12837
- {
12838
- width: "12",
12839
- height: "12",
12840
- fill: "white",
12841
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12842
- }
12843
- ) }),
12844
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12845
- "rect",
12846
- {
12847
- width: "12",
12848
- height: "12",
12849
- fill: "white",
12850
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12851
- }
12852
- ) })
12853
- ] })
12854
- ]
12855
- }
12856
- );
12857
- };
12858
- const schema$2 = objectType({
12859
- customer_id: stringType().min(1)
12860
- });
12861
- const SalesChannel = () => {
12862
- const { id } = reactRouterDom.useParams();
12863
- const { draft_order, isPending, isError, error } = useDraftOrder(
12864
- id,
12865
- {
12866
- fields: "+sales_channel_id"
12867
- },
12868
- {
12869
- enabled: !!id
12870
- }
12871
- );
12872
- if (isError) {
12873
- throw error;
12874
- }
12875
- const ISrEADY = !!draft_order && !isPending;
12876
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12877
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12878
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
12879
- /* @__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" }) })
12880
- ] }),
12881
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
12882
- ] });
12883
- };
12884
- const SalesChannelForm = ({ order }) => {
12885
- const form = reactHookForm.useForm({
12886
- defaultValues: {
12887
- sales_channel_id: order.sales_channel_id || ""
12888
- },
12889
- resolver: zod.zodResolver(schema$1)
12890
- });
12891
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12892
- const { handleSuccess } = useRouteModal();
12893
- const onSubmit = form.handleSubmit(async (data) => {
12894
- await mutateAsync(
12895
- {
12896
- sales_channel_id: data.sales_channel_id
12897
- },
12898
- {
12899
- onSuccess: () => {
12900
- ui.toast.success("Sales channel updated");
12901
- handleSuccess();
12902
- },
12903
- onError: (error) => {
12904
- ui.toast.error(error.message);
12905
- }
12906
- }
12907
- );
12908
- });
12909
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12910
- KeyboundForm,
12911
- {
12912
- className: "flex flex-1 flex-col overflow-hidden",
12913
- onSubmit,
12914
- children: [
12915
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
12916
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12917
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12918
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12919
- ] }) })
12920
- ]
12921
- }
12922
- ) });
12923
- };
12924
- const SalesChannelField = ({ control, order }) => {
12925
- const salesChannels = useComboboxData({
12926
- queryFn: async (params) => {
12927
- return await sdk.admin.salesChannel.list(params);
12928
- },
12929
- queryKey: ["sales-channels"],
12930
- getOptions: (data) => {
12931
- return data.sales_channels.map((salesChannel) => ({
12932
- label: salesChannel.name,
12933
- value: salesChannel.id
12934
- }));
12935
- },
12936
- defaultValue: order.sales_channel_id || void 0
12937
- });
12938
- return /* @__PURE__ */ jsxRuntime.jsx(
12939
- Form$2.Field,
12940
- {
12941
- control,
12942
- name: "sales_channel_id",
12943
- render: ({ field }) => {
12944
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
12946
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12947
- Combobox,
12782
+ width: "12",
12783
+ height: "12",
12784
+ fill: "white",
12785
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12786
+ }
12787
+ ) }),
12788
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12789
+ "rect",
12948
12790
  {
12949
- options: salesChannels.options,
12950
- fetchNextPage: salesChannels.fetchNextPage,
12951
- isFetchingNextPage: salesChannels.isFetchingNextPage,
12952
- searchValue: salesChannels.searchValue,
12953
- onSearchValueChange: salesChannels.onSearchValueChange,
12954
- placeholder: "Select sales channel",
12955
- ...field
12791
+ width: "12",
12792
+ height: "12",
12793
+ fill: "white",
12794
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12956
12795
  }
12957
12796
  ) }),
12958
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12959
- ] });
12960
- }
12797
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12798
+ "rect",
12799
+ {
12800
+ width: "12",
12801
+ height: "12",
12802
+ fill: "white",
12803
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12804
+ }
12805
+ ) }),
12806
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12807
+ "rect",
12808
+ {
12809
+ width: "12",
12810
+ height: "12",
12811
+ fill: "white",
12812
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12813
+ }
12814
+ ) }),
12815
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12816
+ "rect",
12817
+ {
12818
+ width: "12",
12819
+ height: "12",
12820
+ fill: "white",
12821
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12822
+ }
12823
+ ) })
12824
+ ] })
12825
+ ]
12961
12826
  }
12962
12827
  );
12963
12828
  };
12964
12829
  const schema$1 = objectType({
12965
- sales_channel_id: stringType().min(1)
12830
+ customer_id: stringType().min(1)
12966
12831
  });
12967
- const Email = () => {
12832
+ const ShippingAddress = () => {
12968
12833
  const { id } = reactRouterDom.useParams();
12969
12834
  const { order, isPending, isError, error } = useOrder(id, {
12970
- fields: "+email"
12835
+ fields: "+shipping_address"
12971
12836
  });
12972
12837
  if (isError) {
12973
12838
  throw error;
@@ -12975,16 +12840,26 @@ const Email = () => {
12975
12840
  const isReady = !isPending && !!order;
12976
12841
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12977
12842
  /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12978
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Email" }) }),
12979
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the email for the draft order" }) })
12843
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12980
12845
  ] }),
12981
- isReady && /* @__PURE__ */ jsxRuntime.jsx(EmailForm, { order })
12846
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12982
12847
  ] });
12983
12848
  };
12984
- const EmailForm = ({ order }) => {
12849
+ const ShippingAddressForm = ({ order }) => {
12850
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12985
12851
  const form = reactHookForm.useForm({
12986
12852
  defaultValues: {
12987
- email: order.email ?? ""
12853
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12854
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12855
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12856
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12857
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12858
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12859
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12860
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12861
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12862
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12988
12863
  },
12989
12864
  resolver: zod.zodResolver(schema)
12990
12865
  });
@@ -12992,7 +12867,20 @@ const EmailForm = ({ order }) => {
12992
12867
  const { handleSuccess } = useRouteModal();
12993
12868
  const onSubmit = form.handleSubmit(async (data) => {
12994
12869
  await mutateAsync(
12995
- { email: data.email },
12870
+ {
12871
+ shipping_address: {
12872
+ first_name: data.first_name,
12873
+ last_name: data.last_name,
12874
+ company: data.company,
12875
+ address_1: data.address_1,
12876
+ address_2: data.address_2,
12877
+ city: data.city,
12878
+ province: data.province,
12879
+ country_code: data.country_code,
12880
+ postal_code: data.postal_code,
12881
+ phone: data.phone
12882
+ }
12883
+ },
12996
12884
  {
12997
12885
  onSuccess: () => {
12998
12886
  handleSuccess();
@@ -13009,18 +12897,132 @@ const EmailForm = ({ order }) => {
13009
12897
  className: "flex flex-1 flex-col overflow-hidden",
13010
12898
  onSubmit,
13011
12899
  children: [
13012
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(
13013
- Form$2.Field,
13014
- {
13015
- control: form.control,
13016
- name: "email",
13017
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13018
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Email" }),
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13020
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13021
- ] })
13022
- }
13023
- ) }),
12900
+ /* @__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: [
12901
+ /* @__PURE__ */ jsxRuntime.jsx(
12902
+ Form$2.Field,
12903
+ {
12904
+ control: form.control,
12905
+ name: "country_code",
12906
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12907
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12908
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12909
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12910
+ ] })
12911
+ }
12912
+ ),
12913
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "first_name",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsx(
12927
+ Form$2.Field,
12928
+ {
12929
+ control: form.control,
12930
+ name: "last_name",
12931
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
+ ] })
12936
+ }
12937
+ )
12938
+ ] }),
12939
+ /* @__PURE__ */ jsxRuntime.jsx(
12940
+ Form$2.Field,
12941
+ {
12942
+ control: form.control,
12943
+ name: "company",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12949
+ }
12950
+ ),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12953
+ {
12954
+ control: form.control,
12955
+ name: "address_1",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
+ ] })
12961
+ }
12962
+ ),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(
12964
+ Form$2.Field,
12965
+ {
12966
+ control: form.control,
12967
+ name: "address_2",
12968
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
+ ] })
12973
+ }
12974
+ ),
12975
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "postal_code",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsx(
12989
+ Form$2.Field,
12990
+ {
12991
+ control: form.control,
12992
+ name: "city",
12993
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
+ ] })
12998
+ }
12999
+ )
13000
+ ] }),
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13003
+ {
13004
+ control: form.control,
13005
+ name: "province",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13011
+ }
13012
+ ),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control: form.control,
13017
+ name: "phone",
13018
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
+ ] })
13023
+ }
13024
+ )
13025
+ ] }) }),
13024
13026
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13025
13027
  /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13026
13028
  /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -13029,9 +13031,7 @@ const EmailForm = ({ order }) => {
13029
13031
  }
13030
13032
  ) });
13031
13033
  };
13032
- const schema = objectType({
13033
- email: stringType().email()
13034
- });
13034
+ const schema = addressSchema;
13035
13035
  const widgetModule = { widgets: [] };
13036
13036
  const routeModule = {
13037
13037
  routes: [
@@ -13061,36 +13061,36 @@ const routeModule = {
13061
13061
  path: "/draft-orders/:id/custom-items"
13062
13062
  },
13063
13063
  {
13064
- Component: Metadata,
13065
- path: "/draft-orders/:id/metadata"
13064
+ Component: Email,
13065
+ path: "/draft-orders/:id/email"
13066
13066
  },
13067
13067
  {
13068
13068
  Component: Items,
13069
13069
  path: "/draft-orders/:id/items"
13070
13070
  },
13071
+ {
13072
+ Component: Metadata,
13073
+ path: "/draft-orders/:id/metadata"
13074
+ },
13071
13075
  {
13072
13076
  Component: Promotions,
13073
13077
  path: "/draft-orders/:id/promotions"
13074
13078
  },
13075
13079
  {
13076
- Component: Shipping,
13077
- path: "/draft-orders/:id/shipping"
13080
+ Component: SalesChannel,
13081
+ path: "/draft-orders/:id/sales-channel"
13078
13082
  },
13079
13083
  {
13080
- Component: ShippingAddress,
13081
- path: "/draft-orders/:id/shipping-address"
13084
+ Component: Shipping,
13085
+ path: "/draft-orders/:id/shipping"
13082
13086
  },
13083
13087
  {
13084
13088
  Component: TransferOwnership,
13085
13089
  path: "/draft-orders/:id/transfer-ownership"
13086
13090
  },
13087
13091
  {
13088
- Component: SalesChannel,
13089
- path: "/draft-orders/:id/sales-channel"
13090
- },
13091
- {
13092
- Component: Email,
13093
- path: "/draft-orders/:id/email"
13092
+ Component: ShippingAddress,
13093
+ path: "/draft-orders/:id/shipping-address"
13094
13094
  }
13095
13095
  ]
13096
13096
  }