index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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<{orgId: string}, {}>;
  15. type State = AsyncView['state'] & {
  16. requestList: AccessRequest[];
  17. };
  18. class OrganizationTeamsContainer extends AsyncView<Props, State> {
  19. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  20. const {orgId} = this.props.params;
  21. return [['requestList', `/organizations/${orgId}/access-requests/`]];
  22. }
  23. componentDidMount() {
  24. this.fetchStats();
  25. }
  26. fetchStats() {
  27. loadStats(this.props.api, {
  28. orgId: this.props.params.orgId,
  29. query: {
  30. since: (new Date().getTime() / 1000 - 3600 * 24).toString(),
  31. stat: 'generated',
  32. group: 'project',
  33. },
  34. });
  35. }
  36. removeAccessRequest = (id: string, isApproved: boolean) => {
  37. const requestToRemove = this.state.requestList.find(request => request.id === id);
  38. this.setState(state => ({
  39. requestList: state.requestList.filter(request => request.id !== id),
  40. }));
  41. if (isApproved && requestToRemove) {
  42. const team = requestToRemove.team;
  43. TeamStore.onUpdateSuccess(team.slug, {
  44. ...team,
  45. memberCount: team.memberCount + 1,
  46. });
  47. }
  48. };
  49. renderBody() {
  50. const {organization} = this.props;
  51. if (!organization) {
  52. return null;
  53. }
  54. return (
  55. <OrganizationTeams
  56. {...this.props}
  57. access={new Set(organization.access)}
  58. features={new Set(organization.features)}
  59. organization={organization}
  60. requestList={this.state.requestList}
  61. onRemoveAccessRequest={this.removeAccessRequest}
  62. />
  63. );
  64. }
  65. }
  66. export {OrganizationTeamsContainer};
  67. export default withApi(withOrganization(OrganizationTeamsContainer));