diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.json index ae45e293d2..fd4d178818 100644 --- a/apps/web/public/static/locales/en/common.json +++ b/apps/web/public/static/locales/en/common.json @@ -683,6 +683,7 @@ "user_from_team": "{{user}} from {{team}}", "preview": "Preview", "link_copied": "Link copied!", + "copied": "Copied!", "private_link_copied": "Private link copied!", "link_shared": "Link shared!", "title": "Title", diff --git a/packages/features/users/components/UserTable/UserListTable.tsx b/packages/features/users/components/UserTable/UserListTable.tsx index a389d0d0ed..2fdafcc6b4 100644 --- a/packages/features/users/components/UserTable/UserListTable.tsx +++ b/packages/features/users/components/UserTable/UserListTable.tsx @@ -1,10 +1,12 @@ import { keepPreviousData } from "@tanstack/react-query"; -import type { ColumnDef } from "@tanstack/react-table"; +import type { ColumnDef, Table } from "@tanstack/react-table"; +import { m } from "framer-motion"; import { useSession } from "next-auth/react"; import { useCallback, useEffect, useMemo, useReducer, useRef, useState } from "react"; import { WEBAPP_URL } from "@calcom/lib/constants"; import { getUserAvatarUrl } from "@calcom/lib/getAvatarUrl"; +import { useCopy } from "@calcom/lib/hooks/useCopy"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import type { MembershipRole } from "@calcom/prisma/enums"; import { trpc } from "@calcom/trpc"; @@ -110,6 +112,7 @@ function reducer(state: State, action: Action): State { export function UserListTable() { const { data: session } = useSession(); + const { copyToClipboard, isCopied } = useCopy(); const { data: org } = trpc.viewer.organizations.listCurrent.useQuery(); const { data: teams } = trpc.viewer.organizations.getTeams.useQuery(); const tableContainerRef = useRef(null); @@ -117,6 +120,7 @@ export function UserListTable() { const { t } = useLocale(); const orgBranding = useOrgBranding(); const [debouncedSearchTerm, setDebouncedSearchTerm] = useState(""); + const [dynamicLinkVisible, setDynamicLinkVisible] = useState(false); const { data, isPending, fetchNextPage, isFetching } = trpc.viewer.organizations.listMembers.useInfiniteQuery( { @@ -325,6 +329,15 @@ export function UserListTable() { type: "render", render: (table) => , }, + { + type: "action", + icon: "handshake", + label: "Group Meeting", + needsXSelected: 2, + onClick: () => { + setDynamicLinkVisible((old) => !old); + }, + }, { type: "render", render: (table) => ( @@ -335,6 +348,50 @@ export function UserListTable() { ), }, ]} + renderAboveSelection={(table: Table) => { + const numberOfSelectedRows = table.getSelectedRowModel().rows.length; + const isVisible = numberOfSelectedRows >= 2 && dynamicLinkVisible; + + const users = table + .getSelectedRowModel() + .flatRows.map((row) => row.original.username) + .filter((u) => u !== null); + + const usersNameAsString = users.join("+"); + + const dynamicLinkOfSelectedUsers = `${domain}/${usersNameAsString}`; + const domainWithoutHttps = dynamicLinkOfSelectedUsers.replace(/https?:\/\//g, ""); + + return ( + <> + {isVisible ? ( + +
+

{domainWithoutHttps}

+
+
+ + +
+
+ ) : null} + + ); + }} tableContainerRef={tableContainerRef} tableCTA={ adminOrOwner && ( diff --git a/packages/ui/components/data-table/DataTableSelectionBar.tsx b/packages/ui/components/data-table/DataTableSelectionBar.tsx index ec2319ac2f..28a57a4664 100644 --- a/packages/ui/components/data-table/DataTableSelectionBar.tsx +++ b/packages/ui/components/data-table/DataTableSelectionBar.tsx @@ -1,5 +1,6 @@ import type { Table } from "@tanstack/react-table"; -import { AnimatePresence, motion } from "framer-motion"; +import type { Table as TableType } from "@tanstack/table-core/build/lib/types"; +import { AnimatePresence } from "framer-motion"; import { Fragment } from "react"; import type { IconName } from "../.."; @@ -11,42 +12,58 @@ export type ActionItem = label: string; onClick: () => void; icon?: IconName; + needsXSelected?: number; } | { type: "render"; render: (table: Table) => React.ReactNode; + needsXSelected?: number; }; interface DataTableSelectionBarProps { table: Table; actions?: ActionItem[]; + renderAboveSelection?: (table: TableType) => React.ReactNode; } -export function DataTableSelectionBar({ table, actions }: DataTableSelectionBarProps) { +export function DataTableSelectionBar({ + table, + actions, + renderAboveSelection, +}: DataTableSelectionBarProps) { const numberOfSelectedRows = table.getSelectedRowModel().rows.length; const isVisible = numberOfSelectedRows > 0; + // Hacky left % to center + const actionsVisible = actions?.filter((a) => { + if (!a.needsXSelected) return true; + return a.needsXSelected <= numberOfSelectedRows; + }); + return ( {isVisible ? ( - -
{numberOfSelectedRows} selected
- {actions?.map((action, index) => ( - - {action.type === "action" ? ( - - ) : action.type === "render" ? ( - action.render(table) - ) : null} - - ))} -
+
+ {renderAboveSelection && renderAboveSelection(table)} +
+

+ {numberOfSelectedRows} selected +

+ {actionsVisible?.map((action, index) => { + return ( + + {action.type === "action" ? ( + + ) : action.type === "render" ? ( + action.render(table) + ) : null} + + ); + })} +
+
) : null}
); diff --git a/packages/ui/components/data-table/DataTableToolbar.tsx b/packages/ui/components/data-table/DataTableToolbar.tsx index ac05d8f75a..ab0803619a 100644 --- a/packages/ui/components/data-table/DataTableToolbar.tsx +++ b/packages/ui/components/data-table/DataTableToolbar.tsx @@ -49,7 +49,7 @@ export function DataTableToolbar({ const { t } = useLocale(); return ( -
+
{searchKey && ( { onSearch?: (value: string) => void; filterableItems?: FilterableItems; selectionOptions?: ActionItem[]; + renderAboveSelection?: (table: TableType) => React.ReactNode; tableCTA?: React.ReactNode; isPending?: boolean; onRowMouseclick?: (row: Row) => void; @@ -54,6 +56,7 @@ export function DataTable({ isPending, tableOverlay, variant, + renderAboveSelection, /** This should only really be used if you dont have actions in a row. */ onSearch, onRowMouseclick, @@ -101,7 +104,7 @@ export function DataTable({ virtualRows.length > 0 ? totalSize - (virtualRows?.[virtualRows.length - 1]?.end || 0) : 0; return ( -
+
({
{/* */} - +
); }