system features initor

This commit is contained in:
StyleZhang 2024-07-02 14:20:39 +08:00
parent cb09dbef66
commit aac90e54ec
8 changed files with 85 additions and 31 deletions

View File

@ -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 }) => {
<Header />
</HeaderWrapper>
{children}
<LicenseInfo />
</ModalContextProvider>
</ProviderContextProvider>
</EventEmitterContextProvider>

View 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

View File

@ -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

View File

@ -0,0 +1,4 @@
.bg {
background-image: url(../../../signin/assets/background.png);
background-size: cover;
}

View 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 }),
}))

View File

@ -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 = ({
<Topbar />
<BrowerInitor>
<SentryInitor>
<I18nServer>{children}</I18nServer>
<SystemFeaturesInitor>
<I18nServer>{children}</I18nServer>
</SystemFeaturesInitor>
</SentryInitor>
</BrowerInitor>
</body>

View File

@ -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<boolean>(true)
const [systemFeatures, setSystemFeatures] = useState<SystemFeatures>(defaultSystemFeatures)
useEffect(() => {
getSystemFeatures().then((res) => {
setSystemFeatures(res)
}).finally(() => {
setLoading(false)
})
}, [])
const { systemFeatures } = useSystemFeaturesStore()
return (
<>
@ -59,19 +45,7 @@ gtag('config', 'AW-11217955271"');
}>
<Header />
{loading && (
<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 && (
{!systemFeatures.sso_enforced_for_signin && (
<>
<Forms />
<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} />
)}
</div>

View File

@ -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 = {