UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

135 lines (134 loc) 4.65 kB
import _extends from "@babel/runtime/helpers/extends"; import React, { forwardRef, Suspense } from 'react'; import { fg } from '@atlaskit/platform-feature-flags'; import { isForgeAgentByCreatorType } from '@atlaskit/rovo-agent-components/common/utils/is-forge-agent'; import { navigateToTeamsApp } from '@atlaskit/teams-app-config/navigation'; import { useAnalyticsEvents } from '@atlaskit/teams-app-internal-analytics'; import { getAAIDFromARI } from '../../util/rovoAgentUtils'; import ProfileCardTrigger from '../common/ProfileCardTrigger'; import { AgentProfileCardLazy } from './lazyAgentProfileCard'; export const AgentProfileCardTrigger = /*#__PURE__*/forwardRef(({ ...props }, ref) => { const { resourceClient, agentId: userId, cloudId } = props; const { fireEvent } = useAnalyticsEvents(); /** * @TODO replace with `getAgentCreator` from `@atlassian/rovo-agent-components` * @deprecated use `getAgentCreator` from `@atlassian/rovo-agent-components` */ const getCreator = async ({ creator_type, creator, authoringTeam }) => { if (!creator) { return undefined; } if (isForgeAgentByCreatorType(creator_type) && fg('rovo_agent_support_a2a_avatar')) { return { type: 'THIRD_PARTY', name: creator !== null && creator !== void 0 ? creator : '' }; } switch (creator_type) { case 'SYSTEM': return { type: 'SYSTEM' }; case 'THIRD_PARTY': return { type: 'THIRD_PARTY', name: creator !== null && creator !== void 0 ? creator : '' }; case 'FORGE': return { type: 'THIRD_PARTY', name: creator !== null && creator !== void 0 ? creator : '' }; case 'CUSTOMER': const userId = getAAIDFromARI(creator) || ''; try { if (!userId || !cloudId) { return undefined; } if (authoringTeam) { var _authoringTeam$displa, _authoringTeam$profil; return { type: 'CUSTOMER', name: (_authoringTeam$displa = authoringTeam.displayName) !== null && _authoringTeam$displa !== void 0 ? _authoringTeam$displa : '', profileLink: (_authoringTeam$profil = authoringTeam.profileUrl) !== null && _authoringTeam$profil !== void 0 ? _authoringTeam$profil : '' }; } const { href: profileHref } = navigateToTeamsApp({ type: 'USER', payload: { userId: userId }, cloudId }); const creatorInfo = await props.resourceClient.getProfile(cloudId, userId, fireEvent); return { type: 'CUSTOMER', name: creatorInfo.fullName, profileLink: fg('platform-adopt-teams-nav-config') ? profileHref : `/people/${userId}`, id: userId }; } catch { return undefined; } default: return undefined; } }; const fetchAgentProfile = async () => { var _agentProfileResult$a, _agentProfileResult$a2; const agentProfileResult = await resourceClient.getRovoAgentProfile({ type: 'agent', value: userId }, fireEvent); const agentInfo = agentProfileResult.restData; const agentCreatorInfo = await getCreator({ creator_type: agentInfo.creator_type, creator: agentInfo.creator || undefined, authoringTeam: (_agentProfileResult$a = (_agentProfileResult$a2 = agentProfileResult.aggData) === null || _agentProfileResult$a2 === void 0 ? void 0 : _agentProfileResult$a2.authoringTeam) !== null && _agentProfileResult$a !== void 0 ? _agentProfileResult$a : undefined }); return { ...agentInfo, creatorInfo: agentCreatorInfo }; }; const renderProfileCard = ({ profileData, error }) => { return /*#__PURE__*/React.createElement(Suspense, { fallback: null }, /*#__PURE__*/React.createElement(AgentProfileCardLazy, { agent: profileData, hasError: !!error, cloudId: props.cloudId, errorType: error, onChatClick: props.onChatClick, onConversationStartersClick: props.onConversationStartersClick, resourceClient: props.resourceClient, onDeleteAgent: props.onDeleteAgent, addFlag: props.addFlag })); }; return /*#__PURE__*/React.createElement(ProfileCardTrigger, _extends({}, props, { ref: ref, trigger: "hover", renderProfileCard: renderProfileCard, fetchProfile: fetchAgentProfile, fireAnalytics: fireEvent, profileCardType: "agent" })); });