Skip to content

Commit f7bdc1d

Browse files
authored
Adds automatic polling and update when team or repository calculation… (#87)
* Adds automatic polling and update when team or repository calculation is created * Fixes linter issues * Fixes linter * Fixes typo on repositories flow calculation button and linter
1 parent e79139c commit f7bdc1d

File tree

5 files changed

+57
-22
lines changed

5 files changed

+57
-22
lines changed

src/app/(dashboard)/repositories/[repositoryId]/page.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default function TeamDetailsPage({ params }: PageProps) {
5353
const [hasContributionRequest, setHasContributionRequest] = useState(false);
5454
const [contributionCalculation, setContributionCalculation] =
5555
useState<ContributionCalculation>();
56+
const [pollingCount, setPollingCount] = useState<number>(0);
5657

5758
const router = useRouter();
5859

@@ -141,6 +142,22 @@ export default function TeamDetailsPage({ params }: PageProps) {
141142
}
142143
};
143144

145+
useEffect(() => {
146+
if (hasContributionRequest) {
147+
const delayDebounceFn = setTimeout(() => {
148+
handleFetchContributionRequest();
149+
setPollingCount(pollingCount + 1);
150+
}, 5000);
151+
return () => clearTimeout(delayDebounceFn);
152+
} else if (pollingCount > 0 && !hasContributionRequest) {
153+
handleFetchTeams();
154+
handleFetchUserCreds();
155+
handleFetchRegisteredRepos();
156+
handleFetchContributionCalculation();
157+
handleFetchTeamOverview();
158+
}
159+
}, [hasContributionRequest, pollingCount]);
160+
144161
return (
145162
<>
146163
<div className="flex-1 space-y-4 p-4 md:p-8 pt-6">
@@ -162,10 +179,10 @@ export default function TeamDetailsPage({ params }: PageProps) {
162179
<Button
163180
variant="default"
164181
onClick={() => {
165-
router.push("/teams");
182+
router.push("/repositories");
166183
}}
167184
>
168-
Return to teams
185+
Return to repositories
169186
</Button>
170187
</div>
171188
</div>

src/app/(dashboard)/teams/[teamId]/page.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ import { LoadingCircle } from "@/components/navigation/loading";
2222
import { TextGenerateEffect } from "@/components/ui/text-generate-effect";
2323
import { TeamContributionTable } from "./teamContributionTable";
2424
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
25-
import {
26-
Card,
27-
CardContent,
28-
CardDescription,
29-
CardFooter,
30-
CardHeader,
31-
CardTitle,
32-
} from "@/components/ui/card";
25+
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
3326

3427
interface PageProps {
3528
params: { teamId: string };
@@ -60,6 +53,7 @@ export default function TeamDetailsPage({ params }: PageProps) {
6053
const [hasContributionRequest, setHasContributionRequest] = useState(false);
6154
const [contributionCalculation, setContributionCalculation] =
6255
useState<ContributionCalculation>();
56+
const [pollingCount, setPollingCount] = useState<number>(0);
6357

6458
const router = useRouter();
6559

@@ -81,6 +75,13 @@ export default function TeamDetailsPage({ params }: PageProps) {
8175
}
8276
}, [registeredGitRepos, team, userCredDtos]);
8377

78+
const handleFetchUserCreds = async () => {
79+
const { data } = await axios.get(`/api/cred?team_id=${teamId}`);
80+
if (data.success) {
81+
setUserCredDtos(data.userCreds);
82+
}
83+
};
84+
8485
const handleFetchContributionRequest = async () => {
8586
const { data } = await axios.get(
8687
`/api/contribution-request?team_id=${teamId}`,
@@ -141,12 +142,21 @@ export default function TeamDetailsPage({ params }: PageProps) {
141142
}
142143
}, [userCredDtos]);
143144

144-
const handleFetchUserCreds = async () => {
145-
const { data } = await axios.get(`/api/cred?team_id=${teamId}`);
146-
if (data.success) {
147-
setUserCredDtos(data.userCreds);
145+
useEffect(() => {
146+
if (hasContributionRequest) {
147+
const delayDebounceFn = setTimeout(() => {
148+
handleFetchContributionRequest();
149+
setPollingCount(pollingCount + 1);
150+
}, 5000);
151+
return () => clearTimeout(delayDebounceFn);
152+
} else if (pollingCount > 0 && !hasContributionRequest) {
153+
handleFetchTeams();
154+
handleFetchUserCreds();
155+
handleFetchRegisteredRepos();
156+
handleFetchContributionCalculation();
157+
handleFetchTeamOverview();
148158
}
149-
};
159+
}, [hasContributionRequest, pollingCount]);
150160

151161
return (
152162
<>

src/app/(dashboard)/teams/[teamId]/teamInsights.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ export function TeamInsights({ overview }: TeamInsightsProps) {
1717
</CardHeader>
1818
<CardContent>
1919
<div className="text-2xl font-bold">
20-
{overview?.totalScore.toFixed(2)}
20+
{overview?.totalScore?.toFixed(2) || 0}
2121
</div>
2222
<div className="flex justify-between">
2323
<p className="pt-1 text-xs text-muted-foreground">
24-
+{overview?.weekGrowth.toFixed(2)}% impact this week
24+
+{overview?.weekGrowth?.toFixed(2) || 0}% impact this week
2525
</p>
2626
<HoverExplainer
2727
title="How the current week compares to the total engagement and impact"
@@ -42,12 +42,12 @@ export function TeamInsights({ overview }: TeamInsightsProps) {
4242
</CardHeader>
4343
<CardContent>
4444
<div className="text-2xl font-bold">
45-
{overview?.weekScore.toFixed(2)}
45+
{overview?.weekScore?.toFixed(2) || 0}
4646
</div>
47+
4748
<div className="flex justify-between">
4849
<p className="pt-1 text-xs text-muted-foreground">
49-
{overview?.wowScore ? (overview?.wowScore > 0 ? "+" : "-") : ""}{" "}
50-
{overview?.wowScore.toFixed(2)}% over last week
50+
{overview?.wowScore?.toFixed(2) || 0}% over last week
5151
</p>
5252
<HoverExplainer
5353
title="How the current week compares to the previous week"

src/app/(dashboard)/teams/new/page.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use client";
22

33
import axios from "axios";
4-
import React, { useState } from "react";
4+
import React, { useEffect, useState } from "react";
55
import BreadCrumb from "@/components/breadcrumbs";
66
import { CreateTeamStepper } from "@/components/createTeamSteps";
77
import { CreateTeamCard } from "@/components/teams/createTeam";
@@ -11,7 +11,7 @@ import { Team } from "@/app/api/teams/fetchUserTeams";
1111
import { LoadingCircle } from "@/components/navigation/loading";
1212
import { Button } from "@/components/ui/button";
1313
import { TeamCalculationCreated } from "@/components/teams/teamCalculationCreated";
14-
import { useRouter } from "next/navigation";
14+
import { redirect, useRouter } from "next/navigation";
1515
import { toast } from "sonner";
1616
import TeamGithubRepositoriesTable from "@/components/teams/teamGithubRepositoriesTable";
1717

@@ -61,6 +61,12 @@ export default function CreateTeamPage() {
6161
}
6262
};
6363

64+
useEffect(() => {
65+
if (currentStep === 2) {
66+
redirect(`/teams/${selectedTeam?.id}`);
67+
}
68+
}, [currentStep]);
69+
6470
return (
6571
<>
6672
<div className="flex-1 space-y-4 p-4 md:p-8 pt-6">

src/components/teams/teamCalculationCreated.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use client";
2+
13
import React from "react";
24
import { EvervaultCard, Icon } from "../ui/evervault-card";
35

0 commit comments

Comments
 (0)