diff --git a/frontend/web/components/GithubStar.tsx b/frontend/web/components/GithubStar.tsx index eed95c7816c5..c5ed8d76223a 100644 --- a/frontend/web/components/GithubStar.tsx +++ b/frontend/web/components/GithubStar.tsx @@ -10,15 +10,21 @@ const GithubStar: FC = ({}) => { const organisation = AccountStore.getOrganisation() const plan = organisation?.subscription?.plan || '' const planName = Utils.getPlanName(plan) - const [stars, setStars] = useState() - // eslint-disable-next-line react-hooks/rules-of-hooks + const [stars, setStars] = useState(null) + + const formatStars = (count: number): string => { + if (count >= 1000) { + const formattedCount = Math.ceil(count / 100) * 100 // Round up to nearest 100 + return `${(formattedCount / 1000).toFixed(1)}k` // Format as 'x.xk' + } + return count.toString() + } + useEffect(() => { if (planName !== planNames.enterprise) { - fetch(`https://api.github.com/repos/flagsmith/flagsmith`) - .then(function (res) { - return res.json() - }) - .then(function (res) { + fetch('https://api.github.com/repos/flagsmith/flagsmith') + .then((res) => res.json()) + .then((res) => { setStars(res.stargazers_count) }) .catch(() => {}) @@ -39,13 +45,13 @@ const GithubStar: FC = ({}) => { >
- {stars &&
{stars}
} + {stars !== null &&
{formatStars(stars)}
}
)