@medusajs/draft-order 2.12.4-snapshot-20251226024319 → 2.12.4-snapshot-20251226061341
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 +368 -368
- package/.medusa/server/src/admin/index.mjs +368 -368
- package/package.json +16 -16
|
@@ -10825,283 +10825,6 @@ const customItemSchema = objectType({
|
|
|
10825
10825
|
quantity: numberType(),
|
|
10826
10826
|
unit_price: unionType([numberType(), stringType()])
|
|
10827
10827
|
});
|
|
10828
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
10829
|
-
const promotionsQueryKeys = {
|
|
10830
|
-
list: (query2) => [
|
|
10831
|
-
PROMOTION_QUERY_KEY,
|
|
10832
|
-
query2 ? query2 : void 0
|
|
10833
|
-
],
|
|
10834
|
-
detail: (id, query2) => [
|
|
10835
|
-
PROMOTION_QUERY_KEY,
|
|
10836
|
-
id,
|
|
10837
|
-
query2 ? query2 : void 0
|
|
10838
|
-
]
|
|
10839
|
-
};
|
|
10840
|
-
const usePromotions = (query2, options) => {
|
|
10841
|
-
const { data, ...rest } = reactQuery.useQuery({
|
|
10842
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
10843
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10844
|
-
...options
|
|
10845
|
-
});
|
|
10846
|
-
return { ...data, ...rest };
|
|
10847
|
-
};
|
|
10848
|
-
const Promotions = () => {
|
|
10849
|
-
const { id } = reactRouterDom.useParams();
|
|
10850
|
-
const {
|
|
10851
|
-
order: preview,
|
|
10852
|
-
isError: isPreviewError,
|
|
10853
|
-
error: previewError
|
|
10854
|
-
} = useOrderPreview(id, void 0);
|
|
10855
|
-
useInitiateOrderEdit({ preview });
|
|
10856
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10857
|
-
if (isPreviewError) {
|
|
10858
|
-
throw previewError;
|
|
10859
|
-
}
|
|
10860
|
-
const isReady = !!preview;
|
|
10861
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10862
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
10863
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
10864
|
-
] });
|
|
10865
|
-
};
|
|
10866
|
-
const PromotionForm = ({ preview }) => {
|
|
10867
|
-
const { items, shipping_methods } = preview;
|
|
10868
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
10869
|
-
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
10870
|
-
const { handleSuccess } = useRouteModal();
|
|
10871
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10872
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10873
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
10874
|
-
{
|
|
10875
|
-
id: promoIds
|
|
10876
|
-
},
|
|
10877
|
-
{
|
|
10878
|
-
enabled: !!promoIds.length
|
|
10879
|
-
}
|
|
10880
|
-
);
|
|
10881
|
-
const comboboxData = useComboboxData({
|
|
10882
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
10883
|
-
queryFn: async (params) => {
|
|
10884
|
-
return await sdk.admin.promotion.list({
|
|
10885
|
-
...params,
|
|
10886
|
-
id: {
|
|
10887
|
-
$nin: promoIds
|
|
10888
|
-
}
|
|
10889
|
-
});
|
|
10890
|
-
},
|
|
10891
|
-
getOptions: (data) => {
|
|
10892
|
-
return data.promotions.map((promotion) => ({
|
|
10893
|
-
label: promotion.code,
|
|
10894
|
-
value: promotion.code
|
|
10895
|
-
}));
|
|
10896
|
-
}
|
|
10897
|
-
});
|
|
10898
|
-
const add = async (value) => {
|
|
10899
|
-
if (!value) {
|
|
10900
|
-
return;
|
|
10901
|
-
}
|
|
10902
|
-
addPromotions(
|
|
10903
|
-
{
|
|
10904
|
-
promo_codes: [value]
|
|
10905
|
-
},
|
|
10906
|
-
{
|
|
10907
|
-
onError: (e) => {
|
|
10908
|
-
ui.toast.error(e.message);
|
|
10909
|
-
comboboxData.onSearchValueChange("");
|
|
10910
|
-
setComboboxValue("");
|
|
10911
|
-
},
|
|
10912
|
-
onSuccess: () => {
|
|
10913
|
-
comboboxData.onSearchValueChange("");
|
|
10914
|
-
setComboboxValue("");
|
|
10915
|
-
}
|
|
10916
|
-
}
|
|
10917
|
-
);
|
|
10918
|
-
};
|
|
10919
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10920
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10921
|
-
const onSubmit = async () => {
|
|
10922
|
-
setIsSubmitting(true);
|
|
10923
|
-
let requestSucceeded = false;
|
|
10924
|
-
await requestOrderEdit(void 0, {
|
|
10925
|
-
onError: (e) => {
|
|
10926
|
-
ui.toast.error(e.message);
|
|
10927
|
-
},
|
|
10928
|
-
onSuccess: () => {
|
|
10929
|
-
requestSucceeded = true;
|
|
10930
|
-
}
|
|
10931
|
-
});
|
|
10932
|
-
if (!requestSucceeded) {
|
|
10933
|
-
setIsSubmitting(false);
|
|
10934
|
-
return;
|
|
10935
|
-
}
|
|
10936
|
-
await confirmOrderEdit(void 0, {
|
|
10937
|
-
onError: (e) => {
|
|
10938
|
-
ui.toast.error(e.message);
|
|
10939
|
-
},
|
|
10940
|
-
onSuccess: () => {
|
|
10941
|
-
handleSuccess();
|
|
10942
|
-
},
|
|
10943
|
-
onSettled: () => {
|
|
10944
|
-
setIsSubmitting(false);
|
|
10945
|
-
}
|
|
10946
|
-
});
|
|
10947
|
-
};
|
|
10948
|
-
if (isError) {
|
|
10949
|
-
throw error;
|
|
10950
|
-
}
|
|
10951
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10952
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10953
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10954
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
10955
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10956
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10957
|
-
] }),
|
|
10958
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10959
|
-
Combobox,
|
|
10960
|
-
{
|
|
10961
|
-
id: "promotion-combobox",
|
|
10962
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
10963
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10964
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
10965
|
-
options: comboboxData.options,
|
|
10966
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10967
|
-
searchValue: comboboxData.searchValue,
|
|
10968
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10969
|
-
onChange: add,
|
|
10970
|
-
value: comboboxValue
|
|
10971
|
-
}
|
|
10972
|
-
)
|
|
10973
|
-
] }),
|
|
10974
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10975
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
10976
|
-
PromotionItem,
|
|
10977
|
-
{
|
|
10978
|
-
promotion,
|
|
10979
|
-
orderId: preview.id,
|
|
10980
|
-
isLoading: isPending
|
|
10981
|
-
},
|
|
10982
|
-
promotion.id
|
|
10983
|
-
)) })
|
|
10984
|
-
] }) }),
|
|
10985
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10986
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10987
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10988
|
-
ui.Button,
|
|
10989
|
-
{
|
|
10990
|
-
size: "small",
|
|
10991
|
-
type: "submit",
|
|
10992
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
10993
|
-
children: "Save"
|
|
10994
|
-
}
|
|
10995
|
-
)
|
|
10996
|
-
] }) })
|
|
10997
|
-
] });
|
|
10998
|
-
};
|
|
10999
|
-
const PromotionItem = ({
|
|
11000
|
-
promotion,
|
|
11001
|
-
orderId,
|
|
11002
|
-
isLoading
|
|
11003
|
-
}) => {
|
|
11004
|
-
var _a;
|
|
11005
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11006
|
-
const onRemove = async () => {
|
|
11007
|
-
removePromotions(
|
|
11008
|
-
{
|
|
11009
|
-
promo_codes: [promotion.code]
|
|
11010
|
-
},
|
|
11011
|
-
{
|
|
11012
|
-
onError: (e) => {
|
|
11013
|
-
ui.toast.error(e.message);
|
|
11014
|
-
}
|
|
11015
|
-
}
|
|
11016
|
-
);
|
|
11017
|
-
};
|
|
11018
|
-
const displayValue = getDisplayValue(promotion);
|
|
11019
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11020
|
-
"div",
|
|
11021
|
-
{
|
|
11022
|
-
className: ui.clx(
|
|
11023
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11024
|
-
{
|
|
11025
|
-
"animate-pulse": isLoading
|
|
11026
|
-
}
|
|
11027
|
-
),
|
|
11028
|
-
children: [
|
|
11029
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11030
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11031
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11032
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11033
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11034
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11035
|
-
] }),
|
|
11036
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11037
|
-
] })
|
|
11038
|
-
] }),
|
|
11039
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11040
|
-
ui.IconButton,
|
|
11041
|
-
{
|
|
11042
|
-
size: "small",
|
|
11043
|
-
type: "button",
|
|
11044
|
-
variant: "transparent",
|
|
11045
|
-
onClick: onRemove,
|
|
11046
|
-
isLoading: isPending || isLoading,
|
|
11047
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11048
|
-
}
|
|
11049
|
-
)
|
|
11050
|
-
]
|
|
11051
|
-
},
|
|
11052
|
-
promotion.id
|
|
11053
|
-
);
|
|
11054
|
-
};
|
|
11055
|
-
function getDisplayValue(promotion) {
|
|
11056
|
-
var _a, _b, _c, _d;
|
|
11057
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11058
|
-
if (!value) {
|
|
11059
|
-
return null;
|
|
11060
|
-
}
|
|
11061
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11062
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11063
|
-
if (!currency) {
|
|
11064
|
-
return null;
|
|
11065
|
-
}
|
|
11066
|
-
return getLocaleAmount(value, currency);
|
|
11067
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11068
|
-
return formatPercentage(value);
|
|
11069
|
-
}
|
|
11070
|
-
return null;
|
|
11071
|
-
}
|
|
11072
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11073
|
-
style: "percent",
|
|
11074
|
-
minimumFractionDigits: 2
|
|
11075
|
-
});
|
|
11076
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11077
|
-
let val = value || 0;
|
|
11078
|
-
if (!isPercentageValue) {
|
|
11079
|
-
val = val / 100;
|
|
11080
|
-
}
|
|
11081
|
-
return formatter.format(val);
|
|
11082
|
-
};
|
|
11083
|
-
function getPromotionIds(items, shippingMethods) {
|
|
11084
|
-
const promotionIds = /* @__PURE__ */ new Set();
|
|
11085
|
-
for (const item of items) {
|
|
11086
|
-
if (item.adjustments) {
|
|
11087
|
-
for (const adjustment of item.adjustments) {
|
|
11088
|
-
if (adjustment.promotion_id) {
|
|
11089
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11090
|
-
}
|
|
11091
|
-
}
|
|
11092
|
-
}
|
|
11093
|
-
}
|
|
11094
|
-
for (const shippingMethod of shippingMethods) {
|
|
11095
|
-
if (shippingMethod.adjustments) {
|
|
11096
|
-
for (const adjustment of shippingMethod.adjustments) {
|
|
11097
|
-
if (adjustment.promotion_id) {
|
|
11098
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11099
|
-
}
|
|
11100
|
-
}
|
|
11101
|
-
}
|
|
11102
|
-
}
|
|
11103
|
-
return Array.from(promotionIds);
|
|
11104
|
-
}
|
|
11105
10828
|
const InlineTip = React.forwardRef(
|
|
11106
10829
|
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11107
10830
|
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
@@ -11452,112 +11175,283 @@ function getHasUneditableRows(metadata) {
|
|
|
11452
11175
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11453
11176
|
);
|
|
11454
11177
|
}
|
|
11455
|
-
const
|
|
11456
|
-
|
|
11457
|
-
|
|
11178
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
11179
|
+
const promotionsQueryKeys = {
|
|
11180
|
+
list: (query2) => [
|
|
11181
|
+
PROMOTION_QUERY_KEY,
|
|
11182
|
+
query2 ? query2 : void 0
|
|
11183
|
+
],
|
|
11184
|
+
detail: (id, query2) => [
|
|
11185
|
+
PROMOTION_QUERY_KEY,
|
|
11458
11186
|
id,
|
|
11187
|
+
query2 ? query2 : void 0
|
|
11188
|
+
]
|
|
11189
|
+
};
|
|
11190
|
+
const usePromotions = (query2, options) => {
|
|
11191
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
11192
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
11193
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11194
|
+
...options
|
|
11195
|
+
});
|
|
11196
|
+
return { ...data, ...rest };
|
|
11197
|
+
};
|
|
11198
|
+
const Promotions = () => {
|
|
11199
|
+
const { id } = reactRouterDom.useParams();
|
|
11200
|
+
const {
|
|
11201
|
+
order: preview,
|
|
11202
|
+
isError: isPreviewError,
|
|
11203
|
+
error: previewError
|
|
11204
|
+
} = useOrderPreview(id, void 0);
|
|
11205
|
+
useInitiateOrderEdit({ preview });
|
|
11206
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11207
|
+
if (isPreviewError) {
|
|
11208
|
+
throw previewError;
|
|
11209
|
+
}
|
|
11210
|
+
const isReady = !!preview;
|
|
11211
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11212
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11213
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11214
|
+
] });
|
|
11215
|
+
};
|
|
11216
|
+
const PromotionForm = ({ preview }) => {
|
|
11217
|
+
const { items, shipping_methods } = preview;
|
|
11218
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11219
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11220
|
+
const { handleSuccess } = useRouteModal();
|
|
11221
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11222
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11223
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
11459
11224
|
{
|
|
11460
|
-
|
|
11225
|
+
id: promoIds
|
|
11461
11226
|
},
|
|
11462
11227
|
{
|
|
11463
|
-
enabled: !!
|
|
11228
|
+
enabled: !!promoIds.length
|
|
11464
11229
|
}
|
|
11465
11230
|
);
|
|
11466
|
-
|
|
11467
|
-
|
|
11468
|
-
|
|
11469
|
-
|
|
11470
|
-
|
|
11471
|
-
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
|
|
11475
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
11476
|
-
] });
|
|
11477
|
-
};
|
|
11478
|
-
const SalesChannelForm = ({ order }) => {
|
|
11479
|
-
const form = reactHookForm.useForm({
|
|
11480
|
-
defaultValues: {
|
|
11481
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
11231
|
+
const comboboxData = useComboboxData({
|
|
11232
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
11233
|
+
queryFn: async (params) => {
|
|
11234
|
+
return await sdk.admin.promotion.list({
|
|
11235
|
+
...params,
|
|
11236
|
+
id: {
|
|
11237
|
+
$nin: promoIds
|
|
11238
|
+
}
|
|
11239
|
+
});
|
|
11482
11240
|
},
|
|
11483
|
-
|
|
11241
|
+
getOptions: (data) => {
|
|
11242
|
+
return data.promotions.map((promotion) => ({
|
|
11243
|
+
label: promotion.code,
|
|
11244
|
+
value: promotion.code
|
|
11245
|
+
}));
|
|
11246
|
+
}
|
|
11484
11247
|
});
|
|
11485
|
-
const
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
|
|
11248
|
+
const add = async (value) => {
|
|
11249
|
+
if (!value) {
|
|
11250
|
+
return;
|
|
11251
|
+
}
|
|
11252
|
+
addPromotions(
|
|
11489
11253
|
{
|
|
11490
|
-
|
|
11254
|
+
promo_codes: [value]
|
|
11491
11255
|
},
|
|
11492
11256
|
{
|
|
11257
|
+
onError: (e) => {
|
|
11258
|
+
ui.toast.error(e.message);
|
|
11259
|
+
comboboxData.onSearchValueChange("");
|
|
11260
|
+
setComboboxValue("");
|
|
11261
|
+
},
|
|
11493
11262
|
onSuccess: () => {
|
|
11494
|
-
|
|
11495
|
-
|
|
11263
|
+
comboboxData.onSearchValueChange("");
|
|
11264
|
+
setComboboxValue("");
|
|
11265
|
+
}
|
|
11266
|
+
}
|
|
11267
|
+
);
|
|
11268
|
+
};
|
|
11269
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11270
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11271
|
+
const onSubmit = async () => {
|
|
11272
|
+
setIsSubmitting(true);
|
|
11273
|
+
let requestSucceeded = false;
|
|
11274
|
+
await requestOrderEdit(void 0, {
|
|
11275
|
+
onError: (e) => {
|
|
11276
|
+
ui.toast.error(e.message);
|
|
11277
|
+
},
|
|
11278
|
+
onSuccess: () => {
|
|
11279
|
+
requestSucceeded = true;
|
|
11280
|
+
}
|
|
11281
|
+
});
|
|
11282
|
+
if (!requestSucceeded) {
|
|
11283
|
+
setIsSubmitting(false);
|
|
11284
|
+
return;
|
|
11285
|
+
}
|
|
11286
|
+
await confirmOrderEdit(void 0, {
|
|
11287
|
+
onError: (e) => {
|
|
11288
|
+
ui.toast.error(e.message);
|
|
11289
|
+
},
|
|
11290
|
+
onSuccess: () => {
|
|
11291
|
+
handleSuccess();
|
|
11292
|
+
},
|
|
11293
|
+
onSettled: () => {
|
|
11294
|
+
setIsSubmitting(false);
|
|
11295
|
+
}
|
|
11296
|
+
});
|
|
11297
|
+
};
|
|
11298
|
+
if (isError) {
|
|
11299
|
+
throw error;
|
|
11300
|
+
}
|
|
11301
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11302
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11303
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11304
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11305
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11306
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11307
|
+
] }),
|
|
11308
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11309
|
+
Combobox,
|
|
11310
|
+
{
|
|
11311
|
+
id: "promotion-combobox",
|
|
11312
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
11313
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11314
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
11315
|
+
options: comboboxData.options,
|
|
11316
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11317
|
+
searchValue: comboboxData.searchValue,
|
|
11318
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11319
|
+
onChange: add,
|
|
11320
|
+
value: comboboxValue
|
|
11321
|
+
}
|
|
11322
|
+
)
|
|
11323
|
+
] }),
|
|
11324
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11325
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
11326
|
+
PromotionItem,
|
|
11327
|
+
{
|
|
11328
|
+
promotion,
|
|
11329
|
+
orderId: preview.id,
|
|
11330
|
+
isLoading: isPending
|
|
11496
11331
|
},
|
|
11497
|
-
|
|
11498
|
-
|
|
11332
|
+
promotion.id
|
|
11333
|
+
)) })
|
|
11334
|
+
] }) }),
|
|
11335
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11336
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11337
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11338
|
+
ui.Button,
|
|
11339
|
+
{
|
|
11340
|
+
size: "small",
|
|
11341
|
+
type: "submit",
|
|
11342
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
11343
|
+
children: "Save"
|
|
11344
|
+
}
|
|
11345
|
+
)
|
|
11346
|
+
] }) })
|
|
11347
|
+
] });
|
|
11348
|
+
};
|
|
11349
|
+
const PromotionItem = ({
|
|
11350
|
+
promotion,
|
|
11351
|
+
orderId,
|
|
11352
|
+
isLoading
|
|
11353
|
+
}) => {
|
|
11354
|
+
var _a;
|
|
11355
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11356
|
+
const onRemove = async () => {
|
|
11357
|
+
removePromotions(
|
|
11358
|
+
{
|
|
11359
|
+
promo_codes: [promotion.code]
|
|
11360
|
+
},
|
|
11361
|
+
{
|
|
11362
|
+
onError: (e) => {
|
|
11363
|
+
ui.toast.error(e.message);
|
|
11499
11364
|
}
|
|
11500
11365
|
}
|
|
11501
11366
|
);
|
|
11502
|
-
}
|
|
11503
|
-
|
|
11504
|
-
|
|
11367
|
+
};
|
|
11368
|
+
const displayValue = getDisplayValue(promotion);
|
|
11369
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11370
|
+
"div",
|
|
11505
11371
|
{
|
|
11506
|
-
className:
|
|
11507
|
-
|
|
11372
|
+
className: ui.clx(
|
|
11373
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11374
|
+
{
|
|
11375
|
+
"animate-pulse": isLoading
|
|
11376
|
+
}
|
|
11377
|
+
),
|
|
11508
11378
|
children: [
|
|
11509
|
-
/* @__PURE__ */ jsxRuntime.
|
|
11510
|
-
|
|
11511
|
-
/* @__PURE__ */ jsxRuntime.
|
|
11512
|
-
|
|
11513
|
-
|
|
11379
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11380
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11381
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11382
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11383
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11384
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11385
|
+
] }),
|
|
11386
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11387
|
+
] })
|
|
11388
|
+
] }),
|
|
11389
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11390
|
+
ui.IconButton,
|
|
11391
|
+
{
|
|
11392
|
+
size: "small",
|
|
11393
|
+
type: "button",
|
|
11394
|
+
variant: "transparent",
|
|
11395
|
+
onClick: onRemove,
|
|
11396
|
+
isLoading: isPending || isLoading,
|
|
11397
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11398
|
+
}
|
|
11399
|
+
)
|
|
11514
11400
|
]
|
|
11515
|
-
}
|
|
11516
|
-
) });
|
|
11517
|
-
};
|
|
11518
|
-
const SalesChannelField = ({ control, order }) => {
|
|
11519
|
-
const salesChannels = useComboboxData({
|
|
11520
|
-
queryFn: async (params) => {
|
|
11521
|
-
return await sdk.admin.salesChannel.list(params);
|
|
11522
|
-
},
|
|
11523
|
-
queryKey: ["sales-channels"],
|
|
11524
|
-
getOptions: (data) => {
|
|
11525
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
11526
|
-
label: salesChannel.name,
|
|
11527
|
-
value: salesChannel.id
|
|
11528
|
-
}));
|
|
11529
11401
|
},
|
|
11530
|
-
|
|
11531
|
-
});
|
|
11532
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11533
|
-
Form$2.Field,
|
|
11534
|
-
{
|
|
11535
|
-
control,
|
|
11536
|
-
name: "sales_channel_id",
|
|
11537
|
-
render: ({ field }) => {
|
|
11538
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11539
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11540
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11541
|
-
Combobox,
|
|
11542
|
-
{
|
|
11543
|
-
options: salesChannels.options,
|
|
11544
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
11545
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11546
|
-
searchValue: salesChannels.searchValue,
|
|
11547
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11548
|
-
placeholder: "Select sales channel",
|
|
11549
|
-
...field
|
|
11550
|
-
}
|
|
11551
|
-
) }),
|
|
11552
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11553
|
-
] });
|
|
11554
|
-
}
|
|
11555
|
-
}
|
|
11402
|
+
promotion.id
|
|
11556
11403
|
);
|
|
11557
11404
|
};
|
|
11558
|
-
|
|
11559
|
-
|
|
11405
|
+
function getDisplayValue(promotion) {
|
|
11406
|
+
var _a, _b, _c, _d;
|
|
11407
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11408
|
+
if (!value) {
|
|
11409
|
+
return null;
|
|
11410
|
+
}
|
|
11411
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11412
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11413
|
+
if (!currency) {
|
|
11414
|
+
return null;
|
|
11415
|
+
}
|
|
11416
|
+
return getLocaleAmount(value, currency);
|
|
11417
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11418
|
+
return formatPercentage(value);
|
|
11419
|
+
}
|
|
11420
|
+
return null;
|
|
11421
|
+
}
|
|
11422
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11423
|
+
style: "percent",
|
|
11424
|
+
minimumFractionDigits: 2
|
|
11560
11425
|
});
|
|
11426
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11427
|
+
let val = value || 0;
|
|
11428
|
+
if (!isPercentageValue) {
|
|
11429
|
+
val = val / 100;
|
|
11430
|
+
}
|
|
11431
|
+
return formatter.format(val);
|
|
11432
|
+
};
|
|
11433
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11434
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11435
|
+
for (const item of items) {
|
|
11436
|
+
if (item.adjustments) {
|
|
11437
|
+
for (const adjustment of item.adjustments) {
|
|
11438
|
+
if (adjustment.promotion_id) {
|
|
11439
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11440
|
+
}
|
|
11441
|
+
}
|
|
11442
|
+
}
|
|
11443
|
+
}
|
|
11444
|
+
for (const shippingMethod of shippingMethods) {
|
|
11445
|
+
if (shippingMethod.adjustments) {
|
|
11446
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11447
|
+
if (adjustment.promotion_id) {
|
|
11448
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11449
|
+
}
|
|
11450
|
+
}
|
|
11451
|
+
}
|
|
11452
|
+
}
|
|
11453
|
+
return Array.from(promotionIds);
|
|
11454
|
+
}
|
|
11561
11455
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11562
11456
|
const Shipping = () => {
|
|
11563
11457
|
var _a;
|
|
@@ -12397,7 +12291,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12397
12291
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12398
12292
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12399
12293
|
},
|
|
12400
|
-
resolver: zod.zodResolver(schema$
|
|
12294
|
+
resolver: zod.zodResolver(schema$2)
|
|
12401
12295
|
});
|
|
12402
12296
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12403
12297
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12567,7 +12461,113 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12567
12461
|
}
|
|
12568
12462
|
) });
|
|
12569
12463
|
};
|
|
12570
|
-
const schema$
|
|
12464
|
+
const schema$2 = addressSchema;
|
|
12465
|
+
const SalesChannel = () => {
|
|
12466
|
+
const { id } = reactRouterDom.useParams();
|
|
12467
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12468
|
+
id,
|
|
12469
|
+
{
|
|
12470
|
+
fields: "+sales_channel_id"
|
|
12471
|
+
},
|
|
12472
|
+
{
|
|
12473
|
+
enabled: !!id
|
|
12474
|
+
}
|
|
12475
|
+
);
|
|
12476
|
+
if (isError) {
|
|
12477
|
+
throw error;
|
|
12478
|
+
}
|
|
12479
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
12480
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12481
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12482
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
12483
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Update which sales channel the draft order is associated with" }) })
|
|
12484
|
+
] }),
|
|
12485
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
12486
|
+
] });
|
|
12487
|
+
};
|
|
12488
|
+
const SalesChannelForm = ({ order }) => {
|
|
12489
|
+
const form = reactHookForm.useForm({
|
|
12490
|
+
defaultValues: {
|
|
12491
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
12492
|
+
},
|
|
12493
|
+
resolver: zod.zodResolver(schema$1)
|
|
12494
|
+
});
|
|
12495
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12496
|
+
const { handleSuccess } = useRouteModal();
|
|
12497
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
12498
|
+
await mutateAsync(
|
|
12499
|
+
{
|
|
12500
|
+
sales_channel_id: data.sales_channel_id
|
|
12501
|
+
},
|
|
12502
|
+
{
|
|
12503
|
+
onSuccess: () => {
|
|
12504
|
+
ui.toast.success("Sales channel updated");
|
|
12505
|
+
handleSuccess();
|
|
12506
|
+
},
|
|
12507
|
+
onError: (error) => {
|
|
12508
|
+
ui.toast.error(error.message);
|
|
12509
|
+
}
|
|
12510
|
+
}
|
|
12511
|
+
);
|
|
12512
|
+
});
|
|
12513
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12514
|
+
KeyboundForm,
|
|
12515
|
+
{
|
|
12516
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
12517
|
+
onSubmit,
|
|
12518
|
+
children: [
|
|
12519
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12520
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12521
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12522
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12523
|
+
] }) })
|
|
12524
|
+
]
|
|
12525
|
+
}
|
|
12526
|
+
) });
|
|
12527
|
+
};
|
|
12528
|
+
const SalesChannelField = ({ control, order }) => {
|
|
12529
|
+
const salesChannels = useComboboxData({
|
|
12530
|
+
queryFn: async (params) => {
|
|
12531
|
+
return await sdk.admin.salesChannel.list(params);
|
|
12532
|
+
},
|
|
12533
|
+
queryKey: ["sales-channels"],
|
|
12534
|
+
getOptions: (data) => {
|
|
12535
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
12536
|
+
label: salesChannel.name,
|
|
12537
|
+
value: salesChannel.id
|
|
12538
|
+
}));
|
|
12539
|
+
},
|
|
12540
|
+
defaultValue: order.sales_channel_id || void 0
|
|
12541
|
+
});
|
|
12542
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12543
|
+
Form$2.Field,
|
|
12544
|
+
{
|
|
12545
|
+
control,
|
|
12546
|
+
name: "sales_channel_id",
|
|
12547
|
+
render: ({ field }) => {
|
|
12548
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12549
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
12550
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12551
|
+
Combobox,
|
|
12552
|
+
{
|
|
12553
|
+
options: salesChannels.options,
|
|
12554
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
12555
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
12556
|
+
searchValue: salesChannels.searchValue,
|
|
12557
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
12558
|
+
placeholder: "Select sales channel",
|
|
12559
|
+
...field
|
|
12560
|
+
}
|
|
12561
|
+
) }),
|
|
12562
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12563
|
+
] });
|
|
12564
|
+
}
|
|
12565
|
+
}
|
|
12566
|
+
);
|
|
12567
|
+
};
|
|
12568
|
+
const schema$1 = objectType({
|
|
12569
|
+
sales_channel_id: stringType().min(1)
|
|
12570
|
+
});
|
|
12571
12571
|
const TransferOwnership = () => {
|
|
12572
12572
|
const { id } = reactRouterDom.useParams();
|
|
12573
12573
|
const { draft_order, isPending, isError, error } = useDraftOrder(id, {
|
|
@@ -13080,17 +13080,13 @@ const routeModule = {
|
|
|
13080
13080
|
Component: Items,
|
|
13081
13081
|
path: "/draft-orders/:id/items"
|
|
13082
13082
|
},
|
|
13083
|
-
{
|
|
13084
|
-
Component: Promotions,
|
|
13085
|
-
path: "/draft-orders/:id/promotions"
|
|
13086
|
-
},
|
|
13087
13083
|
{
|
|
13088
13084
|
Component: Metadata,
|
|
13089
13085
|
path: "/draft-orders/:id/metadata"
|
|
13090
13086
|
},
|
|
13091
13087
|
{
|
|
13092
|
-
Component:
|
|
13093
|
-
path: "/draft-orders/:id/
|
|
13088
|
+
Component: Promotions,
|
|
13089
|
+
path: "/draft-orders/:id/promotions"
|
|
13094
13090
|
},
|
|
13095
13091
|
{
|
|
13096
13092
|
Component: Shipping,
|
|
@@ -13100,6 +13096,10 @@ const routeModule = {
|
|
|
13100
13096
|
Component: ShippingAddress,
|
|
13101
13097
|
path: "/draft-orders/:id/shipping-address"
|
|
13102
13098
|
},
|
|
13099
|
+
{
|
|
13100
|
+
Component: SalesChannel,
|
|
13101
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13102
|
+
},
|
|
13103
13103
|
{
|
|
13104
13104
|
Component: TransferOwnership,
|
|
13105
13105
|
path: "/draft-orders/:id/transfer-ownership"
|