fix(teams.tsx): reduce network calls to /team/info

This commit is contained in:
Krrish Dholakia 2024-08-10 15:24:23 -07:00
parent 19bb95f781
commit e67a239520
2 changed files with 9 additions and 16 deletions

View file

@ -660,7 +660,7 @@ export const teamListCall = async (
} }
const data = await response.json(); const data = await response.json();
console.log("API Response:", data); console.log("/team/list API Response:", data);
return data; return data;
// Handle success - you might want to update some state or UI based on the created key // Handle success - you might want to update some state or UI based on the created key
} catch (error) { } catch (error) {

View file

@ -74,12 +74,6 @@ const Team: React.FC<TeamProps> = ({
userRole, userRole,
}) => { }) => {
if (teams && teams.length > 0) {
console.log(`Received teams: ${JSON.stringify(teams, null, 2)}`);
} else {
console.log("No teams received or teams array is empty.");
}
useEffect(() => { useEffect(() => {
console.log(`inside useeffect - ${teams}`) console.log(`inside useeffect - ${teams}`)
if (teams === null && accessToken) { if (teams === null && accessToken) {
@ -331,15 +325,15 @@ const Team: React.FC<TeamProps> = ({
return; return;
} }
console.log("fetching team info:");
let _team_id_to_info: Record<string, any> = {}; let _team_id_to_info: Record<string, any> = {};
for (let i = 0; i < teams?.length; i++) { const teamList = await teamListCall(accessToken)
let _team_id = teams[i].team_id; for (let i = 0; i < teamList.length; i++) {
const teamInfo = await teamInfoCall(accessToken, _team_id); let team = teamList[i];
console.log("teamInfo response:", teamInfo); let _team_id = team.team_id;
if (teamInfo !== null) {
_team_id_to_info = { ..._team_id_to_info, [_team_id]: teamInfo }; // Use the team info directly from the teamList
if (team !== null) {
_team_id_to_info = { ..._team_id_to_info, [_team_id]: team };
} }
} }
setPerTeamInfo(_team_id_to_info); setPerTeamInfo(_team_id_to_info);
@ -417,7 +411,6 @@ const Team: React.FC<TeamProps> = ({
console.error("Error creating the team:", error); console.error("Error creating the team:", error);
} }
}; };
console.log(`received teams ${JSON.stringify(teams)}`);
return ( return (
<div className="w-full mx-4"> <div className="w-full mx-4">
<Grid numItems={1} className="gap-2 p-8 h-[75vh] w-full mt-2"> <Grid numItems={1} className="gap-2 p-8 h-[75vh] w-full mt-2">