'use client' import { useState } from 'react' import useSWR from 'swr' import dayjs from 'dayjs' import 'dayjs/locale/zh-cn' import relativeTime from 'dayjs/plugin/relativeTime' import DetailModal from './detail-modal' import UserModal from './user-modal' import { useContext } from 'use-context-selector' import { RiAddLine } from '@remixicon/react' import { useTranslation } from 'react-i18next' import { delDept, fetchDepts } from '@/service/common' import I18n from '@/context/i18n' import { useAppContext } from '@/context/app-context' import LogoEmbeddedChatHeader from '@/app/components/base/logo/logo-embedded-chat-header' import { useProviderContext } from '@/context/provider-context' import { Plan } from '@/app/components/billing/type' import Button from '@/app/components/base/button' import UpgradeBtn from '@/app/components/billing/upgrade-btn' import { NUM_INFINITE } from '@/app/components/billing/config' import { LanguagesSupported } from '@/i18n/language' import cn from '@/utils/classnames' import Confirm from '@/app/components/base/confirm' import useTimestamp from '@/hooks/use-timestamp' import { Column as AntdColumn, Space as AntdSpace, Table as AntdTable } from 'antd' dayjs.extend(relativeTime) const DeptsPage = () => { const { t } = useTranslation() const { locale } = useContext(I18n) const { formatTime } = useTimestamp() const { userProfile, currentWorkspace, isCurrentWorkspaceOwner, isCurrentWorkspaceManager, systemFeatures } = useAppContext() const { data, mutate }: any = useSWR( { url: '/depts', params: { }, }, fetchDepts, ) const [detailModalVisible, setDetailModalVisible] = useState(false) const [userModalVisible, setUserModalVisible] = useState(false) const [transfer, setTransfer] = useState({ mode: 'add', row: null, }) const deptList = data?.data || [] const { plan, enableBilling } = useProviderContext() const isNotUnlimitedMemberPlan = enableBilling && plan.type !== Plan.team && plan.type !== Plan.enterprise const isMemberFull = enableBilling && isNotUnlimitedMemberPlan && deptList.length >= plan.total.teamMembers const [showConfirmDelete, setShowConfirmDelete] = useState(false) const [row, setRow] = useState({}) const handleDel = async () => { try { await delDept({ url: `/depts/${row.dept_id}`, body: {}, }) setShowConfirmDelete(false) mutate() } catch (e) { } } return ( <>
{currentWorkspace?.name}
{enableBilling && (
{isNotUnlimitedMemberPlan ? (
{t('billing.plansCommon.member')}{locale !== LanguagesSupported[1] && deptList.length > 1 && 's'}
{deptList.length}
/
{plan.total.teamMembers === NUM_INFINITE ? t('billing.plansCommon.unlimited') : plan.total.teamMembers}
) : (
{deptList.length}
{t('billing.plansCommon.memberAfter')}{locale !== LanguagesSupported[1] && deptList.length > 1 && 's'}
)}
)}
{isMemberFull && ( )}
{/* */} ( {!(record.children?.length > 0) && ( )} {!(record.children?.length > 0) && !(record.relation > 0) && ( )} )}/>
{ detailModalVisible && ( setDetailModalVisible(false)} onSend={() => { mutate() }} /> ) } { userModalVisible && ( { setUserModalVisible(false) mutate() }} onSend={() => mutate()} /> ) } {showConfirmDelete && ( setShowConfirmDelete(false)} /> )} ) } export default DeptsPage