import { useEffect, useState } from "react"; import { Link, useSearchParams } from "react-router-dom"; import { MessageSquare } from "lucide-react"; import { useAuthServiceContext, useCollaborationTeamServiceContext } from "../../../services"; import type { TeamWithMembers } from "../../../utils/collaborationTeamSides"; import { PendingApprovalsSection } from "./PendingApprovalsSection"; import { PendingExternalInvites } from "./PendingExternalInvites"; import { TeamMembersSection } from "./TeamMembersSection"; import { GiveRecordAccessSection } from "./GiveRecordAccessSection"; import { InviteMemberDialog } from "./InviteMemberDialog"; import { TeamLifecycleSection } from "./TeamLifecycleSection"; import { TeamAppointmentsSection } from "../../../components/CollaborationTeam/TeamAppointmentsSection"; interface CareTeamDetailProps { team: TeamWithMembers; unread?: number; /** Re-reads the list after any change; there is no single-team read on the server. */ onChanged: () => Promise; /** False while the list behind this team is being re-read or could not be. */ decisionsOpen?: boolean; } // The patient's own team, opened over the list: its conversation, who is waiting, who is in it, and how to end it. export const CareTeamDetail = ({ team, unread = 0, onChanged, decisionsOpen = true }: CareTeamDetailProps) => { const { teamAction, inviteMember, memberAction, authorizeMember, resolveInvitee, inviteExternalPractitioner, resendExternalInvite, withdrawExternalInvite, } = useCollaborationTeamServiceContext(); const { currentUser, actingAs } = useAuthServiceContext(); // Who is reading, as the server records an actor: the signed-in person, or the guardian switched in. const viewerRefs = [ currentUser?.fhir?.id ? `${currentUser.fhir.resourceType}/${currentUser.fhir.id}` : undefined, actingAs?.relatedPersonId ? `RelatedPerson/${actingAs.relatedPersonId}` : undefined, ].filter((ref): ref is string => Boolean(ref)); const [searchParams, setSearchParams] = useSearchParams(); // Read once, then dropped from the address so a reload does not reopen the invite. const [prefillLookup] = useState(() => searchParams.get("invite") ?? undefined); useEffect(() => { if (!searchParams.has("invite")) return; const next = new URLSearchParams(searchParams); next.delete("invite"); setSearchParams(next, { replace: true }); }, [searchParams, setSearchParams]); return (
{/* The thread outlives a dissolved team and stays readable there. */}
); }; export default CareTeamDetail;