authorize.tsx34 lines · main
| 1 | import { useParams } from 'common' |
| 2 | import { useEffect } from 'react' |
| 3 | |
| 4 | import { useGitHubAuthorizationCreateMutation } from '@/data/integrations/github-authorization-create-mutation' |
| 5 | |
| 6 | const GitHubIntegrationAuthorize = () => { |
| 7 | const { code, state, setup_action } = useParams() |
| 8 | |
| 9 | const { mutate, isSuccess, isError, isPending } = useGitHubAuthorizationCreateMutation({ |
| 10 | onSuccess() { |
| 11 | window.close() |
| 12 | }, |
| 13 | }) |
| 14 | |
| 15 | useEffect(() => { |
| 16 | if (code && state) { |
| 17 | mutate({ code, state }) |
| 18 | } else if (setup_action === 'install') { |
| 19 | window.close() |
| 20 | } |
| 21 | }, [code, state, mutate, setup_action]) |
| 22 | |
| 23 | return ( |
| 24 | <div className="h-screen flex flex-col justify-center items-center gap-4"> |
| 25 | <h2>Completing GitHub Authorization...</h2> |
| 26 | |
| 27 | {isSuccess && <p>You can now close this window.</p>} |
| 28 | {isPending && <p>Authorizing...</p>} |
| 29 | {isError && <p>Unable to authorize. Please try again.</p>} |
| 30 | </div> |
| 31 | ) |
| 32 | } |
| 33 | |
| 34 | export default GitHubIntegrationAuthorize |