UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

180 lines (179 loc) 8.37 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _objectDestructuringEmpty from "@babel/runtime/helpers/objectDestructuringEmpty"; import _extends from "@babel/runtime/helpers/extends"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import _regeneratorRuntime from "@babel/runtime/regenerator"; 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 var AgentProfileCardTrigger = /*#__PURE__*/forwardRef(function (_ref, ref) { var props = _extends({}, (_objectDestructuringEmpty(_ref), _ref)); var resourceClient = props.resourceClient, userId = props.agentId, cloudId = props.cloudId; var _useAnalyticsEvents = useAnalyticsEvents(), fireEvent = _useAnalyticsEvents.fireEvent; /** * @TODO replace with `getAgentCreator` from `@atlassian/rovo-agent-components` * @deprecated use `getAgentCreator` from `@atlassian/rovo-agent-components` */ var getCreator = /*#__PURE__*/function () { var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) { var creator_type, creator, authoringTeam, _userId, _authoringTeam$displa, _authoringTeam$profil, _navigateToTeamsApp, profileHref, creatorInfo; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: creator_type = _ref2.creator_type, creator = _ref2.creator, authoringTeam = _ref2.authoringTeam; if (creator) { _context.next = 3; break; } return _context.abrupt("return", undefined); case 3: if (!(isForgeAgentByCreatorType(creator_type) && fg('rovo_agent_support_a2a_avatar'))) { _context.next = 5; break; } return _context.abrupt("return", { type: 'THIRD_PARTY', name: creator !== null && creator !== void 0 ? creator : '' }); case 5: _context.t0 = creator_type; _context.next = _context.t0 === 'SYSTEM' ? 8 : _context.t0 === 'THIRD_PARTY' ? 9 : _context.t0 === 'FORGE' ? 10 : _context.t0 === 'CUSTOMER' ? 11 : 27; break; case 8: return _context.abrupt("return", { type: 'SYSTEM' }); case 9: return _context.abrupt("return", { type: 'THIRD_PARTY', name: creator !== null && creator !== void 0 ? creator : '' }); case 10: return _context.abrupt("return", { type: 'THIRD_PARTY', name: creator !== null && creator !== void 0 ? creator : '' }); case 11: _userId = getAAIDFromARI(creator) || ''; _context.prev = 12; if (!(!_userId || !cloudId)) { _context.next = 15; break; } return _context.abrupt("return", undefined); case 15: if (!authoringTeam) { _context.next = 17; break; } return _context.abrupt("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 : '' }); case 17: _navigateToTeamsApp = navigateToTeamsApp({ type: 'USER', payload: { userId: _userId }, cloudId: cloudId }), profileHref = _navigateToTeamsApp.href; _context.next = 20; return props.resourceClient.getProfile(cloudId, _userId, fireEvent); case 20: creatorInfo = _context.sent; return _context.abrupt("return", { type: 'CUSTOMER', name: creatorInfo.fullName, profileLink: fg('platform-adopt-teams-nav-config') ? profileHref : "/people/".concat(_userId), id: _userId }); case 24: _context.prev = 24; _context.t1 = _context["catch"](12); return _context.abrupt("return", undefined); case 27: return _context.abrupt("return", undefined); case 28: case "end": return _context.stop(); } }, _callee, null, [[12, 24]]); })); return function getCreator(_x) { return _ref3.apply(this, arguments); }; }(); var fetchAgentProfile = /*#__PURE__*/function () { var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() { var _agentProfileResult$a, _agentProfileResult$a2; var agentProfileResult, agentInfo, agentCreatorInfo; return _regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return resourceClient.getRovoAgentProfile({ type: 'agent', value: userId }, fireEvent); case 2: agentProfileResult = _context2.sent; agentInfo = agentProfileResult.restData; _context2.next = 6; return 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 }); case 6: agentCreatorInfo = _context2.sent; return _context2.abrupt("return", _objectSpread(_objectSpread({}, agentInfo), {}, { creatorInfo: agentCreatorInfo })); case 8: case "end": return _context2.stop(); } }, _callee2); })); return function fetchAgentProfile() { return _ref4.apply(this, arguments); }; }(); var renderProfileCard = function renderProfileCard(_ref5) { var profileData = _ref5.profileData, error = _ref5.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" })); });