@medusajs/draft-order 2.11.0-snapshot-20251019075109 → 2.11.0-snapshot-20251020120939
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 +525 -527
- package/.medusa/server/src/admin/index.mjs +525 -527
- package/package.json +16 -16
|
@@ -7817,12 +7817,10 @@ const CustomerField$1 = ({ control, setValue }) => {
|
|
|
7817
7817
|
(option) => option.value === value
|
|
7818
7818
|
)) == null ? void 0 : _a.label;
|
|
7819
7819
|
const customerEmail = ((_b = label == null ? void 0 : label.match(/\((.*@.*)\)$/)) == null ? void 0 : _b[1]) || label;
|
|
7820
|
-
|
|
7821
|
-
|
|
7822
|
-
|
|
7823
|
-
|
|
7824
|
-
});
|
|
7825
|
-
}
|
|
7820
|
+
setValue("email", customerEmail || "", {
|
|
7821
|
+
shouldDirty: true,
|
|
7822
|
+
shouldTouch: true
|
|
7823
|
+
});
|
|
7826
7824
|
},
|
|
7827
7825
|
[email, setValue, customers.options]
|
|
7828
7826
|
);
|
|
@@ -9567,27 +9565,6 @@ const ID = () => {
|
|
|
9567
9565
|
/* @__PURE__ */ jsx(Outlet, {})
|
|
9568
9566
|
] });
|
|
9569
9567
|
};
|
|
9570
|
-
const CustomItems = () => {
|
|
9571
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9572
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9573
|
-
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9574
|
-
] });
|
|
9575
|
-
};
|
|
9576
|
-
const CustomItemsForm = () => {
|
|
9577
|
-
const form = useForm({
|
|
9578
|
-
resolver: zodResolver(schema$5)
|
|
9579
|
-
});
|
|
9580
|
-
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9581
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9582
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9583
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9584
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9585
|
-
] }) })
|
|
9586
|
-
] }) });
|
|
9587
|
-
};
|
|
9588
|
-
const schema$5 = objectType({
|
|
9589
|
-
email: stringType().email()
|
|
9590
|
-
});
|
|
9591
9568
|
const BillingAddress = () => {
|
|
9592
9569
|
const { id } = useParams();
|
|
9593
9570
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -9620,7 +9597,7 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9620
9597
|
postal_code: ((_i = order.billing_address) == null ? void 0 : _i.postal_code) ?? "",
|
|
9621
9598
|
phone: ((_j = order.billing_address) == null ? void 0 : _j.phone) ?? ""
|
|
9622
9599
|
},
|
|
9623
|
-
resolver: zodResolver(schema$
|
|
9600
|
+
resolver: zodResolver(schema$5)
|
|
9624
9601
|
});
|
|
9625
9602
|
const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
|
|
9626
9603
|
const { handleSuccess } = useRouteModal();
|
|
@@ -9777,7 +9754,28 @@ const BillingAddressForm = ({ order }) => {
|
|
|
9777
9754
|
}
|
|
9778
9755
|
) });
|
|
9779
9756
|
};
|
|
9780
|
-
const schema$
|
|
9757
|
+
const schema$5 = addressSchema;
|
|
9758
|
+
const CustomItems = () => {
|
|
9759
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
9760
|
+
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Custom Items" }) }) }),
|
|
9761
|
+
/* @__PURE__ */ jsx(CustomItemsForm, {})
|
|
9762
|
+
] });
|
|
9763
|
+
};
|
|
9764
|
+
const CustomItemsForm = () => {
|
|
9765
|
+
const form = useForm({
|
|
9766
|
+
resolver: zodResolver(schema$4)
|
|
9767
|
+
});
|
|
9768
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
|
|
9769
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, {}),
|
|
9770
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
9771
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
9772
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", children: "Save" })
|
|
9773
|
+
] }) })
|
|
9774
|
+
] }) });
|
|
9775
|
+
};
|
|
9776
|
+
const schema$4 = objectType({
|
|
9777
|
+
email: stringType().email()
|
|
9778
|
+
});
|
|
9781
9779
|
const Email = () => {
|
|
9782
9780
|
const { id } = useParams();
|
|
9783
9781
|
const { order, isPending, isError, error } = useOrder(id, {
|
|
@@ -10820,128 +10818,405 @@ const customItemSchema = objectType({
|
|
|
10820
10818
|
quantity: numberType(),
|
|
10821
10819
|
unit_price: unionType([numberType(), stringType()])
|
|
10822
10820
|
});
|
|
10823
|
-
const
|
|
10824
|
-
|
|
10825
|
-
|
|
10826
|
-
|
|
10827
|
-
|
|
10828
|
-
|
|
10829
|
-
|
|
10830
|
-
|
|
10831
|
-
|
|
10832
|
-
|
|
10833
|
-
|
|
10834
|
-
|
|
10835
|
-
|
|
10836
|
-
|
|
10837
|
-
|
|
10838
|
-
|
|
10839
|
-
|
|
10840
|
-
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
10841
|
-
"bg-ui-tag-orange-icon": variant === "warning"
|
|
10842
|
-
})
|
|
10843
|
-
}
|
|
10844
|
-
),
|
|
10845
|
-
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
10846
|
-
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
10847
|
-
labelValue,
|
|
10848
|
-
":"
|
|
10849
|
-
] }),
|
|
10850
|
-
" ",
|
|
10851
|
-
children
|
|
10852
|
-
] })
|
|
10853
|
-
]
|
|
10854
|
-
}
|
|
10855
|
-
);
|
|
10856
|
-
}
|
|
10857
|
-
);
|
|
10858
|
-
InlineTip.displayName = "InlineTip";
|
|
10859
|
-
const MetadataFieldSchema = objectType({
|
|
10860
|
-
key: stringType(),
|
|
10861
|
-
disabled: booleanType().optional(),
|
|
10862
|
-
value: anyType()
|
|
10863
|
-
});
|
|
10864
|
-
const MetadataSchema = objectType({
|
|
10865
|
-
metadata: arrayType(MetadataFieldSchema)
|
|
10866
|
-
});
|
|
10867
|
-
const Metadata = () => {
|
|
10868
|
-
const { id } = useParams();
|
|
10869
|
-
const { order, isPending, isError, error } = useOrder(id, {
|
|
10870
|
-
fields: "metadata"
|
|
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
|
|
10871
10838
|
});
|
|
10872
|
-
|
|
10873
|
-
|
|
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;
|
|
10874
10852
|
}
|
|
10875
|
-
const isReady =
|
|
10876
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
10877
|
-
/* @__PURE__ */
|
|
10878
|
-
|
|
10879
|
-
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
10880
|
-
] }),
|
|
10881
|
-
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
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 })
|
|
10882
10857
|
] });
|
|
10883
10858
|
};
|
|
10884
|
-
const
|
|
10885
|
-
const
|
|
10886
|
-
const
|
|
10859
|
+
const PromotionForm = ({ preview }) => {
|
|
10860
|
+
const { items, shipping_methods } = preview;
|
|
10861
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
10862
|
+
const [comboboxValue, setComboboxValue] = useState("");
|
|
10887
10863
|
const { handleSuccess } = useRouteModal();
|
|
10888
|
-
const
|
|
10889
|
-
const
|
|
10890
|
-
const
|
|
10891
|
-
|
|
10892
|
-
|
|
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
|
|
10893
10869
|
},
|
|
10894
|
-
|
|
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
|
+
}
|
|
10895
10890
|
});
|
|
10896
|
-
const
|
|
10897
|
-
|
|
10898
|
-
|
|
10891
|
+
const add = async (value) => {
|
|
10892
|
+
if (!value) {
|
|
10893
|
+
return;
|
|
10894
|
+
}
|
|
10895
|
+
addPromotions(
|
|
10899
10896
|
{
|
|
10900
|
-
|
|
10897
|
+
promo_codes: [value]
|
|
10901
10898
|
},
|
|
10902
10899
|
{
|
|
10903
|
-
|
|
10904
|
-
toast.
|
|
10905
|
-
|
|
10900
|
+
onError: (e) => {
|
|
10901
|
+
toast.error(e.message);
|
|
10902
|
+
comboboxData.onSearchValueChange("");
|
|
10903
|
+
setComboboxValue("");
|
|
10906
10904
|
},
|
|
10907
|
-
|
|
10908
|
-
|
|
10905
|
+
onSuccess: () => {
|
|
10906
|
+
comboboxData.onSearchValueChange("");
|
|
10907
|
+
setComboboxValue("");
|
|
10909
10908
|
}
|
|
10910
10909
|
}
|
|
10911
10910
|
);
|
|
10912
|
-
}
|
|
10913
|
-
const {
|
|
10914
|
-
|
|
10915
|
-
|
|
10916
|
-
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
|
|
10922
|
-
|
|
10923
|
-
|
|
10924
|
-
}
|
|
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;
|
|
10925
10928
|
}
|
|
10926
|
-
|
|
10927
|
-
|
|
10928
|
-
|
|
10929
|
-
|
|
10930
|
-
|
|
10931
|
-
|
|
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
|
+
}
|
|
10932
10939
|
});
|
|
10940
|
+
};
|
|
10941
|
+
if (isError) {
|
|
10942
|
+
throw error;
|
|
10933
10943
|
}
|
|
10934
|
-
return /* @__PURE__ */
|
|
10935
|
-
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10940
|
-
|
|
10941
|
-
|
|
10942
|
-
|
|
10943
|
-
|
|
10944
|
-
|
|
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
|
+
const InlineTip = forwardRef(
|
|
11099
|
+
({ variant = "tip", label, className, children, ...props }, ref) => {
|
|
11100
|
+
const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
|
|
11101
|
+
return /* @__PURE__ */ jsxs(
|
|
11102
|
+
"div",
|
|
11103
|
+
{
|
|
11104
|
+
ref,
|
|
11105
|
+
className: clx(
|
|
11106
|
+
"bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
|
|
11107
|
+
className
|
|
11108
|
+
),
|
|
11109
|
+
...props,
|
|
11110
|
+
children: [
|
|
11111
|
+
/* @__PURE__ */ jsx(
|
|
11112
|
+
"div",
|
|
11113
|
+
{
|
|
11114
|
+
role: "presentation",
|
|
11115
|
+
className: clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
|
|
11116
|
+
"bg-ui-tag-orange-icon": variant === "warning"
|
|
11117
|
+
})
|
|
11118
|
+
}
|
|
11119
|
+
),
|
|
11120
|
+
/* @__PURE__ */ jsxs("div", { className: "text-pretty", children: [
|
|
11121
|
+
/* @__PURE__ */ jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
|
|
11122
|
+
labelValue,
|
|
11123
|
+
":"
|
|
11124
|
+
] }),
|
|
11125
|
+
" ",
|
|
11126
|
+
children
|
|
11127
|
+
] })
|
|
11128
|
+
]
|
|
11129
|
+
}
|
|
11130
|
+
);
|
|
11131
|
+
}
|
|
11132
|
+
);
|
|
11133
|
+
InlineTip.displayName = "InlineTip";
|
|
11134
|
+
const MetadataFieldSchema = objectType({
|
|
11135
|
+
key: stringType(),
|
|
11136
|
+
disabled: booleanType().optional(),
|
|
11137
|
+
value: anyType()
|
|
11138
|
+
});
|
|
11139
|
+
const MetadataSchema = objectType({
|
|
11140
|
+
metadata: arrayType(MetadataFieldSchema)
|
|
11141
|
+
});
|
|
11142
|
+
const Metadata = () => {
|
|
11143
|
+
const { id } = useParams();
|
|
11144
|
+
const { order, isPending, isError, error } = useOrder(id, {
|
|
11145
|
+
fields: "metadata"
|
|
11146
|
+
});
|
|
11147
|
+
if (isError) {
|
|
11148
|
+
throw error;
|
|
11149
|
+
}
|
|
11150
|
+
const isReady = !isPending && !!order;
|
|
11151
|
+
return /* @__PURE__ */ jsxs(RouteDrawer, { children: [
|
|
11152
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Header, { children: [
|
|
11153
|
+
/* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Metadata" }) }),
|
|
11154
|
+
/* @__PURE__ */ jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
|
|
11155
|
+
] }),
|
|
11156
|
+
!isReady ? /* @__PURE__ */ jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
|
|
11157
|
+
] });
|
|
11158
|
+
};
|
|
11159
|
+
const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
|
|
11160
|
+
const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
|
|
11161
|
+
const MetadataForm = ({ orderId, metadata }) => {
|
|
11162
|
+
const { handleSuccess } = useRouteModal();
|
|
11163
|
+
const hasUneditableRows = getHasUneditableRows(metadata);
|
|
11164
|
+
const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
|
|
11165
|
+
const form = useForm({
|
|
11166
|
+
defaultValues: {
|
|
11167
|
+
metadata: getDefaultValues(metadata)
|
|
11168
|
+
},
|
|
11169
|
+
resolver: zodResolver(MetadataSchema)
|
|
11170
|
+
});
|
|
11171
|
+
const handleSubmit = form.handleSubmit(async (data) => {
|
|
11172
|
+
const parsedData = parseValues(data);
|
|
11173
|
+
await mutateAsync(
|
|
11174
|
+
{
|
|
11175
|
+
metadata: parsedData
|
|
11176
|
+
},
|
|
11177
|
+
{
|
|
11178
|
+
onSuccess: () => {
|
|
11179
|
+
toast.success("Metadata updated");
|
|
11180
|
+
handleSuccess();
|
|
11181
|
+
},
|
|
11182
|
+
onError: (error) => {
|
|
11183
|
+
toast.error(error.message);
|
|
11184
|
+
}
|
|
11185
|
+
}
|
|
11186
|
+
);
|
|
11187
|
+
});
|
|
11188
|
+
const { fields, insert, remove } = useFieldArray({
|
|
11189
|
+
control: form.control,
|
|
11190
|
+
name: "metadata"
|
|
11191
|
+
});
|
|
11192
|
+
function deleteRow(index) {
|
|
11193
|
+
remove(index);
|
|
11194
|
+
if (fields.length === 1) {
|
|
11195
|
+
insert(0, {
|
|
11196
|
+
key: "",
|
|
11197
|
+
value: "",
|
|
11198
|
+
disabled: false
|
|
11199
|
+
});
|
|
11200
|
+
}
|
|
11201
|
+
}
|
|
11202
|
+
function insertRow(index, position) {
|
|
11203
|
+
insert(index + (position === "above" ? 0 : 1), {
|
|
11204
|
+
key: "",
|
|
11205
|
+
value: "",
|
|
11206
|
+
disabled: false
|
|
11207
|
+
});
|
|
11208
|
+
}
|
|
11209
|
+
return /* @__PURE__ */ jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxs(
|
|
11210
|
+
KeyboundForm,
|
|
11211
|
+
{
|
|
11212
|
+
onSubmit: handleSubmit,
|
|
11213
|
+
className: "flex flex-1 flex-col overflow-hidden",
|
|
11214
|
+
children: [
|
|
11215
|
+
/* @__PURE__ */ jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
|
|
11216
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
|
|
11217
|
+
/* @__PURE__ */ jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
|
|
11218
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
|
|
11219
|
+
/* @__PURE__ */ jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
|
|
10945
11220
|
] }),
|
|
10946
11221
|
fields.map((field, index) => {
|
|
10947
11222
|
const isDisabled = field.disabled || false;
|
|
@@ -11046,406 +11321,129 @@ const MetadataForm = ({ orderId, metadata }) => {
|
|
|
11046
11321
|
/* @__PURE__ */ jsx(DropdownMenu.Separator, {}),
|
|
11047
11322
|
/* @__PURE__ */ jsxs(
|
|
11048
11323
|
DropdownMenu.Item,
|
|
11049
|
-
{
|
|
11050
|
-
className: "gap-x-2",
|
|
11051
|
-
onClick: () => deleteRow(index),
|
|
11052
|
-
children: [
|
|
11053
|
-
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11054
|
-
"Delete row"
|
|
11055
|
-
]
|
|
11056
|
-
}
|
|
11057
|
-
)
|
|
11058
|
-
] })
|
|
11059
|
-
] })
|
|
11060
|
-
] })
|
|
11061
|
-
},
|
|
11062
|
-
field.id
|
|
11063
|
-
);
|
|
11064
|
-
})
|
|
11065
|
-
] }),
|
|
11066
|
-
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
11067
|
-
] }),
|
|
11068
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11069
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11070
|
-
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11071
|
-
] }) })
|
|
11072
|
-
]
|
|
11073
|
-
}
|
|
11074
|
-
) });
|
|
11075
|
-
};
|
|
11076
|
-
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11077
|
-
return /* @__PURE__ */ jsx(
|
|
11078
|
-
"input",
|
|
11079
|
-
{
|
|
11080
|
-
ref,
|
|
11081
|
-
...props,
|
|
11082
|
-
autoComplete: "off",
|
|
11083
|
-
className: clx(
|
|
11084
|
-
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
11085
|
-
className
|
|
11086
|
-
)
|
|
11087
|
-
}
|
|
11088
|
-
);
|
|
11089
|
-
});
|
|
11090
|
-
GridInput.displayName = "MetadataForm.GridInput";
|
|
11091
|
-
const PlaceholderInner = () => {
|
|
11092
|
-
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11093
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11094
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11095
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11096
|
-
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11097
|
-
] }) })
|
|
11098
|
-
] });
|
|
11099
|
-
};
|
|
11100
|
-
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11101
|
-
function getDefaultValues(metadata) {
|
|
11102
|
-
if (!metadata || !Object.keys(metadata).length) {
|
|
11103
|
-
return [
|
|
11104
|
-
{
|
|
11105
|
-
key: "",
|
|
11106
|
-
value: "",
|
|
11107
|
-
disabled: false
|
|
11108
|
-
}
|
|
11109
|
-
];
|
|
11110
|
-
}
|
|
11111
|
-
return Object.entries(metadata).map(([key, value]) => {
|
|
11112
|
-
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11113
|
-
return {
|
|
11114
|
-
key,
|
|
11115
|
-
value,
|
|
11116
|
-
disabled: true
|
|
11117
|
-
};
|
|
11118
|
-
}
|
|
11119
|
-
let stringValue = value;
|
|
11120
|
-
if (typeof value !== "string") {
|
|
11121
|
-
stringValue = JSON.stringify(value);
|
|
11122
|
-
}
|
|
11123
|
-
return {
|
|
11124
|
-
key,
|
|
11125
|
-
value: stringValue,
|
|
11126
|
-
original_key: key
|
|
11127
|
-
};
|
|
11128
|
-
});
|
|
11129
|
-
}
|
|
11130
|
-
function parseValues(values) {
|
|
11131
|
-
const metadata = values.metadata;
|
|
11132
|
-
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11133
|
-
if (isEmpty) {
|
|
11134
|
-
return null;
|
|
11135
|
-
}
|
|
11136
|
-
const update = {};
|
|
11137
|
-
metadata.forEach((field) => {
|
|
11138
|
-
let key = field.key;
|
|
11139
|
-
let value = field.value;
|
|
11140
|
-
const disabled = field.disabled;
|
|
11141
|
-
if (!key || !value) {
|
|
11142
|
-
return;
|
|
11143
|
-
}
|
|
11144
|
-
if (disabled) {
|
|
11145
|
-
update[key] = value;
|
|
11146
|
-
return;
|
|
11147
|
-
}
|
|
11148
|
-
key = key.trim();
|
|
11149
|
-
value = value.trim();
|
|
11150
|
-
if (value === "true") {
|
|
11151
|
-
update[key] = true;
|
|
11152
|
-
} else if (value === "false") {
|
|
11153
|
-
update[key] = false;
|
|
11154
|
-
} else {
|
|
11155
|
-
const parsedNumber = parseFloat(value);
|
|
11156
|
-
if (!isNaN(parsedNumber)) {
|
|
11157
|
-
update[key] = parsedNumber;
|
|
11158
|
-
} else {
|
|
11159
|
-
update[key] = value;
|
|
11160
|
-
}
|
|
11161
|
-
}
|
|
11162
|
-
});
|
|
11163
|
-
return update;
|
|
11164
|
-
}
|
|
11165
|
-
function getHasUneditableRows(metadata) {
|
|
11166
|
-
if (!metadata) {
|
|
11167
|
-
return false;
|
|
11168
|
-
}
|
|
11169
|
-
return Object.values(metadata).some(
|
|
11170
|
-
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11171
|
-
);
|
|
11172
|
-
}
|
|
11173
|
-
const PROMOTION_QUERY_KEY = "promotions";
|
|
11174
|
-
const promotionsQueryKeys = {
|
|
11175
|
-
list: (query2) => [
|
|
11176
|
-
PROMOTION_QUERY_KEY,
|
|
11177
|
-
query2 ? query2 : void 0
|
|
11178
|
-
],
|
|
11179
|
-
detail: (id, query2) => [
|
|
11180
|
-
PROMOTION_QUERY_KEY,
|
|
11181
|
-
id,
|
|
11182
|
-
query2 ? query2 : void 0
|
|
11183
|
-
]
|
|
11184
|
-
};
|
|
11185
|
-
const usePromotions = (query2, options) => {
|
|
11186
|
-
const { data, ...rest } = useQuery({
|
|
11187
|
-
queryKey: promotionsQueryKeys.list(query2),
|
|
11188
|
-
queryFn: async () => sdk.admin.promotion.list(query2),
|
|
11189
|
-
...options
|
|
11190
|
-
});
|
|
11191
|
-
return { ...data, ...rest };
|
|
11192
|
-
};
|
|
11193
|
-
const Promotions = () => {
|
|
11194
|
-
const { id } = useParams();
|
|
11195
|
-
const {
|
|
11196
|
-
order: preview,
|
|
11197
|
-
isError: isPreviewError,
|
|
11198
|
-
error: previewError
|
|
11199
|
-
} = useOrderPreview(id, void 0);
|
|
11200
|
-
useInitiateOrderEdit({ preview });
|
|
11201
|
-
const { onCancel } = useCancelOrderEdit({ preview });
|
|
11202
|
-
if (isPreviewError) {
|
|
11203
|
-
throw previewError;
|
|
11204
|
-
}
|
|
11205
|
-
const isReady = !!preview;
|
|
11206
|
-
return /* @__PURE__ */ jsxs(RouteDrawer, { onClose: onCancel, children: [
|
|
11207
|
-
/* @__PURE__ */ jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsx(Heading, { children: "Edit Promotions" }) }) }),
|
|
11208
|
-
isReady && /* @__PURE__ */ jsx(PromotionForm, { preview })
|
|
11209
|
-
] });
|
|
11210
|
-
};
|
|
11211
|
-
const PromotionForm = ({ preview }) => {
|
|
11212
|
-
const { items, shipping_methods } = preview;
|
|
11213
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
11214
|
-
const [comboboxValue, setComboboxValue] = useState("");
|
|
11215
|
-
const { handleSuccess } = useRouteModal();
|
|
11216
|
-
const { mutateAsync: addPromotions, isPending: isAddingPromotions } = useDraftOrderAddPromotions(preview.id);
|
|
11217
|
-
const promoIds = getPromotionIds(items, shipping_methods);
|
|
11218
|
-
const { promotions, isPending, isError, error } = usePromotions(
|
|
11219
|
-
{
|
|
11220
|
-
id: promoIds
|
|
11221
|
-
},
|
|
11222
|
-
{
|
|
11223
|
-
enabled: !!promoIds.length
|
|
11224
|
-
}
|
|
11225
|
-
);
|
|
11226
|
-
const comboboxData = useComboboxData({
|
|
11227
|
-
queryKey: ["promotions", "combobox", promoIds],
|
|
11228
|
-
queryFn: async (params) => {
|
|
11229
|
-
return await sdk.admin.promotion.list({
|
|
11230
|
-
...params,
|
|
11231
|
-
id: {
|
|
11232
|
-
$nin: promoIds
|
|
11233
|
-
}
|
|
11234
|
-
});
|
|
11235
|
-
},
|
|
11236
|
-
getOptions: (data) => {
|
|
11237
|
-
return data.promotions.map((promotion) => ({
|
|
11238
|
-
label: promotion.code,
|
|
11239
|
-
value: promotion.code
|
|
11240
|
-
}));
|
|
11241
|
-
}
|
|
11242
|
-
});
|
|
11243
|
-
const add = async (value) => {
|
|
11244
|
-
if (!value) {
|
|
11245
|
-
return;
|
|
11246
|
-
}
|
|
11247
|
-
addPromotions(
|
|
11248
|
-
{
|
|
11249
|
-
promo_codes: [value]
|
|
11250
|
-
},
|
|
11251
|
-
{
|
|
11252
|
-
onError: (e) => {
|
|
11253
|
-
toast.error(e.message);
|
|
11254
|
-
comboboxData.onSearchValueChange("");
|
|
11255
|
-
setComboboxValue("");
|
|
11256
|
-
},
|
|
11257
|
-
onSuccess: () => {
|
|
11258
|
-
comboboxData.onSearchValueChange("");
|
|
11259
|
-
setComboboxValue("");
|
|
11260
|
-
}
|
|
11261
|
-
}
|
|
11262
|
-
);
|
|
11263
|
-
};
|
|
11264
|
-
const { mutateAsync: confirmOrderEdit } = useDraftOrderConfirmEdit(preview.id);
|
|
11265
|
-
const { mutateAsync: requestOrderEdit } = useOrderEditRequest(preview.id);
|
|
11266
|
-
const onSubmit = async () => {
|
|
11267
|
-
setIsSubmitting(true);
|
|
11268
|
-
let requestSucceeded = false;
|
|
11269
|
-
await requestOrderEdit(void 0, {
|
|
11270
|
-
onError: (e) => {
|
|
11271
|
-
toast.error(e.message);
|
|
11272
|
-
},
|
|
11273
|
-
onSuccess: () => {
|
|
11274
|
-
requestSucceeded = true;
|
|
11275
|
-
}
|
|
11276
|
-
});
|
|
11277
|
-
if (!requestSucceeded) {
|
|
11278
|
-
setIsSubmitting(false);
|
|
11279
|
-
return;
|
|
11280
|
-
}
|
|
11281
|
-
await confirmOrderEdit(void 0, {
|
|
11282
|
-
onError: (e) => {
|
|
11283
|
-
toast.error(e.message);
|
|
11284
|
-
},
|
|
11285
|
-
onSuccess: () => {
|
|
11286
|
-
handleSuccess();
|
|
11287
|
-
},
|
|
11288
|
-
onSettled: () => {
|
|
11289
|
-
setIsSubmitting(false);
|
|
11290
|
-
}
|
|
11291
|
-
});
|
|
11292
|
-
};
|
|
11293
|
-
if (isError) {
|
|
11294
|
-
throw error;
|
|
11295
|
-
}
|
|
11296
|
-
return /* @__PURE__ */ jsxs(KeyboundForm, { className: "flex flex-1 flex-col", onSubmit, children: [
|
|
11297
|
-
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-4", children: [
|
|
11298
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
11299
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
11300
|
-
/* @__PURE__ */ jsx(Label$1, { size: "small", weight: "plus", htmlFor: "promotion-combobox", children: "Apply promotions" }),
|
|
11301
|
-
/* @__PURE__ */ jsx(Hint$1, { id: "promotion-combobox-hint", children: "Manage promotions that should be applied to the order." })
|
|
11324
|
+
{
|
|
11325
|
+
className: "gap-x-2",
|
|
11326
|
+
onClick: () => deleteRow(index),
|
|
11327
|
+
children: [
|
|
11328
|
+
/* @__PURE__ */ jsx(Trash, { className: "text-ui-fg-subtle" }),
|
|
11329
|
+
"Delete row"
|
|
11330
|
+
]
|
|
11331
|
+
}
|
|
11332
|
+
)
|
|
11333
|
+
] })
|
|
11334
|
+
] })
|
|
11335
|
+
] })
|
|
11336
|
+
},
|
|
11337
|
+
field.id
|
|
11338
|
+
);
|
|
11339
|
+
})
|
|
11340
|
+
] }),
|
|
11341
|
+
hasUneditableRows && /* @__PURE__ */ jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
|
|
11302
11342
|
] }),
|
|
11303
|
-
/* @__PURE__ */ jsx(
|
|
11304
|
-
|
|
11305
|
-
{
|
|
11306
|
-
|
|
11307
|
-
|
|
11308
|
-
|
|
11309
|
-
|
|
11310
|
-
|
|
11311
|
-
|
|
11312
|
-
|
|
11313
|
-
|
|
11314
|
-
|
|
11315
|
-
|
|
11316
|
-
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
PromotionItem,
|
|
11322
|
-
{
|
|
11323
|
-
promotion,
|
|
11324
|
-
orderId: preview.id,
|
|
11325
|
-
isLoading: isPending
|
|
11326
|
-
},
|
|
11327
|
-
promotion.id
|
|
11328
|
-
)) })
|
|
11329
|
-
] }) }),
|
|
11330
|
-
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex justify-end gap-2", children: [
|
|
11331
|
-
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
|
|
11332
|
-
/* @__PURE__ */ jsx(
|
|
11333
|
-
Button,
|
|
11334
|
-
{
|
|
11335
|
-
size: "small",
|
|
11336
|
-
type: "submit",
|
|
11337
|
-
isLoading: isSubmitting || isAddingPromotions,
|
|
11338
|
-
children: "Save"
|
|
11339
|
-
}
|
|
11343
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11344
|
+
/* @__PURE__ */ jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
|
|
11345
|
+
/* @__PURE__ */ jsx(Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
|
|
11346
|
+
] }) })
|
|
11347
|
+
]
|
|
11348
|
+
}
|
|
11349
|
+
) });
|
|
11350
|
+
};
|
|
11351
|
+
const GridInput = forwardRef(({ className, ...props }, ref) => {
|
|
11352
|
+
return /* @__PURE__ */ jsx(
|
|
11353
|
+
"input",
|
|
11354
|
+
{
|
|
11355
|
+
ref,
|
|
11356
|
+
...props,
|
|
11357
|
+
autoComplete: "off",
|
|
11358
|
+
className: clx(
|
|
11359
|
+
"txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
|
|
11360
|
+
className
|
|
11340
11361
|
)
|
|
11362
|
+
}
|
|
11363
|
+
);
|
|
11364
|
+
});
|
|
11365
|
+
GridInput.displayName = "MetadataForm.GridInput";
|
|
11366
|
+
const PlaceholderInner = () => {
|
|
11367
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
|
|
11368
|
+
/* @__PURE__ */ jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsx(Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
|
|
11369
|
+
/* @__PURE__ */ jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
|
|
11370
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" }),
|
|
11371
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-7 w-12 rounded-md" })
|
|
11341
11372
|
] }) })
|
|
11342
11373
|
] });
|
|
11343
11374
|
};
|
|
11344
|
-
const
|
|
11345
|
-
|
|
11346
|
-
|
|
11347
|
-
|
|
11348
|
-
}) => {
|
|
11349
|
-
var _a;
|
|
11350
|
-
const { mutateAsync: removePromotions, isPending } = useDraftOrderRemovePromotions(orderId);
|
|
11351
|
-
const onRemove = async () => {
|
|
11352
|
-
removePromotions(
|
|
11353
|
-
{
|
|
11354
|
-
promo_codes: [promotion.code]
|
|
11355
|
-
},
|
|
11375
|
+
const EDITABLE_TYPES = ["string", "number", "boolean"];
|
|
11376
|
+
function getDefaultValues(metadata) {
|
|
11377
|
+
if (!metadata || !Object.keys(metadata).length) {
|
|
11378
|
+
return [
|
|
11356
11379
|
{
|
|
11357
|
-
|
|
11358
|
-
|
|
11359
|
-
|
|
11380
|
+
key: "",
|
|
11381
|
+
value: "",
|
|
11382
|
+
disabled: false
|
|
11360
11383
|
}
|
|
11361
|
-
|
|
11362
|
-
};
|
|
11363
|
-
const displayValue = getDisplayValue(promotion);
|
|
11364
|
-
return /* @__PURE__ */ jsxs(
|
|
11365
|
-
"div",
|
|
11366
|
-
{
|
|
11367
|
-
className: clx(
|
|
11368
|
-
"bg-ui-bg-component shadow-elevation-card-rest flex items-center justify-between rounded-lg px-3 py-2",
|
|
11369
|
-
{
|
|
11370
|
-
"animate-pulse": isLoading
|
|
11371
|
-
}
|
|
11372
|
-
),
|
|
11373
|
-
children: [
|
|
11374
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
11375
|
-
/* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", leading: "compact", children: promotion.code }),
|
|
11376
|
-
/* @__PURE__ */ jsxs("div", { className: "text-ui-fg-subtle flex items-center gap-1.5", children: [
|
|
11377
|
-
displayValue && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
|
|
11378
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: displayValue }),
|
|
11379
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", children: "·" })
|
|
11380
|
-
] }),
|
|
11381
|
-
/* @__PURE__ */ jsx(Text, { size: "small", leading: "compact", className: "capitalize", children: (_a = promotion.application_method) == null ? void 0 : _a.allocation })
|
|
11382
|
-
] })
|
|
11383
|
-
] }),
|
|
11384
|
-
/* @__PURE__ */ jsx(
|
|
11385
|
-
IconButton,
|
|
11386
|
-
{
|
|
11387
|
-
size: "small",
|
|
11388
|
-
type: "button",
|
|
11389
|
-
variant: "transparent",
|
|
11390
|
-
onClick: onRemove,
|
|
11391
|
-
isLoading: isPending || isLoading,
|
|
11392
|
-
children: /* @__PURE__ */ jsx(XMark, {})
|
|
11393
|
-
}
|
|
11394
|
-
)
|
|
11395
|
-
]
|
|
11396
|
-
},
|
|
11397
|
-
promotion.id
|
|
11398
|
-
);
|
|
11399
|
-
};
|
|
11400
|
-
function getDisplayValue(promotion) {
|
|
11401
|
-
var _a, _b, _c, _d;
|
|
11402
|
-
const value = (_a = promotion.application_method) == null ? void 0 : _a.value;
|
|
11403
|
-
if (!value) {
|
|
11404
|
-
return null;
|
|
11384
|
+
];
|
|
11405
11385
|
}
|
|
11406
|
-
|
|
11407
|
-
|
|
11408
|
-
|
|
11409
|
-
|
|
11386
|
+
return Object.entries(metadata).map(([key, value]) => {
|
|
11387
|
+
if (!EDITABLE_TYPES.includes(typeof value)) {
|
|
11388
|
+
return {
|
|
11389
|
+
key,
|
|
11390
|
+
value,
|
|
11391
|
+
disabled: true
|
|
11392
|
+
};
|
|
11410
11393
|
}
|
|
11411
|
-
|
|
11412
|
-
|
|
11413
|
-
|
|
11414
|
-
|
|
11415
|
-
|
|
11394
|
+
let stringValue = value;
|
|
11395
|
+
if (typeof value !== "string") {
|
|
11396
|
+
stringValue = JSON.stringify(value);
|
|
11397
|
+
}
|
|
11398
|
+
return {
|
|
11399
|
+
key,
|
|
11400
|
+
value: stringValue,
|
|
11401
|
+
original_key: key
|
|
11402
|
+
};
|
|
11403
|
+
});
|
|
11416
11404
|
}
|
|
11417
|
-
|
|
11418
|
-
|
|
11419
|
-
|
|
11420
|
-
|
|
11421
|
-
|
|
11422
|
-
let val = value || 0;
|
|
11423
|
-
if (!isPercentageValue) {
|
|
11424
|
-
val = val / 100;
|
|
11405
|
+
function parseValues(values) {
|
|
11406
|
+
const metadata = values.metadata;
|
|
11407
|
+
const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
|
|
11408
|
+
if (isEmpty) {
|
|
11409
|
+
return null;
|
|
11425
11410
|
}
|
|
11426
|
-
|
|
11427
|
-
|
|
11428
|
-
|
|
11429
|
-
|
|
11430
|
-
|
|
11431
|
-
if (
|
|
11432
|
-
|
|
11433
|
-
if (adjustment.promotion_id) {
|
|
11434
|
-
promotionIds.add(adjustment.promotion_id);
|
|
11435
|
-
}
|
|
11436
|
-
}
|
|
11411
|
+
const update = {};
|
|
11412
|
+
metadata.forEach((field) => {
|
|
11413
|
+
let key = field.key;
|
|
11414
|
+
let value = field.value;
|
|
11415
|
+
const disabled = field.disabled;
|
|
11416
|
+
if (!key || !value) {
|
|
11417
|
+
return;
|
|
11437
11418
|
}
|
|
11438
|
-
|
|
11439
|
-
|
|
11440
|
-
|
|
11441
|
-
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11419
|
+
if (disabled) {
|
|
11420
|
+
update[key] = value;
|
|
11421
|
+
return;
|
|
11422
|
+
}
|
|
11423
|
+
key = key.trim();
|
|
11424
|
+
value = value.trim();
|
|
11425
|
+
if (value === "true") {
|
|
11426
|
+
update[key] = true;
|
|
11427
|
+
} else if (value === "false") {
|
|
11428
|
+
update[key] = false;
|
|
11429
|
+
} else {
|
|
11430
|
+
const parsedNumber = parseFloat(value);
|
|
11431
|
+
if (!isNaN(parsedNumber)) {
|
|
11432
|
+
update[key] = parsedNumber;
|
|
11433
|
+
} else {
|
|
11434
|
+
update[key] = value;
|
|
11445
11435
|
}
|
|
11446
11436
|
}
|
|
11437
|
+
});
|
|
11438
|
+
return update;
|
|
11439
|
+
}
|
|
11440
|
+
function getHasUneditableRows(metadata) {
|
|
11441
|
+
if (!metadata) {
|
|
11442
|
+
return false;
|
|
11447
11443
|
}
|
|
11448
|
-
return
|
|
11444
|
+
return Object.values(metadata).some(
|
|
11445
|
+
(value) => !EDITABLE_TYPES.includes(typeof value)
|
|
11446
|
+
);
|
|
11449
11447
|
}
|
|
11450
11448
|
const SalesChannel = () => {
|
|
11451
11449
|
const { id } = useParams();
|
|
@@ -13059,14 +13057,14 @@ const routeModule = {
|
|
|
13059
13057
|
handle,
|
|
13060
13058
|
loader,
|
|
13061
13059
|
children: [
|
|
13062
|
-
{
|
|
13063
|
-
Component: CustomItems,
|
|
13064
|
-
path: "/draft-orders/:id/custom-items"
|
|
13065
|
-
},
|
|
13066
13060
|
{
|
|
13067
13061
|
Component: BillingAddress,
|
|
13068
13062
|
path: "/draft-orders/:id/billing-address"
|
|
13069
13063
|
},
|
|
13064
|
+
{
|
|
13065
|
+
Component: CustomItems,
|
|
13066
|
+
path: "/draft-orders/:id/custom-items"
|
|
13067
|
+
},
|
|
13070
13068
|
{
|
|
13071
13069
|
Component: Email,
|
|
13072
13070
|
path: "/draft-orders/:id/email"
|
|
@@ -13075,14 +13073,14 @@ const routeModule = {
|
|
|
13075
13073
|
Component: Items,
|
|
13076
13074
|
path: "/draft-orders/:id/items"
|
|
13077
13075
|
},
|
|
13078
|
-
{
|
|
13079
|
-
Component: Metadata,
|
|
13080
|
-
path: "/draft-orders/:id/metadata"
|
|
13081
|
-
},
|
|
13082
13076
|
{
|
|
13083
13077
|
Component: Promotions,
|
|
13084
13078
|
path: "/draft-orders/:id/promotions"
|
|
13085
13079
|
},
|
|
13080
|
+
{
|
|
13081
|
+
Component: Metadata,
|
|
13082
|
+
path: "/draft-orders/:id/metadata"
|
|
13083
|
+
},
|
|
13086
13084
|
{
|
|
13087
13085
|
Component: SalesChannel,
|
|
13088
13086
|
path: "/draft-orders/:id/sales-channel"
|