@atlaskit/profilecard
Version:
A React component to display a card with user information.
53 lines • 1.71 kB
JavaScript
import { teamRequestAnalytics } from '../util/analytics';
import { getPageTime } from '../util/performance';
import CachingClient from './CachingClient';
import { getErrorAttributes } from './errorUtils';
import { getTeamFromAGG } from './getTeamFromAGG';
export default class TeamProfileCardClient extends CachingClient {
constructor(options) {
super(options);
this.options = options;
}
makeRequest(teamId, _orgId) {
if (!this.options.gatewayGraphqlUrl) {
throw new Error('Trying to fetch via gateway with no specified config.gatewayGraphqlUrl');
}
return getTeamFromAGG(this.options.gatewayGraphqlUrl, teamId, this.options.cloudId);
}
getProfile(teamId, orgId, analytics) {
if (!teamId) {
return Promise.reject(new Error('teamId is missing'));
}
const cache = this.getCachedProfile(teamId);
if (cache) {
return Promise.resolve(cache);
}
return new Promise((resolve, reject) => {
const startTime = getPageTime();
if (analytics) {
analytics(teamRequestAnalytics('triggered'));
}
this.makeRequest(teamId, orgId).then(data => {
if (this.cache) {
this.setCachedProfile(teamId, data);
}
if (analytics) {
analytics(teamRequestAnalytics('succeeded', {
duration: getPageTime() - startTime,
gateway: true
}));
}
resolve(data);
}).catch(error => {
if (analytics) {
analytics(teamRequestAnalytics('failed', {
duration: getPageTime() - startTime,
...getErrorAttributes(error),
gateway: true
}));
}
reject(error);
});
});
}
}