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