()
| 11 | import { GitHubLink } from '@prisma/client'; |
| 12 | |
| 13 | export const GitHubLinkButton = () => { |
| 14 | const [isProcessing, setIsProcessing] = useState(false); |
| 15 | const [githubData, setGithubData] = useState<GitHubLink | null>(null); |
| 16 | const searchParams = useSearchParams(); |
| 17 | const router = useRouter(); |
| 18 | |
| 19 | useEffect(() => { |
| 20 | if (searchParams.get('github_linked') === 'true') { |
| 21 | router.push('/payout-methods'); |
| 22 | toast.success('Github account linked successfully'); |
| 23 | } else if (searchParams.get('error') === 'github_link_failed') { |
| 24 | toast.error("Couldn't link with your github , Try again after sometime"); |
| 25 | } |
| 26 | }, [searchParams]); |
| 27 | |
| 28 | const getGithubData = async () => { |
| 29 | const response = await fetch('/api/github/details'); |
| 30 | const resp = await response.json(); |
| 31 | setGithubData(resp.data[0]); |
| 32 | }; |
| 33 | |
| 34 | const handleUnlinkAccount = async () => { |
| 35 | setIsProcessing(true); |
| 36 | const response = await fetch('/api/github/details', { |
| 37 | method: 'DELETE', |
| 38 | }); |
| 39 | setIsProcessing(false); |
| 40 | const resp = await response.json(); |
| 41 | console.log(resp); |
| 42 | if (resp.success) { |
| 43 | toast.success(resp.message); |
| 44 | getGithubData(); |
| 45 | } else { |
| 46 | toast.error(resp.message); |
| 47 | } |
| 48 | }; |
| 49 | |
| 50 | useEffect(() => { |
| 51 | // fetch the saved github linked data |
| 52 | getGithubData(); |
| 53 | }, [searchParams]); |
| 54 | |
| 55 | const handleLinkGitHub = async () => { |
| 56 | setIsProcessing(true); |
| 57 | window.location.href = '/api/github/link'; |
| 58 | }; |
| 59 | |
| 60 | return ( |
| 61 | <> |
| 62 | <div className="group relative flex h-[18rem] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 p-6"> |
| 63 | <div> |
| 64 | <div> |
| 65 | <h3 className="text-lg font-semibold">Github</h3> |
| 66 | <p className="text-sm text-muted-foreground"> |
| 67 | Link your Github account |
| 68 | </p> |
| 69 | </div> |
| 70 | </div> |
nothing calls this directly
no test coverage detected