system features initor
This commit is contained in:
parent
cb09dbef66
commit
aac90e54ec
@ -8,6 +8,7 @@ import Header from '@/app/components/header'
|
|||||||
import { EventEmitterContextProvider } from '@/context/event-emitter'
|
import { EventEmitterContextProvider } from '@/context/event-emitter'
|
||||||
import { ProviderContextProvider } from '@/context/provider-context'
|
import { ProviderContextProvider } from '@/context/provider-context'
|
||||||
import { ModalContextProvider } from '@/context/modal-context'
|
import { ModalContextProvider } from '@/context/modal-context'
|
||||||
|
import LicenseInfo from '@/app/components/system-features-initor/license-info'
|
||||||
|
|
||||||
const Layout = ({ children }: { children: ReactNode }) => {
|
const Layout = ({ children }: { children: ReactNode }) => {
|
||||||
return (
|
return (
|
||||||
@ -22,6 +23,7 @@ const Layout = ({ children }: { children: ReactNode }) => {
|
|||||||
<Header />
|
<Header />
|
||||||
</HeaderWrapper>
|
</HeaderWrapper>
|
||||||
{children}
|
{children}
|
||||||
|
<LicenseInfo />
|
||||||
</ModalContextProvider>
|
</ModalContextProvider>
|
||||||
</ProviderContextProvider>
|
</ProviderContextProvider>
|
||||||
</EventEmitterContextProvider>
|
</EventEmitterContextProvider>
|
||||||
|
25
web/app/components/system-features-initor/index.tsx
Normal file
25
web/app/components/system-features-initor/index.tsx
Normal file
@ -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
|
@ -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 (
|
||||||
|
<div className='fixed inset-0 flex flex-col pt-14 z-[99999]'>
|
||||||
|
<div className={cn(s.bg, 'grow flex flex-col items-center justify-center bg-white')}>
|
||||||
|
<div className='mb-3 text-xl font-semibold'>
|
||||||
|
Your organization's Dify Enterprise license has expired.
|
||||||
|
</div>
|
||||||
|
<div className='text-gray-300'>
|
||||||
|
Please contact your administrator to continue using Dify.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LicenseInfo
|
@ -0,0 +1,4 @@
|
|||||||
|
.bg {
|
||||||
|
background-image: url(../../../signin/assets/background.png);
|
||||||
|
background-size: cover;
|
||||||
|
}
|
18
web/app/components/system-features-initor/store.tsx
Normal file
18
web/app/components/system-features-initor/store.tsx
Normal file
@ -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<StateAndAction>(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 }),
|
||||||
|
}))
|
@ -3,6 +3,7 @@ import I18nServer from './components/i18n-server'
|
|||||||
import BrowerInitor from './components/browser-initor'
|
import BrowerInitor from './components/browser-initor'
|
||||||
import SentryInitor from './components/sentry-initor'
|
import SentryInitor from './components/sentry-initor'
|
||||||
import Topbar from './components/base/topbar'
|
import Topbar from './components/base/topbar'
|
||||||
|
import SystemFeaturesInitor from './components/system-features-initor'
|
||||||
import { getLocaleOnServer } from '@/i18n/server'
|
import { getLocaleOnServer } from '@/i18n/server'
|
||||||
import './styles/globals.css'
|
import './styles/globals.css'
|
||||||
import './styles/markdown.scss'
|
import './styles/markdown.scss'
|
||||||
@ -47,7 +48,9 @@ const LocaleLayout = ({
|
|||||||
<Topbar />
|
<Topbar />
|
||||||
<BrowerInitor>
|
<BrowerInitor>
|
||||||
<SentryInitor>
|
<SentryInitor>
|
||||||
|
<SystemFeaturesInitor>
|
||||||
<I18nServer>{children}</I18nServer>
|
<I18nServer>{children}</I18nServer>
|
||||||
|
</SystemFeaturesInitor>
|
||||||
</SentryInitor>
|
</SentryInitor>
|
||||||
</BrowerInitor>
|
</BrowerInitor>
|
||||||
</body>
|
</body>
|
||||||
|
@ -1,29 +1,15 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import React, { useEffect, useState } from 'react'
|
|
||||||
import cn from 'classnames'
|
import cn from 'classnames'
|
||||||
import Script from 'next/script'
|
import Script from 'next/script'
|
||||||
import Loading from '../components/base/loading'
|
import { useSystemFeaturesStore } from '../components/system-features-initor/store'
|
||||||
import Forms from './forms'
|
import Forms from './forms'
|
||||||
import Header from './_header'
|
import Header from './_header'
|
||||||
import style from './page.module.css'
|
import style from './page.module.css'
|
||||||
import UserSSOForm from './userSSOForm'
|
import UserSSOForm from './userSSOForm'
|
||||||
import { IS_CE_EDITION } from '@/config'
|
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 SignIn = () => {
|
||||||
const [loading, setLoading] = useState<boolean>(true)
|
const { systemFeatures } = useSystemFeaturesStore()
|
||||||
const [systemFeatures, setSystemFeatures] = useState<SystemFeatures>(defaultSystemFeatures)
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getSystemFeatures().then((res) => {
|
|
||||||
setSystemFeatures(res)
|
|
||||||
}).finally(() => {
|
|
||||||
setLoading(false)
|
|
||||||
})
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@ -59,19 +45,7 @@ gtag('config', 'AW-11217955271"');
|
|||||||
}>
|
}>
|
||||||
<Header />
|
<Header />
|
||||||
|
|
||||||
{loading && (
|
{!systemFeatures.sso_enforced_for_signin && (
|
||||||
<div className={
|
|
||||||
cn(
|
|
||||||
'flex flex-col items-center w-full grow justify-center',
|
|
||||||
'px-6',
|
|
||||||
'md:px-[108px]',
|
|
||||||
)
|
|
||||||
}>
|
|
||||||
<Loading type='area' />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!loading && !systemFeatures.sso_enforced_for_signin && (
|
|
||||||
<>
|
<>
|
||||||
<Forms />
|
<Forms />
|
||||||
<div className='px-8 py-6 text-sm font-normal text-gray-500'>
|
<div className='px-8 py-6 text-sm font-normal text-gray-500'>
|
||||||
@ -80,7 +54,7 @@ gtag('config', 'AW-11217955271"');
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!loading && systemFeatures.sso_enforced_for_signin && (
|
{systemFeatures.sso_enforced_for_signin && (
|
||||||
<UserSSOForm protocol={systemFeatures.sso_enforced_for_signin_protocol} />
|
<UserSSOForm protocol={systemFeatures.sso_enforced_for_signin_protocol} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,6 +3,7 @@ export type SystemFeatures = {
|
|||||||
sso_enforced_for_signin_protocol: string
|
sso_enforced_for_signin_protocol: string
|
||||||
sso_enforced_for_web: boolean
|
sso_enforced_for_web: boolean
|
||||||
sso_enforced_for_web_protocol: string
|
sso_enforced_for_web_protocol: string
|
||||||
|
expired_at?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export const defaultSystemFeatures: SystemFeatures = {
|
export const defaultSystemFeatures: SystemFeatures = {
|
||||||
|
Loading…
Reference in New Issue
Block a user