fix: copy to clipboard button (#17512)

* fixes copy to clipboard button

* fix type error
This commit is contained in:
sean-brydon
2024-11-06 15:11:55 +00:00
committed by GitHub
parent 3f7e632d5c
commit 4eefb08a0d
2 changed files with 24 additions and 4 deletions
@@ -18,8 +18,9 @@ import { InfiniteSkeletonLoader } from "@calcom/features/eventtypes/components/S
import { getTeamsFiltersFromQuery } from "@calcom/features/filters/lib/getTeamsFiltersFromQuery";
import Shell from "@calcom/features/shell/Shell";
import { parseEventTypeColor } from "@calcom/lib";
import { APP_NAME } from "@calcom/lib/constants";
import { APP_NAME, WEBSITE_URL } from "@calcom/lib/constants";
import { useCompatSearchParams } from "@calcom/lib/hooks/useCompatSearchParams";
import { useCopy } from "@calcom/lib/hooks/useCopy";
import { useDebounce } from "@calcom/lib/hooks/useDebounce";
import { useInViewObserver } from "@calcom/lib/hooks/useInViewObserver";
import { useLocale } from "@calcom/lib/hooks/useLocale";
@@ -257,6 +258,7 @@ export const InfiniteEventTypeList = ({
const router = useRouter();
const pathname = usePathname();
const searchParams = useCompatSearchParams();
const { copyToClipboard } = useCopy();
const [parent] = useAutoAnimate<HTMLUListElement>();
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [deleteDialogTypeId, setDeleteDialogTypeId] = useState(0);
@@ -566,7 +568,7 @@ export const InfiniteEventTypeList = ({
StartIcon="link"
onClick={() => {
showToast(t("link_copied"), "success");
navigator.clipboard.writeText(calLink);
copyToClipboard(calLink);
}}
/>
</Tooltip>
@@ -579,7 +581,7 @@ export const InfiniteEventTypeList = ({
StartIcon="venetian-mask"
onClick={() => {
showToast(t("private_link_copied"), "success");
navigator.clipboard.writeText(placeholderHashedLink);
copyToClipboard(placeholderHashedLink);
setPrivateLinkCopyIndices((prev) => {
const prevIndex = prev[type.slug] ?? 0;
prev[type.slug] = (prevIndex + 1) % type.hashedLink.length;
@@ -893,6 +895,7 @@ const InfiniteScrollMain = ({
}) => {
const searchParams = useCompatSearchParams();
const { data } = useTypedQuery(querySchema);
const orgBranding = useOrgBranding();
if (status === "error") {
return <Alert severity="error" title="Something went wrong" message={errorMessage} />;
@@ -911,6 +914,18 @@ const InfiniteScrollMain = ({
const activeEventTypeGroup =
eventTypeGroups.filter((item) => item.teamId === data.teamId) ?? eventTypeGroups[0];
const bookerUrl = orgBranding ? orgBranding?.fullDomain : WEBSITE_URL;
// If the event type group is the same as the org branding team, or the parent team, set the bookerUrl to the org branding URL
// This is to ensure that the bookerUrl is always the same as the one in the org branding settings
// This keeps the app working for personal event types that were not migrated to the org (rare)
if (
activeEventTypeGroup[0].teamId === orgBranding?.id ||
activeEventTypeGroup[0].parentId === orgBranding?.id
) {
activeEventTypeGroup[0].bookerUrl = bookerUrl;
}
return (
<>
{eventTypeGroups.length >= 1 && (
@@ -10,6 +10,7 @@ import type { NextRouter as NextPageRouter } from "next/router";
import { useEffect, useRef, useState } from "react";
import { z } from "zod";
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
import type { ChildrenEventType } from "@calcom/features/eventtypes/components/ChildrenEventTypeSelect";
import { EventType as EventTypeComponent } from "@calcom/features/eventtypes/components/EventType";
import type { EventTypeSetupProps } from "@calcom/features/eventtypes/lib/types";
@@ -224,9 +225,13 @@ const EventTypeWeb = ({
},
});
const permalink = `${WEBSITE_URL}/${team ? `team/${team.slug}` : eventType.users[0].username}/${
const orgBranding = useOrgBranding();
const bookerUrl = orgBranding ? orgBranding?.fullDomain : WEBSITE_URL;
const permalink = `${bookerUrl}/${team ? `team/${team.slug}` : eventType.users[0].username}/${
eventType.slug
}`;
const tabMap = {
setup: (
<EventSetupTab