'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 { useContext } from 'use-context-selector' import { RiUserAddLine } from '@remixicon/react' import { useTranslation } from 'react-i18next' import InviteModal from './invite-modal' import InvitedModal from './invited-modal' import Operation from './operation' import { fetchMembers } from '@/service/common' import I18n from '@/context/i18n' import { useAppContext } from '@/context/app-context' import Avatar from '@/app/components/base/avatar' import type { InvitationResult } from '@/models/common' 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 UpgradeBtn from '@/app/components/billing/upgrade-btn' import { NUM_INFINITE } from '@/app/components/billing/config' import { LanguagesSupported } from '@/i18n/language' dayjs.extend(relativeTime) const MembersPage = () => { const { t } = useTranslation() const RoleMap = { owner: t('common.members.owner'), admin: t('common.members.admin'), editor: t('common.members.editor'), dataset_operator: t('common.members.datasetOperator'), normal: t('common.members.normal'), } const { locale } = useContext(I18n) const { userProfile, currentWorkspace, isCurrentWorkspaceManager } = useAppContext() const { data, mutate } = useSWR({ url: '/workspaces/current/members' }, fetchMembers) const [inviteModalVisible, setInviteModalVisible] = useState(false) const [invitationResults, setInvitationResults] = useState([]) const [invitedModalVisible, setInvitedModalVisible] = useState(false) const accounts = data?.accounts || [] const owner = accounts.filter(account => account.role === 'owner')?.[0]?.email === userProfile.email const { plan, enableBilling } = useProviderContext() const isNotUnlimitedMemberPlan = enableBilling && plan.type !== Plan.team && plan.type !== Plan.enterprise const isMemberFull = enableBilling && isNotUnlimitedMemberPlan && accounts.length >= plan.total.teamMembers return ( <>
{currentWorkspace?.name}
{enableBilling && (
{isNotUnlimitedMemberPlan ? (
{t('billing.plansCommon.member')}{locale !== LanguagesSupported[1] && accounts.length > 1 && 's'}
{accounts.length}
/
{plan.total.teamMembers === NUM_INFINITE ? t('billing.plansCommon.unlimited') : plan.total.teamMembers}
) : (
{accounts.length}
{t('billing.plansCommon.memberAfter')}{locale !== LanguagesSupported[1] && accounts.length > 1 && 's'}
)}
)}
{isMemberFull && ( )}
(isCurrentWorkspaceManager && !isMemberFull) && setInviteModalVisible(true)}> {t('common.members.invite')}
{t('common.members.name')}
{t('common.members.lastActive')}
{t('common.members.role')}
{ accounts.map(account => (
{account.name} {account.status === 'pending' && {t('common.members.pending')}} {userProfile.email === account.email && {t('common.members.you')}}
{account.email}
{dayjs(Number((account.last_active_at || account.created_at)) * 1000).locale(locale === 'zh-Hans' ? 'zh-cn' : 'en').fromNow()}
{ (owner && account.role !== 'owner') ? :
{RoleMap[account.role] || RoleMap.normal}
}
)) }
{ inviteModalVisible && ( setInviteModalVisible(false)} onSend={(invitationResults) => { setInvitedModalVisible(true) setInvitationResults(invitationResults) mutate() }} /> ) } { invitedModalVisible && ( setInvitedModalVisible(false)} /> ) } ) } export default MembersPage