🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
'use client';
import { Button, Icon } from '@lobehub/ui';
import { BriefcaseIcon, LinkIcon, Trash2Icon } from 'lucide-react';
import { memo } from 'react';
import { useTranslation } from 'react-i18next';
import AsyncError from '@/components/AsyncError';
import { usePermission } from '@/hooks/usePermission';
import { createMessengerLinkModal } from '../LinkModal';
import { MessengerPushSection } from './MessengerPush';
import {
ConnectionRow,
DetailLayout,
IntegrationDetailSkeleton,
styles,
useDisconnectInstallation,
useLinkActions,
useMessengerData,
UserAgentConnection,
} from './shared';
interface SlackDetailProps {
appId?: string;
botUsername?: string;
name: string;
onBack?: () => void;
}
const SlackDetail = memo<SlackDetailProps>(({ appId, botUsername, name, onBack }) => {
const { t } = useTranslation('messenger');
const { allowed: canCreate } = usePermission('create_content');
const { allowed: canEdit } = usePermission('edit_own_content');
const data = useMessengerData('slack');
const { handleSetActive, handleUnlink } = useLinkActions({
name,
platform: 'slack',
});
const disconnectInstallation = useDisconnectInstallation();
// For Slack, disconnecting an install row freezes the workspace's bot —
// dispatch is token-gated, so removing the install effectively kills the
// workspace integration even though the bot user remains in Slack.
const handleDisconnectInstallation = (id: string) =>
canEdit &&
disconnectInstallation(id, {
confirm: t('messenger.slack.connections.disconnectConfirm'),
failedKey: 'messenger.slack.connections.disconnectFailed',
success: t('messenger.slack.connections.disconnectSuccess'),
title: t('messenger.slack.connections.disconnectTitle'),
});
if (data.error && data.isInitialLoading)
return <AsyncError error={data.error} variant={'block'} onRetry={data.mutate} />;
if (data.isInitialLoading) return <IntegrationDetailSkeleton platform={'slack'} />;
const { installations, links, tenantNameByTenantId } = data;
const hasInstallations = installations.length > 0;
const hasLinks = links.length > 0;
const pushTargets = links.map((link) => ({
label: tenantNameByTenantId.get(link.tenantId) || link.tenantId,
tenantId: link.tenantId,
}));
const handleOpenLink = () =>
createMessengerLinkModal({ appId, botUsername, name, platform: 'slack' });
const headerAction = (
<Button
disabled={!canCreate || !canEdit}
icon={<Icon icon={LinkIcon} />}
type={hasInstallations ? 'default' : 'primary'}
onClick={handleOpenLink}
>
{hasInstallations ? t('messenger.detail.addWorkspace') : t('messenger.linkCta')}
</Button>
);
// Slack: render one workspace row per install + one user row per link.
// Installs without a matching link are surfaced with `pending` status so the
// user knows they still need to DM the bot to finish per-account binding.
const linkByTenantId = new Map(links.map((l) => [l.tenantId, l]));
const allInstallsUnlinked =
hasInstallations && installations.every((install) => !linkByTenantId.has(install.tenantId));
return (
<DetailLayout
hasConnections={hasInstallations || hasLinks}
headerAction={headerAction}
name={name}
platform="slack"
extraSections={
hasLinks ? (
<MessengerPushSection name={name} platform="slack" targets={pushTargets} />
) : undefined
}
onBack={onBack}
>
{installations.map((install) => (
<ConnectionRow
icon={<Icon icon={BriefcaseIcon} size="small" />}
key={install.id}
label={t('messenger.detail.connections.workspaceLabel')}
name={install.tenantName || install.tenantId}
status="connected"
action={
<Button
danger
disabled={!canEdit}
icon={<Icon icon={Trash2Icon} />}
size="small"
onClick={() => handleDisconnectInstallation(install.id)}
>
{t('messenger.detail.disconnect')}
</Button>
}
/>
))}
{links.map((link) => {
const workspace = tenantNameByTenantId.get(link.tenantId) || link.tenantId;
return (
<UserAgentConnection
extraLabel={workspace}
key={link.id}
link={link}
onSetActive={(agentId) => handleSetActive(link.tenantId, agentId)}
onUnlink={() => handleUnlink(link.tenantId)}
/>
);
})}
{allInstallsUnlinked && !hasLinks && (
<div className={styles.emptyRow}>{t('messenger.detail.connections.linkHint')}</div>
)}
</DetailLayout>
);
});
SlackDetail.displayName = 'MessengerSlackDetail';
export default SlackDetail;