(isInitialLoad = false)
| 135 | }, [organizationId]) |
| 136 | |
| 137 | const fetchTeamData = async (isInitialLoad = false) => { |
| 138 | try { |
| 139 | if (isInitialLoad) { |
| 140 | setLoading(true) |
| 141 | } else { |
| 142 | setRefreshing(true) |
| 143 | } |
| 144 | |
| 145 | const [membersResponse, invitationsResponse] = await Promise.all([ |
| 146 | fetch(`/api/orgs/${organizationId}/members`), |
| 147 | fetch(`/api/orgs/${organizationId}/invitations`), |
| 148 | ]) |
| 149 | |
| 150 | if (membersResponse.ok) { |
| 151 | const membersData = await membersResponse.json() |
| 152 | setMembers(membersData.members || []) |
| 153 | } |
| 154 | |
| 155 | if (invitationsResponse.ok) { |
| 156 | const invitationsData = await invitationsResponse.json() |
| 157 | setInvitations(invitationsData.invitations || []) |
| 158 | } |
| 159 | |
| 160 | if (!hasInitiallyLoaded) { |
| 161 | setHasInitiallyLoaded(true) |
| 162 | } |
| 163 | } catch (error) { |
| 164 | console.error('Error fetching team data:', error) |
| 165 | toast({ |
| 166 | title: 'Error', |
| 167 | description: 'Failed to load team data', |
| 168 | variant: 'destructive', |
| 169 | }) |
| 170 | } finally { |
| 171 | if (isInitialLoad) { |
| 172 | setLoading(false) |
| 173 | } else { |
| 174 | setRefreshing(false) |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | const handleInviteMember = async () => { |
| 180 | if (!inviteForm.email.trim()) { |
no test coverage detected