2022-05-04 21:06:41 +00:00
|
|
|
import { PencilIcon, UserRemoveIcon } from "@heroicons/react/outline";
|
|
|
|
import { ClockIcon, DotsHorizontalIcon, ExternalLinkIcon } from "@heroicons/react/solid";
|
2022-03-22 15:22:20 +00:00
|
|
|
import { MembershipRole } from "@prisma/client";
|
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-03-16 23:36:43 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
|
|
|
import showToast from "@calcom/lib/notification";
|
|
|
|
import Button from "@calcom/ui/Button";
|
|
|
|
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-05-05 21:16:25 +00:00
|
|
|
import { Tooltip } from "@calcom/ui/Tooltip";
|
2021-12-09 23:51:30 +00:00
|
|
|
import TeamAvailabilityModal from "@ee/components/team/availability/TeamAvailabilityModal";
|
|
|
|
|
|
|
|
import { getPlaceholderAvatar } from "@lib/getPlaceholderAvatar";
|
2022-05-04 21:06:41 +00:00
|
|
|
import useCurrentUserId from "@lib/hooks/useCurrentUserId";
|
|
|
|
import { inferQueryOutput, trpc } from "@lib/trpc";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
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 ConfirmationDialogContent from "@components/dialog/ConfirmationDialogContent";
|
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
|
|
|
|
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);
|
|
|
|
|
|
|
|
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
|
|
|
|
imageSrc={getPlaceholderAvatar(props.member?.avatar, name)}
|
|
|
|
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 && (
|
|
|
|
<Tooltip content={t("hidden_team_member_message")}>
|
|
|
|
<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>
|
|
|
|
<div className="flex">
|
2021-12-21 00:59:06 +00:00
|
|
|
<Tooltip 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-02-09 00:05:13 +00:00
|
|
|
className="group hidden h-10 w-10 items-center justify-center border border-transparent px-0 py-0 text-neutral-400 hover:border-gray-200 hover:bg-white sm:flex">
|
|
|
|
<ClockIcon className="h-5 w-5 group-hover:text-gray-800" />
|
2021-12-09 23:51:30 +00:00
|
|
|
</Button>
|
|
|
|
</Tooltip>
|
|
|
|
<Dropdown>
|
2022-02-09 00:05:13 +00:00
|
|
|
<DropdownMenuTrigger className="group h-10 w-10 border border-transparent p-0 text-neutral-400 hover:border-gray-200 hover:bg-white">
|
|
|
|
<DotsHorizontalIcon className="h-5 w-5 group-hover:text-gray-800" />
|
2021-12-09 23:51:30 +00:00
|
|
|
</DropdownMenuTrigger>
|
|
|
|
<DropdownMenuContent>
|
|
|
|
<DropdownMenuItem>
|
|
|
|
<Link href={"/" + props.member.username}>
|
|
|
|
<a target="_blank">
|
2021-12-17 00:16:59 +00:00
|
|
|
<Button color="minimal" StartIcon={ExternalLinkIcon} 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"
|
|
|
|
StartIcon={PencilIcon}
|
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" />
|
2021-12-09 23:51:30 +00:00
|
|
|
<DropdownMenuItem>
|
|
|
|
<Dialog>
|
|
|
|
<DialogTrigger asChild>
|
|
|
|
<Button
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
color="warn"
|
|
|
|
StartIcon={UserRemoveIcon}
|
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)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{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
|
|
|
);
|
|
|
|
}
|