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