import { useState } from "react"; import { Link } from "react-router-dom"; import { MessageSquare } from "lucide-react"; import { AlertDialog, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "../../../components/ui/alert-dialog"; import { STATE_LABELS } from "../../../services"; import type { MemberActionType, TeamMembership } from "../../../services"; import type { OtherTeam } from "../../../utils/collaborationTeamSides"; import { relayServerFailure } from "../../../utils/fetchFailureMessage"; import { MemberIdentity } from "./MemberIdentity"; import { MemberAffiliation } from "./MemberAffiliation"; import { PersonBadge } from "../../../components/ui/person-badge.tsx"; import { TeamAppointmentsSection } from "../../../components/CollaborationTeam/TeamAppointmentsSection"; interface MemberTeamDetailProps { other: OtherTeam; unread?: number; memberAction: (teamId: string, memberRef: string, action: MemberActionType) => Promise; onLeft: () => Promise | void; /** The reader's own name, for the initials on their row. */ myName?: string; } // Somebody else's team: the same people and conversation, without invite, approve or deny, and always a way out. export const MemberTeamDetail = ({ other, unread = 0, memberAction, onLeft, myName = "You" }: MemberTeamDetailProps) => { const { team, mine, ownerName } = other; const [confirming, setConfirming] = useState(false); const [leaving, setLeaving] = useState(false); const [error, setError] = useState(null); const waiting = team.members.filter((member) => member.state === "pending-patient-approval"); const members = team.members.filter( (member) => member.state !== "pending-patient-approval" && member.memberRef !== mine.memberRef, ); const leave = async () => { setLeaving(true); setError(null); try { await memberAction(team.teamId, mine.memberRef, "leave"); setConfirming(false); await onLeft(); } catch (err) { setError(relayServerFailure(err, "You could not leave the team. Please try again.")); } finally { setLeaving(false); } }; return (
); }; export default MemberTeamDetail;