import { useEffect, useState } from 'react'; import { useToast } from '../../hooks/use-toast'; import { Users2 } from 'lucide-react'; import { httpGet } from '../../lib/http'; import { cn } from '../../lib/classname'; import type { UserTeamItem } from '../TeamDropdown/TeamDropdown'; type TransferToTeamListProps = { teams: UserTeamItem[]; setTeams: (teams: UserTeamItem[]) => void; selectedTeamId: string | null; setSelectedTeamId: (teamId: string | null) => void; isTeamMembersLoading: boolean; setIsTeamMembersLoading: (isLoading: boolean) => void; onTeamChange: (teamId: string | null) => void; }; export function TransferToTeamList(props: TransferToTeamListProps) { const { teams, setTeams, selectedTeamId, setSelectedTeamId, isTeamMembersLoading, setIsTeamMembersLoading, onTeamChange, } = props; const toast = useToast(); const [isLoading, setIsLoading] = useState(true); async function getAllTeams() { if (teams.length > 0) { return; } const { response, error } = await httpGet( `${import.meta.env.PUBLIC_API_URL}/v1-get-user-teams` ); if (error || !response) { toast.error(error?.message || 'Something went wrong'); return; } setTeams( response.filter((team) => ['admin', 'manager'].includes(team.role)) ); } useEffect(() => { getAllTeams().finally(() => setIsLoading(false)); }, []); const loadingTeams = isLoading && ( ); return ( <> {(teams.length > 0 || isLoading) && (

Select a team to transfer this roadmap to

)} {loadingTeams} {teams.length > 0 && !isLoading && ( )} {teams.length === 0 && !isLoading && (

You are not a member of any team.

)} ); }