@medusajs/draft-order 2.10.4-preview-20250925031439 → 2.10.4-preview-20250925090152
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 +531 -531
- package/.medusa/server/src/admin/index.mjs +531 -531
- package/package.json +16 -16
|
@@ -9763,6 +9763,27 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9763
9763
|
) });
|
|
9764
9764
|
};
|
|
9765
9765
|
const schema$5 = addressSchema;
|
|
9766
|
+
const CustomItems = () => {
|
|
9767
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
9768
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
9769
|
+
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
9770
|
+
] });
|
|
9771
|
+
};
|
|
9772
|
+
const CustomItemsForm = () => {
|
|
9773
|
+
const form = reactHookForm.useForm({
|
|
9774
|
+
resolver: zod.zodResolver(schema$4)
|
|
9775
|
+
});
|
|
9776
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9777
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
9778
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9779
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9780
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
9781
|
+
] }) })
|
|
9782
|
+
] }) });
|
|
9783
|
+
};
|
|
9784
|
+
const schema$4 = objectType({
|
|
9785
|
+
email: stringType().email()
|
|
9786
|
+
});
|
|
9766
9787
|
const Email = () => {
|
|
9767
9788
|
const { id } = reactRouterDom.useParams();
|
|
9768
9789
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9785,7 +9806,7 @@ const EmailForm = ({ order }) => {
|
|
|
9785
9806
|
defaultValues: {
|
|
9786
9807
|
email: order.email ?? ""
|
|
9787
9808
|
},
|
|
9788
|
-
resolver: zod.zodResolver(schema$
|
|
9809
|
+
resolver: zod.zodResolver(schema$3)
|
|
9789
9810
|
});
|
|
9790
9811
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9791
9812
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9828,7 +9849,7 @@ const EmailForm = ({ order }) => {
|
|
|
9828
9849
|
}
|
|
9829
9850
|
) });
|
|
9830
9851
|
};
|
|
9831
|
-
const schema$
|
|
9852
|
+
const schema$3 = objectType({
|
|
9832
9853
|
email: stringType().email()
|
|
9833
9854
|
});
|
|
9834
9855
|
const NumberInput = React.forwardRef(
|
|
@@ -10805,148 +10826,425 @@ const customItemSchema = objectType({
|
|
|
10805
10826
|
quantity: numberType(),
|
|
10806
10827
|
unit_price: unionType([numberType(), stringType()])
|
|
10807
10828
|
});
|
|
10808
|
-
const
|
|
10809
|
-
|
|
10810
|
-
|
|
10811
|
-
|
|
10812
|
-
|
|
10813
|
-
|
|
10814
|
-
|
|
10815
|
-
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10821
|
-
|
|
10822
|
-
|
|
10823
|
-
|
|
10824
|
-
|
|
10825
|
-
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10826
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10827
|
-
})
|
|
10828
|
-
}
|
|
10829
|
-
),
|
|
10830
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
10831
|
-
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10832
|
-
labelValue,
|
|
10833
|
-
":"
|
|
10834
|
-
] }),
|
|
10835
|
-
" ",
|
|
10836
|
-
children
|
|
10837
|
-
] })
|
|
10838
|
-
]
|
|
10839
|
-
}
|
|
10840
|
-
);
|
|
10841
|
-
}
|
|
10842
|
-
);
|
|
10843
|
-
InlineTip.displayName = "InlineTip";
|
|
10844
|
-
const MetadataFieldSchema = objectType({
|
|
10845
|
-
key: stringType(),
|
|
10846
|
-
disabled: booleanType().optional(),
|
|
10847
|
-
value: anyType()
|
|
10848
|
-
});
|
|
10849
|
-
const MetadataSchema = objectType({
|
|
10850
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10851
|
-
});
|
|
10852
|
-
const Metadata = () => {
|
|
10853
|
-
const { id } = reactRouterDom.useParams();
|
|
10854
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10855
|
-
fields: "metadata"
|
|
10829
|
+
const PROMOTION_QUERY_KEY = "promotions";
|
|
10830
|
+
const promotionsQueryKeys = {
|
|
10831
|
+
list: (query2) => [
|
|
10832
|
+
PROMOTION_QUERY_KEY,
|
|
10833
|
+
query2 ? query2 : void 0
|
|
10834
|
+
],
|
|
10835
|
+
detail: (id, query2) => [
|
|
10836
|
+
PROMOTION_QUERY_KEY,
|
|
10837
|
+
id,
|
|
10838
|
+
query2 ? query2 : void 0
|
|
10839
|
+
]
|
|
10840
|
+
};
|
|
10841
|
+
const usePromotions = (query2, options) => {
|
|
10842
|
+
const { data, ...rest } = reactQuery.useQuery({
|
|
10843
|
+
queryKey: promotionsQueryKeys.list(query2),
|
|
10844
|
+
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
10845
|
+
...options
|
|
10856
10846
|
});
|
|
10857
|
-
|
|
10858
|
-
|
|
10847
|
+
return { ...data, ...rest };
|
|
10848
|
+
};
|
|
10849
|
+
const Promotions = () => {
|
|
10850
|
+
const { id } = reactRouterDom.useParams();
|
|
10851
|
+
const {
|
|
10852
|
+
order: preview,
|
|
10853
|
+
isError: isPreviewError,
|
|
10854
|
+
error: previewError
|
|
10855
|
+
} = useOrderPreview(id, void 0);
|
|
10856
|
+
useInitiateOrderEdit({ preview });
|
|
10857
|
+
const { onCancel } = useCancelOrderEdit({ preview });
|
|
10858
|
+
if (isPreviewError) {
|
|
10859
|
+
throw previewError;
|
|
10859
10860
|
}
|
|
10860
|
-
const isReady =
|
|
10861
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
10862
|
-
/* @__PURE__ */ jsxRuntime.
|
|
10863
|
-
|
|
10864
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10865
|
-
] }),
|
|
10866
|
-
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
10861
|
+
const isReady = !!preview;
|
|
10862
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
10863
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
10864
|
+
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
10867
10865
|
] });
|
|
10868
10866
|
};
|
|
10869
|
-
const
|
|
10870
|
-
const
|
|
10871
|
-
const
|
|
10867
|
+
const PromotionForm = ({ preview }) => {
|
|
10868
|
+
const { items, shipping_methods } = preview;
|
|
10869
|
+
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
10870
|
+
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
10872
10871
|
const { handleSuccess } = useRouteModal();
|
|
10873
|
-
const
|
|
10874
|
-
const
|
|
10875
|
-
const
|
|
10876
|
-
|
|
10877
|
-
|
|
10872
|
+
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
10873
|
+
const promoIds = getPromotionIds(items, shipping_methods);
|
|
10874
|
+
const { promotions, isPending, isError, error } = usePromotions(
|
|
10875
|
+
{
|
|
10876
|
+
id: promoIds
|
|
10878
10877
|
},
|
|
10879
|
-
|
|
10878
|
+
{
|
|
10879
|
+
enabled: !!promoIds.length
|
|
10880
|
+
}
|
|
10881
|
+
);
|
|
10882
|
+
const comboboxData = useComboboxData({
|
|
10883
|
+
queryKey: ["promotions", "combobox", promoIds],
|
|
10884
|
+
queryFn: async (params) => {
|
|
10885
|
+
return await sdk.admin.promotion.list({
|
|
10886
|
+
...params,
|
|
10887
|
+
id: {
|
|
10888
|
+
$nin: promoIds
|
|
10889
|
+
}
|
|
10890
|
+
});
|
|
10891
|
+
},
|
|
10892
|
+
getOptions: (data) => {
|
|
10893
|
+
return data.promotions.map((promotion) => ({
|
|
10894
|
+
label: promotion.code,
|
|
10895
|
+
value: promotion.code
|
|
10896
|
+
}));
|
|
10897
|
+
}
|
|
10880
10898
|
});
|
|
10881
|
-
const
|
|
10882
|
-
|
|
10883
|
-
|
|
10899
|
+
const add = async (value) => {
|
|
10900
|
+
if (!value) {
|
|
10901
|
+
return;
|
|
10902
|
+
}
|
|
10903
|
+
addPromotions(
|
|
10884
10904
|
{
|
|
10885
|
-
|
|
10905
|
+
promo_codes: [value]
|
|
10886
10906
|
},
|
|
10887
10907
|
{
|
|
10888
|
-
|
|
10889
|
-
ui.toast.
|
|
10890
|
-
|
|
10908
|
+
onError: (e) => {
|
|
10909
|
+
ui.toast.error(e.message);
|
|
10910
|
+
comboboxData.onSearchValueChange("");
|
|
10911
|
+
setComboboxValue("");
|
|
10891
10912
|
},
|
|
10892
|
-
|
|
10893
|
-
|
|
10913
|
+
onSuccess: () => {
|
|
10914
|
+
comboboxData.onSearchValueChange("");
|
|
10915
|
+
setComboboxValue("");
|
|
10894
10916
|
}
|
|
10895
10917
|
}
|
|
10896
10918
|
);
|
|
10897
|
-
}
|
|
10898
|
-
const {
|
|
10899
|
-
|
|
10900
|
-
|
|
10901
|
-
|
|
10902
|
-
|
|
10903
|
-
|
|
10904
|
-
|
|
10905
|
-
|
|
10906
|
-
|
|
10907
|
-
|
|
10908
|
-
|
|
10909
|
-
}
|
|
10919
|
+
};
|
|
10920
|
+
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
10921
|
+
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
10922
|
+
const onSubmit = async () => {
|
|
10923
|
+
setIsSubmitting(true);
|
|
10924
|
+
let requestSucceeded = false;
|
|
10925
|
+
await requestOrderEdit(void 0, {
|
|
10926
|
+
onError: (e) => {
|
|
10927
|
+
ui.toast.error(e.message);
|
|
10928
|
+
},
|
|
10929
|
+
onSuccess: () => {
|
|
10930
|
+
requestSucceeded = true;
|
|
10931
|
+
}
|
|
10932
|
+
});
|
|
10933
|
+
if (!requestSucceeded) {
|
|
10934
|
+
setIsSubmitting(false);
|
|
10935
|
+
return;
|
|
10910
10936
|
}
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10937
|
+
await confirmOrderEdit(void 0, {
|
|
10938
|
+
onError: (e) => {
|
|
10939
|
+
ui.toast.error(e.message);
|
|
10940
|
+
},
|
|
10941
|
+
onSuccess: () => {
|
|
10942
|
+
handleSuccess();
|
|
10943
|
+
},
|
|
10944
|
+
onSettled: () => {
|
|
10945
|
+
setIsSubmitting(false);
|
|
10946
|
+
}
|
|
10917
10947
|
});
|
|
10948
|
+
};
|
|
10949
|
+
if (isError) {
|
|
10950
|
+
throw error;
|
|
10918
10951
|
}
|
|
10919
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
|
|
10925
|
-
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
10932
|
-
|
|
10933
|
-
|
|
10934
|
-
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10940
|
-
|
|
10941
|
-
|
|
10942
|
-
|
|
10943
|
-
|
|
10944
|
-
|
|
10945
|
-
|
|
10946
|
-
|
|
10947
|
-
|
|
10948
|
-
|
|
10949
|
-
|
|
10952
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
10953
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
10954
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
10955
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
10956
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
10957
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
10958
|
+
] }),
|
|
10959
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10960
|
+
Combobox,
|
|
10961
|
+
{
|
|
10962
|
+
id: "promotion-combobox",
|
|
10963
|
+
"aria-describedby": "promotion-combobox-hint",
|
|
10964
|
+
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
10965
|
+
fetchNextPage: comboboxData.fetchNextPage,
|
|
10966
|
+
options: comboboxData.options,
|
|
10967
|
+
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
10968
|
+
searchValue: comboboxData.searchValue,
|
|
10969
|
+
disabled: comboboxData.disabled || isAddingPromotions,
|
|
10970
|
+
onChange: add,
|
|
10971
|
+
value: comboboxValue
|
|
10972
|
+
}
|
|
10973
|
+
)
|
|
10974
|
+
] }),
|
|
10975
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
10976
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
10977
|
+
PromotionItem,
|
|
10978
|
+
{
|
|
10979
|
+
promotion,
|
|
10980
|
+
orderId: preview.id,
|
|
10981
|
+
isLoading: isPending
|
|
10982
|
+
},
|
|
10983
|
+
promotion.id
|
|
10984
|
+
)) })
|
|
10985
|
+
] }) }),
|
|
10986
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
10987
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
10988
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
10989
|
+
ui.Button,
|
|
10990
|
+
{
|
|
10991
|
+
size: "small",
|
|
10992
|
+
type: "submit",
|
|
10993
|
+
isLoading: isSubmitting || isAddingPromotions,
|
|
10994
|
+
children: "Save"
|
|
10995
|
+
}
|
|
10996
|
+
)
|
|
10997
|
+
] }) })
|
|
10998
|
+
] });
|
|
10999
|
+
};
|
|
11000
|
+
const PromotionItem = ({
|
|
11001
|
+
promotion,
|
|
11002
|
+
orderId,
|
|
11003
|
+
isLoading
|
|
11004
|
+
}) => {
|
|
11005
|
+
var _a;
|
|
11006
|
+
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11007
|
+
const onRemove = async () => {
|
|
11008
|
+
removePromotions(
|
|
11009
|
+
{
|
|
11010
|
+
promo_codes: [promotion.code]
|
|
11011
|
+
},
|
|
11012
|
+
{
|
|
11013
|
+
onError: (e) => {
|
|
11014
|
+
ui.toast.error(e.message);
|
|
11015
|
+
}
|
|
11016
|
+
}
|
|
11017
|
+
);
|
|
11018
|
+
};
|
|
11019
|
+
const displayValue = getDisplayValue(promotion);
|
|
11020
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11021
|
+
"div",
|
|
11022
|
+
{
|
|
11023
|
+
className: ui.clx(
|
|
11024
|
+
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11025
|
+
{
|
|
11026
|
+
"animate-pulse": isLoading
|
|
11027
|
+
}
|
|
11028
|
+
),
|
|
11029
|
+
children: [
|
|
11030
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11031
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11032
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11033
|
+
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11034
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11035
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11036
|
+
] }),
|
|
11037
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11038
|
+
] })
|
|
11039
|
+
] }),
|
|
11040
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11041
|
+
ui.IconButton,
|
|
11042
|
+
{
|
|
11043
|
+
size: "small",
|
|
11044
|
+
type: "button",
|
|
11045
|
+
variant: "transparent",
|
|
11046
|
+
onClick: onRemove,
|
|
11047
|
+
isLoading: isPending || isLoading,
|
|
11048
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11049
|
+
}
|
|
11050
|
+
)
|
|
11051
|
+
]
|
|
11052
|
+
},
|
|
11053
|
+
promotion.id
|
|
11054
|
+
);
|
|
11055
|
+
};
|
|
11056
|
+
function getDisplayValue(promotion) {
|
|
11057
|
+
var _a, _b, _c, _d;
|
|
11058
|
+
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11059
|
+
if (!value) {
|
|
11060
|
+
return null;
|
|
11061
|
+
}
|
|
11062
|
+
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11063
|
+
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11064
|
+
if (!currency) {
|
|
11065
|
+
return null;
|
|
11066
|
+
}
|
|
11067
|
+
return getLocaleAmount(value, currency);
|
|
11068
|
+
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11069
|
+
return formatPercentage(value);
|
|
11070
|
+
}
|
|
11071
|
+
return null;
|
|
11072
|
+
}
|
|
11073
|
+
const formatter = new Intl.NumberFormat([], {
|
|
11074
|
+
style: "percent",
|
|
11075
|
+
minimumFractionDigits: 2
|
|
11076
|
+
});
|
|
11077
|
+
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11078
|
+
let val = value || 0;
|
|
11079
|
+
if (!isPercentageValue) {
|
|
11080
|
+
val = val / 100;
|
|
11081
|
+
}
|
|
11082
|
+
return formatter.format(val);
|
|
11083
|
+
};
|
|
11084
|
+
function getPromotionIds(items, shippingMethods) {
|
|
11085
|
+
const promotionIds = /* @__PURE__ */ new Set();
|
|
11086
|
+
for (const item of items) {
|
|
11087
|
+
if (item.adjustments) {
|
|
11088
|
+
for (const adjustment of item.adjustments) {
|
|
11089
|
+
if (adjustment.promotion_id) {
|
|
11090
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11091
|
+
}
|
|
11092
|
+
}
|
|
11093
|
+
}
|
|
11094
|
+
}
|
|
11095
|
+
for (const shippingMethod of shippingMethods) {
|
|
11096
|
+
if (shippingMethod.adjustments) {
|
|
11097
|
+
for (const adjustment of shippingMethod.adjustments) {
|
|
11098
|
+
if (adjustment.promotion_id) {
|
|
11099
|
+
promotionIds.add(adjustment.promotion_id);
|
|
11100
|
+
}
|
|
11101
|
+
}
|
|
11102
|
+
}
|
|
11103
|
+
}
|
|
11104
|
+
return Array.from(promotionIds);
|
|
11105
|
+
}
|
|
11106
|
+
const InlineTip = React.forwardRef(
|
|
11107
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11108
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11109
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11110
|
+
"div",
|
|
11111
|
+
{
|
|
11112
|
+
ref,
|
|
11113
|
+
className: ui.clx(
|
|
11114
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11115
|
+
className
|
|
11116
|
+
),
|
|
11117
|
+
...props,
|
|
11118
|
+
children: [
|
|
11119
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11120
|
+
"div",
|
|
11121
|
+
{
|
|
11122
|
+
role: "presentation",
|
|
11123
|
+
className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11124
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11125
|
+
})
|
|
11126
|
+
}
|
|
11127
|
+
),
|
|
11128
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
|
|
11129
|
+
/* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11130
|
+
labelValue,
|
|
11131
|
+
":"
|
|
11132
|
+
] }),
|
|
11133
|
+
" ",
|
|
11134
|
+
children
|
|
11135
|
+
] })
|
|
11136
|
+
]
|
|
11137
|
+
}
|
|
11138
|
+
);
|
|
11139
|
+
}
|
|
11140
|
+
);
|
|
11141
|
+
InlineTip.displayName = "InlineTip";
|
|
11142
|
+
const MetadataFieldSchema = objectType({
|
|
11143
|
+
key: stringType(),
|
|
11144
|
+
disabled: booleanType().optional(),
|
|
11145
|
+
value: anyType()
|
|
11146
|
+
});
|
|
11147
|
+
const MetadataSchema = objectType({
|
|
11148
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
11149
|
+
});
|
|
11150
|
+
const Metadata = () => {
|
|
11151
|
+
const { id } = reactRouterDom.useParams();
|
|
11152
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11153
|
+
fields: "metadata"
|
|
11154
|
+
});
|
|
11155
|
+
if (isError) {
|
|
11156
|
+
throw error;
|
|
11157
|
+
}
|
|
11158
|
+
const isReady = !isPending && !!order;
|
|
11159
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11160
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11161
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
|
|
11162
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
11163
|
+
] }),
|
|
11164
|
+
!isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
11165
|
+
] });
|
|
11166
|
+
};
|
|
11167
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
11168
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11169
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
11170
|
+
const { handleSuccess } = useRouteModal();
|
|
11171
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11172
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11173
|
+
const form = reactHookForm.useForm({
|
|
11174
|
+
defaultValues: {
|
|
11175
|
+
metadata: getDefaultValues(metadata)
|
|
11176
|
+
},
|
|
11177
|
+
resolver: zod.zodResolver(MetadataSchema)
|
|
11178
|
+
});
|
|
11179
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11180
|
+
const parsedData = parseValues(data);
|
|
11181
|
+
await mutateAsync(
|
|
11182
|
+
{
|
|
11183
|
+
metadata: parsedData
|
|
11184
|
+
},
|
|
11185
|
+
{
|
|
11186
|
+
onSuccess: () => {
|
|
11187
|
+
ui.toast.success("Metadata updated");
|
|
11188
|
+
handleSuccess();
|
|
11189
|
+
},
|
|
11190
|
+
onError: (error) => {
|
|
11191
|
+
ui.toast.error(error.message);
|
|
11192
|
+
}
|
|
11193
|
+
}
|
|
11194
|
+
);
|
|
11195
|
+
});
|
|
11196
|
+
const { fields, insert, remove } = reactHookForm.useFieldArray({
|
|
11197
|
+
control: form.control,
|
|
11198
|
+
name: "metadata"
|
|
11199
|
+
});
|
|
11200
|
+
function deleteRow(index) {
|
|
11201
|
+
remove(index);
|
|
11202
|
+
if (fields.length === 1) {
|
|
11203
|
+
insert(0, {
|
|
11204
|
+
key: "",
|
|
11205
|
+
value: "",
|
|
11206
|
+
disabled: false
|
|
11207
|
+
});
|
|
11208
|
+
}
|
|
11209
|
+
}
|
|
11210
|
+
function insertRow(index, position) {
|
|
11211
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
11212
|
+
key: "",
|
|
11213
|
+
value: "",
|
|
11214
|
+
disabled: false
|
|
11215
|
+
});
|
|
11216
|
+
}
|
|
11217
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11218
|
+
KeyboundForm,
|
|
11219
|
+
{
|
|
11220
|
+
onSubmit: handleSubmit,
|
|
11221
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11222
|
+
children: [
|
|
11223
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
11224
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
11225
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
11226
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
11227
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
11228
|
+
] }),
|
|
11229
|
+
fields.map((field, index) => {
|
|
11230
|
+
const isDisabled = field.disabled || false;
|
|
11231
|
+
let placeholder = "-";
|
|
11232
|
+
if (typeof field.value === "object") {
|
|
11233
|
+
placeholder = "{ ... }";
|
|
11234
|
+
}
|
|
11235
|
+
if (Array.isArray(field.value)) {
|
|
11236
|
+
placeholder = "[ ... ]";
|
|
11237
|
+
}
|
|
11238
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11239
|
+
ConditionalTooltip,
|
|
11240
|
+
{
|
|
11241
|
+
showTooltip: isDisabled,
|
|
11242
|
+
content: "This row is disabled because it contains non-primitive data.",
|
|
11243
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
|
|
11244
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
11245
|
+
"div",
|
|
11246
|
+
{
|
|
11247
|
+
className: ui.clx("grid grid-cols-2 divide-x", {
|
|
10950
11248
|
"overflow-hidden rounded-b-lg": index === fields.length - 1
|
|
10951
11249
|
}),
|
|
10952
11250
|
children: [
|
|
@@ -11155,283 +11453,112 @@ function getHasUneditableRows(metadata) {
|
|
|
11155
11453
|
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11156
11454
|
);
|
|
11157
11455
|
}
|
|
11158
|
-
const
|
|
11159
|
-
const promotionsQueryKeys = {
|
|
11160
|
-
list: (query2) => [
|
|
11161
|
-
PROMOTION_QUERY_KEY,
|
|
11162
|
-
query2 ? query2 : void 0
|
|
11163
|
-
],
|
|
11164
|
-
detail: (id, query2) => [
|
|
11165
|
-
PROMOTION_QUERY_KEY,
|
|
11166
|
-
id,
|
|
11167
|
-
query2 ? query2 : void 0
|
|
11168
|
-
]
|
|
11169
|
-
};
|
|
11170
|
-
const usePromotions = (query2, options) => {
|
|
11171
|
-
const { data, ...rest } = reactQuery.useQuery({
|
|
11172
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
11173
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11174
|
-
...options
|
|
11175
|
-
});
|
|
11176
|
-
return { ...data, ...rest };
|
|
11177
|
-
};
|
|
11178
|
-
const Promotions = () => {
|
|
11456
|
+
const SalesChannel = () => {
|
|
11179
11457
|
const { id } = reactRouterDom.useParams();
|
|
11180
|
-
const {
|
|
11181
|
-
|
|
11182
|
-
isError: isPreviewError,
|
|
11183
|
-
error: previewError
|
|
11184
|
-
} = useOrderPreview(id, void 0);
|
|
11185
|
-
useInitiateOrderEdit({ preview });
|
|
11186
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11187
|
-
if (isPreviewError) {
|
|
11188
|
-
throw previewError;
|
|
11189
|
-
}
|
|
11190
|
-
const isReady = !!preview;
|
|
11191
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11192
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Promotions" }) }) }),
|
|
11193
|
-
isReady && /* @__PURE__ */ jsxRuntime.jsx(PromotionForm, { preview })
|
|
11194
|
-
] });
|
|
11195
|
-
};
|
|
11196
|
-
const PromotionForm = ({ preview }) => {
|
|
11197
|
-
const { items, shipping_methods } = preview;
|
|
11198
|
-
const [isSubmitting, setIsSubmitting] = React.useState(false);
|
|
11199
|
-
const [comboboxValue, setComboboxValue] = React.useState("");
|
|
11200
|
-
const { handleSuccess } = useRouteModal();
|
|
11201
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11202
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11203
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
11458
|
+
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
11459
|
+
id,
|
|
11204
11460
|
{
|
|
11205
|
-
|
|
11461
|
+
fields: "+sales_channel_id"
|
|
11206
11462
|
},
|
|
11207
11463
|
{
|
|
11208
|
-
enabled: !!
|
|
11464
|
+
enabled: !!id
|
|
11209
11465
|
}
|
|
11210
11466
|
);
|
|
11211
|
-
const comboboxData = useComboboxData({
|
|
11212
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
11213
|
-
queryFn: async (params) => {
|
|
11214
|
-
return await sdk.admin.promotion.list({
|
|
11215
|
-
...params,
|
|
11216
|
-
id: {
|
|
11217
|
-
$nin: promoIds
|
|
11218
|
-
}
|
|
11219
|
-
});
|
|
11220
|
-
},
|
|
11221
|
-
getOptions: (data) => {
|
|
11222
|
-
return data.promotions.map((promotion) => ({
|
|
11223
|
-
label: promotion.code,
|
|
11224
|
-
value: promotion.code
|
|
11225
|
-
}));
|
|
11226
|
-
}
|
|
11227
|
-
});
|
|
11228
|
-
const add = async (value) => {
|
|
11229
|
-
if (!value) {
|
|
11230
|
-
return;
|
|
11231
|
-
}
|
|
11232
|
-
addPromotions(
|
|
11233
|
-
{
|
|
11234
|
-
promo_codes: [value]
|
|
11235
|
-
},
|
|
11236
|
-
{
|
|
11237
|
-
onError: (e) => {
|
|
11238
|
-
ui.toast.error(e.message);
|
|
11239
|
-
comboboxData.onSearchValueChange("");
|
|
11240
|
-
setComboboxValue("");
|
|
11241
|
-
},
|
|
11242
|
-
onSuccess: () => {
|
|
11243
|
-
comboboxData.onSearchValueChange("");
|
|
11244
|
-
setComboboxValue("");
|
|
11245
|
-
}
|
|
11246
|
-
}
|
|
11247
|
-
);
|
|
11248
|
-
};
|
|
11249
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11250
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11251
|
-
const onSubmit = async () => {
|
|
11252
|
-
setIsSubmitting(true);
|
|
11253
|
-
let requestSucceeded = false;
|
|
11254
|
-
await requestOrderEdit(void 0, {
|
|
11255
|
-
onError: (e) => {
|
|
11256
|
-
ui.toast.error(e.message);
|
|
11257
|
-
},
|
|
11258
|
-
onSuccess: () => {
|
|
11259
|
-
requestSucceeded = true;
|
|
11260
|
-
}
|
|
11261
|
-
});
|
|
11262
|
-
if (!requestSucceeded) {
|
|
11263
|
-
setIsSubmitting(false);
|
|
11264
|
-
return;
|
|
11265
|
-
}
|
|
11266
|
-
await confirmOrderEdit(void 0, {
|
|
11267
|
-
onError: (e) => {
|
|
11268
|
-
ui.toast.error(e.message);
|
|
11269
|
-
},
|
|
11270
|
-
onSuccess: () => {
|
|
11271
|
-
handleSuccess();
|
|
11272
|
-
},
|
|
11273
|
-
onSettled: () => {
|
|
11274
|
-
setIsSubmitting(false);
|
|
11275
|
-
}
|
|
11276
|
-
});
|
|
11277
|
-
};
|
|
11278
11467
|
if (isError) {
|
|
11279
|
-
throw error;
|
|
11280
|
-
}
|
|
11281
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11282
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11283
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11284
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
11285
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11286
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Hint, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11287
|
-
] }),
|
|
11288
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11289
|
-
Combobox,
|
|
11290
|
-
{
|
|
11291
|
-
id: "promotion-combobox",
|
|
11292
|
-
"aria-describedby": "promotion-combobox-hint",
|
|
11293
|
-
isFetchingNextPage: comboboxData.isFetchingNextPage,
|
|
11294
|
-
fetchNextPage: comboboxData.fetchNextPage,
|
|
11295
|
-
options: comboboxData.options,
|
|
11296
|
-
onSearchValueChange: comboboxData.onSearchValueChange,
|
|
11297
|
-
searchValue: comboboxData.searchValue,
|
|
11298
|
-
disabled: comboboxData.disabled || isAddingPromotions,
|
|
11299
|
-
onChange: add,
|
|
11300
|
-
value: comboboxValue
|
|
11301
|
-
}
|
|
11302
|
-
)
|
|
11303
|
-
] }),
|
|
11304
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
|
|
11305
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-col gap-2", children: promotions == null ? void 0 : promotions.map((promotion) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
11306
|
-
PromotionItem,
|
|
11307
|
-
{
|
|
11308
|
-
promotion,
|
|
11309
|
-
orderId: preview.id,
|
|
11310
|
-
isLoading: isPending
|
|
11311
|
-
},
|
|
11312
|
-
promotion.id
|
|
11313
|
-
)) })
|
|
11314
|
-
] }) }),
|
|
11315
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11316
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11317
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11318
|
-
ui.Button,
|
|
11319
|
-
{
|
|
11320
|
-
size: "small",
|
|
11321
|
-
type: "submit",
|
|
11322
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11323
|
-
children: "Save"
|
|
11324
|
-
}
|
|
11325
|
-
)
|
|
11326
|
-
] }) })
|
|
11327
|
-
] });
|
|
11328
|
-
};
|
|
11329
|
-
const PromotionItem = ({
|
|
11330
|
-
promotion,
|
|
11331
|
-
orderId,
|
|
11332
|
-
isLoading
|
|
11333
|
-
}) => {
|
|
11334
|
-
var _a;
|
|
11335
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11336
|
-
const onRemove = async () => {
|
|
11337
|
-
removePromotions(
|
|
11338
|
-
{
|
|
11339
|
-
promo_codes: [promotion.code]
|
|
11340
|
-
},
|
|
11341
|
-
{
|
|
11342
|
-
onError: (e) => {
|
|
11343
|
-
ui.toast.error(e.message);
|
|
11344
|
-
}
|
|
11345
|
-
}
|
|
11346
|
-
);
|
|
11347
|
-
};
|
|
11348
|
-
const displayValue = getDisplayValue(promotion);
|
|
11349
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11350
|
-
"div",
|
|
11351
|
-
{
|
|
11352
|
-
className: ui.clx(
|
|
11353
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11354
|
-
{
|
|
11355
|
-
"animate-pulse": isLoading
|
|
11356
|
-
}
|
|
11357
|
-
),
|
|
11358
|
-
children: [
|
|
11359
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
11360
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11361
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11362
|
-
displayValue && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11363
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11364
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", children: "·" })
|
|
11365
|
-
] }),
|
|
11366
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11367
|
-
] })
|
|
11368
|
-
] }),
|
|
11369
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11370
|
-
ui.IconButton,
|
|
11371
|
-
{
|
|
11372
|
-
size: "small",
|
|
11373
|
-
type: "button",
|
|
11374
|
-
variant: "transparent",
|
|
11375
|
-
onClick: onRemove,
|
|
11376
|
-
isLoading: isPending || isLoading,
|
|
11377
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(icons.XMark, {})
|
|
11378
|
-
}
|
|
11379
|
-
)
|
|
11380
|
-
]
|
|
11381
|
-
},
|
|
11382
|
-
promotion.id
|
|
11383
|
-
);
|
|
11384
|
-
};
|
|
11385
|
-
function getDisplayValue(promotion) {
|
|
11386
|
-
var _a, _b, _c, _d;
|
|
11387
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11388
|
-
if (!value) {
|
|
11389
|
-
return null;
|
|
11390
|
-
}
|
|
11391
|
-
if (((_b = promotion.application_method) == null ? void 0 : _b.type) === "fixed") {
|
|
11392
|
-
const currency = (_c = promotion.application_method) == null ? void 0 : _c.currency_code;
|
|
11393
|
-
if (!currency) {
|
|
11394
|
-
return null;
|
|
11395
|
-
}
|
|
11396
|
-
return getLocaleAmount(value, currency);
|
|
11397
|
-
} else if (((_d = promotion.application_method) == null ? void 0 : _d.type) === "percentage") {
|
|
11398
|
-
return formatPercentage(value);
|
|
11399
|
-
}
|
|
11400
|
-
return null;
|
|
11401
|
-
}
|
|
11402
|
-
const formatter = new Intl.NumberFormat([], {
|
|
11403
|
-
style: "percent",
|
|
11404
|
-
minimumFractionDigits: 2
|
|
11405
|
-
});
|
|
11406
|
-
const formatPercentage = (value, isPercentageValue = false) => {
|
|
11407
|
-
let val = value || 0;
|
|
11408
|
-
if (!isPercentageValue) {
|
|
11409
|
-
val = val / 100;
|
|
11468
|
+
throw error;
|
|
11410
11469
|
}
|
|
11411
|
-
|
|
11470
|
+
const ISrEADY = !!draft_order && !isPending;
|
|
11471
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
11472
|
+
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
11473
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
11474
|
+
/* @__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" }) })
|
|
11475
|
+
] }),
|
|
11476
|
+
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
11477
|
+
] });
|
|
11412
11478
|
};
|
|
11413
|
-
|
|
11414
|
-
const
|
|
11415
|
-
|
|
11416
|
-
|
|
11417
|
-
|
|
11418
|
-
|
|
11419
|
-
|
|
11479
|
+
const SalesChannelForm = ({ order }) => {
|
|
11480
|
+
const form = reactHookForm.useForm({
|
|
11481
|
+
defaultValues: {
|
|
11482
|
+
sales_channel_id: order.sales_channel_id || ""
|
|
11483
|
+
},
|
|
11484
|
+
resolver: zod.zodResolver(schema$2)
|
|
11485
|
+
});
|
|
11486
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
11487
|
+
const { handleSuccess } = useRouteModal();
|
|
11488
|
+
const onSubmit = form.handleSubmit(async (data) => {
|
|
11489
|
+
await mutateAsync(
|
|
11490
|
+
{
|
|
11491
|
+
sales_channel_id: data.sales_channel_id
|
|
11492
|
+
},
|
|
11493
|
+
{
|
|
11494
|
+
onSuccess: () => {
|
|
11495
|
+
ui.toast.success("Sales channel updated");
|
|
11496
|
+
handleSuccess();
|
|
11497
|
+
},
|
|
11498
|
+
onError: (error) => {
|
|
11499
|
+
ui.toast.error(error.message);
|
|
11420
11500
|
}
|
|
11421
11501
|
}
|
|
11502
|
+
);
|
|
11503
|
+
});
|
|
11504
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11505
|
+
KeyboundForm,
|
|
11506
|
+
{
|
|
11507
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11508
|
+
onSubmit,
|
|
11509
|
+
children: [
|
|
11510
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
11511
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11512
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11513
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11514
|
+
] }) })
|
|
11515
|
+
]
|
|
11422
11516
|
}
|
|
11423
|
-
}
|
|
11424
|
-
|
|
11425
|
-
|
|
11426
|
-
|
|
11427
|
-
|
|
11428
|
-
|
|
11429
|
-
|
|
11517
|
+
) });
|
|
11518
|
+
};
|
|
11519
|
+
const SalesChannelField = ({ control, order }) => {
|
|
11520
|
+
const salesChannels = useComboboxData({
|
|
11521
|
+
queryFn: async (params) => {
|
|
11522
|
+
return await sdk.admin.salesChannel.list(params);
|
|
11523
|
+
},
|
|
11524
|
+
queryKey: ["sales-channels"],
|
|
11525
|
+
getOptions: (data) => {
|
|
11526
|
+
return data.sales_channels.map((salesChannel) => ({
|
|
11527
|
+
label: salesChannel.name,
|
|
11528
|
+
value: salesChannel.id
|
|
11529
|
+
}));
|
|
11530
|
+
},
|
|
11531
|
+
defaultValue: order.sales_channel_id || void 0
|
|
11532
|
+
});
|
|
11533
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11534
|
+
Form$2.Field,
|
|
11535
|
+
{
|
|
11536
|
+
control,
|
|
11537
|
+
name: "sales_channel_id",
|
|
11538
|
+
render: ({ field }) => {
|
|
11539
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
11540
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
11541
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
11542
|
+
Combobox,
|
|
11543
|
+
{
|
|
11544
|
+
options: salesChannels.options,
|
|
11545
|
+
fetchNextPage: salesChannels.fetchNextPage,
|
|
11546
|
+
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
11547
|
+
searchValue: salesChannels.searchValue,
|
|
11548
|
+
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
11549
|
+
placeholder: "Select sales channel",
|
|
11550
|
+
...field
|
|
11551
|
+
}
|
|
11552
|
+
) }),
|
|
11553
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
11554
|
+
] });
|
|
11430
11555
|
}
|
|
11431
11556
|
}
|
|
11432
|
-
|
|
11433
|
-
|
|
11434
|
-
|
|
11557
|
+
);
|
|
11558
|
+
};
|
|
11559
|
+
const schema$2 = objectType({
|
|
11560
|
+
sales_channel_id: stringType().min(1)
|
|
11561
|
+
});
|
|
11435
11562
|
const STACKED_FOCUS_MODAL_ID = "shipping-form";
|
|
11436
11563
|
const Shipping = () => {
|
|
11437
11564
|
var _a;
|
|
@@ -12262,7 +12389,7 @@ const TransferOwnershipForm = ({ order }) => {
|
|
|
12262
12389
|
defaultValues: {
|
|
12263
12390
|
customer_id: order.customer_id || ""
|
|
12264
12391
|
},
|
|
12265
|
-
resolver: zod.zodResolver(schema$
|
|
12392
|
+
resolver: zod.zodResolver(schema$1)
|
|
12266
12393
|
});
|
|
12267
12394
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12268
12395
|
const { handleSuccess } = useRouteModal();
|
|
@@ -12712,115 +12839,9 @@ const Illustration = () => {
|
|
|
12712
12839
|
}
|
|
12713
12840
|
);
|
|
12714
12841
|
};
|
|
12715
|
-
const schema$
|
|
12842
|
+
const schema$1 = objectType({
|
|
12716
12843
|
customer_id: stringType().min(1)
|
|
12717
12844
|
});
|
|
12718
|
-
const SalesChannel = () => {
|
|
12719
|
-
const { id } = reactRouterDom.useParams();
|
|
12720
|
-
const { draft_order, isPending, isError, error } = useDraftOrder(
|
|
12721
|
-
id,
|
|
12722
|
-
{
|
|
12723
|
-
fields: "+sales_channel_id"
|
|
12724
|
-
},
|
|
12725
|
-
{
|
|
12726
|
-
enabled: !!id
|
|
12727
|
-
}
|
|
12728
|
-
);
|
|
12729
|
-
if (isError) {
|
|
12730
|
-
throw error;
|
|
12731
|
-
}
|
|
12732
|
-
const ISrEADY = !!draft_order && !isPending;
|
|
12733
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
12734
|
-
/* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
|
|
12735
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Sales Channel" }) }),
|
|
12736
|
-
/* @__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" }) })
|
|
12737
|
-
] }),
|
|
12738
|
-
ISrEADY && /* @__PURE__ */ jsxRuntime.jsx(SalesChannelForm, { order: draft_order })
|
|
12739
|
-
] });
|
|
12740
|
-
};
|
|
12741
|
-
const SalesChannelForm = ({ order }) => {
|
|
12742
|
-
const form = reactHookForm.useForm({
|
|
12743
|
-
defaultValues: {
|
|
12744
|
-
sales_channel_id: order.sales_channel_id || ""
|
|
12745
|
-
},
|
|
12746
|
-
resolver: zod.zodResolver(schema$2)
|
|
12747
|
-
});
|
|
12748
|
-
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12749
|
-
const { handleSuccess } = useRouteModal();
|
|
12750
|
-
const onSubmit = form.handleSubmit(async (data) => {
|
|
12751
|
-
await mutateAsync(
|
|
12752
|
-
{
|
|
12753
|
-
sales_channel_id: data.sales_channel_id
|
|
12754
|
-
},
|
|
12755
|
-
{
|
|
12756
|
-
onSuccess: () => {
|
|
12757
|
-
ui.toast.success("Sales channel updated");
|
|
12758
|
-
handleSuccess();
|
|
12759
|
-
},
|
|
12760
|
-
onError: (error) => {
|
|
12761
|
-
ui.toast.error(error.message);
|
|
12762
|
-
}
|
|
12763
|
-
}
|
|
12764
|
-
);
|
|
12765
|
-
});
|
|
12766
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
12767
|
-
KeyboundForm,
|
|
12768
|
-
{
|
|
12769
|
-
className: "flex flex-1 flex-col overflow-hidden",
|
|
12770
|
-
onSubmit,
|
|
12771
|
-
children: [
|
|
12772
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsx(SalesChannelField, { control: form.control, order }) }),
|
|
12773
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
12774
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
12775
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
12776
|
-
] }) })
|
|
12777
|
-
]
|
|
12778
|
-
}
|
|
12779
|
-
) });
|
|
12780
|
-
};
|
|
12781
|
-
const SalesChannelField = ({ control, order }) => {
|
|
12782
|
-
const salesChannels = useComboboxData({
|
|
12783
|
-
queryFn: async (params) => {
|
|
12784
|
-
return await sdk.admin.salesChannel.list(params);
|
|
12785
|
-
},
|
|
12786
|
-
queryKey: ["sales-channels"],
|
|
12787
|
-
getOptions: (data) => {
|
|
12788
|
-
return data.sales_channels.map((salesChannel) => ({
|
|
12789
|
-
label: salesChannel.name,
|
|
12790
|
-
value: salesChannel.id
|
|
12791
|
-
}));
|
|
12792
|
-
},
|
|
12793
|
-
defaultValue: order.sales_channel_id || void 0
|
|
12794
|
-
});
|
|
12795
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
12796
|
-
Form$2.Field,
|
|
12797
|
-
{
|
|
12798
|
-
control,
|
|
12799
|
-
name: "sales_channel_id",
|
|
12800
|
-
render: ({ field }) => {
|
|
12801
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
|
|
12802
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Sales Channel" }),
|
|
12803
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
12804
|
-
Combobox,
|
|
12805
|
-
{
|
|
12806
|
-
options: salesChannels.options,
|
|
12807
|
-
fetchNextPage: salesChannels.fetchNextPage,
|
|
12808
|
-
isFetchingNextPage: salesChannels.isFetchingNextPage,
|
|
12809
|
-
searchValue: salesChannels.searchValue,
|
|
12810
|
-
onSearchValueChange: salesChannels.onSearchValueChange,
|
|
12811
|
-
placeholder: "Select sales channel",
|
|
12812
|
-
...field
|
|
12813
|
-
}
|
|
12814
|
-
) }),
|
|
12815
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
|
|
12816
|
-
] });
|
|
12817
|
-
}
|
|
12818
|
-
}
|
|
12819
|
-
);
|
|
12820
|
-
};
|
|
12821
|
-
const schema$2 = objectType({
|
|
12822
|
-
sales_channel_id: stringType().min(1)
|
|
12823
|
-
});
|
|
12824
12845
|
const ShippingAddress = () => {
|
|
12825
12846
|
const { id } = reactRouterDom.useParams();
|
|
12826
12847
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -12853,7 +12874,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
12853
12874
|
postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
12854
12875
|
phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
|
|
12855
12876
|
},
|
|
12856
|
-
resolver: zod.zodResolver(schema
|
|
12877
|
+
resolver: zod.zodResolver(schema)
|
|
12857
12878
|
});
|
|
12858
12879
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
12859
12880
|
const { handleSuccess } = useRouteModal();
|
|
@@ -13023,28 +13044,7 @@ const ShippingAddressForm = ({ order }) => {
|
|
|
13023
13044
|
}
|
|
13024
13045
|
) });
|
|
13025
13046
|
};
|
|
13026
|
-
const schema
|
|
13027
|
-
const CustomItems = () => {
|
|
13028
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
|
|
13029
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
|
|
13030
|
-
/* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
|
|
13031
|
-
] });
|
|
13032
|
-
};
|
|
13033
|
-
const CustomItemsForm = () => {
|
|
13034
|
-
const form = reactHookForm.useForm({
|
|
13035
|
-
resolver: zod.zodResolver(schema)
|
|
13036
|
-
});
|
|
13037
|
-
return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
13038
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
|
|
13039
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
13040
|
-
/* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
13041
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
|
|
13042
|
-
] }) })
|
|
13043
|
-
] }) });
|
|
13044
|
-
};
|
|
13045
|
-
const schema = objectType({
|
|
13046
|
-
email: stringType().email()
|
|
13047
|
-
});
|
|
13047
|
+
const schema = addressSchema;
|
|
13048
13048
|
const widgetModule = { widgets: [] };
|
|
13049
13049
|
const routeModule = {
|
|
13050
13050
|
routes: [
|
|
@@ -13069,6 +13069,10 @@ const routeModule = {
|
|
|
13069
13069
|
Component: BillingAddress,
|
|
13070
13070
|
path: "/draft-orders/:id/billing-address"
|
|
13071
13071
|
},
|
|
13072
|
+
{
|
|
13073
|
+
Component: CustomItems,
|
|
13074
|
+
path: "/draft-orders/:id/custom-items"
|
|
13075
|
+
},
|
|
13072
13076
|
{
|
|
13073
13077
|
Component: Email,
|
|
13074
13078
|
path: "/draft-orders/:id/email"
|
|
@@ -13077,13 +13081,17 @@ const routeModule = {
|
|
|
13077
13081
|
Component: Items,
|
|
13078
13082
|
path: "/draft-orders/:id/items"
|
|
13079
13083
|
},
|
|
13084
|
+
{
|
|
13085
|
+
Component: Promotions,
|
|
13086
|
+
path: "/draft-orders/:id/promotions"
|
|
13087
|
+
},
|
|
13080
13088
|
{
|
|
13081
13089
|
Component: Metadata,
|
|
13082
13090
|
path: "/draft-orders/:id/metadata"
|
|
13083
13091
|
},
|
|
13084
13092
|
{
|
|
13085
|
-
Component:
|
|
13086
|
-
path: "/draft-orders/:id/
|
|
13093
|
+
Component: SalesChannel,
|
|
13094
|
+
path: "/draft-orders/:id/sales-channel"
|
|
13087
13095
|
},
|
|
13088
13096
|
{
|
|
13089
13097
|
Component: Shipping,
|
|
@@ -13093,17 +13101,9 @@ const routeModule = {
|
|
|
13093
13101
|
Component: TransferOwnership,
|
|
13094
13102
|
path: "/draft-orders/:id/transfer-ownership"
|
|
13095
13103
|
},
|
|
13096
|
-
{
|
|
13097
|
-
Component: SalesChannel,
|
|
13098
|
-
path: "/draft-orders/:id/sales-channel"
|
|
13099
|
-
},
|
|
13100
13104
|
{
|
|
13101
13105
|
Component: ShippingAddress,
|
|
13102
13106
|
path: "/draft-orders/:id/shipping-address"
|
|
13103
|
-
},
|
|
13104
|
-
{
|
|
13105
|
-
Component: CustomItems,
|
|
13106
|
-
path: "/draft-orders/:id/custom-items"
|
|
13107
13107
|
}
|
|
13108
13108
|
]
|
|
13109
13109
|
}
|