fix: async clipboard support in Safari (#16619)

This commit is contained in:
Omar López authored and GitHub committed 2024-09-13 09:27:28 +01:00
1 parent 111e2f30c6
commit fcb79888f3
2 files changed
+46 -11

No files matched your search

+13 -10
View File
@@ -929,7 +929,7 @@ function SideBarContainer({ bannersHeight, isPlatformUser = false }: SideBarCont
}
function SideBar({ bannersHeight, user }: SideBarProps) {
const { copyToClipboard } = useCopy();
const { fetchAndCopyToClipboard } = useCopy();
const { t, isLocaleReady } = useLocale();
const orgBranding = useOrgBranding();
const pathname = usePathname();
@@ -967,16 +967,19 @@ function SideBar({ bannersHeight, user }: SideBarProps) {
? {
name: "copy_referral_link",
href: "",
onClick: async (e: { preventDefault: () => void }) => {
onClick: (e: { preventDefault: () => void }) => {
e.preventDefault();
const res = await fetch("/api/generate-referral-link", {
method: "POST",
});
const { shortLink } = await res.json();
copyToClipboard(shortLink, {
onSuccess: () => showToast(t("link_copied"), "success"),
onFailure: () => showToast("Copy to clipboard failed", "error"),
});
fetchAndCopyToClipboard(
fetch("/api/generate-referral-link", {
method: "POST",
})
.then((res) => res.json())
.then((res) => res.shortLink),
{
onSuccess: () => showToast(t("link_copied"), "success"),
onFailure: () => showToast("Copy to clipboard failed", "error"),
}
);
},
icon: "gift",
}