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";
|
2022-11-10 20:23:56 +00:00
|
|
|
import { useRouter } from "next/router";
|
2023-01-21 15:32:00 +00:00
|
|
|
import { useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2023-01-21 15:32:00 +00:00
|
|
|
import MemberInvitationModal from "@calcom/ee/teams/components/MemberInvitationModal";
|
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-11-10 23:40:01 +00:00
|
|
|
import { RouterOutputs, trpc } from "@calcom/trpc/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import {
|
|
|
|
Avatar,
|
|
|
|
Button,
|
|
|
|
ButtonGroup,
|
|
|
|
ConfirmationDialogContent,
|
|
|
|
Dialog,
|
|
|
|
DialogTrigger,
|
|
|
|
Dropdown,
|
2022-11-10 20:23:56 +00:00
|
|
|
DropdownItem,
|
2022-03-16 19:55:18 +00:00
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuSeparator,
|
2022-05-14 18:47:23 +00:00
|
|
|
DropdownMenuTrigger,
|
2022-11-23 02:55:25 +00:00
|
|
|
showToast,
|
|
|
|
Tooltip,
|
|
|
|
} from "@calcom/ui";
|
2023-01-23 23:08:01 +00:00
|
|
|
import {
|
|
|
|
FiMoreHorizontal,
|
|
|
|
FiCheck,
|
|
|
|
FiX,
|
|
|
|
FiLink,
|
|
|
|
FiEdit2,
|
|
|
|
FiExternalLink,
|
|
|
|
FiTrash,
|
|
|
|
FiLogOut,
|
|
|
|
FiGlobe,
|
|
|
|
FiSend,
|
|
|
|
} from "@calcom/ui/components/icon";
|
2022-03-16 19:55:18 +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 {
|
2022-11-10 23:40:01 +00:00
|
|
|
team: RouterOutputs["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) {
|
2023-01-21 15:32:00 +00:00
|
|
|
const { t, i18n } = useLocale();
|
2021-12-09 23:51:30 +00:00
|
|
|
const utils = trpc.useContext();
|
|
|
|
const team = props.team;
|
2023-01-21 15:32:00 +00:00
|
|
|
const [openMemberInvitationModal, setOpenMemberInvitationModal] = useState(false);
|
|
|
|
const teamQuery = trpc.viewer.teams.get.useQuery({ teamId: team?.id });
|
|
|
|
const inviteMemberMutation = trpc.viewer.teams.inviteMember.useMutation({
|
|
|
|
async onSuccess() {
|
|
|
|
await utils.viewer.teams.get.invalidate();
|
|
|
|
setOpenMemberInvitationModal(false);
|
|
|
|
},
|
|
|
|
onError: (error) => {
|
|
|
|
showToast(error.message, "error");
|
|
|
|
},
|
|
|
|
});
|
2021-06-05 22:53:33 +00:00
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const acceptOrLeaveMutation = trpc.viewer.teams.acceptOrLeave.useMutation({
|
2021-12-09 23:51:30 +00:00
|
|
|
onSuccess: () => {
|
2022-11-10 23:40:01 +00:00
|
|
|
utils.viewer.teams.list.invalidate();
|
2021-12-09 23:51:30 +00:00
|
|
|
},
|
|
|
|
});
|
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
|
2022-11-16 21:07:20 +00:00
|
|
|
size="sm"
|
2021-12-09 23:51:30 +00:00
|
|
|
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
|
|
|
/>
|
2023-01-04 07:38:45 +00:00
|
|
|
<div className="inline-block ltr:ml-3 rtl:mr-3">
|
2023-01-12 16:57:43 +00:00
|
|
|
<span className="text-sm font-bold text-gray-700">{team.name}</span>
|
2021-12-09 23:51:30 +00:00
|
|
|
<span className="block text-xs text-gray-400">
|
2022-11-10 20:23:56 +00:00
|
|
|
{team.slug ? `${process.env.NEXT_PUBLIC_WEBSITE_URL}/team/${team.slug}` : "Unpublished team"}
|
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">
|
2023-01-21 15:32:00 +00:00
|
|
|
<MemberInvitationModal
|
|
|
|
isOpen={openMemberInvitationModal}
|
|
|
|
onExit={() => {
|
|
|
|
setOpenMemberInvitationModal(false);
|
|
|
|
}}
|
|
|
|
onSubmit={(values) => {
|
|
|
|
inviteMemberMutation.mutate({
|
|
|
|
teamId: team.id,
|
|
|
|
language: i18n.language,
|
|
|
|
role: values.role,
|
|
|
|
usernameOrEmail: values.emailOrUsername,
|
|
|
|
sendEmailInvitation: values.sendInviteEmail,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
members={teamQuery?.data?.members || []}
|
|
|
|
/>
|
2021-12-09 23:51:30 +00:00
|
|
|
<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 ? (
|
2023-01-06 12:13:56 +00:00
|
|
|
<Link
|
|
|
|
href={"/settings/teams/" + team.id + "/profile"}
|
|
|
|
className="flex-grow cursor-pointer truncate text-sm"
|
|
|
|
title={`${team.name}`}>
|
|
|
|
{teamInfo}
|
2021-12-09 23:51:30 +00:00
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
teamInfo
|
|
|
|
)}
|
|
|
|
<div className="px-5 py-5">
|
2022-11-10 20:23:56 +00:00
|
|
|
{isInvitee ? (
|
2021-12-09 23:51:30 +00:00
|
|
|
<>
|
2022-07-01 18:29:59 +00:00
|
|
|
<div className="hidden sm:block">
|
|
|
|
<Button type="button" color="secondary" onClick={declineInvite}>
|
|
|
|
{t("reject")}
|
|
|
|
</Button>
|
2023-01-04 07:38:45 +00:00
|
|
|
<Button
|
|
|
|
type="button"
|
|
|
|
color="primary"
|
|
|
|
className="ltr:ml-2 ltr:mr-2 rtl:ml-2"
|
|
|
|
onClick={acceptInvite}>
|
2022-07-01 18:29:59 +00:00
|
|
|
{t("accept")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
<div className="block sm:hidden">
|
|
|
|
<Dropdown>
|
2022-07-27 02:24:00 +00:00
|
|
|
<DropdownMenuTrigger asChild>
|
2023-01-23 23:08:01 +00:00
|
|
|
<Button type="button" color="minimal" variant="icon" StartIcon={FiMoreHorizontal} />
|
2022-07-01 18:29:59 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem>
|
2023-01-23 23:08:01 +00:00
|
|
|
<DropdownItem type="button" StartIcon={FiCheck} onClick={acceptInvite}>
|
2022-07-01 18:29:59 +00:00
|
|
|
{t("accept")}
|
2023-01-15 11:40:40 +00:00
|
|
|
</DropdownItem>
|
2022-07-01 18:29:59 +00:00
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuItem>
|
2023-01-23 23:08:01 +00:00
|
|
|
<DropdownItem color="destructive" type="button" StartIcon={FiX} onClick={declineInvite}>
|
2022-07-01 18:29:59 +00:00
|
|
|
{t("reject")}
|
2023-01-15 11:40:40 +00:00
|
|
|
</DropdownItem>
|
2022-07-01 18:29:59 +00:00
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
2021-12-09 23:51:30 +00:00
|
|
|
</>
|
2022-11-10 20:23:56 +00:00
|
|
|
) : (
|
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>
|
2022-11-10 20:23:56 +00:00
|
|
|
{team.slug && (
|
|
|
|
<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");
|
|
|
|
}}
|
2023-01-19 14:55:32 +00:00
|
|
|
variant="icon"
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiLink}
|
2022-11-10 20:23:56 +00:00
|
|
|
/>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
2022-09-18 11:32:54 +00:00
|
|
|
<Dropdown>
|
2023-01-22 00:03:59 +00:00
|
|
|
<DropdownMenuTrigger asChild>
|
2023-01-19 14:55:32 +00:00
|
|
|
<Button
|
2023-01-22 00:03:59 +00:00
|
|
|
className="radix-state-open:rounded-r-md"
|
2023-01-19 14:55:32 +00:00
|
|
|
type="button"
|
|
|
|
color="secondary"
|
|
|
|
variant="icon"
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiMoreHorizontal}
|
2023-01-19 14:55:32 +00:00
|
|
|
/>
|
2022-09-18 11:32:54 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent hidden={hideDropdown}>
|
|
|
|
{isAdmin && (
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<DropdownItem
|
|
|
|
type="button"
|
|
|
|
href={"/settings/teams/" + team.id + "/profile"}
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiEdit2}>
|
2022-09-18 11:32:54 +00:00
|
|
|
{t("edit_team") as string}
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
)}
|
2022-11-10 20:23:56 +00:00
|
|
|
{!team.slug && <TeamPublishButton teamId={team.id} />}
|
|
|
|
{team.slug && (
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<DropdownItem
|
|
|
|
type="button"
|
|
|
|
target="_blank"
|
|
|
|
href={`${process.env.NEXT_PUBLIC_WEBSITE_URL}/team/${team.slug}`}
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiExternalLink}>
|
2022-11-10 20:23:56 +00:00
|
|
|
{t("preview_team") as string}
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
)}
|
2023-01-21 15:32:00 +00:00
|
|
|
<DropdownMenuItem>
|
|
|
|
<DropdownItem
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
setOpenMemberInvitationModal(true);
|
|
|
|
}}
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiSend}>
|
2023-01-21 15:32:00 +00:00
|
|
|
{t("invite_team_member") as string}
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenuItem>
|
2023-01-15 11:40:40 +00:00
|
|
|
<DropdownMenuSeparator />
|
2022-09-18 11:32:54 +00:00
|
|
|
{isOwner && (
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Dialog open={hideDropdown} onOpenChange={setHideDropdown}>
|
|
|
|
<DialogTrigger asChild>
|
2023-01-15 11:40:40 +00:00
|
|
|
<DropdownItem
|
|
|
|
color="destructive"
|
|
|
|
type="button"
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiTrash}
|
2022-09-18 11:32:54 +00:00
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
2023-01-15 11:40:40 +00:00
|
|
|
}}>
|
2022-09-18 11:32:54 +00:00
|
|
|
{t("disband_team")}
|
2023-01-15 11:40:40 +00:00
|
|
|
</DropdownItem>
|
2022-09-18 11:32:54 +00:00
|
|
|
</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"
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiLogOut}
|
2022-09-18 11:32:54 +00:00
|
|
|
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
|
|
|
}
|
2022-11-10 20:23:56 +00:00
|
|
|
|
|
|
|
const TeamPublishButton = ({ teamId }: { teamId: number }) => {
|
|
|
|
const { t } = useLocale();
|
|
|
|
const router = useRouter();
|
2022-11-10 23:40:01 +00:00
|
|
|
const publishTeamMutation = trpc.viewer.teams.publish.useMutation({
|
2022-11-10 20:23:56 +00:00
|
|
|
onSuccess(data) {
|
|
|
|
router.push(data.url);
|
|
|
|
},
|
|
|
|
onError: (error) => {
|
|
|
|
showToast(error.message, "error");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<DropdownItem
|
|
|
|
type="button"
|
|
|
|
onClick={() => {
|
|
|
|
publishTeamMutation.mutate({ teamId });
|
|
|
|
}}
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiGlobe}>
|
2022-11-10 20:23:56 +00:00
|
|
|
{t("team_publish")}
|
|
|
|
</DropdownItem>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
);
|
|
|
|
};
|