mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-10 11:26:52 +08:00
Feat/header ssr (#594)
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
import { Fragment } from 'react'
|
||||
import { switchWorkspace } from '@/service/common'
|
||||
import { Menu, Transition } from '@headlessui/react'
|
||||
import { ChevronRightIcon, CheckIcon } from '@heroicons/react/24/outline'
|
||||
import cn from 'classnames'
|
||||
import s from './index.module.css'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import { ToastContext } from '@/app/components/base/toast'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Menu, Transition } from '@headlessui/react'
|
||||
import cn from 'classnames'
|
||||
import s from './index.module.css'
|
||||
import { switchWorkspace } from '@/service/common'
|
||||
import { useWorkspacesContext } from '@/context/workspace-context'
|
||||
import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows'
|
||||
import { Check } from '@/app/components/base/icons/src/vender/line/general'
|
||||
import { ToastContext } from '@/app/components/base/toast'
|
||||
|
||||
const itemClassName = `
|
||||
flex items-center px-3 py-2 h-10 cursor-pointer
|
||||
`
|
||||
const itemIconClassName = `
|
||||
shrink-0 mr-2 w-6 h-6 bg-[#EFF4FF] rounded-md
|
||||
shrink-0 mr-2 flex items-center justify-center w-6 h-6 bg-[#EFF4FF] rounded-md text-xs font-medium text-primary-600
|
||||
`
|
||||
const itemNameClassName = `
|
||||
grow mr-2 text-sm text-gray-700 text-left
|
||||
@@ -32,12 +33,12 @@ const WorkplaceSelector = () => {
|
||||
|
||||
const handleSwitchWorkspace = async (tenant_id: string) => {
|
||||
try {
|
||||
await switchWorkspace({ url: `/workspaces/switch`, body: { tenant_id } })
|
||||
await switchWorkspace({ url: '/workspaces/switch', body: { tenant_id } })
|
||||
notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') })
|
||||
router.replace('/apps')
|
||||
} catch (e) {
|
||||
}
|
||||
catch (e) {
|
||||
notify({ type: 'error', message: t('common.provider.saveFailed') })
|
||||
} finally {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +50,12 @@ const WorkplaceSelector = () => {
|
||||
<Menu.Button className={cn(
|
||||
`
|
||||
${itemClassName} w-full
|
||||
group hover:bg-gray-50 cursor-pointer ${open && 'bg-gray-50'}
|
||||
`
|
||||
group hover:bg-gray-50 cursor-pointer ${open && 'bg-gray-50'} rounded-lg
|
||||
`,
|
||||
)}>
|
||||
<div className={itemIconClassName} />
|
||||
<div className={itemIconClassName}>{currentWrokspace?.name[0].toLocaleUpperCase()}</div>
|
||||
<div className={`${itemNameClassName} truncate`}>{currentWrokspace?.name}</div>
|
||||
<ChevronRightIcon className='shrink-0 w-[14px] h-[14px]' />
|
||||
<ChevronRight className='shrink-0 w-[14px] h-[14px] text-gray-500' />
|
||||
</Menu.Button>
|
||||
<Transition
|
||||
as={Fragment}
|
||||
@@ -71,16 +72,16 @@ const WorkplaceSelector = () => {
|
||||
absolute top-[1px] min-w-[200px] z-10 bg-white border-[0.5px] border-gray-200
|
||||
divide-y divide-gray-100 origin-top-right rounded-xl
|
||||
`,
|
||||
s.popup
|
||||
s.popup,
|
||||
)}
|
||||
>
|
||||
<div className="px-1 py-1">
|
||||
{
|
||||
workspaces.map(workspace => (
|
||||
<div className={itemClassName} key={workspace.id} onClick={() => handleSwitchWorkspace(workspace.id)}>
|
||||
<div className={itemIconClassName} />
|
||||
<div className={itemIconClassName}>{workspace.name[0].toLocaleUpperCase()}</div>
|
||||
<div className={itemNameClassName}>{workspace.name}</div>
|
||||
{workspace.current && <CheckIcon className={itemCheckClassName} />}
|
||||
{workspace.current && <Check className={itemCheckClassName} />}
|
||||
</div>
|
||||
))
|
||||
}
|
||||
@@ -94,4 +95,4 @@ const WorkplaceSelector = () => {
|
||||
)
|
||||
}
|
||||
|
||||
export default WorkplaceSelector
|
||||
export default WorkplaceSelector
|
||||
|
||||
Reference in New Issue
Block a user