Compare commits

...

3 Commits

Author SHA1 Message Date
StyleZhang
a8358e8ad1 Merge branch 'main' into fix/notion-sync 2023-09-27 16:07:37 +08:00
StyleZhang
a968d008a6 Merge branch 'main' into fix/notion-sync 2023-09-27 15:14:33 +08:00
StyleZhang
74990cfb90 fix: notion connection 2023-09-27 15:12:05 +08:00
2 changed files with 25 additions and 9 deletions

View File

@@ -1,14 +1,15 @@
import { useState } from 'react'
import useSWR from 'swr'
import { useTranslation } from 'react-i18next'
import Link from 'next/link'
import { PlusIcon } from '@heroicons/react/24/solid'
import cn from 'classnames'
import Indicator from '../../../indicator'
import Operate from './operate'
import s from './style.module.css'
import NotionIcon from '@/app/components/base/notion-icon'
import { apiPrefix } from '@/config'
import type { DataSourceNotion as TDataSourceNotion } from '@/models/common'
import { useAppContext } from '@/context/app-context'
import { fetchNotionConnection } from '@/service/common'
type DataSourceNotionProps = {
workspaces: TDataSourceNotion[]
@@ -18,9 +19,18 @@ const DataSourceNotion = ({
}: DataSourceNotionProps) => {
const { t } = useTranslation()
const { isCurrentWorkspaceManager } = useAppContext()
const [canConnectNotion, setCanConnectNotion] = useState(false)
useSWR(canConnectNotion ? '/oauth/data-source/notion' : null, fetchNotionConnection)
const connected = !!workspaces.length
const handleConnectNotion = () => {
if (!isCurrentWorkspaceManager)
return
setCanConnectNotion(true)
}
return (
<div className='mb-2 border-[0.5px] border-gray-200 bg-gray-50 rounded-xl'>
<div className='flex items-center px-3 py-[9px]'>
@@ -40,26 +50,28 @@ const DataSourceNotion = ({
{
connected
? (
<Link
<div
className={
`flex items-center ml-3 px-3 h-7 bg-white border border-gray-200
rounded-md text-xs font-medium text-gray-700
${isCurrentWorkspaceManager ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
}
href={isCurrentWorkspaceManager ? `${apiPrefix}/oauth/data-source/notion` : '/'}>
onClick={handleConnectNotion}
>
{t('common.dataSource.connect')}
</Link>
</div>
)
: (
<Link
href={isCurrentWorkspaceManager ? `${apiPrefix}/oauth/data-source/notion` : '/' }
<div
className={
`flex items-center px-3 h-7 bg-white border-[0.5px] border-gray-200 text-xs font-medium text-primary-600 rounded-md
${isCurrentWorkspaceManager ? 'cursor-pointer' : 'grayscale opacity-50 cursor-default'}`
}>
}
onClick={handleConnectNotion}
>
<PlusIcon className='w-[14px] h-[14px] mr-[5px]' />
{t('common.dataSource.notion.addWorkspace')}
</Link>
</div>
)
}
</div>

View File

@@ -188,3 +188,7 @@ export const fetchDocumentsLimit: Fetcher<DocumentsLimitResponse, string> = (url
export const fetchFreeQuotaVerify: Fetcher<{ result: string; flag: boolean; reason: string }, string> = (url) => {
return get(url) as Promise<{ result: string; flag: boolean; reason: string }>
}
export const fetchNotionConnection: Fetcher<CommonResponse, string> = (url) => {
return get(url) as Promise<CommonResponse>
}