Skip to content

Commit f17c7c0

Browse files
committed
#1183 hook done
1 parent 9a17327 commit f17c7c0

6 files changed

Lines changed: 68 additions & 4 deletions

File tree

src/frontend/src/apis/teams.api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ export const setTeamHead = (id: string, userId: number) => {
3636
userId
3737
});
3838
};
39+
40+
export const deleteTeam = (id: string) => {
41+
return axios.post<{ message: string }>(apiUrls.teamsDelete(id));
42+
};

src/frontend/src/hooks/teams.hooks.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { useQuery, useQueryClient, useMutation } from 'react-query';
77
import { Team } from 'shared';
8-
import { getAllTeams, getSingleTeam, setTeamMembers, setTeamDescription, setTeamHead } from '../apis/teams.api';
8+
import { getAllTeams, getSingleTeam, setTeamMembers, setTeamDescription, setTeamHead, deleteTeam } from '../apis/teams.api';
99

1010
export const useAllTeams = () => {
1111
return useQuery<Team[], Error>(['teams'], async () => {
@@ -67,3 +67,19 @@ export const useEditTeamDescription = (teamId: string) => {
6767
}
6868
);
6969
};
70+
71+
export const useDeleteTeam = () => {
72+
const queryClient = useQueryClient();
73+
return useMutation<{ message: string }, Error, any>(
74+
['teams', 'delete'],
75+
async (teamId: string) => {
76+
const { data } = await deleteTeam(teamId);
77+
return data;
78+
},
79+
{
80+
onSuccess: () => {
81+
queryClient.invalidateQueries(['teams']);
82+
}
83+
}
84+
);
85+
};
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { useHistory } from 'react-router-dom';
2+
import { useToast } from '../../../hooks/toasts.hooks';
3+
import { useDeleteWorkPackage } from '../../../hooks/work-packages.hooks';
4+
import { useDeleteTeam } from '../../../hooks/teams.hooks';
5+
import LoadingIndicator from '../../../components/LoadingIndicator';
6+
import ErrorPage from '../../ErrorPage';
7+
8+
interface DeleteTeamProps {
9+
teamId: string;
10+
showModal: boolean;
11+
handleClose: () => void;
12+
}
13+
14+
export interface DeleteTeamInputs {
15+
teamId: string;
16+
}
17+
18+
const DeleteTeam: React.FC<DeleteTeamProps> = ({ teamId, showModal, handleClose }: DeleteTeamProps) => {
19+
const history = useHistory();
20+
const toast = useToast();
21+
const { isLoading, isError, error, mutateAsync } = useDeleteTeam();
22+
23+
const handleConfirm = async ({ teamId }: DeleteTeamInputs) => {
24+
try {
25+
await mutateAsync(teamId);
26+
handleClose();
27+
history.goBack();
28+
toast.success('Team deleted successfully!');
29+
} catch (e) {
30+
if (e instanceof Error) {
31+
toast.error(e.message);
32+
}
33+
}
34+
};
35+
36+
if (isLoading) return <LoadingIndicator />;
37+
if (isError) return <ErrorPage message={error?.message} />;
38+
39+
return <DeleteTeamView team={teamId} showModal={showModal} onHide={handleClose} onSubmit={handleConfirm} />;
40+
};
41+
42+
export default DeleteTeam;

src/frontend/src/pages/TeamDetailPage/DeleteTeamModalContainer/DeleteTeamView.tsx

Whitespace-only changes.

src/frontend/src/pages/TeamDetailPage/TeamDetailPage.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Grid } from '@mui/material';
22
import { useSingleTeam } from '../../hooks/teams.hooks';
33
import { useParams } from 'react-router-dom';
4-
import TeamMembersPageBlock from '../TeamsPage/TeamMembersPageBlock';
4+
import TeamMembersPageBlock from './TeamMembersPageBlock';
55
import LoadingIndicator from '../../components/LoadingIndicator';
66
import ErrorPage from '../ErrorPage';
77
import PageBlock from '../../layouts/PageBlock';
8-
import ActiveProjectCardView from '../TeamsPage/ProjectCardsView';
9-
import DescriptionPageBlock from '../TeamsPage/DescriptionPageBlock';
8+
import ActiveProjectCardView from './ProjectCardsView';
9+
import DescriptionPageBlock from './DescriptionPageBlock';
1010
import { routes } from '../../utils/routes';
1111
import PageLayout from '../../components/PageLayout';
1212

src/frontend/src/utils/urls.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const changeRequestCreateProposeSolution = () => `${changeRequestsCreate()}/prop
6868
/**************** Teams Endpoints ****************/
6969
const teams = () => `${API_URL}/teams`;
7070
const teamsById = (id: string) => `${teams()}/${id}`;
71+
const teamsDelete = (id: string) => `${teams()}/${id}`;
7172
const teamsSetMembers = (id: string) => `${teamsById(id)}/set-members`;
7273
const teamsSetHead = (id: string) => `${teamsById(id)}/set-head`;
7374
const teamsSetDescription = (id: string) => `${teamsById(id)}/edit-description`;
@@ -151,6 +152,7 @@ export const apiUrls = {
151152

152153
teams,
153154
teamsById,
155+
teamsDelete,
154156
teamsSetMembers,
155157
teamsSetHead,
156158
teamsSetDescription,

0 commit comments

Comments
 (0)