createTeamModal.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {Fragment} from 'react';
  2. import {ModalRenderProps} from 'sentry/actionCreators/modal';
  3. import {createTeam} from 'sentry/actionCreators/teams';
  4. import CreateTeamForm from 'sentry/components/teams/createTeamForm';
  5. import {t} from 'sentry/locale';
  6. import {Organization, Team} from 'sentry/types';
  7. import useApi from 'sentry/utils/useApi';
  8. type Props = ModalRenderProps & {
  9. organization: Organization;
  10. onClose?: (team: Team) => void;
  11. };
  12. function CreateTeamModal({Body, Header, ...props}: Props) {
  13. const {onClose, closeModal, organization} = props;
  14. const api = useApi();
  15. async function handleSubmit(
  16. data: {slug: string},
  17. onSuccess: Function,
  18. onError: Function
  19. ) {
  20. try {
  21. const team: Team = await createTeam(api, data, {orgId: organization.slug});
  22. closeModal();
  23. onClose?.(team);
  24. onSuccess(team);
  25. } catch (err) {
  26. onError(err);
  27. }
  28. }
  29. return (
  30. <Fragment>
  31. <Header closeButton>{t('Create Team')}</Header>
  32. <Body>
  33. <CreateTeamForm {...props} onSubmit={handleSubmit} />
  34. </Body>
  35. </Fragment>
  36. );
  37. }
  38. export default CreateTeamModal;