index.tsx 2.3 KB

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