mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 11:56:09 +08:00
Feat/e license limit (#18436)
Co-authored-by: Garfield Dai <dai.hai@foxmail.com>
This commit is contained in:
parent
14f378bbc6
commit
9f07584a00
2
.github/workflows/build-push.yml
vendored
2
.github/workflows/build-push.yml
vendored
@ -6,7 +6,7 @@ on:
|
|||||||
- "main"
|
- "main"
|
||||||
- "deploy/dev"
|
- "deploy/dev"
|
||||||
- "deploy/enterprise"
|
- "deploy/enterprise"
|
||||||
- "e-0154"
|
- "e-0156"
|
||||||
release:
|
release:
|
||||||
types: [published]
|
types: [published]
|
||||||
|
|
||||||
|
@ -68,6 +68,10 @@ export type CurrentPlanInfoBackend = {
|
|||||||
model_load_balancing_enabled: boolean
|
model_load_balancing_enabled: boolean
|
||||||
dataset_operator_enabled: boolean
|
dataset_operator_enabled: boolean
|
||||||
webapp_copyright_enabled: boolean
|
webapp_copyright_enabled: boolean
|
||||||
|
workspace_members: {
|
||||||
|
size: number
|
||||||
|
limit: number
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SubscriptionItem = {
|
export type SubscriptionItem = {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback, useEffect, useState } from 'react'
|
||||||
import { useContext } from 'use-context-selector'
|
import { useContext } from 'use-context-selector'
|
||||||
import { XMarkIcon } from '@heroicons/react/24/outline'
|
import { XMarkIcon } from '@heroicons/react/24/outline'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
@ -17,6 +17,7 @@ import type { InvitationResult } from '@/models/common'
|
|||||||
import I18n from '@/context/i18n'
|
import I18n from '@/context/i18n'
|
||||||
|
|
||||||
import 'react-multi-email/dist/style.css'
|
import 'react-multi-email/dist/style.css'
|
||||||
|
import { useProviderContextSelector } from '@/context/provider-context'
|
||||||
type IInviteModalProps = {
|
type IInviteModalProps = {
|
||||||
isEmailSetup: boolean
|
isEmailSetup: boolean
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
@ -29,13 +30,26 @@ const InviteModal = ({
|
|||||||
onSend,
|
onSend,
|
||||||
}: IInviteModalProps) => {
|
}: IInviteModalProps) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const licenseLimit = useProviderContextSelector(s => s.licenseLimit)
|
||||||
const [emails, setEmails] = useState<string[]>([])
|
const [emails, setEmails] = useState<string[]>([])
|
||||||
const { notify } = useContext(ToastContext)
|
const { notify } = useContext(ToastContext)
|
||||||
|
const [isLimited, setIsLimited] = useState(false)
|
||||||
|
const [isLimitExceeded, setIsLimitExceeded] = useState(false)
|
||||||
|
const [usedSize, setUsedSize] = useState(licenseLimit.workspace_members.size ?? 0)
|
||||||
|
useEffect(() => {
|
||||||
|
const limited = licenseLimit.workspace_members.limit > 0
|
||||||
|
const used = emails.length + licenseLimit.workspace_members.size
|
||||||
|
setIsLimited(limited)
|
||||||
|
setUsedSize(used)
|
||||||
|
setIsLimitExceeded(limited && (used > licenseLimit.workspace_members.limit))
|
||||||
|
}, [licenseLimit, emails])
|
||||||
|
|
||||||
const { locale } = useContext(I18n)
|
const { locale } = useContext(I18n)
|
||||||
const [role, setRole] = useState<string>('normal')
|
const [role, setRole] = useState<string>('normal')
|
||||||
|
|
||||||
const handleSend = useCallback(async () => {
|
const handleSend = useCallback(async () => {
|
||||||
|
if (isLimitExceeded)
|
||||||
|
return
|
||||||
if (emails.map((email: string) => emailRegex.test(email)).every(Boolean)) {
|
if (emails.map((email: string) => emailRegex.test(email)).every(Boolean)) {
|
||||||
try {
|
try {
|
||||||
const { result, invitation_results } = await inviteMember({
|
const { result, invitation_results } = await inviteMember({
|
||||||
@ -53,7 +67,7 @@ const InviteModal = ({
|
|||||||
else {
|
else {
|
||||||
notify({ type: 'error', message: t('common.members.emailInvalid') })
|
notify({ type: 'error', message: t('common.members.emailInvalid') })
|
||||||
}
|
}
|
||||||
}, [role, emails, notify, onCancel, onSend, t])
|
}, [isLimitExceeded, emails, role, locale, onCancel, onSend, notify, t])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn(s.wrap)}>
|
<div className={cn(s.wrap)}>
|
||||||
@ -81,7 +95,7 @@ const InviteModal = ({
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div className='mb-2 text-sm font-medium text-gray-900'>{t('common.members.email')}</div>
|
<div className='mb-2 text-sm font-medium text-gray-900'>{t('common.members.email')}</div>
|
||||||
<div className='mb-8 h-36 flex items-stretch'>
|
<div className='mb-8 h-36 flex flex-col items-stretch'>
|
||||||
<ReactMultiEmail
|
<ReactMultiEmail
|
||||||
className={cn('w-full pt-2 px-3 outline-none border-none',
|
className={cn('w-full pt-2 px-3 outline-none border-none',
|
||||||
'appearance-none text-sm text-gray-900 rounded-lg overflow-y-auto',
|
'appearance-none text-sm text-gray-900 rounded-lg overflow-y-auto',
|
||||||
@ -101,6 +115,14 @@ const InviteModal = ({
|
|||||||
}
|
}
|
||||||
placeholder={t('common.members.emailPlaceholder') || ''}
|
placeholder={t('common.members.emailPlaceholder') || ''}
|
||||||
/>
|
/>
|
||||||
|
<div className={
|
||||||
|
cn('flex items-center justify-end system-xs-regular text-text-tertiary',
|
||||||
|
(isLimited && usedSize > licenseLimit.workspace_members.limit) ? 'text-text-destructive' : '')}
|
||||||
|
>
|
||||||
|
<span>{usedSize}</span>
|
||||||
|
<span>/</span>
|
||||||
|
<span>{isLimited ? licenseLimit.workspace_members.limit : t('common.license.unlimited')}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='mb-6'>
|
<div className='mb-6'>
|
||||||
<RoleSelector value={role} onChange={setRole} />
|
<RoleSelector value={role} onChange={setRole} />
|
||||||
@ -109,7 +131,7 @@ const InviteModal = ({
|
|||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
className='w-full'
|
className='w-full'
|
||||||
onClick={handleSend}
|
onClick={handleSend}
|
||||||
disabled={!emails.length}
|
disabled={!emails.length || isLimitExceeded}
|
||||||
variant='primary'
|
variant='primary'
|
||||||
>
|
>
|
||||||
{t('common.members.sendInvite')}
|
{t('common.members.sendInvite')}
|
||||||
|
@ -36,6 +36,12 @@ type ProviderContextState = {
|
|||||||
modelLoadBalancingEnabled: boolean
|
modelLoadBalancingEnabled: boolean
|
||||||
datasetOperatorEnabled: boolean
|
datasetOperatorEnabled: boolean
|
||||||
webappCopyrightEnabled: boolean
|
webappCopyrightEnabled: boolean
|
||||||
|
licenseLimit: {
|
||||||
|
workspace_members: {
|
||||||
|
size: number
|
||||||
|
limit: number
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const ProviderContext = createContext<ProviderContextState>({
|
const ProviderContext = createContext<ProviderContextState>({
|
||||||
modelProviders: [],
|
modelProviders: [],
|
||||||
@ -66,6 +72,12 @@ const ProviderContext = createContext<ProviderContextState>({
|
|||||||
modelLoadBalancingEnabled: false,
|
modelLoadBalancingEnabled: false,
|
||||||
datasetOperatorEnabled: false,
|
datasetOperatorEnabled: false,
|
||||||
webappCopyrightEnabled: false,
|
webappCopyrightEnabled: false,
|
||||||
|
licenseLimit: {
|
||||||
|
workspace_members: {
|
||||||
|
size: 0,
|
||||||
|
limit: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
export const useProviderContext = () => useContext(ProviderContext)
|
export const useProviderContext = () => useContext(ProviderContext)
|
||||||
@ -94,6 +106,12 @@ export const ProviderContextProvider = ({
|
|||||||
const [modelLoadBalancingEnabled, setModelLoadBalancingEnabled] = useState(false)
|
const [modelLoadBalancingEnabled, setModelLoadBalancingEnabled] = useState(false)
|
||||||
const [datasetOperatorEnabled, setDatasetOperatorEnabled] = useState(false)
|
const [datasetOperatorEnabled, setDatasetOperatorEnabled] = useState(false)
|
||||||
const [webappCopyrightEnabled, setWebappCopyrightEnabled] = useState(false)
|
const [webappCopyrightEnabled, setWebappCopyrightEnabled] = useState(false)
|
||||||
|
const [licenseLimit, setLicenseLimit] = useState({
|
||||||
|
workspace_members: {
|
||||||
|
size: 0,
|
||||||
|
limit: 0,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const fetchPlan = async () => {
|
const fetchPlan = async () => {
|
||||||
const data = await fetchCurrentPlanInfo()
|
const data = await fetchCurrentPlanInfo()
|
||||||
@ -110,6 +128,8 @@ export const ProviderContextProvider = ({
|
|||||||
setDatasetOperatorEnabled(true)
|
setDatasetOperatorEnabled(true)
|
||||||
if (data.webapp_copyright_enabled)
|
if (data.webapp_copyright_enabled)
|
||||||
setWebappCopyrightEnabled(true)
|
setWebappCopyrightEnabled(true)
|
||||||
|
if (data.workspace_members)
|
||||||
|
setLicenseLimit({ workspace_members: data.workspace_members })
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchPlan()
|
fetchPlan()
|
||||||
@ -129,6 +149,7 @@ export const ProviderContextProvider = ({
|
|||||||
modelLoadBalancingEnabled,
|
modelLoadBalancingEnabled,
|
||||||
datasetOperatorEnabled,
|
datasetOperatorEnabled,
|
||||||
webappCopyrightEnabled,
|
webappCopyrightEnabled,
|
||||||
|
licenseLimit,
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</ProviderContext.Provider>
|
</ProviderContext.Provider>
|
||||||
|
@ -617,6 +617,7 @@ const translation = {
|
|||||||
license: {
|
license: {
|
||||||
expiring: 'Expiring in one day',
|
expiring: 'Expiring in one day',
|
||||||
expiring_plural: 'Expiring in {{count}} days',
|
expiring_plural: 'Expiring in {{count}} days',
|
||||||
|
unlimited: 'Unlimited',
|
||||||
},
|
},
|
||||||
pagination: {
|
pagination: {
|
||||||
perPage: 'Items per page',
|
perPage: 'Items per page',
|
||||||
|
@ -617,6 +617,7 @@ const translation = {
|
|||||||
license: {
|
license: {
|
||||||
expiring: '许可证还有 1 天到期',
|
expiring: '许可证还有 1 天到期',
|
||||||
expiring_plural: '许可证还有 {{count}} 天到期',
|
expiring_plural: '许可证还有 {{count}} 天到期',
|
||||||
|
unlimited: '无限制',
|
||||||
},
|
},
|
||||||
pagination: {
|
pagination: {
|
||||||
perPage: '每页显示',
|
perPage: '每页显示',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user