UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

117 lines 5.12 kB
/* Actions.tsx generated by @compiled/babel-plugin v0.39.1 */ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; import "./Actions.compiled.css"; import { ax, ix } from "@compiled/react/runtime"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React, { useCallback, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl-next'; import Button from '@atlaskit/button/new'; import { Box, Inline } from '@atlaskit/primitives/compiled'; import { AgentDropdownMenu } from '@atlaskit/rovo-agent-components/ui/AgentDropdownMenu'; import { useAnalyticsEvents } from '@atlaskit/teams-app-internal-analytics'; import { AgentDeleteConfirmationModal } from './AgentDeleteConfirmationModal'; var styles = { chatToAgentButtonContainer: "_1bsb1osq", chatToAgentButtonWrapper: "_1e0c1txw _1bah1h6o _k48p1wq8 _4t3igktf", chatPillTextStyles: "_1nmz1hna _y3gn1e5h _o5721jtm", actionsWrapperStyles: "_ca0qutpp _u5f3utpp _n3tdutpp _19bvutpp _syazi7uo" }; export var AgentActions = function AgentActions(_ref) { var onEditAgent = _ref.onEditAgent, onDeleteAgent = _ref.onDeleteAgent, onDuplicateAgent = _ref.onDuplicateAgent, onCopyAgent = _ref.onCopyAgent, onChatClick = _ref.onChatClick, onViewFullProfileClick = _ref.onViewFullProfileClick, agent = _ref.agent, resourceClient = _ref.resourceClient, hideMoreActions = _ref.hideMoreActions; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; var _useAnalyticsEvents = useAnalyticsEvents(), fireEvent = _useAnalyticsEvents.fireEvent; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), isDeleteModalOpen = _useState2[0], setIsDeleteModalOpen = _useState2[1]; var isForgeAgent = agent.creator_type === 'FORGE' || agent.creator_type === 'THIRD_PARTY'; var loadAgentPermissions = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var _yield$resourceClient, _yield$resourceClient2, AGENT_CREATE, AGENT_UPDATE, AGENT_DEACTIVATE; return _regeneratorRuntime.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: _context.next = 2; return resourceClient.getRovoAgentPermissions(agent.id); case 2: _yield$resourceClient = _context.sent; _yield$resourceClient2 = _yield$resourceClient.permissions; AGENT_CREATE = _yield$resourceClient2.AGENT_CREATE; AGENT_UPDATE = _yield$resourceClient2.AGENT_UPDATE; AGENT_DEACTIVATE = _yield$resourceClient2.AGENT_DEACTIVATE; return _context.abrupt("return", { isCreateEnabled: AGENT_CREATE.permitted, isEditEnabled: AGENT_UPDATE.permitted, isDeleteEnabled: AGENT_DEACTIVATE.permitted }); case 8: case "end": return _context.stop(); } }, _callee); })), [agent.id, resourceClient]); var handleDeleteAgent = useCallback(function () { fireEvent('ui.button.clicked.deleteAgentButton', { agentId: agent.id, source: 'agentProfileCard' }); setIsDeleteModalOpen(true); }, [agent.id, fireEvent]); return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Inline, { space: "space.100", xcss: styles.actionsWrapperStyles }, /*#__PURE__*/React.createElement(Box, { xcss: styles.chatToAgentButtonContainer }, /*#__PURE__*/React.createElement(Button, { shouldFitContainer: true, onClick: function onClick(e) { e.stopPropagation(); onChatClick(e); } }, /*#__PURE__*/React.createElement(Box, { xcss: styles.chatToAgentButtonWrapper }, /*#__PURE__*/React.createElement(Inline, { space: "space.050", alignBlock: "center" }, /*#__PURE__*/React.createElement(Box, { xcss: styles.chatPillTextStyles }, formatMessage(messages.actionChatToAgent)))))), !hideMoreActions && /*#__PURE__*/React.createElement(AgentDropdownMenu, { agentId: agent.id, onDeleteAgent: handleDeleteAgent, onEditAgent: onEditAgent, onDuplicateAgent: onDuplicateAgent, onCopyAgent: onCopyAgent, isForgeAgent: isForgeAgent, loadAgentPermissions: loadAgentPermissions, loadPermissionsOnMount: true, onViewAgentFullProfileClick: onViewFullProfileClick, doesAgentHaveIdentityAccountId: !!agent.identity_account_id, shouldTriggerStopPropagation: true, dropdownMenuTestId: "agent-dropdown-menu" })), /*#__PURE__*/React.createElement(AgentDeleteConfirmationModal, { isOpen: isDeleteModalOpen, onClose: function onClose() { setIsDeleteModalOpen(false); }, onSubmit: onDeleteAgent, agentId: agent.id, agentName: agent.name })); }; var messages = defineMessages({ actionChatToAgent: { id: 'ptc-directory.agent-profile.action.dropdown.chat-with-agent', defaultMessage: 'Chat with Agent', description: 'Text for the "chat with agent" action to chat to the agent' } });