diff --git a/web/app/(commonLayout)/layout.tsx b/web/app/(commonLayout)/layout.tsx index ceeb164315..78c26803a0 100644 --- a/web/app/(commonLayout)/layout.tsx +++ b/web/app/(commonLayout)/layout.tsx @@ -8,6 +8,7 @@ import Header from '@/app/components/header' import { EventEmitterContextProvider } from '@/context/event-emitter' import { ProviderContextProvider } from '@/context/provider-context' import { ModalContextProvider } from '@/context/modal-context' +import LicenseInfo from '@/app/components/system-features-initor/license-info' const Layout = ({ children }: { children: ReactNode }) => { return ( @@ -22,6 +23,7 @@ const Layout = ({ children }: { children: ReactNode }) => {
{children} + diff --git a/web/app/components/system-features-initor/index.tsx b/web/app/components/system-features-initor/index.tsx new file mode 100644 index 0000000000..3a0cfeb930 --- /dev/null +++ b/web/app/components/system-features-initor/index.tsx @@ -0,0 +1,25 @@ +'use client' +import { + useEffect, + useState, +} from 'react' +import { useSystemFeaturesStore } from './store' +import { getSystemFeatures } from '@/service/common' + +const SystemFeaturesInitor = ({ + children, +}: { children: React.ReactElement }) => { + const [init, setInit] = useState(false) + const { setSystemFeatures } = useSystemFeaturesStore() + + useEffect(() => { + getSystemFeatures().then((res) => { + setSystemFeatures(res) + }).finally(() => { + setInit(true) + }) + }, []) + return init ? children : null +} + +export default SystemFeaturesInitor diff --git a/web/app/components/system-features-initor/license-info/index.tsx b/web/app/components/system-features-initor/license-info/index.tsx new file mode 100644 index 0000000000..fb74ffc8e0 --- /dev/null +++ b/web/app/components/system-features-initor/license-info/index.tsx @@ -0,0 +1,27 @@ +'use client' +import cn from 'classnames' +import { useSystemFeaturesStore } from '../store' +import s from './styles.module.css' + +const LicenseInfo = () => { + const { systemFeatures } = useSystemFeaturesStore() + + if (!systemFeatures.expired_at) { + return ( +
+
+
+ Your organization's Dify Enterprise license has expired. +
+
+ Please contact your administrator to continue using Dify. +
+
+
+ ) + } + + return null +} + +export default LicenseInfo \ No newline at end of file diff --git a/web/app/components/system-features-initor/license-info/styles.module.css b/web/app/components/system-features-initor/license-info/styles.module.css new file mode 100644 index 0000000000..37bed5742f --- /dev/null +++ b/web/app/components/system-features-initor/license-info/styles.module.css @@ -0,0 +1,4 @@ +.bg { + background-image: url(../../../signin/assets/background.png); + background-size: cover; +} \ No newline at end of file diff --git a/web/app/components/system-features-initor/store.tsx b/web/app/components/system-features-initor/store.tsx new file mode 100644 index 0000000000..ebf27059de --- /dev/null +++ b/web/app/components/system-features-initor/store.tsx @@ -0,0 +1,18 @@ +import { create } from 'zustand' +import type { SystemFeatures } from '@/types/feature' + +type StateAndAction = { + systemFeatures: SystemFeatures + setSystemFeatures: (features: SystemFeatures) => void +} + +export const useSystemFeaturesStore = create(set => ({ + systemFeatures: { + sso_enforced_for_signin: false, + sso_enforced_for_signin_protocol: '', + sso_enforced_for_web: false, + sso_enforced_for_web_protocol: '', + expired_at: 11, + }, + setSystemFeatures: features => set({ systemFeatures: features }), +})) diff --git a/web/app/layout.tsx b/web/app/layout.tsx index fedf66045a..3b1982637e 100644 --- a/web/app/layout.tsx +++ b/web/app/layout.tsx @@ -3,6 +3,7 @@ import I18nServer from './components/i18n-server' import BrowerInitor from './components/browser-initor' import SentryInitor from './components/sentry-initor' import Topbar from './components/base/topbar' +import SystemFeaturesInitor from './components/system-features-initor' import { getLocaleOnServer } from '@/i18n/server' import './styles/globals.css' import './styles/markdown.scss' @@ -47,7 +48,9 @@ const LocaleLayout = ({ - {children} + + {children} + diff --git a/web/app/signin/page.tsx b/web/app/signin/page.tsx index b0ee172a95..6b689b7673 100644 --- a/web/app/signin/page.tsx +++ b/web/app/signin/page.tsx @@ -1,29 +1,15 @@ 'use client' -import React, { useEffect, useState } from 'react' import cn from 'classnames' import Script from 'next/script' -import Loading from '../components/base/loading' +import { useSystemFeaturesStore } from '../components/system-features-initor/store' import Forms from './forms' import Header from './_header' import style from './page.module.css' import UserSSOForm from './userSSOForm' import { IS_CE_EDITION } from '@/config' -import type { SystemFeatures } from '@/types/feature' -import { defaultSystemFeatures } from '@/types/feature' -import { getSystemFeatures } from '@/service/common' - const SignIn = () => { - const [loading, setLoading] = useState(true) - const [systemFeatures, setSystemFeatures] = useState(defaultSystemFeatures) - - useEffect(() => { - getSystemFeatures().then((res) => { - setSystemFeatures(res) - }).finally(() => { - setLoading(false) - }) - }, []) + const { systemFeatures } = useSystemFeaturesStore() return ( <> @@ -59,19 +45,7 @@ gtag('config', 'AW-11217955271"'); }>
- {loading && ( -
- -
- )} - - {!loading && !systemFeatures.sso_enforced_for_signin && ( + {!systemFeatures.sso_enforced_for_signin && ( <>
@@ -80,7 +54,7 @@ gtag('config', 'AW-11217955271"'); )} - {!loading && systemFeatures.sso_enforced_for_signin && ( + {systemFeatures.sso_enforced_for_signin && ( )}
diff --git a/web/types/feature.ts b/web/types/feature.ts index 89af9d21ab..a6c25027a4 100644 --- a/web/types/feature.ts +++ b/web/types/feature.ts @@ -3,6 +3,7 @@ export type SystemFeatures = { sso_enforced_for_signin_protocol: string sso_enforced_for_web: boolean sso_enforced_for_web_protocol: string + expired_at?: number } export const defaultSystemFeatures: SystemFeatures = {