refactor: reuse access denied description

This commit is contained in:
EnixCoda 2020-03-29 15:58:02 +08:00
parent ea1123bfec
commit ed3b117d30
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD
3 changed files with 39 additions and 41 deletions

View file

@ -0,0 +1,37 @@
import { usePlatform } from 'containers/PlatformContext'
import { GITHUB_OAUTH } from 'env'
import { GitHub } from 'platforms/GitHub'
import * as React from 'react'
export function AccessDeniedDescription({ hasToken }: { hasToken: boolean }) {
const platform = usePlatform()
return (
<div className={'description'}>
<h5>Access Denied</h5>
{hasToken ? (
<>
<p>
Current access token is either invalid or not granted with permissions to access this
project.
</p>
{platform === GitHub && (
<p>
You can grant or request access{' '}
<a
href={`https://github.com/settings/connections/applications/${GITHUB_OAUTH.clientId}`}
>
here
</a>{' '}
if you setup Gitako with OAuth.
</p>
)}
</>
) : (
<p>
Gitako needs access token to read this project. Please setup access token in the settings
panel below.
</p>
)}
</div>
)
}

View file

@ -1,4 +1,5 @@
import { raiseError } from 'analytics'
import { AccessDeniedDescription } from 'components/AccessDeniedDescription'
import { FileExplorer } from 'components/FileExplorer'
import { MetaBar } from 'components/MetaBar'
import { Portal } from 'components/Portal'
@ -12,7 +13,6 @@ import { SideBarCore } from 'driver/core'
import { ConnectorState, Props } from 'driver/core/SideBar'
import { platform } from 'platforms'
import { useGitHubAttachCopyFileButton, useGitHubAttachCopySnippetButton } from 'platforms/GitHub'
import { GitHubAccessDeniedError } from 'platforms/GitHub/components'
import * as React from 'react'
import { useEvent, useUpdateEffect } from 'react-use'
import { cx } from 'utils/cx'
@ -144,7 +144,7 @@ RawGitako.defaultProps = {
export const SideBar = connect(SideBarCore)(RawGitako)
function AccessDeniedError({ hasToken }: { hasToken: boolean }) {
return <GitHubAccessDeniedError hasToken={hasToken} />
return <AccessDeniedDescription hasToken={hasToken} />
}
async function trySetUpAccessTokenWithCode() {

View file

@ -1,39 +0,0 @@
import { GITHUB_OAUTH } from 'env'
import * as React from 'react'
export function GitHubAccessDeniedError({ hasToken }: { hasToken: boolean }) {
return (
<div className={'description'}>
<h5>Access Denied</h5>
{hasToken ? (
<>
<p>
Current access token is either invalid or not granted with permissions to access this
project.
</p>
<p>
You can grant or request access{' '}
<a
href={`https://github.com/settings/connections/applications/${GITHUB_OAUTH.clientId}`}
>
here
</a>{' '}
if you setup Gitako with OAuth.
</p>
</>
) : (
<p>
Gitako needs access token to read this project due to{' '}
<a href="https://developer.github.com/v3/#rate-limiting" target="_blank">
GitHub rate limiting
</a>{' '}
and{' '}
<a href="https://developer.github.com/v3/#authentication" target="_blank">
auth needs
</a>
. Please setup access token in the settings panel below.
</p>
)}
</div>
)
}