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:
parent
8387f6278f
commit
58e68fca9c
1 changed files with 14 additions and 12 deletions
|
|
@ -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 ?? {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue