From 13482b0fc130bcb7ed30afe9ff2e8eafa62f48a4 Mon Sep 17 00:00:00 2001 From: zxhlyh Date: Fri, 25 Aug 2023 19:38:52 +0800 Subject: [PATCH] feat: maintenance notice (#1016) --- .../components/header/maintenance-notice.tsx | 38 +++++++++++++++++++ web/app/layout.tsx | 1 + web/context/app-context.tsx | 8 +++- 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 web/app/components/header/maintenance-notice.tsx diff --git a/web/app/components/header/maintenance-notice.tsx b/web/app/components/header/maintenance-notice.tsx new file mode 100644 index 0000000000..e44a6721b5 --- /dev/null +++ b/web/app/components/header/maintenance-notice.tsx @@ -0,0 +1,38 @@ +import { useState } from 'react' +import { useContext } from 'use-context-selector' +import I18n from '@/context/i18n' +import { X } from '@/app/components/base/icons/src/vender/line/general' + +const NOTICE_I18N = { + title: { + 'en': 'Important Notice', + 'zh-Hans': '重要公告', + }, + desc: { + 'en': 'Our system will be unavailable from 19:00 to 24:00 UTC on August 28 for an upgrade. For questions, kindly contact our support team (support@dify.ai). We value your patience.', + 'zh-Hans': '为了有效提升数据检索能力及稳定性,Dify 将于 2022 年 8 月 29 日 03:00 至 08:00 期间进行服务升级,届时 Dify 云端版及应用将无法访问。感谢您的耐心与支持。', + }, +} + +const MaintenanceNotice = () => { + const { locale } = useContext(I18n) + const [showNotice, setShowNotice] = useState(localStorage.getItem('hide-maintenance-notice') !== '1') + + const handleCloseNotice = () => { + localStorage.setItem('hide-maintenance-notice', '1') + setShowNotice(false) + } + + if (!showNotice) + return null + + return ( +
+
{NOTICE_I18N.title[locale]}
+
{NOTICE_I18N.desc[locale]}
+ +
+ ) +} + +export default MaintenanceNotice diff --git a/web/app/layout.tsx b/web/app/layout.tsx index 0f3ac793f3..ea5e06f586 100644 --- a/web/app/layout.tsx +++ b/web/app/layout.tsx @@ -25,6 +25,7 @@ const LocaleLayout = ({ data-pubic-api-prefix={process.env.NEXT_PUBLIC_PUBLIC_API_PREFIX} data-public-edition={process.env.NEXT_PUBLIC_EDITION} data-public-sentry-dsn={process.env.NEXT_PUBLIC_SENTRY_DSN} + data-public-maintenance-notice={process.env.NEXT_PUBLIC_MAINTENANCE_NOTICE} > diff --git a/web/context/app-context.tsx b/web/context/app-context.tsx index 793e3a5a35..e5f694f224 100644 --- a/web/context/app-context.tsx +++ b/web/context/app-context.tsx @@ -9,6 +9,7 @@ import Loading from '@/app/components/base/loading' import { fetchCurrentWorkspace, fetchLanggeniusVersion, fetchUserProfile } from '@/service/common' import type { App } from '@/types/app' import type { ICurrentWorkspace, LangGeniusVersionResponse, UserProfileResponse } from '@/models/common' +import MaintenanceNotice from '@/app/components/header/maintenance-notice' export type AppContextValue = { apps: App[] @@ -119,8 +120,11 @@ export const AppContextProvider: FC = ({ children }) => isCurrentWorkspaceManager, mutateCurrentWorkspace, }}> -
- {children} +
+ {globalThis.document?.body?.getAttribute('data-public-maintenance-notice') && } +
+ {children} +
)