fix: simplify GetStartedProgress percentage calculation logic (#8183)

🐛 (get-started-progress.tsx): fix calculation of totalPercentage to correctly display progress bar percentage
💡 (get-started-progress.tsx): refactor logic to calculate totalPercentage based on user opt-ins and flows
This commit is contained in:
Cristhian Zanforlin Lousa 2025-05-22 13:38:08 -03:00 committed by GitHub
commit 58e68fca9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -35,25 +35,27 @@ export const GetStartedProgress: FC<{
const hasFlows = flows && flows?.length > 0;
const percentageGetStarted = useMemo(() => {
const totalSteps = 3;
let hasFlowsCount = 0;
const completedSteps = Object.keys(userData?.optins ?? {}).filter(
(key) => userData?.optins?.[key],
)?.length;
const stepValue = 33;
let totalPercentage = 0;
if (hasFlows) {
hasFlowsCount = 33;
if (userData?.optins?.github_starred) {
totalPercentage += stepValue;
}
const percentage =
Math.round((completedSteps / totalSteps) * 100) + hasFlowsCount;
if (userData?.optins?.discord_clicked) {
totalPercentage += stepValue;
}
if (percentage > 100) {
if (hasFlows) {
totalPercentage += stepValue;
}
if (totalPercentage === 99) {
return 100;
}
return percentage;
}, [userData?.optins, isGithubStarredChild, isDiscordJoinedChild, hasFlows]);
return Math.min(totalPercentage, 100);
}, [userData?.optins, hasFlows]);
const handleUserTrack = (key: string) => {
const optins = userData?.optins ?? {};