@atlaskit/profilecard
Version:
A React component to display a card with user information.
60 lines • 2 kB
JavaScript
import { PACKAGE_META_DATA } 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('operational.teamProfileCard.triggered.request', {
firedAt: Math.round(getPageTime()),
...PACKAGE_META_DATA
});
}
this.makeRequest(teamId, orgId).then(data => {
if (this.cache) {
this.setCachedProfile(teamId, data);
}
if (analytics) {
analytics('operational.teamProfileCard.succeeded.request', {
duration: getPageTime() - startTime,
gateway: true,
firedAt: Math.round(getPageTime()),
...PACKAGE_META_DATA
});
}
resolve(data);
}).catch(error => {
if (analytics) {
analytics('operational.teamProfileCard.failed.request', {
duration: getPageTime() - startTime,
...getErrorAttributes(error),
gateway: true,
firedAt: Math.round(getPageTime()),
...PACKAGE_META_DATA
});
}
reject(error);
});
});
}
}