@medusajs/draft-order 2.11.4-preview-20251116210130 → 2.11.4-preview-20251117000309

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.
@@ -9851,795 +9851,604 @@ const EmailForm = ({ order }) => {
9851
9851
  const schema$3 = objectType({
9852
9852
  email: stringType().email()
9853
9853
  });
9854
- const InlineTip = React.forwardRef(
9855
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9856
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9854
+ const NumberInput = React.forwardRef(
9855
+ ({
9856
+ value,
9857
+ onChange,
9858
+ size = "base",
9859
+ min = 0,
9860
+ max = 100,
9861
+ step = 1,
9862
+ className,
9863
+ disabled,
9864
+ ...props
9865
+ }, ref) => {
9866
+ const handleChange = (event) => {
9867
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9868
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9869
+ onChange(newValue);
9870
+ }
9871
+ };
9872
+ const handleIncrement = () => {
9873
+ const newValue = value + step;
9874
+ if (max === void 0 || newValue <= max) {
9875
+ onChange(newValue);
9876
+ }
9877
+ };
9878
+ const handleDecrement = () => {
9879
+ const newValue = value - step;
9880
+ if (min === void 0 || newValue >= min) {
9881
+ onChange(newValue);
9882
+ }
9883
+ };
9857
9884
  return /* @__PURE__ */ jsxRuntime.jsxs(
9858
9885
  "div",
9859
9886
  {
9860
- ref,
9861
9887
  className: ui.clx(
9862
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9888
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9889
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9890
+ {
9891
+ "h-7": size === "small",
9892
+ "h-8": size === "base"
9893
+ },
9863
9894
  className
9864
9895
  ),
9865
- ...props,
9866
9896
  children: [
9867
9897
  /* @__PURE__ */ jsxRuntime.jsx(
9868
- "div",
9898
+ "input",
9869
9899
  {
9870
- role: "presentation",
9871
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9872
- "bg-ui-tag-orange-icon": variant === "warning"
9873
- })
9900
+ ref,
9901
+ type: "number",
9902
+ value,
9903
+ onChange: handleChange,
9904
+ min,
9905
+ max,
9906
+ step,
9907
+ className: ui.clx(
9908
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9909
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9910
+ "placeholder:text-ui-fg-muted"
9911
+ ),
9912
+ ...props
9874
9913
  }
9875
9914
  ),
9876
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9877
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9878
- labelValue,
9879
- ":"
9880
- ] }),
9881
- " ",
9882
- children
9883
- ] })
9915
+ /* @__PURE__ */ jsxRuntime.jsxs(
9916
+ "button",
9917
+ {
9918
+ className: ui.clx(
9919
+ "flex items-center justify-center outline-none transition-fg",
9920
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9921
+ "focus:bg-ui-bg-field-component-hover",
9922
+ "hover:bg-ui-bg-field-component-hover",
9923
+ {
9924
+ "size-7": size === "small",
9925
+ "size-8": size === "base"
9926
+ }
9927
+ ),
9928
+ type: "button",
9929
+ onClick: handleDecrement,
9930
+ disabled: min !== void 0 && value <= min || disabled,
9931
+ children: [
9932
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9933
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9934
+ ]
9935
+ }
9936
+ ),
9937
+ /* @__PURE__ */ jsxRuntime.jsxs(
9938
+ "button",
9939
+ {
9940
+ className: ui.clx(
9941
+ "flex items-center justify-center outline-none transition-fg",
9942
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9943
+ "focus:bg-ui-bg-field-hover",
9944
+ "hover:bg-ui-bg-field-hover",
9945
+ {
9946
+ "size-7": size === "small",
9947
+ "size-8": size === "base"
9948
+ }
9949
+ ),
9950
+ type: "button",
9951
+ onClick: handleIncrement,
9952
+ disabled: max !== void 0 && value >= max || disabled,
9953
+ children: [
9954
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9955
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9956
+ ]
9957
+ }
9958
+ )
9884
9959
  ]
9885
9960
  }
9886
9961
  );
9887
9962
  }
9888
9963
  );
9889
- InlineTip.displayName = "InlineTip";
9890
- const MetadataFieldSchema = objectType({
9891
- key: stringType(),
9892
- disabled: booleanType().optional(),
9893
- value: anyType()
9894
- });
9895
- const MetadataSchema = objectType({
9896
- metadata: arrayType(MetadataFieldSchema)
9897
- });
9898
- const Metadata = () => {
9964
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9965
+ const productVariantsQueryKeys = {
9966
+ list: (query2) => [
9967
+ PRODUCT_VARIANTS_QUERY_KEY,
9968
+ query2 ? query2 : void 0
9969
+ ]
9970
+ };
9971
+ const useProductVariants = (query2, options) => {
9972
+ const { data, ...rest } = reactQuery.useQuery({
9973
+ queryKey: productVariantsQueryKeys.list(query2),
9974
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9975
+ ...options
9976
+ });
9977
+ return { ...data, ...rest };
9978
+ };
9979
+ const useCancelOrderEdit = ({ preview }) => {
9980
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9981
+ const onCancel = React.useCallback(async () => {
9982
+ if (!preview) {
9983
+ return true;
9984
+ }
9985
+ let res = false;
9986
+ await cancelOrderEdit(void 0, {
9987
+ onError: (e) => {
9988
+ ui.toast.error(e.message);
9989
+ },
9990
+ onSuccess: () => {
9991
+ res = true;
9992
+ }
9993
+ });
9994
+ return res;
9995
+ }, [preview, cancelOrderEdit]);
9996
+ return { onCancel };
9997
+ };
9998
+ let IS_REQUEST_RUNNING = false;
9999
+ const useInitiateOrderEdit = ({
10000
+ preview
10001
+ }) => {
10002
+ const navigate = reactRouterDom.useNavigate();
10003
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10004
+ React.useEffect(() => {
10005
+ async function run() {
10006
+ if (IS_REQUEST_RUNNING || !preview) {
10007
+ return;
10008
+ }
10009
+ if (preview.order_change) {
10010
+ return;
10011
+ }
10012
+ IS_REQUEST_RUNNING = true;
10013
+ await mutateAsync(void 0, {
10014
+ onError: (e) => {
10015
+ ui.toast.error(e.message);
10016
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10017
+ return;
10018
+ }
10019
+ });
10020
+ IS_REQUEST_RUNNING = false;
10021
+ }
10022
+ run();
10023
+ }, [preview, navigate, mutateAsync]);
10024
+ };
10025
+ function convertNumber(value) {
10026
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10027
+ }
10028
+ const STACKED_MODAL_ID = "items_stacked_modal";
10029
+ const Items = () => {
9899
10030
  const { id } = reactRouterDom.useParams();
9900
- const { order, isPending, isError, error } = useOrder(id, {
9901
- fields: "metadata"
10031
+ const {
10032
+ order: preview,
10033
+ isPending: isPreviewPending,
10034
+ isError: isPreviewError,
10035
+ error: previewError
10036
+ } = useOrderPreview(id, void 0, {
10037
+ placeholderData: reactQuery.keepPreviousData
9902
10038
  });
10039
+ useInitiateOrderEdit({ preview });
10040
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10041
+ id,
10042
+ {
10043
+ fields: "currency_code"
10044
+ },
10045
+ {
10046
+ enabled: !!id
10047
+ }
10048
+ );
10049
+ const { onCancel } = useCancelOrderEdit({ preview });
9903
10050
  if (isError) {
9904
10051
  throw error;
9905
10052
  }
9906
- const isReady = !isPending && !!order;
9907
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9908
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9909
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9910
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9911
- ] }),
9912
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9913
- ] });
10053
+ if (isPreviewError) {
10054
+ throw previewError;
10055
+ }
10056
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10057
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10058
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10059
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10060
+ ] }) });
9914
10061
  };
9915
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9916
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9917
- const MetadataForm = ({ orderId, metadata }) => {
10062
+ const ItemsForm = ({ preview, currencyCode }) => {
10063
+ var _a;
10064
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10065
+ const [modalContent, setModalContent] = React.useState(
10066
+ null
10067
+ );
9918
10068
  const { handleSuccess } = useRouteModal();
9919
- const hasUneditableRows = getHasUneditableRows(metadata);
9920
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9921
- const form = reactHookForm.useForm({
9922
- defaultValues: {
9923
- metadata: getDefaultValues(metadata)
9924
- },
9925
- resolver: zod.zodResolver(MetadataSchema)
9926
- });
9927
- const handleSubmit = form.handleSubmit(async (data) => {
9928
- const parsedData = parseValues(data);
9929
- await mutateAsync(
9930
- {
9931
- metadata: parsedData
9932
- },
9933
- {
9934
- onSuccess: () => {
9935
- ui.toast.success("Metadata updated");
9936
- handleSuccess();
9937
- },
9938
- onError: (error) => {
9939
- ui.toast.error(error.message);
9940
- }
10069
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10070
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10071
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10072
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10073
+ const matches = React.useMemo(() => {
10074
+ return matchSorter.matchSorter(preview.items, query2, {
10075
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10076
+ });
10077
+ }, [preview.items, query2]);
10078
+ const onSubmit = async () => {
10079
+ setIsSubmitting(true);
10080
+ let requestSucceeded = false;
10081
+ await requestOrderEdit(void 0, {
10082
+ onError: (e) => {
10083
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10084
+ },
10085
+ onSuccess: () => {
10086
+ requestSucceeded = true;
9941
10087
  }
9942
- );
9943
- });
9944
- const { fields, insert, remove } = reactHookForm.useFieldArray({
9945
- control: form.control,
9946
- name: "metadata"
9947
- });
9948
- function deleteRow(index) {
9949
- remove(index);
9950
- if (fields.length === 1) {
9951
- insert(0, {
9952
- key: "",
9953
- value: "",
9954
- disabled: false
9955
- });
10088
+ });
10089
+ if (!requestSucceeded) {
10090
+ setIsSubmitting(false);
10091
+ return;
9956
10092
  }
9957
- }
9958
- function insertRow(index, position) {
9959
- insert(index + (position === "above" ? 0 : 1), {
9960
- key: "",
9961
- value: "",
9962
- disabled: false
10093
+ await confirmOrderEdit(void 0, {
10094
+ onError: (e) => {
10095
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10096
+ },
10097
+ onSuccess: () => {
10098
+ handleSuccess();
10099
+ },
10100
+ onSettled: () => {
10101
+ setIsSubmitting(false);
10102
+ }
9963
10103
  });
9964
- }
9965
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9966
- KeyboundForm,
9967
- {
9968
- onSubmit: handleSubmit,
9969
- className: "flex flex-1 flex-col overflow-hidden",
9970
- children: [
9971
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9973
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9974
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9975
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10104
+ };
10105
+ const onKeyDown = React.useCallback(
10106
+ (e) => {
10107
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10108
+ if (modalContent || isSubmitting) {
10109
+ return;
10110
+ }
10111
+ onSubmit();
10112
+ }
10113
+ },
10114
+ [modalContent, isSubmitting, onSubmit]
10115
+ );
10116
+ React.useEffect(() => {
10117
+ document.addEventListener("keydown", onKeyDown);
10118
+ return () => {
10119
+ document.removeEventListener("keydown", onKeyDown);
10120
+ };
10121
+ }, [onKeyDown]);
10122
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10123
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10124
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10125
+ StackedFocusModal,
10126
+ {
10127
+ id: STACKED_MODAL_ID,
10128
+ onOpenChangeCallback: (open) => {
10129
+ if (!open) {
10130
+ setModalContent(null);
10131
+ }
10132
+ },
10133
+ children: [
10134
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10135
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10136
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10137
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
9976
10138
  ] }),
9977
- fields.map((field, index) => {
9978
- const isDisabled = field.disabled || false;
9979
- let placeholder = "-";
9980
- if (typeof field.value === "object") {
9981
- placeholder = "{ ... }";
9982
- }
9983
- if (Array.isArray(field.value)) {
9984
- placeholder = "[ ... ]";
9985
- }
9986
- return /* @__PURE__ */ jsxRuntime.jsx(
9987
- ConditionalTooltip,
9988
- {
9989
- showTooltip: isDisabled,
9990
- content: "This row is disabled because it contains non-primitive data.",
9991
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9992
- /* @__PURE__ */ jsxRuntime.jsxs(
9993
- "div",
9994
- {
9995
- className: ui.clx("grid grid-cols-2 divide-x", {
9996
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9997
- }),
9998
- children: [
9999
- /* @__PURE__ */ jsxRuntime.jsx(
10000
- Form$2.Field,
10001
- {
10002
- control: form.control,
10003
- name: `metadata.${index}.key`,
10004
- render: ({ field: field2 }) => {
10005
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10006
- GridInput,
10007
- {
10008
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10009
- ...field2,
10010
- disabled: isDisabled,
10011
- placeholder: "Key"
10012
- }
10013
- ) }) });
10014
- }
10015
- }
10016
- ),
10017
- /* @__PURE__ */ jsxRuntime.jsx(
10018
- Form$2.Field,
10019
- {
10020
- control: form.control,
10021
- name: `metadata.${index}.value`,
10022
- render: ({ field: { value, ...field2 } }) => {
10023
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10024
- GridInput,
10025
- {
10026
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10027
- ...field2,
10028
- value: isDisabled ? placeholder : value,
10029
- disabled: isDisabled,
10030
- placeholder: "Value"
10031
- }
10032
- ) }) });
10033
- }
10034
- }
10035
- )
10036
- ]
10037
- }
10038
- ),
10039
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10139
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10140
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10141
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10142
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10143
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10144
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10145
+ ] }),
10146
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10147
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10148
+ ui.Input,
10149
+ {
10150
+ type: "search",
10151
+ placeholder: "Search items",
10152
+ value: searchValue,
10153
+ onChange: (e) => onSearchValueChange(e.target.value)
10154
+ }
10155
+ ) }),
10156
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10157
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10158
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10040
10159
  /* @__PURE__ */ jsxRuntime.jsx(
10041
- ui.DropdownMenu.Trigger,
10160
+ StackedModalTrigger$1,
10042
10161
  {
10043
- className: ui.clx(
10044
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10045
- {
10046
- hidden: isDisabled
10047
- }
10048
- ),
10049
- disabled: isDisabled,
10050
- asChild: true,
10051
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10162
+ type: "add-items",
10163
+ setModalContent
10052
10164
  }
10053
10165
  ),
10054
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10055
- /* @__PURE__ */ jsxRuntime.jsxs(
10056
- ui.DropdownMenu.Item,
10057
- {
10058
- className: "gap-x-2",
10059
- onClick: () => insertRow(index, "above"),
10060
- children: [
10061
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10062
- "Insert row above"
10063
- ]
10064
- }
10065
- ),
10066
- /* @__PURE__ */ jsxRuntime.jsxs(
10067
- ui.DropdownMenu.Item,
10068
- {
10069
- className: "gap-x-2",
10070
- onClick: () => insertRow(index, "below"),
10071
- children: [
10072
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10073
- "Insert row below"
10074
- ]
10075
- }
10076
- ),
10077
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10078
- /* @__PURE__ */ jsxRuntime.jsxs(
10079
- ui.DropdownMenu.Item,
10080
- {
10081
- className: "gap-x-2",
10082
- onClick: () => deleteRow(index),
10083
- children: [
10084
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10085
- "Delete row"
10086
- ]
10087
- }
10088
- )
10089
- ] })
10166
+ /* @__PURE__ */ jsxRuntime.jsx(
10167
+ StackedModalTrigger$1,
10168
+ {
10169
+ type: "add-custom-item",
10170
+ setModalContent
10171
+ }
10172
+ )
10090
10173
  ] })
10091
10174
  ] })
10092
- },
10093
- field.id
10094
- );
10095
- })
10096
- ] }),
10097
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10098
- ] }),
10099
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10100
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10102
- ] }) })
10103
- ]
10104
- }
10105
- ) });
10106
- };
10107
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10108
- return /* @__PURE__ */ jsxRuntime.jsx(
10109
- "input",
10110
- {
10111
- ref,
10112
- ...props,
10113
- autoComplete: "off",
10114
- className: ui.clx(
10115
- "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",
10116
- className
10175
+ ] })
10176
+ ] }),
10177
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10178
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10179
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10180
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10181
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10182
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
10183
+ ] }) }),
10184
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10185
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10186
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10187
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10188
+ Item,
10189
+ {
10190
+ item,
10191
+ preview,
10192
+ currencyCode
10193
+ },
10194
+ item.id
10195
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10196
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10197
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10198
+ 'No items found for "',
10199
+ query2,
10200
+ '".'
10201
+ ] })
10202
+ ] }) })
10203
+ ] })
10204
+ ] }),
10205
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10206
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10207
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10208
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10209
+ ui.Text,
10210
+ {
10211
+ size: "small",
10212
+ leading: "compact",
10213
+ className: "text-ui-fg-subtle",
10214
+ children: [
10215
+ itemCount,
10216
+ " ",
10217
+ itemCount === 1 ? "item" : "items"
10218
+ ]
10219
+ }
10220
+ ) }),
10221
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10222
+ ] })
10223
+ ] }) }),
10224
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10225
+ CustomItemForm,
10226
+ {
10227
+ orderId: preview.id,
10228
+ currencyCode
10229
+ }
10230
+ ) : null)
10231
+ ]
10232
+ }
10233
+ ) }),
10234
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10235
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10236
+ /* @__PURE__ */ jsxRuntime.jsx(
10237
+ ui.Button,
10238
+ {
10239
+ size: "small",
10240
+ type: "button",
10241
+ onClick: onSubmit,
10242
+ isLoading: isSubmitting,
10243
+ children: "Save"
10244
+ }
10117
10245
  )
10118
- }
10119
- );
10120
- });
10121
- GridInput.displayName = "MetadataForm.GridInput";
10122
- const PlaceholderInner = () => {
10123
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10124
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10125
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10126
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10127
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10128
10246
  ] }) })
10129
10247
  ] });
10130
10248
  };
10131
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10132
- function getDefaultValues(metadata) {
10133
- if (!metadata || !Object.keys(metadata).length) {
10134
- return [
10135
- {
10136
- key: "",
10137
- value: "",
10138
- disabled: false
10139
- }
10140
- ];
10249
+ const Item = ({ item, preview, currencyCode }) => {
10250
+ if (item.variant_id) {
10251
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10141
10252
  }
10142
- return Object.entries(metadata).map(([key, value]) => {
10143
- if (!EDITABLE_TYPES.includes(typeof value)) {
10144
- return {
10145
- key,
10146
- value,
10147
- disabled: true
10148
- };
10149
- }
10150
- let stringValue = value;
10151
- if (typeof value !== "string") {
10152
- stringValue = JSON.stringify(value);
10153
- }
10154
- return {
10155
- key,
10156
- value: stringValue,
10157
- original_key: key
10158
- };
10253
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10254
+ };
10255
+ const VariantItem = ({ item, preview, currencyCode }) => {
10256
+ const [editing, setEditing] = React.useState(false);
10257
+ const form = reactHookForm.useForm({
10258
+ defaultValues: {
10259
+ quantity: item.quantity,
10260
+ unit_price: item.unit_price
10261
+ },
10262
+ resolver: zod.zodResolver(variantItemSchema)
10159
10263
  });
10160
- }
10161
- function parseValues(values) {
10162
- const metadata = values.metadata;
10163
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10164
- if (isEmpty) {
10165
- return null;
10166
- }
10167
- const update = {};
10168
- metadata.forEach((field) => {
10169
- let key = field.key;
10170
- let value = field.value;
10171
- const disabled = field.disabled;
10172
- if (!key || !value) {
10264
+ const actionId = React.useMemo(() => {
10265
+ var _a, _b;
10266
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10267
+ }, [item]);
10268
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10269
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10270
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10271
+ const onSubmit = form.handleSubmit(async (data) => {
10272
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10273
+ setEditing(false);
10173
10274
  return;
10174
10275
  }
10175
- if (disabled) {
10176
- update[key] = value;
10276
+ if (!actionId) {
10277
+ await updateOriginalItem(
10278
+ {
10279
+ item_id: item.id,
10280
+ quantity: data.quantity,
10281
+ unit_price: convertNumber(data.unit_price)
10282
+ },
10283
+ {
10284
+ onSuccess: () => {
10285
+ setEditing(false);
10286
+ },
10287
+ onError: (e) => {
10288
+ ui.toast.error(e.message);
10289
+ }
10290
+ }
10291
+ );
10177
10292
  return;
10178
10293
  }
10179
- key = key.trim();
10180
- value = value.trim();
10181
- if (value === "true") {
10182
- update[key] = true;
10183
- } else if (value === "false") {
10184
- update[key] = false;
10185
- } else {
10186
- const parsedNumber = parseFloat(value);
10187
- if (!isNaN(parsedNumber)) {
10188
- update[key] = parsedNumber;
10189
- } else {
10190
- update[key] = value;
10294
+ await updateActionItem(
10295
+ {
10296
+ action_id: actionId,
10297
+ quantity: data.quantity,
10298
+ unit_price: convertNumber(data.unit_price)
10299
+ },
10300
+ {
10301
+ onSuccess: () => {
10302
+ setEditing(false);
10303
+ },
10304
+ onError: (e) => {
10305
+ ui.toast.error(e.message);
10306
+ }
10191
10307
  }
10192
- }
10308
+ );
10193
10309
  });
10194
- return update;
10195
- }
10196
- function getHasUneditableRows(metadata) {
10197
- if (!metadata) {
10198
- return false;
10199
- }
10200
- return Object.values(metadata).some(
10201
- (value) => !EDITABLE_TYPES.includes(typeof value)
10202
- );
10203
- }
10204
- const NumberInput = React.forwardRef(
10205
- ({
10206
- value,
10207
- onChange,
10208
- size = "base",
10209
- min = 0,
10210
- max = 100,
10211
- step = 1,
10212
- className,
10213
- disabled,
10214
- ...props
10215
- }, ref) => {
10216
- const handleChange = (event) => {
10217
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10218
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10219
- onChange(newValue);
10220
- }
10221
- };
10222
- const handleIncrement = () => {
10223
- const newValue = value + step;
10224
- if (max === void 0 || newValue <= max) {
10225
- onChange(newValue);
10226
- }
10227
- };
10228
- const handleDecrement = () => {
10229
- const newValue = value - step;
10230
- if (min === void 0 || newValue >= min) {
10231
- onChange(newValue);
10232
- }
10233
- };
10234
- return /* @__PURE__ */ jsxRuntime.jsxs(
10235
- "div",
10236
- {
10237
- className: ui.clx(
10238
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10239
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10240
- {
10241
- "h-7": size === "small",
10242
- "h-8": size === "base"
10243
- },
10244
- className
10245
- ),
10246
- children: [
10247
- /* @__PURE__ */ jsxRuntime.jsx(
10248
- "input",
10249
- {
10250
- ref,
10251
- type: "number",
10252
- value,
10253
- onChange: handleChange,
10254
- min,
10255
- max,
10256
- step,
10257
- className: ui.clx(
10258
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10259
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10260
- "placeholder:text-ui-fg-muted"
10261
- ),
10262
- ...props
10263
- }
10264
- ),
10310
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.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: [
10311
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10312
+ /* @__PURE__ */ jsxRuntime.jsx(
10313
+ Thumbnail,
10314
+ {
10315
+ thumbnail: item.thumbnail,
10316
+ alt: item.product_title ?? void 0
10317
+ }
10318
+ ),
10319
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10320
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10321
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10265
10322
  /* @__PURE__ */ jsxRuntime.jsxs(
10266
- "button",
10323
+ ui.Text,
10267
10324
  {
10268
- className: ui.clx(
10269
- "flex items-center justify-center outline-none transition-fg",
10270
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10271
- "focus:bg-ui-bg-field-component-hover",
10272
- "hover:bg-ui-bg-field-component-hover",
10273
- {
10274
- "size-7": size === "small",
10275
- "size-8": size === "base"
10276
- }
10277
- ),
10278
- type: "button",
10279
- onClick: handleDecrement,
10280
- disabled: min !== void 0 && value <= min || disabled,
10325
+ size: "small",
10326
+ leading: "compact",
10327
+ className: "text-ui-fg-subtle",
10281
10328
  children: [
10282
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10283
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10329
+ "(",
10330
+ item.variant_title,
10331
+ ")"
10284
10332
  ]
10285
10333
  }
10286
- ),
10287
- /* @__PURE__ */ jsxRuntime.jsxs(
10288
- "button",
10334
+ )
10335
+ ] }),
10336
+ /* @__PURE__ */ jsxRuntime.jsx(
10337
+ ui.Text,
10338
+ {
10339
+ size: "small",
10340
+ leading: "compact",
10341
+ className: "text-ui-fg-subtle",
10342
+ children: item.variant_sku
10343
+ }
10344
+ )
10345
+ ] })
10346
+ ] }),
10347
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10348
+ Form$2.Field,
10349
+ {
10350
+ control: form.control,
10351
+ name: "quantity",
10352
+ render: ({ field }) => {
10353
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10354
+ }
10355
+ }
10356
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10357
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10358
+ Form$2.Field,
10359
+ {
10360
+ control: form.control,
10361
+ name: "unit_price",
10362
+ render: ({ field: { onChange, ...field } }) => {
10363
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10364
+ ui.CurrencyInput,
10289
10365
  {
10290
- className: ui.clx(
10291
- "flex items-center justify-center outline-none transition-fg",
10292
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10293
- "focus:bg-ui-bg-field-hover",
10294
- "hover:bg-ui-bg-field-hover",
10295
- {
10296
- "size-7": size === "small",
10297
- "size-8": size === "base"
10298
- }
10299
- ),
10300
- type: "button",
10301
- onClick: handleIncrement,
10302
- disabled: max !== void 0 && value >= max || disabled,
10303
- children: [
10304
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10305
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10306
- ]
10366
+ ...field,
10367
+ symbol: getNativeSymbol(currencyCode),
10368
+ code: currencyCode,
10369
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10307
10370
  }
10308
- )
10309
- ]
10371
+ ) }) });
10372
+ }
10310
10373
  }
10311
- );
10312
- }
10313
- );
10314
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10315
- const productVariantsQueryKeys = {
10316
- list: (query2) => [
10317
- PRODUCT_VARIANTS_QUERY_KEY,
10318
- query2 ? query2 : void 0
10319
- ]
10320
- };
10321
- const useProductVariants = (query2, options) => {
10322
- const { data, ...rest } = reactQuery.useQuery({
10323
- queryKey: productVariantsQueryKeys.list(query2),
10324
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10325
- ...options
10326
- });
10327
- return { ...data, ...rest };
10328
- };
10329
- const useCancelOrderEdit = ({ preview }) => {
10330
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10331
- const onCancel = React.useCallback(async () => {
10332
- if (!preview) {
10333
- return true;
10334
- }
10335
- let res = false;
10336
- await cancelOrderEdit(void 0, {
10337
- onError: (e) => {
10338
- ui.toast.error(e.message);
10339
- },
10340
- onSuccess: () => {
10341
- res = true;
10374
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10375
+ /* @__PURE__ */ jsxRuntime.jsx(
10376
+ ui.IconButton,
10377
+ {
10378
+ type: "button",
10379
+ size: "small",
10380
+ onClick: editing ? onSubmit : () => {
10381
+ setEditing(true);
10382
+ },
10383
+ disabled: isPending,
10384
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10342
10385
  }
10343
- });
10344
- return res;
10345
- }, [preview, cancelOrderEdit]);
10346
- return { onCancel };
10386
+ )
10387
+ ] }) }) });
10347
10388
  };
10348
- let IS_REQUEST_RUNNING = false;
10349
- const useInitiateOrderEdit = ({
10350
- preview
10351
- }) => {
10352
- const navigate = reactRouterDom.useNavigate();
10353
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10389
+ const variantItemSchema = objectType({
10390
+ quantity: numberType(),
10391
+ unit_price: unionType([numberType(), stringType()])
10392
+ });
10393
+ const CustomItem = ({ item, preview, currencyCode }) => {
10394
+ const [editing, setEditing] = React.useState(false);
10395
+ const { quantity, unit_price, title } = item;
10396
+ const form = reactHookForm.useForm({
10397
+ defaultValues: {
10398
+ title,
10399
+ quantity,
10400
+ unit_price
10401
+ },
10402
+ resolver: zod.zodResolver(customItemSchema)
10403
+ });
10354
10404
  React.useEffect(() => {
10355
- async function run() {
10356
- if (IS_REQUEST_RUNNING || !preview) {
10357
- return;
10358
- }
10359
- if (preview.order_change) {
10360
- return;
10361
- }
10362
- IS_REQUEST_RUNNING = true;
10363
- await mutateAsync(void 0, {
10405
+ form.reset({
10406
+ title,
10407
+ quantity,
10408
+ unit_price
10409
+ });
10410
+ }, [form, title, quantity, unit_price]);
10411
+ const actionId = React.useMemo(() => {
10412
+ var _a, _b;
10413
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10414
+ }, [item]);
10415
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10416
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10417
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10418
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10419
+ const onSubmit = form.handleSubmit(async (data) => {
10420
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10421
+ setEditing(false);
10422
+ return;
10423
+ }
10424
+ if (!actionId) {
10425
+ await updateOriginalItem(
10426
+ {
10427
+ item_id: item.id,
10428
+ quantity: data.quantity,
10429
+ unit_price: convertNumber(data.unit_price)
10430
+ },
10431
+ {
10432
+ onSuccess: () => {
10433
+ setEditing(false);
10434
+ },
10435
+ onError: (e) => {
10436
+ ui.toast.error(e.message);
10437
+ }
10438
+ }
10439
+ );
10440
+ return;
10441
+ }
10442
+ if (data.quantity === 0) {
10443
+ await removeActionItem(actionId, {
10444
+ onSuccess: () => {
10445
+ setEditing(false);
10446
+ },
10364
10447
  onError: (e) => {
10365
10448
  ui.toast.error(e.message);
10366
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10367
- return;
10368
10449
  }
10369
10450
  });
10370
- IS_REQUEST_RUNNING = false;
10371
- }
10372
- run();
10373
- }, [preview, navigate, mutateAsync]);
10374
- };
10375
- function convertNumber(value) {
10376
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10377
- }
10378
- const STACKED_MODAL_ID = "items_stacked_modal";
10379
- const Items = () => {
10380
- const { id } = reactRouterDom.useParams();
10381
- const {
10382
- order: preview,
10383
- isPending: isPreviewPending,
10384
- isError: isPreviewError,
10385
- error: previewError
10386
- } = useOrderPreview(id, void 0, {
10387
- placeholderData: reactQuery.keepPreviousData
10388
- });
10389
- useInitiateOrderEdit({ preview });
10390
- const { draft_order, isPending, isError, error } = useDraftOrder(
10391
- id,
10392
- {
10393
- fields: "currency_code"
10394
- },
10395
- {
10396
- enabled: !!id
10397
- }
10398
- );
10399
- const { onCancel } = useCancelOrderEdit({ preview });
10400
- if (isError) {
10401
- throw error;
10402
- }
10403
- if (isPreviewError) {
10404
- throw previewError;
10405
- }
10406
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10407
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10408
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10409
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10410
- ] }) });
10411
- };
10412
- const ItemsForm = ({ preview, currencyCode }) => {
10413
- var _a;
10414
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10415
- const [modalContent, setModalContent] = React.useState(
10416
- null
10417
- );
10418
- const { handleSuccess } = useRouteModal();
10419
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10420
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10421
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10422
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10423
- const matches = React.useMemo(() => {
10424
- return matchSorter.matchSorter(preview.items, query2, {
10425
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10426
- });
10427
- }, [preview.items, query2]);
10428
- const onSubmit = async () => {
10429
- setIsSubmitting(true);
10430
- let requestSucceeded = false;
10431
- await requestOrderEdit(void 0, {
10432
- onError: (e) => {
10433
- ui.toast.error(`Failed to request order edit: ${e.message}`);
10434
- },
10435
- onSuccess: () => {
10436
- requestSucceeded = true;
10437
- }
10438
- });
10439
- if (!requestSucceeded) {
10440
- setIsSubmitting(false);
10441
- return;
10442
- }
10443
- await confirmOrderEdit(void 0, {
10444
- onError: (e) => {
10445
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10446
- },
10447
- onSuccess: () => {
10448
- handleSuccess();
10449
- },
10450
- onSettled: () => {
10451
- setIsSubmitting(false);
10452
- }
10453
- });
10454
- };
10455
- const onKeyDown = React.useCallback(
10456
- (e) => {
10457
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10458
- if (modalContent || isSubmitting) {
10459
- return;
10460
- }
10461
- onSubmit();
10462
- }
10463
- },
10464
- [modalContent, isSubmitting, onSubmit]
10465
- );
10466
- React.useEffect(() => {
10467
- document.addEventListener("keydown", onKeyDown);
10468
- return () => {
10469
- document.removeEventListener("keydown", onKeyDown);
10470
- };
10471
- }, [onKeyDown]);
10472
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10473
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10474
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10475
- StackedFocusModal,
10476
- {
10477
- id: STACKED_MODAL_ID,
10478
- onOpenChangeCallback: (open) => {
10479
- if (!open) {
10480
- setModalContent(null);
10481
- }
10482
- },
10483
- children: [
10484
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
10485
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10486
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10487
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
10488
- ] }),
10489
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10490
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10491
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10492
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10493
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10494
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10495
- ] }),
10496
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10497
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10498
- ui.Input,
10499
- {
10500
- type: "search",
10501
- placeholder: "Search items",
10502
- value: searchValue,
10503
- onChange: (e) => onSearchValueChange(e.target.value)
10504
- }
10505
- ) }),
10506
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10507
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10508
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10509
- /* @__PURE__ */ jsxRuntime.jsx(
10510
- StackedModalTrigger$1,
10511
- {
10512
- type: "add-items",
10513
- setModalContent
10514
- }
10515
- ),
10516
- /* @__PURE__ */ jsxRuntime.jsx(
10517
- StackedModalTrigger$1,
10518
- {
10519
- type: "add-custom-item",
10520
- setModalContent
10521
- }
10522
- )
10523
- ] })
10524
- ] })
10525
- ] })
10526
- ] }),
10527
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10528
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
10529
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10530
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10531
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10532
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
10533
- ] }) }),
10534
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10535
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10536
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10537
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10538
- Item,
10539
- {
10540
- item,
10541
- preview,
10542
- currencyCode
10543
- },
10544
- item.id
10545
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
10546
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10547
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10548
- 'No items found for "',
10549
- query2,
10550
- '".'
10551
- ] })
10552
- ] }) })
10553
- ] })
10554
- ] }),
10555
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10556
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10557
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10558
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10559
- ui.Text,
10560
- {
10561
- size: "small",
10562
- leading: "compact",
10563
- className: "text-ui-fg-subtle",
10564
- children: [
10565
- itemCount,
10566
- " ",
10567
- itemCount === 1 ? "item" : "items"
10568
- ]
10569
- }
10570
- ) }),
10571
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
10572
- ] })
10573
- ] }) }),
10574
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10575
- CustomItemForm,
10576
- {
10577
- orderId: preview.id,
10578
- currencyCode
10579
- }
10580
- ) : null)
10581
- ]
10582
- }
10583
- ) }),
10584
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10585
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10586
- /* @__PURE__ */ jsxRuntime.jsx(
10587
- ui.Button,
10588
- {
10589
- size: "small",
10590
- type: "button",
10591
- onClick: onSubmit,
10592
- isLoading: isSubmitting,
10593
- children: "Save"
10594
- }
10595
- )
10596
- ] }) })
10597
- ] });
10598
- };
10599
- const Item = ({ item, preview, currencyCode }) => {
10600
- if (item.variant_id) {
10601
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10602
- }
10603
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10604
- };
10605
- const VariantItem = ({ item, preview, currencyCode }) => {
10606
- const [editing, setEditing] = React.useState(false);
10607
- const form = reactHookForm.useForm({
10608
- defaultValues: {
10609
- quantity: item.quantity,
10610
- unit_price: item.unit_price
10611
- },
10612
- resolver: zod.zodResolver(variantItemSchema)
10613
- });
10614
- const actionId = React.useMemo(() => {
10615
- var _a, _b;
10616
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10617
- }, [item]);
10618
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10619
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10620
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10621
- const onSubmit = form.handleSubmit(async (data) => {
10622
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10623
- setEditing(false);
10624
- return;
10625
- }
10626
- if (!actionId) {
10627
- await updateOriginalItem(
10628
- {
10629
- item_id: item.id,
10630
- quantity: data.quantity,
10631
- unit_price: convertNumber(data.unit_price)
10632
- },
10633
- {
10634
- onSuccess: () => {
10635
- setEditing(false);
10636
- },
10637
- onError: (e) => {
10638
- ui.toast.error(e.message);
10639
- }
10640
- }
10641
- );
10642
- return;
10451
+ return;
10643
10452
  }
10644
10453
  await updateActionItem(
10645
10454
  {
@@ -10658,171 +10467,12 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10658
10467
  );
10659
10468
  });
10660
10469
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.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: [
10661
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10470
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10662
10471
  /* @__PURE__ */ jsxRuntime.jsx(
10663
10472
  Thumbnail,
10664
10473
  {
10665
10474
  thumbnail: item.thumbnail,
10666
- alt: item.product_title ?? void 0
10667
- }
10668
- ),
10669
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10670
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10671
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10672
- /* @__PURE__ */ jsxRuntime.jsxs(
10673
- ui.Text,
10674
- {
10675
- size: "small",
10676
- leading: "compact",
10677
- className: "text-ui-fg-subtle",
10678
- children: [
10679
- "(",
10680
- item.variant_title,
10681
- ")"
10682
- ]
10683
- }
10684
- )
10685
- ] }),
10686
- /* @__PURE__ */ jsxRuntime.jsx(
10687
- ui.Text,
10688
- {
10689
- size: "small",
10690
- leading: "compact",
10691
- className: "text-ui-fg-subtle",
10692
- children: item.variant_sku
10693
- }
10694
- )
10695
- ] })
10696
- ] }),
10697
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10698
- Form$2.Field,
10699
- {
10700
- control: form.control,
10701
- name: "quantity",
10702
- render: ({ field }) => {
10703
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10704
- }
10705
- }
10706
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10707
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10708
- Form$2.Field,
10709
- {
10710
- control: form.control,
10711
- name: "unit_price",
10712
- render: ({ field: { onChange, ...field } }) => {
10713
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10714
- ui.CurrencyInput,
10715
- {
10716
- ...field,
10717
- symbol: getNativeSymbol(currencyCode),
10718
- code: currencyCode,
10719
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10720
- }
10721
- ) }) });
10722
- }
10723
- }
10724
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10725
- /* @__PURE__ */ jsxRuntime.jsx(
10726
- ui.IconButton,
10727
- {
10728
- type: "button",
10729
- size: "small",
10730
- onClick: editing ? onSubmit : () => {
10731
- setEditing(true);
10732
- },
10733
- disabled: isPending,
10734
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10735
- }
10736
- )
10737
- ] }) }) });
10738
- };
10739
- const variantItemSchema = objectType({
10740
- quantity: numberType(),
10741
- unit_price: unionType([numberType(), stringType()])
10742
- });
10743
- const CustomItem = ({ item, preview, currencyCode }) => {
10744
- const [editing, setEditing] = React.useState(false);
10745
- const { quantity, unit_price, title } = item;
10746
- const form = reactHookForm.useForm({
10747
- defaultValues: {
10748
- title,
10749
- quantity,
10750
- unit_price
10751
- },
10752
- resolver: zod.zodResolver(customItemSchema)
10753
- });
10754
- React.useEffect(() => {
10755
- form.reset({
10756
- title,
10757
- quantity,
10758
- unit_price
10759
- });
10760
- }, [form, title, quantity, unit_price]);
10761
- const actionId = React.useMemo(() => {
10762
- var _a, _b;
10763
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10764
- }, [item]);
10765
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10766
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10767
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10768
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10769
- const onSubmit = form.handleSubmit(async (data) => {
10770
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10771
- setEditing(false);
10772
- return;
10773
- }
10774
- if (!actionId) {
10775
- await updateOriginalItem(
10776
- {
10777
- item_id: item.id,
10778
- quantity: data.quantity,
10779
- unit_price: convertNumber(data.unit_price)
10780
- },
10781
- {
10782
- onSuccess: () => {
10783
- setEditing(false);
10784
- },
10785
- onError: (e) => {
10786
- ui.toast.error(e.message);
10787
- }
10788
- }
10789
- );
10790
- return;
10791
- }
10792
- if (data.quantity === 0) {
10793
- await removeActionItem(actionId, {
10794
- onSuccess: () => {
10795
- setEditing(false);
10796
- },
10797
- onError: (e) => {
10798
- ui.toast.error(e.message);
10799
- }
10800
- });
10801
- return;
10802
- }
10803
- await updateActionItem(
10804
- {
10805
- action_id: actionId,
10806
- quantity: data.quantity,
10807
- unit_price: convertNumber(data.unit_price)
10808
- },
10809
- {
10810
- onSuccess: () => {
10811
- setEditing(false);
10812
- },
10813
- onError: (e) => {
10814
- ui.toast.error(e.message);
10815
- }
10816
- }
10817
- );
10818
- });
10819
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.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: [
10820
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10821
- /* @__PURE__ */ jsxRuntime.jsx(
10822
- Thumbnail,
10823
- {
10824
- thumbnail: item.thumbnail,
10825
- alt: item.title ?? void 0
10475
+ alt: item.title ?? void 0
10826
10476
  }
10827
10477
  ),
10828
10478
  editing ? /* @__PURE__ */ jsxRuntime.jsx(
@@ -11175,6 +10825,356 @@ const customItemSchema = objectType({
11175
10825
  quantity: numberType(),
11176
10826
  unit_price: unionType([numberType(), stringType()])
11177
10827
  });
10828
+ const InlineTip = React.forwardRef(
10829
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10830
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10831
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10832
+ "div",
10833
+ {
10834
+ ref,
10835
+ className: ui.clx(
10836
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10837
+ className
10838
+ ),
10839
+ ...props,
10840
+ children: [
10841
+ /* @__PURE__ */ jsxRuntime.jsx(
10842
+ "div",
10843
+ {
10844
+ role: "presentation",
10845
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10846
+ "bg-ui-tag-orange-icon": variant === "warning"
10847
+ })
10848
+ }
10849
+ ),
10850
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10851
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10852
+ labelValue,
10853
+ ":"
10854
+ ] }),
10855
+ " ",
10856
+ children
10857
+ ] })
10858
+ ]
10859
+ }
10860
+ );
10861
+ }
10862
+ );
10863
+ InlineTip.displayName = "InlineTip";
10864
+ const MetadataFieldSchema = objectType({
10865
+ key: stringType(),
10866
+ disabled: booleanType().optional(),
10867
+ value: anyType()
10868
+ });
10869
+ const MetadataSchema = objectType({
10870
+ metadata: arrayType(MetadataFieldSchema)
10871
+ });
10872
+ const Metadata = () => {
10873
+ const { id } = reactRouterDom.useParams();
10874
+ const { order, isPending, isError, error } = useOrder(id, {
10875
+ fields: "metadata"
10876
+ });
10877
+ if (isError) {
10878
+ throw error;
10879
+ }
10880
+ const isReady = !isPending && !!order;
10881
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10882
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10883
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10884
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10885
+ ] }),
10886
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10887
+ ] });
10888
+ };
10889
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10890
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10891
+ const MetadataForm = ({ orderId, metadata }) => {
10892
+ const { handleSuccess } = useRouteModal();
10893
+ const hasUneditableRows = getHasUneditableRows(metadata);
10894
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10895
+ const form = reactHookForm.useForm({
10896
+ defaultValues: {
10897
+ metadata: getDefaultValues(metadata)
10898
+ },
10899
+ resolver: zod.zodResolver(MetadataSchema)
10900
+ });
10901
+ const handleSubmit = form.handleSubmit(async (data) => {
10902
+ const parsedData = parseValues(data);
10903
+ await mutateAsync(
10904
+ {
10905
+ metadata: parsedData
10906
+ },
10907
+ {
10908
+ onSuccess: () => {
10909
+ ui.toast.success("Metadata updated");
10910
+ handleSuccess();
10911
+ },
10912
+ onError: (error) => {
10913
+ ui.toast.error(error.message);
10914
+ }
10915
+ }
10916
+ );
10917
+ });
10918
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10919
+ control: form.control,
10920
+ name: "metadata"
10921
+ });
10922
+ function deleteRow(index) {
10923
+ remove(index);
10924
+ if (fields.length === 1) {
10925
+ insert(0, {
10926
+ key: "",
10927
+ value: "",
10928
+ disabled: false
10929
+ });
10930
+ }
10931
+ }
10932
+ function insertRow(index, position) {
10933
+ insert(index + (position === "above" ? 0 : 1), {
10934
+ key: "",
10935
+ value: "",
10936
+ disabled: false
10937
+ });
10938
+ }
10939
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10940
+ KeyboundForm,
10941
+ {
10942
+ onSubmit: handleSubmit,
10943
+ className: "flex flex-1 flex-col overflow-hidden",
10944
+ children: [
10945
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10946
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10947
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10948
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10949
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10950
+ ] }),
10951
+ fields.map((field, index) => {
10952
+ const isDisabled = field.disabled || false;
10953
+ let placeholder = "-";
10954
+ if (typeof field.value === "object") {
10955
+ placeholder = "{ ... }";
10956
+ }
10957
+ if (Array.isArray(field.value)) {
10958
+ placeholder = "[ ... ]";
10959
+ }
10960
+ return /* @__PURE__ */ jsxRuntime.jsx(
10961
+ ConditionalTooltip,
10962
+ {
10963
+ showTooltip: isDisabled,
10964
+ content: "This row is disabled because it contains non-primitive data.",
10965
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10966
+ /* @__PURE__ */ jsxRuntime.jsxs(
10967
+ "div",
10968
+ {
10969
+ className: ui.clx("grid grid-cols-2 divide-x", {
10970
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10971
+ }),
10972
+ children: [
10973
+ /* @__PURE__ */ jsxRuntime.jsx(
10974
+ Form$2.Field,
10975
+ {
10976
+ control: form.control,
10977
+ name: `metadata.${index}.key`,
10978
+ render: ({ field: field2 }) => {
10979
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10980
+ GridInput,
10981
+ {
10982
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10983
+ ...field2,
10984
+ disabled: isDisabled,
10985
+ placeholder: "Key"
10986
+ }
10987
+ ) }) });
10988
+ }
10989
+ }
10990
+ ),
10991
+ /* @__PURE__ */ jsxRuntime.jsx(
10992
+ Form$2.Field,
10993
+ {
10994
+ control: form.control,
10995
+ name: `metadata.${index}.value`,
10996
+ render: ({ field: { value, ...field2 } }) => {
10997
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10998
+ GridInput,
10999
+ {
11000
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11001
+ ...field2,
11002
+ value: isDisabled ? placeholder : value,
11003
+ disabled: isDisabled,
11004
+ placeholder: "Value"
11005
+ }
11006
+ ) }) });
11007
+ }
11008
+ }
11009
+ )
11010
+ ]
11011
+ }
11012
+ ),
11013
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11014
+ /* @__PURE__ */ jsxRuntime.jsx(
11015
+ ui.DropdownMenu.Trigger,
11016
+ {
11017
+ className: ui.clx(
11018
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11019
+ {
11020
+ hidden: isDisabled
11021
+ }
11022
+ ),
11023
+ disabled: isDisabled,
11024
+ asChild: true,
11025
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11026
+ }
11027
+ ),
11028
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11029
+ /* @__PURE__ */ jsxRuntime.jsxs(
11030
+ ui.DropdownMenu.Item,
11031
+ {
11032
+ className: "gap-x-2",
11033
+ onClick: () => insertRow(index, "above"),
11034
+ children: [
11035
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11036
+ "Insert row above"
11037
+ ]
11038
+ }
11039
+ ),
11040
+ /* @__PURE__ */ jsxRuntime.jsxs(
11041
+ ui.DropdownMenu.Item,
11042
+ {
11043
+ className: "gap-x-2",
11044
+ onClick: () => insertRow(index, "below"),
11045
+ children: [
11046
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11047
+ "Insert row below"
11048
+ ]
11049
+ }
11050
+ ),
11051
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11052
+ /* @__PURE__ */ jsxRuntime.jsxs(
11053
+ ui.DropdownMenu.Item,
11054
+ {
11055
+ className: "gap-x-2",
11056
+ onClick: () => deleteRow(index),
11057
+ children: [
11058
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11059
+ "Delete row"
11060
+ ]
11061
+ }
11062
+ )
11063
+ ] })
11064
+ ] })
11065
+ ] })
11066
+ },
11067
+ field.id
11068
+ );
11069
+ })
11070
+ ] }),
11071
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11072
+ ] }),
11073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11074
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11075
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11076
+ ] }) })
11077
+ ]
11078
+ }
11079
+ ) });
11080
+ };
11081
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11082
+ return /* @__PURE__ */ jsxRuntime.jsx(
11083
+ "input",
11084
+ {
11085
+ ref,
11086
+ ...props,
11087
+ autoComplete: "off",
11088
+ className: ui.clx(
11089
+ "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",
11090
+ className
11091
+ )
11092
+ }
11093
+ );
11094
+ });
11095
+ GridInput.displayName = "MetadataForm.GridInput";
11096
+ const PlaceholderInner = () => {
11097
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11099
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11101
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11102
+ ] }) })
11103
+ ] });
11104
+ };
11105
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11106
+ function getDefaultValues(metadata) {
11107
+ if (!metadata || !Object.keys(metadata).length) {
11108
+ return [
11109
+ {
11110
+ key: "",
11111
+ value: "",
11112
+ disabled: false
11113
+ }
11114
+ ];
11115
+ }
11116
+ return Object.entries(metadata).map(([key, value]) => {
11117
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11118
+ return {
11119
+ key,
11120
+ value,
11121
+ disabled: true
11122
+ };
11123
+ }
11124
+ let stringValue = value;
11125
+ if (typeof value !== "string") {
11126
+ stringValue = JSON.stringify(value);
11127
+ }
11128
+ return {
11129
+ key,
11130
+ value: stringValue,
11131
+ original_key: key
11132
+ };
11133
+ });
11134
+ }
11135
+ function parseValues(values) {
11136
+ const metadata = values.metadata;
11137
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11138
+ if (isEmpty) {
11139
+ return null;
11140
+ }
11141
+ const update = {};
11142
+ metadata.forEach((field) => {
11143
+ let key = field.key;
11144
+ let value = field.value;
11145
+ const disabled = field.disabled;
11146
+ if (!key || !value) {
11147
+ return;
11148
+ }
11149
+ if (disabled) {
11150
+ update[key] = value;
11151
+ return;
11152
+ }
11153
+ key = key.trim();
11154
+ value = value.trim();
11155
+ if (value === "true") {
11156
+ update[key] = true;
11157
+ } else if (value === "false") {
11158
+ update[key] = false;
11159
+ } else {
11160
+ const parsedNumber = parseFloat(value);
11161
+ if (!isNaN(parsedNumber)) {
11162
+ update[key] = parsedNumber;
11163
+ } else {
11164
+ update[key] = value;
11165
+ }
11166
+ }
11167
+ });
11168
+ return update;
11169
+ }
11170
+ function getHasUneditableRows(metadata) {
11171
+ if (!metadata) {
11172
+ return false;
11173
+ }
11174
+ return Object.values(metadata).some(
11175
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11176
+ );
11177
+ }
11178
11178
  const PROMOTION_QUERY_KEY = "promotions";
11179
11179
  const promotionsQueryKeys = {
11180
11180
  list: (query2) => [
@@ -11540,24 +11540,227 @@ const SalesChannelField = ({ control, order }) => {
11540
11540
  /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11541
11541
  Combobox,
11542
11542
  {
11543
- options: salesChannels.options,
11544
- fetchNextPage: salesChannels.fetchNextPage,
11545
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11546
- searchValue: salesChannels.searchValue,
11547
- onSearchValueChange: salesChannels.onSearchValueChange,
11548
- placeholder: "Select sales channel",
11549
- ...field
11543
+ options: salesChannels.options,
11544
+ fetchNextPage: salesChannels.fetchNextPage,
11545
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11546
+ searchValue: salesChannels.searchValue,
11547
+ onSearchValueChange: salesChannels.onSearchValueChange,
11548
+ placeholder: "Select sales channel",
11549
+ ...field
11550
+ }
11551
+ ) }),
11552
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11553
+ ] });
11554
+ }
11555
+ }
11556
+ );
11557
+ };
11558
+ const schema$2 = objectType({
11559
+ sales_channel_id: stringType().min(1)
11560
+ });
11561
+ const ShippingAddress = () => {
11562
+ const { id } = reactRouterDom.useParams();
11563
+ const { order, isPending, isError, error } = useOrder(id, {
11564
+ fields: "+shipping_address"
11565
+ });
11566
+ if (isError) {
11567
+ throw error;
11568
+ }
11569
+ const isReady = !isPending && !!order;
11570
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11571
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11572
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11573
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11574
+ ] }),
11575
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11576
+ ] });
11577
+ };
11578
+ const ShippingAddressForm = ({ order }) => {
11579
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11580
+ const form = reactHookForm.useForm({
11581
+ defaultValues: {
11582
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11583
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11584
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11585
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11586
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11587
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11588
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11589
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11590
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11591
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11592
+ },
11593
+ resolver: zod.zodResolver(schema$1)
11594
+ });
11595
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11596
+ const { handleSuccess } = useRouteModal();
11597
+ const onSubmit = form.handleSubmit(async (data) => {
11598
+ await mutateAsync(
11599
+ {
11600
+ shipping_address: {
11601
+ first_name: data.first_name,
11602
+ last_name: data.last_name,
11603
+ company: data.company,
11604
+ address_1: data.address_1,
11605
+ address_2: data.address_2,
11606
+ city: data.city,
11607
+ province: data.province,
11608
+ country_code: data.country_code,
11609
+ postal_code: data.postal_code,
11610
+ phone: data.phone
11611
+ }
11612
+ },
11613
+ {
11614
+ onSuccess: () => {
11615
+ handleSuccess();
11616
+ },
11617
+ onError: (error) => {
11618
+ ui.toast.error(error.message);
11619
+ }
11620
+ }
11621
+ );
11622
+ });
11623
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11624
+ KeyboundForm,
11625
+ {
11626
+ className: "flex flex-1 flex-col overflow-hidden",
11627
+ onSubmit,
11628
+ children: [
11629
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
11630
+ /* @__PURE__ */ jsxRuntime.jsx(
11631
+ Form$2.Field,
11632
+ {
11633
+ control: form.control,
11634
+ name: "country_code",
11635
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11636
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11637
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11638
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11639
+ ] })
11640
+ }
11641
+ ),
11642
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11643
+ /* @__PURE__ */ jsxRuntime.jsx(
11644
+ Form$2.Field,
11645
+ {
11646
+ control: form.control,
11647
+ name: "first_name",
11648
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11649
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11650
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11651
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11652
+ ] })
11653
+ }
11654
+ ),
11655
+ /* @__PURE__ */ jsxRuntime.jsx(
11656
+ Form$2.Field,
11657
+ {
11658
+ control: form.control,
11659
+ name: "last_name",
11660
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11661
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
11662
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11663
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11664
+ ] })
11665
+ }
11666
+ )
11667
+ ] }),
11668
+ /* @__PURE__ */ jsxRuntime.jsx(
11669
+ Form$2.Field,
11670
+ {
11671
+ control: form.control,
11672
+ name: "company",
11673
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11674
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11675
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11676
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11677
+ ] })
11678
+ }
11679
+ ),
11680
+ /* @__PURE__ */ jsxRuntime.jsx(
11681
+ Form$2.Field,
11682
+ {
11683
+ control: form.control,
11684
+ name: "address_1",
11685
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11686
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
11687
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11688
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11689
+ ] })
11690
+ }
11691
+ ),
11692
+ /* @__PURE__ */ jsxRuntime.jsx(
11693
+ Form$2.Field,
11694
+ {
11695
+ control: form.control,
11696
+ name: "address_2",
11697
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11698
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
11699
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11700
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11701
+ ] })
11702
+ }
11703
+ ),
11704
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11705
+ /* @__PURE__ */ jsxRuntime.jsx(
11706
+ Form$2.Field,
11707
+ {
11708
+ control: form.control,
11709
+ name: "postal_code",
11710
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11711
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11712
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11713
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11714
+ ] })
11715
+ }
11716
+ ),
11717
+ /* @__PURE__ */ jsxRuntime.jsx(
11718
+ Form$2.Field,
11719
+ {
11720
+ control: form.control,
11721
+ name: "city",
11722
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11723
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
11724
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11725
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11726
+ ] })
11727
+ }
11728
+ )
11729
+ ] }),
11730
+ /* @__PURE__ */ jsxRuntime.jsx(
11731
+ Form$2.Field,
11732
+ {
11733
+ control: form.control,
11734
+ name: "province",
11735
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11736
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11737
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11738
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11739
+ ] })
11740
+ }
11741
+ ),
11742
+ /* @__PURE__ */ jsxRuntime.jsx(
11743
+ Form$2.Field,
11744
+ {
11745
+ control: form.control,
11746
+ name: "phone",
11747
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11748
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
11749
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11750
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11751
+ ] })
11550
11752
  }
11551
- ) }),
11552
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11553
- ] });
11554
- }
11753
+ )
11754
+ ] }) }),
11755
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11756
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11757
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11758
+ ] }) })
11759
+ ]
11555
11760
  }
11556
- );
11761
+ ) });
11557
11762
  };
11558
- const schema$2 = objectType({
11559
- sales_channel_id: stringType().min(1)
11560
- });
11763
+ const schema$1 = addressSchema;
11561
11764
  const STACKED_FOCUS_MODAL_ID = "shipping-form";
11562
11765
  const Shipping = () => {
11563
11766
  var _a;
@@ -12365,209 +12568,6 @@ const CustomAmountField = ({
12365
12568
  }
12366
12569
  );
12367
12570
  };
12368
- const ShippingAddress = () => {
12369
- const { id } = reactRouterDom.useParams();
12370
- const { order, isPending, isError, error } = useOrder(id, {
12371
- fields: "+shipping_address"
12372
- });
12373
- if (isError) {
12374
- throw error;
12375
- }
12376
- const isReady = !isPending && !!order;
12377
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12378
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12379
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12380
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12381
- ] }),
12382
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12383
- ] });
12384
- };
12385
- const ShippingAddressForm = ({ order }) => {
12386
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12387
- const form = reactHookForm.useForm({
12388
- defaultValues: {
12389
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12390
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12391
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12392
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12393
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12394
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12395
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12396
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12397
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12398
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12399
- },
12400
- resolver: zod.zodResolver(schema$1)
12401
- });
12402
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12403
- const { handleSuccess } = useRouteModal();
12404
- const onSubmit = form.handleSubmit(async (data) => {
12405
- await mutateAsync(
12406
- {
12407
- shipping_address: {
12408
- first_name: data.first_name,
12409
- last_name: data.last_name,
12410
- company: data.company,
12411
- address_1: data.address_1,
12412
- address_2: data.address_2,
12413
- city: data.city,
12414
- province: data.province,
12415
- country_code: data.country_code,
12416
- postal_code: data.postal_code,
12417
- phone: data.phone
12418
- }
12419
- },
12420
- {
12421
- onSuccess: () => {
12422
- handleSuccess();
12423
- },
12424
- onError: (error) => {
12425
- ui.toast.error(error.message);
12426
- }
12427
- }
12428
- );
12429
- });
12430
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12431
- KeyboundForm,
12432
- {
12433
- className: "flex flex-1 flex-col overflow-hidden",
12434
- onSubmit,
12435
- children: [
12436
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12437
- /* @__PURE__ */ jsxRuntime.jsx(
12438
- Form$2.Field,
12439
- {
12440
- control: form.control,
12441
- name: "country_code",
12442
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12443
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12444
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12445
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12446
- ] })
12447
- }
12448
- ),
12449
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12450
- /* @__PURE__ */ jsxRuntime.jsx(
12451
- Form$2.Field,
12452
- {
12453
- control: form.control,
12454
- name: "first_name",
12455
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12456
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12457
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12458
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12459
- ] })
12460
- }
12461
- ),
12462
- /* @__PURE__ */ jsxRuntime.jsx(
12463
- Form$2.Field,
12464
- {
12465
- control: form.control,
12466
- name: "last_name",
12467
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12468
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12469
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12470
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12471
- ] })
12472
- }
12473
- )
12474
- ] }),
12475
- /* @__PURE__ */ jsxRuntime.jsx(
12476
- Form$2.Field,
12477
- {
12478
- control: form.control,
12479
- name: "company",
12480
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12481
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12482
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12483
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12484
- ] })
12485
- }
12486
- ),
12487
- /* @__PURE__ */ jsxRuntime.jsx(
12488
- Form$2.Field,
12489
- {
12490
- control: form.control,
12491
- name: "address_1",
12492
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12493
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12494
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12495
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12496
- ] })
12497
- }
12498
- ),
12499
- /* @__PURE__ */ jsxRuntime.jsx(
12500
- Form$2.Field,
12501
- {
12502
- control: form.control,
12503
- name: "address_2",
12504
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12505
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12506
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12507
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12508
- ] })
12509
- }
12510
- ),
12511
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12512
- /* @__PURE__ */ jsxRuntime.jsx(
12513
- Form$2.Field,
12514
- {
12515
- control: form.control,
12516
- name: "postal_code",
12517
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12518
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12519
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12521
- ] })
12522
- }
12523
- ),
12524
- /* @__PURE__ */ jsxRuntime.jsx(
12525
- Form$2.Field,
12526
- {
12527
- control: form.control,
12528
- name: "city",
12529
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12530
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12533
- ] })
12534
- }
12535
- )
12536
- ] }),
12537
- /* @__PURE__ */ jsxRuntime.jsx(
12538
- Form$2.Field,
12539
- {
12540
- control: form.control,
12541
- name: "province",
12542
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12543
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12546
- ] })
12547
- }
12548
- ),
12549
- /* @__PURE__ */ jsxRuntime.jsx(
12550
- Form$2.Field,
12551
- {
12552
- control: form.control,
12553
- name: "phone",
12554
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12555
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12558
- ] })
12559
- }
12560
- )
12561
- ] }) }),
12562
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12563
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12565
- ] }) })
12566
- ]
12567
- }
12568
- ) });
12569
- };
12570
- const schema$1 = addressSchema;
12571
12571
  const TransferOwnership = () => {
12572
12572
  const { id } = reactRouterDom.useParams();
12573
12573
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -13076,14 +13076,14 @@ const routeModule = {
13076
13076
  Component: Email,
13077
13077
  path: "/draft-orders/:id/email"
13078
13078
  },
13079
- {
13080
- Component: Metadata,
13081
- path: "/draft-orders/:id/metadata"
13082
- },
13083
13079
  {
13084
13080
  Component: Items,
13085
13081
  path: "/draft-orders/:id/items"
13086
13082
  },
13083
+ {
13084
+ Component: Metadata,
13085
+ path: "/draft-orders/:id/metadata"
13086
+ },
13087
13087
  {
13088
13088
  Component: Promotions,
13089
13089
  path: "/draft-orders/:id/promotions"
@@ -13092,14 +13092,14 @@ const routeModule = {
13092
13092
  Component: SalesChannel,
13093
13093
  path: "/draft-orders/:id/sales-channel"
13094
13094
  },
13095
- {
13096
- Component: Shipping,
13097
- path: "/draft-orders/:id/shipping"
13098
- },
13099
13095
  {
13100
13096
  Component: ShippingAddress,
13101
13097
  path: "/draft-orders/:id/shipping-address"
13102
13098
  },
13099
+ {
13100
+ Component: Shipping,
13101
+ path: "/draft-orders/:id/shipping"
13102
+ },
13103
13103
  {
13104
13104
  Component: TransferOwnership,
13105
13105
  path: "/draft-orders/:id/transfer-ownership"