@atlaskit/editor-plugin-mentions
Version:
Mentions plugin for @atlaskit/editor-core
185 lines (184 loc) • 8.18 kB
JavaScript
/* ProfileCardComponent.tsx generated by @compiled/babel-plugin v0.39.1 */
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
import "./ProfileCardComponent.compiled.css";
import * as React from 'react';
import { ax, ix } from "@compiled/react/runtime";
import _regeneratorRuntime from "@babel/runtime/regenerator";
import { useEffect, useState, useMemo } from 'react';
import { bind } from 'bind-event-listener';
import { ProfileCardLazy } from '@atlaskit/profilecard/user';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { Popup } from './PopperWrapper';
var styles = {
loadingStyles: "_2rko12b0 _16qs130s"
};
var LoadingWrapper = function LoadingWrapper(_ref) {
var children = _ref.children,
isLoading = _ref.isLoading;
return isLoading ? /*#__PURE__*/React.createElement("div", {
className: ax([styles.loadingStyles])
}, children) : children;
};
export var useProfileCardState = function useProfileCardState(_ref2) {
var id = _ref2.id,
provider = _ref2.provider;
var _useState = useState(),
_useState2 = _slicedToArray(_useState, 2),
data = _useState2[0],
setData = _useState2[1];
var _useState3 = useState(undefined),
_useState4 = _slicedToArray(_useState3, 2),
reportingLinesData = _useState4[0],
setReportingLinesData = _useState4[1];
var _useState5 = useState(false),
_useState6 = _slicedToArray(_useState5, 2),
shouldShowGiveKudos = _useState6[0],
setShouldShowGiveKudos = _useState6[1];
var _useState7 = useState(undefined),
_useState8 = _slicedToArray(_useState7, 2),
teamCentralBaseUrl = _useState8[0],
setTeamCentralBaseUrl = _useState8[1];
var _useState9 = useState(false),
_useState0 = _slicedToArray(_useState9, 2),
isLoading = _useState0[0],
setIsLoading = _useState0[1];
var _useState1 = useState(false),
_useState10 = _slicedToArray(_useState1, 2),
hasError = _useState10[0],
setHasError = _useState10[1];
// From: packages/people-and-teams/profilecard/src/components/User/ProfileCardTrigger.tsx
useEffect(function () {
var fetchData = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var _yield$Promise$all, _yield$Promise$all2, _data, reportingLines, shouldGiveKudos, _teamCentralBaseUrl;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!(!id || !provider)) {
_context.next = 2;
break;
}
return _context.abrupt("return");
case 2:
setIsLoading(true);
_context.prev = 3;
_context.next = 6;
return Promise.all([provider === null || provider === void 0 ? void 0 : provider.resourceClient.getProfile((provider === null || provider === void 0 ? void 0 : provider.cloudId) || '', id, function () {}), provider === null || provider === void 0 ? void 0 : provider.resourceClient.getReportingLines(id), provider === null || provider === void 0 ? void 0 : provider.resourceClient.shouldShowGiveKudos(), provider === null || provider === void 0 ? void 0 : provider.resourceClient.getTeamCentralBaseUrl({
withOrgContext: true,
withSiteContext: true
})]);
case 6:
_yield$Promise$all = _context.sent;
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 4);
_data = _yield$Promise$all2[0];
reportingLines = _yield$Promise$all2[1];
shouldGiveKudos = _yield$Promise$all2[2];
_teamCentralBaseUrl = _yield$Promise$all2[3];
setData(_data);
setReportingLinesData(reportingLines);
setShouldShowGiveKudos(shouldGiveKudos !== null && shouldGiveKudos !== void 0 ? shouldGiveKudos : false);
setTeamCentralBaseUrl(_teamCentralBaseUrl);
setHasError(false);
_context.next = 22;
break;
case 19:
_context.prev = 19;
_context.t0 = _context["catch"](3);
setHasError(true);
case 22:
_context.prev = 22;
setIsLoading(false);
return _context.finish(22);
case 25:
case "end":
return _context.stop();
}
}, _callee, null, [[3, 19, 22, 25]]);
}));
return function fetchData() {
return _ref3.apply(this, arguments);
};
}();
fetchData();
}, [id, provider]);
return {
data: data,
reportingLinesData: reportingLinesData,
shouldShowGiveKudos: shouldShowGiveKudos,
teamCentralBaseUrl: teamCentralBaseUrl,
isLoading: isLoading,
hasError: hasError
};
};
export function ProfileCardComponent(_ref4) {
var _ref6;
var profilecardProvider = _ref4.profilecardProvider,
activeMention = _ref4.activeMention,
dom = _ref4.dom,
closeComponent = _ref4.closeComponent;
var _useState11 = useState(undefined),
_useState12 = _slicedToArray(_useState11, 2),
provider = _useState12[0],
setProvider = _useState12[1];
useEffect(function () {
profilecardProvider === null || profilecardProvider === void 0 || profilecardProvider.then(function (p) {
setProvider(p);
});
}, [profilecardProvider]);
var _ref5 = (_ref6 = activeMention.attrs) !== null && _ref6 !== void 0 ? _ref6 : {},
id = _ref5.id,
text = _ref5.text,
accessLevel = _ref5.accessLevel;
var actions = useMemo(function () {
return provider === null || provider === void 0 ? void 0 : provider.getActions(id, text !== null && text !== void 0 ? text : '', accessLevel);
}, [accessLevel, id, provider, text]);
var _useProfileCardState = useProfileCardState({
id: id,
provider: provider
}),
data = _useProfileCardState.data,
reportingLinesData = _useProfileCardState.reportingLinesData,
shouldShowGiveKudos = _useProfileCardState.shouldShowGiveKudos,
teamCentralBaseUrl = _useProfileCardState.teamCentralBaseUrl,
isLoading = _useProfileCardState.isLoading,
hasError = _useProfileCardState.hasError;
useEffect(function () {
return bind(window, {
type: 'keydown',
listener: function listener(e) {
if (e.key === 'Escape') {
closeComponent();
}
}
});
});
return /*#__PURE__*/React.createElement(Popup, {
referenceElement: dom
}, /*#__PURE__*/React.createElement(LoadingWrapper, {
isLoading: isLoading
}, /*#__PURE__*/React.createElement(ProfileCardLazy, {
avatarUrl: data === null || data === void 0 ? void 0 : data.avatarUrl,
accountType: data === null || data === void 0 ? void 0 : data.accountType,
status: data === null || data === void 0 ? void 0 : data.status,
statusModifiedDate: data === null || data === void 0 ? void 0 : data.statusModifiedDate,
timestring: data === null || data === void 0 ? void 0 : data.timestring,
isCurrentUser: data === null || data === void 0 ? void 0 : data.isCurrentUser,
isBot: data === null || data === void 0 ? void 0 : data.isBot,
fullName: data === null || data === void 0 ? void 0 : data.fullName,
userId: id,
cloudId: provider === null || provider === void 0 ? void 0 : provider.cloudId,
actions: actions,
isLoading: isLoading,
location: data === null || data === void 0 ? void 0 : data.location,
companyName: data === null || data === void 0 ? void 0 : data.companyName,
customLozenges: data === null || data === void 0 ? void 0 : data.customLozenges,
nickname: data === null || data === void 0 ? void 0 : data.nickname,
email: data === null || data === void 0 ? void 0 : data.email,
hasError: hasError,
reportingLines: reportingLinesData,
isKudosEnabled: shouldShowGiveKudos,
teamCentralBaseUrl: teamCentralBaseUrl,
isRenderedInPortal: expValEquals('editor_a11y_7152_profile_card_tab_order', 'isEnabled', true)
})));
}