2022-03-22 15:22:20 +00:00
|
|
|
import { MembershipRole } from "@prisma/client";
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
import Link from "next/link";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import classNames from "@calcom/lib/classNames";
|
|
|
|
import { getPlaceholderAvatar } from "@calcom/lib/getPlaceholderAvatar";
|
2022-03-16 23:36:43 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { inferQueryOutput, trpc } from "@calcom/trpc/react";
|
2022-09-17 17:53:31 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-11-04 15:40:46 +00:00
|
|
|
import { Button } from "@calcom/ui/components/button";
|
|
|
|
import { ButtonGroup } from "@calcom/ui/components/buttonGroup";
|
2022-09-17 17:53:31 +00:00
|
|
|
import ConfirmationDialogContent from "@calcom/ui/v2/core/ConfirmationDialogContent";
|
|
|
|
import { Dialog, DialogTrigger } from "@calcom/ui/v2/core/Dialog";
|
2022-03-16 19:55:18 +00:00
|
|
|
import Dropdown, {
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuSeparator,
|
2022-05-14 18:47:23 +00:00
|
|
|
DropdownMenuTrigger,
|
2022-09-18 11:32:54 +00:00
|
|
|
DropdownItem,
|
2022-09-17 17:53:31 +00:00
|
|
|
} from "@calcom/ui/v2/core/Dropdown";
|
|
|
|
import { Tooltip } from "@calcom/ui/v2/core/Tooltip";
|
|
|
|
import showToast from "@calcom/ui/v2/core/notifications";
|
2022-03-16 19:55:18 +00:00
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
import Avatar from "@components/ui/Avatar";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-02-07 23:35:26 +00:00
|
|
|
import { TeamRole } from "./TeamPill";
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
interface Props {
|
|
|
|
team: inferQueryOutput<"viewer.teams.list">[number];
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
key: number;
|
|
|
|
onActionSelect: (text: string) => void;
|
2022-05-14 18:47:23 +00:00
|
|
|
isLoading?: boolean;
|
2022-07-31 19:48:17 +00:00
|
|
|
hideDropdown: boolean;
|
|
|
|
setHideDropdown: (value: boolean) => void;
|
2021-12-09 23:51:30 +00:00
|
|
|
}
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
export default function TeamListItem(props: Props) {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const utils = trpc.useContext();
|
|
|
|
const team = props.team;
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const acceptOrLeaveMutation = trpc.useMutation("viewer.teams.acceptOrLeave", {
|
|
|
|
onSuccess: () => {
|
|
|
|
utils.invalidateQueries(["viewer.teams.list"]);
|
|
|
|
},
|
|
|
|
});
|
2022-07-31 19:48:17 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
function acceptOrLeave(accept: boolean) {
|
|
|
|
acceptOrLeaveMutation.mutate({
|
|
|
|
teamId: team?.id as number,
|
|
|
|
accept,
|
2021-08-02 20:51:57 +00:00
|
|
|
});
|
2021-12-09 23:51:30 +00:00
|
|
|
}
|
2022-07-31 19:48:17 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const acceptInvite = () => acceptOrLeave(true);
|
|
|
|
const declineInvite = () => acceptOrLeave(false);
|
|
|
|
|
|
|
|
const isOwner = props.team.role === MembershipRole.OWNER;
|
|
|
|
const isInvitee = !props.team.accepted;
|
|
|
|
const isAdmin = props.team.role === MembershipRole.OWNER || props.team.role === MembershipRole.ADMIN;
|
2022-07-31 19:48:17 +00:00
|
|
|
const { hideDropdown, setHideDropdown } = props;
|
2021-12-09 23:51:30 +00:00
|
|
|
|
|
|
|
if (!team) return <></>;
|
|
|
|
|
|
|
|
const teamInfo = (
|
|
|
|
<div className="flex px-5 py-5">
|
|
|
|
<Avatar
|
|
|
|
size={9}
|
|
|
|
imageSrc={getPlaceholderAvatar(team?.logo, team?.name as string)}
|
|
|
|
alt="Team Logo"
|
2022-02-09 22:32:31 +00:00
|
|
|
className="min-h-9 min-w-9 h-9 w-9 rounded-full"
|
2021-12-09 23:51:30 +00:00
|
|
|
/>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="ml-3 inline-block">
|
2021-12-09 23:51:30 +00:00
|
|
|
<span className="text-sm font-bold text-neutral-700">{team.name}</span>
|
|
|
|
<span className="block text-xs text-gray-400">
|
2022-03-26 00:39:38 +00:00
|
|
|
{process.env.NEXT_PUBLIC_WEBSITE_URL}/team/{team.slug}
|
2021-12-09 23:51:30 +00:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2021-08-02 20:51:57 +00:00
|
|
|
return (
|
2021-12-09 23:51:30 +00:00
|
|
|
<li className="divide-y">
|
|
|
|
<div
|
|
|
|
className={classNames(
|
2022-02-09 00:05:13 +00:00
|
|
|
"flex items-center justify-between",
|
2021-12-09 23:51:30 +00:00
|
|
|
!isInvitee && "group hover:bg-neutral-50"
|
|
|
|
)}>
|
|
|
|
{!isInvitee ? (
|
2022-09-17 17:53:31 +00:00
|
|
|
<Link href={"/settings/teams/" + team.id + "/profile"}>
|
2022-02-09 00:05:13 +00:00
|
|
|
<a className="flex-grow cursor-pointer truncate text-sm" title={`${team.name}`}>
|
2021-12-09 23:51:30 +00:00
|
|
|
{teamInfo}
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
teamInfo
|
|
|
|
)}
|
|
|
|
<div className="px-5 py-5">
|
|
|
|
{isInvitee && (
|
|
|
|
<>
|
2022-07-01 18:29:59 +00:00
|
|
|
<div className="hidden sm:block">
|
|
|
|
<Button type="button" color="secondary" onClick={declineInvite}>
|
|
|
|
{t("reject")}
|
|
|
|
</Button>
|
|
|
|
<Button type="button" color="primary" className="ltr:ml-2 rtl:mr-2" onClick={acceptInvite}>
|
|
|
|
{t("accept")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<div className="block sm:hidden">
|
|
|
|
<Dropdown>
|
2022-07-27 02:24:00 +00:00
|
|
|
<DropdownMenuTrigger asChild>
|
2022-08-03 16:01:29 +00:00
|
|
|
<Button type="button" color="minimal" size="icon" StartIcon={Icon.FiMoreHorizontal} />
|
2022-07-01 18:29:59 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Button
|
|
|
|
color="minimal"
|
|
|
|
className="w-full rounded-none font-medium"
|
2022-08-03 16:01:29 +00:00
|
|
|
StartIcon={Icon.FiCheck}
|
2022-07-01 18:29:59 +00:00
|
|
|
onClick={acceptInvite}>
|
|
|
|
{t("accept")}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Button
|
2022-09-17 17:53:31 +00:00
|
|
|
color="destructive"
|
2022-07-01 18:29:59 +00:00
|
|
|
className="w-full rounded-none font-medium"
|
2022-08-03 16:01:29 +00:00
|
|
|
StartIcon={Icon.FiX}
|
2022-07-01 18:29:59 +00:00
|
|
|
onClick={declineInvite}>
|
|
|
|
{t("reject")}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
2021-12-09 23:51:30 +00:00
|
|
|
</>
|
2021-08-02 20:51:57 +00:00
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
{!isInvitee && (
|
2022-07-27 02:24:00 +00:00
|
|
|
<div className="flex space-x-2 rtl:space-x-reverse">
|
2022-02-07 23:35:26 +00:00
|
|
|
<TeamRole role={team.role} />
|
2022-09-18 11:32:54 +00:00
|
|
|
<ButtonGroup combined>
|
|
|
|
<Tooltip content={t("copy_link_team")}>
|
|
|
|
<Button
|
|
|
|
color="secondary"
|
|
|
|
onClick={() => {
|
|
|
|
navigator.clipboard.writeText(
|
|
|
|
process.env.NEXT_PUBLIC_WEBSITE_URL + "/team/" + team.slug
|
|
|
|
);
|
|
|
|
showToast(t("link_copied"), "success");
|
|
|
|
}}
|
|
|
|
size="icon"
|
|
|
|
StartIcon={Icon.FiLink}
|
|
|
|
combined
|
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
<Dropdown>
|
2022-10-20 11:35:12 +00:00
|
|
|
<DropdownMenuTrigger asChild className="radix-state-open:rounded-r-md">
|
2022-09-18 11:32:54 +00:00
|
|
|
<Button type="button" color="secondary" size="icon" StartIcon={Icon.FiMoreHorizontal} />
|
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent hidden={hideDropdown}>
|
|
|
|
{isAdmin && (
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<DropdownItem
|
|
|
|
type="button"
|
|
|
|
href={"/settings/teams/" + team.id + "/profile"}
|
|
|
|
StartIcon={Icon.FiEdit2}>
|
|
|
|
{t("edit_team") as string}
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
<DropdownMenuItem>
|
2022-09-18 11:32:54 +00:00
|
|
|
<DropdownItem
|
|
|
|
type="button"
|
|
|
|
target="_blank"
|
|
|
|
href={`${process.env.NEXT_PUBLIC_WEBSITE_URL}/team/${team.slug}`}
|
|
|
|
StartIcon={Icon.FiExternalLink}>
|
|
|
|
{t("preview_team") as string}
|
|
|
|
</DropdownItem>
|
2021-12-09 23:51:30 +00:00
|
|
|
</DropdownMenuItem>
|
2022-09-18 11:32:54 +00:00
|
|
|
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
|
|
|
{isOwner && (
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Dialog open={hideDropdown} onOpenChange={setHideDropdown}>
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<Button
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
color="destructive"
|
|
|
|
className="rounded-none px-3 font-normal"
|
|
|
|
StartIcon={Icon.FiTrash}>
|
|
|
|
{t("disband_team")}
|
|
|
|
</Button>
|
|
|
|
</DialogTrigger>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="danger"
|
|
|
|
title={t("disband_team")}
|
|
|
|
confirmBtnText={t("confirm_disband_team")}
|
|
|
|
isLoading={props.isLoading}
|
|
|
|
onConfirm={() => {
|
|
|
|
props.onActionSelect("disband");
|
2021-12-09 23:51:30 +00:00
|
|
|
}}>
|
2022-09-18 11:32:54 +00:00
|
|
|
{t("disband_team_confirmation_message")}
|
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{!isOwner && (
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Dialog>
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
color="destructive"
|
|
|
|
size="lg"
|
|
|
|
StartIcon={Icon.FiLogOut}
|
|
|
|
className="w-full rounded-none"
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}>
|
|
|
|
{t("leave_team")}
|
|
|
|
</Button>
|
|
|
|
</DialogTrigger>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="danger"
|
|
|
|
title={t("leave_team")}
|
|
|
|
confirmBtnText={t("confirm_leave_team")}
|
|
|
|
onConfirm={declineInvite}>
|
|
|
|
{t("leave_team_confirmation_message")}
|
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
)}
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
</ButtonGroup>
|
2021-08-02 20:51:57 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2021-06-05 22:53:33 +00:00
|
|
|
</div>
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
|
|
|
</li>
|
2021-08-02 20:51:57 +00:00
|
|
|
);
|
2021-07-30 23:05:38 +00:00
|
|
|
}
|