'use client' import Image from 'next/image' import { useMutation, useQueryClient } from '@tanstack/react-query' import api from '@/services/api' export interface GitHubProfileCardProps { login: string name?: string bio?: string avatarUrl?: string followers?: number following?: number publicRepos?: number company?: string location?: string websiteUrl?: string isLoading?: boolean } function formatCount(n: number): string { if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M` if (n >= 1_000) return `${(n / 1_000).toFixed(1)}k` return String(n) } function normalizeWebsiteUrl(url: string): string { return /^https?:\/\//i.test(url) ? url : `https://${url}` } function GitHubProfileCardSkeleton() { return (
) } export default function GitHubProfileCard({ login, name, bio, avatarUrl, followers = 0, following = 0, publicRepos = 0, company, location, websiteUrl, isLoading = false, }: GitHubProfileCardProps) { const queryClient = useQueryClient() const followMutation = useMutation({ mutationFn: () => api.post(`/users/${login}/follow`), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['user', login] }) }, }) if (isLoading) { return } const displayName = name || login const avatarSrc = avatarUrl || `https://avatars.githubusercontent.com/${login}` const githubUrl = `https://github.com/${login}` return (
{/* Avatar + names */}
{`${displayName}

{displayName}

@{login}

{/* Bio */} {bio && (

{bio}

)} {/* Stats row */}
{formatCount(followers)}{' '} followers {formatCount(following)}{' '} following {formatCount(publicRepos)}{' '} repos
{/* Meta: company / location / website */} {(company || location || websiteUrl) && (
    {company && (
  • {company}
  • )} {location && (
  • {location}
  • )} {websiteUrl && (
  • {websiteUrl}
  • )}
)} {/* Actions */}
GitHub
{/* Follow error */} {followMutation.isError && (

Failed to follow. Please try again.

)}
) }