import {cloneElement, isValidElement, useState} from 'react';
import {browserHistory, RouteComponentProps} from 'react-router';
import styled from '@emotion/styled';
import {addErrorMessage, addSuccessMessage} from 'sentry/actionCreators/indicator';
import {joinTeam} from 'sentry/actionCreators/teams';
import Alert from 'sentry/components/alert';
import Button from 'sentry/components/button';
import IdBadge from 'sentry/components/idBadge';
import ListLink from 'sentry/components/links/listLink';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import NavTabs from 'sentry/components/navTabs';
import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
import {t, tct} from 'sentry/locale';
import TeamStore from 'sentry/stores/teamStore';
import {Team} from 'sentry/types';
import recreateRoute from 'sentry/utils/recreateRoute';
import useApi from 'sentry/utils/useApi';
import useTeams from 'sentry/utils/useTeams';
type Props = {
children: React.ReactNode;
} & RouteComponentProps<{orgId: string; teamId: string}, {}>;
function TeamDetails({children, ...props}: Props) {
const api = useApi();
const [currentTeam, setCurrentTeam] = useState(
TeamStore.getBySlug(props.params.teamId)
);
const [requesting, setRequesting] = useState(false);
function handleRequestAccess(team: Team) {
if (!team) {
return;
}
setRequesting(true);
joinTeam(
api,
{
orgId: props.params.orgId,
teamId: team.slug,
},
{
success: () => {
addSuccessMessage(
tct('You have requested access to [team]', {
team: `#${team.slug}`,
})
);
setRequesting(false);
},
error: () => {
addErrorMessage(
tct('Unable to request access to [team]', {
team: `#${team.slug}`,
})
);
setRequesting(false);
},
}
);
}
function onTeamChange(data: Team) {
if (currentTeam !== data) {
const orgId = props.params.orgId;
browserHistory.replace(`/organizations/${orgId}/teams/${data.slug}/settings/`);
} else {
setCurrentTeam({...currentTeam, ...data});
}
}
// `/organizations/${orgId}/teams/${teamId}`;
const routePrefix = recreateRoute('', {
routes: props.routes,
params: props.params,
stepBack: -1,
});
const navigationTabs = [