@medusajs/draft-order 2.10.2-preview-20250909081836 → 2.10.2-preview-20250909120201

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.
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
4
4
  import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
5
5
  import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
6
6
  import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
7
- import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
7
+ import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, Minus, PencilSquare, EllipsisVertical, ArrowUpMini, ArrowDownMini } from "@medusajs/icons";
8
8
  import Medusa from "@medusajs/js-sdk";
9
9
  import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
10
10
  import { enUS } from "date-fns/locale";
@@ -9757,27 +9757,6 @@ const BillingAddressForm = ({ order }) => {
9757
9757
  ) });
9758
9758
  };
9759
9759
  const schema$5 = addressSchema;
9760
- const CustomItems = () => {
9761
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9762
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
9763
- /* @__PURE__ */ jsx(CustomItemsForm, {})
9764
- ] });
9765
- };
9766
- const CustomItemsForm = () => {
9767
- const form = useForm({
9768
- resolver: zodResolver(schema$4)
9769
- });
9770
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9771
- /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
9772
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
9773
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9774
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
9775
- ] }) })
9776
- ] }) });
9777
- };
9778
- const schema$4 = objectType({
9779
- email: stringType().email()
9780
- });
9781
9760
  const Email = () => {
9782
9761
  const { id } = useParams();
9783
9762
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9800,7 +9779,7 @@ const EmailForm = ({ order }) => {
9800
9779
  defaultValues: {
9801
9780
  email: order.email ?? ""
9802
9781
  },
9803
- resolver: zodResolver(schema$3)
9782
+ resolver: zodResolver(schema$4)
9804
9783
  });
9805
9784
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9806
9785
  const { handleSuccess } = useRouteModal();
@@ -9843,912 +9822,179 @@ const EmailForm = ({ order }) => {
9843
9822
  }
9844
9823
  ) });
9845
9824
  };
9846
- const schema$3 = objectType({
9825
+ const schema$4 = objectType({
9847
9826
  email: stringType().email()
9848
9827
  });
9849
- const InlineTip = forwardRef(
9850
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9851
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9828
+ const NumberInput = forwardRef(
9829
+ ({
9830
+ value,
9831
+ onChange,
9832
+ size = "base",
9833
+ min = 0,
9834
+ max = 100,
9835
+ step = 1,
9836
+ className,
9837
+ disabled,
9838
+ ...props
9839
+ }, ref) => {
9840
+ const handleChange = (event) => {
9841
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9842
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9843
+ onChange(newValue);
9844
+ }
9845
+ };
9846
+ const handleIncrement = () => {
9847
+ const newValue = value + step;
9848
+ if (max === void 0 || newValue <= max) {
9849
+ onChange(newValue);
9850
+ }
9851
+ };
9852
+ const handleDecrement = () => {
9853
+ const newValue = value - step;
9854
+ if (min === void 0 || newValue >= min) {
9855
+ onChange(newValue);
9856
+ }
9857
+ };
9852
9858
  return /* @__PURE__ */ jsxs(
9853
9859
  "div",
9854
9860
  {
9855
- ref,
9856
9861
  className: clx(
9857
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9862
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9863
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9864
+ {
9865
+ "h-7": size === "small",
9866
+ "h-8": size === "base"
9867
+ },
9858
9868
  className
9859
9869
  ),
9860
- ...props,
9861
9870
  children: [
9862
9871
  /* @__PURE__ */ jsx(
9863
- "div",
9872
+ "input",
9864
9873
  {
9865
- role: "presentation",
9866
- className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9867
- "bg-ui-tag-orange-icon": variant === "warning"
9868
- })
9874
+ ref,
9875
+ type: "number",
9876
+ value,
9877
+ onChange: handleChange,
9878
+ min,
9879
+ max,
9880
+ step,
9881
+ className: clx(
9882
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9883
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9884
+ "placeholder:text-ui-fg-muted"
9885
+ ),
9886
+ ...props
9869
9887
  }
9870
9888
  ),
9871
- /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
9872
- /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9873
- labelValue,
9874
- ":"
9875
- ] }),
9876
- " ",
9877
- children
9878
- ] })
9889
+ /* @__PURE__ */ jsxs(
9890
+ "button",
9891
+ {
9892
+ className: clx(
9893
+ "flex items-center justify-center outline-none transition-fg",
9894
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9895
+ "focus:bg-ui-bg-field-component-hover",
9896
+ "hover:bg-ui-bg-field-component-hover",
9897
+ {
9898
+ "size-7": size === "small",
9899
+ "size-8": size === "base"
9900
+ }
9901
+ ),
9902
+ type: "button",
9903
+ onClick: handleDecrement,
9904
+ disabled: min !== void 0 && value <= min || disabled,
9905
+ children: [
9906
+ /* @__PURE__ */ jsx(Minus, {}),
9907
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9908
+ ]
9909
+ }
9910
+ ),
9911
+ /* @__PURE__ */ jsxs(
9912
+ "button",
9913
+ {
9914
+ className: clx(
9915
+ "flex items-center justify-center outline-none transition-fg",
9916
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9917
+ "focus:bg-ui-bg-field-hover",
9918
+ "hover:bg-ui-bg-field-hover",
9919
+ {
9920
+ "size-7": size === "small",
9921
+ "size-8": size === "base"
9922
+ }
9923
+ ),
9924
+ type: "button",
9925
+ onClick: handleIncrement,
9926
+ disabled: max !== void 0 && value >= max || disabled,
9927
+ children: [
9928
+ /* @__PURE__ */ jsx(Plus, {}),
9929
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9930
+ ]
9931
+ }
9932
+ )
9879
9933
  ]
9880
9934
  }
9881
9935
  );
9882
9936
  }
9883
9937
  );
9884
- InlineTip.displayName = "InlineTip";
9885
- const MetadataFieldSchema = objectType({
9886
- key: stringType(),
9887
- disabled: booleanType().optional(),
9888
- value: anyType()
9889
- });
9890
- const MetadataSchema = objectType({
9891
- metadata: arrayType(MetadataFieldSchema)
9892
- });
9893
- const Metadata = () => {
9894
- const { id } = useParams();
9895
- const { order, isPending, isError, error } = useOrder(id, {
9896
- fields: "metadata"
9897
- });
9898
- if (isError) {
9899
- throw error;
9900
- }
9901
- const isReady = !isPending && !!order;
9902
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
9903
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
9904
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
9905
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9906
- ] }),
9907
- !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9908
- ] });
9938
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9939
+ const productVariantsQueryKeys = {
9940
+ list: (query2) => [
9941
+ PRODUCT_VARIANTS_QUERY_KEY,
9942
+ query2 ? query2 : void 0
9943
+ ]
9909
9944
  };
9910
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9911
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9912
- const MetadataForm = ({ orderId, metadata }) => {
9913
- const { handleSuccess } = useRouteModal();
9914
- const hasUneditableRows = getHasUneditableRows(metadata);
9915
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9916
- const form = useForm({
9917
- defaultValues: {
9918
- metadata: getDefaultValues(metadata)
9919
- },
9920
- resolver: zodResolver(MetadataSchema)
9945
+ const useProductVariants = (query2, options) => {
9946
+ const { data, ...rest } = useQuery({
9947
+ queryKey: productVariantsQueryKeys.list(query2),
9948
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9949
+ ...options
9921
9950
  });
9922
- const handleSubmit = form.handleSubmit(async (data) => {
9923
- const parsedData = parseValues(data);
9924
- await mutateAsync(
9925
- {
9926
- metadata: parsedData
9951
+ return { ...data, ...rest };
9952
+ };
9953
+ const useCancelOrderEdit = ({ preview }) => {
9954
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9955
+ const onCancel = useCallback(async () => {
9956
+ if (!preview) {
9957
+ return true;
9958
+ }
9959
+ let res = false;
9960
+ await cancelOrderEdit(void 0, {
9961
+ onError: (e) => {
9962
+ toast.error(e.message);
9927
9963
  },
9928
- {
9929
- onSuccess: () => {
9930
- toast.success("Metadata updated");
9931
- handleSuccess();
9932
- },
9933
- onError: (error) => {
9934
- toast.error(error.message);
9935
- }
9964
+ onSuccess: () => {
9965
+ res = true;
9936
9966
  }
9937
- );
9938
- });
9939
- const { fields, insert, remove } = useFieldArray({
9940
- control: form.control,
9941
- name: "metadata"
9942
- });
9943
- function deleteRow(index) {
9944
- remove(index);
9945
- if (fields.length === 1) {
9946
- insert(0, {
9947
- key: "",
9948
- value: "",
9949
- disabled: false
9967
+ });
9968
+ return res;
9969
+ }, [preview, cancelOrderEdit]);
9970
+ return { onCancel };
9971
+ };
9972
+ let IS_REQUEST_RUNNING = false;
9973
+ const useInitiateOrderEdit = ({
9974
+ preview
9975
+ }) => {
9976
+ const navigate = useNavigate();
9977
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9978
+ useEffect(() => {
9979
+ async function run() {
9980
+ if (IS_REQUEST_RUNNING || !preview) {
9981
+ return;
9982
+ }
9983
+ if (preview.order_change) {
9984
+ return;
9985
+ }
9986
+ IS_REQUEST_RUNNING = true;
9987
+ await mutateAsync(void 0, {
9988
+ onError: (e) => {
9989
+ toast.error(e.message);
9990
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
9991
+ return;
9992
+ }
9950
9993
  });
9994
+ IS_REQUEST_RUNNING = false;
9951
9995
  }
9952
- }
9953
- function insertRow(index, position) {
9954
- insert(index + (position === "above" ? 0 : 1), {
9955
- key: "",
9956
- value: "",
9957
- disabled: false
9958
- });
9959
- }
9960
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
9961
- KeyboundForm,
9962
- {
9963
- onSubmit: handleSubmit,
9964
- className: "flex flex-1 flex-col overflow-hidden",
9965
- children: [
9966
- /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9967
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9968
- /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9969
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9970
- /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9971
- ] }),
9972
- fields.map((field, index) => {
9973
- const isDisabled = field.disabled || false;
9974
- let placeholder = "-";
9975
- if (typeof field.value === "object") {
9976
- placeholder = "{ ... }";
9977
- }
9978
- if (Array.isArray(field.value)) {
9979
- placeholder = "[ ... ]";
9980
- }
9981
- return /* @__PURE__ */ jsx(
9982
- ConditionalTooltip,
9983
- {
9984
- showTooltip: isDisabled,
9985
- content: "This row is disabled because it contains non-primitive data.",
9986
- children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
9987
- /* @__PURE__ */ jsxs(
9988
- "div",
9989
- {
9990
- className: clx("grid grid-cols-2 divide-x", {
9991
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9992
- }),
9993
- children: [
9994
- /* @__PURE__ */ jsx(
9995
- Form$2.Field,
9996
- {
9997
- control: form.control,
9998
- name: `metadata.${index}.key`,
9999
- render: ({ field: field2 }) => {
10000
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10001
- GridInput,
10002
- {
10003
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10004
- ...field2,
10005
- disabled: isDisabled,
10006
- placeholder: "Key"
10007
- }
10008
- ) }) });
10009
- }
10010
- }
10011
- ),
10012
- /* @__PURE__ */ jsx(
10013
- Form$2.Field,
10014
- {
10015
- control: form.control,
10016
- name: `metadata.${index}.value`,
10017
- render: ({ field: { value, ...field2 } }) => {
10018
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10019
- GridInput,
10020
- {
10021
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10022
- ...field2,
10023
- value: isDisabled ? placeholder : value,
10024
- disabled: isDisabled,
10025
- placeholder: "Value"
10026
- }
10027
- ) }) });
10028
- }
10029
- }
10030
- )
10031
- ]
10032
- }
10033
- ),
10034
- /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10035
- /* @__PURE__ */ jsx(
10036
- DropdownMenu.Trigger,
10037
- {
10038
- className: clx(
10039
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10040
- {
10041
- hidden: isDisabled
10042
- }
10043
- ),
10044
- disabled: isDisabled,
10045
- asChild: true,
10046
- children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
10047
- }
10048
- ),
10049
- /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
10050
- /* @__PURE__ */ jsxs(
10051
- DropdownMenu.Item,
10052
- {
10053
- className: "gap-x-2",
10054
- onClick: () => insertRow(index, "above"),
10055
- children: [
10056
- /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
10057
- "Insert row above"
10058
- ]
10059
- }
10060
- ),
10061
- /* @__PURE__ */ jsxs(
10062
- DropdownMenu.Item,
10063
- {
10064
- className: "gap-x-2",
10065
- onClick: () => insertRow(index, "below"),
10066
- children: [
10067
- /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
10068
- "Insert row below"
10069
- ]
10070
- }
10071
- ),
10072
- /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
10073
- /* @__PURE__ */ jsxs(
10074
- DropdownMenu.Item,
10075
- {
10076
- className: "gap-x-2",
10077
- onClick: () => deleteRow(index),
10078
- children: [
10079
- /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
10080
- "Delete row"
10081
- ]
10082
- }
10083
- )
10084
- ] })
10085
- ] })
10086
- ] })
10087
- },
10088
- field.id
10089
- );
10090
- })
10091
- ] }),
10092
- hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10093
- ] }),
10094
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10095
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10096
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10097
- ] }) })
10098
- ]
10099
- }
10100
- ) });
10101
- };
10102
- const GridInput = forwardRef(({ className, ...props }, ref) => {
10103
- return /* @__PURE__ */ jsx(
10104
- "input",
10105
- {
10106
- ref,
10107
- ...props,
10108
- autoComplete: "off",
10109
- className: clx(
10110
- "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",
10111
- className
10112
- )
10113
- }
10114
- );
10115
- });
10116
- GridInput.displayName = "MetadataForm.GridInput";
10117
- const PlaceholderInner = () => {
10118
- return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10119
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10120
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10121
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
10122
- /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
10123
- ] }) })
10124
- ] });
10125
- };
10126
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10127
- function getDefaultValues(metadata) {
10128
- if (!metadata || !Object.keys(metadata).length) {
10129
- return [
10130
- {
10131
- key: "",
10132
- value: "",
10133
- disabled: false
10134
- }
10135
- ];
10136
- }
10137
- return Object.entries(metadata).map(([key, value]) => {
10138
- if (!EDITABLE_TYPES.includes(typeof value)) {
10139
- return {
10140
- key,
10141
- value,
10142
- disabled: true
10143
- };
10144
- }
10145
- let stringValue = value;
10146
- if (typeof value !== "string") {
10147
- stringValue = JSON.stringify(value);
10148
- }
10149
- return {
10150
- key,
10151
- value: stringValue,
10152
- original_key: key
10153
- };
10154
- });
10155
- }
10156
- function parseValues(values) {
10157
- const metadata = values.metadata;
10158
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10159
- if (isEmpty) {
10160
- return null;
10161
- }
10162
- const update = {};
10163
- metadata.forEach((field) => {
10164
- let key = field.key;
10165
- let value = field.value;
10166
- const disabled = field.disabled;
10167
- if (!key || !value) {
10168
- return;
10169
- }
10170
- if (disabled) {
10171
- update[key] = value;
10172
- return;
10173
- }
10174
- key = key.trim();
10175
- value = value.trim();
10176
- if (value === "true") {
10177
- update[key] = true;
10178
- } else if (value === "false") {
10179
- update[key] = false;
10180
- } else {
10181
- const parsedNumber = parseFloat(value);
10182
- if (!isNaN(parsedNumber)) {
10183
- update[key] = parsedNumber;
10184
- } else {
10185
- update[key] = value;
10186
- }
10187
- }
10188
- });
10189
- return update;
10190
- }
10191
- function getHasUneditableRows(metadata) {
10192
- if (!metadata) {
10193
- return false;
10194
- }
10195
- return Object.values(metadata).some(
10196
- (value) => !EDITABLE_TYPES.includes(typeof value)
10197
- );
10198
- }
10199
- const PROMOTION_QUERY_KEY = "promotions";
10200
- const promotionsQueryKeys = {
10201
- list: (query2) => [
10202
- PROMOTION_QUERY_KEY,
10203
- query2 ? query2 : void 0
10204
- ],
10205
- detail: (id, query2) => [
10206
- PROMOTION_QUERY_KEY,
10207
- id,
10208
- query2 ? query2 : void 0
10209
- ]
10210
- };
10211
- const usePromotions = (query2, options) => {
10212
- const { data, ...rest } = useQuery({
10213
- queryKey: promotionsQueryKeys.list(query2),
10214
- queryFn: async () => sdk.admin.promotion.list(query2),
10215
- ...options
10216
- });
10217
- return { ...data, ...rest };
10218
- };
10219
- const useCancelOrderEdit = ({ preview }) => {
10220
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10221
- const onCancel = useCallback(async () => {
10222
- if (!preview) {
10223
- return true;
10224
- }
10225
- let res = false;
10226
- await cancelOrderEdit(void 0, {
10227
- onError: (e) => {
10228
- toast.error(e.message);
10229
- },
10230
- onSuccess: () => {
10231
- res = true;
10232
- }
10233
- });
10234
- return res;
10235
- }, [preview, cancelOrderEdit]);
10236
- return { onCancel };
10237
- };
10238
- let IS_REQUEST_RUNNING = false;
10239
- const useInitiateOrderEdit = ({
10240
- preview
10241
- }) => {
10242
- const navigate = useNavigate();
10243
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10244
- useEffect(() => {
10245
- async function run() {
10246
- if (IS_REQUEST_RUNNING || !preview) {
10247
- return;
10248
- }
10249
- if (preview.order_change) {
10250
- return;
10251
- }
10252
- IS_REQUEST_RUNNING = true;
10253
- await mutateAsync(void 0, {
10254
- onError: (e) => {
10255
- toast.error(e.message);
10256
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10257
- return;
10258
- }
10259
- });
10260
- IS_REQUEST_RUNNING = false;
10261
- }
10262
- run();
10263
- }, [preview, navigate, mutateAsync]);
10264
- };
10265
- const Promotions = () => {
10266
- const { id } = useParams();
10267
- const {
10268
- order: preview,
10269
- isError: isPreviewError,
10270
- error: previewError
10271
- } = useOrderPreview(id, void 0);
10272
- useInitiateOrderEdit({ preview });
10273
- const { onCancel } = useCancelOrderEdit({ preview });
10274
- if (isPreviewError) {
10275
- throw previewError;
10276
- }
10277
- const isReady = !!preview;
10278
- return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
10279
- /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
10280
- isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
10281
- ] });
10282
- };
10283
- const PromotionForm = ({ preview }) => {
10284
- const { items, shipping_methods } = preview;
10285
- const [isSubmitting, setIsSubmitting] = useState(false);
10286
- const [comboboxValue, setComboboxValue] = useState("");
10287
- const { handleSuccess } = useRouteModal();
10288
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
10289
- const promoIds = getPromotionIds(items, shipping_methods);
10290
- const { promotions, isPending, isError, error } = usePromotions(
10291
- {
10292
- id: promoIds
10293
- },
10294
- {
10295
- enabled: !!promoIds.length
10296
- }
10297
- );
10298
- const comboboxData = useComboboxData({
10299
- queryKey: ["promotions", "combobox", promoIds],
10300
- queryFn: async (params) => {
10301
- return await sdk.admin.promotion.list({
10302
- ...params,
10303
- id: {
10304
- $nin: promoIds
10305
- }
10306
- });
10307
- },
10308
- getOptions: (data) => {
10309
- return data.promotions.map((promotion) => ({
10310
- label: promotion.code,
10311
- value: promotion.code
10312
- }));
10313
- }
10314
- });
10315
- const add = async (value) => {
10316
- if (!value) {
10317
- return;
10318
- }
10319
- addPromotions(
10320
- {
10321
- promo_codes: [value]
10322
- },
10323
- {
10324
- onError: (e) => {
10325
- toast.error(e.message);
10326
- comboboxData.onSearchValueChange("");
10327
- setComboboxValue("");
10328
- },
10329
- onSuccess: () => {
10330
- comboboxData.onSearchValueChange("");
10331
- setComboboxValue("");
10332
- }
10333
- }
10334
- );
10335
- };
10336
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10337
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
10338
- const onSubmit = async () => {
10339
- setIsSubmitting(true);
10340
- let requestSucceeded = false;
10341
- await requestOrderEdit(void 0, {
10342
- onError: (e) => {
10343
- toast.error(e.message);
10344
- },
10345
- onSuccess: () => {
10346
- requestSucceeded = true;
10347
- }
10348
- });
10349
- if (!requestSucceeded) {
10350
- setIsSubmitting(false);
10351
- return;
10352
- }
10353
- await confirmOrderEdit(void 0, {
10354
- onError: (e) => {
10355
- toast.error(e.message);
10356
- },
10357
- onSuccess: () => {
10358
- handleSuccess();
10359
- },
10360
- onSettled: () => {
10361
- setIsSubmitting(false);
10362
- }
10363
- });
10364
- };
10365
- if (isError) {
10366
- throw error;
10367
- }
10368
- return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
10369
- /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
10370
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
10371
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10372
- /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
10373
- /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
10374
- ] }),
10375
- /* @__PURE__ */ jsx(
10376
- Combobox,
10377
- {
10378
- id: "promotion-combobox",
10379
- "aria-describedby": "promotion-combobox-hint",
10380
- isFetchingNextPage: comboboxData.isFetchingNextPage,
10381
- fetchNextPage: comboboxData.fetchNextPage,
10382
- options: comboboxData.options,
10383
- onSearchValueChange: comboboxData.onSearchValueChange,
10384
- searchValue: comboboxData.searchValue,
10385
- disabled: comboboxData.disabled || isAddingPromotions,
10386
- onChange: add,
10387
- value: comboboxValue
10388
- }
10389
- )
10390
- ] }),
10391
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10392
- /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
10393
- PromotionItem,
10394
- {
10395
- promotion,
10396
- orderId: preview.id,
10397
- isLoading: isPending
10398
- },
10399
- promotion.id
10400
- )) })
10401
- ] }) }),
10402
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10403
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10404
- /* @__PURE__ */ jsx(
10405
- Button,
10406
- {
10407
- size: "small",
10408
- type: "submit",
10409
- isLoading: isSubmitting || isAddingPromotions,
10410
- children: "Save"
10411
- }
10412
- )
10413
- ] }) })
10414
- ] });
10415
- };
10416
- const PromotionItem = ({
10417
- promotion,
10418
- orderId,
10419
- isLoading
10420
- }) => {
10421
- var _a;
10422
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
10423
- const onRemove = async () => {
10424
- removePromotions(
10425
- {
10426
- promo_codes: [promotion.code]
10427
- },
10428
- {
10429
- onError: (e) => {
10430
- toast.error(e.message);
10431
- }
10432
- }
10433
- );
10434
- };
10435
- const displayValue = getDisplayValue(promotion);
10436
- return /* @__PURE__ */ jsxs(
10437
- "div",
10438
- {
10439
- className: clx(
10440
- "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
10441
- {
10442
- "animate-pulse": isLoading
10443
- }
10444
- ),
10445
- children: [
10446
- /* @__PURE__ */ jsxs("div", { children: [
10447
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
10448
- /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
10449
- displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
10450
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
10451
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
10452
- ] }),
10453
- /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
10454
- ] })
10455
- ] }),
10456
- /* @__PURE__ */ jsx(
10457
- IconButton,
10458
- {
10459
- size: "small",
10460
- type: "button",
10461
- variant: "transparent",
10462
- onClick: onRemove,
10463
- isLoading: isPending || isLoading,
10464
- children: /* @__PURE__ */ jsx(XMark, {})
10465
- }
10466
- )
10467
- ]
10468
- },
10469
- promotion.id
10470
- );
10471
- };
10472
- function getDisplayValue(promotion) {
10473
- var _a, _b, _c, _d;
10474
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
10475
- if (!value) {
10476
- return null;
10477
- }
10478
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
10479
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
10480
- if (!currency) {
10481
- return null;
10482
- }
10483
- return getLocaleAmount(value, currency);
10484
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
10485
- return formatPercentage(value);
10486
- }
10487
- return null;
10488
- }
10489
- const formatter = new Intl.NumberFormat([], {
10490
- style: "percent",
10491
- minimumFractionDigits: 2
10492
- });
10493
- const formatPercentage = (value, isPercentageValue = false) => {
10494
- let val = value || 0;
10495
- if (!isPercentageValue) {
10496
- val = val / 100;
10497
- }
10498
- return formatter.format(val);
10499
- };
10500
- function getPromotionIds(items, shippingMethods) {
10501
- const promotionIds = /* @__PURE__ */ new Set();
10502
- for (const item of items) {
10503
- if (item.adjustments) {
10504
- for (const adjustment of item.adjustments) {
10505
- if (adjustment.promotion_id) {
10506
- promotionIds.add(adjustment.promotion_id);
10507
- }
10508
- }
10509
- }
10510
- }
10511
- for (const shippingMethod of shippingMethods) {
10512
- if (shippingMethod.adjustments) {
10513
- for (const adjustment of shippingMethod.adjustments) {
10514
- if (adjustment.promotion_id) {
10515
- promotionIds.add(adjustment.promotion_id);
10516
- }
10517
- }
10518
- }
10519
- }
10520
- return Array.from(promotionIds);
10521
- }
10522
- const SalesChannel = () => {
10523
- const { id } = useParams();
10524
- const { draft_order, isPending, isError, error } = useDraftOrder(
10525
- id,
10526
- {
10527
- fields: "+sales_channel_id"
10528
- },
10529
- {
10530
- enabled: !!id
10531
- }
10532
- );
10533
- if (isError) {
10534
- throw error;
10535
- }
10536
- const ISrEADY = !!draft_order && !isPending;
10537
- return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10538
- /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10539
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
10540
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
10541
- ] }),
10542
- ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
10543
- ] });
10544
- };
10545
- const SalesChannelForm = ({ order }) => {
10546
- const form = useForm({
10547
- defaultValues: {
10548
- sales_channel_id: order.sales_channel_id || ""
10549
- },
10550
- resolver: zodResolver(schema$2)
10551
- });
10552
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
10553
- const { handleSuccess } = useRouteModal();
10554
- const onSubmit = form.handleSubmit(async (data) => {
10555
- await mutateAsync(
10556
- {
10557
- sales_channel_id: data.sales_channel_id
10558
- },
10559
- {
10560
- onSuccess: () => {
10561
- toast.success("Sales channel updated");
10562
- handleSuccess();
10563
- },
10564
- onError: (error) => {
10565
- toast.error(error.message);
10566
- }
10567
- }
10568
- );
10569
- });
10570
- return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10571
- KeyboundForm,
10572
- {
10573
- className: "flex flex-1 flex-col overflow-hidden",
10574
- onSubmit,
10575
- children: [
10576
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
10577
- /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
10578
- /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10579
- /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10580
- ] }) })
10581
- ]
10582
- }
10583
- ) });
10584
- };
10585
- const SalesChannelField = ({ control, order }) => {
10586
- const salesChannels = useComboboxData({
10587
- queryFn: async (params) => {
10588
- return await sdk.admin.salesChannel.list(params);
10589
- },
10590
- queryKey: ["sales-channels"],
10591
- getOptions: (data) => {
10592
- return data.sales_channels.map((salesChannel) => ({
10593
- label: salesChannel.name,
10594
- value: salesChannel.id
10595
- }));
10596
- },
10597
- defaultValue: order.sales_channel_id || void 0
10598
- });
10599
- return /* @__PURE__ */ jsx(
10600
- Form$2.Field,
10601
- {
10602
- control,
10603
- name: "sales_channel_id",
10604
- render: ({ field }) => {
10605
- return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
10606
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
10607
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10608
- Combobox,
10609
- {
10610
- options: salesChannels.options,
10611
- fetchNextPage: salesChannels.fetchNextPage,
10612
- isFetchingNextPage: salesChannels.isFetchingNextPage,
10613
- searchValue: salesChannels.searchValue,
10614
- onSearchValueChange: salesChannels.onSearchValueChange,
10615
- placeholder: "Select sales channel",
10616
- ...field
10617
- }
10618
- ) }),
10619
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10620
- ] });
10621
- }
10622
- }
10623
- );
10624
- };
10625
- const schema$2 = objectType({
10626
- sales_channel_id: stringType().min(1)
10627
- });
10628
- const NumberInput = forwardRef(
10629
- ({
10630
- value,
10631
- onChange,
10632
- size = "base",
10633
- min = 0,
10634
- max = 100,
10635
- step = 1,
10636
- className,
10637
- disabled,
10638
- ...props
10639
- }, ref) => {
10640
- const handleChange = (event) => {
10641
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10642
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10643
- onChange(newValue);
10644
- }
10645
- };
10646
- const handleIncrement = () => {
10647
- const newValue = value + step;
10648
- if (max === void 0 || newValue <= max) {
10649
- onChange(newValue);
10650
- }
10651
- };
10652
- const handleDecrement = () => {
10653
- const newValue = value - step;
10654
- if (min === void 0 || newValue >= min) {
10655
- onChange(newValue);
10656
- }
10657
- };
10658
- return /* @__PURE__ */ jsxs(
10659
- "div",
10660
- {
10661
- className: clx(
10662
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10663
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10664
- {
10665
- "h-7": size === "small",
10666
- "h-8": size === "base"
10667
- },
10668
- className
10669
- ),
10670
- children: [
10671
- /* @__PURE__ */ jsx(
10672
- "input",
10673
- {
10674
- ref,
10675
- type: "number",
10676
- value,
10677
- onChange: handleChange,
10678
- min,
10679
- max,
10680
- step,
10681
- className: clx(
10682
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10683
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10684
- "placeholder:text-ui-fg-muted"
10685
- ),
10686
- ...props
10687
- }
10688
- ),
10689
- /* @__PURE__ */ jsxs(
10690
- "button",
10691
- {
10692
- className: clx(
10693
- "flex items-center justify-center outline-none transition-fg",
10694
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10695
- "focus:bg-ui-bg-field-component-hover",
10696
- "hover:bg-ui-bg-field-component-hover",
10697
- {
10698
- "size-7": size === "small",
10699
- "size-8": size === "base"
10700
- }
10701
- ),
10702
- type: "button",
10703
- onClick: handleDecrement,
10704
- disabled: min !== void 0 && value <= min || disabled,
10705
- children: [
10706
- /* @__PURE__ */ jsx(Minus, {}),
10707
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10708
- ]
10709
- }
10710
- ),
10711
- /* @__PURE__ */ jsxs(
10712
- "button",
10713
- {
10714
- className: clx(
10715
- "flex items-center justify-center outline-none transition-fg",
10716
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10717
- "focus:bg-ui-bg-field-hover",
10718
- "hover:bg-ui-bg-field-hover",
10719
- {
10720
- "size-7": size === "small",
10721
- "size-8": size === "base"
10722
- }
10723
- ),
10724
- type: "button",
10725
- onClick: handleIncrement,
10726
- disabled: max !== void 0 && value >= max || disabled,
10727
- children: [
10728
- /* @__PURE__ */ jsx(Plus, {}),
10729
- /* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10730
- ]
10731
- }
10732
- )
10733
- ]
10734
- }
10735
- );
10736
- }
10737
- );
10738
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10739
- const productVariantsQueryKeys = {
10740
- list: (query2) => [
10741
- PRODUCT_VARIANTS_QUERY_KEY,
10742
- query2 ? query2 : void 0
10743
- ]
10744
- };
10745
- const useProductVariants = (query2, options) => {
10746
- const { data, ...rest } = useQuery({
10747
- queryKey: productVariantsQueryKeys.list(query2),
10748
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10749
- ...options
10750
- });
10751
- return { ...data, ...rest };
9996
+ run();
9997
+ }, [preview, navigate, mutateAsync]);
10752
9998
  };
10753
9999
  function convertNumber(value) {
10754
10000
  return typeof value === "string" ? Number(value.replace(",", ".")) : value;
@@ -10997,7 +10243,155 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10997
10243
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10998
10244
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10999
10245
  const onSubmit = form.handleSubmit(async (data) => {
11000
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10246
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10247
+ setEditing(false);
10248
+ return;
10249
+ }
10250
+ if (!actionId) {
10251
+ await updateOriginalItem(
10252
+ {
10253
+ item_id: item.id,
10254
+ quantity: data.quantity,
10255
+ unit_price: convertNumber(data.unit_price)
10256
+ },
10257
+ {
10258
+ onSuccess: () => {
10259
+ setEditing(false);
10260
+ },
10261
+ onError: (e) => {
10262
+ toast.error(e.message);
10263
+ }
10264
+ }
10265
+ );
10266
+ return;
10267
+ }
10268
+ await updateActionItem(
10269
+ {
10270
+ action_id: actionId,
10271
+ quantity: data.quantity,
10272
+ unit_price: convertNumber(data.unit_price)
10273
+ },
10274
+ {
10275
+ onSuccess: () => {
10276
+ setEditing(false);
10277
+ },
10278
+ onError: (e) => {
10279
+ toast.error(e.message);
10280
+ }
10281
+ }
10282
+ );
10283
+ });
10284
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10285
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10286
+ /* @__PURE__ */ jsx(
10287
+ Thumbnail,
10288
+ {
10289
+ thumbnail: item.thumbnail,
10290
+ alt: item.product_title ?? void 0
10291
+ }
10292
+ ),
10293
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
10294
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
10295
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10296
+ /* @__PURE__ */ jsxs(
10297
+ Text,
10298
+ {
10299
+ size: "small",
10300
+ leading: "compact",
10301
+ className: "text-ui-fg-subtle",
10302
+ children: [
10303
+ "(",
10304
+ item.variant_title,
10305
+ ")"
10306
+ ]
10307
+ }
10308
+ )
10309
+ ] }),
10310
+ /* @__PURE__ */ jsx(
10311
+ Text,
10312
+ {
10313
+ size: "small",
10314
+ leading: "compact",
10315
+ className: "text-ui-fg-subtle",
10316
+ children: item.variant_sku
10317
+ }
10318
+ )
10319
+ ] })
10320
+ ] }),
10321
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10322
+ Form$2.Field,
10323
+ {
10324
+ control: form.control,
10325
+ name: "quantity",
10326
+ render: ({ field }) => {
10327
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10328
+ }
10329
+ }
10330
+ ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
10331
+ editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10332
+ Form$2.Field,
10333
+ {
10334
+ control: form.control,
10335
+ name: "unit_price",
10336
+ render: ({ field: { onChange, ...field } }) => {
10337
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10338
+ CurrencyInput,
10339
+ {
10340
+ ...field,
10341
+ symbol: getNativeSymbol(currencyCode),
10342
+ code: currencyCode,
10343
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10344
+ }
10345
+ ) }) });
10346
+ }
10347
+ }
10348
+ ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10349
+ /* @__PURE__ */ jsx(
10350
+ IconButton,
10351
+ {
10352
+ type: "button",
10353
+ size: "small",
10354
+ onClick: editing ? onSubmit : () => {
10355
+ setEditing(true);
10356
+ },
10357
+ disabled: isPending,
10358
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10359
+ }
10360
+ )
10361
+ ] }) }) });
10362
+ };
10363
+ const variantItemSchema = objectType({
10364
+ quantity: numberType(),
10365
+ unit_price: unionType([numberType(), stringType()])
10366
+ });
10367
+ const CustomItem = ({ item, preview, currencyCode }) => {
10368
+ const [editing, setEditing] = useState(false);
10369
+ const { quantity, unit_price, title } = item;
10370
+ const form = useForm({
10371
+ defaultValues: {
10372
+ title,
10373
+ quantity,
10374
+ unit_price
10375
+ },
10376
+ resolver: zodResolver(customItemSchema)
10377
+ });
10378
+ useEffect(() => {
10379
+ form.reset({
10380
+ title,
10381
+ quantity,
10382
+ unit_price
10383
+ });
10384
+ }, [form, title, quantity, unit_price]);
10385
+ const actionId = useMemo(() => {
10386
+ var _a, _b;
10387
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10388
+ }, [item]);
10389
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10390
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10391
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10392
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10393
+ const onSubmit = form.handleSubmit(async (data) => {
10394
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
11001
10395
  setEditing(false);
11002
10396
  return;
11003
10397
  }
@@ -11019,6 +10413,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
11019
10413
  );
11020
10414
  return;
11021
10415
  }
10416
+ if (data.quantity === 0) {
10417
+ await removeActionItem(actionId, {
10418
+ onSuccess: () => {
10419
+ setEditing(false);
10420
+ },
10421
+ onError: (e) => {
10422
+ toast.error(e.message);
10423
+ }
10424
+ });
10425
+ return;
10426
+ }
11022
10427
  await updateActionItem(
11023
10428
  {
11024
10429
  action_id: actionId,
@@ -11036,43 +10441,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
11036
10441
  );
11037
10442
  });
11038
10443
  return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
11039
- /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10444
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
11040
10445
  /* @__PURE__ */ jsx(
11041
10446
  Thumbnail,
11042
10447
  {
11043
10448
  thumbnail: item.thumbnail,
11044
- alt: item.product_title ?? void 0
10449
+ alt: item.title ?? void 0
11045
10450
  }
11046
10451
  ),
11047
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11048
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
11049
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
11050
- /* @__PURE__ */ jsxs(
11051
- Text,
11052
- {
11053
- size: "small",
11054
- leading: "compact",
11055
- className: "text-ui-fg-subtle",
11056
- children: [
11057
- "(",
11058
- item.variant_title,
11059
- ")"
11060
- ]
11061
- }
11062
- )
11063
- ] }),
11064
- /* @__PURE__ */ jsx(
11065
- Text,
11066
- {
11067
- size: "small",
11068
- leading: "compact",
11069
- className: "text-ui-fg-subtle",
11070
- children: item.variant_sku
10452
+ editing ? /* @__PURE__ */ jsx(
10453
+ Form$2.Field,
10454
+ {
10455
+ control: form.control,
10456
+ name: "title",
10457
+ render: ({ field }) => {
10458
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
11071
10459
  }
11072
- )
11073
- ] })
10460
+ }
10461
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
11074
10462
  ] }),
11075
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10463
+ editing ? /* @__PURE__ */ jsx(
11076
10464
  Form$2.Field,
11077
10465
  {
11078
10466
  control: form.control,
@@ -11081,8 +10469,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
11081
10469
  return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
11082
10470
  }
11083
10471
  }
11084
- ) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
11085
- editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
10472
+ ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
10473
+ editing ? /* @__PURE__ */ jsx(
11086
10474
  Form$2.Field,
11087
10475
  {
11088
10476
  control: form.control,
@@ -11096,97 +10484,233 @@ const VariantItem = ({ item, preview, currencyCode }) => {
11096
10484
  code: currencyCode,
11097
10485
  onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11098
10486
  }
11099
- ) }) });
11100
- }
11101
- }
11102
- ) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11103
- /* @__PURE__ */ jsx(
11104
- IconButton,
11105
- {
11106
- type: "button",
11107
- size: "small",
11108
- onClick: editing ? onSubmit : () => {
11109
- setEditing(true);
10487
+ ) }) });
10488
+ }
10489
+ }
10490
+ ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10491
+ /* @__PURE__ */ jsx(
10492
+ IconButton,
10493
+ {
10494
+ type: "button",
10495
+ size: "small",
10496
+ onClick: editing ? onSubmit : () => {
10497
+ setEditing(true);
10498
+ },
10499
+ disabled: isPending,
10500
+ children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
10501
+ }
10502
+ )
10503
+ ] }) }) });
10504
+ };
10505
+ const StackedModalTrigger$1 = ({
10506
+ type,
10507
+ setModalContent
10508
+ }) => {
10509
+ const { setIsOpen } = useStackedModal();
10510
+ const onClick = useCallback(() => {
10511
+ setModalContent(type);
10512
+ setIsOpen(STACKED_MODAL_ID, true);
10513
+ }, [setModalContent, setIsOpen, type]);
10514
+ return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10515
+ };
10516
+ const VARIANT_PREFIX = "items";
10517
+ const LIMIT = 50;
10518
+ const ExistingItemsForm = ({ orderId, items }) => {
10519
+ const { setIsOpen } = useStackedModal();
10520
+ const [rowSelection, setRowSelection] = useState(
10521
+ items.reduce((acc, item) => {
10522
+ acc[item.variant_id] = true;
10523
+ return acc;
10524
+ }, {})
10525
+ );
10526
+ useEffect(() => {
10527
+ setRowSelection(
10528
+ items.reduce((acc, item) => {
10529
+ if (item.variant_id) {
10530
+ acc[item.variant_id] = true;
10531
+ }
10532
+ return acc;
10533
+ }, {})
10534
+ );
10535
+ }, [items]);
10536
+ const { q, order, offset } = useQueryParams(
10537
+ ["q", "order", "offset"],
10538
+ VARIANT_PREFIX
10539
+ );
10540
+ const { variants, count, isPending, isError, error } = useProductVariants(
10541
+ {
10542
+ q,
10543
+ order,
10544
+ offset: offset ? parseInt(offset) : void 0,
10545
+ limit: LIMIT
10546
+ },
10547
+ {
10548
+ placeholderData: keepPreviousData
10549
+ }
10550
+ );
10551
+ const columns = useColumns();
10552
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10553
+ const onSubmit = async () => {
10554
+ const ids = Object.keys(rowSelection).filter(
10555
+ (id) => !items.find((i) => i.variant_id === id)
10556
+ );
10557
+ await mutateAsync(
10558
+ {
10559
+ items: ids.map((id) => ({
10560
+ variant_id: id,
10561
+ quantity: 1
10562
+ }))
10563
+ },
10564
+ {
10565
+ onSuccess: () => {
10566
+ setRowSelection({});
10567
+ setIsOpen(STACKED_MODAL_ID, false);
10568
+ },
10569
+ onError: (e) => {
10570
+ toast.error(e.message);
10571
+ }
10572
+ }
10573
+ );
10574
+ };
10575
+ if (isError) {
10576
+ throw error;
10577
+ }
10578
+ return /* @__PURE__ */ jsxs(
10579
+ StackedFocusModal.Content,
10580
+ {
10581
+ onOpenAutoFocus: (e) => {
10582
+ e.preventDefault();
10583
+ const searchInput = document.querySelector(
10584
+ "[data-modal-id='modal-search-input']"
10585
+ );
10586
+ if (searchInput) {
10587
+ searchInput.focus();
10588
+ }
10589
+ },
10590
+ children: [
10591
+ /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
10592
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10593
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10594
+ ] }),
10595
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
10596
+ DataTable,
10597
+ {
10598
+ data: variants,
10599
+ columns,
10600
+ isLoading: isPending,
10601
+ getRowId: (row) => row.id,
10602
+ rowCount: count,
10603
+ prefix: VARIANT_PREFIX,
10604
+ layout: "fill",
10605
+ rowSelection: {
10606
+ state: rowSelection,
10607
+ onRowSelectionChange: setRowSelection,
10608
+ enableRowSelection: (row) => {
10609
+ return !items.find((i) => i.variant_id === row.original.id);
10610
+ }
10611
+ },
10612
+ autoFocusSearch: true
10613
+ }
10614
+ ) }),
10615
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10616
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10617
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10618
+ ] }) })
10619
+ ]
10620
+ }
10621
+ );
10622
+ };
10623
+ const columnHelper = createDataTableColumnHelper();
10624
+ const useColumns = () => {
10625
+ return useMemo(() => {
10626
+ return [
10627
+ columnHelper.select(),
10628
+ columnHelper.accessor("product.title", {
10629
+ header: "Product",
10630
+ cell: ({ row }) => {
10631
+ var _a, _b, _c;
10632
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
10633
+ /* @__PURE__ */ jsx(
10634
+ Thumbnail,
10635
+ {
10636
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10637
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10638
+ }
10639
+ ),
10640
+ /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10641
+ ] });
10642
+ },
10643
+ enableSorting: true
10644
+ }),
10645
+ columnHelper.accessor("title", {
10646
+ header: "Variant",
10647
+ enableSorting: true
10648
+ }),
10649
+ columnHelper.accessor("sku", {
10650
+ header: "SKU",
10651
+ cell: ({ getValue }) => {
10652
+ return getValue() ?? "-";
10653
+ },
10654
+ enableSorting: true
10655
+ }),
10656
+ columnHelper.accessor("updated_at", {
10657
+ header: "Updated",
10658
+ cell: ({ getValue }) => {
10659
+ return /* @__PURE__ */ jsx(
10660
+ Tooltip,
10661
+ {
10662
+ content: getFullDate({ date: getValue(), includeTime: true }),
10663
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10664
+ }
10665
+ );
10666
+ },
10667
+ enableSorting: true,
10668
+ sortAscLabel: "Oldest first",
10669
+ sortDescLabel: "Newest first"
10670
+ }),
10671
+ columnHelper.accessor("created_at", {
10672
+ header: "Created",
10673
+ cell: ({ getValue }) => {
10674
+ return /* @__PURE__ */ jsx(
10675
+ Tooltip,
10676
+ {
10677
+ content: getFullDate({ date: getValue(), includeTime: true }),
10678
+ children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
10679
+ }
10680
+ );
11110
10681
  },
11111
- disabled: isPending,
11112
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
11113
- }
11114
- )
11115
- ] }) }) });
10682
+ enableSorting: true,
10683
+ sortAscLabel: "Oldest first",
10684
+ sortDescLabel: "Newest first"
10685
+ })
10686
+ ];
10687
+ }, []);
11116
10688
  };
11117
- const variantItemSchema = objectType({
11118
- quantity: numberType(),
11119
- unit_price: unionType([numberType(), stringType()])
11120
- });
11121
- const CustomItem = ({ item, preview, currencyCode }) => {
11122
- const [editing, setEditing] = useState(false);
11123
- const { quantity, unit_price, title } = item;
10689
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10690
+ const { setIsOpen } = useStackedModal();
10691
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11124
10692
  const form = useForm({
11125
10693
  defaultValues: {
11126
- title,
11127
- quantity,
11128
- unit_price
10694
+ title: "",
10695
+ quantity: 1,
10696
+ unit_price: ""
11129
10697
  },
11130
10698
  resolver: zodResolver(customItemSchema)
11131
10699
  });
11132
- useEffect(() => {
11133
- form.reset({
11134
- title,
11135
- quantity,
11136
- unit_price
11137
- });
11138
- }, [form, title, quantity, unit_price]);
11139
- const actionId = useMemo(() => {
11140
- var _a, _b;
11141
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
11142
- }, [item]);
11143
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
11144
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
11145
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
11146
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
11147
10700
  const onSubmit = form.handleSubmit(async (data) => {
11148
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
11149
- setEditing(false);
11150
- return;
11151
- }
11152
- if (!actionId) {
11153
- await updateOriginalItem(
11154
- {
11155
- item_id: item.id,
11156
- quantity: data.quantity,
11157
- unit_price: convertNumber(data.unit_price)
11158
- },
11159
- {
11160
- onSuccess: () => {
11161
- setEditing(false);
11162
- },
11163
- onError: (e) => {
11164
- toast.error(e.message);
11165
- }
11166
- }
11167
- );
11168
- return;
11169
- }
11170
- if (data.quantity === 0) {
11171
- await removeActionItem(actionId, {
11172
- onSuccess: () => {
11173
- setEditing(false);
11174
- },
11175
- onError: (e) => {
11176
- toast.error(e.message);
11177
- }
11178
- });
11179
- return;
11180
- }
11181
- await updateActionItem(
10701
+ await addItems(
11182
10702
  {
11183
- action_id: actionId,
11184
- quantity: data.quantity,
11185
- unit_price: convertNumber(data.unit_price)
10703
+ items: [
10704
+ {
10705
+ title: data.title,
10706
+ quantity: data.quantity,
10707
+ unit_price: convertNumber(data.unit_price)
10708
+ }
10709
+ ]
11186
10710
  },
11187
10711
  {
11188
10712
  onSuccess: () => {
11189
- setEditing(false);
10713
+ setIsOpen(STACKED_MODAL_ID, false);
11190
10714
  },
11191
10715
  onError: (e) => {
11192
10716
  toast.error(e.message);
@@ -11194,419 +10718,754 @@ const CustomItem = ({ item, preview, currencyCode }) => {
11194
10718
  }
11195
10719
  );
11196
10720
  });
11197
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
11198
- /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
10721
+ return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
10722
+ /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
10723
+ /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10724
+ /* @__PURE__ */ jsxs("div", { children: [
10725
+ /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
10726
+ /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10727
+ ] }),
10728
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11199
10729
  /* @__PURE__ */ jsx(
11200
- Thumbnail,
10730
+ Form$2.Field,
11201
10731
  {
11202
- thumbnail: item.thumbnail,
11203
- alt: item.title ?? void 0
10732
+ control: form.control,
10733
+ name: "title",
10734
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10735
+ /* @__PURE__ */ jsxs("div", { children: [
10736
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
10737
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
10738
+ ] }),
10739
+ /* @__PURE__ */ jsxs("div", { children: [
10740
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
10741
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10742
+ ] })
10743
+ ] }) })
11204
10744
  }
11205
10745
  ),
11206
- editing ? /* @__PURE__ */ jsx(
10746
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10747
+ /* @__PURE__ */ jsx(
11207
10748
  Form$2.Field,
11208
10749
  {
11209
10750
  control: form.control,
11210
- name: "title",
11211
- render: ({ field }) => {
11212
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
11213
- }
11214
- }
11215
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
11216
- ] }),
11217
- editing ? /* @__PURE__ */ jsx(
11218
- Form$2.Field,
11219
- {
11220
- control: form.control,
11221
- name: "quantity",
11222
- render: ({ field }) => {
11223
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
10751
+ name: "unit_price",
10752
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10753
+ /* @__PURE__ */ jsxs("div", { children: [
10754
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
10755
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10756
+ ] }),
10757
+ /* @__PURE__ */ jsxs("div", { children: [
10758
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10759
+ CurrencyInput,
10760
+ {
10761
+ symbol: getNativeSymbol(currencyCode),
10762
+ code: currencyCode,
10763
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10764
+ ...field
10765
+ }
10766
+ ) }),
10767
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10768
+ ] })
10769
+ ] }) })
11224
10770
  }
11225
- }
11226
- ) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
11227
- editing ? /* @__PURE__ */ jsx(
11228
- Form$2.Field,
11229
- {
11230
- control: form.control,
11231
- name: "unit_price",
11232
- render: ({ field: { onChange, ...field } }) => {
11233
- return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11234
- CurrencyInput,
11235
- {
11236
- ...field,
11237
- symbol: getNativeSymbol(currencyCode),
11238
- code: currencyCode,
11239
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
11240
- }
11241
- ) }) });
10771
+ ),
10772
+ /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
10773
+ /* @__PURE__ */ jsx(
10774
+ Form$2.Field,
10775
+ {
10776
+ control: form.control,
10777
+ name: "quantity",
10778
+ render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10779
+ /* @__PURE__ */ jsxs("div", { children: [
10780
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
10781
+ /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10782
+ ] }),
10783
+ /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
10784
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10785
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
10786
+ ] })
10787
+ ] }) })
11242
10788
  }
11243
- }
11244
- ) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
11245
- /* @__PURE__ */ jsx(
11246
- IconButton,
11247
- {
11248
- type: "button",
11249
- size: "small",
11250
- onClick: editing ? onSubmit : () => {
11251
- setEditing(true);
11252
- },
11253
- disabled: isPending,
11254
- children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
11255
- }
11256
- )
10789
+ )
10790
+ ] }) }) }),
10791
+ /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10792
+ /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10793
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10794
+ ] }) })
11257
10795
  ] }) }) });
11258
10796
  };
11259
- const StackedModalTrigger$1 = ({
11260
- type,
11261
- setModalContent
11262
- }) => {
11263
- const { setIsOpen } = useStackedModal();
11264
- const onClick = useCallback(() => {
11265
- setModalContent(type);
11266
- setIsOpen(STACKED_MODAL_ID, true);
11267
- }, [setModalContent, setIsOpen, type]);
11268
- return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
11269
- };
11270
- const VARIANT_PREFIX = "items";
11271
- const LIMIT = 50;
11272
- const ExistingItemsForm = ({ orderId, items }) => {
11273
- const { setIsOpen } = useStackedModal();
11274
- const [rowSelection, setRowSelection] = useState(
11275
- items.reduce((acc, item) => {
11276
- acc[item.variant_id] = true;
11277
- return acc;
11278
- }, {})
11279
- );
11280
- useEffect(() => {
11281
- setRowSelection(
11282
- items.reduce((acc, item) => {
11283
- if (item.variant_id) {
11284
- acc[item.variant_id] = true;
11285
- }
11286
- return acc;
11287
- }, {})
10797
+ const customItemSchema = objectType({
10798
+ title: stringType().min(1),
10799
+ quantity: numberType(),
10800
+ unit_price: unionType([numberType(), stringType()])
10801
+ });
10802
+ const InlineTip = forwardRef(
10803
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10804
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10805
+ return /* @__PURE__ */ jsxs(
10806
+ "div",
10807
+ {
10808
+ ref,
10809
+ className: clx(
10810
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10811
+ className
10812
+ ),
10813
+ ...props,
10814
+ children: [
10815
+ /* @__PURE__ */ jsx(
10816
+ "div",
10817
+ {
10818
+ role: "presentation",
10819
+ className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10820
+ "bg-ui-tag-orange-icon": variant === "warning"
10821
+ })
10822
+ }
10823
+ ),
10824
+ /* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
10825
+ /* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10826
+ labelValue,
10827
+ ":"
10828
+ ] }),
10829
+ " ",
10830
+ children
10831
+ ] })
10832
+ ]
10833
+ }
11288
10834
  );
11289
- }, [items]);
11290
- const { q, order, offset } = useQueryParams(
11291
- ["q", "order", "offset"],
11292
- VARIANT_PREFIX
11293
- );
11294
- const { variants, count, isPending, isError, error } = useProductVariants(
11295
- {
11296
- q,
11297
- order,
11298
- offset: offset ? parseInt(offset) : void 0,
11299
- limit: LIMIT
10835
+ }
10836
+ );
10837
+ InlineTip.displayName = "InlineTip";
10838
+ const MetadataFieldSchema = objectType({
10839
+ key: stringType(),
10840
+ disabled: booleanType().optional(),
10841
+ value: anyType()
10842
+ });
10843
+ const MetadataSchema = objectType({
10844
+ metadata: arrayType(MetadataFieldSchema)
10845
+ });
10846
+ const Metadata = () => {
10847
+ const { id } = useParams();
10848
+ const { order, isPending, isError, error } = useOrder(id, {
10849
+ fields: "metadata"
10850
+ });
10851
+ if (isError) {
10852
+ throw error;
10853
+ }
10854
+ const isReady = !isPending && !!order;
10855
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
10856
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
10857
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
10858
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10859
+ ] }),
10860
+ !isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10861
+ ] });
10862
+ };
10863
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10864
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10865
+ const MetadataForm = ({ orderId, metadata }) => {
10866
+ const { handleSuccess } = useRouteModal();
10867
+ const hasUneditableRows = getHasUneditableRows(metadata);
10868
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10869
+ const form = useForm({
10870
+ defaultValues: {
10871
+ metadata: getDefaultValues(metadata)
11300
10872
  },
11301
- {
11302
- placeholderData: keepPreviousData
11303
- }
11304
- );
11305
- const columns = useColumns();
11306
- const { mutateAsync } = useDraftOrderAddItems(orderId);
11307
- const onSubmit = async () => {
11308
- const ids = Object.keys(rowSelection).filter(
11309
- (id) => !items.find((i) => i.variant_id === id)
11310
- );
10873
+ resolver: zodResolver(MetadataSchema)
10874
+ });
10875
+ const handleSubmit = form.handleSubmit(async (data) => {
10876
+ const parsedData = parseValues(data);
11311
10877
  await mutateAsync(
11312
10878
  {
11313
- items: ids.map((id) => ({
11314
- variant_id: id,
11315
- quantity: 1
11316
- }))
10879
+ metadata: parsedData
11317
10880
  },
11318
10881
  {
11319
10882
  onSuccess: () => {
11320
- setRowSelection({});
11321
- setIsOpen(STACKED_MODAL_ID, false);
10883
+ toast.success("Metadata updated");
10884
+ handleSuccess();
11322
10885
  },
11323
- onError: (e) => {
11324
- toast.error(e.message);
10886
+ onError: (error) => {
10887
+ toast.error(error.message);
11325
10888
  }
11326
10889
  }
11327
10890
  );
11328
- };
11329
- if (isError) {
11330
- throw error;
10891
+ });
10892
+ const { fields, insert, remove } = useFieldArray({
10893
+ control: form.control,
10894
+ name: "metadata"
10895
+ });
10896
+ function deleteRow(index) {
10897
+ remove(index);
10898
+ if (fields.length === 1) {
10899
+ insert(0, {
10900
+ key: "",
10901
+ value: "",
10902
+ disabled: false
10903
+ });
10904
+ }
11331
10905
  }
11332
- return /* @__PURE__ */ jsxs(
11333
- StackedFocusModal.Content,
10906
+ function insertRow(index, position) {
10907
+ insert(index + (position === "above" ? 0 : 1), {
10908
+ key: "",
10909
+ value: "",
10910
+ disabled: false
10911
+ });
10912
+ }
10913
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
10914
+ KeyboundForm,
11334
10915
  {
11335
- onOpenAutoFocus: (e) => {
11336
- e.preventDefault();
11337
- const searchInput = document.querySelector(
11338
- "[data-modal-id='modal-search-input']"
11339
- );
11340
- if (searchInput) {
11341
- searchInput.focus();
11342
- }
11343
- },
10916
+ onSubmit: handleSubmit,
10917
+ className: "flex flex-1 flex-col overflow-hidden",
11344
10918
  children: [
11345
- /* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
11346
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
11347
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10919
+ /* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10920
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10921
+ /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10922
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10923
+ /* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10924
+ ] }),
10925
+ fields.map((field, index) => {
10926
+ const isDisabled = field.disabled || false;
10927
+ let placeholder = "-";
10928
+ if (typeof field.value === "object") {
10929
+ placeholder = "{ ... }";
10930
+ }
10931
+ if (Array.isArray(field.value)) {
10932
+ placeholder = "[ ... ]";
10933
+ }
10934
+ return /* @__PURE__ */ jsx(
10935
+ ConditionalTooltip,
10936
+ {
10937
+ showTooltip: isDisabled,
10938
+ content: "This row is disabled because it contains non-primitive data.",
10939
+ children: /* @__PURE__ */ jsxs("div", { className: "group/table relative", children: [
10940
+ /* @__PURE__ */ jsxs(
10941
+ "div",
10942
+ {
10943
+ className: clx("grid grid-cols-2 divide-x", {
10944
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10945
+ }),
10946
+ children: [
10947
+ /* @__PURE__ */ jsx(
10948
+ Form$2.Field,
10949
+ {
10950
+ control: form.control,
10951
+ name: `metadata.${index}.key`,
10952
+ render: ({ field: field2 }) => {
10953
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10954
+ GridInput,
10955
+ {
10956
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10957
+ ...field2,
10958
+ disabled: isDisabled,
10959
+ placeholder: "Key"
10960
+ }
10961
+ ) }) });
10962
+ }
10963
+ }
10964
+ ),
10965
+ /* @__PURE__ */ jsx(
10966
+ Form$2.Field,
10967
+ {
10968
+ control: form.control,
10969
+ name: `metadata.${index}.value`,
10970
+ render: ({ field: { value, ...field2 } }) => {
10971
+ return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
10972
+ GridInput,
10973
+ {
10974
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10975
+ ...field2,
10976
+ value: isDisabled ? placeholder : value,
10977
+ disabled: isDisabled,
10978
+ placeholder: "Value"
10979
+ }
10980
+ ) }) });
10981
+ }
10982
+ }
10983
+ )
10984
+ ]
10985
+ }
10986
+ ),
10987
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
10988
+ /* @__PURE__ */ jsx(
10989
+ DropdownMenu.Trigger,
10990
+ {
10991
+ className: clx(
10992
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10993
+ {
10994
+ hidden: isDisabled
10995
+ }
10996
+ ),
10997
+ disabled: isDisabled,
10998
+ asChild: true,
10999
+ children: /* @__PURE__ */ jsx(IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsx(EllipsisVertical, {}) })
11000
+ }
11001
+ ),
11002
+ /* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
11003
+ /* @__PURE__ */ jsxs(
11004
+ DropdownMenu.Item,
11005
+ {
11006
+ className: "gap-x-2",
11007
+ onClick: () => insertRow(index, "above"),
11008
+ children: [
11009
+ /* @__PURE__ */ jsx(ArrowUpMini, { className: "text-ui-fg-subtle" }),
11010
+ "Insert row above"
11011
+ ]
11012
+ }
11013
+ ),
11014
+ /* @__PURE__ */ jsxs(
11015
+ DropdownMenu.Item,
11016
+ {
11017
+ className: "gap-x-2",
11018
+ onClick: () => insertRow(index, "below"),
11019
+ children: [
11020
+ /* @__PURE__ */ jsx(ArrowDownMini, { className: "text-ui-fg-subtle" }),
11021
+ "Insert row below"
11022
+ ]
11023
+ }
11024
+ ),
11025
+ /* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
11026
+ /* @__PURE__ */ jsxs(
11027
+ DropdownMenu.Item,
11028
+ {
11029
+ className: "gap-x-2",
11030
+ onClick: () => deleteRow(index),
11031
+ children: [
11032
+ /* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
11033
+ "Delete row"
11034
+ ]
11035
+ }
11036
+ )
11037
+ ] })
11038
+ ] })
11039
+ ] })
11040
+ },
11041
+ field.id
11042
+ );
11043
+ })
11044
+ ] }),
11045
+ hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11348
11046
  ] }),
11349
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
11350
- DataTable,
11351
- {
11352
- data: variants,
11353
- columns,
11354
- isLoading: isPending,
11355
- getRowId: (row) => row.id,
11356
- rowCount: count,
11357
- prefix: VARIANT_PREFIX,
11358
- layout: "fill",
11359
- rowSelection: {
11360
- state: rowSelection,
11361
- onRowSelectionChange: setRowSelection,
11362
- enableRowSelection: (row) => {
11363
- return !items.find((i) => i.variant_id === row.original.id);
11364
- }
11365
- },
11366
- autoFocusSearch: true
11367
- }
11368
- ) }),
11369
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11370
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11371
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
11047
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11048
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11049
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11372
11050
  ] }) })
11373
11051
  ]
11374
11052
  }
11053
+ ) });
11054
+ };
11055
+ const GridInput = forwardRef(({ className, ...props }, ref) => {
11056
+ return /* @__PURE__ */ jsx(
11057
+ "input",
11058
+ {
11059
+ ref,
11060
+ ...props,
11061
+ autoComplete: "off",
11062
+ className: clx(
11063
+ "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",
11064
+ className
11065
+ )
11066
+ }
11375
11067
  );
11068
+ });
11069
+ GridInput.displayName = "MetadataForm.GridInput";
11070
+ const PlaceholderInner = () => {
11071
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11072
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11073
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11074
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
11075
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
11076
+ ] }) })
11077
+ ] });
11376
11078
  };
11377
- const columnHelper = createDataTableColumnHelper();
11378
- const useColumns = () => {
11379
- return useMemo(() => {
11079
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11080
+ function getDefaultValues(metadata) {
11081
+ if (!metadata || !Object.keys(metadata).length) {
11380
11082
  return [
11381
- columnHelper.select(),
11382
- columnHelper.accessor("product.title", {
11383
- header: "Product",
11384
- cell: ({ row }) => {
11385
- var _a, _b, _c;
11386
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
11387
- /* @__PURE__ */ jsx(
11388
- Thumbnail,
11389
- {
11390
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11391
- alt: (_b = row.original.product) == null ? void 0 : _b.title
11392
- }
11393
- ),
11394
- /* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11395
- ] });
11396
- },
11397
- enableSorting: true
11398
- }),
11399
- columnHelper.accessor("title", {
11400
- header: "Variant",
11401
- enableSorting: true
11402
- }),
11403
- columnHelper.accessor("sku", {
11404
- header: "SKU",
11405
- cell: ({ getValue }) => {
11406
- return getValue() ?? "-";
11407
- },
11408
- enableSorting: true
11409
- }),
11410
- columnHelper.accessor("updated_at", {
11411
- header: "Updated",
11412
- cell: ({ getValue }) => {
11413
- return /* @__PURE__ */ jsx(
11414
- Tooltip,
11415
- {
11416
- content: getFullDate({ date: getValue(), includeTime: true }),
11417
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11418
- }
11419
- );
11420
- },
11421
- enableSorting: true,
11422
- sortAscLabel: "Oldest first",
11423
- sortDescLabel: "Newest first"
11424
- }),
11425
- columnHelper.accessor("created_at", {
11426
- header: "Created",
11427
- cell: ({ getValue }) => {
11428
- return /* @__PURE__ */ jsx(
11429
- Tooltip,
11430
- {
11431
- content: getFullDate({ date: getValue(), includeTime: true }),
11432
- children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
11433
- }
11434
- );
11435
- },
11436
- enableSorting: true,
11437
- sortAscLabel: "Oldest first",
11438
- sortDescLabel: "Newest first"
11439
- })
11083
+ {
11084
+ key: "",
11085
+ value: "",
11086
+ disabled: false
11087
+ }
11440
11088
  ];
11441
- }, []);
11089
+ }
11090
+ return Object.entries(metadata).map(([key, value]) => {
11091
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11092
+ return {
11093
+ key,
11094
+ value,
11095
+ disabled: true
11096
+ };
11097
+ }
11098
+ let stringValue = value;
11099
+ if (typeof value !== "string") {
11100
+ stringValue = JSON.stringify(value);
11101
+ }
11102
+ return {
11103
+ key,
11104
+ value: stringValue,
11105
+ original_key: key
11106
+ };
11107
+ });
11108
+ }
11109
+ function parseValues(values) {
11110
+ const metadata = values.metadata;
11111
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11112
+ if (isEmpty) {
11113
+ return null;
11114
+ }
11115
+ const update = {};
11116
+ metadata.forEach((field) => {
11117
+ let key = field.key;
11118
+ let value = field.value;
11119
+ const disabled = field.disabled;
11120
+ if (!key || !value) {
11121
+ return;
11122
+ }
11123
+ if (disabled) {
11124
+ update[key] = value;
11125
+ return;
11126
+ }
11127
+ key = key.trim();
11128
+ value = value.trim();
11129
+ if (value === "true") {
11130
+ update[key] = true;
11131
+ } else if (value === "false") {
11132
+ update[key] = false;
11133
+ } else {
11134
+ const parsedNumber = parseFloat(value);
11135
+ if (!isNaN(parsedNumber)) {
11136
+ update[key] = parsedNumber;
11137
+ } else {
11138
+ update[key] = value;
11139
+ }
11140
+ }
11141
+ });
11142
+ return update;
11143
+ }
11144
+ function getHasUneditableRows(metadata) {
11145
+ if (!metadata) {
11146
+ return false;
11147
+ }
11148
+ return Object.values(metadata).some(
11149
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11150
+ );
11151
+ }
11152
+ const PROMOTION_QUERY_KEY = "promotions";
11153
+ const promotionsQueryKeys = {
11154
+ list: (query2) => [
11155
+ PROMOTION_QUERY_KEY,
11156
+ query2 ? query2 : void 0
11157
+ ],
11158
+ detail: (id, query2) => [
11159
+ PROMOTION_QUERY_KEY,
11160
+ id,
11161
+ query2 ? query2 : void 0
11162
+ ]
11442
11163
  };
11443
- const CustomItemForm = ({ orderId, currencyCode }) => {
11444
- const { setIsOpen } = useStackedModal();
11445
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11446
- const form = useForm({
11447
- defaultValues: {
11448
- title: "",
11449
- quantity: 1,
11450
- unit_price: ""
11164
+ const usePromotions = (query2, options) => {
11165
+ const { data, ...rest } = useQuery({
11166
+ queryKey: promotionsQueryKeys.list(query2),
11167
+ queryFn: async () => sdk.admin.promotion.list(query2),
11168
+ ...options
11169
+ });
11170
+ return { ...data, ...rest };
11171
+ };
11172
+ const Promotions = () => {
11173
+ const { id } = useParams();
11174
+ const {
11175
+ order: preview,
11176
+ isError: isPreviewError,
11177
+ error: previewError
11178
+ } = useOrderPreview(id, void 0);
11179
+ useInitiateOrderEdit({ preview });
11180
+ const { onCancel } = useCancelOrderEdit({ preview });
11181
+ if (isPreviewError) {
11182
+ throw previewError;
11183
+ }
11184
+ const isReady = !!preview;
11185
+ return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
11186
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
11187
+ isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
11188
+ ] });
11189
+ };
11190
+ const PromotionForm = ({ preview }) => {
11191
+ const { items, shipping_methods } = preview;
11192
+ const [isSubmitting, setIsSubmitting] = useState(false);
11193
+ const [comboboxValue, setComboboxValue] = useState("");
11194
+ const { handleSuccess } = useRouteModal();
11195
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11196
+ const promoIds = getPromotionIds(items, shipping_methods);
11197
+ const { promotions, isPending, isError, error } = usePromotions(
11198
+ {
11199
+ id: promoIds
11451
11200
  },
11452
- resolver: zodResolver(customItemSchema)
11201
+ {
11202
+ enabled: !!promoIds.length
11203
+ }
11204
+ );
11205
+ const comboboxData = useComboboxData({
11206
+ queryKey: ["promotions", "combobox", promoIds],
11207
+ queryFn: async (params) => {
11208
+ return await sdk.admin.promotion.list({
11209
+ ...params,
11210
+ id: {
11211
+ $nin: promoIds
11212
+ }
11213
+ });
11214
+ },
11215
+ getOptions: (data) => {
11216
+ return data.promotions.map((promotion) => ({
11217
+ label: promotion.code,
11218
+ value: promotion.code
11219
+ }));
11220
+ }
11453
11221
  });
11454
- const onSubmit = form.handleSubmit(async (data) => {
11455
- await addItems(
11222
+ const add = async (value) => {
11223
+ if (!value) {
11224
+ return;
11225
+ }
11226
+ addPromotions(
11456
11227
  {
11457
- items: [
11458
- {
11459
- title: data.title,
11460
- quantity: data.quantity,
11461
- unit_price: convertNumber(data.unit_price)
11462
- }
11463
- ]
11228
+ promo_codes: [value]
11464
11229
  },
11465
11230
  {
11466
- onSuccess: () => {
11467
- setIsOpen(STACKED_MODAL_ID, false);
11468
- },
11469
11231
  onError: (e) => {
11470
11232
  toast.error(e.message);
11233
+ comboboxData.onSearchValueChange("");
11234
+ setComboboxValue("");
11235
+ },
11236
+ onSuccess: () => {
11237
+ comboboxData.onSearchValueChange("");
11238
+ setComboboxValue("");
11471
11239
  }
11472
11240
  }
11473
11241
  );
11474
- });
11475
- return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
11476
- /* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
11477
- /* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
11478
- /* @__PURE__ */ jsxs("div", { children: [
11479
- /* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
11480
- /* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
11242
+ };
11243
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11244
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11245
+ const onSubmit = async () => {
11246
+ setIsSubmitting(true);
11247
+ let requestSucceeded = false;
11248
+ await requestOrderEdit(void 0, {
11249
+ onError: (e) => {
11250
+ toast.error(e.message);
11251
+ },
11252
+ onSuccess: () => {
11253
+ requestSucceeded = true;
11254
+ }
11255
+ });
11256
+ if (!requestSucceeded) {
11257
+ setIsSubmitting(false);
11258
+ return;
11259
+ }
11260
+ await confirmOrderEdit(void 0, {
11261
+ onError: (e) => {
11262
+ toast.error(e.message);
11263
+ },
11264
+ onSuccess: () => {
11265
+ handleSuccess();
11266
+ },
11267
+ onSettled: () => {
11268
+ setIsSubmitting(false);
11269
+ }
11270
+ });
11271
+ };
11272
+ if (isError) {
11273
+ throw error;
11274
+ }
11275
+ return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11276
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
11277
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
11278
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
11279
+ /* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11280
+ /* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11281
+ ] }),
11282
+ /* @__PURE__ */ jsx(
11283
+ Combobox,
11284
+ {
11285
+ id: "promotion-combobox",
11286
+ "aria-describedby": "promotion-combobox-hint",
11287
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11288
+ fetchNextPage: comboboxData.fetchNextPage,
11289
+ options: comboboxData.options,
11290
+ onSearchValueChange: comboboxData.onSearchValueChange,
11291
+ searchValue: comboboxData.searchValue,
11292
+ disabled: comboboxData.disabled || isAddingPromotions,
11293
+ onChange: add,
11294
+ value: comboboxValue
11295
+ }
11296
+ )
11481
11297
  ] }),
11482
11298
  /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11299
+ /* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
11300
+ PromotionItem,
11301
+ {
11302
+ promotion,
11303
+ orderId: preview.id,
11304
+ isLoading: isPending
11305
+ },
11306
+ promotion.id
11307
+ )) })
11308
+ ] }) }),
11309
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11310
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11483
11311
  /* @__PURE__ */ jsx(
11484
- Form$2.Field,
11312
+ Button,
11485
11313
  {
11486
- control: form.control,
11487
- name: "title",
11488
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11489
- /* @__PURE__ */ jsxs("div", { children: [
11490
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
11491
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
11492
- ] }),
11493
- /* @__PURE__ */ jsxs("div", { children: [
11494
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11495
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11496
- ] })
11497
- ] }) })
11314
+ size: "small",
11315
+ type: "submit",
11316
+ isLoading: isSubmitting || isAddingPromotions,
11317
+ children: "Save"
11498
11318
  }
11499
- ),
11500
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11501
- /* @__PURE__ */ jsx(
11502
- Form$2.Field,
11319
+ )
11320
+ ] }) })
11321
+ ] });
11322
+ };
11323
+ const PromotionItem = ({
11324
+ promotion,
11325
+ orderId,
11326
+ isLoading
11327
+ }) => {
11328
+ var _a;
11329
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11330
+ const onRemove = async () => {
11331
+ removePromotions(
11332
+ {
11333
+ promo_codes: [promotion.code]
11334
+ },
11335
+ {
11336
+ onError: (e) => {
11337
+ toast.error(e.message);
11338
+ }
11339
+ }
11340
+ );
11341
+ };
11342
+ const displayValue = getDisplayValue(promotion);
11343
+ return /* @__PURE__ */ jsxs(
11344
+ "div",
11345
+ {
11346
+ className: clx(
11347
+ "bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
11503
11348
  {
11504
- control: form.control,
11505
- name: "unit_price",
11506
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11507
- /* @__PURE__ */ jsxs("div", { children: [
11508
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
11509
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11510
- ] }),
11511
- /* @__PURE__ */ jsxs("div", { children: [
11512
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11513
- CurrencyInput,
11514
- {
11515
- symbol: getNativeSymbol(currencyCode),
11516
- code: currencyCode,
11517
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11518
- ...field
11519
- }
11520
- ) }),
11521
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11522
- ] })
11523
- ] }) })
11349
+ "animate-pulse": isLoading
11524
11350
  }
11525
11351
  ),
11526
- /* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
11527
- /* @__PURE__ */ jsx(
11528
- Form$2.Field,
11529
- {
11530
- control: form.control,
11531
- name: "quantity",
11532
- render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11533
- /* @__PURE__ */ jsxs("div", { children: [
11534
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
11535
- /* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11352
+ children: [
11353
+ /* @__PURE__ */ jsxs("div", { children: [
11354
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11355
+ /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
11356
+ displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
11357
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
11358
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
11536
11359
  ] }),
11537
- /* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
11538
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11539
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11540
- ] })
11541
- ] }) })
11542
- }
11543
- )
11544
- ] }) }) }),
11545
- /* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11546
- /* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11547
- /* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11548
- ] }) })
11549
- ] }) }) });
11360
+ /* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11361
+ ] })
11362
+ ] }),
11363
+ /* @__PURE__ */ jsx(
11364
+ IconButton,
11365
+ {
11366
+ size: "small",
11367
+ type: "button",
11368
+ variant: "transparent",
11369
+ onClick: onRemove,
11370
+ isLoading: isPending || isLoading,
11371
+ children: /* @__PURE__ */ jsx(XMark, {})
11372
+ }
11373
+ )
11374
+ ]
11375
+ },
11376
+ promotion.id
11377
+ );
11550
11378
  };
11551
- const customItemSchema = objectType({
11552
- title: stringType().min(1),
11553
- quantity: numberType(),
11554
- unit_price: unionType([numberType(), stringType()])
11379
+ function getDisplayValue(promotion) {
11380
+ var _a, _b, _c, _d;
11381
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11382
+ if (!value) {
11383
+ return null;
11384
+ }
11385
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11386
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11387
+ if (!currency) {
11388
+ return null;
11389
+ }
11390
+ return getLocaleAmount(value, currency);
11391
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11392
+ return formatPercentage(value);
11393
+ }
11394
+ return null;
11395
+ }
11396
+ const formatter = new Intl.NumberFormat([], {
11397
+ style: "percent",
11398
+ minimumFractionDigits: 2
11555
11399
  });
11556
- const ShippingAddress = () => {
11400
+ const formatPercentage = (value, isPercentageValue = false) => {
11401
+ let val = value || 0;
11402
+ if (!isPercentageValue) {
11403
+ val = val / 100;
11404
+ }
11405
+ return formatter.format(val);
11406
+ };
11407
+ function getPromotionIds(items, shippingMethods) {
11408
+ const promotionIds = /* @__PURE__ */ new Set();
11409
+ for (const item of items) {
11410
+ if (item.adjustments) {
11411
+ for (const adjustment of item.adjustments) {
11412
+ if (adjustment.promotion_id) {
11413
+ promotionIds.add(adjustment.promotion_id);
11414
+ }
11415
+ }
11416
+ }
11417
+ }
11418
+ for (const shippingMethod of shippingMethods) {
11419
+ if (shippingMethod.adjustments) {
11420
+ for (const adjustment of shippingMethod.adjustments) {
11421
+ if (adjustment.promotion_id) {
11422
+ promotionIds.add(adjustment.promotion_id);
11423
+ }
11424
+ }
11425
+ }
11426
+ }
11427
+ return Array.from(promotionIds);
11428
+ }
11429
+ const SalesChannel = () => {
11557
11430
  const { id } = useParams();
11558
- const { order, isPending, isError, error } = useOrder(id, {
11559
- fields: "+shipping_address"
11560
- });
11431
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11432
+ id,
11433
+ {
11434
+ fields: "+sales_channel_id"
11435
+ },
11436
+ {
11437
+ enabled: !!id
11438
+ }
11439
+ );
11561
11440
  if (isError) {
11562
11441
  throw error;
11563
11442
  }
11564
- const isReady = !isPending && !!order;
11443
+ const ISrEADY = !!draft_order && !isPending;
11565
11444
  return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
11566
11445
  /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
11567
- /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
11568
- /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11446
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
11447
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11569
11448
  ] }),
11570
- isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
11449
+ ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
11571
11450
  ] });
11572
11451
  };
11573
- const ShippingAddressForm = ({ order }) => {
11574
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11452
+ const SalesChannelForm = ({ order }) => {
11575
11453
  const form = useForm({
11576
11454
  defaultValues: {
11577
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11578
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11579
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11580
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11581
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11582
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11583
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11584
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11585
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11586
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11455
+ sales_channel_id: order.sales_channel_id || ""
11587
11456
  },
11588
- resolver: zodResolver(schema$1)
11457
+ resolver: zodResolver(schema$3)
11589
11458
  });
11590
11459
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11591
11460
  const { handleSuccess } = useRouteModal();
11592
11461
  const onSubmit = form.handleSubmit(async (data) => {
11593
11462
  await mutateAsync(
11594
11463
  {
11595
- shipping_address: {
11596
- first_name: data.first_name,
11597
- last_name: data.last_name,
11598
- company: data.company,
11599
- address_1: data.address_1,
11600
- address_2: data.address_2,
11601
- city: data.city,
11602
- province: data.province,
11603
- country_code: data.country_code,
11604
- postal_code: data.postal_code,
11605
- phone: data.phone
11606
- }
11464
+ sales_channel_id: data.sales_channel_id
11607
11465
  },
11608
11466
  {
11609
11467
  onSuccess: () => {
11468
+ toast.success("Sales channel updated");
11610
11469
  handleSuccess();
11611
11470
  },
11612
11471
  onError: (error) => {
@@ -11621,132 +11480,7 @@ const ShippingAddressForm = ({ order }) => {
11621
11480
  className: "flex flex-1 flex-col overflow-hidden",
11622
11481
  onSubmit,
11623
11482
  children: [
11624
- /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
11625
- /* @__PURE__ */ jsx(
11626
- Form$2.Field,
11627
- {
11628
- control: form.control,
11629
- name: "country_code",
11630
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11631
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
11632
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
11633
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11634
- ] })
11635
- }
11636
- ),
11637
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11638
- /* @__PURE__ */ jsx(
11639
- Form$2.Field,
11640
- {
11641
- control: form.control,
11642
- name: "first_name",
11643
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11644
- /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
11645
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11646
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11647
- ] })
11648
- }
11649
- ),
11650
- /* @__PURE__ */ jsx(
11651
- Form$2.Field,
11652
- {
11653
- control: form.control,
11654
- name: "last_name",
11655
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11656
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
11657
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11658
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11659
- ] })
11660
- }
11661
- )
11662
- ] }),
11663
- /* @__PURE__ */ jsx(
11664
- Form$2.Field,
11665
- {
11666
- control: form.control,
11667
- name: "company",
11668
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11669
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
11670
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11671
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11672
- ] })
11673
- }
11674
- ),
11675
- /* @__PURE__ */ jsx(
11676
- Form$2.Field,
11677
- {
11678
- control: form.control,
11679
- name: "address_1",
11680
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11681
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
11682
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11683
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11684
- ] })
11685
- }
11686
- ),
11687
- /* @__PURE__ */ jsx(
11688
- Form$2.Field,
11689
- {
11690
- control: form.control,
11691
- name: "address_2",
11692
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11693
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11694
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11695
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11696
- ] })
11697
- }
11698
- ),
11699
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11700
- /* @__PURE__ */ jsx(
11701
- Form$2.Field,
11702
- {
11703
- control: form.control,
11704
- name: "postal_code",
11705
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11706
- /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
11707
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11708
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11709
- ] })
11710
- }
11711
- ),
11712
- /* @__PURE__ */ jsx(
11713
- Form$2.Field,
11714
- {
11715
- control: form.control,
11716
- name: "city",
11717
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11718
- /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
11719
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11720
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11721
- ] })
11722
- }
11723
- )
11724
- ] }),
11725
- /* @__PURE__ */ jsx(
11726
- Form$2.Field,
11727
- {
11728
- control: form.control,
11729
- name: "province",
11730
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11731
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11732
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11733
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11734
- ] })
11735
- }
11736
- ),
11737
- /* @__PURE__ */ jsx(
11738
- Form$2.Field,
11739
- {
11740
- control: form.control,
11741
- name: "phone",
11742
- render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11743
- /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
11744
- /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
11745
- /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11746
- ] })
11747
- }
11748
- )
11749
- ] }) }),
11483
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
11750
11484
  /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
11751
11485
  /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11752
11486
  /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
@@ -11755,7 +11489,49 @@ const ShippingAddressForm = ({ order }) => {
11755
11489
  }
11756
11490
  ) });
11757
11491
  };
11758
- const schema$1 = addressSchema;
11492
+ const SalesChannelField = ({ control, order }) => {
11493
+ const salesChannels = useComboboxData({
11494
+ queryFn: async (params) => {
11495
+ return await sdk.admin.salesChannel.list(params);
11496
+ },
11497
+ queryKey: ["sales-channels"],
11498
+ getOptions: (data) => {
11499
+ return data.sales_channels.map((salesChannel) => ({
11500
+ label: salesChannel.name,
11501
+ value: salesChannel.id
11502
+ }));
11503
+ },
11504
+ defaultValue: order.sales_channel_id || void 0
11505
+ });
11506
+ return /* @__PURE__ */ jsx(
11507
+ Form$2.Field,
11508
+ {
11509
+ control,
11510
+ name: "sales_channel_id",
11511
+ render: ({ field }) => {
11512
+ return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
11513
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
11514
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
11515
+ Combobox,
11516
+ {
11517
+ options: salesChannels.options,
11518
+ fetchNextPage: salesChannels.fetchNextPage,
11519
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11520
+ searchValue: salesChannels.searchValue,
11521
+ onSearchValueChange: salesChannels.onSearchValueChange,
11522
+ placeholder: "Select sales channel",
11523
+ ...field
11524
+ }
11525
+ ) }),
11526
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
11527
+ ] });
11528
+ }
11529
+ }
11530
+ );
11531
+ };
11532
+ const schema$3 = objectType({
11533
+ sales_channel_id: stringType().min(1)
11534
+ });
11759
11535
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11760
11536
  const Shipping = () => {
11761
11537
  var _a;
@@ -12586,7 +12362,7 @@ const TransferOwnershipForm = ({ order }) => {
12586
12362
  defaultValues: {
12587
12363
  customer_id: order.customer_id || ""
12588
12364
  },
12589
- resolver: zodResolver(schema)
12365
+ resolver: zodResolver(schema$2)
12590
12366
  });
12591
12367
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12592
12368
  const { handleSuccess } = useRouteModal();
@@ -13036,9 +12812,233 @@ const Illustration = () => {
13036
12812
  }
13037
12813
  );
13038
12814
  };
13039
- const schema = objectType({
12815
+ const schema$2 = objectType({
13040
12816
  customer_id: stringType().min(1)
13041
12817
  });
12818
+ const ShippingAddress = () => {
12819
+ const { id } = useParams();
12820
+ const { order, isPending, isError, error } = useOrder(id, {
12821
+ fields: "+shipping_address"
12822
+ });
12823
+ if (isError) {
12824
+ throw error;
12825
+ }
12826
+ const isReady = !isPending && !!order;
12827
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
12828
+ /* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
12829
+ /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Shipping Address" }) }),
12830
+ /* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12831
+ ] }),
12832
+ isReady && /* @__PURE__ */ jsx(ShippingAddressForm, { order })
12833
+ ] });
12834
+ };
12835
+ const ShippingAddressForm = ({ order }) => {
12836
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12837
+ const form = useForm({
12838
+ defaultValues: {
12839
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12840
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12841
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12842
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12843
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12844
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12845
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12846
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12847
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12848
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12849
+ },
12850
+ resolver: zodResolver(schema$1)
12851
+ });
12852
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12853
+ const { handleSuccess } = useRouteModal();
12854
+ const onSubmit = form.handleSubmit(async (data) => {
12855
+ await mutateAsync(
12856
+ {
12857
+ shipping_address: {
12858
+ first_name: data.first_name,
12859
+ last_name: data.last_name,
12860
+ company: data.company,
12861
+ address_1: data.address_1,
12862
+ address_2: data.address_2,
12863
+ city: data.city,
12864
+ province: data.province,
12865
+ country_code: data.country_code,
12866
+ postal_code: data.postal_code,
12867
+ phone: data.phone
12868
+ }
12869
+ },
12870
+ {
12871
+ onSuccess: () => {
12872
+ handleSuccess();
12873
+ },
12874
+ onError: (error) => {
12875
+ toast.error(error.message);
12876
+ }
12877
+ }
12878
+ );
12879
+ });
12880
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
12881
+ KeyboundForm,
12882
+ {
12883
+ className: "flex flex-1 flex-col overflow-hidden",
12884
+ onSubmit,
12885
+ children: [
12886
+ /* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-4", children: [
12887
+ /* @__PURE__ */ jsx(
12888
+ Form$2.Field,
12889
+ {
12890
+ control: form.control,
12891
+ name: "country_code",
12892
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12893
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Country" }),
12894
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(CountrySelect, { ...field }) }),
12895
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12896
+ ] })
12897
+ }
12898
+ ),
12899
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12900
+ /* @__PURE__ */ jsx(
12901
+ Form$2.Field,
12902
+ {
12903
+ control: form.control,
12904
+ name: "first_name",
12905
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12906
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "First name" }),
12907
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12908
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12909
+ ] })
12910
+ }
12911
+ ),
12912
+ /* @__PURE__ */ jsx(
12913
+ Form$2.Field,
12914
+ {
12915
+ control: form.control,
12916
+ name: "last_name",
12917
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12918
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Last name" }),
12919
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12920
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12921
+ ] })
12922
+ }
12923
+ )
12924
+ ] }),
12925
+ /* @__PURE__ */ jsx(
12926
+ Form$2.Field,
12927
+ {
12928
+ control: form.control,
12929
+ name: "company",
12930
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12931
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Company" }),
12932
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12933
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12934
+ ] })
12935
+ }
12936
+ ),
12937
+ /* @__PURE__ */ jsx(
12938
+ Form$2.Field,
12939
+ {
12940
+ control: form.control,
12941
+ name: "address_1",
12942
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12943
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Address" }),
12944
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12945
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12946
+ ] })
12947
+ }
12948
+ ),
12949
+ /* @__PURE__ */ jsx(
12950
+ Form$2.Field,
12951
+ {
12952
+ control: form.control,
12953
+ name: "address_2",
12954
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12955
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12956
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12957
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12958
+ ] })
12959
+ }
12960
+ ),
12961
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12962
+ /* @__PURE__ */ jsx(
12963
+ Form$2.Field,
12964
+ {
12965
+ control: form.control,
12966
+ name: "postal_code",
12967
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12968
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "Postal code" }),
12969
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12970
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12971
+ ] })
12972
+ }
12973
+ ),
12974
+ /* @__PURE__ */ jsx(
12975
+ Form$2.Field,
12976
+ {
12977
+ control: form.control,
12978
+ name: "city",
12979
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12980
+ /* @__PURE__ */ jsx(Form$2.Label, { children: "City" }),
12981
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12982
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12983
+ ] })
12984
+ }
12985
+ )
12986
+ ] }),
12987
+ /* @__PURE__ */ jsx(
12988
+ Form$2.Field,
12989
+ {
12990
+ control: form.control,
12991
+ name: "province",
12992
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
12993
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12994
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
12995
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
12996
+ ] })
12997
+ }
12998
+ ),
12999
+ /* @__PURE__ */ jsx(
13000
+ Form$2.Field,
13001
+ {
13002
+ control: form.control,
13003
+ name: "phone",
13004
+ render: ({ field }) => /* @__PURE__ */ jsxs(Form$2.Item, { children: [
13005
+ /* @__PURE__ */ jsx(Form$2.Label, { optional: true, children: "Phone" }),
13006
+ /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
13007
+ /* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
13008
+ ] })
13009
+ }
13010
+ )
13011
+ ] }) }),
13012
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13013
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13014
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13015
+ ] }) })
13016
+ ]
13017
+ }
13018
+ ) });
13019
+ };
13020
+ const schema$1 = addressSchema;
13021
+ const CustomItems = () => {
13022
+ return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
13023
+ /* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
13024
+ /* @__PURE__ */ jsx(CustomItemsForm, {})
13025
+ ] });
13026
+ };
13027
+ const CustomItemsForm = () => {
13028
+ const form = useForm({
13029
+ resolver: zodResolver(schema)
13030
+ });
13031
+ return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
13032
+ /* @__PURE__ */ jsx(RouteDrawer.Body, {}),
13033
+ /* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
13034
+ /* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13035
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
13036
+ ] }) })
13037
+ ] }) });
13038
+ };
13039
+ const schema = objectType({
13040
+ email: stringType().email()
13041
+ });
13042
13042
  const widgetModule = { widgets: [] };
13043
13043
  const routeModule = {
13044
13044
  routes: [
@@ -13063,14 +13063,14 @@ const routeModule = {
13063
13063
  Component: BillingAddress,
13064
13064
  path: "/draft-orders/:id/billing-address"
13065
13065
  },
13066
- {
13067
- Component: CustomItems,
13068
- path: "/draft-orders/:id/custom-items"
13069
- },
13070
13066
  {
13071
13067
  Component: Email,
13072
13068
  path: "/draft-orders/:id/email"
13073
13069
  },
13070
+ {
13071
+ Component: Items,
13072
+ path: "/draft-orders/:id/items"
13073
+ },
13074
13074
  {
13075
13075
  Component: Metadata,
13076
13076
  path: "/draft-orders/:id/metadata"
@@ -13083,14 +13083,6 @@ const routeModule = {
13083
13083
  Component: SalesChannel,
13084
13084
  path: "/draft-orders/:id/sales-channel"
13085
13085
  },
13086
- {
13087
- Component: Items,
13088
- path: "/draft-orders/:id/items"
13089
- },
13090
- {
13091
- Component: ShippingAddress,
13092
- path: "/draft-orders/:id/shipping-address"
13093
- },
13094
13086
  {
13095
13087
  Component: Shipping,
13096
13088
  path: "/draft-orders/:id/shipping"
@@ -13098,6 +13090,14 @@ const routeModule = {
13098
13090
  {
13099
13091
  Component: TransferOwnership,
13100
13092
  path: "/draft-orders/:id/transfer-ownership"
13093
+ },
13094
+ {
13095
+ Component: ShippingAddress,
13096
+ path: "/draft-orders/:id/shipping-address"
13097
+ },
13098
+ {
13099
+ Component: CustomItems,
13100
+ path: "/draft-orders/:id/custom-items"
13101
13101
  }
13102
13102
  ]
13103
13103
  }