* Icon and IconName * Button and ButtonGroup * UserAvatar * AvatarGroup * Avatar * WizardLayout * Dialogs * EmptyScreen * showToast and TextField * Editor * Skeleton * Skeleton * TopBanner and showToast * Button again * more * perf: Remove app-store reference from @calcom/ui * more * Fixing types * Icon * Fixed casing * dropdown * more * Select * more * Badge * List * more * Divider * more * fix * fix type check * refactor * fix * fix * fix * fix * fix * fix * fix * fix type check * fix * fix * fix * fix * more * more * more * more * add index file to components/command * fix * fix * fix * fix imports * fix * fix * fix * fix * fix * fix * fix * fix build errors * fix build errors * fix --------- Co-authored-by: Keith Williams <keithwillcode@gmail.com>
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import type { Table } from "@tanstack/react-table";
|
|
import { useQueryState, parseAsBoolean } from "nuqs";
|
|
|
|
import { useCopy } from "@calcom/lib/hooks/useCopy";
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
import { Button } from "@calcom/ui/components/button";
|
|
|
|
export function DynamicLink<T extends { username: string | null }>({
|
|
table,
|
|
domain,
|
|
}: {
|
|
table: Table<T>;
|
|
domain: string;
|
|
}) {
|
|
const { t } = useLocale();
|
|
const [dynamicLinkVisible, _] = useQueryState("dynamicLink", parseAsBoolean);
|
|
const { copyToClipboard, isCopied } = useCopy();
|
|
const numberOfSelectedRows = table.getSelectedRowModel().rows.length;
|
|
const isVisible = numberOfSelectedRows >= 2 && dynamicLinkVisible;
|
|
|
|
const users = table
|
|
.getSelectedRowModel()
|
|
.flatRows.map((row) => row.original.username)
|
|
.filter((u): u is string => u !== null);
|
|
|
|
const usersNameAsString = users.join("+");
|
|
|
|
const dynamicLinkOfSelectedUsers = `${domain}/${usersNameAsString}`;
|
|
const domainWithoutHttps = dynamicLinkOfSelectedUsers.replace(/https?:\/\//g, "");
|
|
|
|
return (
|
|
<>
|
|
{isVisible ? (
|
|
<div className="w-full gap-1 rounded-lg text-sm font-medium leading-none md:flex">
|
|
<div className="items-center truncate p-2 md:max-w-[300px]">
|
|
<p className="text-center md:text-left">{domainWithoutHttps}</p>
|
|
</div>
|
|
<div className="ml-auto flex items-center justify-center gap-1 md:justify-start">
|
|
<Button
|
|
variant="icon"
|
|
StartIcon={isCopied ? "check" : "copy"}
|
|
size="sm"
|
|
onClick={() => copyToClipboard(dynamicLinkOfSelectedUsers)}
|
|
color="secondary">
|
|
<span className="sr-only">{!isCopied ? t("copy") : t("copied")}</span>
|
|
</Button>
|
|
<Button
|
|
color="secondary"
|
|
EndIcon="external-link"
|
|
size="sm"
|
|
href={dynamicLinkOfSelectedUsers}
|
|
target="_blank"
|
|
rel="noopener noreferrer">
|
|
Open
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
) : null}
|
|
</>
|
|
);
|
|
}
|