@medusajs/draft-order 2.10.4-preview-20251001180205 → 2.10.4-preview-20251001210152
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.
- package/.medusa/server/src/admin/index.js +1432 -1432
- package/.medusa/server/src/admin/index.mjs +1433 -1433
- package/package.json +16 -16
|
@@ -4,7 +4,7 @@ import { Tooltip, DropdownMenu, clx, IconButton, useDataTable, DataTable as Data
|
|
|
4
4
|
import { useQuery, useQueryClient, useMutation, keepPreviousData, useInfiniteQuery } from "@tanstack/react-query";
|
|
5
5
|
import React, { useState, useCallback, useMemo, Fragment, createContext, forwardRef, useId, useContext, useTransition, useRef, useImperativeHandle, useDeferredValue, useEffect, Suspense } from "react";
|
|
6
6
|
import { useSearchParams, Link, useNavigate, Outlet, useBlocker, useLocation, useParams } from "react-router-dom";
|
|
7
|
-
import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent,
|
|
7
|
+
import { EllipsisHorizontal, XMark, InformationCircleSolid, XMarkMini, TrianglesMini, CheckMini, EllipseMiniSolid, PlusMini, ExclamationCircleSolid, ArrowPath, FlyingBox, CurrencyDollar, Envelope, Channels, Trash, ArrowUpRightOnBox, TriangleDownMini, Check, SquareTwoStack, Photo, TriangleRightMini, Shopping, Buildings, TruckFast, Plus, ReceiptPercent, EllipsisVertical, ArrowUpMini, ArrowDownMini, Minus, PencilSquare } from "@medusajs/icons";
|
|
8
8
|
import Medusa from "@medusajs/js-sdk";
|
|
9
9
|
import { format, formatDistance, sub, subDays, subMonths } from "date-fns";
|
|
10
10
|
import { enUS } from "date-fns/locale";
|
|
@@ -9846,127 +9846,22 @@ const EmailForm = ({ order }) => {
|
|
|
9846
9846
|
const schema$3 = objectType({
|
|
9847
9847
|
email: stringType().email()
|
|
9848
9848
|
});
|
|
9849
|
-
const
|
|
9850
|
-
|
|
9851
|
-
value,
|
|
9852
|
-
onChange,
|
|
9853
|
-
size = "base",
|
|
9854
|
-
min = 0,
|
|
9855
|
-
max = 100,
|
|
9856
|
-
step = 1,
|
|
9857
|
-
className,
|
|
9858
|
-
disabled,
|
|
9859
|
-
...props
|
|
9860
|
-
}, ref) => {
|
|
9861
|
-
const handleChange = (event) => {
|
|
9862
|
-
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
9863
|
-
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
9864
|
-
onChange(newValue);
|
|
9865
|
-
}
|
|
9866
|
-
};
|
|
9867
|
-
const handleIncrement = () => {
|
|
9868
|
-
const newValue = value + step;
|
|
9869
|
-
if (max === void 0 || newValue <= max) {
|
|
9870
|
-
onChange(newValue);
|
|
9871
|
-
}
|
|
9872
|
-
};
|
|
9873
|
-
const handleDecrement = () => {
|
|
9874
|
-
const newValue = value - step;
|
|
9875
|
-
if (min === void 0 || newValue >= min) {
|
|
9876
|
-
onChange(newValue);
|
|
9877
|
-
}
|
|
9878
|
-
};
|
|
9879
|
-
return /* @__PURE__ */ jsxs(
|
|
9880
|
-
"div",
|
|
9881
|
-
{
|
|
9882
|
-
className: clx(
|
|
9883
|
-
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
9884
|
-
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
9885
|
-
{
|
|
9886
|
-
"h-7": size === "small",
|
|
9887
|
-
"h-8": size === "base"
|
|
9888
|
-
},
|
|
9889
|
-
className
|
|
9890
|
-
),
|
|
9891
|
-
children: [
|
|
9892
|
-
/* @__PURE__ */ jsx(
|
|
9893
|
-
"input",
|
|
9894
|
-
{
|
|
9895
|
-
ref,
|
|
9896
|
-
type: "number",
|
|
9897
|
-
value,
|
|
9898
|
-
onChange: handleChange,
|
|
9899
|
-
min,
|
|
9900
|
-
max,
|
|
9901
|
-
step,
|
|
9902
|
-
className: clx(
|
|
9903
|
-
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
9904
|
-
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
9905
|
-
"placeholder:text-ui-fg-muted"
|
|
9906
|
-
),
|
|
9907
|
-
...props
|
|
9908
|
-
}
|
|
9909
|
-
),
|
|
9910
|
-
/* @__PURE__ */ jsxs(
|
|
9911
|
-
"button",
|
|
9912
|
-
{
|
|
9913
|
-
className: clx(
|
|
9914
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
9915
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9916
|
-
"focus:bg-ui-bg-field-component-hover",
|
|
9917
|
-
"hover:bg-ui-bg-field-component-hover",
|
|
9918
|
-
{
|
|
9919
|
-
"size-7": size === "small",
|
|
9920
|
-
"size-8": size === "base"
|
|
9921
|
-
}
|
|
9922
|
-
),
|
|
9923
|
-
type: "button",
|
|
9924
|
-
onClick: handleDecrement,
|
|
9925
|
-
disabled: min !== void 0 && value <= min || disabled,
|
|
9926
|
-
children: [
|
|
9927
|
-
/* @__PURE__ */ jsx(Minus, {}),
|
|
9928
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
9929
|
-
]
|
|
9930
|
-
}
|
|
9931
|
-
),
|
|
9932
|
-
/* @__PURE__ */ jsxs(
|
|
9933
|
-
"button",
|
|
9934
|
-
{
|
|
9935
|
-
className: clx(
|
|
9936
|
-
"flex items-center justify-center outline-none transition-fg",
|
|
9937
|
-
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
9938
|
-
"focus:bg-ui-bg-field-hover",
|
|
9939
|
-
"hover:bg-ui-bg-field-hover",
|
|
9940
|
-
{
|
|
9941
|
-
"size-7": size === "small",
|
|
9942
|
-
"size-8": size === "base"
|
|
9943
|
-
}
|
|
9944
|
-
),
|
|
9945
|
-
type: "button",
|
|
9946
|
-
onClick: handleIncrement,
|
|
9947
|
-
disabled: max !== void 0 && value >= max || disabled,
|
|
9948
|
-
children: [
|
|
9949
|
-
/* @__PURE__ */ jsx(Plus, {}),
|
|
9950
|
-
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
9951
|
-
]
|
|
9952
|
-
}
|
|
9953
|
-
)
|
|
9954
|
-
]
|
|
9955
|
-
}
|
|
9956
|
-
);
|
|
9957
|
-
}
|
|
9958
|
-
);
|
|
9959
|
-
const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
|
|
9960
|
-
const productVariantsQueryKeys = {
|
|
9849
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
9850
|
+
const promotionsQueryKeys = {
|
|
9961
9851
|
list: (query2) => [
|
|
9962
|
-
|
|
9852
|
+
PROMOTION_QUERY_KEY,
|
|
9853
|
+
query2 ? query2 : void 0
|
|
9854
|
+
],
|
|
9855
|
+
detail: (id, query2) => [
|
|
9856
|
+
PROMOTION_QUERY_KEY,
|
|
9857
|
+
id,
|
|
9963
9858
|
query2 ? query2 : void 0
|
|
9964
9859
|
]
|
|
9965
9860
|
};
|
|
9966
|
-
const
|
|
9861
|
+
const usePromotions = (query2, options) => {
|
|
9967
9862
|
const { data, ...rest } = useQuery({
|
|
9968
|
-
queryKey:
|
|
9969
|
-
queryFn: async () =>
|
|
9863
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
9864
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
9970
9865
|
...options
|
|
9971
9866
|
});
|
|
9972
9867
|
return { ...data, ...rest };
|
|
@@ -10017,65 +9912,85 @@ const useInitiateOrderEdit = ({
|
|
|
10017
9912
|
run();
|
|
10018
9913
|
}, [preview, navigate, mutateAsync]);
|
|
10019
9914
|
};
|
|
10020
|
-
|
|
10021
|
-
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10022
|
-
}
|
|
10023
|
-
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
10024
|
-
const Items = () => {
|
|
9915
|
+
const Promotions = () => {
|
|
10025
9916
|
const { id } = useParams();
|
|
10026
9917
|
const {
|
|
10027
9918
|
order: preview,
|
|
10028
|
-
isPending: isPreviewPending,
|
|
10029
9919
|
isError: isPreviewError,
|
|
10030
9920
|
error: previewError
|
|
10031
|
-
} = useOrderPreview(id, void 0
|
|
10032
|
-
placeholderData: keepPreviousData
|
|
10033
|
-
});
|
|
9921
|
+
} = useOrderPreview(id, void 0);
|
|
10034
9922
|
useInitiateOrderEdit({ preview });
|
|
10035
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
10036
|
-
id,
|
|
10037
|
-
{
|
|
10038
|
-
fields: "currency_code"
|
|
10039
|
-
},
|
|
10040
|
-
{
|
|
10041
|
-
enabled: !!id
|
|
10042
|
-
}
|
|
10043
|
-
);
|
|
10044
9923
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10045
|
-
if (isError) {
|
|
10046
|
-
throw error;
|
|
10047
|
-
}
|
|
10048
9924
|
if (isPreviewError) {
|
|
10049
9925
|
throw previewError;
|
|
10050
9926
|
}
|
|
10051
|
-
const
|
|
10052
|
-
return /* @__PURE__ */
|
|
10053
|
-
/* @__PURE__ */ jsx(
|
|
10054
|
-
|
|
10055
|
-
] })
|
|
9927
|
+
const isReady = !!preview;
|
|
9928
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
9929
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
9930
|
+
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
9931
|
+
] });
|
|
10056
9932
|
};
|
|
10057
|
-
const
|
|
10058
|
-
|
|
9933
|
+
const PromotionForm = ({ preview }) => {
|
|
9934
|
+
const { items, shipping_methods } = preview;
|
|
10059
9935
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10060
|
-
const [
|
|
10061
|
-
null
|
|
10062
|
-
);
|
|
9936
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
10063
9937
|
const { handleSuccess } = useRouteModal();
|
|
10064
|
-
const {
|
|
9938
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
9939
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
9940
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
9941
|
+
{
|
|
9942
|
+
id: promoIds
|
|
9943
|
+
},
|
|
9944
|
+
{
|
|
9945
|
+
enabled: !!promoIds.length
|
|
9946
|
+
}
|
|
9947
|
+
);
|
|
9948
|
+
const comboboxData = useComboboxData({
|
|
9949
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
9950
|
+
queryFn: async (params) => {
|
|
9951
|
+
return await sdk.admin.promotion.list({
|
|
9952
|
+
...params,
|
|
9953
|
+
id: {
|
|
9954
|
+
$nin: promoIds
|
|
9955
|
+
}
|
|
9956
|
+
});
|
|
9957
|
+
},
|
|
9958
|
+
getOptions: (data) => {
|
|
9959
|
+
return data.promotions.map((promotion) => ({
|
|
9960
|
+
label: promotion.code,
|
|
9961
|
+
value: promotion.code
|
|
9962
|
+
}));
|
|
9963
|
+
}
|
|
9964
|
+
});
|
|
9965
|
+
const add = async (value) => {
|
|
9966
|
+
if (!value) {
|
|
9967
|
+
return;
|
|
9968
|
+
}
|
|
9969
|
+
addPromotions(
|
|
9970
|
+
{
|
|
9971
|
+
promo_codes: [value]
|
|
9972
|
+
},
|
|
9973
|
+
{
|
|
9974
|
+
onError: (e) => {
|
|
9975
|
+
toast.error(e.message);
|
|
9976
|
+
comboboxData.onSearchValueChange("");
|
|
9977
|
+
setComboboxValue("");
|
|
9978
|
+
},
|
|
9979
|
+
onSuccess: () => {
|
|
9980
|
+
comboboxData.onSearchValueChange("");
|
|
9981
|
+
setComboboxValue("");
|
|
9982
|
+
}
|
|
9983
|
+
}
|
|
9984
|
+
);
|
|
9985
|
+
};
|
|
10065
9986
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10066
|
-
const { mutateAsync: requestOrderEdit } =
|
|
10067
|
-
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
10068
|
-
const matches = useMemo(() => {
|
|
10069
|
-
return matchSorter(preview.items, query2, {
|
|
10070
|
-
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
10071
|
-
});
|
|
10072
|
-
}, [preview.items, query2]);
|
|
9987
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10073
9988
|
const onSubmit = async () => {
|
|
10074
9989
|
setIsSubmitting(true);
|
|
10075
9990
|
let requestSucceeded = false;
|
|
10076
9991
|
await requestOrderEdit(void 0, {
|
|
10077
9992
|
onError: (e) => {
|
|
10078
|
-
toast.error(
|
|
9993
|
+
toast.error(e.message);
|
|
10079
9994
|
},
|
|
10080
9995
|
onSuccess: () => {
|
|
10081
9996
|
requestSucceeded = true;
|
|
@@ -10087,7 +10002,7 @@ const ItemsForm = ({ preview, currencyCode }) => {
|
|
|
10087
10002
|
}
|
|
10088
10003
|
await confirmOrderEdit(void 0, {
|
|
10089
10004
|
onError: (e) => {
|
|
10090
|
-
toast.error(
|
|
10005
|
+
toast.error(e.message);
|
|
10091
10006
|
},
|
|
10092
10007
|
onSuccess: () => {
|
|
10093
10008
|
handleSuccess();
|
|
@@ -10097,860 +10012,294 @@ const ItemsForm = ({ preview, currencyCode }) => {
|
|
|
10097
10012
|
}
|
|
10098
10013
|
});
|
|
10099
10014
|
};
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10015
|
+
if (isError) {
|
|
10016
|
+
throw error;
|
|
10017
|
+
}
|
|
10018
|
+
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10019
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10020
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10021
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10022
|
+
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10023
|
+
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10024
|
+
] }),
|
|
10025
|
+
/* @__PURE__ */ jsx(
|
|
10026
|
+
Combobox,
|
|
10027
|
+
{
|
|
10028
|
+
id: "promotion-combobox",
|
|
10029
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
10030
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10031
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
10032
|
+
options: comboboxData.options,
|
|
10033
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10034
|
+
searchValue: comboboxData.searchValue,
|
|
10035
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10036
|
+
onChange: add,
|
|
10037
|
+
value: comboboxValue
|
|
10038
|
+
}
|
|
10039
|
+
)
|
|
10040
|
+
] }),
|
|
10041
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10042
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
10043
|
+
PromotionItem,
|
|
10044
|
+
{
|
|
10045
|
+
promotion,
|
|
10046
|
+
orderId: preview.id,
|
|
10047
|
+
isLoading: isPending
|
|
10127
10048
|
},
|
|
10128
|
-
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
] }),
|
|
10134
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10135
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
10136
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
10137
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
10138
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
10139
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
10140
|
-
] }),
|
|
10141
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
10142
|
-
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
10143
|
-
Input,
|
|
10144
|
-
{
|
|
10145
|
-
type: "search",
|
|
10146
|
-
placeholder: "Search items",
|
|
10147
|
-
value: searchValue,
|
|
10148
|
-
onChange: (e) => onSearchValueChange(e.target.value)
|
|
10149
|
-
}
|
|
10150
|
-
) }),
|
|
10151
|
-
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
10152
|
-
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
10153
|
-
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
10154
|
-
/* @__PURE__ */ jsx(
|
|
10155
|
-
StackedModalTrigger$1,
|
|
10156
|
-
{
|
|
10157
|
-
type: "add-items",
|
|
10158
|
-
setModalContent
|
|
10159
|
-
}
|
|
10160
|
-
),
|
|
10161
|
-
/* @__PURE__ */ jsx(
|
|
10162
|
-
StackedModalTrigger$1,
|
|
10163
|
-
{
|
|
10164
|
-
type: "add-custom-item",
|
|
10165
|
-
setModalContent
|
|
10166
|
-
}
|
|
10167
|
-
)
|
|
10168
|
-
] })
|
|
10169
|
-
] })
|
|
10170
|
-
] })
|
|
10171
|
-
] }),
|
|
10172
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
10173
|
-
/* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
|
|
10174
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
10175
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
10176
|
-
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
10177
|
-
/* @__PURE__ */ jsx("div", {})
|
|
10178
|
-
] }) }),
|
|
10179
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
10180
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
10181
|
-
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
10182
|
-
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
|
|
10183
|
-
Item,
|
|
10184
|
-
{
|
|
10185
|
-
item,
|
|
10186
|
-
preview,
|
|
10187
|
-
currencyCode
|
|
10188
|
-
},
|
|
10189
|
-
item.id
|
|
10190
|
-
)) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
10191
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
10192
|
-
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
10193
|
-
'No items found for "',
|
|
10194
|
-
query2,
|
|
10195
|
-
'".'
|
|
10196
|
-
] })
|
|
10197
|
-
] }) })
|
|
10198
|
-
] })
|
|
10199
|
-
] }),
|
|
10200
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10201
|
-
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
10202
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
10203
|
-
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
10204
|
-
Text,
|
|
10205
|
-
{
|
|
10206
|
-
size: "small",
|
|
10207
|
-
leading: "compact",
|
|
10208
|
-
className: "text-ui-fg-subtle",
|
|
10209
|
-
children: [
|
|
10210
|
-
itemCount,
|
|
10211
|
-
" ",
|
|
10212
|
-
itemCount === 1 ? "item" : "items"
|
|
10213
|
-
]
|
|
10214
|
-
}
|
|
10215
|
-
) }),
|
|
10216
|
-
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
10217
|
-
] })
|
|
10218
|
-
] }) }),
|
|
10219
|
-
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
|
|
10220
|
-
CustomItemForm,
|
|
10221
|
-
{
|
|
10222
|
-
orderId: preview.id,
|
|
10223
|
-
currencyCode
|
|
10224
|
-
}
|
|
10225
|
-
) : null)
|
|
10226
|
-
]
|
|
10227
|
-
}
|
|
10228
|
-
) }),
|
|
10229
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10230
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10049
|
+
promotion.id
|
|
10050
|
+
)) })
|
|
10051
|
+
] }) }),
|
|
10052
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10053
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10231
10054
|
/* @__PURE__ */ jsx(
|
|
10232
10055
|
Button,
|
|
10233
10056
|
{
|
|
10234
10057
|
size: "small",
|
|
10235
|
-
type: "
|
|
10236
|
-
|
|
10237
|
-
isLoading: isSubmitting,
|
|
10058
|
+
type: "submit",
|
|
10059
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
10238
10060
|
children: "Save"
|
|
10239
10061
|
}
|
|
10240
10062
|
)
|
|
10241
10063
|
] }) })
|
|
10242
10064
|
] });
|
|
10243
10065
|
};
|
|
10244
|
-
const
|
|
10245
|
-
|
|
10246
|
-
|
|
10247
|
-
|
|
10248
|
-
|
|
10249
|
-
|
|
10250
|
-
const
|
|
10251
|
-
const
|
|
10252
|
-
|
|
10253
|
-
defaultValues: {
|
|
10254
|
-
quantity: item.quantity,
|
|
10255
|
-
unit_price: item.unit_price
|
|
10256
|
-
},
|
|
10257
|
-
resolver: zodResolver(variantItemSchema)
|
|
10258
|
-
});
|
|
10259
|
-
const actionId = useMemo(() => {
|
|
10260
|
-
var _a, _b;
|
|
10261
|
-
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10262
|
-
}, [item]);
|
|
10263
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10264
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10265
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10266
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10267
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
10268
|
-
setEditing(false);
|
|
10269
|
-
return;
|
|
10270
|
-
}
|
|
10271
|
-
if (!actionId) {
|
|
10272
|
-
await updateOriginalItem(
|
|
10273
|
-
{
|
|
10274
|
-
item_id: item.id,
|
|
10275
|
-
quantity: data.quantity,
|
|
10276
|
-
unit_price: convertNumber(data.unit_price)
|
|
10277
|
-
},
|
|
10278
|
-
{
|
|
10279
|
-
onSuccess: () => {
|
|
10280
|
-
setEditing(false);
|
|
10281
|
-
},
|
|
10282
|
-
onError: (e) => {
|
|
10283
|
-
toast.error(e.message);
|
|
10284
|
-
}
|
|
10285
|
-
}
|
|
10286
|
-
);
|
|
10287
|
-
return;
|
|
10288
|
-
}
|
|
10289
|
-
await updateActionItem(
|
|
10066
|
+
const PromotionItem = ({
|
|
10067
|
+
promotion,
|
|
10068
|
+
orderId,
|
|
10069
|
+
isLoading
|
|
10070
|
+
}) => {
|
|
10071
|
+
var _a;
|
|
10072
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
10073
|
+
const onRemove = async () => {
|
|
10074
|
+
removePromotions(
|
|
10290
10075
|
{
|
|
10291
|
-
|
|
10292
|
-
quantity: data.quantity,
|
|
10293
|
-
unit_price: convertNumber(data.unit_price)
|
|
10076
|
+
promo_codes: [promotion.code]
|
|
10294
10077
|
},
|
|
10295
10078
|
{
|
|
10296
|
-
onSuccess: () => {
|
|
10297
|
-
setEditing(false);
|
|
10298
|
-
},
|
|
10299
10079
|
onError: (e) => {
|
|
10300
10080
|
toast.error(e.message);
|
|
10301
10081
|
}
|
|
10302
10082
|
}
|
|
10303
10083
|
);
|
|
10304
|
-
}
|
|
10305
|
-
|
|
10306
|
-
|
|
10307
|
-
|
|
10308
|
-
|
|
10084
|
+
};
|
|
10085
|
+
const displayValue = getDisplayValue(promotion);
|
|
10086
|
+
return /* @__PURE__ */ jsxs(
|
|
10087
|
+
"div",
|
|
10088
|
+
{
|
|
10089
|
+
className: clx(
|
|
10090
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
10309
10091
|
{
|
|
10310
|
-
|
|
10311
|
-
alt: item.product_title ?? void 0
|
|
10092
|
+
"animate-pulse": isLoading
|
|
10312
10093
|
}
|
|
10313
10094
|
),
|
|
10314
|
-
|
|
10315
|
-
/* @__PURE__ */ jsxs("div", {
|
|
10316
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children:
|
|
10317
|
-
/* @__PURE__ */ jsxs(
|
|
10318
|
-
|
|
10319
|
-
|
|
10320
|
-
size: "small",
|
|
10321
|
-
|
|
10322
|
-
|
|
10323
|
-
|
|
10324
|
-
"(",
|
|
10325
|
-
item.variant_title,
|
|
10326
|
-
")"
|
|
10327
|
-
]
|
|
10328
|
-
}
|
|
10329
|
-
)
|
|
10095
|
+
children: [
|
|
10096
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
10097
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
10098
|
+
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
10099
|
+
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
10100
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
10101
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
10102
|
+
] }),
|
|
10103
|
+
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
10104
|
+
] })
|
|
10330
10105
|
] }),
|
|
10331
10106
|
/* @__PURE__ */ jsx(
|
|
10332
|
-
|
|
10107
|
+
IconButton,
|
|
10333
10108
|
{
|
|
10334
10109
|
size: "small",
|
|
10335
|
-
|
|
10336
|
-
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10110
|
+
type: "button",
|
|
10111
|
+
variant: "transparent",
|
|
10112
|
+
onClick: onRemove,
|
|
10113
|
+
isLoading: isPending || isLoading,
|
|
10114
|
+
children: /* @__PURE__ */ jsx(XMark, {})
|
|
10115
|
+
}
|
|
10116
|
+
)
|
|
10117
|
+
]
|
|
10118
|
+
},
|
|
10119
|
+
promotion.id
|
|
10120
|
+
);
|
|
10121
|
+
};
|
|
10122
|
+
function getDisplayValue(promotion) {
|
|
10123
|
+
var _a, _b, _c, _d;
|
|
10124
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
10125
|
+
if (!value) {
|
|
10126
|
+
return null;
|
|
10127
|
+
}
|
|
10128
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
10129
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
10130
|
+
if (!currency) {
|
|
10131
|
+
return null;
|
|
10132
|
+
}
|
|
10133
|
+
return getLocaleAmount(value, currency);
|
|
10134
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
10135
|
+
return formatPercentage(value);
|
|
10136
|
+
}
|
|
10137
|
+
return null;
|
|
10138
|
+
}
|
|
10139
|
+
const formatter = new Intl.NumberFormat([], {
|
|
10140
|
+
style: "percent",
|
|
10141
|
+
minimumFractionDigits: 2
|
|
10142
|
+
});
|
|
10143
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
10144
|
+
let val = value || 0;
|
|
10145
|
+
if (!isPercentageValue) {
|
|
10146
|
+
val = val / 100;
|
|
10147
|
+
}
|
|
10148
|
+
return formatter.format(val);
|
|
10149
|
+
};
|
|
10150
|
+
function getPromotionIds(items, shippingMethods) {
|
|
10151
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
10152
|
+
for (const item of items) {
|
|
10153
|
+
if (item.adjustments) {
|
|
10154
|
+
for (const adjustment of item.adjustments) {
|
|
10155
|
+
if (adjustment.promotion_id) {
|
|
10156
|
+
promotionIds.add(adjustment.promotion_id);
|
|
10349
10157
|
}
|
|
10350
10158
|
}
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
|
|
10354
|
-
|
|
10355
|
-
|
|
10356
|
-
|
|
10357
|
-
|
|
10358
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10359
|
-
CurrencyInput,
|
|
10360
|
-
{
|
|
10361
|
-
...field,
|
|
10362
|
-
symbol: getNativeSymbol(currencyCode),
|
|
10363
|
-
code: currencyCode,
|
|
10364
|
-
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
10365
|
-
}
|
|
10366
|
-
) }) });
|
|
10159
|
+
}
|
|
10160
|
+
}
|
|
10161
|
+
for (const shippingMethod of shippingMethods) {
|
|
10162
|
+
if (shippingMethod.adjustments) {
|
|
10163
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
10164
|
+
if (adjustment.promotion_id) {
|
|
10165
|
+
promotionIds.add(adjustment.promotion_id);
|
|
10367
10166
|
}
|
|
10368
10167
|
}
|
|
10369
|
-
|
|
10370
|
-
|
|
10371
|
-
|
|
10168
|
+
}
|
|
10169
|
+
}
|
|
10170
|
+
return Array.from(promotionIds);
|
|
10171
|
+
}
|
|
10172
|
+
const InlineTip = forwardRef(
|
|
10173
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10174
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10175
|
+
return /* @__PURE__ */ jsxs(
|
|
10176
|
+
"div",
|
|
10372
10177
|
{
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
|
|
10377
|
-
|
|
10378
|
-
|
|
10379
|
-
children:
|
|
10178
|
+
ref,
|
|
10179
|
+
className: clx(
|
|
10180
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10181
|
+
className
|
|
10182
|
+
),
|
|
10183
|
+
...props,
|
|
10184
|
+
children: [
|
|
10185
|
+
/* @__PURE__ */ jsx(
|
|
10186
|
+
"div",
|
|
10187
|
+
{
|
|
10188
|
+
role: "presentation",
|
|
10189
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10190
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10191
|
+
})
|
|
10192
|
+
}
|
|
10193
|
+
),
|
|
10194
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10195
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10196
|
+
labelValue,
|
|
10197
|
+
":"
|
|
10198
|
+
] }),
|
|
10199
|
+
" ",
|
|
10200
|
+
children
|
|
10201
|
+
] })
|
|
10202
|
+
]
|
|
10380
10203
|
}
|
|
10381
|
-
)
|
|
10382
|
-
|
|
10383
|
-
|
|
10384
|
-
|
|
10385
|
-
|
|
10386
|
-
|
|
10204
|
+
);
|
|
10205
|
+
}
|
|
10206
|
+
);
|
|
10207
|
+
InlineTip.displayName = "InlineTip";
|
|
10208
|
+
const MetadataFieldSchema = objectType({
|
|
10209
|
+
key: stringType(),
|
|
10210
|
+
disabled: booleanType().optional(),
|
|
10211
|
+
value: anyType()
|
|
10387
10212
|
});
|
|
10388
|
-
const
|
|
10389
|
-
|
|
10390
|
-
|
|
10213
|
+
const MetadataSchema = objectType({
|
|
10214
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
10215
|
+
});
|
|
10216
|
+
const Metadata = () => {
|
|
10217
|
+
const { id } = useParams();
|
|
10218
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10219
|
+
fields: "metadata"
|
|
10220
|
+
});
|
|
10221
|
+
if (isError) {
|
|
10222
|
+
throw error;
|
|
10223
|
+
}
|
|
10224
|
+
const isReady = !isPending && !!order;
|
|
10225
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10226
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10227
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10228
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10229
|
+
] }),
|
|
10230
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10231
|
+
] });
|
|
10232
|
+
};
|
|
10233
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10234
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10235
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
10236
|
+
const { handleSuccess } = useRouteModal();
|
|
10237
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10238
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10391
10239
|
const form = useForm({
|
|
10392
10240
|
defaultValues: {
|
|
10393
|
-
|
|
10394
|
-
quantity,
|
|
10395
|
-
unit_price
|
|
10241
|
+
metadata: getDefaultValues(metadata)
|
|
10396
10242
|
},
|
|
10397
|
-
resolver: zodResolver(
|
|
10243
|
+
resolver: zodResolver(MetadataSchema)
|
|
10398
10244
|
});
|
|
10399
|
-
|
|
10400
|
-
|
|
10401
|
-
|
|
10402
|
-
quantity,
|
|
10403
|
-
unit_price
|
|
10404
|
-
});
|
|
10405
|
-
}, [form, title, quantity, unit_price]);
|
|
10406
|
-
const actionId = useMemo(() => {
|
|
10407
|
-
var _a, _b;
|
|
10408
|
-
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
10409
|
-
}, [item]);
|
|
10410
|
-
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
10411
|
-
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
10412
|
-
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
10413
|
-
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
10414
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10415
|
-
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
|
|
10416
|
-
setEditing(false);
|
|
10417
|
-
return;
|
|
10418
|
-
}
|
|
10419
|
-
if (!actionId) {
|
|
10420
|
-
await updateOriginalItem(
|
|
10421
|
-
{
|
|
10422
|
-
item_id: item.id,
|
|
10423
|
-
quantity: data.quantity,
|
|
10424
|
-
unit_price: convertNumber(data.unit_price)
|
|
10425
|
-
},
|
|
10426
|
-
{
|
|
10427
|
-
onSuccess: () => {
|
|
10428
|
-
setEditing(false);
|
|
10429
|
-
},
|
|
10430
|
-
onError: (e) => {
|
|
10431
|
-
toast.error(e.message);
|
|
10432
|
-
}
|
|
10433
|
-
}
|
|
10434
|
-
);
|
|
10435
|
-
return;
|
|
10436
|
-
}
|
|
10437
|
-
if (data.quantity === 0) {
|
|
10438
|
-
await removeActionItem(actionId, {
|
|
10439
|
-
onSuccess: () => {
|
|
10440
|
-
setEditing(false);
|
|
10441
|
-
},
|
|
10442
|
-
onError: (e) => {
|
|
10443
|
-
toast.error(e.message);
|
|
10444
|
-
}
|
|
10445
|
-
});
|
|
10446
|
-
return;
|
|
10447
|
-
}
|
|
10448
|
-
await updateActionItem(
|
|
10245
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10246
|
+
const parsedData = parseValues(data);
|
|
10247
|
+
await mutateAsync(
|
|
10449
10248
|
{
|
|
10450
|
-
|
|
10451
|
-
quantity: data.quantity,
|
|
10452
|
-
unit_price: convertNumber(data.unit_price)
|
|
10249
|
+
metadata: parsedData
|
|
10453
10250
|
},
|
|
10454
10251
|
{
|
|
10455
10252
|
onSuccess: () => {
|
|
10456
|
-
|
|
10253
|
+
toast.success("Metadata updated");
|
|
10254
|
+
handleSuccess();
|
|
10457
10255
|
},
|
|
10458
|
-
onError: (
|
|
10459
|
-
toast.error(
|
|
10256
|
+
onError: (error) => {
|
|
10257
|
+
toast.error(error.message);
|
|
10460
10258
|
}
|
|
10461
10259
|
}
|
|
10462
10260
|
);
|
|
10463
10261
|
});
|
|
10464
|
-
|
|
10465
|
-
|
|
10466
|
-
|
|
10467
|
-
|
|
10468
|
-
|
|
10469
|
-
|
|
10470
|
-
|
|
10471
|
-
|
|
10472
|
-
|
|
10473
|
-
|
|
10474
|
-
|
|
10475
|
-
|
|
10476
|
-
control: form.control,
|
|
10477
|
-
name: "title",
|
|
10478
|
-
render: ({ field }) => {
|
|
10479
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
|
|
10480
|
-
}
|
|
10481
|
-
}
|
|
10482
|
-
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
|
|
10483
|
-
] }),
|
|
10484
|
-
editing ? /* @__PURE__ */ jsx(
|
|
10485
|
-
Form$2.Field,
|
|
10486
|
-
{
|
|
10487
|
-
control: form.control,
|
|
10488
|
-
name: "quantity",
|
|
10489
|
-
render: ({ field }) => {
|
|
10490
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
10491
|
-
}
|
|
10492
|
-
}
|
|
10493
|
-
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
10494
|
-
editing ? /* @__PURE__ */ jsx(
|
|
10495
|
-
Form$2.Field,
|
|
10496
|
-
{
|
|
10497
|
-
control: form.control,
|
|
10498
|
-
name: "unit_price",
|
|
10499
|
-
render: ({ field: { onChange, ...field } }) => {
|
|
10500
|
-
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10501
|
-
CurrencyInput,
|
|
10502
|
-
{
|
|
10503
|
-
...field,
|
|
10504
|
-
symbol: getNativeSymbol(currencyCode),
|
|
10505
|
-
code: currencyCode,
|
|
10506
|
-
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
10507
|
-
}
|
|
10508
|
-
) }) });
|
|
10509
|
-
}
|
|
10510
|
-
}
|
|
10511
|
-
) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
10512
|
-
/* @__PURE__ */ jsx(
|
|
10513
|
-
IconButton,
|
|
10514
|
-
{
|
|
10515
|
-
type: "button",
|
|
10516
|
-
size: "small",
|
|
10517
|
-
onClick: editing ? onSubmit : () => {
|
|
10518
|
-
setEditing(true);
|
|
10519
|
-
},
|
|
10520
|
-
disabled: isPending,
|
|
10521
|
-
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
10522
|
-
}
|
|
10523
|
-
)
|
|
10524
|
-
] }) }) });
|
|
10525
|
-
};
|
|
10526
|
-
const StackedModalTrigger$1 = ({
|
|
10527
|
-
type,
|
|
10528
|
-
setModalContent
|
|
10529
|
-
}) => {
|
|
10530
|
-
const { setIsOpen } = useStackedModal();
|
|
10531
|
-
const onClick = useCallback(() => {
|
|
10532
|
-
setModalContent(type);
|
|
10533
|
-
setIsOpen(STACKED_MODAL_ID, true);
|
|
10534
|
-
}, [setModalContent, setIsOpen, type]);
|
|
10535
|
-
return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
10536
|
-
};
|
|
10537
|
-
const VARIANT_PREFIX = "items";
|
|
10538
|
-
const LIMIT = 50;
|
|
10539
|
-
const ExistingItemsForm = ({ orderId, items }) => {
|
|
10540
|
-
const { setIsOpen } = useStackedModal();
|
|
10541
|
-
const [rowSelection, setRowSelection] = useState(
|
|
10542
|
-
items.reduce((acc, item) => {
|
|
10543
|
-
acc[item.variant_id] = true;
|
|
10544
|
-
return acc;
|
|
10545
|
-
}, {})
|
|
10546
|
-
);
|
|
10547
|
-
useEffect(() => {
|
|
10548
|
-
setRowSelection(
|
|
10549
|
-
items.reduce((acc, item) => {
|
|
10550
|
-
if (item.variant_id) {
|
|
10551
|
-
acc[item.variant_id] = true;
|
|
10552
|
-
}
|
|
10553
|
-
return acc;
|
|
10554
|
-
}, {})
|
|
10555
|
-
);
|
|
10556
|
-
}, [items]);
|
|
10557
|
-
const { q, order, offset } = useQueryParams(
|
|
10558
|
-
["q", "order", "offset"],
|
|
10559
|
-
VARIANT_PREFIX
|
|
10560
|
-
);
|
|
10561
|
-
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
10562
|
-
{
|
|
10563
|
-
q,
|
|
10564
|
-
order,
|
|
10565
|
-
offset: offset ? parseInt(offset) : void 0,
|
|
10566
|
-
limit: LIMIT
|
|
10567
|
-
},
|
|
10568
|
-
{
|
|
10569
|
-
placeholderData: keepPreviousData
|
|
10262
|
+
const { fields, insert, remove } = useFieldArray({
|
|
10263
|
+
control: form.control,
|
|
10264
|
+
name: "metadata"
|
|
10265
|
+
});
|
|
10266
|
+
function deleteRow(index) {
|
|
10267
|
+
remove(index);
|
|
10268
|
+
if (fields.length === 1) {
|
|
10269
|
+
insert(0, {
|
|
10270
|
+
key: "",
|
|
10271
|
+
value: "",
|
|
10272
|
+
disabled: false
|
|
10273
|
+
});
|
|
10570
10274
|
}
|
|
10571
|
-
);
|
|
10572
|
-
const columns = useColumns();
|
|
10573
|
-
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
10574
|
-
const onSubmit = async () => {
|
|
10575
|
-
const ids = Object.keys(rowSelection).filter(
|
|
10576
|
-
(id) => !items.find((i) => i.variant_id === id)
|
|
10577
|
-
);
|
|
10578
|
-
await mutateAsync(
|
|
10579
|
-
{
|
|
10580
|
-
items: ids.map((id) => ({
|
|
10581
|
-
variant_id: id,
|
|
10582
|
-
quantity: 1
|
|
10583
|
-
}))
|
|
10584
|
-
},
|
|
10585
|
-
{
|
|
10586
|
-
onSuccess: () => {
|
|
10587
|
-
setRowSelection({});
|
|
10588
|
-
setIsOpen(STACKED_MODAL_ID, false);
|
|
10589
|
-
},
|
|
10590
|
-
onError: (e) => {
|
|
10591
|
-
toast.error(e.message);
|
|
10592
|
-
}
|
|
10593
|
-
}
|
|
10594
|
-
);
|
|
10595
|
-
};
|
|
10596
|
-
if (isError) {
|
|
10597
|
-
throw error;
|
|
10598
10275
|
}
|
|
10599
|
-
|
|
10600
|
-
|
|
10276
|
+
function insertRow(index, position) {
|
|
10277
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
10278
|
+
key: "",
|
|
10279
|
+
value: "",
|
|
10280
|
+
disabled: false
|
|
10281
|
+
});
|
|
10282
|
+
}
|
|
10283
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10284
|
+
KeyboundForm,
|
|
10601
10285
|
{
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
const searchInput = document.querySelector(
|
|
10605
|
-
"[data-modal-id='modal-search-input']"
|
|
10606
|
-
);
|
|
10607
|
-
if (searchInput) {
|
|
10608
|
-
searchInput.focus();
|
|
10609
|
-
}
|
|
10610
|
-
},
|
|
10286
|
+
onSubmit: handleSubmit,
|
|
10287
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
10611
10288
|
children: [
|
|
10612
|
-
/* @__PURE__ */ jsxs(
|
|
10613
|
-
/* @__PURE__ */
|
|
10614
|
-
|
|
10615
|
-
|
|
10616
|
-
|
|
10617
|
-
|
|
10618
|
-
|
|
10619
|
-
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
|
|
10623
|
-
rowCount: count,
|
|
10624
|
-
prefix: VARIANT_PREFIX,
|
|
10625
|
-
layout: "fill",
|
|
10626
|
-
rowSelection: {
|
|
10627
|
-
state: rowSelection,
|
|
10628
|
-
onRowSelectionChange: setRowSelection,
|
|
10629
|
-
enableRowSelection: (row) => {
|
|
10630
|
-
return !items.find((i) => i.variant_id === row.original.id);
|
|
10289
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10290
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10291
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10292
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
10293
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
10294
|
+
] }),
|
|
10295
|
+
fields.map((field, index) => {
|
|
10296
|
+
const isDisabled = field.disabled || false;
|
|
10297
|
+
let placeholder = "-";
|
|
10298
|
+
if (typeof field.value === "object") {
|
|
10299
|
+
placeholder = "{ ... }";
|
|
10631
10300
|
}
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
}
|
|
10635
|
-
) }),
|
|
10636
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10637
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10638
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
10639
|
-
] }) })
|
|
10640
|
-
]
|
|
10641
|
-
}
|
|
10642
|
-
);
|
|
10643
|
-
};
|
|
10644
|
-
const columnHelper = createDataTableColumnHelper();
|
|
10645
|
-
const useColumns = () => {
|
|
10646
|
-
return useMemo(() => {
|
|
10647
|
-
return [
|
|
10648
|
-
columnHelper.select(),
|
|
10649
|
-
columnHelper.accessor("product.title", {
|
|
10650
|
-
header: "Product",
|
|
10651
|
-
cell: ({ row }) => {
|
|
10652
|
-
var _a, _b, _c;
|
|
10653
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
10654
|
-
/* @__PURE__ */ jsx(
|
|
10655
|
-
Thumbnail,
|
|
10656
|
-
{
|
|
10657
|
-
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
10658
|
-
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
10659
|
-
}
|
|
10660
|
-
),
|
|
10661
|
-
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
10662
|
-
] });
|
|
10663
|
-
},
|
|
10664
|
-
enableSorting: true
|
|
10665
|
-
}),
|
|
10666
|
-
columnHelper.accessor("title", {
|
|
10667
|
-
header: "Variant",
|
|
10668
|
-
enableSorting: true
|
|
10669
|
-
}),
|
|
10670
|
-
columnHelper.accessor("sku", {
|
|
10671
|
-
header: "SKU",
|
|
10672
|
-
cell: ({ getValue }) => {
|
|
10673
|
-
return getValue() ?? "-";
|
|
10674
|
-
},
|
|
10675
|
-
enableSorting: true
|
|
10676
|
-
}),
|
|
10677
|
-
columnHelper.accessor("updated_at", {
|
|
10678
|
-
header: "Updated",
|
|
10679
|
-
cell: ({ getValue }) => {
|
|
10680
|
-
return /* @__PURE__ */ jsx(
|
|
10681
|
-
Tooltip,
|
|
10682
|
-
{
|
|
10683
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10684
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10685
|
-
}
|
|
10686
|
-
);
|
|
10687
|
-
},
|
|
10688
|
-
enableSorting: true,
|
|
10689
|
-
sortAscLabel: "Oldest first",
|
|
10690
|
-
sortDescLabel: "Newest first"
|
|
10691
|
-
}),
|
|
10692
|
-
columnHelper.accessor("created_at", {
|
|
10693
|
-
header: "Created",
|
|
10694
|
-
cell: ({ getValue }) => {
|
|
10695
|
-
return /* @__PURE__ */ jsx(
|
|
10696
|
-
Tooltip,
|
|
10697
|
-
{
|
|
10698
|
-
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
10699
|
-
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
10700
|
-
}
|
|
10701
|
-
);
|
|
10702
|
-
},
|
|
10703
|
-
enableSorting: true,
|
|
10704
|
-
sortAscLabel: "Oldest first",
|
|
10705
|
-
sortDescLabel: "Newest first"
|
|
10706
|
-
})
|
|
10707
|
-
];
|
|
10708
|
-
}, []);
|
|
10709
|
-
};
|
|
10710
|
-
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
10711
|
-
const { setIsOpen } = useStackedModal();
|
|
10712
|
-
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
10713
|
-
const form = useForm({
|
|
10714
|
-
defaultValues: {
|
|
10715
|
-
title: "",
|
|
10716
|
-
quantity: 1,
|
|
10717
|
-
unit_price: ""
|
|
10718
|
-
},
|
|
10719
|
-
resolver: zodResolver(customItemSchema)
|
|
10720
|
-
});
|
|
10721
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
10722
|
-
await addItems(
|
|
10723
|
-
{
|
|
10724
|
-
items: [
|
|
10725
|
-
{
|
|
10726
|
-
title: data.title,
|
|
10727
|
-
quantity: data.quantity,
|
|
10728
|
-
unit_price: convertNumber(data.unit_price)
|
|
10729
|
-
}
|
|
10730
|
-
]
|
|
10731
|
-
},
|
|
10732
|
-
{
|
|
10733
|
-
onSuccess: () => {
|
|
10734
|
-
setIsOpen(STACKED_MODAL_ID, false);
|
|
10735
|
-
},
|
|
10736
|
-
onError: (e) => {
|
|
10737
|
-
toast.error(e.message);
|
|
10738
|
-
}
|
|
10739
|
-
}
|
|
10740
|
-
);
|
|
10741
|
-
});
|
|
10742
|
-
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
10743
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
10744
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
|
|
10745
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10746
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
10747
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
|
|
10748
|
-
] }),
|
|
10749
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10750
|
-
/* @__PURE__ */ jsx(
|
|
10751
|
-
Form$2.Field,
|
|
10752
|
-
{
|
|
10753
|
-
control: form.control,
|
|
10754
|
-
name: "title",
|
|
10755
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10756
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10757
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
10758
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
10759
|
-
] }),
|
|
10760
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10761
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
10762
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10763
|
-
] })
|
|
10764
|
-
] }) })
|
|
10765
|
-
}
|
|
10766
|
-
),
|
|
10767
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10768
|
-
/* @__PURE__ */ jsx(
|
|
10769
|
-
Form$2.Field,
|
|
10770
|
-
{
|
|
10771
|
-
control: form.control,
|
|
10772
|
-
name: "unit_price",
|
|
10773
|
-
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10774
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10775
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
10776
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
10777
|
-
] }),
|
|
10778
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10779
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
10780
|
-
CurrencyInput,
|
|
10781
|
-
{
|
|
10782
|
-
symbol: getNativeSymbol(currencyCode),
|
|
10783
|
-
code: currencyCode,
|
|
10784
|
-
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
10785
|
-
...field
|
|
10786
|
-
}
|
|
10787
|
-
) }),
|
|
10788
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10789
|
-
] })
|
|
10790
|
-
] }) })
|
|
10791
|
-
}
|
|
10792
|
-
),
|
|
10793
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
10794
|
-
/* @__PURE__ */ jsx(
|
|
10795
|
-
Form$2.Field,
|
|
10796
|
-
{
|
|
10797
|
-
control: form.control,
|
|
10798
|
-
name: "quantity",
|
|
10799
|
-
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
10800
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
10801
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
10802
|
-
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
10803
|
-
] }),
|
|
10804
|
-
/* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
|
|
10805
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
10806
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
10807
|
-
] })
|
|
10808
|
-
] }) })
|
|
10809
|
-
}
|
|
10810
|
-
)
|
|
10811
|
-
] }) }) }),
|
|
10812
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
10813
|
-
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
10814
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
10815
|
-
] }) })
|
|
10816
|
-
] }) }) });
|
|
10817
|
-
};
|
|
10818
|
-
const customItemSchema = objectType({
|
|
10819
|
-
title: stringType().min(1),
|
|
10820
|
-
quantity: numberType(),
|
|
10821
|
-
unit_price: unionType([numberType(), stringType()])
|
|
10822
|
-
});
|
|
10823
|
-
const InlineTip = forwardRef(
|
|
10824
|
-
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
10825
|
-
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
10826
|
-
return /* @__PURE__ */ jsxs(
|
|
10827
|
-
"div",
|
|
10828
|
-
{
|
|
10829
|
-
ref,
|
|
10830
|
-
className: clx(
|
|
10831
|
-
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
10832
|
-
className
|
|
10833
|
-
),
|
|
10834
|
-
...props,
|
|
10835
|
-
children: [
|
|
10836
|
-
/* @__PURE__ */ jsx(
|
|
10837
|
-
"div",
|
|
10838
|
-
{
|
|
10839
|
-
role: "presentation",
|
|
10840
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10841
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10842
|
-
})
|
|
10843
|
-
}
|
|
10844
|
-
),
|
|
10845
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10846
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10847
|
-
labelValue,
|
|
10848
|
-
":"
|
|
10849
|
-
] }),
|
|
10850
|
-
" ",
|
|
10851
|
-
children
|
|
10852
|
-
] })
|
|
10853
|
-
]
|
|
10854
|
-
}
|
|
10855
|
-
);
|
|
10856
|
-
}
|
|
10857
|
-
);
|
|
10858
|
-
InlineTip.displayName = "InlineTip";
|
|
10859
|
-
const MetadataFieldSchema = objectType({
|
|
10860
|
-
key: stringType(),
|
|
10861
|
-
disabled: booleanType().optional(),
|
|
10862
|
-
value: anyType()
|
|
10863
|
-
});
|
|
10864
|
-
const MetadataSchema = objectType({
|
|
10865
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10866
|
-
});
|
|
10867
|
-
const Metadata = () => {
|
|
10868
|
-
const { id } = useParams();
|
|
10869
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10870
|
-
fields: "metadata"
|
|
10871
|
-
});
|
|
10872
|
-
if (isError) {
|
|
10873
|
-
throw error;
|
|
10874
|
-
}
|
|
10875
|
-
const isReady = !isPending && !!order;
|
|
10876
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10877
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
10878
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
10879
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10880
|
-
] }),
|
|
10881
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10882
|
-
] });
|
|
10883
|
-
};
|
|
10884
|
-
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
10885
|
-
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
10886
|
-
const MetadataForm = ({ orderId, metadata }) => {
|
|
10887
|
-
const { handleSuccess } = useRouteModal();
|
|
10888
|
-
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
10889
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
10890
|
-
const form = useForm({
|
|
10891
|
-
defaultValues: {
|
|
10892
|
-
metadata: getDefaultValues(metadata)
|
|
10893
|
-
},
|
|
10894
|
-
resolver: zodResolver(MetadataSchema)
|
|
10895
|
-
});
|
|
10896
|
-
const handleSubmit = form.handleSubmit(async (data) => {
|
|
10897
|
-
const parsedData = parseValues(data);
|
|
10898
|
-
await mutateAsync(
|
|
10899
|
-
{
|
|
10900
|
-
metadata: parsedData
|
|
10901
|
-
},
|
|
10902
|
-
{
|
|
10903
|
-
onSuccess: () => {
|
|
10904
|
-
toast.success("Metadata updated");
|
|
10905
|
-
handleSuccess();
|
|
10906
|
-
},
|
|
10907
|
-
onError: (error) => {
|
|
10908
|
-
toast.error(error.message);
|
|
10909
|
-
}
|
|
10910
|
-
}
|
|
10911
|
-
);
|
|
10912
|
-
});
|
|
10913
|
-
const { fields, insert, remove } = useFieldArray({
|
|
10914
|
-
control: form.control,
|
|
10915
|
-
name: "metadata"
|
|
10916
|
-
});
|
|
10917
|
-
function deleteRow(index) {
|
|
10918
|
-
remove(index);
|
|
10919
|
-
if (fields.length === 1) {
|
|
10920
|
-
insert(0, {
|
|
10921
|
-
key: "",
|
|
10922
|
-
value: "",
|
|
10923
|
-
disabled: false
|
|
10924
|
-
});
|
|
10925
|
-
}
|
|
10926
|
-
}
|
|
10927
|
-
function insertRow(index, position) {
|
|
10928
|
-
insert(index + (position === "above" ? 0 : 1), {
|
|
10929
|
-
key: "",
|
|
10930
|
-
value: "",
|
|
10931
|
-
disabled: false
|
|
10932
|
-
});
|
|
10933
|
-
}
|
|
10934
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
10935
|
-
KeyboundForm,
|
|
10936
|
-
{
|
|
10937
|
-
onSubmit: handleSubmit,
|
|
10938
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
10939
|
-
children: [
|
|
10940
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
10941
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
10942
|
-
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
10943
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
10944
|
-
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
10945
|
-
] }),
|
|
10946
|
-
fields.map((field, index) => {
|
|
10947
|
-
const isDisabled = field.disabled || false;
|
|
10948
|
-
let placeholder = "-";
|
|
10949
|
-
if (typeof field.value === "object") {
|
|
10950
|
-
placeholder = "{ ... }";
|
|
10951
|
-
}
|
|
10952
|
-
if (Array.isArray(field.value)) {
|
|
10953
|
-
placeholder = "[ ... ]";
|
|
10301
|
+
if (Array.isArray(field.value)) {
|
|
10302
|
+
placeholder = "[ ... ]";
|
|
10954
10303
|
}
|
|
10955
10304
|
return /* @__PURE__ */ jsx(
|
|
10956
10305
|
ConditionalTooltip,
|
|
@@ -11170,105 +10519,80 @@ function getHasUneditableRows(metadata) {
|
|
|
11170
10519
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11171
10520
|
);
|
|
11172
10521
|
}
|
|
11173
|
-
|
|
11174
|
-
|
|
11175
|
-
|
|
11176
|
-
|
|
11177
|
-
|
|
11178
|
-
|
|
11179
|
-
detail: (id, query2) => [
|
|
11180
|
-
PROMOTION_QUERY_KEY,
|
|
11181
|
-
id,
|
|
11182
|
-
query2 ? query2 : void 0
|
|
11183
|
-
]
|
|
11184
|
-
};
|
|
11185
|
-
const usePromotions = (query2, options) => {
|
|
11186
|
-
const { data, ...rest } = useQuery({
|
|
11187
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
11188
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11189
|
-
...options
|
|
11190
|
-
});
|
|
11191
|
-
return { ...data, ...rest };
|
|
11192
|
-
};
|
|
11193
|
-
const Promotions = () => {
|
|
10522
|
+
function convertNumber(value) {
|
|
10523
|
+
return typeof value === "string" ? Number(value.replace(",", ".")) : value;
|
|
10524
|
+
}
|
|
10525
|
+
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
10526
|
+
const Shipping = () => {
|
|
10527
|
+
var _a;
|
|
11194
10528
|
const { id } = useParams();
|
|
10529
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
10530
|
+
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
10531
|
+
});
|
|
11195
10532
|
const {
|
|
11196
10533
|
order: preview,
|
|
10534
|
+
isPending: isPreviewPending,
|
|
11197
10535
|
isError: isPreviewError,
|
|
11198
10536
|
error: previewError
|
|
11199
|
-
} = useOrderPreview(id
|
|
10537
|
+
} = useOrderPreview(id);
|
|
11200
10538
|
useInitiateOrderEdit({ preview });
|
|
11201
10539
|
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10540
|
+
if (isError) {
|
|
10541
|
+
throw error;
|
|
10542
|
+
}
|
|
11202
10543
|
if (isPreviewError) {
|
|
11203
10544
|
throw previewError;
|
|
11204
10545
|
}
|
|
11205
|
-
const
|
|
11206
|
-
|
|
11207
|
-
|
|
11208
|
-
|
|
11209
|
-
|
|
10546
|
+
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
10547
|
+
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
10548
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
10549
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
10550
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
10551
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
10552
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
10553
|
+
] }) }) }),
|
|
10554
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
10555
|
+
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
10556
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
10557
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
10558
|
+
] }) });
|
|
11210
10559
|
};
|
|
11211
|
-
const
|
|
11212
|
-
|
|
10560
|
+
const ShippingForm = ({ preview, order }) => {
|
|
10561
|
+
var _a;
|
|
10562
|
+
const { setIsOpen } = useStackedModal();
|
|
11213
10563
|
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11214
|
-
const [
|
|
11215
|
-
const
|
|
11216
|
-
const {
|
|
11217
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11218
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
10564
|
+
const [data, setData] = useState(null);
|
|
10565
|
+
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
10566
|
+
const { shipping_options } = useShippingOptions(
|
|
11219
10567
|
{
|
|
11220
|
-
id:
|
|
10568
|
+
id: appliedShippingOptionIds,
|
|
10569
|
+
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11221
10570
|
},
|
|
11222
10571
|
{
|
|
11223
|
-
enabled:
|
|
10572
|
+
enabled: appliedShippingOptionIds.length > 0
|
|
11224
10573
|
}
|
|
11225
10574
|
);
|
|
11226
|
-
const
|
|
11227
|
-
|
|
11228
|
-
|
|
11229
|
-
|
|
11230
|
-
|
|
11231
|
-
|
|
11232
|
-
|
|
11233
|
-
|
|
11234
|
-
|
|
11235
|
-
|
|
11236
|
-
|
|
11237
|
-
return data.promotions.map((promotion) => ({
|
|
11238
|
-
label: promotion.code,
|
|
11239
|
-
value: promotion.code
|
|
11240
|
-
}));
|
|
11241
|
-
}
|
|
11242
|
-
});
|
|
11243
|
-
const add = async (value) => {
|
|
11244
|
-
if (!value) {
|
|
11245
|
-
return;
|
|
11246
|
-
}
|
|
11247
|
-
addPromotions(
|
|
11248
|
-
{
|
|
11249
|
-
promo_codes: [value]
|
|
11250
|
-
},
|
|
11251
|
-
{
|
|
11252
|
-
onError: (e) => {
|
|
11253
|
-
toast.error(e.message);
|
|
11254
|
-
comboboxData.onSearchValueChange("");
|
|
11255
|
-
setComboboxValue("");
|
|
11256
|
-
},
|
|
11257
|
-
onSuccess: () => {
|
|
11258
|
-
comboboxData.onSearchValueChange("");
|
|
11259
|
-
setComboboxValue("");
|
|
11260
|
-
}
|
|
11261
|
-
}
|
|
11262
|
-
);
|
|
11263
|
-
};
|
|
10575
|
+
const uniqueShippingProfiles = useMemo(() => {
|
|
10576
|
+
const profiles = /* @__PURE__ */ new Map();
|
|
10577
|
+
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
10578
|
+
profiles.set(profile.id, profile);
|
|
10579
|
+
});
|
|
10580
|
+
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
10581
|
+
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
10582
|
+
});
|
|
10583
|
+
return Array.from(profiles.values());
|
|
10584
|
+
}, [order.items, shipping_options]);
|
|
10585
|
+
const { handleSuccess } = useRouteModal();
|
|
11264
10586
|
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11265
|
-
const { mutateAsync: requestOrderEdit } =
|
|
10587
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
10588
|
+
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
10589
|
+
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11266
10590
|
const onSubmit = async () => {
|
|
11267
10591
|
setIsSubmitting(true);
|
|
11268
10592
|
let requestSucceeded = false;
|
|
11269
10593
|
await requestOrderEdit(void 0, {
|
|
11270
10594
|
onError: (e) => {
|
|
11271
|
-
toast.error(e.message);
|
|
10595
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11272
10596
|
},
|
|
11273
10597
|
onSuccess: () => {
|
|
11274
10598
|
requestSucceeded = true;
|
|
@@ -11280,7 +10604,7 @@ const PromotionForm = ({ preview }) => {
|
|
|
11280
10604
|
}
|
|
11281
10605
|
await confirmOrderEdit(void 0, {
|
|
11282
10606
|
onError: (e) => {
|
|
11283
|
-
toast.error(e.message);
|
|
10607
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11284
10608
|
},
|
|
11285
10609
|
onSuccess: () => {
|
|
11286
10610
|
handleSuccess();
|
|
@@ -11290,371 +10614,16 @@ const PromotionForm = ({ preview }) => {
|
|
|
11290
10614
|
}
|
|
11291
10615
|
});
|
|
11292
10616
|
};
|
|
11293
|
-
|
|
11294
|
-
|
|
11295
|
-
|
|
11296
|
-
|
|
11297
|
-
|
|
11298
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11299
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11300
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11301
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11302
|
-
] }),
|
|
11303
|
-
/* @__PURE__ */ jsx(
|
|
11304
|
-
Combobox,
|
|
11305
|
-
{
|
|
11306
|
-
id: "promotion-combobox",
|
|
11307
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11308
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11309
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11310
|
-
options: comboboxData.options,
|
|
11311
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11312
|
-
searchValue: comboboxData.searchValue,
|
|
11313
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11314
|
-
onChange: add,
|
|
11315
|
-
value: comboboxValue
|
|
11316
|
-
}
|
|
11317
|
-
)
|
|
11318
|
-
] }),
|
|
11319
|
-
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
11320
|
-
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsx(
|
|
11321
|
-
PromotionItem,
|
|
11322
|
-
{
|
|
11323
|
-
promotion,
|
|
11324
|
-
orderId: preview.id,
|
|
11325
|
-
isLoading: isPending
|
|
11326
|
-
},
|
|
11327
|
-
promotion.id
|
|
11328
|
-
)) })
|
|
11329
|
-
] }) }),
|
|
11330
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11331
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11332
|
-
/* @__PURE__ */ jsx(
|
|
11333
|
-
Button,
|
|
11334
|
-
{
|
|
11335
|
-
size: "small",
|
|
11336
|
-
type: "submit",
|
|
11337
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11338
|
-
children: "Save"
|
|
11339
|
-
}
|
|
11340
|
-
)
|
|
11341
|
-
] }) })
|
|
11342
|
-
] });
|
|
11343
|
-
};
|
|
11344
|
-
const PromotionItem = ({
|
|
11345
|
-
promotion,
|
|
11346
|
-
orderId,
|
|
11347
|
-
isLoading
|
|
11348
|
-
}) => {
|
|
11349
|
-
var _a;
|
|
11350
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11351
|
-
const onRemove = async () => {
|
|
11352
|
-
removePromotions(
|
|
11353
|
-
{
|
|
11354
|
-
promo_codes: [promotion.code]
|
|
11355
|
-
},
|
|
11356
|
-
{
|
|
11357
|
-
onError: (e) => {
|
|
11358
|
-
toast.error(e.message);
|
|
10617
|
+
const onKeydown = useCallback(
|
|
10618
|
+
(e) => {
|
|
10619
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
10620
|
+
if (data || isSubmitting) {
|
|
10621
|
+
return;
|
|
11359
10622
|
}
|
|
10623
|
+
onSubmit();
|
|
11360
10624
|
}
|
|
11361
|
-
);
|
|
11362
|
-
};
|
|
11363
|
-
const displayValue = getDisplayValue(promotion);
|
|
11364
|
-
return /* @__PURE__ */ jsxs(
|
|
11365
|
-
"div",
|
|
11366
|
-
{
|
|
11367
|
-
className: clx(
|
|
11368
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11369
|
-
{
|
|
11370
|
-
"animate-pulse": isLoading
|
|
11371
|
-
}
|
|
11372
|
-
),
|
|
11373
|
-
children: [
|
|
11374
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11375
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11376
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11377
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11378
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11379
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11380
|
-
] }),
|
|
11381
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11382
|
-
] })
|
|
11383
|
-
] }),
|
|
11384
|
-
/* @__PURE__ */ jsx(
|
|
11385
|
-
IconButton,
|
|
11386
|
-
{
|
|
11387
|
-
size: "small",
|
|
11388
|
-
type: "button",
|
|
11389
|
-
variant: "transparent",
|
|
11390
|
-
onClick: onRemove,
|
|
11391
|
-
isLoading: isPending || isLoading,
|
|
11392
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11393
|
-
}
|
|
11394
|
-
)
|
|
11395
|
-
]
|
|
11396
10625
|
},
|
|
11397
|
-
|
|
11398
|
-
);
|
|
11399
|
-
};
|
|
11400
|
-
function getDisplayValue(promotion) {
|
|
11401
|
-
var _a, _b, _c, _d;
|
|
11402
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11403
|
-
if (!value) {
|
|
11404
|
-
return null;
|
|
11405
|
-
}
|
|
11406
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11407
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11408
|
-
if (!currency) {
|
|
11409
|
-
return null;
|
|
11410
|
-
}
|
|
11411
|
-
return getLocaleAmount(value, currency);
|
|
11412
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11413
|
-
return formatPercentage(value);
|
|
11414
|
-
}
|
|
11415
|
-
return null;
|
|
11416
|
-
}
|
|
11417
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11418
|
-
style: "percent",
|
|
11419
|
-
minimumFractionDigits: 2
|
|
11420
|
-
});
|
|
11421
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11422
|
-
let val = value || 0;
|
|
11423
|
-
if (!isPercentageValue) {
|
|
11424
|
-
val = val / 100;
|
|
11425
|
-
}
|
|
11426
|
-
return formatter.format(val);
|
|
11427
|
-
};
|
|
11428
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11429
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11430
|
-
for (const item of items) {
|
|
11431
|
-
if (item.adjustments) {
|
|
11432
|
-
for (const adjustment of item.adjustments) {
|
|
11433
|
-
if (adjustment.promotion_id) {
|
|
11434
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11435
|
-
}
|
|
11436
|
-
}
|
|
11437
|
-
}
|
|
11438
|
-
}
|
|
11439
|
-
for (const shippingMethod of shippingMethods) {
|
|
11440
|
-
if (shippingMethod.adjustments) {
|
|
11441
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11442
|
-
if (adjustment.promotion_id) {
|
|
11443
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11444
|
-
}
|
|
11445
|
-
}
|
|
11446
|
-
}
|
|
11447
|
-
}
|
|
11448
|
-
return Array.from(promotionIds);
|
|
11449
|
-
}
|
|
11450
|
-
const SalesChannel = () => {
|
|
11451
|
-
const { id } = useParams();
|
|
11452
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11453
|
-
id,
|
|
11454
|
-
{
|
|
11455
|
-
fields: "+sales_channel_id"
|
|
11456
|
-
},
|
|
11457
|
-
{
|
|
11458
|
-
enabled: !!id
|
|
11459
|
-
}
|
|
11460
|
-
);
|
|
11461
|
-
if (isError) {
|
|
11462
|
-
throw error;
|
|
11463
|
-
}
|
|
11464
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
11465
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11466
|
-
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11467
|
-
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
11468
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
11469
|
-
] }),
|
|
11470
|
-
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
11471
|
-
] });
|
|
11472
|
-
};
|
|
11473
|
-
const SalesChannelForm = ({ order }) => {
|
|
11474
|
-
const form = useForm({
|
|
11475
|
-
defaultValues: {
|
|
11476
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11477
|
-
},
|
|
11478
|
-
resolver: zodResolver(schema$2)
|
|
11479
|
-
});
|
|
11480
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11481
|
-
const { handleSuccess } = useRouteModal();
|
|
11482
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
11483
|
-
await mutateAsync(
|
|
11484
|
-
{
|
|
11485
|
-
sales_channel_id: data.sales_channel_id
|
|
11486
|
-
},
|
|
11487
|
-
{
|
|
11488
|
-
onSuccess: () => {
|
|
11489
|
-
toast.success("Sales channel updated");
|
|
11490
|
-
handleSuccess();
|
|
11491
|
-
},
|
|
11492
|
-
onError: (error) => {
|
|
11493
|
-
toast.error(error.message);
|
|
11494
|
-
}
|
|
11495
|
-
}
|
|
11496
|
-
);
|
|
11497
|
-
});
|
|
11498
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11499
|
-
KeyboundForm,
|
|
11500
|
-
{
|
|
11501
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
11502
|
-
onSubmit,
|
|
11503
|
-
children: [
|
|
11504
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11505
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11506
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11507
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11508
|
-
] }) })
|
|
11509
|
-
]
|
|
11510
|
-
}
|
|
11511
|
-
) });
|
|
11512
|
-
};
|
|
11513
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11514
|
-
const salesChannels = useComboboxData({
|
|
11515
|
-
queryFn: async (params) => {
|
|
11516
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11517
|
-
},
|
|
11518
|
-
queryKey: ["sales-channels"],
|
|
11519
|
-
getOptions: (data) => {
|
|
11520
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11521
|
-
label: salesChannel.name,
|
|
11522
|
-
value: salesChannel.id
|
|
11523
|
-
}));
|
|
11524
|
-
},
|
|
11525
|
-
defaultValue: order.sales_channel_id || void 0
|
|
11526
|
-
});
|
|
11527
|
-
return /* @__PURE__ */ jsx(
|
|
11528
|
-
Form$2.Field,
|
|
11529
|
-
{
|
|
11530
|
-
control,
|
|
11531
|
-
name: "sales_channel_id",
|
|
11532
|
-
render: ({ field }) => {
|
|
11533
|
-
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
11534
|
-
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11535
|
-
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
11536
|
-
Combobox,
|
|
11537
|
-
{
|
|
11538
|
-
options: salesChannels.options,
|
|
11539
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11540
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11541
|
-
searchValue: salesChannels.searchValue,
|
|
11542
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11543
|
-
placeholder: "Select sales channel",
|
|
11544
|
-
...field
|
|
11545
|
-
}
|
|
11546
|
-
) }),
|
|
11547
|
-
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
11548
|
-
] });
|
|
11549
|
-
}
|
|
11550
|
-
}
|
|
11551
|
-
);
|
|
11552
|
-
};
|
|
11553
|
-
const schema$2 = objectType({
|
|
11554
|
-
sales_channel_id: stringType().min(1)
|
|
11555
|
-
});
|
|
11556
|
-
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11557
|
-
const Shipping = () => {
|
|
11558
|
-
var _a;
|
|
11559
|
-
const { id } = useParams();
|
|
11560
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
11561
|
-
fields: "+items.*,+items.variant.*,+items.variant.product.*,+items.variant.product.shipping_profile.*,+currency_code"
|
|
11562
|
-
});
|
|
11563
|
-
const {
|
|
11564
|
-
order: preview,
|
|
11565
|
-
isPending: isPreviewPending,
|
|
11566
|
-
isError: isPreviewError,
|
|
11567
|
-
error: previewError
|
|
11568
|
-
} = useOrderPreview(id);
|
|
11569
|
-
useInitiateOrderEdit({ preview });
|
|
11570
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11571
|
-
if (isError) {
|
|
11572
|
-
throw error;
|
|
11573
|
-
}
|
|
11574
|
-
if (isPreviewError) {
|
|
11575
|
-
throw previewError;
|
|
11576
|
-
}
|
|
11577
|
-
const orderHasItems = (((_a = order == null ? void 0 : order.items) == null ? void 0 : _a.length) || 0) > 0;
|
|
11578
|
-
const isReady = preview && !isPreviewPending && order && !isPending;
|
|
11579
|
-
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: !orderHasItems ? /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden ", children: [
|
|
11580
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
11581
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 py-16 px-6", children: [
|
|
11582
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Shipping" }) }),
|
|
11583
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "This draft order currently has no items. Add items to the order before adding shipping." }) })
|
|
11584
|
-
] }) }) }),
|
|
11585
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }) })
|
|
11586
|
-
] }) : isReady ? /* @__PURE__ */ jsx(ShippingForm, { preview, order }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
11587
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Shipping" }) }),
|
|
11588
|
-
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
11589
|
-
] }) });
|
|
11590
|
-
};
|
|
11591
|
-
const ShippingForm = ({ preview, order }) => {
|
|
11592
|
-
var _a;
|
|
11593
|
-
const { setIsOpen } = useStackedModal();
|
|
11594
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11595
|
-
const [data, setData] = useState(null);
|
|
11596
|
-
const appliedShippingOptionIds = (_a = preview.shipping_methods) == null ? void 0 : _a.map((method) => method.shipping_option_id).filter(Boolean);
|
|
11597
|
-
const { shipping_options } = useShippingOptions(
|
|
11598
|
-
{
|
|
11599
|
-
id: appliedShippingOptionIds,
|
|
11600
|
-
fields: "+service_zone.*,+service_zone.fulfillment_set.*,+service_zone.fulfillment_set.location.*"
|
|
11601
|
-
},
|
|
11602
|
-
{
|
|
11603
|
-
enabled: appliedShippingOptionIds.length > 0
|
|
11604
|
-
}
|
|
11605
|
-
);
|
|
11606
|
-
const uniqueShippingProfiles = useMemo(() => {
|
|
11607
|
-
const profiles = /* @__PURE__ */ new Map();
|
|
11608
|
-
getUniqueShippingProfiles(order.items).forEach((profile) => {
|
|
11609
|
-
profiles.set(profile.id, profile);
|
|
11610
|
-
});
|
|
11611
|
-
shipping_options == null ? void 0 : shipping_options.forEach((option) => {
|
|
11612
|
-
profiles.set(option.shipping_profile_id, option.shipping_profile);
|
|
11613
|
-
});
|
|
11614
|
-
return Array.from(profiles.values());
|
|
11615
|
-
}, [order.items, shipping_options]);
|
|
11616
|
-
const { handleSuccess } = useRouteModal();
|
|
11617
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11618
|
-
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
11619
|
-
const { mutateAsync: removeShippingMethod } = useDraftOrderRemoveShippingMethod(preview.id);
|
|
11620
|
-
const { mutateAsync: removeActionShippingMethod } = useDraftOrderRemoveActionShippingMethod(preview.id);
|
|
11621
|
-
const onSubmit = async () => {
|
|
11622
|
-
setIsSubmitting(true);
|
|
11623
|
-
let requestSucceeded = false;
|
|
11624
|
-
await requestOrderEdit(void 0, {
|
|
11625
|
-
onError: (e) => {
|
|
11626
|
-
toast.error(`Failed to request order edit: ${e.message}`);
|
|
11627
|
-
},
|
|
11628
|
-
onSuccess: () => {
|
|
11629
|
-
requestSucceeded = true;
|
|
11630
|
-
}
|
|
11631
|
-
});
|
|
11632
|
-
if (!requestSucceeded) {
|
|
11633
|
-
setIsSubmitting(false);
|
|
11634
|
-
return;
|
|
11635
|
-
}
|
|
11636
|
-
await confirmOrderEdit(void 0, {
|
|
11637
|
-
onError: (e) => {
|
|
11638
|
-
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
11639
|
-
},
|
|
11640
|
-
onSuccess: () => {
|
|
11641
|
-
handleSuccess();
|
|
11642
|
-
},
|
|
11643
|
-
onSettled: () => {
|
|
11644
|
-
setIsSubmitting(false);
|
|
11645
|
-
}
|
|
11646
|
-
});
|
|
11647
|
-
};
|
|
11648
|
-
const onKeydown = useCallback(
|
|
11649
|
-
(e) => {
|
|
11650
|
-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
11651
|
-
if (data || isSubmitting) {
|
|
11652
|
-
return;
|
|
11653
|
-
}
|
|
11654
|
-
onSubmit();
|
|
11655
|
-
}
|
|
11656
|
-
},
|
|
11657
|
-
[data, isSubmitting, onSubmit]
|
|
10626
|
+
[data, isSubmitting, onSubmit]
|
|
11658
10627
|
);
|
|
11659
10628
|
useEffect(() => {
|
|
11660
10629
|
document.addEventListener("keydown", onKeydown);
|
|
@@ -11860,7 +10829,7 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
11860
10829
|
]
|
|
11861
10830
|
}
|
|
11862
10831
|
) : /* @__PURE__ */ jsx(
|
|
11863
|
-
StackedModalTrigger,
|
|
10832
|
+
StackedModalTrigger$1,
|
|
11864
10833
|
{
|
|
11865
10834
|
shippingProfileId: profile.id,
|
|
11866
10835
|
shippingOption,
|
|
@@ -11971,7 +10940,7 @@ const ShippingForm = ({ preview, order }) => {
|
|
|
11971
10940
|
] }) })
|
|
11972
10941
|
] });
|
|
11973
10942
|
};
|
|
11974
|
-
const StackedModalTrigger = ({
|
|
10943
|
+
const StackedModalTrigger$1 = ({
|
|
11975
10944
|
shippingProfileId,
|
|
11976
10945
|
shippingOption,
|
|
11977
10946
|
shippingMethod,
|
|
@@ -12392,7 +11361,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12392
11361
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12393
11362
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12394
11363
|
},
|
|
12395
|
-
resolver: zodResolver(schema$
|
|
11364
|
+
resolver: zodResolver(schema$2)
|
|
12396
11365
|
});
|
|
12397
11366
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12398
11367
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12562,7 +11531,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12562
11531
|
}
|
|
12563
11532
|
) });
|
|
12564
11533
|
};
|
|
12565
|
-
const schema$
|
|
11534
|
+
const schema$2 = addressSchema;
|
|
12566
11535
|
const TransferOwnership = () => {
|
|
12567
11536
|
const { id } = useParams();
|
|
12568
11537
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -12586,7 +11555,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12586
11555
|
defaultValues: {
|
|
12587
11556
|
customer_id: order.customer_id || ""
|
|
12588
11557
|
},
|
|
12589
|
-
resolver: zodResolver(schema)
|
|
11558
|
+
resolver: zodResolver(schema$1)
|
|
12590
11559
|
});
|
|
12591
11560
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12592
11561
|
const { handleSuccess } = useRouteModal();
|
|
@@ -13016,28 +11985,1059 @@ const Illustration = () => {
|
|
|
13016
11985
|
/* @__PURE__ */ jsx("clipPath", { id: "clip4_20915_38670", children: /* @__PURE__ */ jsx(
|
|
13017
11986
|
"rect",
|
|
13018
11987
|
{
|
|
13019
|
-
width: "12",
|
|
13020
|
-
height: "12",
|
|
13021
|
-
fill: "white",
|
|
13022
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
11988
|
+
width: "12",
|
|
11989
|
+
height: "12",
|
|
11990
|
+
fill: "white",
|
|
11991
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 131.318 90.4594)"
|
|
11992
|
+
}
|
|
11993
|
+
) }),
|
|
11994
|
+
/* @__PURE__ */ jsx("clipPath", { id: "clip5_20915_38670", children: /* @__PURE__ */ jsx(
|
|
11995
|
+
"rect",
|
|
11996
|
+
{
|
|
11997
|
+
width: "12",
|
|
11998
|
+
height: "12",
|
|
11999
|
+
fill: "white",
|
|
12000
|
+
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12001
|
+
}
|
|
12002
|
+
) })
|
|
12003
|
+
] })
|
|
12004
|
+
]
|
|
12005
|
+
}
|
|
12006
|
+
);
|
|
12007
|
+
};
|
|
12008
|
+
const schema$1 = objectType({
|
|
12009
|
+
customer_id: stringType().min(1)
|
|
12010
|
+
});
|
|
12011
|
+
const SalesChannel = () => {
|
|
12012
|
+
const { id } = useParams();
|
|
12013
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12014
|
+
id,
|
|
12015
|
+
{
|
|
12016
|
+
fields: "+sales_channel_id"
|
|
12017
|
+
},
|
|
12018
|
+
{
|
|
12019
|
+
enabled: !!id
|
|
12020
|
+
}
|
|
12021
|
+
);
|
|
12022
|
+
if (isError) {
|
|
12023
|
+
throw error;
|
|
12024
|
+
}
|
|
12025
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
12026
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
12027
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
12028
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Sales Channel" }) }),
|
|
12029
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12030
|
+
] }),
|
|
12031
|
+
ISrEADY && /* @__PURE__ */ jsx(SalesChannelForm, { order: draft_order })
|
|
12032
|
+
] });
|
|
12033
|
+
};
|
|
12034
|
+
const SalesChannelForm = ({ order }) => {
|
|
12035
|
+
const form = useForm({
|
|
12036
|
+
defaultValues: {
|
|
12037
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
12038
|
+
},
|
|
12039
|
+
resolver: zodResolver(schema)
|
|
12040
|
+
});
|
|
12041
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12042
|
+
const { handleSuccess } = useRouteModal();
|
|
12043
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12044
|
+
await mutateAsync(
|
|
12045
|
+
{
|
|
12046
|
+
sales_channel_id: data.sales_channel_id
|
|
12047
|
+
},
|
|
12048
|
+
{
|
|
12049
|
+
onSuccess: () => {
|
|
12050
|
+
toast.success("Sales channel updated");
|
|
12051
|
+
handleSuccess();
|
|
12052
|
+
},
|
|
12053
|
+
onError: (error) => {
|
|
12054
|
+
toast.error(error.message);
|
|
12055
|
+
}
|
|
12056
|
+
}
|
|
12057
|
+
);
|
|
12058
|
+
});
|
|
12059
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
12060
|
+
KeyboundForm,
|
|
12061
|
+
{
|
|
12062
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12063
|
+
onSubmit,
|
|
12064
|
+
children: [
|
|
12065
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12066
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12067
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12068
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12069
|
+
] }) })
|
|
12070
|
+
]
|
|
12071
|
+
}
|
|
12072
|
+
) });
|
|
12073
|
+
};
|
|
12074
|
+
const SalesChannelField = ({ control, order }) => {
|
|
12075
|
+
const salesChannels = useComboboxData({
|
|
12076
|
+
queryFn: async (params) => {
|
|
12077
|
+
return await sdk.admin.salesChannel.list(params);
|
|
12078
|
+
},
|
|
12079
|
+
queryKey: ["sales-channels"],
|
|
12080
|
+
getOptions: (data) => {
|
|
12081
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
12082
|
+
label: salesChannel.name,
|
|
12083
|
+
value: salesChannel.id
|
|
12084
|
+
}));
|
|
12085
|
+
},
|
|
12086
|
+
defaultValue: order.sales_channel_id || void 0
|
|
12087
|
+
});
|
|
12088
|
+
return /* @__PURE__ */ jsx(
|
|
12089
|
+
Form$2.Field,
|
|
12090
|
+
{
|
|
12091
|
+
control,
|
|
12092
|
+
name: "sales_channel_id",
|
|
12093
|
+
render: ({ field }) => {
|
|
12094
|
+
return /* @__PURE__ */ jsxs(Form$2.Item, { children: [
|
|
12095
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
12096
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12097
|
+
Combobox,
|
|
12098
|
+
{
|
|
12099
|
+
options: salesChannels.options,
|
|
12100
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
12101
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
12102
|
+
searchValue: salesChannels.searchValue,
|
|
12103
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
12104
|
+
placeholder: "Select sales channel",
|
|
12105
|
+
...field
|
|
12106
|
+
}
|
|
12107
|
+
) }),
|
|
12108
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12109
|
+
] });
|
|
12110
|
+
}
|
|
12111
|
+
}
|
|
12112
|
+
);
|
|
12113
|
+
};
|
|
12114
|
+
const schema = objectType({
|
|
12115
|
+
sales_channel_id: stringType().min(1)
|
|
12116
|
+
});
|
|
12117
|
+
const NumberInput = forwardRef(
|
|
12118
|
+
({
|
|
12119
|
+
value,
|
|
12120
|
+
onChange,
|
|
12121
|
+
size = "base",
|
|
12122
|
+
min = 0,
|
|
12123
|
+
max = 100,
|
|
12124
|
+
step = 1,
|
|
12125
|
+
className,
|
|
12126
|
+
disabled,
|
|
12127
|
+
...props
|
|
12128
|
+
}, ref) => {
|
|
12129
|
+
const handleChange = (event) => {
|
|
12130
|
+
const newValue = event.target.value === "" ? min : Number(event.target.value);
|
|
12131
|
+
if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
|
|
12132
|
+
onChange(newValue);
|
|
12133
|
+
}
|
|
12134
|
+
};
|
|
12135
|
+
const handleIncrement = () => {
|
|
12136
|
+
const newValue = value + step;
|
|
12137
|
+
if (max === void 0 || newValue <= max) {
|
|
12138
|
+
onChange(newValue);
|
|
12139
|
+
}
|
|
12140
|
+
};
|
|
12141
|
+
const handleDecrement = () => {
|
|
12142
|
+
const newValue = value - step;
|
|
12143
|
+
if (min === void 0 || newValue >= min) {
|
|
12144
|
+
onChange(newValue);
|
|
12145
|
+
}
|
|
12146
|
+
};
|
|
12147
|
+
return /* @__PURE__ */ jsxs(
|
|
12148
|
+
"div",
|
|
12149
|
+
{
|
|
12150
|
+
className: clx(
|
|
12151
|
+
"inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
|
|
12152
|
+
"[&:has(input:focus)]:shadow-borders-interactive-with-active",
|
|
12153
|
+
{
|
|
12154
|
+
"h-7": size === "small",
|
|
12155
|
+
"h-8": size === "base"
|
|
12156
|
+
},
|
|
12157
|
+
className
|
|
12158
|
+
),
|
|
12159
|
+
children: [
|
|
12160
|
+
/* @__PURE__ */ jsx(
|
|
12161
|
+
"input",
|
|
12162
|
+
{
|
|
12163
|
+
ref,
|
|
12164
|
+
type: "number",
|
|
12165
|
+
value,
|
|
12166
|
+
onChange: handleChange,
|
|
12167
|
+
min,
|
|
12168
|
+
max,
|
|
12169
|
+
step,
|
|
12170
|
+
className: clx(
|
|
12171
|
+
"flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
|
|
12172
|
+
"[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
|
|
12173
|
+
"placeholder:text-ui-fg-muted"
|
|
12174
|
+
),
|
|
12175
|
+
...props
|
|
12176
|
+
}
|
|
12177
|
+
),
|
|
12178
|
+
/* @__PURE__ */ jsxs(
|
|
12179
|
+
"button",
|
|
12180
|
+
{
|
|
12181
|
+
className: clx(
|
|
12182
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
12183
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
12184
|
+
"focus:bg-ui-bg-field-component-hover",
|
|
12185
|
+
"hover:bg-ui-bg-field-component-hover",
|
|
12186
|
+
{
|
|
12187
|
+
"size-7": size === "small",
|
|
12188
|
+
"size-8": size === "base"
|
|
12189
|
+
}
|
|
12190
|
+
),
|
|
12191
|
+
type: "button",
|
|
12192
|
+
onClick: handleDecrement,
|
|
12193
|
+
disabled: min !== void 0 && value <= min || disabled,
|
|
12194
|
+
children: [
|
|
12195
|
+
/* @__PURE__ */ jsx(Minus, {}),
|
|
12196
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
|
|
12197
|
+
]
|
|
12198
|
+
}
|
|
12199
|
+
),
|
|
12200
|
+
/* @__PURE__ */ jsxs(
|
|
12201
|
+
"button",
|
|
12202
|
+
{
|
|
12203
|
+
className: clx(
|
|
12204
|
+
"flex items-center justify-center outline-none transition-fg",
|
|
12205
|
+
"disabled:cursor-not-allowed disabled:text-ui-fg-muted",
|
|
12206
|
+
"focus:bg-ui-bg-field-hover",
|
|
12207
|
+
"hover:bg-ui-bg-field-hover",
|
|
12208
|
+
{
|
|
12209
|
+
"size-7": size === "small",
|
|
12210
|
+
"size-8": size === "base"
|
|
12211
|
+
}
|
|
12212
|
+
),
|
|
12213
|
+
type: "button",
|
|
12214
|
+
onClick: handleIncrement,
|
|
12215
|
+
disabled: max !== void 0 && value >= max || disabled,
|
|
12216
|
+
children: [
|
|
12217
|
+
/* @__PURE__ */ jsx(Plus, {}),
|
|
12218
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: `Increase by ${step}` })
|
|
12219
|
+
]
|
|
12220
|
+
}
|
|
12221
|
+
)
|
|
12222
|
+
]
|
|
12223
|
+
}
|
|
12224
|
+
);
|
|
12225
|
+
}
|
|
12226
|
+
);
|
|
12227
|
+
const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
|
|
12228
|
+
const productVariantsQueryKeys = {
|
|
12229
|
+
list: (query2) => [
|
|
12230
|
+
PRODUCT_VARIANTS_QUERY_KEY,
|
|
12231
|
+
query2 ? query2 : void 0
|
|
12232
|
+
]
|
|
12233
|
+
};
|
|
12234
|
+
const useProductVariants = (query2, options) => {
|
|
12235
|
+
const { data, ...rest } = useQuery({
|
|
12236
|
+
queryKey: productVariantsQueryKeys.list(query2),
|
|
12237
|
+
queryFn: async () => await sdk.admin.productVariant.list(query2),
|
|
12238
|
+
...options
|
|
12239
|
+
});
|
|
12240
|
+
return { ...data, ...rest };
|
|
12241
|
+
};
|
|
12242
|
+
const STACKED_MODAL_ID = "items_stacked_modal";
|
|
12243
|
+
const Items = () => {
|
|
12244
|
+
const { id } = useParams();
|
|
12245
|
+
const {
|
|
12246
|
+
order: preview,
|
|
12247
|
+
isPending: isPreviewPending,
|
|
12248
|
+
isError: isPreviewError,
|
|
12249
|
+
error: previewError
|
|
12250
|
+
} = useOrderPreview(id, void 0, {
|
|
12251
|
+
placeholderData: keepPreviousData
|
|
12252
|
+
});
|
|
12253
|
+
useInitiateOrderEdit({ preview });
|
|
12254
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12255
|
+
id,
|
|
12256
|
+
{
|
|
12257
|
+
fields: "currency_code"
|
|
12258
|
+
},
|
|
12259
|
+
{
|
|
12260
|
+
enabled: !!id
|
|
12261
|
+
}
|
|
12262
|
+
);
|
|
12263
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
12264
|
+
if (isError) {
|
|
12265
|
+
throw error;
|
|
12266
|
+
}
|
|
12267
|
+
if (isPreviewError) {
|
|
12268
|
+
throw previewError;
|
|
12269
|
+
}
|
|
12270
|
+
const ready = !!preview && !isPreviewPending && !!draft_order && !isPending;
|
|
12271
|
+
return /* @__PURE__ */ jsx(RouteFocusModal, { onClose: onCancel, children: ready ? /* @__PURE__ */ jsx(ItemsForm, { preview, currencyCode: draft_order.currency_code }) : /* @__PURE__ */ jsxs("div", { children: [
|
|
12272
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Edit Items" }) }),
|
|
12273
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Loading data for the draft order, please wait..." }) })
|
|
12274
|
+
] }) });
|
|
12275
|
+
};
|
|
12276
|
+
const ItemsForm = ({ preview, currencyCode }) => {
|
|
12277
|
+
var _a;
|
|
12278
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
12279
|
+
const [modalContent, setModalContent] = useState(
|
|
12280
|
+
null
|
|
12281
|
+
);
|
|
12282
|
+
const { handleSuccess } = useRouteModal();
|
|
12283
|
+
const { searchValue, onSearchValueChange, query: query2 } = useDebouncedSearch();
|
|
12284
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
12285
|
+
const { mutateAsync: requestOrderEdit } = useDraftOrderRequestEdit(preview.id);
|
|
12286
|
+
const itemCount = ((_a = preview.items) == null ? void 0 : _a.reduce((acc, item) => acc + item.quantity, 0)) || 0;
|
|
12287
|
+
const matches = useMemo(() => {
|
|
12288
|
+
return matchSorter(preview.items, query2, {
|
|
12289
|
+
keys: ["product_title", "variant_title", "variant_sku", "title"]
|
|
12290
|
+
});
|
|
12291
|
+
}, [preview.items, query2]);
|
|
12292
|
+
const onSubmit = async () => {
|
|
12293
|
+
setIsSubmitting(true);
|
|
12294
|
+
let requestSucceeded = false;
|
|
12295
|
+
await requestOrderEdit(void 0, {
|
|
12296
|
+
onError: (e) => {
|
|
12297
|
+
toast.error(`Failed to request order edit: ${e.message}`);
|
|
12298
|
+
},
|
|
12299
|
+
onSuccess: () => {
|
|
12300
|
+
requestSucceeded = true;
|
|
12301
|
+
}
|
|
12302
|
+
});
|
|
12303
|
+
if (!requestSucceeded) {
|
|
12304
|
+
setIsSubmitting(false);
|
|
12305
|
+
return;
|
|
12306
|
+
}
|
|
12307
|
+
await confirmOrderEdit(void 0, {
|
|
12308
|
+
onError: (e) => {
|
|
12309
|
+
toast.error(`Failed to confirm order edit: ${e.message}`);
|
|
12310
|
+
},
|
|
12311
|
+
onSuccess: () => {
|
|
12312
|
+
handleSuccess();
|
|
12313
|
+
},
|
|
12314
|
+
onSettled: () => {
|
|
12315
|
+
setIsSubmitting(false);
|
|
12316
|
+
}
|
|
12317
|
+
});
|
|
12318
|
+
};
|
|
12319
|
+
const onKeyDown = useCallback(
|
|
12320
|
+
(e) => {
|
|
12321
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
12322
|
+
if (modalContent || isSubmitting) {
|
|
12323
|
+
return;
|
|
12324
|
+
}
|
|
12325
|
+
onSubmit();
|
|
12326
|
+
}
|
|
12327
|
+
},
|
|
12328
|
+
[modalContent, isSubmitting, onSubmit]
|
|
12329
|
+
);
|
|
12330
|
+
useEffect(() => {
|
|
12331
|
+
document.addEventListener("keydown", onKeyDown);
|
|
12332
|
+
return () => {
|
|
12333
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
12334
|
+
};
|
|
12335
|
+
}, [onKeyDown]);
|
|
12336
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex h-full flex-col overflow-hidden", children: [
|
|
12337
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Header, {}),
|
|
12338
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxs(
|
|
12339
|
+
StackedFocusModal,
|
|
12340
|
+
{
|
|
12341
|
+
id: STACKED_MODAL_ID,
|
|
12342
|
+
onOpenChangeCallback: (open) => {
|
|
12343
|
+
if (!open) {
|
|
12344
|
+
setModalContent(null);
|
|
12345
|
+
}
|
|
12346
|
+
},
|
|
12347
|
+
children: [
|
|
12348
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-6 py-16", children: [
|
|
12349
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12350
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Items" }) }),
|
|
12351
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Edit the items in the draft order" }) })
|
|
12352
|
+
] }),
|
|
12353
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12354
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-y-6", children: [
|
|
12355
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 items-center gap-3", children: [
|
|
12356
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12357
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Items" }),
|
|
12358
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Choose items from the product catalog." })
|
|
12359
|
+
] }),
|
|
12360
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
12361
|
+
/* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
|
|
12362
|
+
Input,
|
|
12363
|
+
{
|
|
12364
|
+
type: "search",
|
|
12365
|
+
placeholder: "Search items",
|
|
12366
|
+
value: searchValue,
|
|
12367
|
+
onChange: (e) => onSearchValueChange(e.target.value)
|
|
12368
|
+
}
|
|
12369
|
+
) }),
|
|
12370
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
12371
|
+
/* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { type: "button", children: /* @__PURE__ */ jsx(Plus, {}) }) }),
|
|
12372
|
+
/* @__PURE__ */ jsxs(DropdownMenu.Content, { children: [
|
|
12373
|
+
/* @__PURE__ */ jsx(
|
|
12374
|
+
StackedModalTrigger,
|
|
12375
|
+
{
|
|
12376
|
+
type: "add-items",
|
|
12377
|
+
setModalContent
|
|
12378
|
+
}
|
|
12379
|
+
),
|
|
12380
|
+
/* @__PURE__ */ jsx(
|
|
12381
|
+
StackedModalTrigger,
|
|
12382
|
+
{
|
|
12383
|
+
type: "add-custom-item",
|
|
12384
|
+
setModalContent
|
|
12385
|
+
}
|
|
12386
|
+
)
|
|
12387
|
+
] })
|
|
12388
|
+
] })
|
|
12389
|
+
] })
|
|
12390
|
+
] }),
|
|
12391
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle shadow-elevation-card-rest rounded-xl", children: [
|
|
12392
|
+
/* @__PURE__ */ jsx("div", { className: "px-[5px]", children: /* @__PURE__ */ jsxs("div", { className: "text-ui-fg-muted grid grid-cols-[2fr_1fr_2fr_28px] gap-3 px-4 py-2", children: [
|
|
12393
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Item" }) }),
|
|
12394
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Quantity" }) }),
|
|
12395
|
+
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Price" }) }),
|
|
12396
|
+
/* @__PURE__ */ jsx("div", {})
|
|
12397
|
+
] }) }),
|
|
12398
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col gap-y-1.5 px-[5px] pb-[5px]", children: itemCount <= 0 ? /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
12399
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "There are no items in this order" }),
|
|
12400
|
+
/* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add items to the order to get started." })
|
|
12401
|
+
] }) : matches.length > 0 ? matches == null ? void 0 : matches.map((item) => /* @__PURE__ */ jsx(
|
|
12402
|
+
Item,
|
|
12403
|
+
{
|
|
12404
|
+
item,
|
|
12405
|
+
preview,
|
|
12406
|
+
currencyCode
|
|
12407
|
+
},
|
|
12408
|
+
item.id
|
|
12409
|
+
)) : /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest flex flex-col items-center justify-center gap-1 gap-x-3 rounded-lg p-4", children: [
|
|
12410
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "No items found" }),
|
|
12411
|
+
/* @__PURE__ */ jsxs(Text, { size: "small", className: "text-ui-fg-subtle", children: [
|
|
12412
|
+
'No items found for "',
|
|
12413
|
+
query2,
|
|
12414
|
+
'".'
|
|
12415
|
+
] })
|
|
12416
|
+
] }) })
|
|
12417
|
+
] })
|
|
12418
|
+
] }),
|
|
12419
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12420
|
+
/* @__PURE__ */ jsxs("div", { className: "grid grid-cols-[1fr_0.5fr_0.5fr] gap-3", children: [
|
|
12421
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: "Subtotal" }) }),
|
|
12422
|
+
/* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsxs(
|
|
12423
|
+
Text,
|
|
12424
|
+
{
|
|
12425
|
+
size: "small",
|
|
12426
|
+
leading: "compact",
|
|
12427
|
+
className: "text-ui-fg-subtle",
|
|
12428
|
+
children: [
|
|
12429
|
+
itemCount,
|
|
12430
|
+
" ",
|
|
12431
|
+
itemCount === 1 ? "item" : "items"
|
|
12432
|
+
]
|
|
12433
|
+
}
|
|
12434
|
+
) }),
|
|
12435
|
+
/* @__PURE__ */ jsx("div", { className: "text-right", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: getStylizedAmount(preview.item_subtotal, currencyCode) }) })
|
|
12436
|
+
] })
|
|
12437
|
+
] }) }),
|
|
12438
|
+
modalContent && (modalContent === "add-items" ? /* @__PURE__ */ jsx(ExistingItemsForm, { orderId: preview.id, items: preview.items }) : modalContent === "add-custom-item" ? /* @__PURE__ */ jsx(
|
|
12439
|
+
CustomItemForm,
|
|
12440
|
+
{
|
|
12441
|
+
orderId: preview.id,
|
|
12442
|
+
currencyCode
|
|
12443
|
+
}
|
|
12444
|
+
) : null)
|
|
12445
|
+
]
|
|
12446
|
+
}
|
|
12447
|
+
) }),
|
|
12448
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12449
|
+
/* @__PURE__ */ jsx(RouteFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12450
|
+
/* @__PURE__ */ jsx(
|
|
12451
|
+
Button,
|
|
12452
|
+
{
|
|
12453
|
+
size: "small",
|
|
12454
|
+
type: "button",
|
|
12455
|
+
onClick: onSubmit,
|
|
12456
|
+
isLoading: isSubmitting,
|
|
12457
|
+
children: "Save"
|
|
12458
|
+
}
|
|
12459
|
+
)
|
|
12460
|
+
] }) })
|
|
12461
|
+
] });
|
|
12462
|
+
};
|
|
12463
|
+
const Item = ({ item, preview, currencyCode }) => {
|
|
12464
|
+
if (item.variant_id) {
|
|
12465
|
+
return /* @__PURE__ */ jsx(VariantItem, { item, preview, currencyCode });
|
|
12466
|
+
}
|
|
12467
|
+
return /* @__PURE__ */ jsx(CustomItem, { item, preview, currencyCode });
|
|
12468
|
+
};
|
|
12469
|
+
const VariantItem = ({ item, preview, currencyCode }) => {
|
|
12470
|
+
const [editing, setEditing] = useState(false);
|
|
12471
|
+
const form = useForm({
|
|
12472
|
+
defaultValues: {
|
|
12473
|
+
quantity: item.quantity,
|
|
12474
|
+
unit_price: item.unit_price
|
|
12475
|
+
},
|
|
12476
|
+
resolver: zodResolver(variantItemSchema)
|
|
12477
|
+
});
|
|
12478
|
+
const actionId = useMemo(() => {
|
|
12479
|
+
var _a, _b;
|
|
12480
|
+
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
12481
|
+
}, [item]);
|
|
12482
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
12483
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
12484
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
12485
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12486
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
|
|
12487
|
+
setEditing(false);
|
|
12488
|
+
return;
|
|
12489
|
+
}
|
|
12490
|
+
if (!actionId) {
|
|
12491
|
+
await updateOriginalItem(
|
|
12492
|
+
{
|
|
12493
|
+
item_id: item.id,
|
|
12494
|
+
quantity: data.quantity,
|
|
12495
|
+
unit_price: convertNumber(data.unit_price)
|
|
12496
|
+
},
|
|
12497
|
+
{
|
|
12498
|
+
onSuccess: () => {
|
|
12499
|
+
setEditing(false);
|
|
12500
|
+
},
|
|
12501
|
+
onError: (e) => {
|
|
12502
|
+
toast.error(e.message);
|
|
12503
|
+
}
|
|
12504
|
+
}
|
|
12505
|
+
);
|
|
12506
|
+
return;
|
|
12507
|
+
}
|
|
12508
|
+
await updateActionItem(
|
|
12509
|
+
{
|
|
12510
|
+
action_id: actionId,
|
|
12511
|
+
quantity: data.quantity,
|
|
12512
|
+
unit_price: convertNumber(data.unit_price)
|
|
12513
|
+
},
|
|
12514
|
+
{
|
|
12515
|
+
onSuccess: () => {
|
|
12516
|
+
setEditing(false);
|
|
12517
|
+
},
|
|
12518
|
+
onError: (e) => {
|
|
12519
|
+
toast.error(e.message);
|
|
12520
|
+
}
|
|
12521
|
+
}
|
|
12522
|
+
);
|
|
12523
|
+
});
|
|
12524
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
12525
|
+
/* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
|
|
12526
|
+
/* @__PURE__ */ jsx(
|
|
12527
|
+
Thumbnail,
|
|
12528
|
+
{
|
|
12529
|
+
thumbnail: item.thumbnail,
|
|
12530
|
+
alt: item.product_title ?? void 0
|
|
12531
|
+
}
|
|
12532
|
+
),
|
|
12533
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
12534
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-1", children: [
|
|
12535
|
+
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
|
|
12536
|
+
/* @__PURE__ */ jsxs(
|
|
12537
|
+
Text,
|
|
12538
|
+
{
|
|
12539
|
+
size: "small",
|
|
12540
|
+
leading: "compact",
|
|
12541
|
+
className: "text-ui-fg-subtle",
|
|
12542
|
+
children: [
|
|
12543
|
+
"(",
|
|
12544
|
+
item.variant_title,
|
|
12545
|
+
")"
|
|
12546
|
+
]
|
|
12547
|
+
}
|
|
12548
|
+
)
|
|
12549
|
+
] }),
|
|
12550
|
+
/* @__PURE__ */ jsx(
|
|
12551
|
+
Text,
|
|
12552
|
+
{
|
|
12553
|
+
size: "small",
|
|
12554
|
+
leading: "compact",
|
|
12555
|
+
className: "text-ui-fg-subtle",
|
|
12556
|
+
children: item.variant_sku
|
|
12557
|
+
}
|
|
12558
|
+
)
|
|
12559
|
+
] })
|
|
12560
|
+
] }),
|
|
12561
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
|
|
12562
|
+
Form$2.Field,
|
|
12563
|
+
{
|
|
12564
|
+
control: form.control,
|
|
12565
|
+
name: "quantity",
|
|
12566
|
+
render: ({ field }) => {
|
|
12567
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
12568
|
+
}
|
|
12569
|
+
}
|
|
12570
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }) }),
|
|
12571
|
+
editing ? /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(
|
|
12572
|
+
Form$2.Field,
|
|
12573
|
+
{
|
|
12574
|
+
control: form.control,
|
|
12575
|
+
name: "unit_price",
|
|
12576
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
12577
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12578
|
+
CurrencyInput,
|
|
12579
|
+
{
|
|
12580
|
+
...field,
|
|
12581
|
+
symbol: getNativeSymbol(currencyCode),
|
|
12582
|
+
code: currencyCode,
|
|
12583
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
12584
|
+
}
|
|
12585
|
+
) }) });
|
|
12586
|
+
}
|
|
12587
|
+
}
|
|
12588
|
+
) }) : /* @__PURE__ */ jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
12589
|
+
/* @__PURE__ */ jsx(
|
|
12590
|
+
IconButton,
|
|
12591
|
+
{
|
|
12592
|
+
type: "button",
|
|
12593
|
+
size: "small",
|
|
12594
|
+
onClick: editing ? onSubmit : () => {
|
|
12595
|
+
setEditing(true);
|
|
12596
|
+
},
|
|
12597
|
+
disabled: isPending,
|
|
12598
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
12599
|
+
}
|
|
12600
|
+
)
|
|
12601
|
+
] }) }) });
|
|
12602
|
+
};
|
|
12603
|
+
const variantItemSchema = objectType({
|
|
12604
|
+
quantity: numberType(),
|
|
12605
|
+
unit_price: unionType([numberType(), stringType()])
|
|
12606
|
+
});
|
|
12607
|
+
const CustomItem = ({ item, preview, currencyCode }) => {
|
|
12608
|
+
const [editing, setEditing] = useState(false);
|
|
12609
|
+
const { quantity, unit_price, title } = item;
|
|
12610
|
+
const form = useForm({
|
|
12611
|
+
defaultValues: {
|
|
12612
|
+
title,
|
|
12613
|
+
quantity,
|
|
12614
|
+
unit_price
|
|
12615
|
+
},
|
|
12616
|
+
resolver: zodResolver(customItemSchema)
|
|
12617
|
+
});
|
|
12618
|
+
useEffect(() => {
|
|
12619
|
+
form.reset({
|
|
12620
|
+
title,
|
|
12621
|
+
quantity,
|
|
12622
|
+
unit_price
|
|
12623
|
+
});
|
|
12624
|
+
}, [form, title, quantity, unit_price]);
|
|
12625
|
+
const actionId = useMemo(() => {
|
|
12626
|
+
var _a, _b;
|
|
12627
|
+
return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
|
|
12628
|
+
}, [item]);
|
|
12629
|
+
const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
|
|
12630
|
+
const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
|
|
12631
|
+
const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
|
|
12632
|
+
const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
|
|
12633
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12634
|
+
if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
|
|
12635
|
+
setEditing(false);
|
|
12636
|
+
return;
|
|
12637
|
+
}
|
|
12638
|
+
if (!actionId) {
|
|
12639
|
+
await updateOriginalItem(
|
|
12640
|
+
{
|
|
12641
|
+
item_id: item.id,
|
|
12642
|
+
quantity: data.quantity,
|
|
12643
|
+
unit_price: convertNumber(data.unit_price)
|
|
12644
|
+
},
|
|
12645
|
+
{
|
|
12646
|
+
onSuccess: () => {
|
|
12647
|
+
setEditing(false);
|
|
12648
|
+
},
|
|
12649
|
+
onError: (e) => {
|
|
12650
|
+
toast.error(e.message);
|
|
12651
|
+
}
|
|
12652
|
+
}
|
|
12653
|
+
);
|
|
12654
|
+
return;
|
|
12655
|
+
}
|
|
12656
|
+
if (data.quantity === 0) {
|
|
12657
|
+
await removeActionItem(actionId, {
|
|
12658
|
+
onSuccess: () => {
|
|
12659
|
+
setEditing(false);
|
|
12660
|
+
},
|
|
12661
|
+
onError: (e) => {
|
|
12662
|
+
toast.error(e.message);
|
|
12663
|
+
}
|
|
12664
|
+
});
|
|
12665
|
+
return;
|
|
12666
|
+
}
|
|
12667
|
+
await updateActionItem(
|
|
12668
|
+
{
|
|
12669
|
+
action_id: actionId,
|
|
12670
|
+
quantity: data.quantity,
|
|
12671
|
+
unit_price: convertNumber(data.unit_price)
|
|
12672
|
+
},
|
|
12673
|
+
{
|
|
12674
|
+
onSuccess: () => {
|
|
12675
|
+
setEditing(false);
|
|
12676
|
+
},
|
|
12677
|
+
onError: (e) => {
|
|
12678
|
+
toast.error(e.message);
|
|
12679
|
+
}
|
|
12680
|
+
}
|
|
12681
|
+
);
|
|
12682
|
+
});
|
|
12683
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx("form", { onSubmit, children: /* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
|
|
12684
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-3", children: [
|
|
12685
|
+
/* @__PURE__ */ jsx(
|
|
12686
|
+
Thumbnail,
|
|
12687
|
+
{
|
|
12688
|
+
thumbnail: item.thumbnail,
|
|
12689
|
+
alt: item.title ?? void 0
|
|
12690
|
+
}
|
|
12691
|
+
),
|
|
12692
|
+
editing ? /* @__PURE__ */ jsx(
|
|
12693
|
+
Form$2.Field,
|
|
12694
|
+
{
|
|
12695
|
+
control: form.control,
|
|
12696
|
+
name: "title",
|
|
12697
|
+
render: ({ field }) => {
|
|
12698
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }) });
|
|
12699
|
+
}
|
|
12700
|
+
}
|
|
12701
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.title })
|
|
12702
|
+
] }),
|
|
12703
|
+
editing ? /* @__PURE__ */ jsx(
|
|
12704
|
+
Form$2.Field,
|
|
12705
|
+
{
|
|
12706
|
+
control: form.control,
|
|
12707
|
+
name: "quantity",
|
|
12708
|
+
render: ({ field }) => {
|
|
12709
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(NumberInput, { ...field }) }) });
|
|
12710
|
+
}
|
|
12711
|
+
}
|
|
12712
|
+
) : /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: item.quantity }),
|
|
12713
|
+
editing ? /* @__PURE__ */ jsx(
|
|
12714
|
+
Form$2.Field,
|
|
12715
|
+
{
|
|
12716
|
+
control: form.control,
|
|
12717
|
+
name: "unit_price",
|
|
12718
|
+
render: ({ field: { onChange, ...field } }) => {
|
|
12719
|
+
return /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12720
|
+
CurrencyInput,
|
|
12721
|
+
{
|
|
12722
|
+
...field,
|
|
12723
|
+
symbol: getNativeSymbol(currencyCode),
|
|
12724
|
+
code: currencyCode,
|
|
12725
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
|
|
12726
|
+
}
|
|
12727
|
+
) }) });
|
|
12728
|
+
}
|
|
12729
|
+
}
|
|
12730
|
+
) : /* @__PURE__ */ jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
|
|
12731
|
+
/* @__PURE__ */ jsx(
|
|
12732
|
+
IconButton,
|
|
12733
|
+
{
|
|
12734
|
+
type: "button",
|
|
12735
|
+
size: "small",
|
|
12736
|
+
onClick: editing ? onSubmit : () => {
|
|
12737
|
+
setEditing(true);
|
|
12738
|
+
},
|
|
12739
|
+
disabled: isPending,
|
|
12740
|
+
children: editing ? /* @__PURE__ */ jsx(Check, {}) : /* @__PURE__ */ jsx(PencilSquare, {})
|
|
12741
|
+
}
|
|
12742
|
+
)
|
|
12743
|
+
] }) }) });
|
|
12744
|
+
};
|
|
12745
|
+
const StackedModalTrigger = ({
|
|
12746
|
+
type,
|
|
12747
|
+
setModalContent
|
|
12748
|
+
}) => {
|
|
12749
|
+
const { setIsOpen } = useStackedModal();
|
|
12750
|
+
const onClick = useCallback(() => {
|
|
12751
|
+
setModalContent(type);
|
|
12752
|
+
setIsOpen(STACKED_MODAL_ID, true);
|
|
12753
|
+
}, [setModalContent, setIsOpen, type]);
|
|
12754
|
+
return /* @__PURE__ */ jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
|
|
12755
|
+
};
|
|
12756
|
+
const VARIANT_PREFIX = "items";
|
|
12757
|
+
const LIMIT = 50;
|
|
12758
|
+
const ExistingItemsForm = ({ orderId, items }) => {
|
|
12759
|
+
const { setIsOpen } = useStackedModal();
|
|
12760
|
+
const [rowSelection, setRowSelection] = useState(
|
|
12761
|
+
items.reduce((acc, item) => {
|
|
12762
|
+
acc[item.variant_id] = true;
|
|
12763
|
+
return acc;
|
|
12764
|
+
}, {})
|
|
12765
|
+
);
|
|
12766
|
+
useEffect(() => {
|
|
12767
|
+
setRowSelection(
|
|
12768
|
+
items.reduce((acc, item) => {
|
|
12769
|
+
if (item.variant_id) {
|
|
12770
|
+
acc[item.variant_id] = true;
|
|
12771
|
+
}
|
|
12772
|
+
return acc;
|
|
12773
|
+
}, {})
|
|
12774
|
+
);
|
|
12775
|
+
}, [items]);
|
|
12776
|
+
const { q, order, offset } = useQueryParams(
|
|
12777
|
+
["q", "order", "offset"],
|
|
12778
|
+
VARIANT_PREFIX
|
|
12779
|
+
);
|
|
12780
|
+
const { variants, count, isPending, isError, error } = useProductVariants(
|
|
12781
|
+
{
|
|
12782
|
+
q,
|
|
12783
|
+
order,
|
|
12784
|
+
offset: offset ? parseInt(offset) : void 0,
|
|
12785
|
+
limit: LIMIT
|
|
12786
|
+
},
|
|
12787
|
+
{
|
|
12788
|
+
placeholderData: keepPreviousData
|
|
12789
|
+
}
|
|
12790
|
+
);
|
|
12791
|
+
const columns = useColumns();
|
|
12792
|
+
const { mutateAsync } = useDraftOrderAddItems(orderId);
|
|
12793
|
+
const onSubmit = async () => {
|
|
12794
|
+
const ids = Object.keys(rowSelection).filter(
|
|
12795
|
+
(id) => !items.find((i) => i.variant_id === id)
|
|
12796
|
+
);
|
|
12797
|
+
await mutateAsync(
|
|
12798
|
+
{
|
|
12799
|
+
items: ids.map((id) => ({
|
|
12800
|
+
variant_id: id,
|
|
12801
|
+
quantity: 1
|
|
12802
|
+
}))
|
|
12803
|
+
},
|
|
12804
|
+
{
|
|
12805
|
+
onSuccess: () => {
|
|
12806
|
+
setRowSelection({});
|
|
12807
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
12808
|
+
},
|
|
12809
|
+
onError: (e) => {
|
|
12810
|
+
toast.error(e.message);
|
|
12811
|
+
}
|
|
12812
|
+
}
|
|
12813
|
+
);
|
|
12814
|
+
};
|
|
12815
|
+
if (isError) {
|
|
12816
|
+
throw error;
|
|
12817
|
+
}
|
|
12818
|
+
return /* @__PURE__ */ jsxs(
|
|
12819
|
+
StackedFocusModal.Content,
|
|
12820
|
+
{
|
|
12821
|
+
onOpenAutoFocus: (e) => {
|
|
12822
|
+
e.preventDefault();
|
|
12823
|
+
const searchInput = document.querySelector(
|
|
12824
|
+
"[data-modal-id='modal-search-input']"
|
|
12825
|
+
);
|
|
12826
|
+
if (searchInput) {
|
|
12827
|
+
searchInput.focus();
|
|
12828
|
+
}
|
|
12829
|
+
},
|
|
12830
|
+
children: [
|
|
12831
|
+
/* @__PURE__ */ jsxs(StackedFocusModal.Header, { children: [
|
|
12832
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Product Variants" }) }),
|
|
12833
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
|
|
12834
|
+
] }),
|
|
12835
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsx(
|
|
12836
|
+
DataTable,
|
|
12837
|
+
{
|
|
12838
|
+
data: variants,
|
|
12839
|
+
columns,
|
|
12840
|
+
isLoading: isPending,
|
|
12841
|
+
getRowId: (row) => row.id,
|
|
12842
|
+
rowCount: count,
|
|
12843
|
+
prefix: VARIANT_PREFIX,
|
|
12844
|
+
layout: "fill",
|
|
12845
|
+
rowSelection: {
|
|
12846
|
+
state: rowSelection,
|
|
12847
|
+
onRowSelectionChange: setRowSelection,
|
|
12848
|
+
enableRowSelection: (row) => {
|
|
12849
|
+
return !items.find((i) => i.variant_id === row.original.id);
|
|
12850
|
+
}
|
|
12851
|
+
},
|
|
12852
|
+
autoFocusSearch: true
|
|
12853
|
+
}
|
|
12854
|
+
) }),
|
|
12855
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
12856
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
12857
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
|
|
12858
|
+
] }) })
|
|
12859
|
+
]
|
|
12860
|
+
}
|
|
12861
|
+
);
|
|
12862
|
+
};
|
|
12863
|
+
const columnHelper = createDataTableColumnHelper();
|
|
12864
|
+
const useColumns = () => {
|
|
12865
|
+
return useMemo(() => {
|
|
12866
|
+
return [
|
|
12867
|
+
columnHelper.select(),
|
|
12868
|
+
columnHelper.accessor("product.title", {
|
|
12869
|
+
header: "Product",
|
|
12870
|
+
cell: ({ row }) => {
|
|
12871
|
+
var _a, _b, _c;
|
|
12872
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-x-2", children: [
|
|
12873
|
+
/* @__PURE__ */ jsx(
|
|
12874
|
+
Thumbnail,
|
|
12875
|
+
{
|
|
12876
|
+
thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
|
|
12877
|
+
alt: (_b = row.original.product) == null ? void 0 : _b.title
|
|
12878
|
+
}
|
|
12879
|
+
),
|
|
12880
|
+
/* @__PURE__ */ jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
|
|
12881
|
+
] });
|
|
12882
|
+
},
|
|
12883
|
+
enableSorting: true
|
|
12884
|
+
}),
|
|
12885
|
+
columnHelper.accessor("title", {
|
|
12886
|
+
header: "Variant",
|
|
12887
|
+
enableSorting: true
|
|
12888
|
+
}),
|
|
12889
|
+
columnHelper.accessor("sku", {
|
|
12890
|
+
header: "SKU",
|
|
12891
|
+
cell: ({ getValue }) => {
|
|
12892
|
+
return getValue() ?? "-";
|
|
12893
|
+
},
|
|
12894
|
+
enableSorting: true
|
|
12895
|
+
}),
|
|
12896
|
+
columnHelper.accessor("updated_at", {
|
|
12897
|
+
header: "Updated",
|
|
12898
|
+
cell: ({ getValue }) => {
|
|
12899
|
+
return /* @__PURE__ */ jsx(
|
|
12900
|
+
Tooltip,
|
|
12901
|
+
{
|
|
12902
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
12903
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
13023
12904
|
}
|
|
13024
|
-
)
|
|
13025
|
-
|
|
13026
|
-
|
|
12905
|
+
);
|
|
12906
|
+
},
|
|
12907
|
+
enableSorting: true,
|
|
12908
|
+
sortAscLabel: "Oldest first",
|
|
12909
|
+
sortDescLabel: "Newest first"
|
|
12910
|
+
}),
|
|
12911
|
+
columnHelper.accessor("created_at", {
|
|
12912
|
+
header: "Created",
|
|
12913
|
+
cell: ({ getValue }) => {
|
|
12914
|
+
return /* @__PURE__ */ jsx(
|
|
12915
|
+
Tooltip,
|
|
13027
12916
|
{
|
|
13028
|
-
|
|
13029
|
-
|
|
13030
|
-
fill: "white",
|
|
13031
|
-
transform: "matrix(0.865865 0.500278 -0.871576 0.490261 141.709 96.4627)"
|
|
12917
|
+
content: getFullDate({ date: getValue(), includeTime: true }),
|
|
12918
|
+
children: /* @__PURE__ */ jsx("span", { children: getFullDate({ date: getValue() }) })
|
|
13032
12919
|
}
|
|
13033
|
-
)
|
|
13034
|
-
|
|
13035
|
-
|
|
13036
|
-
|
|
13037
|
-
|
|
12920
|
+
);
|
|
12921
|
+
},
|
|
12922
|
+
enableSorting: true,
|
|
12923
|
+
sortAscLabel: "Oldest first",
|
|
12924
|
+
sortDescLabel: "Newest first"
|
|
12925
|
+
})
|
|
12926
|
+
];
|
|
12927
|
+
}, []);
|
|
13038
12928
|
};
|
|
13039
|
-
const
|
|
13040
|
-
|
|
12929
|
+
const CustomItemForm = ({ orderId, currencyCode }) => {
|
|
12930
|
+
const { setIsOpen } = useStackedModal();
|
|
12931
|
+
const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
|
|
12932
|
+
const form = useForm({
|
|
12933
|
+
defaultValues: {
|
|
12934
|
+
title: "",
|
|
12935
|
+
quantity: 1,
|
|
12936
|
+
unit_price: ""
|
|
12937
|
+
},
|
|
12938
|
+
resolver: zodResolver(customItemSchema)
|
|
12939
|
+
});
|
|
12940
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12941
|
+
await addItems(
|
|
12942
|
+
{
|
|
12943
|
+
items: [
|
|
12944
|
+
{
|
|
12945
|
+
title: data.title,
|
|
12946
|
+
quantity: data.quantity,
|
|
12947
|
+
unit_price: convertNumber(data.unit_price)
|
|
12948
|
+
}
|
|
12949
|
+
]
|
|
12950
|
+
},
|
|
12951
|
+
{
|
|
12952
|
+
onSuccess: () => {
|
|
12953
|
+
setIsOpen(STACKED_MODAL_ID, false);
|
|
12954
|
+
},
|
|
12955
|
+
onError: (e) => {
|
|
12956
|
+
toast.error(e.message);
|
|
12957
|
+
}
|
|
12958
|
+
}
|
|
12959
|
+
);
|
|
12960
|
+
});
|
|
12961
|
+
return /* @__PURE__ */ jsx(Form$2, { ...form, children: /* @__PURE__ */ jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxs(StackedFocusModal.Content, { children: [
|
|
12962
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Header, {}),
|
|
12963
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
|
|
12964
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12965
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Add custom item" }) }),
|
|
12966
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsx(Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
|
|
12967
|
+
] }),
|
|
12968
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12969
|
+
/* @__PURE__ */ jsx(
|
|
12970
|
+
Form$2.Field,
|
|
12971
|
+
{
|
|
12972
|
+
control: form.control,
|
|
12973
|
+
name: "title",
|
|
12974
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12975
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12976
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Title" }),
|
|
12977
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the title of the item" })
|
|
12978
|
+
] }),
|
|
12979
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12980
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(Input, { ...field }) }),
|
|
12981
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
12982
|
+
] })
|
|
12983
|
+
] }) })
|
|
12984
|
+
}
|
|
12985
|
+
),
|
|
12986
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
12987
|
+
/* @__PURE__ */ jsx(
|
|
12988
|
+
Form$2.Field,
|
|
12989
|
+
{
|
|
12990
|
+
control: form.control,
|
|
12991
|
+
name: "unit_price",
|
|
12992
|
+
render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
12993
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12994
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Unit price" }),
|
|
12995
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
|
|
12996
|
+
] }),
|
|
12997
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12998
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx(
|
|
12999
|
+
CurrencyInput,
|
|
13000
|
+
{
|
|
13001
|
+
symbol: getNativeSymbol(currencyCode),
|
|
13002
|
+
code: currencyCode,
|
|
13003
|
+
onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
|
|
13004
|
+
...field
|
|
13005
|
+
}
|
|
13006
|
+
) }),
|
|
13007
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13008
|
+
] })
|
|
13009
|
+
] }) })
|
|
13010
|
+
}
|
|
13011
|
+
),
|
|
13012
|
+
/* @__PURE__ */ jsx(Divider, { variant: "dashed" }),
|
|
13013
|
+
/* @__PURE__ */ jsx(
|
|
13014
|
+
Form$2.Field,
|
|
13015
|
+
{
|
|
13016
|
+
control: form.control,
|
|
13017
|
+
name: "quantity",
|
|
13018
|
+
render: ({ field }) => /* @__PURE__ */ jsx(Form$2.Item, { children: /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
|
|
13019
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
13020
|
+
/* @__PURE__ */ jsx(Form$2.Label, { children: "Quantity" }),
|
|
13021
|
+
/* @__PURE__ */ jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
|
|
13022
|
+
] }),
|
|
13023
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full flex-1", children: [
|
|
13024
|
+
/* @__PURE__ */ jsx(Form$2.Control, { children: /* @__PURE__ */ jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsx(NumberInput, { ...field, className: "w-full" }) }) }),
|
|
13025
|
+
/* @__PURE__ */ jsx(Form$2.ErrorMessage, {})
|
|
13026
|
+
] })
|
|
13027
|
+
] }) })
|
|
13028
|
+
}
|
|
13029
|
+
)
|
|
13030
|
+
] }) }) }),
|
|
13031
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
13032
|
+
/* @__PURE__ */ jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
13033
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
|
|
13034
|
+
] }) })
|
|
13035
|
+
] }) }) });
|
|
13036
|
+
};
|
|
13037
|
+
const customItemSchema = objectType({
|
|
13038
|
+
title: stringType().min(1),
|
|
13039
|
+
quantity: numberType(),
|
|
13040
|
+
unit_price: unionType([numberType(), stringType()])
|
|
13041
13041
|
});
|
|
13042
13042
|
const widgetModule = { widgets: [] };
|
|
13043
13043
|
const routeModule = {
|
|
@@ -13071,21 +13071,13 @@ const routeModule = {
|
|
|
13071
13071
|
Component: Email,
|
|
13072
13072
|
path: "/draft-orders/:id/email"
|
|
13073
13073
|
},
|
|
13074
|
-
{
|
|
13075
|
-
Component: Items,
|
|
13076
|
-
path: "/draft-orders/:id/items"
|
|
13077
|
-
},
|
|
13078
|
-
{
|
|
13079
|
-
Component: Metadata,
|
|
13080
|
-
path: "/draft-orders/:id/metadata"
|
|
13081
|
-
},
|
|
13082
13074
|
{
|
|
13083
13075
|
Component: Promotions,
|
|
13084
13076
|
path: "/draft-orders/:id/promotions"
|
|
13085
13077
|
},
|
|
13086
13078
|
{
|
|
13087
|
-
Component:
|
|
13088
|
-
path: "/draft-orders/:id/
|
|
13079
|
+
Component: Metadata,
|
|
13080
|
+
path: "/draft-orders/:id/metadata"
|
|
13089
13081
|
},
|
|
13090
13082
|
{
|
|
13091
13083
|
Component: Shipping,
|
|
@@ -13098,6 +13090,14 @@ const routeModule = {
|
|
|
13098
13090
|
{
|
|
13099
13091
|
Component: TransferOwnership,
|
|
13100
13092
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13093
|
+
},
|
|
13094
|
+
{
|
|
13095
|
+
Component: SalesChannel,
|
|
13096
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13097
|
+
},
|
|
13098
|
+
{
|
|
13099
|
+
Component: Items,
|
|
13100
|
+
path: "/draft-orders/:id/items"
|
|
13101
13101
|
}
|
|
13102
13102
|
]
|
|
13103
13103
|
}
|