({})
| 6 | type GithubStarType = {} |
| 7 | |
| 8 | const GithubStar: FC<GithubStarType> = ({}) => { |
| 9 | const organisation = AccountStore.getOrganisation() |
| 10 | const plan = organisation?.subscription?.plan || '' |
| 11 | const planName = Utils.getPlanName(plan) |
| 12 | const [stars, setStars] = useState<number | null>(null) |
| 13 | |
| 14 | const formatStars = (count: number): string => { |
| 15 | if (count >= 1000) { |
| 16 | const formattedCount = Math.ceil(count / 100) * 100 // Round up to nearest 100 |
| 17 | return `${(formattedCount / 1000).toFixed(1)}k` // Format as 'x.xk' |
| 18 | } |
| 19 | return count.toString() |
| 20 | } |
| 21 | |
| 22 | useEffect(() => { |
| 23 | if (planName !== planNames.enterprise) { |
| 24 | fetch('https://api.github.com/repos/flagsmith/flagsmith') |
| 25 | .then((res) => res.json()) |
| 26 | .then((res) => { |
| 27 | if (res.stargazers_count) { |
| 28 | setStars(res.stargazers_count) |
| 29 | } |
| 30 | }) |
| 31 | .catch(() => {}) |
| 32 | } |
| 33 | }, [planName]) |
| 34 | |
| 35 | if (planName === planNames.enterprise) { |
| 36 | return <></> |
| 37 | } |
| 38 | |
| 39 | return ( |
| 40 | <a |
| 41 | target='_blank' |
| 42 | href='https://github.com/flagsmith/flagsmith' |
| 43 | className='d-flex text-body' |
| 44 | rel='noreferrer' |
| 45 | > |
| 46 | <div |
| 47 | className={ |
| 48 | stars !== null |
| 49 | ? 'd-flex flex-row justify-content-center align-items-center' |
| 50 | : '' |
| 51 | } |
| 52 | > |
| 53 | <GithubIcon width={16} height={16} /> |
| 54 | {stars !== null && <div className='ms-1'>{formatStars(stars)}</div>} |
| 55 | </div> |
| 56 | </a> |
| 57 | ) |
| 58 | } |
| 59 | |
| 60 | export default GithubStar |
nothing calls this directly
no test coverage detected