2023-03-10 22:10:56 +00:00
|
|
|
import type { MembershipRole } from "@prisma/client";
|
2022-09-12 22:04:33 +00:00
|
|
|
|
|
|
|
import classNames from "@calcom/lib/classNames";
|
2023-03-10 22:10:56 +00:00
|
|
|
import { getPlaceholderAvatar } from "@calcom/lib/defaultAvatarImage";
|
2022-09-12 22:04:33 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
|
|
|
Avatar,
|
|
|
|
Button,
|
|
|
|
Dropdown,
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
2023-01-15 11:40:40 +00:00
|
|
|
DropdownItem,
|
2022-11-23 02:55:25 +00:00
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "@calcom/ui";
|
2023-04-12 15:26:31 +00:00
|
|
|
import { Slash, Check, MoreHorizontal, X } from "@calcom/ui/components/icon";
|
2022-09-12 22:04:33 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
team: {
|
|
|
|
id?: number;
|
|
|
|
name?: string | null;
|
|
|
|
slug?: string | null;
|
|
|
|
logo?: string | null;
|
|
|
|
bio?: string | null;
|
|
|
|
hideBranding?: boolean | undefined;
|
|
|
|
role: MembershipRole;
|
|
|
|
accepted: boolean;
|
|
|
|
};
|
|
|
|
key: number;
|
|
|
|
onActionSelect: (text: string) => void;
|
|
|
|
isLoading?: boolean;
|
|
|
|
hideDropdown: boolean;
|
|
|
|
setHideDropdown: (value: boolean) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function TeamInviteListItem(props: Props) {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const team = props.team;
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const acceptOrLeaveMutation = trpc.viewer.teams.acceptOrLeave.useMutation({
|
2022-09-12 22:04:33 +00:00
|
|
|
onSuccess: async () => {
|
2022-11-10 23:40:01 +00:00
|
|
|
await utils.viewer.teams.get.invalidate();
|
|
|
|
await utils.viewer.teams.list.invalidate();
|
2022-09-12 22:04:33 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
function acceptOrLeave(accept: boolean) {
|
|
|
|
acceptOrLeaveMutation.mutate({
|
|
|
|
teamId: team?.id as number,
|
|
|
|
accept,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const acceptInvite = () => acceptOrLeave(true);
|
|
|
|
const declineInvite = () => acceptOrLeave(false);
|
|
|
|
|
|
|
|
const isInvitee = !props.team.accepted;
|
|
|
|
|
|
|
|
if (!team) return <></>;
|
|
|
|
|
|
|
|
const teamInfo = (
|
|
|
|
<div className="flex">
|
|
|
|
<Avatar
|
|
|
|
size="mdLg"
|
|
|
|
imageSrc={getPlaceholderAvatar(team?.logo, team?.name as string)}
|
|
|
|
alt="Team Logo"
|
|
|
|
className=""
|
|
|
|
/>
|
2023-04-09 09:13:57 +00:00
|
|
|
<div className="ms-3 inline-block">
|
2023-04-05 18:14:46 +00:00
|
|
|
<span className="text-emphasis text-sm font-semibold">{team.name}</span>
|
|
|
|
<span className="text-default block text-sm leading-5">
|
2022-09-12 22:04:33 +00:00
|
|
|
{t("invited_by_team", { teamName: team.name, role: t(team.role.toLocaleLowerCase()) })}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2023-04-11 12:15:10 +00:00
|
|
|
<li className="bg-subtle border-emphasis divide-subtle divide-y rounded-md border px-5 py-4">
|
2022-09-12 22:04:33 +00:00
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
"flex items-center justify-between",
|
|
|
|
!isInvitee && "group hover:bg-neutral-50"
|
|
|
|
)}>
|
|
|
|
{teamInfo}
|
|
|
|
<div>
|
|
|
|
<>
|
|
|
|
<div className="hidden sm:flex">
|
|
|
|
<Button
|
|
|
|
type="button"
|
2023-04-09 09:13:57 +00:00
|
|
|
className="border-empthasis mr-3"
|
2023-01-19 14:55:32 +00:00
|
|
|
variant="icon"
|
2022-09-12 22:04:33 +00:00
|
|
|
color="secondary"
|
|
|
|
onClick={declineInvite}
|
2023-04-12 15:26:31 +00:00
|
|
|
StartIcon={Slash}
|
2022-09-12 22:04:33 +00:00
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
type="button"
|
2023-04-05 18:14:46 +00:00
|
|
|
className="border-empthasis"
|
2023-01-19 14:55:32 +00:00
|
|
|
variant="icon"
|
2022-09-12 22:04:33 +00:00
|
|
|
color="secondary"
|
|
|
|
onClick={acceptInvite}
|
2023-04-12 15:26:31 +00:00
|
|
|
StartIcon={Check}
|
2022-09-12 22:04:33 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="block sm:hidden">
|
|
|
|
<Dropdown>
|
|
|
|
<DropdownMenuTrigger asChild>
|
2023-04-12 15:26:31 +00:00
|
|
|
<Button type="button" color="minimal" variant="icon" StartIcon={MoreHorizontal} />
|
2022-09-12 22:04:33 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem>
|
2023-04-12 15:26:31 +00:00
|
|
|
<DropdownItem type="button" StartIcon={Check} onClick={acceptInvite}>
|
2022-09-12 22:04:33 +00:00
|
|
|
{t("accept")}
|
2023-01-15 11:40:40 +00:00
|
|
|
</DropdownItem>
|
2022-09-12 22:04:33 +00:00
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuItem>
|
2023-04-12 15:26:31 +00:00
|
|
|
<DropdownItem color="destructive" type="button" StartIcon={X} onClick={declineInvite}>
|
2022-09-12 22:04:33 +00:00
|
|
|
{t("reject")}
|
2023-01-15 11:40:40 +00:00
|
|
|
</DropdownItem>
|
2022-09-12 22:04:33 +00:00
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|