@atlaskit/profilecard
Version:
A React component to display a card with user information.
104 lines • 3.77 kB
JavaScript
/* Actions.tsx generated by @compiled/babel-plugin v0.39.1 */
import "./Actions.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
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';
const styles = {
chatToAgentButtonContainer: "_1bsb1osq",
chatToAgentButtonWrapper: "_1e0c1txw _1bah1h6o _k48p1wq8 _4t3igktf",
chatPillTextStyles: "_1nmz1hna _y3gn1e5h _o5721jtm",
actionsWrapperStyles: "_ca0qutpp _u5f3utpp _n3tdutpp _19bvutpp _syazi7uo"
};
export const AgentActions = ({
onEditAgent,
onDeleteAgent,
onDuplicateAgent,
onCopyAgent,
onChatClick,
onViewFullProfileClick,
agent,
resourceClient,
hideMoreActions
}) => {
const {
formatMessage
} = useIntl();
const {
fireEvent
} = useAnalyticsEvents();
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const isForgeAgent = agent.creator_type === 'FORGE' || agent.creator_type === 'THIRD_PARTY';
const loadAgentPermissions = useCallback(async () => {
const {
permissions: {
AGENT_CREATE,
AGENT_UPDATE,
AGENT_DEACTIVATE
}
} = await resourceClient.getRovoAgentPermissions(agent.id);
return {
isCreateEnabled: AGENT_CREATE.permitted,
isEditEnabled: AGENT_UPDATE.permitted,
isDeleteEnabled: AGENT_DEACTIVATE.permitted
};
}, [agent.id, resourceClient]);
const handleDeleteAgent = useCallback(() => {
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: 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: () => {
setIsDeleteModalOpen(false);
},
onSubmit: onDeleteAgent,
agentId: agent.id,
agentName: agent.name
}));
};
const 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'
}
});