connect-github.tsx64 lines, 1.8 KB
| 1 | "use client"; |
| 2 | |
| 3 | import { useState } from "react"; |
| 4 | import { linkSocial } from "@/lib/auth-client"; |
| 5 | import { Button } from "@/components/ui/button"; |
| 6 | import { Card, CardContent } from "@/components/ui/card"; |
| 7 | import { Github, Loader2 } from "lucide-react"; |
| 8 | import { cn } from "@/lib/utils"; |
| 9 | import { FaGithub } from "react-icons/fa"; |
| 10 | |
| 11 | interface ConnectGitHubProps { |
| 12 | title?: string; |
| 13 | description?: string; |
| 14 | className?: string; |
| 15 | } |
| 16 | |
| 17 | export function ConnectGithub({ |
| 18 | title = "Connect your GitHub account", |
| 19 | description = "Link your GitHub account to access your repositories and enable AI code reviews.", |
| 20 | className, |
| 21 | }: ConnectGitHubProps) { |
| 22 | const [isConnecting, setIsConnecting] = useState(false); |
| 23 | |
| 24 | const handleConnect = async () => { |
| 25 | setIsConnecting(true); |
| 26 | try { |
| 27 | await linkSocial({ |
| 28 | provider: "github", |
| 29 | callbackURL: window.location.href, |
| 30 | }); |
| 31 | } catch (error) { |
| 32 | console.error("Failed to connect GitHub:", error); |
| 33 | setIsConnecting(false); |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | return ( |
| 38 | <Card className={cn(className)}> |
| 39 | <CardContent className="py-12 text-center"> |
| 40 | <div className="mx-auto size-14 rounded-full bg-muted flex items-center justify-center"> |
| 41 | <FaGithub className="text-muted-foreground size-7" /> |
| 42 | </div> |
| 43 | <h3 className="mt-4 font-semibold text-lg">{title}</h3> |
| 44 | <p className="text-sm text-muted-foreground mt-2 max-w-md mx-auto"> |
| 45 | {description} |
| 46 | </p> |
| 47 | <Button |
| 48 | className="mt-6" |
| 49 | onClick={handleConnect} |
| 50 | disabled={isConnecting} |
| 51 | > |
| 52 | {isConnecting ? ( |
| 53 | <Loader2 className="h-4 w-4 animate-spin" /> |
| 54 | ) : ( |
| 55 | <> |
| 56 | <FaGithub className="size-4" /> |
| 57 | Connect GitHub |
| 58 | </> |
| 59 | )} |
| 60 | </Button> |
| 61 | </CardContent> |
| 62 | </Card> |
| 63 | ); |
| 64 | } |