index.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {RouteComponentProps} from 'react-router';
  2. import {loadStats} from 'sentry/actionCreators/projects';
  3. import {Client} from 'sentry/api';
  4. import TeamStore from 'sentry/stores/teamStore';
  5. import {AccessRequest, Organization, Team} from 'sentry/types';
  6. import withApi from 'sentry/utils/withApi';
  7. import withOrganization from 'sentry/utils/withOrganization';
  8. import AsyncView from 'sentry/views/asyncView';
  9. import OrganizationTeams from './organizationTeams';
  10. type Props = {
  11. api: Client;
  12. organization: Organization;
  13. teams: Team[];
  14. } & RouteComponentProps<{}, {}>;
  15. type State = AsyncView['state'] & {
  16. requestList: AccessRequest[];
  17. };
  18. class OrganizationTeamsContainer extends AsyncView<Props, State> {
  19. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  20. const {organization} = this.props;
  21. return [['requestList', `/organizations/${organization.slug}/access-requests/`]];
  22. }
  23. componentDidMount() {
  24. this.fetchStats();
  25. }
  26. fetchStats() {
  27. const {organization} = this.props;
  28. loadStats(this.props.api, {
  29. orgId: organization.slug,
  30. query: {
  31. since: (new Date().getTime() / 1000 - 3600 * 24).toString(),
  32. stat: 'generated',
  33. group: 'project',
  34. },
  35. });
  36. }
  37. removeAccessRequest = (id: string, isApproved: boolean) => {
  38. const requestToRemove = this.state.requestList.find(request => request.id === id);
  39. this.setState(state => ({
  40. requestList: state.requestList.filter(request => request.id !== id),
  41. }));
  42. if (isApproved && requestToRemove) {
  43. const team = requestToRemove.team;
  44. TeamStore.onUpdateSuccess(team.slug, {
  45. ...team,
  46. memberCount: team.memberCount + 1,
  47. });
  48. }
  49. };
  50. renderBody() {
  51. const {organization} = this.props;
  52. if (!organization) {
  53. return null;
  54. }
  55. return (
  56. <OrganizationTeams
  57. {...this.props}
  58. access={new Set(organization.access)}
  59. features={new Set(organization.features)}
  60. organization={organization}
  61. requestList={this.state.requestList}
  62. onRemoveAccessRequest={this.removeAccessRequest}
  63. />
  64. );
  65. }
  66. }
  67. export {OrganizationTeamsContainer};
  68. export default withApi(withOrganization(OrganizationTeamsContainer));