@medusajs/draft-order 2.10.2-snapshot-20250829152522 → 2.10.2-snapshot-20250901132949

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.
@@ -9818,777 +9818,596 @@ const EmailForm = ({ order }) => {
9818
9818
  const schema$4 = objectType({
9819
9819
  email: stringType().email()
9820
9820
  });
9821
- const InlineTip = React.forwardRef(
9822
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9823
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9821
+ const CustomItems = () => {
9822
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9823
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9824
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9825
+ ] });
9826
+ };
9827
+ const CustomItemsForm = () => {
9828
+ const form = reactHookForm.useForm({
9829
+ resolver: zod.zodResolver(schema$3)
9830
+ });
9831
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9832
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9833
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9834
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9835
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9836
+ ] }) })
9837
+ ] }) });
9838
+ };
9839
+ const schema$3 = objectType({
9840
+ email: stringType().email()
9841
+ });
9842
+ const NumberInput = React.forwardRef(
9843
+ ({
9844
+ value,
9845
+ onChange,
9846
+ size = "base",
9847
+ min = 0,
9848
+ max = 100,
9849
+ step = 1,
9850
+ className,
9851
+ disabled,
9852
+ ...props
9853
+ }, ref) => {
9854
+ const handleChange = (event) => {
9855
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9856
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9857
+ onChange(newValue);
9858
+ }
9859
+ };
9860
+ const handleIncrement = () => {
9861
+ const newValue = value + step;
9862
+ if (max === void 0 || newValue <= max) {
9863
+ onChange(newValue);
9864
+ }
9865
+ };
9866
+ const handleDecrement = () => {
9867
+ const newValue = value - step;
9868
+ if (min === void 0 || newValue >= min) {
9869
+ onChange(newValue);
9870
+ }
9871
+ };
9824
9872
  return /* @__PURE__ */ jsxRuntime.jsxs(
9825
9873
  "div",
9826
9874
  {
9827
- ref,
9828
9875
  className: ui.clx(
9829
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9876
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9877
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9878
+ {
9879
+ "h-7": size === "small",
9880
+ "h-8": size === "base"
9881
+ },
9830
9882
  className
9831
9883
  ),
9832
- ...props,
9833
9884
  children: [
9834
9885
  /* @__PURE__ */ jsxRuntime.jsx(
9835
- "div",
9886
+ "input",
9836
9887
  {
9837
- role: "presentation",
9838
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9839
- "bg-ui-tag-orange-icon": variant === "warning"
9840
- })
9888
+ ref,
9889
+ type: "number",
9890
+ value,
9891
+ onChange: handleChange,
9892
+ min,
9893
+ max,
9894
+ step,
9895
+ className: ui.clx(
9896
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9897
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9898
+ "placeholder:text-ui-fg-muted"
9899
+ ),
9900
+ ...props
9841
9901
  }
9842
9902
  ),
9843
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9844
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9845
- labelValue,
9846
- ":"
9847
- ] }),
9848
- " ",
9849
- children
9850
- ] })
9903
+ /* @__PURE__ */ jsxRuntime.jsxs(
9904
+ "button",
9905
+ {
9906
+ className: ui.clx(
9907
+ "flex items-center justify-center outline-none transition-fg",
9908
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9909
+ "focus:bg-ui-bg-field-component-hover",
9910
+ "hover:bg-ui-bg-field-component-hover",
9911
+ {
9912
+ "size-7": size === "small",
9913
+ "size-8": size === "base"
9914
+ }
9915
+ ),
9916
+ type: "button",
9917
+ onClick: handleDecrement,
9918
+ disabled: min !== void 0 && value <= min || disabled,
9919
+ children: [
9920
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9921
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9922
+ ]
9923
+ }
9924
+ ),
9925
+ /* @__PURE__ */ jsxRuntime.jsxs(
9926
+ "button",
9927
+ {
9928
+ className: ui.clx(
9929
+ "flex items-center justify-center outline-none transition-fg",
9930
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9931
+ "focus:bg-ui-bg-field-hover",
9932
+ "hover:bg-ui-bg-field-hover",
9933
+ {
9934
+ "size-7": size === "small",
9935
+ "size-8": size === "base"
9936
+ }
9937
+ ),
9938
+ type: "button",
9939
+ onClick: handleIncrement,
9940
+ disabled: max !== void 0 && value >= max || disabled,
9941
+ children: [
9942
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9943
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9944
+ ]
9945
+ }
9946
+ )
9851
9947
  ]
9852
9948
  }
9853
9949
  );
9854
9950
  }
9855
9951
  );
9856
- InlineTip.displayName = "InlineTip";
9857
- const MetadataFieldSchema = objectType({
9858
- key: stringType(),
9859
- disabled: booleanType().optional(),
9860
- value: anyType()
9861
- });
9862
- const MetadataSchema = objectType({
9863
- metadata: arrayType(MetadataFieldSchema)
9864
- });
9865
- const Metadata = () => {
9952
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9953
+ const productVariantsQueryKeys = {
9954
+ list: (query2) => [
9955
+ PRODUCT_VARIANTS_QUERY_KEY,
9956
+ query2 ? query2 : void 0
9957
+ ]
9958
+ };
9959
+ const useProductVariants = (query2, options) => {
9960
+ const { data, ...rest } = reactQuery.useQuery({
9961
+ queryKey: productVariantsQueryKeys.list(query2),
9962
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9963
+ ...options
9964
+ });
9965
+ return { ...data, ...rest };
9966
+ };
9967
+ const useCancelOrderEdit = ({ preview }) => {
9968
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9969
+ const onCancel = React.useCallback(async () => {
9970
+ if (!preview) {
9971
+ return true;
9972
+ }
9973
+ let res = false;
9974
+ await cancelOrderEdit(void 0, {
9975
+ onError: (e) => {
9976
+ ui.toast.error(e.message);
9977
+ },
9978
+ onSuccess: () => {
9979
+ res = true;
9980
+ }
9981
+ });
9982
+ return res;
9983
+ }, [preview, cancelOrderEdit]);
9984
+ return { onCancel };
9985
+ };
9986
+ let IS_REQUEST_RUNNING = false;
9987
+ const useInitiateOrderEdit = ({
9988
+ preview
9989
+ }) => {
9990
+ const navigate = reactRouterDom.useNavigate();
9991
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9992
+ React.useEffect(() => {
9993
+ async function run() {
9994
+ if (IS_REQUEST_RUNNING || !preview) {
9995
+ return;
9996
+ }
9997
+ if (preview.order_change) {
9998
+ return;
9999
+ }
10000
+ IS_REQUEST_RUNNING = true;
10001
+ await mutateAsync(void 0, {
10002
+ onError: (e) => {
10003
+ ui.toast.error(e.message);
10004
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10005
+ return;
10006
+ }
10007
+ });
10008
+ IS_REQUEST_RUNNING = false;
10009
+ }
10010
+ run();
10011
+ }, [preview, navigate, mutateAsync]);
10012
+ };
10013
+ function convertNumber(value) {
10014
+ return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10015
+ }
10016
+ const STACKED_MODAL_ID = "items_stacked_modal";
10017
+ const Items = () => {
9866
10018
  const { id } = reactRouterDom.useParams();
9867
- const { order, isPending, isError, error } = useOrder(id, {
9868
- fields: "metadata"
10019
+ const {
10020
+ order: preview,
10021
+ isPending: isPreviewPending,
10022
+ isError: isPreviewError,
10023
+ error: previewError
10024
+ } = useOrderPreview(id, void 0, {
10025
+ placeholderData: reactQuery.keepPreviousData
9869
10026
  });
10027
+ useInitiateOrderEdit({ preview });
10028
+ const { draft_order, isPending, isError, error } = useDraftOrder(
10029
+ id,
10030
+ {
10031
+ fields: "currency_code"
10032
+ },
10033
+ {
10034
+ enabled: !!id
10035
+ }
10036
+ );
10037
+ const { onCancel } = useCancelOrderEdit({ preview });
9870
10038
  if (isError) {
9871
10039
  throw error;
9872
10040
  }
9873
- const isReady = !isPending && !!order;
9874
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9875
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9876
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9877
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9878
- ] }),
9879
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9880
- ] });
10041
+ if (isPreviewError) {
10042
+ throw previewError;
10043
+ }
10044
+ const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10045
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10046
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10047
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10048
+ ] }) });
9881
10049
  };
9882
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9883
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9884
- const MetadataForm = ({ orderId, metadata }) => {
10050
+ const ItemsForm = ({ preview, currencyCode }) => {
10051
+ var _a;
10052
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
10053
+ const [modalContent, setModalContent] = React.useState(
10054
+ null
10055
+ );
9885
10056
  const { handleSuccess } = useRouteModal();
9886
- const hasUneditableRows = getHasUneditableRows(metadata);
9887
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10057
+ const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10058
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10059
+ const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10060
+ const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10061
+ const matches = React.useMemo(() => {
10062
+ return matchSorter.matchSorter(preview.items, query2, {
10063
+ keys: ["product_title", "variant_title", "variant_sku", "title"]
10064
+ });
10065
+ }, [preview.items, query2]);
10066
+ const onSubmit = async () => {
10067
+ setIsSubmitting(true);
10068
+ let requestSucceeded = false;
10069
+ await requestOrderEdit(void 0, {
10070
+ onError: (e) => {
10071
+ ui.toast.error(`Failed to request order edit: ${e.message}`);
10072
+ },
10073
+ onSuccess: () => {
10074
+ requestSucceeded = true;
10075
+ }
10076
+ });
10077
+ if (!requestSucceeded) {
10078
+ setIsSubmitting(false);
10079
+ return;
10080
+ }
10081
+ await confirmOrderEdit(void 0, {
10082
+ onError: (e) => {
10083
+ ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10084
+ },
10085
+ onSuccess: () => {
10086
+ handleSuccess();
10087
+ },
10088
+ onSettled: () => {
10089
+ setIsSubmitting(false);
10090
+ }
10091
+ });
10092
+ };
10093
+ const onKeyDown = React.useCallback(
10094
+ (e) => {
10095
+ if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10096
+ if (modalContent || isSubmitting) {
10097
+ return;
10098
+ }
10099
+ onSubmit();
10100
+ }
10101
+ },
10102
+ [modalContent, isSubmitting, onSubmit]
10103
+ );
10104
+ React.useEffect(() => {
10105
+ document.addEventListener("keydown", onKeyDown);
10106
+ return () => {
10107
+ document.removeEventListener("keydown", onKeyDown);
10108
+ };
10109
+ }, [onKeyDown]);
10110
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10111
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10112
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10113
+ StackedFocusModal,
10114
+ {
10115
+ id: STACKED_MODAL_ID,
10116
+ onOpenChangeCallback: (open) => {
10117
+ if (!open) {
10118
+ setModalContent(null);
10119
+ }
10120
+ },
10121
+ children: [
10122
+ /* @__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: [
10123
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10124
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10125
+ /* @__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." }) })
10126
+ ] }),
10127
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10128
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10129
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10130
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10131
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10132
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10133
+ ] }),
10134
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10135
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10136
+ ui.Input,
10137
+ {
10138
+ type: "search",
10139
+ placeholder: "Search items",
10140
+ value: searchValue,
10141
+ onChange: (e) => onSearchValueChange(e.target.value)
10142
+ }
10143
+ ) }),
10144
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10145
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10146
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10147
+ /* @__PURE__ */ jsxRuntime.jsx(
10148
+ StackedModalTrigger$1,
10149
+ {
10150
+ type: "add-items",
10151
+ setModalContent
10152
+ }
10153
+ ),
10154
+ /* @__PURE__ */ jsxRuntime.jsx(
10155
+ StackedModalTrigger$1,
10156
+ {
10157
+ type: "add-custom-item",
10158
+ setModalContent
10159
+ }
10160
+ )
10161
+ ] })
10162
+ ] })
10163
+ ] })
10164
+ ] }),
10165
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10166
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
10167
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10168
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10169
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10170
+ /* @__PURE__ */ jsxRuntime.jsx("div", {})
10171
+ ] }) }),
10172
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10173
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10174
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10175
+ ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10176
+ Item,
10177
+ {
10178
+ item,
10179
+ preview,
10180
+ currencyCode
10181
+ },
10182
+ item.id
10183
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10184
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10185
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10186
+ 'No items found for "',
10187
+ query2,
10188
+ '".'
10189
+ ] })
10190
+ ] }) })
10191
+ ] })
10192
+ ] }),
10193
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10194
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10195
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10196
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10197
+ ui.Text,
10198
+ {
10199
+ size: "small",
10200
+ leading: "compact",
10201
+ className: "text-ui-fg-subtle",
10202
+ children: [
10203
+ itemCount,
10204
+ " ",
10205
+ itemCount === 1 ? "item" : "items"
10206
+ ]
10207
+ }
10208
+ ) }),
10209
+ /* @__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) }) })
10210
+ ] })
10211
+ ] }) }),
10212
+ modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10213
+ CustomItemForm,
10214
+ {
10215
+ orderId: preview.id,
10216
+ currencyCode
10217
+ }
10218
+ ) : null)
10219
+ ]
10220
+ }
10221
+ ) }),
10222
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10223
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10224
+ /* @__PURE__ */ jsxRuntime.jsx(
10225
+ ui.Button,
10226
+ {
10227
+ size: "small",
10228
+ type: "button",
10229
+ onClick: onSubmit,
10230
+ isLoading: isSubmitting,
10231
+ children: "Save"
10232
+ }
10233
+ )
10234
+ ] }) })
10235
+ ] });
10236
+ };
10237
+ const Item = ({ item, preview, currencyCode }) => {
10238
+ if (item.variant_id) {
10239
+ return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10240
+ }
10241
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10242
+ };
10243
+ const VariantItem = ({ item, preview, currencyCode }) => {
10244
+ const [editing, setEditing] = React.useState(false);
9888
10245
  const form = reactHookForm.useForm({
9889
10246
  defaultValues: {
9890
- metadata: getDefaultValues(metadata)
10247
+ quantity: item.quantity,
10248
+ unit_price: item.unit_price
9891
10249
  },
9892
- resolver: zod.zodResolver(MetadataSchema)
10250
+ resolver: zod.zodResolver(variantItemSchema)
9893
10251
  });
9894
- const handleSubmit = form.handleSubmit(async (data) => {
9895
- const parsedData = parseValues(data);
9896
- await mutateAsync(
10252
+ const actionId = React.useMemo(() => {
10253
+ var _a, _b;
10254
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10255
+ }, [item]);
10256
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10257
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10258
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10259
+ const onSubmit = form.handleSubmit(async (data) => {
10260
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10261
+ setEditing(false);
10262
+ return;
10263
+ }
10264
+ if (!actionId) {
10265
+ await updateOriginalItem(
10266
+ {
10267
+ item_id: item.id,
10268
+ quantity: data.quantity,
10269
+ unit_price: convertNumber(data.unit_price)
10270
+ },
10271
+ {
10272
+ onSuccess: () => {
10273
+ setEditing(false);
10274
+ },
10275
+ onError: (e) => {
10276
+ ui.toast.error(e.message);
10277
+ }
10278
+ }
10279
+ );
10280
+ return;
10281
+ }
10282
+ await updateActionItem(
9897
10283
  {
9898
- metadata: parsedData
10284
+ action_id: actionId,
10285
+ quantity: data.quantity,
10286
+ unit_price: convertNumber(data.unit_price)
9899
10287
  },
9900
10288
  {
9901
10289
  onSuccess: () => {
9902
- ui.toast.success("Metadata updated");
9903
- handleSuccess();
10290
+ setEditing(false);
9904
10291
  },
9905
- onError: (error) => {
9906
- ui.toast.error(error.message);
10292
+ onError: (e) => {
10293
+ ui.toast.error(e.message);
9907
10294
  }
9908
10295
  }
9909
10296
  );
9910
10297
  });
9911
- const { fields, insert, remove } = reactHookForm.useFieldArray({
9912
- control: form.control,
9913
- name: "metadata"
9914
- });
9915
- function deleteRow(index) {
9916
- remove(index);
9917
- if (fields.length === 1) {
9918
- insert(0, {
9919
- key: "",
9920
- value: "",
9921
- disabled: false
9922
- });
9923
- }
9924
- }
9925
- function insertRow(index, position) {
9926
- insert(index + (position === "above" ? 0 : 1), {
9927
- key: "",
9928
- value: "",
9929
- disabled: false
9930
- });
9931
- }
9932
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9933
- KeyboundForm,
9934
- {
9935
- onSubmit: handleSubmit,
9936
- className: "flex flex-1 flex-col overflow-hidden",
9937
- children: [
9938
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9939
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9940
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9941
- /* @__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" }) }),
9942
- /* @__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" }) })
9943
- ] }),
9944
- fields.map((field, index) => {
9945
- const isDisabled = field.disabled || false;
9946
- let placeholder = "-";
9947
- if (typeof field.value === "object") {
9948
- placeholder = "{ ... }";
9949
- }
9950
- if (Array.isArray(field.value)) {
9951
- placeholder = "[ ... ]";
9952
- }
9953
- return /* @__PURE__ */ jsxRuntime.jsx(
9954
- ConditionalTooltip,
9955
- {
9956
- showTooltip: isDisabled,
9957
- content: "This row is disabled because it contains non-primitive data.",
9958
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9959
- /* @__PURE__ */ jsxRuntime.jsxs(
9960
- "div",
9961
- {
9962
- className: ui.clx("grid grid-cols-2 divide-x", {
9963
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9964
- }),
9965
- children: [
9966
- /* @__PURE__ */ jsxRuntime.jsx(
9967
- Form$2.Field,
9968
- {
9969
- control: form.control,
9970
- name: `metadata.${index}.key`,
9971
- render: ({ field: field2 }) => {
9972
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9973
- GridInput,
9974
- {
9975
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9976
- ...field2,
9977
- disabled: isDisabled,
9978
- placeholder: "Key"
9979
- }
9980
- ) }) });
9981
- }
9982
- }
9983
- ),
9984
- /* @__PURE__ */ jsxRuntime.jsx(
9985
- Form$2.Field,
9986
- {
9987
- control: form.control,
9988
- name: `metadata.${index}.value`,
9989
- render: ({ field: { value, ...field2 } }) => {
9990
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9991
- GridInput,
9992
- {
9993
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
9994
- ...field2,
9995
- value: isDisabled ? placeholder : value,
9996
- disabled: isDisabled,
9997
- placeholder: "Value"
9998
- }
9999
- ) }) });
10000
- }
10001
- }
10002
- )
10003
- ]
10004
- }
10005
- ),
10006
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10007
- /* @__PURE__ */ jsxRuntime.jsx(
10008
- ui.DropdownMenu.Trigger,
10009
- {
10010
- className: ui.clx(
10011
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10012
- {
10013
- hidden: isDisabled
10014
- }
10015
- ),
10016
- disabled: isDisabled,
10017
- asChild: true,
10018
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10019
- }
10020
- ),
10021
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10022
- /* @__PURE__ */ jsxRuntime.jsxs(
10023
- ui.DropdownMenu.Item,
10024
- {
10025
- className: "gap-x-2",
10026
- onClick: () => insertRow(index, "above"),
10027
- children: [
10028
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10029
- "Insert row above"
10030
- ]
10031
- }
10032
- ),
10033
- /* @__PURE__ */ jsxRuntime.jsxs(
10034
- ui.DropdownMenu.Item,
10035
- {
10036
- className: "gap-x-2",
10037
- onClick: () => insertRow(index, "below"),
10038
- children: [
10039
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10040
- "Insert row below"
10041
- ]
10042
- }
10043
- ),
10044
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10045
- /* @__PURE__ */ jsxRuntime.jsxs(
10046
- ui.DropdownMenu.Item,
10047
- {
10048
- className: "gap-x-2",
10049
- onClick: () => deleteRow(index),
10050
- children: [
10051
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10052
- "Delete row"
10053
- ]
10054
- }
10055
- )
10056
- ] })
10057
- ] })
10058
- ] })
10059
- },
10060
- field.id
10061
- );
10062
- })
10063
- ] }),
10064
- 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." })
10298
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10299
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
10300
+ /* @__PURE__ */ jsxRuntime.jsx(
10301
+ Thumbnail,
10302
+ {
10303
+ thumbnail: item.thumbnail,
10304
+ alt: item.product_title ?? void 0
10305
+ }
10306
+ ),
10307
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10308
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10309
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10310
+ /* @__PURE__ */ jsxRuntime.jsxs(
10311
+ ui.Text,
10312
+ {
10313
+ size: "small",
10314
+ leading: "compact",
10315
+ className: "text-ui-fg-subtle",
10316
+ children: [
10317
+ "(",
10318
+ item.variant_title,
10319
+ ")"
10320
+ ]
10321
+ }
10322
+ )
10065
10323
  ] }),
10066
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10067
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10068
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10069
- ] }) })
10070
- ]
10071
- }
10072
- ) });
10073
- };
10074
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10075
- return /* @__PURE__ */ jsxRuntime.jsx(
10076
- "input",
10077
- {
10078
- ref,
10079
- ...props,
10080
- autoComplete: "off",
10081
- className: ui.clx(
10082
- "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",
10083
- className
10084
- )
10085
- }
10086
- );
10087
- });
10088
- GridInput.displayName = "MetadataForm.GridInput";
10089
- const PlaceholderInner = () => {
10090
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10091
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10092
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10093
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10094
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10095
- ] }) })
10096
- ] });
10097
- };
10098
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10099
- function getDefaultValues(metadata) {
10100
- if (!metadata || !Object.keys(metadata).length) {
10101
- return [
10324
+ /* @__PURE__ */ jsxRuntime.jsx(
10325
+ ui.Text,
10326
+ {
10327
+ size: "small",
10328
+ leading: "compact",
10329
+ className: "text-ui-fg-subtle",
10330
+ children: item.variant_sku
10331
+ }
10332
+ )
10333
+ ] })
10334
+ ] }),
10335
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
10336
+ Form$2.Field,
10102
10337
  {
10103
- key: "",
10104
- value: "",
10105
- disabled: false
10338
+ control: form.control,
10339
+ name: "quantity",
10340
+ render: ({ field }) => {
10341
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10342
+ }
10106
10343
  }
10107
- ];
10108
- }
10109
- return Object.entries(metadata).map(([key, value]) => {
10110
- if (!EDITABLE_TYPES.includes(typeof value)) {
10111
- return {
10112
- key,
10113
- value,
10114
- disabled: true
10115
- };
10116
- }
10117
- let stringValue = value;
10118
- if (typeof value !== "string") {
10119
- stringValue = JSON.stringify(value);
10120
- }
10121
- return {
10122
- key,
10123
- value: stringValue,
10124
- original_key: key
10125
- };
10126
- });
10127
- }
10128
- function parseValues(values) {
10129
- const metadata = values.metadata;
10130
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10131
- if (isEmpty) {
10132
- return null;
10133
- }
10134
- const update = {};
10135
- metadata.forEach((field) => {
10136
- let key = field.key;
10137
- let value = field.value;
10138
- const disabled = field.disabled;
10139
- if (!key || !value) {
10140
- return;
10141
- }
10142
- if (disabled) {
10143
- update[key] = value;
10144
- return;
10145
- }
10146
- key = key.trim();
10147
- value = value.trim();
10148
- if (value === "true") {
10149
- update[key] = true;
10150
- } else if (value === "false") {
10151
- update[key] = false;
10152
- } else {
10153
- const parsedNumber = parseFloat(value);
10154
- if (!isNaN(parsedNumber)) {
10155
- update[key] = parsedNumber;
10156
- } else {
10157
- update[key] = value;
10158
- }
10159
- }
10160
- });
10161
- return update;
10162
- }
10163
- function getHasUneditableRows(metadata) {
10164
- if (!metadata) {
10165
- return false;
10166
- }
10167
- return Object.values(metadata).some(
10168
- (value) => !EDITABLE_TYPES.includes(typeof value)
10169
- );
10170
- }
10171
- const NumberInput = React.forwardRef(
10172
- ({
10173
- value,
10174
- onChange,
10175
- size = "base",
10176
- min = 0,
10177
- max = 100,
10178
- step = 1,
10179
- className,
10180
- disabled,
10181
- ...props
10182
- }, ref) => {
10183
- const handleChange = (event) => {
10184
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10185
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10186
- onChange(newValue);
10187
- }
10188
- };
10189
- const handleIncrement = () => {
10190
- const newValue = value + step;
10191
- if (max === void 0 || newValue <= max) {
10192
- onChange(newValue);
10193
- }
10194
- };
10195
- const handleDecrement = () => {
10196
- const newValue = value - step;
10197
- if (min === void 0 || newValue >= min) {
10198
- onChange(newValue);
10199
- }
10200
- };
10201
- return /* @__PURE__ */ jsxRuntime.jsxs(
10202
- "div",
10344
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10345
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
10346
+ Form$2.Field,
10203
10347
  {
10204
- className: ui.clx(
10205
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10206
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10207
- {
10208
- "h-7": size === "small",
10209
- "h-8": size === "base"
10210
- },
10211
- className
10212
- ),
10213
- children: [
10214
- /* @__PURE__ */ jsxRuntime.jsx(
10215
- "input",
10216
- {
10217
- ref,
10218
- type: "number",
10219
- value,
10220
- onChange: handleChange,
10221
- min,
10222
- max,
10223
- step,
10224
- className: ui.clx(
10225
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10226
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10227
- "placeholder:text-ui-fg-muted"
10228
- ),
10229
- ...props
10230
- }
10231
- ),
10232
- /* @__PURE__ */ jsxRuntime.jsxs(
10233
- "button",
10234
- {
10235
- className: ui.clx(
10236
- "flex items-center justify-center outline-none transition-fg",
10237
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10238
- "focus:bg-ui-bg-field-component-hover",
10239
- "hover:bg-ui-bg-field-component-hover",
10240
- {
10241
- "size-7": size === "small",
10242
- "size-8": size === "base"
10243
- }
10244
- ),
10245
- type: "button",
10246
- onClick: handleDecrement,
10247
- disabled: min !== void 0 && value <= min || disabled,
10248
- children: [
10249
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10250
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10251
- ]
10252
- }
10253
- ),
10254
- /* @__PURE__ */ jsxRuntime.jsxs(
10255
- "button",
10348
+ control: form.control,
10349
+ name: "unit_price",
10350
+ render: ({ field: { onChange, ...field } }) => {
10351
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10352
+ ui.CurrencyInput,
10256
10353
  {
10257
- className: ui.clx(
10258
- "flex items-center justify-center outline-none transition-fg",
10259
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10260
- "focus:bg-ui-bg-field-hover",
10261
- "hover:bg-ui-bg-field-hover",
10262
- {
10263
- "size-7": size === "small",
10264
- "size-8": size === "base"
10265
- }
10266
- ),
10267
- type: "button",
10268
- onClick: handleIncrement,
10269
- disabled: max !== void 0 && value >= max || disabled,
10270
- children: [
10271
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10272
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10273
- ]
10354
+ ...field,
10355
+ symbol: getNativeSymbol(currencyCode),
10356
+ code: currencyCode,
10357
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10274
10358
  }
10275
- )
10276
- ]
10359
+ ) }) });
10360
+ }
10277
10361
  }
10278
- );
10279
- }
10280
- );
10281
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10282
- const productVariantsQueryKeys = {
10283
- list: (query2) => [
10284
- PRODUCT_VARIANTS_QUERY_KEY,
10285
- query2 ? query2 : void 0
10286
- ]
10287
- };
10288
- const useProductVariants = (query2, options) => {
10289
- const { data, ...rest } = reactQuery.useQuery({
10290
- queryKey: productVariantsQueryKeys.list(query2),
10291
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10292
- ...options
10293
- });
10294
- return { ...data, ...rest };
10295
- };
10296
- const useCancelOrderEdit = ({ preview }) => {
10297
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10298
- const onCancel = React.useCallback(async () => {
10299
- if (!preview) {
10300
- return true;
10301
- }
10302
- let res = false;
10303
- await cancelOrderEdit(void 0, {
10304
- onError: (e) => {
10305
- ui.toast.error(e.message);
10306
- },
10307
- onSuccess: () => {
10308
- res = true;
10362
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10363
+ /* @__PURE__ */ jsxRuntime.jsx(
10364
+ ui.IconButton,
10365
+ {
10366
+ type: "button",
10367
+ size: "small",
10368
+ onClick: editing ? onSubmit : () => {
10369
+ setEditing(true);
10370
+ },
10371
+ disabled: isPending,
10372
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10309
10373
  }
10310
- });
10311
- return res;
10312
- }, [preview, cancelOrderEdit]);
10313
- return { onCancel };
10374
+ )
10375
+ ] }) }) });
10314
10376
  };
10315
- let IS_REQUEST_RUNNING = false;
10316
- const useInitiateOrderEdit = ({
10317
- preview
10318
- }) => {
10319
- const navigate = reactRouterDom.useNavigate();
10320
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10377
+ const variantItemSchema = objectType({
10378
+ quantity: numberType(),
10379
+ unit_price: unionType([numberType(), stringType()])
10380
+ });
10381
+ const CustomItem = ({ item, preview, currencyCode }) => {
10382
+ const [editing, setEditing] = React.useState(false);
10383
+ const { quantity, unit_price, title } = item;
10384
+ const form = reactHookForm.useForm({
10385
+ defaultValues: {
10386
+ title,
10387
+ quantity,
10388
+ unit_price
10389
+ },
10390
+ resolver: zod.zodResolver(customItemSchema)
10391
+ });
10321
10392
  React.useEffect(() => {
10322
- async function run() {
10323
- if (IS_REQUEST_RUNNING || !preview) {
10324
- return;
10325
- }
10326
- if (preview.order_change) {
10327
- return;
10328
- }
10329
- IS_REQUEST_RUNNING = true;
10330
- await mutateAsync(void 0, {
10331
- onError: (e) => {
10332
- ui.toast.error(e.message);
10333
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10334
- return;
10335
- }
10336
- });
10337
- IS_REQUEST_RUNNING = false;
10338
- }
10339
- run();
10340
- }, [preview, navigate, mutateAsync]);
10341
- };
10342
- function convertNumber(value) {
10343
- return typeof value === "string" ? Number(value.replace(",", ".")) : value;
10344
- }
10345
- const STACKED_MODAL_ID = "items_stacked_modal";
10346
- const Items = () => {
10347
- const { id } = reactRouterDom.useParams();
10348
- const {
10349
- order: preview,
10350
- isPending: isPreviewPending,
10351
- isError: isPreviewError,
10352
- error: previewError
10353
- } = useOrderPreview(id, void 0, {
10354
- placeholderData: reactQuery.keepPreviousData
10355
- });
10356
- useInitiateOrderEdit({ preview });
10357
- const { draft_order, isPending, isError, error } = useDraftOrder(
10358
- id,
10359
- {
10360
- fields: "currency_code"
10361
- },
10362
- {
10363
- enabled: !!id
10364
- }
10365
- );
10366
- const { onCancel } = useCancelOrderEdit({ preview });
10367
- if (isError) {
10368
- throw error;
10369
- }
10370
- if (isPreviewError) {
10371
- throw previewError;
10372
- }
10373
- const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
10374
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsxRuntime.jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10375
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Items" }) }),
10376
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
10377
- ] }) });
10378
- };
10379
- const ItemsForm = ({ preview, currencyCode }) => {
10380
- var _a;
10381
- const [isSubmitting, setIsSubmitting] = React.useState(false);
10382
- const [modalContent, setModalContent] = React.useState(
10383
- null
10384
- );
10385
- const { handleSuccess } = useRouteModal();
10386
- const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
10387
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
10388
- const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
10389
- const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
10390
- const matches = React.useMemo(() => {
10391
- return matchSorter.matchSorter(preview.items, query2, {
10392
- keys: ["product_title", "variant_title", "variant_sku", "title"]
10393
- });
10394
- }, [preview.items, query2]);
10395
- const onSubmit = async () => {
10396
- setIsSubmitting(true);
10397
- let requestSucceeded = false;
10398
- await requestOrderEdit(void 0, {
10399
- onError: (e) => {
10400
- ui.toast.error(`Failed to request order edit: ${e.message}`);
10401
- },
10402
- onSuccess: () => {
10403
- requestSucceeded = true;
10404
- }
10405
- });
10406
- if (!requestSucceeded) {
10407
- setIsSubmitting(false);
10408
- return;
10409
- }
10410
- await confirmOrderEdit(void 0, {
10411
- onError: (e) => {
10412
- ui.toast.error(`Failed to confirm order edit: ${e.message}`);
10413
- },
10414
- onSuccess: () => {
10415
- handleSuccess();
10416
- },
10417
- onSettled: () => {
10418
- setIsSubmitting(false);
10419
- }
10420
- });
10421
- };
10422
- const onKeyDown = React.useCallback(
10423
- (e) => {
10424
- if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
10425
- if (modalContent || isSubmitting) {
10426
- return;
10427
- }
10428
- onSubmit();
10429
- }
10430
- },
10431
- [modalContent, isSubmitting, onSubmit]
10432
- );
10433
- React.useEffect(() => {
10434
- document.addEventListener("keydown", onKeyDown);
10435
- return () => {
10436
- document.removeEventListener("keydown", onKeyDown);
10437
- };
10438
- }, [onKeyDown]);
10439
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
10440
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
10441
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsxs(
10442
- StackedFocusModal,
10443
- {
10444
- id: STACKED_MODAL_ID,
10445
- onOpenChangeCallback: (open) => {
10446
- if (!open) {
10447
- setModalContent(null);
10448
- }
10449
- },
10450
- children: [
10451
- /* @__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: [
10452
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10453
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Items" }) }),
10454
- /* @__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." }) })
10455
- ] }),
10456
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10457
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
10458
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
10459
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10460
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
10461
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
10462
- ] }),
10463
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
10464
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10465
- ui.Input,
10466
- {
10467
- type: "search",
10468
- placeholder: "Search items",
10469
- value: searchValue,
10470
- onChange: (e) => onSearchValueChange(e.target.value)
10471
- }
10472
- ) }),
10473
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10474
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { type: "button", children: /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) }) }),
10475
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10476
- /* @__PURE__ */ jsxRuntime.jsx(
10477
- StackedModalTrigger$1,
10478
- {
10479
- type: "add-items",
10480
- setModalContent
10481
- }
10482
- ),
10483
- /* @__PURE__ */ jsxRuntime.jsx(
10484
- StackedModalTrigger$1,
10485
- {
10486
- type: "add-custom-item",
10487
- setModalContent
10488
- }
10489
- )
10490
- ] })
10491
- ] })
10492
- ] })
10493
- ] }),
10494
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
10495
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_1fr_1fr_28px] gap-3 px-4 py-2 text-ui-fg-muted", children: [
10496
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
10497
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) }),
10498
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-right", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Price" }) }),
10499
- /* @__PURE__ */ jsxRuntime.jsx("div", {})
10500
- ] }) }),
10501
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10502
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
10503
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
10504
- ] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
10505
- Item,
10506
- {
10507
- item,
10508
- preview,
10509
- currencyCode
10510
- },
10511
- item.id
10512
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
10513
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
10514
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
10515
- 'No items found for "',
10516
- query2,
10517
- '".'
10518
- ] })
10519
- ] }) })
10520
- ] })
10521
- ] }),
10522
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10523
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
10524
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
10525
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsxs(
10526
- ui.Text,
10527
- {
10528
- size: "small",
10529
- leading: "compact",
10530
- className: "text-ui-fg-subtle",
10531
- children: [
10532
- itemCount,
10533
- " ",
10534
- itemCount === 1 ? "item" : "items"
10535
- ]
10536
- }
10537
- ) }),
10538
- /* @__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) }) })
10539
- ] })
10540
- ] }) }),
10541
- modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsxRuntime.jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsxRuntime.jsx(
10542
- CustomItemForm,
10543
- {
10544
- orderId: preview.id,
10545
- currencyCode
10546
- }
10547
- ) : null)
10548
- ]
10549
- }
10550
- ) }),
10551
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2 justify-end", children: [
10552
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10553
- /* @__PURE__ */ jsxRuntime.jsx(
10554
- ui.Button,
10555
- {
10556
- size: "small",
10557
- type: "button",
10558
- onClick: onSubmit,
10559
- isLoading: isSubmitting,
10560
- children: "Save"
10561
- }
10562
- )
10563
- ] }) })
10564
- ] });
10565
- };
10566
- const Item = ({ item, preview, currencyCode }) => {
10567
- if (item.variant_id) {
10568
- return /* @__PURE__ */ jsxRuntime.jsx(VariantItem, { item, preview, currencyCode });
10569
- }
10570
- return /* @__PURE__ */ jsxRuntime.jsx(CustomItem, { item, preview, currencyCode });
10571
- };
10572
- const VariantItem = ({ item, preview, currencyCode }) => {
10573
- const [editing, setEditing] = React.useState(false);
10574
- const form = reactHookForm.useForm({
10575
- defaultValues: {
10576
- quantity: item.quantity,
10577
- unit_price: item.unit_price
10578
- },
10579
- resolver: zod.zodResolver(variantItemSchema)
10580
- });
10581
- const actionId = React.useMemo(() => {
10582
- var _a, _b;
10583
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10584
- }, [item]);
10585
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10586
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10587
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10588
- const onSubmit = form.handleSubmit(async (data) => {
10589
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10590
- setEditing(false);
10591
- return;
10393
+ form.reset({
10394
+ title,
10395
+ quantity,
10396
+ unit_price
10397
+ });
10398
+ }, [form, title, quantity, unit_price]);
10399
+ const actionId = React.useMemo(() => {
10400
+ var _a, _b;
10401
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10402
+ }, [item]);
10403
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10404
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10405
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10406
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10407
+ const onSubmit = form.handleSubmit(async (data) => {
10408
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10409
+ setEditing(false);
10410
+ return;
10592
10411
  }
10593
10412
  if (!actionId) {
10594
10413
  await updateOriginalItem(
@@ -10606,165 +10425,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10606
10425
  }
10607
10426
  }
10608
10427
  );
10609
- return;
10610
- }
10611
- await updateActionItem(
10612
- {
10613
- action_id: actionId,
10614
- quantity: data.quantity,
10615
- unit_price: convertNumber(data.unit_price)
10616
- },
10617
- {
10618
- onSuccess: () => {
10619
- setEditing(false);
10620
- },
10621
- onError: (e) => {
10622
- ui.toast.error(e.message);
10623
- }
10624
- }
10625
- );
10626
- });
10627
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-[minmax(0,1fr)_minmax(0,1fr)_minmax(0,1fr)_28px] gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center", children: [
10628
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3 w-full", children: [
10629
- /* @__PURE__ */ jsxRuntime.jsx(
10630
- Thumbnail,
10631
- {
10632
- thumbnail: item.thumbnail,
10633
- alt: item.product_title ?? void 0
10634
- }
10635
- ),
10636
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10637
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10638
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10639
- /* @__PURE__ */ jsxRuntime.jsxs(
10640
- ui.Text,
10641
- {
10642
- size: "small",
10643
- leading: "compact",
10644
- className: "text-ui-fg-subtle",
10645
- children: [
10646
- "(",
10647
- item.variant_title,
10648
- ")"
10649
- ]
10650
- }
10651
- )
10652
- ] }),
10653
- /* @__PURE__ */ jsxRuntime.jsx(
10654
- ui.Text,
10655
- {
10656
- size: "small",
10657
- leading: "compact",
10658
- className: "text-ui-fg-subtle",
10659
- children: item.variant_sku
10660
- }
10661
- )
10662
- ] })
10663
- ] }),
10664
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
10665
- Form$2.Field,
10666
- {
10667
- control: form.control,
10668
- name: "quantity",
10669
- render: ({ field }) => {
10670
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10671
- }
10672
- }
10673
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10674
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 w-full", children: /* @__PURE__ */ jsxRuntime.jsx(
10675
- Form$2.Field,
10676
- {
10677
- control: form.control,
10678
- name: "unit_price",
10679
- render: ({ field: { onChange, ...field } }) => {
10680
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10681
- ui.CurrencyInput,
10682
- {
10683
- ...field,
10684
- symbol: getNativeSymbol(currencyCode),
10685
- code: currencyCode,
10686
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10687
- }
10688
- ) }) });
10689
- }
10690
- }
10691
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex-1 flex items-center justify-end w-full", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10692
- /* @__PURE__ */ jsxRuntime.jsx(
10693
- ui.IconButton,
10694
- {
10695
- type: "button",
10696
- size: "small",
10697
- onClick: editing ? onSubmit : () => {
10698
- setEditing(true);
10699
- },
10700
- disabled: isPending,
10701
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10702
- }
10703
- )
10704
- ] }) }) });
10705
- };
10706
- const variantItemSchema = objectType({
10707
- quantity: numberType(),
10708
- unit_price: unionType([numberType(), stringType()])
10709
- });
10710
- const CustomItem = ({ item, preview, currencyCode }) => {
10711
- const [editing, setEditing] = React.useState(false);
10712
- const { quantity, unit_price, title } = item;
10713
- const form = reactHookForm.useForm({
10714
- defaultValues: {
10715
- title,
10716
- quantity,
10717
- unit_price
10718
- },
10719
- resolver: zod.zodResolver(customItemSchema)
10720
- });
10721
- React.useEffect(() => {
10722
- form.reset({
10723
- title,
10724
- quantity,
10725
- unit_price
10726
- });
10727
- }, [form, title, quantity, unit_price]);
10728
- const actionId = React.useMemo(() => {
10729
- var _a, _b;
10730
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10731
- }, [item]);
10732
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10733
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10734
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10735
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10736
- const onSubmit = form.handleSubmit(async (data) => {
10737
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10738
- setEditing(false);
10739
- return;
10740
- }
10741
- if (!actionId) {
10742
- await updateOriginalItem(
10743
- {
10744
- item_id: item.id,
10745
- quantity: data.quantity,
10746
- unit_price: convertNumber(data.unit_price)
10747
- },
10748
- {
10749
- onSuccess: () => {
10750
- setEditing(false);
10751
- },
10752
- onError: (e) => {
10753
- ui.toast.error(e.message);
10754
- }
10755
- }
10756
- );
10757
- return;
10758
- }
10759
- if (data.quantity === 0) {
10760
- await removeActionItem(actionId, {
10761
- onSuccess: () => {
10762
- setEditing(false);
10763
- },
10764
- onError: (e) => {
10765
- ui.toast.error(e.message);
10766
- }
10767
- });
10428
+ return;
10429
+ }
10430
+ if (data.quantity === 0) {
10431
+ await removeActionItem(actionId, {
10432
+ onSuccess: () => {
10433
+ setEditing(false);
10434
+ },
10435
+ onError: (e) => {
10436
+ ui.toast.error(e.message);
10437
+ }
10438
+ });
10768
10439
  return;
10769
10440
  }
10770
10441
  await updateActionItem(
@@ -11142,1131 +10813,781 @@ const customItemSchema = objectType({
11142
10813
  quantity: numberType(),
11143
10814
  unit_price: unionType([numberType(), stringType()])
11144
10815
  });
11145
- const CustomItems = () => {
10816
+ const InlineTip = React.forwardRef(
10817
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10818
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10819
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10820
+ "div",
10821
+ {
10822
+ ref,
10823
+ className: ui.clx(
10824
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10825
+ className
10826
+ ),
10827
+ ...props,
10828
+ children: [
10829
+ /* @__PURE__ */ jsxRuntime.jsx(
10830
+ "div",
10831
+ {
10832
+ role: "presentation",
10833
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10834
+ "bg-ui-tag-orange-icon": variant === "warning"
10835
+ })
10836
+ }
10837
+ ),
10838
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10839
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10840
+ labelValue,
10841
+ ":"
10842
+ ] }),
10843
+ " ",
10844
+ children
10845
+ ] })
10846
+ ]
10847
+ }
10848
+ );
10849
+ }
10850
+ );
10851
+ InlineTip.displayName = "InlineTip";
10852
+ const MetadataFieldSchema = objectType({
10853
+ key: stringType(),
10854
+ disabled: booleanType().optional(),
10855
+ value: anyType()
10856
+ });
10857
+ const MetadataSchema = objectType({
10858
+ metadata: arrayType(MetadataFieldSchema)
10859
+ });
10860
+ const Metadata = () => {
10861
+ const { id } = reactRouterDom.useParams();
10862
+ const { order, isPending, isError, error } = useOrder(id, {
10863
+ fields: "metadata"
10864
+ });
10865
+ if (isError) {
10866
+ throw error;
10867
+ }
10868
+ const isReady = !isPending && !!order;
11146
10869
  return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11147
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
11148
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
10870
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10871
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10872
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10873
+ ] }),
10874
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
11149
10875
  ] });
11150
10876
  };
11151
- const CustomItemsForm = () => {
10877
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10878
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10879
+ const MetadataForm = ({ orderId, metadata }) => {
10880
+ const { handleSuccess } = useRouteModal();
10881
+ const hasUneditableRows = getHasUneditableRows(metadata);
10882
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
11152
10883
  const form = reactHookForm.useForm({
11153
- resolver: zod.zodResolver(schema$3)
10884
+ defaultValues: {
10885
+ metadata: getDefaultValues(metadata)
10886
+ },
10887
+ resolver: zod.zodResolver(MetadataSchema)
11154
10888
  });
11155
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11156
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
11157
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11158
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11159
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
11160
- ] }) })
11161
- ] }) });
11162
- };
11163
- const schema$3 = objectType({
11164
- email: stringType().email()
11165
- });
11166
- const PROMOTION_QUERY_KEY = "promotions";
11167
- const promotionsQueryKeys = {
11168
- list: (query2) => [
11169
- PROMOTION_QUERY_KEY,
11170
- query2 ? query2 : void 0
11171
- ],
11172
- detail: (id, query2) => [
11173
- PROMOTION_QUERY_KEY,
11174
- id,
11175
- query2 ? query2 : void 0
11176
- ]
11177
- };
11178
- const usePromotions = (query2, options) => {
11179
- const { data, ...rest } = reactQuery.useQuery({
11180
- queryKey: promotionsQueryKeys.list(query2),
11181
- queryFn: async () => sdk.admin.promotion.list(query2),
11182
- ...options
11183
- });
11184
- return { ...data, ...rest };
11185
- };
11186
- const Promotions = () => {
11187
- const { id } = reactRouterDom.useParams();
11188
- const {
11189
- order: preview,
11190
- isError: isPreviewError,
11191
- error: previewError
11192
- } = useOrderPreview(id, void 0);
11193
- useInitiateOrderEdit({ preview });
11194
- const { onCancel } = useCancelOrderEdit({ preview });
11195
- if (isPreviewError) {
11196
- throw previewError;
11197
- }
11198
- const isReady = !!preview;
11199
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11200
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11201
- isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11202
- ] });
11203
- };
11204
- const PromotionForm = ({ preview }) => {
11205
- const { items, shipping_methods } = preview;
11206
- const [isSubmitting, setIsSubmitting] = React.useState(false);
11207
- const [comboboxValue, setComboboxValue] = React.useState("");
11208
- const { handleSuccess } = useRouteModal();
11209
- const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11210
- const promoCodes = getPromotionCodes(items, shipping_methods);
11211
- const { promotions, isPending, isError, error } = usePromotions(
11212
- {
11213
- code: promoCodes
11214
- },
11215
- {
11216
- enabled: !!promoCodes.length
11217
- }
11218
- );
11219
- const comboboxData = useComboboxData({
11220
- queryKey: ["promotions", "combobox", promoCodes],
11221
- queryFn: async (params) => {
11222
- return await sdk.admin.promotion.list({
11223
- ...params,
11224
- code: {
11225
- $nin: promoCodes
11226
- }
11227
- });
11228
- },
11229
- getOptions: (data) => {
11230
- return data.promotions.map((promotion) => ({
11231
- label: promotion.code,
11232
- value: promotion.code
11233
- }));
11234
- }
11235
- });
11236
- const add = async (value) => {
11237
- if (!value) {
11238
- return;
11239
- }
11240
- addPromotions(
10889
+ const handleSubmit = form.handleSubmit(async (data) => {
10890
+ const parsedData = parseValues(data);
10891
+ await mutateAsync(
11241
10892
  {
11242
- promo_codes: [value]
10893
+ metadata: parsedData
11243
10894
  },
11244
10895
  {
11245
- onError: (e) => {
11246
- ui.toast.error(e.message);
11247
- comboboxData.onSearchValueChange("");
11248
- setComboboxValue("");
11249
- },
11250
10896
  onSuccess: () => {
11251
- comboboxData.onSearchValueChange("");
11252
- setComboboxValue("");
10897
+ ui.toast.success("Metadata updated");
10898
+ handleSuccess();
10899
+ },
10900
+ onError: (error) => {
10901
+ ui.toast.error(error.message);
11253
10902
  }
11254
10903
  }
11255
10904
  );
11256
- };
11257
- const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11258
- const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11259
- const onSubmit = async () => {
11260
- setIsSubmitting(true);
11261
- let requestSucceeded = false;
11262
- await requestOrderEdit(void 0, {
11263
- onError: (e) => {
11264
- ui.toast.error(e.message);
11265
- },
11266
- onSuccess: () => {
11267
- requestSucceeded = true;
11268
- }
11269
- });
11270
- if (!requestSucceeded) {
11271
- setIsSubmitting(false);
11272
- return;
10905
+ });
10906
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10907
+ control: form.control,
10908
+ name: "metadata"
10909
+ });
10910
+ function deleteRow(index) {
10911
+ remove(index);
10912
+ if (fields.length === 1) {
10913
+ insert(0, {
10914
+ key: "",
10915
+ value: "",
10916
+ disabled: false
10917
+ });
11273
10918
  }
11274
- await confirmOrderEdit(void 0, {
11275
- onError: (e) => {
11276
- ui.toast.error(e.message);
11277
- },
11278
- onSuccess: () => {
11279
- handleSuccess();
11280
- },
11281
- onSettled: () => {
11282
- setIsSubmitting(false);
11283
- }
10919
+ }
10920
+ function insertRow(index, position) {
10921
+ insert(index + (position === "above" ? 0 : 1), {
10922
+ key: "",
10923
+ value: "",
10924
+ disabled: false
11284
10925
  });
11285
- };
11286
- if (isError) {
11287
- throw error;
11288
10926
  }
11289
- return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11290
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11291
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11292
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11293
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11294
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11295
- ] }),
11296
- /* @__PURE__ */ jsxRuntime.jsx(
11297
- Combobox,
11298
- {
11299
- id: "promotion-combobox",
11300
- "aria-describedby": "promotion-combobox-hint",
11301
- isFetchingNextPage: comboboxData.isFetchingNextPage,
11302
- fetchNextPage: comboboxData.fetchNextPage,
11303
- options: comboboxData.options,
11304
- onSearchValueChange: comboboxData.onSearchValueChange,
11305
- searchValue: comboboxData.searchValue,
11306
- disabled: comboboxData.disabled || isAddingPromotions,
11307
- onChange: add,
11308
- value: comboboxValue
11309
- }
11310
- )
11311
- ] }),
11312
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11313
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11314
- PromotionItem,
11315
- {
11316
- promotion,
11317
- orderId: preview.id,
11318
- isLoading: isPending
11319
- },
11320
- promotion.id
11321
- )) })
11322
- ] }) }),
11323
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11324
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11325
- /* @__PURE__ */ jsxRuntime.jsx(
11326
- ui.Button,
11327
- {
11328
- size: "small",
11329
- type: "submit",
11330
- isLoading: isSubmitting || isAddingPromotions,
11331
- children: "Save"
11332
- }
11333
- )
11334
- ] }) })
11335
- ] });
11336
- };
11337
- const PromotionItem = ({
11338
- promotion,
11339
- orderId,
11340
- isLoading
11341
- }) => {
11342
- var _a;
11343
- const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11344
- const onRemove = async () => {
11345
- removePromotions(
11346
- {
11347
- promo_codes: [promotion.code]
11348
- },
11349
- {
11350
- onError: (e) => {
11351
- ui.toast.error(e.message);
11352
- }
11353
- }
11354
- );
11355
- };
11356
- const displayValue = getDisplayValue(promotion);
11357
- return /* @__PURE__ */ jsxRuntime.jsxs(
11358
- "div",
10927
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10928
+ KeyboundForm,
11359
10929
  {
11360
- className: ui.clx(
11361
- "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
11362
- {
11363
- "animate-pulse": isLoading
11364
- }
11365
- ),
10930
+ onSubmit: handleSubmit,
10931
+ className: "flex flex-1 flex-col overflow-hidden",
11366
10932
  children: [
11367
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11368
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11369
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
11370
- displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11371
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11372
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
10933
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10934
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10935
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10936
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10937
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
11373
10938
  ] }),
11374
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11375
- ] })
11376
- ] }),
11377
- /* @__PURE__ */ jsxRuntime.jsx(
11378
- ui.IconButton,
11379
- {
11380
- size: "small",
11381
- type: "button",
11382
- variant: "transparent",
11383
- onClick: onRemove,
11384
- isLoading: isPending || isLoading,
11385
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11386
- }
11387
- )
11388
- ]
11389
- },
11390
- promotion.id
11391
- );
11392
- };
11393
- function getDisplayValue(promotion) {
11394
- var _a, _b, _c, _d;
11395
- const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11396
- if (!value) {
11397
- return null;
11398
- }
11399
- if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11400
- const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11401
- if (!currency) {
11402
- return null;
11403
- }
11404
- return getLocaleAmount(value, currency);
11405
- } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11406
- return formatPercentage(value);
11407
- }
11408
- return null;
11409
- }
11410
- const formatter = new Intl.NumberFormat([], {
11411
- style: "percent",
11412
- minimumFractionDigits: 2
10939
+ fields.map((field, index) => {
10940
+ const isDisabled = field.disabled || false;
10941
+ let placeholder = "-";
10942
+ if (typeof field.value === "object") {
10943
+ placeholder = "{ ... }";
10944
+ }
10945
+ if (Array.isArray(field.value)) {
10946
+ placeholder = "[ ... ]";
10947
+ }
10948
+ return /* @__PURE__ */ jsxRuntime.jsx(
10949
+ ConditionalTooltip,
10950
+ {
10951
+ showTooltip: isDisabled,
10952
+ content: "This row is disabled because it contains non-primitive data.",
10953
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10954
+ /* @__PURE__ */ jsxRuntime.jsxs(
10955
+ "div",
10956
+ {
10957
+ className: ui.clx("grid grid-cols-2 divide-x", {
10958
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10959
+ }),
10960
+ children: [
10961
+ /* @__PURE__ */ jsxRuntime.jsx(
10962
+ Form$2.Field,
10963
+ {
10964
+ control: form.control,
10965
+ name: `metadata.${index}.key`,
10966
+ render: ({ field: field2 }) => {
10967
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10968
+ GridInput,
10969
+ {
10970
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10971
+ ...field2,
10972
+ disabled: isDisabled,
10973
+ placeholder: "Key"
10974
+ }
10975
+ ) }) });
10976
+ }
10977
+ }
10978
+ ),
10979
+ /* @__PURE__ */ jsxRuntime.jsx(
10980
+ Form$2.Field,
10981
+ {
10982
+ control: form.control,
10983
+ name: `metadata.${index}.value`,
10984
+ render: ({ field: { value, ...field2 } }) => {
10985
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10986
+ GridInput,
10987
+ {
10988
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
10989
+ ...field2,
10990
+ value: isDisabled ? placeholder : value,
10991
+ disabled: isDisabled,
10992
+ placeholder: "Value"
10993
+ }
10994
+ ) }) });
10995
+ }
10996
+ }
10997
+ )
10998
+ ]
10999
+ }
11000
+ ),
11001
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11002
+ /* @__PURE__ */ jsxRuntime.jsx(
11003
+ ui.DropdownMenu.Trigger,
11004
+ {
11005
+ className: ui.clx(
11006
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11007
+ {
11008
+ hidden: isDisabled
11009
+ }
11010
+ ),
11011
+ disabled: isDisabled,
11012
+ asChild: true,
11013
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11014
+ }
11015
+ ),
11016
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11017
+ /* @__PURE__ */ jsxRuntime.jsxs(
11018
+ ui.DropdownMenu.Item,
11019
+ {
11020
+ className: "gap-x-2",
11021
+ onClick: () => insertRow(index, "above"),
11022
+ children: [
11023
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11024
+ "Insert row above"
11025
+ ]
11026
+ }
11027
+ ),
11028
+ /* @__PURE__ */ jsxRuntime.jsxs(
11029
+ ui.DropdownMenu.Item,
11030
+ {
11031
+ className: "gap-x-2",
11032
+ onClick: () => insertRow(index, "below"),
11033
+ children: [
11034
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11035
+ "Insert row below"
11036
+ ]
11037
+ }
11038
+ ),
11039
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11040
+ /* @__PURE__ */ jsxRuntime.jsxs(
11041
+ ui.DropdownMenu.Item,
11042
+ {
11043
+ className: "gap-x-2",
11044
+ onClick: () => deleteRow(index),
11045
+ children: [
11046
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11047
+ "Delete row"
11048
+ ]
11049
+ }
11050
+ )
11051
+ ] })
11052
+ ] })
11053
+ ] })
11054
+ },
11055
+ field.id
11056
+ );
11057
+ })
11058
+ ] }),
11059
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11060
+ ] }),
11061
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11062
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11063
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11064
+ ] }) })
11065
+ ]
11066
+ }
11067
+ ) });
11068
+ };
11069
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11070
+ return /* @__PURE__ */ jsxRuntime.jsx(
11071
+ "input",
11072
+ {
11073
+ ref,
11074
+ ...props,
11075
+ autoComplete: "off",
11076
+ className: ui.clx(
11077
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11078
+ className
11079
+ )
11080
+ }
11081
+ );
11413
11082
  });
11414
- const formatPercentage = (value, isPercentageValue = false) => {
11415
- let val = value || 0;
11416
- if (!isPercentageValue) {
11417
- val = val / 100;
11418
- }
11419
- return formatter.format(val);
11083
+ GridInput.displayName = "MetadataForm.GridInput";
11084
+ const PlaceholderInner = () => {
11085
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11086
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11087
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11088
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11089
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11090
+ ] }) })
11091
+ ] });
11420
11092
  };
11421
- function getPromotionCodes(items, shippingMethods) {
11422
- const codes = /* @__PURE__ */ new Set();
11423
- for (const item of items) {
11424
- if (item.adjustments) {
11425
- for (const adjustment of item.adjustments) {
11426
- if (adjustment.code) {
11427
- codes.add(adjustment.code);
11428
- }
11093
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11094
+ function getDefaultValues(metadata) {
11095
+ if (!metadata || !Object.keys(metadata).length) {
11096
+ return [
11097
+ {
11098
+ key: "",
11099
+ value: "",
11100
+ disabled: false
11429
11101
  }
11102
+ ];
11103
+ }
11104
+ return Object.entries(metadata).map(([key, value]) => {
11105
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11106
+ return {
11107
+ key,
11108
+ value,
11109
+ disabled: true
11110
+ };
11111
+ }
11112
+ let stringValue = value;
11113
+ if (typeof value !== "string") {
11114
+ stringValue = JSON.stringify(value);
11430
11115
  }
11116
+ return {
11117
+ key,
11118
+ value: stringValue,
11119
+ original_key: key
11120
+ };
11121
+ });
11122
+ }
11123
+ function parseValues(values) {
11124
+ const metadata = values.metadata;
11125
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11126
+ if (isEmpty) {
11127
+ return null;
11431
11128
  }
11432
- for (const shippingMethod of shippingMethods) {
11433
- if (shippingMethod.adjustments) {
11434
- for (const adjustment of shippingMethod.adjustments) {
11435
- if (adjustment.code) {
11436
- codes.add(adjustment.code);
11437
- }
11129
+ const update = {};
11130
+ metadata.forEach((field) => {
11131
+ let key = field.key;
11132
+ let value = field.value;
11133
+ const disabled = field.disabled;
11134
+ if (!key || !value) {
11135
+ return;
11136
+ }
11137
+ if (disabled) {
11138
+ update[key] = value;
11139
+ return;
11140
+ }
11141
+ key = key.trim();
11142
+ value = value.trim();
11143
+ if (value === "true") {
11144
+ update[key] = true;
11145
+ } else if (value === "false") {
11146
+ update[key] = false;
11147
+ } else {
11148
+ const parsedNumber = parseFloat(value);
11149
+ if (!isNaN(parsedNumber)) {
11150
+ update[key] = parsedNumber;
11151
+ } else {
11152
+ update[key] = value;
11438
11153
  }
11439
11154
  }
11155
+ });
11156
+ return update;
11157
+ }
11158
+ function getHasUneditableRows(metadata) {
11159
+ if (!metadata) {
11160
+ return false;
11440
11161
  }
11441
- return Array.from(codes);
11162
+ return Object.values(metadata).some(
11163
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11164
+ );
11442
11165
  }
11443
- const SalesChannel = () => {
11444
- const { id } = reactRouterDom.useParams();
11445
- const { draft_order, isPending, isError, error } = useDraftOrder(
11166
+ const PROMOTION_QUERY_KEY = "promotions";
11167
+ const promotionsQueryKeys = {
11168
+ list: (query2) => [
11169
+ PROMOTION_QUERY_KEY,
11170
+ query2 ? query2 : void 0
11171
+ ],
11172
+ detail: (id, query2) => [
11173
+ PROMOTION_QUERY_KEY,
11446
11174
  id,
11447
- {
11448
- fields: "+sales_channel_id"
11449
- },
11450
- {
11451
- enabled: !!id
11452
- }
11453
- );
11454
- if (isError) {
11455
- throw error;
11175
+ query2 ? query2 : void 0
11176
+ ]
11177
+ };
11178
+ const usePromotions = (query2, options) => {
11179
+ const { data, ...rest } = reactQuery.useQuery({
11180
+ queryKey: promotionsQueryKeys.list(query2),
11181
+ queryFn: async () => sdk.admin.promotion.list(query2),
11182
+ ...options
11183
+ });
11184
+ return { ...data, ...rest };
11185
+ };
11186
+ const Promotions = () => {
11187
+ const { id } = reactRouterDom.useParams();
11188
+ const {
11189
+ order: preview,
11190
+ isError: isPreviewError,
11191
+ error: previewError
11192
+ } = useOrderPreview(id, void 0);
11193
+ useInitiateOrderEdit({ preview });
11194
+ const { onCancel } = useCancelOrderEdit({ preview });
11195
+ if (isPreviewError) {
11196
+ throw previewError;
11456
11197
  }
11457
- const ISrEADY = !!draft_order && !isPending;
11458
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11459
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11460
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11461
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11462
- ] }),
11463
- ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11198
+ const isReady = !!preview;
11199
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
11200
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
11201
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
11464
11202
  ] });
11465
11203
  };
11466
- const SalesChannelForm = ({ order }) => {
11467
- const form = reactHookForm.useForm({
11468
- defaultValues: {
11469
- sales_channel_id: order.sales_channel_id || ""
11470
- },
11471
- resolver: zod.zodResolver(schema$2)
11472
- });
11473
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11204
+ const PromotionForm = ({ preview }) => {
11205
+ const { items, shipping_methods } = preview;
11206
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11207
+ const [comboboxValue, setComboboxValue] = React.useState("");
11474
11208
  const { handleSuccess } = useRouteModal();
11475
- const onSubmit = form.handleSubmit(async (data) => {
11476
- await mutateAsync(
11477
- {
11478
- sales_channel_id: data.sales_channel_id
11479
- },
11480
- {
11481
- onSuccess: () => {
11482
- ui.toast.success("Sales channel updated");
11483
- handleSuccess();
11484
- },
11485
- onError: (error) => {
11486
- ui.toast.error(error.message);
11487
- }
11488
- }
11489
- );
11490
- });
11491
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11492
- KeyboundForm,
11209
+ const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
11210
+ const promoCodes = getPromotionCodes(items, shipping_methods);
11211
+ const { promotions, isPending, isError, error } = usePromotions(
11493
11212
  {
11494
- className: "flex flex-1 flex-col overflow-hidden",
11495
- onSubmit,
11496
- children: [
11497
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11498
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11499
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11500
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11501
- ] }) })
11502
- ]
11213
+ code: promoCodes
11214
+ },
11215
+ {
11216
+ enabled: !!promoCodes.length
11503
11217
  }
11504
- ) });
11505
- };
11506
- const SalesChannelField = ({ control, order }) => {
11507
- const salesChannels = useComboboxData({
11218
+ );
11219
+ const comboboxData = useComboboxData({
11220
+ queryKey: ["promotions", "combobox", promoCodes],
11508
11221
  queryFn: async (params) => {
11509
- return await sdk.admin.salesChannel.list(params);
11222
+ return await sdk.admin.promotion.list({
11223
+ ...params,
11224
+ code: {
11225
+ $nin: promoCodes
11226
+ }
11227
+ });
11510
11228
  },
11511
- queryKey: ["sales-channels"],
11512
11229
  getOptions: (data) => {
11513
- return data.sales_channels.map((salesChannel) => ({
11514
- label: salesChannel.name,
11515
- value: salesChannel.id
11230
+ return data.promotions.map((promotion) => ({
11231
+ label: promotion.code,
11232
+ value: promotion.code
11516
11233
  }));
11517
- },
11518
- defaultValue: order.sales_channel_id || void 0
11519
- });
11520
- return /* @__PURE__ */ jsxRuntime.jsx(
11521
- Form$2.Field,
11522
- {
11523
- control,
11524
- name: "sales_channel_id",
11525
- render: ({ field }) => {
11526
- return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11527
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11528
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11529
- Combobox,
11530
- {
11531
- options: salesChannels.options,
11532
- fetchNextPage: salesChannels.fetchNextPage,
11533
- isFetchingNextPage: salesChannels.isFetchingNextPage,
11534
- searchValue: salesChannels.searchValue,
11535
- onSearchValueChange: salesChannels.onSearchValueChange,
11536
- placeholder: "Select sales channel",
11537
- ...field
11538
- }
11539
- ) }),
11540
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11541
- ] });
11542
- }
11543
11234
  }
11544
- );
11545
- };
11546
- const schema$2 = objectType({
11547
- sales_channel_id: stringType().min(1)
11548
- });
11549
- const ShippingAddress = () => {
11550
- const { id } = reactRouterDom.useParams();
11551
- const { order, isPending, isError, error } = useOrder(id, {
11552
- fields: "+shipping_address"
11553
- });
11554
- if (isError) {
11555
- throw error;
11556
- }
11557
- const isReady = !isPending && !!order;
11558
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11559
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11560
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
11561
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
11562
- ] }),
11563
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
11564
- ] });
11565
- };
11566
- const ShippingAddressForm = ({ order }) => {
11567
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
11568
- const form = reactHookForm.useForm({
11569
- defaultValues: {
11570
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
11571
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
11572
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
11573
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
11574
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
11575
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
11576
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
11577
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
11578
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
11579
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
11580
- },
11581
- resolver: zod.zodResolver(schema$1)
11582
11235
  });
11583
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11584
- const { handleSuccess } = useRouteModal();
11585
- const onSubmit = form.handleSubmit(async (data) => {
11586
- await mutateAsync(
11236
+ const add = async (value) => {
11237
+ if (!value) {
11238
+ return;
11239
+ }
11240
+ addPromotions(
11587
11241
  {
11588
- shipping_address: {
11589
- first_name: data.first_name,
11590
- last_name: data.last_name,
11591
- company: data.company,
11592
- address_1: data.address_1,
11593
- address_2: data.address_2,
11594
- city: data.city,
11595
- province: data.province,
11596
- country_code: data.country_code,
11597
- postal_code: data.postal_code,
11598
- phone: data.phone
11599
- }
11242
+ promo_codes: [value]
11600
11243
  },
11601
11244
  {
11602
- onSuccess: () => {
11603
- handleSuccess();
11245
+ onError: (e) => {
11246
+ ui.toast.error(e.message);
11247
+ comboboxData.onSearchValueChange("");
11248
+ setComboboxValue("");
11604
11249
  },
11605
- onError: (error) => {
11606
- ui.toast.error(error.message);
11250
+ onSuccess: () => {
11251
+ comboboxData.onSearchValueChange("");
11252
+ setComboboxValue("");
11607
11253
  }
11608
11254
  }
11609
11255
  );
11610
- });
11611
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11612
- KeyboundForm,
11613
- {
11614
- className: "flex flex-1 flex-col overflow-hidden",
11615
- onSubmit,
11616
- children: [
11617
- /* @__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: [
11618
- /* @__PURE__ */ jsxRuntime.jsx(
11619
- Form$2.Field,
11620
- {
11621
- control: form.control,
11622
- name: "country_code",
11623
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11624
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
11625
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
11626
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11627
- ] })
11628
- }
11629
- ),
11630
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11631
- /* @__PURE__ */ jsxRuntime.jsx(
11632
- Form$2.Field,
11633
- {
11634
- control: form.control,
11635
- name: "first_name",
11636
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11637
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
11638
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11639
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11640
- ] })
11641
- }
11642
- ),
11643
- /* @__PURE__ */ jsxRuntime.jsx(
11644
- Form$2.Field,
11645
- {
11646
- control: form.control,
11647
- name: "last_name",
11648
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11649
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last 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
- ] }),
11656
- /* @__PURE__ */ jsxRuntime.jsx(
11657
- Form$2.Field,
11658
- {
11659
- control: form.control,
11660
- name: "company",
11661
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11662
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
11663
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11664
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11665
- ] })
11666
- }
11667
- ),
11668
- /* @__PURE__ */ jsxRuntime.jsx(
11669
- Form$2.Field,
11670
- {
11671
- control: form.control,
11672
- name: "address_1",
11673
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11674
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
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_2",
11685
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11686
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
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.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
11693
- /* @__PURE__ */ jsxRuntime.jsx(
11694
- Form$2.Field,
11695
- {
11696
- control: form.control,
11697
- name: "postal_code",
11698
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11699
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
11700
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11701
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11702
- ] })
11703
- }
11704
- ),
11705
- /* @__PURE__ */ jsxRuntime.jsx(
11706
- Form$2.Field,
11707
- {
11708
- control: form.control,
11709
- name: "city",
11710
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11711
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
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
- ] }),
11718
- /* @__PURE__ */ jsxRuntime.jsx(
11719
- Form$2.Field,
11720
- {
11721
- control: form.control,
11722
- name: "province",
11723
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11724
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
11725
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11726
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11727
- ] })
11728
- }
11729
- ),
11730
- /* @__PURE__ */ jsxRuntime.jsx(
11731
- Form$2.Field,
11732
- {
11733
- control: form.control,
11734
- name: "phone",
11735
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11736
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
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
- ] }) }),
11743
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11744
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11745
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11746
- ] }) })
11747
- ]
11256
+ };
11257
+ const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
11258
+ const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
11259
+ const onSubmit = async () => {
11260
+ setIsSubmitting(true);
11261
+ let requestSucceeded = false;
11262
+ await requestOrderEdit(void 0, {
11263
+ onError: (e) => {
11264
+ ui.toast.error(e.message);
11265
+ },
11266
+ onSuccess: () => {
11267
+ requestSucceeded = true;
11268
+ }
11269
+ });
11270
+ if (!requestSucceeded) {
11271
+ setIsSubmitting(false);
11272
+ return;
11748
11273
  }
11749
- ) });
11750
- };
11751
- const schema$1 = addressSchema;
11752
- const TransferOwnership = () => {
11753
- const { id } = reactRouterDom.useParams();
11754
- const { draft_order, isPending, isError, error } = useDraftOrder(id, {
11755
- fields: "id,customer_id,customer.*"
11756
- });
11274
+ await confirmOrderEdit(void 0, {
11275
+ onError: (e) => {
11276
+ ui.toast.error(e.message);
11277
+ },
11278
+ onSuccess: () => {
11279
+ handleSuccess();
11280
+ },
11281
+ onSettled: () => {
11282
+ setIsSubmitting(false);
11283
+ }
11284
+ });
11285
+ };
11757
11286
  if (isError) {
11758
11287
  throw error;
11759
11288
  }
11760
- const isReady = !isPending && !!draft_order;
11761
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11762
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11763
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
11764
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
11765
- ] }),
11766
- isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
11289
+ return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
11290
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
11291
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
11292
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11293
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
11294
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
11295
+ ] }),
11296
+ /* @__PURE__ */ jsxRuntime.jsx(
11297
+ Combobox,
11298
+ {
11299
+ id: "promotion-combobox",
11300
+ "aria-describedby": "promotion-combobox-hint",
11301
+ isFetchingNextPage: comboboxData.isFetchingNextPage,
11302
+ fetchNextPage: comboboxData.fetchNextPage,
11303
+ options: comboboxData.options,
11304
+ onSearchValueChange: comboboxData.onSearchValueChange,
11305
+ searchValue: comboboxData.searchValue,
11306
+ disabled: comboboxData.disabled || isAddingPromotions,
11307
+ onChange: add,
11308
+ value: comboboxValue
11309
+ }
11310
+ )
11311
+ ] }),
11312
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11313
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
11314
+ PromotionItem,
11315
+ {
11316
+ promotion,
11317
+ orderId: preview.id,
11318
+ isLoading: isPending
11319
+ },
11320
+ promotion.id
11321
+ )) })
11322
+ ] }) }),
11323
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11324
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11325
+ /* @__PURE__ */ jsxRuntime.jsx(
11326
+ ui.Button,
11327
+ {
11328
+ size: "small",
11329
+ type: "submit",
11330
+ isLoading: isSubmitting || isAddingPromotions,
11331
+ children: "Save"
11332
+ }
11333
+ )
11334
+ ] }) })
11767
11335
  ] });
11768
11336
  };
11769
- const TransferOwnershipForm = ({ order }) => {
11770
- var _a, _b;
11771
- const form = reactHookForm.useForm({
11772
- defaultValues: {
11773
- customer_id: order.customer_id || ""
11774
- },
11775
- resolver: zod.zodResolver(schema)
11776
- });
11777
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11778
- const { handleSuccess } = useRouteModal();
11779
- const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
11780
- const currentCustomer = order.customer ? {
11781
- label: name ? `${name} (${order.customer.email})` : order.customer.email,
11782
- value: order.customer.id
11783
- } : null;
11784
- const onSubmit = form.handleSubmit(async (data) => {
11785
- await mutateAsync(
11786
- { customer_id: data.customer_id },
11337
+ const PromotionItem = ({
11338
+ promotion,
11339
+ orderId,
11340
+ isLoading
11341
+ }) => {
11342
+ var _a;
11343
+ const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
11344
+ const onRemove = async () => {
11345
+ removePromotions(
11787
11346
  {
11788
- onSuccess: () => {
11789
- ui.toast.success("Customer updated");
11790
- handleSuccess();
11791
- },
11792
- onError: (error) => {
11793
- ui.toast.error(error.message);
11347
+ promo_codes: [promotion.code]
11348
+ },
11349
+ {
11350
+ onError: (e) => {
11351
+ ui.toast.error(e.message);
11794
11352
  }
11795
11353
  }
11796
11354
  );
11797
- });
11798
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11799
- KeyboundForm,
11355
+ };
11356
+ const displayValue = getDisplayValue(promotion);
11357
+ return /* @__PURE__ */ jsxRuntime.jsxs(
11358
+ "div",
11800
11359
  {
11801
- className: "flex flex-1 flex-col overflow-hidden",
11802
- onSubmit,
11360
+ className: ui.clx(
11361
+ "px-3 py-2 rounded-lg bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between",
11362
+ {
11363
+ "animate-pulse": isLoading
11364
+ }
11365
+ ),
11803
11366
  children: [
11804
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
11805
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
11806
- currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
11807
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11808
- /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
11809
- /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
11367
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11368
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
11369
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 text-ui-fg-subtle", children: [
11370
+ displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
11371
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
11372
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
11810
11373
  ] }),
11811
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
11812
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
11813
- /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
11814
- ] })
11815
- ] }),
11816
- /* @__PURE__ */ jsxRuntime.jsx(
11817
- CustomerField,
11818
- {
11819
- control: form.control,
11820
- currentCustomerId: order.customer_id
11821
- }
11822
- )
11374
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
11375
+ ] })
11823
11376
  ] }),
11824
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11825
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
11826
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11827
- ] }) })
11377
+ /* @__PURE__ */ jsxRuntime.jsx(
11378
+ ui.IconButton,
11379
+ {
11380
+ size: "small",
11381
+ type: "button",
11382
+ variant: "transparent",
11383
+ onClick: onRemove,
11384
+ isLoading: isPending || isLoading,
11385
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
11386
+ }
11387
+ )
11388
+ ]
11389
+ },
11390
+ promotion.id
11391
+ );
11392
+ };
11393
+ function getDisplayValue(promotion) {
11394
+ var _a, _b, _c, _d;
11395
+ const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
11396
+ if (!value) {
11397
+ return null;
11398
+ }
11399
+ if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
11400
+ const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
11401
+ if (!currency) {
11402
+ return null;
11403
+ }
11404
+ return getLocaleAmount(value, currency);
11405
+ } else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
11406
+ return formatPercentage(value);
11407
+ }
11408
+ return null;
11409
+ }
11410
+ const formatter = new Intl.NumberFormat([], {
11411
+ style: "percent",
11412
+ minimumFractionDigits: 2
11413
+ });
11414
+ const formatPercentage = (value, isPercentageValue = false) => {
11415
+ let val = value || 0;
11416
+ if (!isPercentageValue) {
11417
+ val = val / 100;
11418
+ }
11419
+ return formatter.format(val);
11420
+ };
11421
+ function getPromotionCodes(items, shippingMethods) {
11422
+ const codes = /* @__PURE__ */ new Set();
11423
+ for (const item of items) {
11424
+ if (item.adjustments) {
11425
+ for (const adjustment of item.adjustments) {
11426
+ if (adjustment.code) {
11427
+ codes.add(adjustment.code);
11428
+ }
11429
+ }
11430
+ }
11431
+ }
11432
+ for (const shippingMethod of shippingMethods) {
11433
+ if (shippingMethod.adjustments) {
11434
+ for (const adjustment of shippingMethod.adjustments) {
11435
+ if (adjustment.code) {
11436
+ codes.add(adjustment.code);
11437
+ }
11438
+ }
11439
+ }
11440
+ }
11441
+ return Array.from(codes);
11442
+ }
11443
+ const SalesChannel = () => {
11444
+ const { id } = reactRouterDom.useParams();
11445
+ const { draft_order, isPending, isError, error } = useDraftOrder(
11446
+ id,
11447
+ {
11448
+ fields: "+sales_channel_id"
11449
+ },
11450
+ {
11451
+ enabled: !!id
11452
+ }
11453
+ );
11454
+ if (isError) {
11455
+ throw error;
11456
+ }
11457
+ const ISrEADY = !!draft_order && !isPending;
11458
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11459
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
11460
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
11461
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
11462
+ ] }),
11463
+ ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
11464
+ ] });
11465
+ };
11466
+ const SalesChannelForm = ({ order }) => {
11467
+ const form = reactHookForm.useForm({
11468
+ defaultValues: {
11469
+ sales_channel_id: order.sales_channel_id || ""
11470
+ },
11471
+ resolver: zod.zodResolver(schema$2)
11472
+ });
11473
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
11474
+ const { handleSuccess } = useRouteModal();
11475
+ const onSubmit = form.handleSubmit(async (data) => {
11476
+ await mutateAsync(
11477
+ {
11478
+ sales_channel_id: data.sales_channel_id
11479
+ },
11480
+ {
11481
+ onSuccess: () => {
11482
+ ui.toast.success("Sales channel updated");
11483
+ handleSuccess();
11484
+ },
11485
+ onError: (error) => {
11486
+ ui.toast.error(error.message);
11487
+ }
11488
+ }
11489
+ );
11490
+ });
11491
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
11492
+ KeyboundForm,
11493
+ {
11494
+ className: "flex flex-1 flex-col overflow-hidden",
11495
+ onSubmit,
11496
+ children: [
11497
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
11498
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11499
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11500
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
11501
+ ] }) })
11828
11502
  ]
11829
11503
  }
11830
11504
  ) });
11831
11505
  };
11832
- const CustomerField = ({ control, currentCustomerId }) => {
11833
- const customers = useComboboxData({
11506
+ const SalesChannelField = ({ control, order }) => {
11507
+ const salesChannels = useComboboxData({
11834
11508
  queryFn: async (params) => {
11835
- return await sdk.admin.customer.list({
11836
- ...params,
11837
- id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
11838
- });
11509
+ return await sdk.admin.salesChannel.list(params);
11839
11510
  },
11840
- queryKey: ["customers"],
11511
+ queryKey: ["sales-channels"],
11841
11512
  getOptions: (data) => {
11842
- return data.customers.map((customer) => {
11843
- const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
11844
- return {
11845
- label: name ? `${name} (${customer.email})` : customer.email,
11846
- value: customer.id
11847
- };
11848
- });
11849
- }
11513
+ return data.sales_channels.map((salesChannel) => ({
11514
+ label: salesChannel.name,
11515
+ value: salesChannel.id
11516
+ }));
11517
+ },
11518
+ defaultValue: order.sales_channel_id || void 0
11850
11519
  });
11851
11520
  return /* @__PURE__ */ jsxRuntime.jsx(
11852
11521
  Form$2.Field,
11853
11522
  {
11854
- name: "customer_id",
11855
11523
  control,
11856
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
11857
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
11858
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
11859
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
11860
- ] }),
11861
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11862
- Combobox,
11863
- {
11864
- options: customers.options,
11865
- fetchNextPage: customers.fetchNextPage,
11866
- isFetchingNextPage: customers.isFetchingNextPage,
11867
- searchValue: customers.searchValue,
11868
- onSearchValueChange: customers.onSearchValueChange,
11869
- placeholder: "Select customer",
11870
- ...field
11871
- }
11872
- ) }),
11873
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11874
- ] })
11524
+ name: "sales_channel_id",
11525
+ render: ({ field }) => {
11526
+ return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
11527
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
11528
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11529
+ Combobox,
11530
+ {
11531
+ options: salesChannels.options,
11532
+ fetchNextPage: salesChannels.fetchNextPage,
11533
+ isFetchingNextPage: salesChannels.isFetchingNextPage,
11534
+ searchValue: salesChannels.searchValue,
11535
+ onSearchValueChange: salesChannels.onSearchValueChange,
11536
+ placeholder: "Select sales channel",
11537
+ ...field
11538
+ }
11539
+ ) }),
11540
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11541
+ ] });
11542
+ }
11875
11543
  }
11876
11544
  );
11877
11545
  };
11878
- const Illustration = () => {
11879
- return /* @__PURE__ */ jsxRuntime.jsxs(
11880
- "svg",
11881
- {
11882
- width: "280",
11883
- height: "180",
11884
- viewBox: "0 0 280 180",
11885
- fill: "none",
11886
- xmlns: "http://www.w3.org/2000/svg",
11887
- children: [
11888
- /* @__PURE__ */ jsxRuntime.jsx(
11889
- "rect",
11890
- {
11891
- x: "0.00428286",
11892
- y: "-0.742904",
11893
- width: "33.5",
11894
- height: "65.5",
11895
- rx: "6.75",
11896
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
11897
- fill: "#D4D4D8",
11898
- stroke: "#52525B",
11899
- strokeWidth: "1.5"
11900
- }
11901
- ),
11902
- /* @__PURE__ */ jsxRuntime.jsx(
11903
- "rect",
11904
- {
11905
- x: "0.00428286",
11906
- y: "-0.742904",
11907
- width: "33.5",
11908
- height: "65.5",
11909
- rx: "6.75",
11910
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
11911
- fill: "white",
11912
- stroke: "#52525B",
11913
- strokeWidth: "1.5"
11914
- }
11915
- ),
11916
- /* @__PURE__ */ jsxRuntime.jsx(
11917
- "path",
11918
- {
11919
- d: "M180.579 107.142L179.126 107.959",
11920
- stroke: "#52525B",
11921
- strokeWidth: "1.5",
11922
- strokeLinecap: "round",
11923
- strokeLinejoin: "round"
11924
- }
11925
- ),
11926
- /* @__PURE__ */ jsxRuntime.jsx(
11927
- "path",
11928
- {
11929
- opacity: "0.88",
11930
- d: "M182.305 109.546L180.257 109.534",
11931
- stroke: "#52525B",
11932
- strokeWidth: "1.5",
11933
- strokeLinecap: "round",
11934
- strokeLinejoin: "round"
11935
- }
11936
- ),
11937
- /* @__PURE__ */ jsxRuntime.jsx(
11938
- "path",
11939
- {
11940
- opacity: "0.75",
11941
- d: "M180.551 111.93L179.108 111.096",
11942
- stroke: "#52525B",
11943
- strokeWidth: "1.5",
11944
- strokeLinecap: "round",
11945
- strokeLinejoin: "round"
11946
- }
11947
- ),
11948
- /* @__PURE__ */ jsxRuntime.jsx(
11949
- "path",
11950
- {
11951
- opacity: "0.63",
11952
- d: "M176.347 112.897L176.354 111.73",
11953
- stroke: "#52525B",
11954
- strokeWidth: "1.5",
11955
- strokeLinecap: "round",
11956
- strokeLinejoin: "round"
11957
- }
11958
- ),
11959
- /* @__PURE__ */ jsxRuntime.jsx(
11960
- "path",
11961
- {
11962
- opacity: "0.5",
11963
- d: "M172.153 111.881L173.606 111.064",
11964
- stroke: "#52525B",
11965
- strokeWidth: "1.5",
11966
- strokeLinecap: "round",
11967
- strokeLinejoin: "round"
11968
- }
11969
- ),
11970
- /* @__PURE__ */ jsxRuntime.jsx(
11971
- "path",
11972
- {
11973
- opacity: "0.38",
11974
- d: "M170.428 109.478L172.476 109.489",
11975
- stroke: "#52525B",
11976
- strokeWidth: "1.5",
11977
- strokeLinecap: "round",
11978
- strokeLinejoin: "round"
11979
- }
11980
- ),
11981
- /* @__PURE__ */ jsxRuntime.jsx(
11982
- "path",
11983
- {
11984
- opacity: "0.25",
11985
- d: "M172.181 107.094L173.624 107.928",
11986
- stroke: "#52525B",
11987
- strokeWidth: "1.5",
11988
- strokeLinecap: "round",
11989
- strokeLinejoin: "round"
11990
- }
11991
- ),
11992
- /* @__PURE__ */ jsxRuntime.jsx(
11993
- "path",
11994
- {
11995
- opacity: "0.13",
11996
- d: "M176.386 106.126L176.379 107.294",
11997
- stroke: "#52525B",
11998
- strokeWidth: "1.5",
11999
- strokeLinecap: "round",
12000
- strokeLinejoin: "round"
12001
- }
12002
- ),
12003
- /* @__PURE__ */ jsxRuntime.jsx(
12004
- "rect",
12005
- {
12006
- width: "12",
12007
- height: "3",
12008
- rx: "1.5",
12009
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12010
- fill: "#D4D4D8"
12011
- }
12012
- ),
12013
- /* @__PURE__ */ jsxRuntime.jsx(
12014
- "rect",
12015
- {
12016
- x: "0.00428286",
12017
- y: "-0.742904",
12018
- width: "33.5",
12019
- height: "65.5",
12020
- rx: "6.75",
12021
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12022
- fill: "#D4D4D8",
12023
- stroke: "#52525B",
12024
- strokeWidth: "1.5"
12025
- }
12026
- ),
12027
- /* @__PURE__ */ jsxRuntime.jsx(
12028
- "rect",
12029
- {
12030
- x: "0.00428286",
12031
- y: "-0.742904",
12032
- width: "33.5",
12033
- height: "65.5",
12034
- rx: "6.75",
12035
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12036
- fill: "white",
12037
- stroke: "#52525B",
12038
- strokeWidth: "1.5"
12039
- }
12040
- ),
12041
- /* @__PURE__ */ jsxRuntime.jsx(
12042
- "rect",
12043
- {
12044
- width: "12",
12045
- height: "3",
12046
- rx: "1.5",
12047
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12048
- fill: "#D4D4D8"
12049
- }
12050
- ),
12051
- /* @__PURE__ */ jsxRuntime.jsx(
12052
- "rect",
12053
- {
12054
- width: "17",
12055
- height: "3",
12056
- rx: "1.5",
12057
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12058
- fill: "#D4D4D8"
12059
- }
12060
- ),
12061
- /* @__PURE__ */ jsxRuntime.jsx(
12062
- "rect",
12063
- {
12064
- width: "12",
12065
- height: "3",
12066
- rx: "1.5",
12067
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12068
- fill: "#D4D4D8"
12069
- }
12070
- ),
12071
- /* @__PURE__ */ jsxRuntime.jsx(
12072
- "path",
12073
- {
12074
- d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12075
- fill: "#A1A1AA"
12076
- }
12077
- ),
12078
- /* @__PURE__ */ jsxRuntime.jsx(
12079
- "rect",
12080
- {
12081
- width: "17",
12082
- height: "3",
12083
- rx: "1.5",
12084
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12085
- fill: "#A1A1AA"
12086
- }
12087
- ),
12088
- /* @__PURE__ */ jsxRuntime.jsx(
12089
- "rect",
12090
- {
12091
- width: "12",
12092
- height: "3",
12093
- rx: "1.5",
12094
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12095
- fill: "#A1A1AA"
12096
- }
12097
- ),
12098
- /* @__PURE__ */ jsxRuntime.jsx(
12099
- "path",
12100
- {
12101
- d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12102
- fill: "#52525B"
12103
- }
12104
- ),
12105
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12106
- "path",
12107
- {
12108
- d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12109
- stroke: "#A1A1AA",
12110
- strokeWidth: "1.5",
12111
- strokeLinecap: "round",
12112
- strokeLinejoin: "round"
12113
- }
12114
- ) }),
12115
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12116
- "path",
12117
- {
12118
- d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12119
- stroke: "#A1A1AA",
12120
- strokeWidth: "1.5",
12121
- strokeLinecap: "round",
12122
- strokeLinejoin: "round"
12123
- }
12124
- ) }),
12125
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12126
- "path",
12127
- {
12128
- d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12129
- stroke: "#A1A1AA",
12130
- strokeWidth: "1.5",
12131
- strokeLinecap: "round",
12132
- strokeLinejoin: "round"
12133
- }
12134
- ) }),
12135
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12136
- "path",
12137
- {
12138
- d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12139
- stroke: "#A1A1AA",
12140
- strokeWidth: "1.5",
12141
- strokeLinecap: "round",
12142
- strokeLinejoin: "round"
12143
- }
12144
- ) }),
12145
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12146
- "path",
12147
- {
12148
- d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12149
- stroke: "#A1A1AA",
12150
- strokeWidth: "1.5",
12151
- strokeLinecap: "round",
12152
- strokeLinejoin: "round"
12153
- }
12154
- ) }),
12155
- /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12156
- "path",
12157
- {
12158
- d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12159
- stroke: "#A1A1AA",
12160
- strokeWidth: "1.5",
12161
- strokeLinecap: "round",
12162
- strokeLinejoin: "round"
12163
- }
12164
- ) }),
12165
- /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12166
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12167
- "rect",
12168
- {
12169
- width: "12",
12170
- height: "12",
12171
- fill: "white",
12172
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12173
- }
12174
- ) }),
12175
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12176
- "rect",
12177
- {
12178
- width: "12",
12179
- height: "12",
12180
- fill: "white",
12181
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12182
- }
12183
- ) }),
12184
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12185
- "rect",
12186
- {
12187
- width: "12",
12188
- height: "12",
12189
- fill: "white",
12190
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12191
- }
12192
- ) }),
12193
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12194
- "rect",
12195
- {
12196
- width: "12",
12197
- height: "12",
12198
- fill: "white",
12199
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12200
- }
12201
- ) }),
12202
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12203
- "rect",
12204
- {
12205
- width: "12",
12206
- height: "12",
12207
- fill: "white",
12208
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12209
- }
12210
- ) }),
12211
- /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12212
- "rect",
12213
- {
12214
- width: "12",
12215
- height: "12",
12216
- fill: "white",
12217
- transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12218
- }
12219
- ) })
12220
- ] })
12221
- ]
12222
- }
12223
- );
12224
- };
12225
- const schema = objectType({
12226
- customer_id: stringType().min(1)
12227
- });
12228
- const STACKED_FOCUS_MODAL_ID = "shipping-form";
12229
- const Shipping = () => {
12230
- var _a;
12231
- const { id } = reactRouterDom.useParams();
12232
- const { order, isPending, isError, error } = useOrder(id, {
12233
- fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
12234
- });
12235
- const {
12236
- order: preview,
12237
- isPending: isPreviewPending,
12238
- isError: isPreviewError,
12239
- error: previewError
12240
- } = useOrderPreview(id);
12241
- useInitiateOrderEdit({ preview });
12242
- const { onCancel } = useCancelOrderEdit({ preview });
12243
- if (isError) {
12244
- throw error;
12245
- }
12246
- if (isPreviewError) {
12247
- throw previewError;
12248
- }
12249
- const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
12250
- const isReady = preview && !isPreviewPending && order && !isPending;
12251
- return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
12252
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
12253
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12254
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12255
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
12256
- ] }) }) }),
12257
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
12258
- ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12259
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
12260
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
12261
- ] }) });
12262
- };
12263
- const ShippingForm = ({ preview, order }) => {
12264
- var _a;
12265
- const { setIsOpen } = useStackedModal();
12266
- const [isSubmitting, setIsSubmitting] = React.useState(false);
12267
- const [data, setData] = React.useState(null);
12268
- const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
12269
- const { shipping_options } = useShippingOptions(
11546
+ const schema$2 = objectType({
11547
+ sales_channel_id: stringType().min(1)
11548
+ });
11549
+ const STACKED_FOCUS_MODAL_ID = "shipping-form";
11550
+ const Shipping = () => {
11551
+ var _a;
11552
+ const { id } = reactRouterDom.useParams();
11553
+ const { order, isPending, isError, error } = useOrder(id, {
11554
+ fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
11555
+ });
11556
+ const {
11557
+ order: preview,
11558
+ isPending: isPreviewPending,
11559
+ isError: isPreviewError,
11560
+ error: previewError
11561
+ } = useOrderPreview(id);
11562
+ useInitiateOrderEdit({ preview });
11563
+ const { onCancel } = useCancelOrderEdit({ preview });
11564
+ if (isError) {
11565
+ throw error;
11566
+ }
11567
+ if (isPreviewError) {
11568
+ throw previewError;
11569
+ }
11570
+ const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
11571
+ const isReady = preview && !isPreviewPending && order && !isPending;
11572
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
11573
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Header, {}),
11574
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
11575
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
11576
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
11577
+ ] }) }) }),
11578
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
11579
+ ] }) : isReady ? /* @__PURE__ */ jsxRuntime.jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11580
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
11581
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
11582
+ ] }) });
11583
+ };
11584
+ const ShippingForm = ({ preview, order }) => {
11585
+ var _a;
11586
+ const { setIsOpen } = useStackedModal();
11587
+ const [isSubmitting, setIsSubmitting] = React.useState(false);
11588
+ const [data, setData] = React.useState(null);
11589
+ const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
11590
+ const { shipping_options } = useShippingOptions(
12270
11591
  {
12271
11592
  id: appliedShippingOptionIds,
12272
11593
  fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
@@ -12622,416 +11943,1095 @@ const ShippingForm = ({ preview, order }) => {
12622
11943
  if (!open) {
12623
11944
  setData(null);
12624
11945
  }
12625
- return open;
12626
- },
12627
- children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
12628
- }
12629
- )
12630
- ] }),
12631
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12632
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12633
- /* @__PURE__ */ jsxRuntime.jsx(
12634
- ui.Button,
11946
+ return open;
11947
+ },
11948
+ children: data && /* @__PURE__ */ jsxRuntime.jsx(ShippingProfileForm, { data, order, preview })
11949
+ }
11950
+ )
11951
+ ] }),
11952
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
11953
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11954
+ /* @__PURE__ */ jsxRuntime.jsx(
11955
+ ui.Button,
11956
+ {
11957
+ size: "small",
11958
+ type: "button",
11959
+ isLoading: isSubmitting,
11960
+ onClick: onSubmit,
11961
+ children: "Save"
11962
+ }
11963
+ )
11964
+ ] }) })
11965
+ ] });
11966
+ };
11967
+ const StackedModalTrigger = ({
11968
+ shippingProfileId,
11969
+ shippingOption,
11970
+ shippingMethod,
11971
+ setData,
11972
+ children
11973
+ }) => {
11974
+ const { setIsOpen, getIsOpen } = useStackedModal();
11975
+ const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
11976
+ const onToggle = () => {
11977
+ if (isOpen) {
11978
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
11979
+ setData(null);
11980
+ } else {
11981
+ setIsOpen(STACKED_FOCUS_MODAL_ID, true);
11982
+ setData({
11983
+ shippingProfileId,
11984
+ shippingOption,
11985
+ shippingMethod
11986
+ });
11987
+ }
11988
+ };
11989
+ return /* @__PURE__ */ jsxRuntime.jsx(
11990
+ ui.Button,
11991
+ {
11992
+ size: "small",
11993
+ variant: "secondary",
11994
+ onClick: onToggle,
11995
+ className: "text-ui-fg-primary shrink-0",
11996
+ children
11997
+ }
11998
+ );
11999
+ };
12000
+ const ShippingProfileForm = ({
12001
+ data,
12002
+ order,
12003
+ preview
12004
+ }) => {
12005
+ var _a, _b, _c, _d, _e, _f;
12006
+ const { setIsOpen } = useStackedModal();
12007
+ const form = reactHookForm.useForm({
12008
+ resolver: zod.zodResolver(shippingMethodSchema),
12009
+ defaultValues: {
12010
+ location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12011
+ shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12012
+ custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12013
+ }
12014
+ });
12015
+ const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12016
+ const {
12017
+ mutateAsync: updateShippingMethod,
12018
+ isPending: isUpdatingShippingMethod
12019
+ } = useDraftOrderUpdateShippingMethod(order.id);
12020
+ const onSubmit = form.handleSubmit(async (values) => {
12021
+ if (lodash.isEqual(values, form.formState.defaultValues)) {
12022
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12023
+ return;
12024
+ }
12025
+ if (data.shippingMethod) {
12026
+ await updateShippingMethod(
12027
+ {
12028
+ method_id: data.shippingMethod.id,
12029
+ shipping_option_id: values.shipping_option_id,
12030
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12031
+ },
12032
+ {
12033
+ onError: (e) => {
12034
+ ui.toast.error(e.message);
12035
+ },
12036
+ onSuccess: () => {
12037
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12038
+ }
12039
+ }
12040
+ );
12041
+ return;
12042
+ }
12043
+ await addShippingMethod(
12044
+ {
12045
+ shipping_option_id: values.shipping_option_id,
12046
+ custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12047
+ },
12048
+ {
12049
+ onError: (e) => {
12050
+ ui.toast.error(e.message);
12051
+ },
12052
+ onSuccess: () => {
12053
+ setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12054
+ }
12055
+ }
12056
+ );
12057
+ });
12058
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12059
+ KeyboundForm,
12060
+ {
12061
+ className: "flex h-full flex-col overflow-hidden",
12062
+ onSubmit,
12063
+ children: [
12064
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12065
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12066
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12067
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12068
+ /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12069
+ ] }),
12070
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12071
+ /* @__PURE__ */ jsxRuntime.jsx(
12072
+ LocationField,
12073
+ {
12074
+ control: form.control,
12075
+ setValue: form.setValue
12076
+ }
12077
+ ),
12078
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12079
+ /* @__PURE__ */ jsxRuntime.jsx(
12080
+ ShippingOptionField,
12081
+ {
12082
+ shippingProfileId: data.shippingProfileId,
12083
+ preview,
12084
+ control: form.control
12085
+ }
12086
+ ),
12087
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12088
+ /* @__PURE__ */ jsxRuntime.jsx(
12089
+ CustomAmountField,
12090
+ {
12091
+ control: form.control,
12092
+ currencyCode: order.currency_code
12093
+ }
12094
+ ),
12095
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12096
+ /* @__PURE__ */ jsxRuntime.jsx(
12097
+ ItemsPreview,
12098
+ {
12099
+ order,
12100
+ shippingProfileId: data.shippingProfileId
12101
+ }
12102
+ )
12103
+ ] }) }) }),
12104
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12105
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12106
+ /* @__PURE__ */ jsxRuntime.jsx(
12107
+ ui.Button,
12108
+ {
12109
+ size: "small",
12110
+ type: "submit",
12111
+ isLoading: isPending || isUpdatingShippingMethod,
12112
+ children: data.shippingMethod ? "Update" : "Add"
12113
+ }
12114
+ )
12115
+ ] }) })
12116
+ ]
12117
+ }
12118
+ ) }) });
12119
+ };
12120
+ const shippingMethodSchema = objectType({
12121
+ location_id: stringType(),
12122
+ shipping_option_id: stringType(),
12123
+ custom_amount: unionType([numberType(), stringType()]).optional()
12124
+ });
12125
+ const ItemsPreview = ({ order, shippingProfileId }) => {
12126
+ const matches = order.items.filter(
12127
+ (item) => {
12128
+ var _a, _b, _c;
12129
+ return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12130
+ }
12131
+ );
12132
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12133
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12134
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12135
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12136
+ ] }) }),
12137
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12138
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12139
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12140
+ /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12141
+ ] }),
12142
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12143
+ "div",
12635
12144
  {
12636
- size: "small",
12637
- type: "button",
12638
- isLoading: isSubmitting,
12639
- onClick: onSubmit,
12640
- children: "Save"
12641
- }
12642
- )
12643
- ] }) })
12145
+ className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12146
+ children: [
12147
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12148
+ /* @__PURE__ */ jsxRuntime.jsx(
12149
+ Thumbnail,
12150
+ {
12151
+ thumbnail: item.thumbnail,
12152
+ alt: item.product_title ?? void 0
12153
+ }
12154
+ ),
12155
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12156
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12157
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12158
+ /* @__PURE__ */ jsxRuntime.jsxs(
12159
+ ui.Text,
12160
+ {
12161
+ size: "small",
12162
+ leading: "compact",
12163
+ className: "text-ui-fg-subtle",
12164
+ children: [
12165
+ "(",
12166
+ item.variant_title,
12167
+ ")"
12168
+ ]
12169
+ }
12170
+ )
12171
+ ] }),
12172
+ /* @__PURE__ */ jsxRuntime.jsx(
12173
+ ui.Text,
12174
+ {
12175
+ size: "small",
12176
+ leading: "compact",
12177
+ className: "text-ui-fg-subtle",
12178
+ children: item.variant_sku
12179
+ }
12180
+ )
12181
+ ] })
12182
+ ] }),
12183
+ /* @__PURE__ */ jsxRuntime.jsxs(
12184
+ ui.Text,
12185
+ {
12186
+ size: "small",
12187
+ leading: "compact",
12188
+ className: "text-ui-fg-subtle",
12189
+ children: [
12190
+ item.quantity,
12191
+ "x"
12192
+ ]
12193
+ }
12194
+ )
12195
+ ]
12196
+ },
12197
+ item.id
12198
+ )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12199
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12200
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12201
+ 'No items found for "',
12202
+ query,
12203
+ '".'
12204
+ ] })
12205
+ ] }) })
12206
+ ] })
12644
12207
  ] });
12645
12208
  };
12646
- const StackedModalTrigger = ({
12209
+ const LocationField = ({ control, setValue }) => {
12210
+ const locations = useComboboxData({
12211
+ queryKey: ["locations"],
12212
+ queryFn: async (params) => {
12213
+ return await sdk.admin.stockLocation.list(params);
12214
+ },
12215
+ getOptions: (data) => {
12216
+ return data.stock_locations.map((location) => ({
12217
+ label: location.name,
12218
+ value: location.id
12219
+ }));
12220
+ }
12221
+ });
12222
+ return /* @__PURE__ */ jsxRuntime.jsx(
12223
+ Form$2.Field,
12224
+ {
12225
+ control,
12226
+ name: "location_id",
12227
+ render: ({ field: { onChange, ...field } }) => {
12228
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12229
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12230
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12231
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12232
+ ] }),
12233
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12234
+ Combobox,
12235
+ {
12236
+ options: locations.options,
12237
+ fetchNextPage: locations.fetchNextPage,
12238
+ isFetchingNextPage: locations.isFetchingNextPage,
12239
+ searchValue: locations.searchValue,
12240
+ onSearchValueChange: locations.onSearchValueChange,
12241
+ placeholder: "Select location",
12242
+ onChange: (value) => {
12243
+ setValue("shipping_option_id", "", {
12244
+ shouldDirty: true,
12245
+ shouldTouch: true
12246
+ });
12247
+ onChange(value);
12248
+ },
12249
+ ...field
12250
+ }
12251
+ ) })
12252
+ ] }) });
12253
+ }
12254
+ }
12255
+ );
12256
+ };
12257
+ const ShippingOptionField = ({
12647
12258
  shippingProfileId,
12648
- shippingOption,
12649
- shippingMethod,
12650
- setData,
12651
- children
12259
+ preview,
12260
+ control
12652
12261
  }) => {
12653
- const { setIsOpen, getIsOpen } = useStackedModal();
12654
- const isOpen = getIsOpen(STACKED_FOCUS_MODAL_ID);
12655
- const onToggle = () => {
12656
- if (isOpen) {
12657
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12658
- setData(null);
12659
- } else {
12660
- setIsOpen(STACKED_FOCUS_MODAL_ID, true);
12661
- setData({
12662
- shippingProfileId,
12663
- shippingOption,
12664
- shippingMethod
12262
+ var _a;
12263
+ const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12264
+ const shippingOptions = useComboboxData({
12265
+ queryKey: ["shipping_options", locationId, shippingProfileId],
12266
+ queryFn: async (params) => {
12267
+ return await sdk.admin.shippingOption.list({
12268
+ ...params,
12269
+ stock_location_id: locationId,
12270
+ shipping_profile_id: shippingProfileId
12665
12271
  });
12272
+ },
12273
+ getOptions: (data) => {
12274
+ return data.shipping_options.map((option) => {
12275
+ var _a2;
12276
+ if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12277
+ (r) => r.attribute === "is_return" && r.value === "true"
12278
+ )) {
12279
+ return void 0;
12280
+ }
12281
+ return {
12282
+ label: option.name,
12283
+ value: option.id
12284
+ };
12285
+ }).filter(Boolean);
12286
+ },
12287
+ enabled: !!locationId && !!shippingProfileId,
12288
+ defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12289
+ });
12290
+ const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12291
+ return /* @__PURE__ */ jsxRuntime.jsx(
12292
+ Form$2.Field,
12293
+ {
12294
+ control,
12295
+ name: "shipping_option_id",
12296
+ render: ({ field }) => {
12297
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12298
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12299
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12300
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12301
+ ] }),
12302
+ /* @__PURE__ */ jsxRuntime.jsx(
12303
+ ConditionalTooltip,
12304
+ {
12305
+ content: tooltipContent,
12306
+ showTooltip: !locationId || !shippingProfileId,
12307
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12308
+ Combobox,
12309
+ {
12310
+ options: shippingOptions.options,
12311
+ fetchNextPage: shippingOptions.fetchNextPage,
12312
+ isFetchingNextPage: shippingOptions.isFetchingNextPage,
12313
+ searchValue: shippingOptions.searchValue,
12314
+ onSearchValueChange: shippingOptions.onSearchValueChange,
12315
+ placeholder: "Select shipping option",
12316
+ ...field,
12317
+ disabled: !locationId || !shippingProfileId
12318
+ }
12319
+ ) }) })
12320
+ }
12321
+ )
12322
+ ] }) });
12323
+ }
12666
12324
  }
12667
- };
12325
+ );
12326
+ };
12327
+ const CustomAmountField = ({
12328
+ control,
12329
+ currencyCode
12330
+ }) => {
12668
12331
  return /* @__PURE__ */ jsxRuntime.jsx(
12669
- ui.Button,
12332
+ Form$2.Field,
12670
12333
  {
12671
- size: "small",
12672
- variant: "secondary",
12673
- onClick: onToggle,
12674
- className: "text-ui-fg-primary shrink-0",
12675
- children
12334
+ control,
12335
+ name: "custom_amount",
12336
+ render: ({ field: { onChange, ...field } }) => {
12337
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12338
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12339
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12340
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12341
+ ] }),
12342
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12343
+ ui.CurrencyInput,
12344
+ {
12345
+ ...field,
12346
+ onValueChange: (value) => onChange(value),
12347
+ symbol: getNativeSymbol(currencyCode),
12348
+ code: currencyCode
12349
+ }
12350
+ ) })
12351
+ ] });
12352
+ }
12676
12353
  }
12677
12354
  );
12678
12355
  };
12679
- const ShippingProfileForm = ({
12680
- data,
12681
- order,
12682
- preview
12683
- }) => {
12684
- var _a, _b, _c, _d, _e, _f;
12685
- const { setIsOpen } = useStackedModal();
12356
+ const TransferOwnership = () => {
12357
+ const { id } = reactRouterDom.useParams();
12358
+ const { draft_order, isPending, isError, error } = useDraftOrder(id, {
12359
+ fields: "id,customer_id,customer.*"
12360
+ });
12361
+ if (isError) {
12362
+ throw error;
12363
+ }
12364
+ const isReady = !isPending && !!draft_order;
12365
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12366
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12367
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Transfer Ownership" }) }),
12368
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Transfer the ownership of this draft order to a new customer" }) })
12369
+ ] }),
12370
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(TransferOwnershipForm, { order: draft_order })
12371
+ ] });
12372
+ };
12373
+ const TransferOwnershipForm = ({ order }) => {
12374
+ var _a, _b;
12686
12375
  const form = reactHookForm.useForm({
12687
- resolver: zod.zodResolver(shippingMethodSchema),
12688
12376
  defaultValues: {
12689
- location_id: (_d = (_c = (_b = (_a = data.shippingOption) == null ? void 0 : _a.service_zone) == null ? void 0 : _b.fulfillment_set) == null ? void 0 : _c.location) == null ? void 0 : _d.id,
12690
- shipping_option_id: (_e = data.shippingOption) == null ? void 0 : _e.id,
12691
- custom_amount: (_f = data.shippingMethod) == null ? void 0 : _f.amount
12377
+ customer_id: order.customer_id || ""
12378
+ },
12379
+ resolver: zod.zodResolver(schema$1)
12380
+ });
12381
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12382
+ const { handleSuccess } = useRouteModal();
12383
+ const name = [(_a = order.customer) == null ? void 0 : _a.first_name, (_b = order.customer) == null ? void 0 : _b.last_name].filter(Boolean).join(" ");
12384
+ const currentCustomer = order.customer ? {
12385
+ label: name ? `${name} (${order.customer.email})` : order.customer.email,
12386
+ value: order.customer.id
12387
+ } : null;
12388
+ const onSubmit = form.handleSubmit(async (data) => {
12389
+ await mutateAsync(
12390
+ { customer_id: data.customer_id },
12391
+ {
12392
+ onSuccess: () => {
12393
+ ui.toast.success("Customer updated");
12394
+ handleSuccess();
12395
+ },
12396
+ onError: (error) => {
12397
+ ui.toast.error(error.message);
12398
+ }
12399
+ }
12400
+ );
12401
+ });
12402
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12403
+ KeyboundForm,
12404
+ {
12405
+ className: "flex flex-1 flex-col overflow-hidden",
12406
+ onSubmit,
12407
+ children: [
12408
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: [
12409
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center bg-ui-bg-component rounded-md border", children: /* @__PURE__ */ jsxRuntime.jsx(Illustration, {}) }),
12410
+ currentCustomer && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col space-y-3", children: [
12411
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12412
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "current-customer", children: "Current owner" }),
12413
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { children: "The customer that is currently associated with this draft order." })
12414
+ ] }),
12415
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Select, { disabled: true, value: currentCustomer.value, children: [
12416
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Trigger, { id: "current-customer", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Value, {}) }),
12417
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Select.Item, { value: currentCustomer.value, children: currentCustomer.label }) })
12418
+ ] })
12419
+ ] }),
12420
+ /* @__PURE__ */ jsxRuntime.jsx(
12421
+ CustomerField,
12422
+ {
12423
+ control: form.control,
12424
+ currentCustomerId: order.customer_id
12425
+ }
12426
+ )
12427
+ ] }),
12428
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
12429
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { variant: "secondary", size: "small", children: "Cancel" }) }),
12430
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12431
+ ] }) })
12432
+ ]
12433
+ }
12434
+ ) });
12435
+ };
12436
+ const CustomerField = ({ control, currentCustomerId }) => {
12437
+ const customers = useComboboxData({
12438
+ queryFn: async (params) => {
12439
+ return await sdk.admin.customer.list({
12440
+ ...params,
12441
+ id: currentCustomerId ? { $nin: [currentCustomerId] } : void 0
12442
+ });
12443
+ },
12444
+ queryKey: ["customers"],
12445
+ getOptions: (data) => {
12446
+ return data.customers.map((customer) => {
12447
+ const name = [customer.first_name, customer.last_name].filter(Boolean).join(" ");
12448
+ return {
12449
+ label: name ? `${name} (${customer.email})` : customer.email,
12450
+ value: customer.id
12451
+ };
12452
+ });
12692
12453
  }
12693
12454
  });
12694
- const { mutateAsync: addShippingMethod, isPending } = useDraftOrderAddShippingMethod(order.id);
12695
- const {
12696
- mutateAsync: updateShippingMethod,
12697
- isPending: isUpdatingShippingMethod
12698
- } = useDraftOrderUpdateShippingMethod(order.id);
12699
- const onSubmit = form.handleSubmit(async (values) => {
12700
- if (lodash.isEqual(values, form.formState.defaultValues)) {
12701
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12702
- return;
12455
+ return /* @__PURE__ */ jsxRuntime.jsx(
12456
+ Form$2.Field,
12457
+ {
12458
+ name: "customer_id",
12459
+ control,
12460
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { className: "space-y-3", children: [
12461
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12462
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "New customer" }),
12463
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "The customer to transfer this draft order to." })
12464
+ ] }),
12465
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12466
+ Combobox,
12467
+ {
12468
+ options: customers.options,
12469
+ fetchNextPage: customers.fetchNextPage,
12470
+ isFetchingNextPage: customers.isFetchingNextPage,
12471
+ searchValue: customers.searchValue,
12472
+ onSearchValueChange: customers.onSearchValueChange,
12473
+ placeholder: "Select customer",
12474
+ ...field
12475
+ }
12476
+ ) }),
12477
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12478
+ ] })
12703
12479
  }
12704
- if (data.shippingMethod) {
12705
- await updateShippingMethod(
12706
- {
12707
- method_id: data.shippingMethod.id,
12708
- shipping_option_id: values.shipping_option_id,
12709
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12710
- },
12711
- {
12712
- onError: (e) => {
12713
- ui.toast.error(e.message);
12714
- },
12715
- onSuccess: () => {
12716
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12480
+ );
12481
+ };
12482
+ const Illustration = () => {
12483
+ return /* @__PURE__ */ jsxRuntime.jsxs(
12484
+ "svg",
12485
+ {
12486
+ width: "280",
12487
+ height: "180",
12488
+ viewBox: "0 0 280 180",
12489
+ fill: "none",
12490
+ xmlns: "http://www.w3.org/2000/svg",
12491
+ children: [
12492
+ /* @__PURE__ */ jsxRuntime.jsx(
12493
+ "rect",
12494
+ {
12495
+ x: "0.00428286",
12496
+ y: "-0.742904",
12497
+ width: "33.5",
12498
+ height: "65.5",
12499
+ rx: "6.75",
12500
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 88.438)",
12501
+ fill: "#D4D4D8",
12502
+ stroke: "#52525B",
12503
+ strokeWidth: "1.5"
12504
+ }
12505
+ ),
12506
+ /* @__PURE__ */ jsxRuntime.jsx(
12507
+ "rect",
12508
+ {
12509
+ x: "0.00428286",
12510
+ y: "-0.742904",
12511
+ width: "33.5",
12512
+ height: "65.5",
12513
+ rx: "6.75",
12514
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 189.756 85.4381)",
12515
+ fill: "white",
12516
+ stroke: "#52525B",
12517
+ strokeWidth: "1.5"
12518
+ }
12519
+ ),
12520
+ /* @__PURE__ */ jsxRuntime.jsx(
12521
+ "path",
12522
+ {
12523
+ d: "M180.579 107.142L179.126 107.959",
12524
+ stroke: "#52525B",
12525
+ strokeWidth: "1.5",
12526
+ strokeLinecap: "round",
12527
+ strokeLinejoin: "round"
12528
+ }
12529
+ ),
12530
+ /* @__PURE__ */ jsxRuntime.jsx(
12531
+ "path",
12532
+ {
12533
+ opacity: "0.88",
12534
+ d: "M182.305 109.546L180.257 109.534",
12535
+ stroke: "#52525B",
12536
+ strokeWidth: "1.5",
12537
+ strokeLinecap: "round",
12538
+ strokeLinejoin: "round"
12717
12539
  }
12718
- }
12719
- );
12720
- return;
12721
- }
12722
- await addShippingMethod(
12723
- {
12724
- shipping_option_id: values.shipping_option_id,
12725
- custom_amount: values.custom_amount ? convertNumber(values.custom_amount) : void 0
12726
- },
12727
- {
12728
- onError: (e) => {
12729
- ui.toast.error(e.message);
12730
- },
12731
- onSuccess: () => {
12732
- setIsOpen(STACKED_FOCUS_MODAL_ID, false);
12733
- }
12734
- }
12735
- );
12736
- });
12737
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Content, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12738
- KeyboundForm,
12739
- {
12740
- className: "flex h-full flex-col overflow-hidden",
12741
- onSubmit,
12742
- children: [
12743
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
12744
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
12745
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12746
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Shipping" }) }),
12747
- /* @__PURE__ */ jsxRuntime.jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a shipping method for the selected shipping profile. You can see the items that will be shipped using this method in the preview below." }) })
12748
- ] }),
12749
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12750
- /* @__PURE__ */ jsxRuntime.jsx(
12751
- LocationField,
12540
+ ),
12541
+ /* @__PURE__ */ jsxRuntime.jsx(
12542
+ "path",
12543
+ {
12544
+ opacity: "0.75",
12545
+ d: "M180.551 111.93L179.108 111.096",
12546
+ stroke: "#52525B",
12547
+ strokeWidth: "1.5",
12548
+ strokeLinecap: "round",
12549
+ strokeLinejoin: "round"
12550
+ }
12551
+ ),
12552
+ /* @__PURE__ */ jsxRuntime.jsx(
12553
+ "path",
12554
+ {
12555
+ opacity: "0.63",
12556
+ d: "M176.347 112.897L176.354 111.73",
12557
+ stroke: "#52525B",
12558
+ strokeWidth: "1.5",
12559
+ strokeLinecap: "round",
12560
+ strokeLinejoin: "round"
12561
+ }
12562
+ ),
12563
+ /* @__PURE__ */ jsxRuntime.jsx(
12564
+ "path",
12565
+ {
12566
+ opacity: "0.5",
12567
+ d: "M172.153 111.881L173.606 111.064",
12568
+ stroke: "#52525B",
12569
+ strokeWidth: "1.5",
12570
+ strokeLinecap: "round",
12571
+ strokeLinejoin: "round"
12572
+ }
12573
+ ),
12574
+ /* @__PURE__ */ jsxRuntime.jsx(
12575
+ "path",
12576
+ {
12577
+ opacity: "0.38",
12578
+ d: "M170.428 109.478L172.476 109.489",
12579
+ stroke: "#52525B",
12580
+ strokeWidth: "1.5",
12581
+ strokeLinecap: "round",
12582
+ strokeLinejoin: "round"
12583
+ }
12584
+ ),
12585
+ /* @__PURE__ */ jsxRuntime.jsx(
12586
+ "path",
12587
+ {
12588
+ opacity: "0.25",
12589
+ d: "M172.181 107.094L173.624 107.928",
12590
+ stroke: "#52525B",
12591
+ strokeWidth: "1.5",
12592
+ strokeLinecap: "round",
12593
+ strokeLinejoin: "round"
12594
+ }
12595
+ ),
12596
+ /* @__PURE__ */ jsxRuntime.jsx(
12597
+ "path",
12598
+ {
12599
+ opacity: "0.13",
12600
+ d: "M176.386 106.126L176.379 107.294",
12601
+ stroke: "#52525B",
12602
+ strokeWidth: "1.5",
12603
+ strokeLinecap: "round",
12604
+ strokeLinejoin: "round"
12605
+ }
12606
+ ),
12607
+ /* @__PURE__ */ jsxRuntime.jsx(
12608
+ "rect",
12609
+ {
12610
+ width: "12",
12611
+ height: "3",
12612
+ rx: "1.5",
12613
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 196.447 92.2925)",
12614
+ fill: "#D4D4D8"
12615
+ }
12616
+ ),
12617
+ /* @__PURE__ */ jsxRuntime.jsx(
12618
+ "rect",
12619
+ {
12620
+ x: "0.00428286",
12621
+ y: "-0.742904",
12622
+ width: "33.5",
12623
+ height: "65.5",
12624
+ rx: "6.75",
12625
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 46.4147)",
12626
+ fill: "#D4D4D8",
12627
+ stroke: "#52525B",
12628
+ strokeWidth: "1.5"
12629
+ }
12630
+ ),
12631
+ /* @__PURE__ */ jsxRuntime.jsx(
12632
+ "rect",
12633
+ {
12634
+ x: "0.00428286",
12635
+ y: "-0.742904",
12636
+ width: "33.5",
12637
+ height: "65.5",
12638
+ rx: "6.75",
12639
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 117.023 43.4147)",
12640
+ fill: "white",
12641
+ stroke: "#52525B",
12642
+ strokeWidth: "1.5"
12643
+ }
12644
+ ),
12645
+ /* @__PURE__ */ jsxRuntime.jsx(
12646
+ "rect",
12647
+ {
12648
+ width: "12",
12649
+ height: "3",
12650
+ rx: "1.5",
12651
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 123.714 50.2691)",
12652
+ fill: "#D4D4D8"
12653
+ }
12654
+ ),
12655
+ /* @__PURE__ */ jsxRuntime.jsx(
12656
+ "rect",
12657
+ {
12658
+ width: "17",
12659
+ height: "3",
12660
+ rx: "1.5",
12661
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 97.5557 66.958)",
12662
+ fill: "#D4D4D8"
12663
+ }
12664
+ ),
12665
+ /* @__PURE__ */ jsxRuntime.jsx(
12666
+ "rect",
12667
+ {
12668
+ width: "12",
12669
+ height: "3",
12670
+ rx: "1.5",
12671
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 93.1978 69.4093)",
12672
+ fill: "#D4D4D8"
12673
+ }
12674
+ ),
12675
+ /* @__PURE__ */ jsxRuntime.jsx(
12676
+ "path",
12677
+ {
12678
+ d: "M92.3603 63.9563C90.9277 63.1286 88.59 63.1152 87.148 63.9263C85.7059 64.7374 85.6983 66.0702 87.1308 66.8979C88.5634 67.7256 90.9011 67.7391 92.3432 66.928C93.7852 66.1168 93.7929 64.784 92.3603 63.9563ZM88.4382 66.1625C87.7221 65.7488 87.726 65.0822 88.4468 64.6767C89.1676 64.2713 90.3369 64.278 91.0529 64.6917C91.769 65.1055 91.7652 65.7721 91.0444 66.1775C90.3236 66.583 89.1543 66.5762 88.4382 66.1625Z",
12679
+ fill: "#A1A1AA"
12680
+ }
12681
+ ),
12682
+ /* @__PURE__ */ jsxRuntime.jsx(
12683
+ "rect",
12684
+ {
12685
+ width: "17",
12686
+ height: "3",
12687
+ rx: "1.5",
12688
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 109.758 60.0944)",
12689
+ fill: "#A1A1AA"
12690
+ }
12691
+ ),
12692
+ /* @__PURE__ */ jsxRuntime.jsx(
12693
+ "rect",
12694
+ {
12695
+ width: "12",
12696
+ height: "3",
12697
+ rx: "1.5",
12698
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 105.4 62.5457)",
12699
+ fill: "#A1A1AA"
12700
+ }
12701
+ ),
12702
+ /* @__PURE__ */ jsxRuntime.jsx(
12703
+ "path",
12704
+ {
12705
+ d: "M104.562 57.0927C103.13 56.265 100.792 56.2515 99.3501 57.0626C97.9081 57.8738 97.9004 59.2065 99.333 60.0343C100.766 60.862 103.103 60.8754 104.545 60.0643C105.987 59.2532 105.995 57.9204 104.562 57.0927ZM103.858 58.8972L100.815 59.1265C100.683 59.1367 100.55 59.1134 100.449 59.063C100.44 59.0585 100.432 59.0545 100.425 59.05C100.339 59.0005 100.29 58.9336 100.291 58.8637L100.294 58.1201C100.294 57.9752 100.501 57.8585 100.756 57.86C101.01 57.8615 101.217 57.98 101.216 58.1256L101.214 58.5669L103.732 58.3769C103.984 58.3578 104.217 58.4584 104.251 58.603C104.286 58.7468 104.11 58.8788 103.858 58.8977L103.858 58.8972Z",
12706
+ fill: "#52525B"
12707
+ }
12708
+ ),
12709
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip0_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12710
+ "path",
12711
+ {
12712
+ d: "M133.106 81.8022L140.49 81.8447L140.515 77.6349",
12713
+ stroke: "#A1A1AA",
12714
+ strokeWidth: "1.5",
12715
+ strokeLinecap: "round",
12716
+ strokeLinejoin: "round"
12717
+ }
12718
+ ) }),
12719
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip1_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12720
+ "path",
12721
+ {
12722
+ d: "M143.496 87.8055L150.881 87.8481L150.905 83.6383",
12723
+ stroke: "#A1A1AA",
12724
+ strokeWidth: "1.5",
12725
+ strokeLinecap: "round",
12726
+ strokeLinejoin: "round"
12727
+ }
12728
+ ) }),
12729
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip2_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12730
+ "path",
12731
+ {
12732
+ d: "M153.887 93.8088L161.271 93.8514L161.295 89.6416",
12733
+ stroke: "#A1A1AA",
12734
+ strokeWidth: "1.5",
12735
+ strokeLinecap: "round",
12736
+ strokeLinejoin: "round"
12737
+ }
12738
+ ) }),
12739
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip3_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12740
+ "path",
12741
+ {
12742
+ d: "M126.114 89.1912L118.729 89.1486L118.705 93.3584",
12743
+ stroke: "#A1A1AA",
12744
+ strokeWidth: "1.5",
12745
+ strokeLinecap: "round",
12746
+ strokeLinejoin: "round"
12747
+ }
12748
+ ) }),
12749
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip4_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12750
+ "path",
12751
+ {
12752
+ d: "M136.504 95.1945L129.12 95.1519L129.095 99.3617",
12753
+ stroke: "#A1A1AA",
12754
+ strokeWidth: "1.5",
12755
+ strokeLinecap: "round",
12756
+ strokeLinejoin: "round"
12757
+ }
12758
+ ) }),
12759
+ /* @__PURE__ */ jsxRuntime.jsx("g", { clipPath: "url(#clip5_20915_38670)", children: /* @__PURE__ */ jsxRuntime.jsx(
12760
+ "path",
12761
+ {
12762
+ d: "M146.894 101.198L139.51 101.155L139.486 105.365",
12763
+ stroke: "#A1A1AA",
12764
+ strokeWidth: "1.5",
12765
+ strokeLinecap: "round",
12766
+ strokeLinejoin: "round"
12767
+ }
12768
+ ) }),
12769
+ /* @__PURE__ */ jsxRuntime.jsxs("defs", { children: [
12770
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip0_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12771
+ "rect",
12752
12772
  {
12753
- control: form.control,
12754
- setValue: form.setValue
12773
+ width: "12",
12774
+ height: "12",
12775
+ fill: "white",
12776
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 138.36 74.6508)"
12755
12777
  }
12756
- ),
12757
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12758
- /* @__PURE__ */ jsxRuntime.jsx(
12759
- ShippingOptionField,
12778
+ ) }),
12779
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip1_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12780
+ "rect",
12760
12781
  {
12761
- shippingProfileId: data.shippingProfileId,
12762
- preview,
12763
- control: form.control
12782
+ width: "12",
12783
+ height: "12",
12784
+ fill: "white",
12785
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 148.75 80.6541)"
12764
12786
  }
12765
- ),
12766
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12767
- /* @__PURE__ */ jsxRuntime.jsx(
12768
- CustomAmountField,
12787
+ ) }),
12788
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip2_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12789
+ "rect",
12769
12790
  {
12770
- control: form.control,
12771
- currencyCode: order.currency_code
12791
+ width: "12",
12792
+ height: "12",
12793
+ fill: "white",
12794
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 159.141 86.6575)"
12772
12795
  }
12773
- ),
12774
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
12775
- /* @__PURE__ */ jsxRuntime.jsx(
12776
- ItemsPreview,
12796
+ ) }),
12797
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip3_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12798
+ "rect",
12777
12799
  {
12778
- order,
12779
- shippingProfileId: data.shippingProfileId
12800
+ width: "12",
12801
+ height: "12",
12802
+ fill: "white",
12803
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 120.928 84.4561)"
12780
12804
  }
12781
- )
12782
- ] }) }) }),
12783
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-x-2", children: [
12784
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
12785
- /* @__PURE__ */ jsxRuntime.jsx(
12786
- ui.Button,
12805
+ ) }),
12806
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12807
+ "rect",
12787
12808
  {
12788
- size: "small",
12789
- type: "submit",
12790
- isLoading: isPending || isUpdatingShippingMethod,
12791
- children: data.shippingMethod ? "Update" : "Add"
12809
+ width: "12",
12810
+ height: "12",
12811
+ fill: "white",
12812
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
12792
12813
  }
12793
- )
12794
- ] }) })
12795
- ]
12796
- }
12797
- ) }) });
12798
- };
12799
- const shippingMethodSchema = objectType({
12800
- location_id: stringType(),
12801
- shipping_option_id: stringType(),
12802
- custom_amount: unionType([numberType(), stringType()]).optional()
12803
- });
12804
- const ItemsPreview = ({ order, shippingProfileId }) => {
12805
- const matches = order.items.filter(
12806
- (item) => {
12807
- var _a, _b, _c;
12808
- return ((_c = (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile) == null ? void 0 : _c.id) === shippingProfileId;
12809
- }
12810
- );
12811
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-6", children: [
12812
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "grid grid-cols-2 items-center gap-3", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12813
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "Items to ship" }),
12814
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Items with the selected shipping profile." })
12815
- ] }) }),
12816
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
12817
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-3 px-4 py-2 text-ui-fg-muted", children: [
12818
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Item" }) }),
12819
- /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: "Quantity" }) })
12820
- ] }),
12821
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
12822
- "div",
12823
- {
12824
- className: "grid grid-cols-2 gap-3 px-4 py-2 bg-ui-bg-base shadow-elevation-card-rest rounded-lg items-center",
12825
- children: [
12826
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
12827
- /* @__PURE__ */ jsxRuntime.jsx(
12828
- Thumbnail,
12829
- {
12830
- thumbnail: item.thumbnail,
12831
- alt: item.product_title ?? void 0
12832
- }
12833
- ),
12834
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12835
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
12836
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
12837
- /* @__PURE__ */ jsxRuntime.jsxs(
12838
- ui.Text,
12839
- {
12840
- size: "small",
12841
- leading: "compact",
12842
- className: "text-ui-fg-subtle",
12843
- children: [
12844
- "(",
12845
- item.variant_title,
12846
- ")"
12847
- ]
12848
- }
12849
- )
12850
- ] }),
12851
- /* @__PURE__ */ jsxRuntime.jsx(
12852
- ui.Text,
12853
- {
12854
- size: "small",
12855
- leading: "compact",
12856
- className: "text-ui-fg-subtle",
12857
- children: item.variant_sku
12858
- }
12859
- )
12860
- ] })
12861
- ] }),
12862
- /* @__PURE__ */ jsxRuntime.jsxs(
12863
- ui.Text,
12864
- {
12865
- size: "small",
12866
- leading: "compact",
12867
- className: "text-ui-fg-subtle",
12868
- children: [
12869
- item.quantity,
12870
- "x"
12871
- ]
12872
- }
12873
- )
12874
- ]
12875
- },
12876
- item.id
12877
- )) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-center gap-x-3 bg-ui-bg-base rounded-lg p-4 shadow-elevation-card-rest flex-col gap-1", children: [
12878
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
12879
- /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: [
12880
- 'No items found for "',
12881
- query,
12882
- '".'
12883
- ] })
12884
- ] }) })
12885
- ] })
12886
- ] });
12887
- };
12888
- const LocationField = ({ control, setValue }) => {
12889
- const locations = useComboboxData({
12890
- queryKey: ["locations"],
12891
- queryFn: async (params) => {
12892
- return await sdk.admin.stockLocation.list(params);
12893
- },
12894
- getOptions: (data) => {
12895
- return data.stock_locations.map((location) => ({
12896
- label: location.name,
12897
- value: location.id
12898
- }));
12899
- }
12900
- });
12901
- return /* @__PURE__ */ jsxRuntime.jsx(
12902
- Form$2.Field,
12903
- {
12904
- control,
12905
- name: "location_id",
12906
- render: ({ field: { onChange, ...field } }) => {
12907
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12908
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
12909
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Location" }),
12910
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose where you want to ship the items from." })
12911
- ] }),
12912
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12913
- Combobox,
12814
+ ) }),
12815
+ /* @__PURE__ */ jsxRuntime.jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsxRuntime.jsx(
12816
+ "rect",
12914
12817
  {
12915
- options: locations.options,
12916
- fetchNextPage: locations.fetchNextPage,
12917
- isFetchingNextPage: locations.isFetchingNextPage,
12918
- searchValue: locations.searchValue,
12919
- onSearchValueChange: locations.onSearchValueChange,
12920
- placeholder: "Select location",
12921
- onChange: (value) => {
12922
- setValue("shipping_option_id", "", {
12923
- shouldDirty: true,
12924
- shouldTouch: true
12925
- });
12926
- onChange(value);
12927
- },
12928
- ...field
12818
+ width: "12",
12819
+ height: "12",
12820
+ fill: "white",
12821
+ transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
12929
12822
  }
12930
12823
  ) })
12931
- ] }) });
12932
- }
12824
+ ] })
12825
+ ]
12933
12826
  }
12934
12827
  );
12935
12828
  };
12936
- const ShippingOptionField = ({
12937
- shippingProfileId,
12938
- preview,
12939
- control
12940
- }) => {
12941
- var _a;
12942
- const locationId = reactHookForm.useWatch({ control, name: "location_id" });
12943
- const shippingOptions = useComboboxData({
12944
- queryKey: ["shipping_options", locationId, shippingProfileId],
12945
- queryFn: async (params) => {
12946
- return await sdk.admin.shippingOption.list({
12947
- ...params,
12948
- stock_location_id: locationId,
12949
- shipping_profile_id: shippingProfileId
12950
- });
12829
+ const schema$1 = objectType({
12830
+ customer_id: stringType().min(1)
12831
+ });
12832
+ const ShippingAddress = () => {
12833
+ const { id } = reactRouterDom.useParams();
12834
+ const { order, isPending, isError, error } = useOrder(id, {
12835
+ fields: "+shipping_address"
12836
+ });
12837
+ if (isError) {
12838
+ throw error;
12839
+ }
12840
+ const isReady = !isPending && !!order;
12841
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12842
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12843
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12844
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12845
+ ] }),
12846
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12847
+ ] });
12848
+ };
12849
+ const ShippingAddressForm = ({ order }) => {
12850
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12851
+ const form = reactHookForm.useForm({
12852
+ defaultValues: {
12853
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12854
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12855
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12856
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12857
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12858
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12859
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12860
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12861
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12862
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12951
12863
  },
12952
- getOptions: (data) => {
12953
- return data.shipping_options.map((option) => {
12954
- var _a2;
12955
- if ((_a2 = option.rules) == null ? void 0 : _a2.find(
12956
- (r) => r.attribute === "is_return" && r.value === "true"
12957
- )) {
12958
- return void 0;
12864
+ resolver: zod.zodResolver(schema)
12865
+ });
12866
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12867
+ const { handleSuccess } = useRouteModal();
12868
+ const onSubmit = form.handleSubmit(async (data) => {
12869
+ await mutateAsync(
12870
+ {
12871
+ shipping_address: {
12872
+ first_name: data.first_name,
12873
+ last_name: data.last_name,
12874
+ company: data.company,
12875
+ address_1: data.address_1,
12876
+ address_2: data.address_2,
12877
+ city: data.city,
12878
+ province: data.province,
12879
+ country_code: data.country_code,
12880
+ postal_code: data.postal_code,
12881
+ phone: data.phone
12959
12882
  }
12960
- return {
12961
- label: option.name,
12962
- value: option.id
12963
- };
12964
- }).filter(Boolean);
12965
- },
12966
- enabled: !!locationId && !!shippingProfileId,
12967
- defaultValue: ((_a = preview.shipping_methods[0]) == null ? void 0 : _a.shipping_option_id) || void 0
12883
+ },
12884
+ {
12885
+ onSuccess: () => {
12886
+ handleSuccess();
12887
+ },
12888
+ onError: (error) => {
12889
+ ui.toast.error(error.message);
12890
+ }
12891
+ }
12892
+ );
12968
12893
  });
12969
- const tooltipContent = !locationId && !shippingProfileId ? "Choose a location and shipping profile first." : !locationId ? "Choose a location first." : "Choose a shipping profile first.";
12970
- return /* @__PURE__ */ jsxRuntime.jsx(
12971
- Form$2.Field,
12894
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12895
+ KeyboundForm,
12972
12896
  {
12973
- control,
12974
- name: "shipping_option_id",
12975
- render: ({ field }) => {
12976
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12977
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12978
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Shipping option" }),
12979
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Choose the shipping option to use." })
12897
+ className: "flex flex-1 flex-col overflow-hidden",
12898
+ onSubmit,
12899
+ children: [
12900
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12901
+ /* @__PURE__ */ jsxRuntime.jsx(
12902
+ Form$2.Field,
12903
+ {
12904
+ control: form.control,
12905
+ name: "country_code",
12906
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12907
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12908
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12909
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12910
+ ] })
12911
+ }
12912
+ ),
12913
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12914
+ /* @__PURE__ */ jsxRuntime.jsx(
12915
+ Form$2.Field,
12916
+ {
12917
+ control: form.control,
12918
+ name: "first_name",
12919
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12922
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12923
+ ] })
12924
+ }
12925
+ ),
12926
+ /* @__PURE__ */ jsxRuntime.jsx(
12927
+ Form$2.Field,
12928
+ {
12929
+ control: form.control,
12930
+ name: "last_name",
12931
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
+ ] })
12936
+ }
12937
+ )
12980
12938
  ] }),
12981
12939
  /* @__PURE__ */ jsxRuntime.jsx(
12982
- ConditionalTooltip,
12940
+ Form$2.Field,
12983
12941
  {
12984
- content: tooltipContent,
12985
- showTooltip: !locationId || !shippingProfileId,
12986
- children: /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12987
- Combobox,
12988
- {
12989
- options: shippingOptions.options,
12990
- fetchNextPage: shippingOptions.fetchNextPage,
12991
- isFetchingNextPage: shippingOptions.isFetchingNextPage,
12992
- searchValue: shippingOptions.searchValue,
12993
- onSearchValueChange: shippingOptions.onSearchValueChange,
12994
- placeholder: "Select shipping option",
12995
- ...field,
12996
- disabled: !locationId || !shippingProfileId
12997
- }
12998
- ) }) })
12942
+ control: form.control,
12943
+ name: "company",
12944
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12947
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12948
+ ] })
12999
12949
  }
13000
- )
13001
- ] }) });
13002
- }
13003
- }
13004
- );
13005
- };
13006
- const CustomAmountField = ({
13007
- control,
13008
- currencyCode
13009
- }) => {
13010
- return /* @__PURE__ */ jsxRuntime.jsx(
13011
- Form$2.Field,
13012
- {
13013
- control,
13014
- name: "custom_amount",
13015
- render: ({ field: { onChange, ...field } }) => {
13016
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
13017
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
13018
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
13019
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12950
+ ),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12953
+ {
12954
+ control: form.control,
12955
+ name: "address_1",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
+ ] })
12961
+ }
12962
+ ),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(
12964
+ Form$2.Field,
12965
+ {
12966
+ control: form.control,
12967
+ name: "address_2",
12968
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
+ ] })
12973
+ }
12974
+ ),
12975
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12976
+ /* @__PURE__ */ jsxRuntime.jsx(
12977
+ Form$2.Field,
12978
+ {
12979
+ control: form.control,
12980
+ name: "postal_code",
12981
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12984
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12985
+ ] })
12986
+ }
12987
+ ),
12988
+ /* @__PURE__ */ jsxRuntime.jsx(
12989
+ Form$2.Field,
12990
+ {
12991
+ control: form.control,
12992
+ name: "city",
12993
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
+ ] })
12998
+ }
12999
+ )
13020
13000
  ] }),
13021
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
13022
- ui.CurrencyInput,
13001
+ /* @__PURE__ */ jsxRuntime.jsx(
13002
+ Form$2.Field,
13023
13003
  {
13024
- ...field,
13025
- onValueChange: (value) => onChange(value),
13026
- symbol: getNativeSymbol(currencyCode),
13027
- code: currencyCode
13004
+ control: form.control,
13005
+ name: "province",
13006
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13009
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13010
+ ] })
13028
13011
  }
13029
- ) })
13030
- ] });
13031
- }
13012
+ ),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control: form.control,
13017
+ name: "phone",
13018
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
+ ] })
13023
+ }
13024
+ )
13025
+ ] }) }),
13026
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13027
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13028
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13029
+ ] }) })
13030
+ ]
13032
13031
  }
13033
- );
13032
+ ) });
13034
13033
  };
13034
+ const schema = addressSchema;
13035
13035
  const widgetModule = { widgets: [] };
13036
13036
  const routeModule = {
13037
13037
  routes: [
@@ -13061,16 +13061,16 @@ const routeModule = {
13061
13061
  path: "/draft-orders/:id/email"
13062
13062
  },
13063
13063
  {
13064
- Component: Metadata,
13065
- path: "/draft-orders/:id/metadata"
13064
+ Component: CustomItems,
13065
+ path: "/draft-orders/:id/custom-items"
13066
13066
  },
13067
13067
  {
13068
13068
  Component: Items,
13069
13069
  path: "/draft-orders/:id/items"
13070
13070
  },
13071
13071
  {
13072
- Component: CustomItems,
13073
- path: "/draft-orders/:id/custom-items"
13072
+ Component: Metadata,
13073
+ path: "/draft-orders/:id/metadata"
13074
13074
  },
13075
13075
  {
13076
13076
  Component: Promotions,
@@ -13081,16 +13081,16 @@ const routeModule = {
13081
13081
  path: "/draft-orders/:id/sales-channel"
13082
13082
  },
13083
13083
  {
13084
- Component: ShippingAddress,
13085
- path: "/draft-orders/:id/shipping-address"
13084
+ Component: Shipping,
13085
+ path: "/draft-orders/:id/shipping"
13086
13086
  },
13087
13087
  {
13088
13088
  Component: TransferOwnership,
13089
13089
  path: "/draft-orders/:id/transfer-ownership"
13090
13090
  },
13091
13091
  {
13092
- Component: Shipping,
13093
- path: "/draft-orders/:id/shipping"
13092
+ Component: ShippingAddress,
13093
+ path: "/draft-orders/:id/shipping-address"
13094
13094
  }
13095
13095
  ]
13096
13096
  }