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 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 ?? {};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue