From efb4f7f59916ee19ff728b177198875d2d6a500a Mon Sep 17 00:00:00 2001 From: StyleZhang Date: Thu, 28 Sep 2023 11:15:57 +0800 Subject: [PATCH] fix notion --- api/controllers/console/auth/data_source_oauth.py | 4 ++-- .../data-source-page/data-source-notion/index.tsx | 9 +++++++-- web/service/common.ts | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/api/controllers/console/auth/data_source_oauth.py b/api/controllers/console/auth/data_source_oauth.py index 17823f235fc259..77e46815e7d95e 100644 --- a/api/controllers/console/auth/data_source_oauth.py +++ b/api/controllers/console/auth/data_source_oauth.py @@ -45,10 +45,10 @@ def get(self, provider: str): if current_app.config.get('NOTION_INTEGRATION_TYPE') == 'internal': internal_secret = current_app.config.get('NOTION_INTERNAL_SECRET') oauth_provider.save_internal_access_token(internal_secret) - return redirect(f'{current_app.config.get("CONSOLE_WEB_URL")}?oauth_data_source=success') + return { 'data': f'{current_app.config.get("CONSOLE_WEB_URL")}?oauth_data_source=success' } else: auth_url = oauth_provider.get_authorization_url() - return redirect(auth_url) + return { 'data': auth_url }, 200 diff --git a/web/app/components/header/account-setting/data-source-page/data-source-notion/index.tsx b/web/app/components/header/account-setting/data-source-page/data-source-notion/index.tsx index cf2da94ec40857..f71fe93024dc7f 100644 --- a/web/app/components/header/account-setting/data-source-page/data-source-notion/index.tsx +++ b/web/app/components/header/account-setting/data-source-page/data-source-notion/index.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useEffect, useState } from 'react' import useSWR from 'swr' import { useTranslation } from 'react-i18next' import { PlusIcon } from '@heroicons/react/24/solid' @@ -20,7 +20,7 @@ const DataSourceNotion = ({ const { t } = useTranslation() const { isCurrentWorkspaceManager } = useAppContext() const [canConnectNotion, setCanConnectNotion] = useState(false) - useSWR(canConnectNotion ? '/oauth/data-source/notion' : null, fetchNotionConnection) + const { data } = useSWR(canConnectNotion ? '/oauth/data-source/notion' : null, fetchNotionConnection) const connected = !!workspaces.length @@ -31,6 +31,11 @@ const DataSourceNotion = ({ setCanConnectNotion(true) } + useEffect(() => { + if (data?.data) + window.location.href = data.data + }, [data]) + return (
diff --git a/web/service/common.ts b/web/service/common.ts index d626da46d980c1..5f36d6729f8913 100644 --- a/web/service/common.ts +++ b/web/service/common.ts @@ -189,6 +189,6 @@ export const fetchFreeQuotaVerify: Fetcher<{ result: string; flag: boolean; reas return get(url) as Promise<{ result: string; flag: boolean; reason: string }> } -export const fetchNotionConnection: Fetcher = (url) => { - return get(url) as Promise +export const fetchNotionConnection: Fetcher<{ data: string }, string> = (url) => { + return get(url) as Promise<{ data: string }> }