2022-03-22 15:22:20 +00:00
|
|
|
import { MembershipRole } from "@prisma/client";
|
2022-07-21 17:02:20 +00:00
|
|
|
import { signIn } from "next-auth/react";
|
2021-12-09 23:51:30 +00:00
|
|
|
import Link from "next/link";
|
2022-05-04 21:06:41 +00:00
|
|
|
import { useState } from "react";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-07-28 19:58:26 +00:00
|
|
|
import TeamAvailabilityModal from "@calcom/features/ee/teams/components/TeamAvailabilityModal";
|
2022-05-30 07:57:48 +00:00
|
|
|
import { WEBAPP_URL } from "@calcom/lib/constants";
|
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-03-16 23:36:43 +00:00
|
|
|
import Button from "@calcom/ui/Button";
|
2022-07-28 19:58:26 +00:00
|
|
|
import ConfirmationDialogContent from "@calcom/ui/ConfirmationDialogContent";
|
2022-03-16 23:36:43 +00:00
|
|
|
import { Dialog, DialogTrigger } from "@calcom/ui/Dialog";
|
2022-03-16 19:55:18 +00:00
|
|
|
import Dropdown, {
|
|
|
|
DropdownMenuContent,
|
|
|
|
DropdownMenuItem,
|
|
|
|
DropdownMenuSeparator,
|
|
|
|
DropdownMenuTrigger,
|
|
|
|
} from "@calcom/ui/Dropdown";
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-05-05 21:16:25 +00:00
|
|
|
import { Tooltip } from "@calcom/ui/Tooltip";
|
2022-10-21 08:54:18 +00:00
|
|
|
import showToast from "@calcom/ui/v2/core/notifications";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
2022-05-04 21:06:41 +00:00
|
|
|
import useCurrentUserId from "@lib/hooks/useCurrentUserId";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-09-14 08:45:28 +00:00
|
|
|
import Avatar from "@components/ui/Avatar";
|
2021-12-09 23:51:30 +00:00
|
|
|
import ModalContainer from "@components/ui/ModalContainer";
|
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
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
import MemberChangeRoleModal from "./MemberChangeRoleModal";
|
2022-02-07 23:35:26 +00:00
|
|
|
import TeamPill, { TeamRole } from "./TeamPill";
|
2021-12-09 23:51:30 +00:00
|
|
|
|
|
|
|
interface Props {
|
|
|
|
team: inferQueryOutput<"viewer.teams.get">;
|
|
|
|
member: inferQueryOutput<"viewer.teams.get">["members"][number];
|
|
|
|
}
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-09-12 22:04:33 +00:00
|
|
|
/** @deprecated Use `packages/features/ee/teams/components/MemberListItem.tsx` */
|
2021-12-09 23:51:30 +00:00
|
|
|
export default function MemberListItem(props: Props) {
|
2021-10-12 13:11:33 +00:00
|
|
|
const { t } = useLocale();
|
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
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const utils = trpc.useContext();
|
|
|
|
const [showChangeMemberRoleModal, setShowChangeMemberRoleModal] = useState(false);
|
|
|
|
const [showTeamAvailabilityModal, setShowTeamAvailabilityModal] = useState(false);
|
2022-07-21 17:02:20 +00:00
|
|
|
const [showImpersonateModal, setShowImpersonateModal] = useState(false);
|
2021-12-09 23:51:30 +00:00
|
|
|
|
|
|
|
const removeMemberMutation = trpc.useMutation("viewer.teams.removeMember", {
|
|
|
|
async onSuccess() {
|
|
|
|
await utils.invalidateQueries(["viewer.teams.get"]);
|
|
|
|
showToast(t("success"), "success");
|
|
|
|
},
|
|
|
|
async onError(err) {
|
|
|
|
showToast(err.message, "error");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-03-14 15:34:05 +00:00
|
|
|
const ownersInTeam = () => {
|
|
|
|
const { members } = props.team;
|
2022-03-15 18:56:11 +00:00
|
|
|
const owners = members.filter((member) => member["role"] === MembershipRole.OWNER && member["accepted"]);
|
2022-03-14 15:34:05 +00:00
|
|
|
return owners.length;
|
|
|
|
};
|
|
|
|
|
2022-05-04 21:06:41 +00:00
|
|
|
const currentUserId = useCurrentUserId();
|
2022-03-14 15:34:05 +00:00
|
|
|
|
2021-12-09 23:51:30 +00:00
|
|
|
const name =
|
|
|
|
props.member.name ||
|
|
|
|
(() => {
|
|
|
|
const emailName = props.member.email.split("@")[0];
|
|
|
|
return emailName.charAt(0).toUpperCase() + emailName.slice(1);
|
|
|
|
})();
|
|
|
|
|
|
|
|
const removeMember = () =>
|
|
|
|
removeMemberMutation.mutate({ teamId: props.team?.id, memberId: props.member.id });
|
|
|
|
|
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
|
|
|
return (
|
2021-12-09 23:51:30 +00:00
|
|
|
<li className="divide-y">
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="my-4 flex justify-between">
|
|
|
|
<div className="flex w-full flex-col justify-between sm:flex-row">
|
2021-12-09 23:51:30 +00:00
|
|
|
<div className="flex">
|
|
|
|
<Avatar
|
2022-05-30 07:57:48 +00:00
|
|
|
imageSrc={WEBAPP_URL + "/" + props.member.username + "/avatar.png"}
|
2021-12-09 23:51:30 +00:00
|
|
|
alt={name || ""}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="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">{name}</span>
|
2022-01-26 16:56:22 +00:00
|
|
|
<span
|
2022-02-09 00:05:13 +00:00
|
|
|
className="-mt-1 block text-xs text-gray-400"
|
2022-01-26 16:56:22 +00:00
|
|
|
data-testid="member-email"
|
|
|
|
data-email={props.member.email}>
|
|
|
|
{props.member.email}
|
|
|
|
</span>
|
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
|
|
|
</div>
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
2022-02-09 00:05:13 +00:00
|
|
|
<div className="mt-2 flex ltr:mr-2 rtl:ml-2 sm:mt-0 sm:justify-center">
|
2022-02-07 23:35:26 +00:00
|
|
|
{/* Tooltip doesn't show... WHY????? */}
|
|
|
|
{props.member.isMissingSeat && (
|
2022-07-14 11:32:28 +00:00
|
|
|
<Tooltip side="top" content={t("hidden_team_member_message")}>
|
2022-02-07 23:35:26 +00:00
|
|
|
<TeamPill color="red" text={t("hidden")} />
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
{!props.member.accepted && <TeamPill color="yellow" text={t("invitee")} />}
|
|
|
|
{props.member.role && <TeamRole role={props.member.role} />}
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-07-27 02:24:00 +00:00
|
|
|
<div className="flex space-x-2">
|
2022-07-14 11:32:28 +00:00
|
|
|
<Tooltip side="top" content={t("team_view_user_availability")}>
|
2021-12-09 23:51:30 +00:00
|
|
|
<Button
|
2021-12-21 00:59:06 +00:00
|
|
|
// Disabled buttons don't trigger Tooltips
|
|
|
|
title={
|
|
|
|
props.member.accepted
|
|
|
|
? t("team_view_user_availability")
|
|
|
|
: t("team_view_user_availability_disabled")
|
|
|
|
}
|
|
|
|
disabled={!props.member.accepted}
|
|
|
|
onClick={() => (props.member.accepted ? setShowTeamAvailabilityModal(true) : null)}
|
2021-12-09 23:51:30 +00:00
|
|
|
color="minimal"
|
2022-07-27 02:24:00 +00:00
|
|
|
size="icon">
|
2022-08-03 16:01:29 +00:00
|
|
|
<Icon.FiClock className="h-5 w-5 group-hover:text-gray-800" />
|
2021-12-09 23:51:30 +00:00
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
<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} />
|
2021-12-09 23:51:30 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Link href={"/" + props.member.username}>
|
|
|
|
<a target="_blank">
|
2022-08-03 16:01:29 +00:00
|
|
|
<Button color="minimal" StartIcon={Icon.FiExternalLink} className="w-full font-normal">
|
2021-12-09 23:51:30 +00:00
|
|
|
{t("view_public_page")}
|
|
|
|
</Button>
|
|
|
|
</a>
|
|
|
|
</Link>
|
|
|
|
</DropdownMenuItem>
|
2021-12-17 00:16:59 +00:00
|
|
|
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
2022-03-14 15:34:05 +00:00
|
|
|
{((props.team.membership.role === MembershipRole.OWNER &&
|
2022-03-14 21:27:38 +00:00
|
|
|
(props.member.role !== MembershipRole.OWNER ||
|
2022-03-15 18:56:11 +00:00
|
|
|
ownersInTeam() > 1 ||
|
2022-05-04 21:06:41 +00:00
|
|
|
props.member.id !== currentUserId)) ||
|
2022-03-14 21:27:38 +00:00
|
|
|
(props.team.membership.role === MembershipRole.ADMIN &&
|
|
|
|
props.member.role !== MembershipRole.OWNER)) && (
|
2021-10-29 12:59:23 +00:00
|
|
|
<>
|
2021-12-09 23:51:30 +00:00
|
|
|
<DropdownMenuItem>
|
|
|
|
<Button
|
|
|
|
onClick={() => setShowChangeMemberRoleModal(true)}
|
|
|
|
color="minimal"
|
2022-08-03 16:01:29 +00:00
|
|
|
StartIcon={Icon.FiEdit2}
|
2022-02-09 00:05:13 +00:00
|
|
|
className="w-full flex-shrink-0 font-normal">
|
2021-12-09 23:51:30 +00:00
|
|
|
{t("edit_role")}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
2021-12-17 00:16:59 +00:00
|
|
|
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
2022-07-21 17:02:20 +00:00
|
|
|
{/* Only show impersonate box if - The user has impersonation enabled,
|
|
|
|
They have accepted the team invite, and it is enabled for this instance */}
|
|
|
|
{!props.member.disableImpersonation &&
|
|
|
|
props.member.accepted &&
|
|
|
|
process.env.NEXT_PUBLIC_TEAM_IMPERSONATION === "true" && (
|
|
|
|
<>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Button
|
|
|
|
onClick={() => setShowImpersonateModal(true)}
|
|
|
|
color="minimal"
|
2022-08-03 16:01:29 +00:00
|
|
|
StartIcon={Icon.FiLock}
|
2022-07-21 17:02:20 +00:00
|
|
|
className="w-full flex-shrink-0 font-normal">
|
|
|
|
{t("impersonate")}
|
|
|
|
</Button>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuSeparator className="h-px bg-gray-200" />
|
|
|
|
</>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
<DropdownMenuItem>
|
|
|
|
<Dialog>
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<Button
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
color="warn"
|
2022-08-03 16:01:29 +00:00
|
|
|
StartIcon={Icon.FiUserMinus}
|
2021-12-17 00:16:59 +00:00
|
|
|
className="w-full font-normal">
|
2021-12-09 23:51:30 +00:00
|
|
|
{t("remove_member")}
|
|
|
|
</Button>
|
|
|
|
</DialogTrigger>
|
|
|
|
<ConfirmationDialogContent
|
|
|
|
variety="danger"
|
|
|
|
title={t("remove_member")}
|
|
|
|
confirmBtnText={t("confirm_remove_member")}
|
|
|
|
onConfirm={removeMember}>
|
|
|
|
{t("remove_member_confirmation_message")}
|
|
|
|
</ConfirmationDialogContent>
|
|
|
|
</Dialog>
|
|
|
|
</DropdownMenuItem>
|
2021-10-29 12:59:23 +00:00
|
|
|
</>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
</DropdownMenuContent>
|
|
|
|
</Dropdown>
|
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
|
|
|
</div>
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
|
|
|
{showChangeMemberRoleModal && (
|
|
|
|
<MemberChangeRoleModal
|
2022-03-17 13:20:49 +00:00
|
|
|
isOpen={showChangeMemberRoleModal}
|
2022-04-28 15:51:10 +00:00
|
|
|
currentMember={props.team.membership.role}
|
2021-12-09 23:51:30 +00:00
|
|
|
teamId={props.team?.id}
|
|
|
|
memberId={props.member.id}
|
|
|
|
initialRole={props.member.role as MembershipRole}
|
|
|
|
onExit={() => setShowChangeMemberRoleModal(false)}
|
|
|
|
/>
|
|
|
|
)}
|
2022-07-21 17:02:20 +00:00
|
|
|
{showImpersonateModal && props.member.username && (
|
|
|
|
<ModalContainer isOpen={showImpersonateModal} onExit={() => setShowImpersonateModal(false)}>
|
|
|
|
<>
|
|
|
|
<div className="mb-4 sm:flex sm:items-start">
|
|
|
|
<div className="text-center sm:text-left">
|
|
|
|
<h3 className="text-lg font-medium leading-6 text-gray-900" id="modal-title">
|
|
|
|
{t("impersonate")}
|
|
|
|
</h3>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<form
|
|
|
|
onSubmit={async (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
await signIn("impersonation-auth", {
|
|
|
|
username: props.member.username,
|
|
|
|
teamId: props.team.id,
|
|
|
|
});
|
|
|
|
}}>
|
|
|
|
<p className="mt-2 text-sm text-gray-500" id="email-description">
|
|
|
|
{t("impersonate_user_tip")}
|
|
|
|
</p>
|
|
|
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
|
|
|
<Button type="submit" color="primary" className="ltr:ml-2 rtl:mr-2">
|
|
|
|
{t("impersonate")}
|
|
|
|
</Button>
|
|
|
|
<Button type="button" color="secondary" onClick={() => setShowImpersonateModal(false)}>
|
|
|
|
{t("cancel")}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
</ModalContainer>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
{showTeamAvailabilityModal && (
|
2022-03-17 13:20:49 +00:00
|
|
|
<ModalContainer
|
|
|
|
wide
|
|
|
|
noPadding
|
|
|
|
isOpen={showTeamAvailabilityModal}
|
|
|
|
onExit={() => setShowTeamAvailabilityModal(false)}>
|
2021-12-09 23:51:30 +00:00
|
|
|
<TeamAvailabilityModal team={props.team} member={props.member} />
|
2022-03-17 13:20:49 +00:00
|
|
|
<div className="space-x-2 border-t py-5 rtl:space-x-reverse">
|
2021-12-09 23:51:30 +00:00
|
|
|
<Button onClick={() => setShowTeamAvailabilityModal(false)}>{t("done")}</Button>
|
2021-12-17 00:16:59 +00:00
|
|
|
{props.team.membership.role !== MembershipRole.MEMBER && (
|
2022-05-04 21:06:41 +00:00
|
|
|
<Link href={`/settings/teams/${props.team.id}/availability`} passHref>
|
2021-12-17 00:16:59 +00:00
|
|
|
<Button color="secondary">{t("Open Team Availability")}</Button>
|
|
|
|
</Link>
|
|
|
|
)}
|
2021-12-09 23:51:30 +00:00
|
|
|
</div>
|
|
|
|
</ModalContainer>
|
|
|
|
)}
|
|
|
|
</li>
|
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
|
|
|
);
|
|
|
|
}
|