fix: Show toast after copy referral link + change icon to "gift" (#16618)

Co-authored-by: zomars <[email protected]>
This commit is contained in:
Steven Teyandzomars authored and GitHub committed 2024-09-12 22:06:21 +00:00
1 parent d9133cb395
commit f2b3e620b4
9 files changed
+41 -17

No files matched your search

+7 -8
View File
@@ -55,7 +55,7 @@ import getBrandColours from "@calcom/lib/getBrandColours";
import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl";
import { useCopy } from "@calcom/lib/hooks/useCopy";
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { useNotifications, ButtonState } from "@calcom/lib/hooks/useNotifications";
import { ButtonState, useNotifications } from "@calcom/lib/hooks/useNotifications";
import useTheme from "@calcom/lib/hooks/useTheme";
import { isKeyInObject } from "@calcom/lib/isKeyInObject";
import { localStorage } from "@calcom/lib/webstorage";
@@ -929,7 +929,7 @@ function SideBarContainer({ bannersHeight, isPlatformUser = false }: SideBarCont
}
function SideBar({ bannersHeight, user }: SideBarProps) {
const { isCopied, copyToClipboard, resetCopyStatus } = useCopy();
const { copyToClipboard } = useCopy();
const { t, isLocaleReady } = useLocale();
const orgBranding = useOrgBranding();
const pathname = usePathname();
@@ -973,13 +973,12 @@ function SideBar({ bannersHeight, user }: SideBarProps) {
method: "POST",
});
const { shortLink } = await res.json();
copyToClipboard(shortLink);
if (isCopied) {
showToast(t("link_copied"), "success");
}
copyToClipboard(shortLink, {
onSuccess: () => showToast(t("link_copied"), "success"),
onFailure: () => showToast("Copy to clipboard failed", "error"),
});
},
icon: "copy",
icon: "gift",
}
: null,
{
+17 -4
View File
@@ -1,14 +1,27 @@
import { useState, useEffect } from "react";
import { useEffect, useState } from "react";
export function useCopy() {
const [isCopied, setIsCopied] = useState(false);
const copyToClipboard = (text: string) => {
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};
const copyToClipboard = (
text: string,
options: { onSuccess?: () => void; onFailure?: () => void } = {}
) => {
const { onSuccess = noop, onFailure = noop } = options;
if (typeof navigator !== "undefined" && navigator.clipboard) {
navigator.clipboard
.writeText(text)
.then(() => setIsCopied(true))
.catch((error) => console.error("Copy to clipboard failed:", error));
.then(() => {
setIsCopied(true);
onSuccess();
})
.catch((error) => {
onFailure();
console.error("Copy to clipboard failed:", error);
});
} else {
console.warn(
"You need to use a secure context to use clipboard \n Please use the following link: ",
+5 -2
View File
@@ -1,10 +1,13 @@
import * as React from "react";
import SVG from "react-inlinesvg";
// eslint-disable-next-line turbo/no-undeclared-env-vars
const vercelCommitHash = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA;
const commitHash = vercelCommitHash ? `-${vercelCommitHash.slice(0, 7)}` : "";
export function IconSprites() {
return (
<SVG
src={`${process.env.NEXT_PUBLIC_WEBAPP_URL}/icons/sprite.svg?v=${process.env.NEXT_PUBLIC_CALCOM_VERSION}`}
src={`${process.env.NEXT_PUBLIC_WEBAPP_URL}/icons/sprite.svg?v=${process.env.NEXT_PUBLIC_CALCOM_VERSION}-${commitHash}`}
/>
);
}
@@ -67,6 +67,7 @@ export const lucideIconList = new Set([
"fingerprint",
"flag",
"folder",
"gift",
"git-merge",
"github",
"globe",
@@ -67,6 +67,7 @@ export type IconName =
| "fingerprint"
| "flag"
| "folder"
| "gift"
| "git-merge"
| "github"
| "globe"