mirror of
https://mirror.skon.top/github.com/langgenius/dify.git
synced 2026-04-20 15:20:15 +08:00
71 lines
3.0 KiB
TypeScript
71 lines
3.0 KiB
TypeScript
'use client'
|
|
import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react'
|
|
import { cn } from '@langgenius/dify-ui/cn'
|
|
import {
|
|
RiArrowDownSLine,
|
|
} from '@remixicon/react'
|
|
import { useSuspenseQuery } from '@tanstack/react-query'
|
|
import { Fragment } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import Loading from '@/app/components/base/loading'
|
|
import { useAppContext } from '@/context/app-context'
|
|
import { systemFeaturesQueryOptions } from '@/service/system-features'
|
|
import { useWorkspacePermissions } from '@/service/use-workspace'
|
|
|
|
type Props = {
|
|
onOperate: () => void
|
|
}
|
|
|
|
const TransferOwnership = ({ onOperate }: Props) => {
|
|
const { t } = useTranslation()
|
|
const { currentWorkspace } = useAppContext()
|
|
const { data: systemFeatures } = useSuspenseQuery(systemFeaturesQueryOptions())
|
|
const { data: workspacePermissions, isFetching: isFetchingWorkspacePermissions } = useWorkspacePermissions(currentWorkspace!.id, systemFeatures.branding.enabled)
|
|
if (systemFeatures.branding.enabled) {
|
|
if (isFetchingWorkspacePermissions) {
|
|
return <Loading />
|
|
}
|
|
if (!workspacePermissions || workspacePermissions.allow_owner_transfer !== true) {
|
|
return <span className="px-3 system-sm-regular text-text-secondary">{t('members.owner', { ns: 'common' })}</span>
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Menu as="div" className="relative h-full w-full">
|
|
{
|
|
({ open }) => (
|
|
<>
|
|
<MenuButton className={cn('group flex h-full w-full cursor-pointer items-center justify-between px-3 system-sm-regular text-text-secondary hover:bg-state-base-hover', open && 'bg-state-base-hover')}>
|
|
{t('members.owner', { ns: 'common' })}
|
|
<RiArrowDownSLine className={cn('h-4 w-4 group-hover:block', open ? 'block' : 'hidden')} />
|
|
</MenuButton>
|
|
<Transition
|
|
as={Fragment}
|
|
enter="transition ease-out duration-100"
|
|
enterFrom="transform opacity-0 scale-95"
|
|
enterTo="transform opacity-100 scale-100"
|
|
leave="transition ease-in duration-75"
|
|
leaveFrom="transform opacity-100 scale-100"
|
|
leaveTo="transform opacity-0 scale-95"
|
|
>
|
|
<MenuItems
|
|
className={cn('absolute top-[52px] right-0 z-10 origin-top-right rounded-xl border-[0.5px] border-components-panel-border bg-components-panel-bg-blur shadow-lg backdrop-blur-xs')}
|
|
>
|
|
<div className="p-1">
|
|
<MenuItem>
|
|
<div className="flex cursor-pointer rounded-lg px-3 py-2 hover:bg-state-base-hover" onClick={onOperate}>
|
|
<div className="system-md-regular whitespace-nowrap text-text-secondary">{t('members.transferOwnership', { ns: 'common' })}</div>
|
|
</div>
|
|
</MenuItem>
|
|
</div>
|
|
</MenuItems>
|
|
</Transition>
|
|
</>
|
|
)
|
|
}
|
|
</Menu>
|
|
)
|
|
}
|
|
|
|
export default TransferOwnership
|