Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

2.4 KB
Raw Blame
'use client';

import { Flexbox } from '@lobehub/ui';
import { type FC } from 'react';
import { memo, Suspense } from 'react';
import { useParams } from 'react-router';

import { delayed } from '@/components/Skeleton/Delayed';
import ProfileSkeleton from '@/components/Skeleton/Profile';
import ResourceConfigAccessGate from '@/features/ResourcePermission/ResourceConfigAccessGate';
import WideScreenContainer from '@/features/WideScreenContainer';
import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
import { useGroupProfileStore } from '@/store/groupProfile';

import AgentBuilder from './features/AgentBuilder';
import GroupProfileSettings from './features/GroupProfile';
import Header from './features/Header';
import MemberProfile from './features/MemberProfile';
import StoreSync from './StoreSync';

const ProfileArea = memo(() => {
  const editor = useGroupProfileStore((s) => s.editor);
  const activeTabId = useGroupProfileStore((s) => s.activeTabId);
  const isGroupsLoading = useAgentGroupStore(agentGroupSelectors.isGroupsInit);

  const isGroupTab = activeTabId === 'group';

  return (
    <Flexbox flex={1} height={'100%'} style={{ minWidth: 0, overflow: 'hidden' }}>
      {isGroupsLoading ? (
        <ProfileSkeleton variant={'group'} />
      ) : (
        <>
          <Header />
          <Flexbox
            horizontal
            height={'100%'}
            style={{ cursor: 'text', display: 'flex', overflowY: 'auto', position: 'relative' }}
            width={'100%'}
            onClick={() => {
              editor?.focus();
            }}
          >
            <WideScreenContainer>
              {isGroupTab ? <GroupProfileSettings /> : <MemberProfile />}
            </WideScreenContainer>
          </Flexbox>
        </>
      )}
    </Flexbox>
  );
});

const GroupProfile: FC = () => {
  const { gid } = useParams<{ gid: string }>();

  return (
    <Suspense fallback={delayed(<ProfileSkeleton variant={'group'} />)}>
      <ResourceConfigAccessGate
        loading={<ProfileSkeleton variant={'group'} />}
        redirectPath={`/group/${gid ?? ''}`}
        resourceId={gid}
        resourceType="agentGroup"
      >
        <StoreSync />
        <Flexbox horizontal height={'100%'} width={'100%'}>
          <ProfileArea />
          <AgentBuilder />
        </Flexbox>
      </ResourceConfigAccessGate>
    </Suspense>
  );
};

export default GroupProfile;