import { Fragment } from 'react' import { useContext } from 'use-context-selector' import { useTranslation } from 'react-i18next' import { Menu, Transition } from '@headlessui/react' import { RiArrowDownSLine } from '@remixicon/react' import cn from '@/utils/classnames' import { switchWorkspace } from '@/service/common' import { useWorkspacesContext } from '@/context/workspace-context' import { ToastContext } from '@/app/components/base/toast' import PlanBadge from '../../plan-badge' import type { Plan } from '@/app/components/billing/type' const WorkplaceSelector = () => { const { t } = useTranslation() const { notify } = useContext(ToastContext) const { workspaces } = useWorkspacesContext() const currentWorkspace = workspaces.find(v => v.current) const handleSwitchWorkspace = async (tenant_id: string) => { try { if (currentWorkspace?.id === tenant_id) return await switchWorkspace({ url: '/workspaces/switch', body: { tenant_id } }) notify({ type: 'success', message: t('common.actionMsg.modifiedSuccessfully') }) location.assign(`${location.origin}`) } catch (e) { notify({ type: 'error', message: t('common.provider.saveFailed') }) } } return ( { ({ open }) => ( <>
{currentWorkspace?.name[0].toLocaleUpperCase()}
{currentWorkspace?.name}
{t('common.userProfile.workspace')}
{ workspaces.map(workspace => (
handleSwitchWorkspace(workspace.id)}>
{workspace.name[0].toLocaleUpperCase()}
{workspace.name}
)) }
) }
) } export default WorkplaceSelector