import { ChevronLeft, Loader2, Plus, Users } from 'lucide-react'; import { $teamList } from '../../stores/team'; import { httpGet } from '../../lib/http'; import type { TeamListResponse } from '../TeamDropdown/TeamDropdown'; import { useToast } from '../../hooks/use-toast'; import { useStore } from '@nanostores/react'; import { useEffect, useState } from 'react'; import { Spinner } from '../ReactIcons/Spinner'; type DropdownTeamListProps = { setIsTeamsOpen: (isOpen: boolean) => void; }; export function DropdownTeamList(props: DropdownTeamListProps) { const { setIsTeamsOpen } = props; const toast = useToast(); const teamList = useStore($teamList); const [isLoading, setIsLoading] = useState(true); async function getAllTeams() { if (teamList.length > 0) { return; } setIsLoading(true); 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; } $teamList.set(response); } useEffect(() => { getAllTeams().finally(() => setIsLoading(false)); }, []); const loadingIndicator = isLoading && (
); return ( <>
{loadingIndicator} {!isLoading && ( )} ); }