actorAvatar.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import React from 'react';
  2. import * as Sentry from '@sentry/react';
  3. import TeamAvatar from 'app/components/avatar/teamAvatar';
  4. import UserAvatar from 'app/components/avatar/userAvatar';
  5. import Tooltip from 'app/components/tooltip';
  6. import MemberListStore from 'app/stores/memberListStore';
  7. import TeamStore from 'app/stores/teamStore';
  8. import {Actor} from 'app/types';
  9. type DefaultProps = {
  10. hasTooltip: boolean;
  11. size: number;
  12. };
  13. type Props = DefaultProps & {
  14. actor: Actor;
  15. default?: string;
  16. title?: string;
  17. gravatar?: boolean;
  18. className?: string;
  19. onClick?: () => void;
  20. suggested?: boolean;
  21. tooltip?: React.ReactNode;
  22. tooltipOptions?: Omit<Tooltip['props'], 'children' | 'title'>;
  23. };
  24. class ActorAvatar extends React.Component<Props> {
  25. static defaultProps: DefaultProps = {
  26. size: 24,
  27. hasTooltip: true,
  28. };
  29. render() {
  30. const {actor, ...props} = this.props;
  31. if (actor.type === 'user') {
  32. const user = actor.id ? MemberListStore.getById(actor.id) ?? actor : actor;
  33. return <UserAvatar user={user} {...props} />;
  34. }
  35. if (actor.type === 'team') {
  36. const team = TeamStore.getById(actor.id);
  37. return <TeamAvatar team={team} {...props} />;
  38. }
  39. Sentry.withScope(scope => {
  40. scope.setExtra('actor', actor);
  41. Sentry.captureException(new Error('Unknown avatar type'));
  42. });
  43. return null;
  44. }
  45. }
  46. export default ActorAvatar;