Skip to content

Commit fc12e4a

Browse files
author
Kevin Borrill
committed
Merged in feature/GFW-1041-remove-team-area (pull request #136)
Feature/GFW-1050 remove team area Approved-by: Owen Evans Approved-by: Uchenna Okafor
2 parents 3198215 + 4dc0455 commit fc12e4a

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

src/pages/area-view/AreaView.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { TTeamDataTable, TTeamDataTableAction, TTemplateDataTable, TTemplateData
1717
import RemoveTemplateModal from "./actions/RemoveTemplate";
1818
import useGetUserId from "hooks/useGetUserId";
1919
import AddTeamModal from "./actions/AddTeam";
20+
import RemoveTeamModal from "./actions/RemoveTeam";
2021

2122
interface IProps extends TPropsFromRedux {}
2223
export type TParams = {
@@ -202,7 +203,7 @@ const AreasView: FC<IProps & RouteComponentProps<TParams>> = ({
202203
<AddTeamModal teams={teamsToAdd} />
203204
</Route>
204205
<Route path={`${path}/team/remove/:teamId`}>
205-
<RemoveTemplateModal />
206+
<RemoveTeamModal />
206207
</Route>
207208
</Switch>
208209
</>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { FC, useCallback, useState } from "react";
2+
import Modal from "components/ui/Modal/Modal";
3+
import Loader from "components/ui/Loader";
4+
import { useHistory, useParams } from "react-router-dom";
5+
import { TParams as TAreaDetailParams } from "../AreaView";
6+
import { toastr } from "react-redux-toastr";
7+
import { TErrorResponse } from "constants/api";
8+
import { useAppDispatch } from "hooks/useRedux";
9+
import { FormattedMessage, useIntl } from "react-intl";
10+
import { areaService } from "services/area";
11+
import { getAreas } from "modules/areas";
12+
13+
type TParams = TAreaDetailParams & {
14+
teamId: string;
15+
};
16+
17+
interface IProps {}
18+
19+
const RemoveTeamModal: FC<IProps> = props => {
20+
const { teamId, areaId } = useParams<TParams>();
21+
const history = useHistory();
22+
const intl = useIntl();
23+
const dispatch = useAppDispatch();
24+
const [isRemoving, setIsRemoving] = useState(false);
25+
26+
const onClose = useCallback(() => {
27+
history.push(`/areas/${areaId}`);
28+
}, [history, areaId]);
29+
30+
const removeTeam = async () => {
31+
setIsRemoving(true);
32+
try {
33+
await areaService.unassignTeamFromArea(areaId, teamId);
34+
dispatch(getAreas());
35+
onClose();
36+
toastr.success(intl.formatMessage({ id: "areas.details.teams.remove.success" }), "");
37+
} catch (e: any) {
38+
const error = JSON.parse(e.message) as TErrorResponse;
39+
toastr.error(
40+
intl.formatMessage({ id: "areas.details.teams.remove.error" }),
41+
error?.errors?.length ? error.errors[0].detail : ""
42+
);
43+
console.error(e);
44+
}
45+
setIsRemoving(false);
46+
};
47+
48+
return (
49+
<Modal
50+
isOpen
51+
dismissible={false}
52+
title={"areas.details.teams.remove.title"}
53+
onClose={onClose}
54+
actions={[
55+
{ name: "common.confirm", onClick: removeTeam },
56+
{ name: "common.cancel", variant: "secondary", onClick: onClose }
57+
]}
58+
>
59+
<Loader isLoading={isRemoving} />
60+
<p>
61+
<FormattedMessage id="areas.details.teams.remove.body" />
62+
</p>
63+
</Modal>
64+
);
65+
};
66+
67+
export default RemoveTeamModal;

src/pages/area-view/actions/RemoveTemplate.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const RemoveTemplateModal: FC<IProps> = props => {
2121
const history = useHistory();
2222
const intl = useIntl();
2323
const dispatch = useAppDispatch();
24-
// const members = useAppSelector(state => state.gfwTeams.members[teamId]);
2524
const [isRemoving, setIsRemoving] = useState(false);
2625

2726
const onClose = useCallback(() => {

src/services/area.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ export class AreaService extends BaseService {
5757
return this.fetch(`/${areaId}/template/${templateId}`, { method: "DELETE" });
5858
}
5959

60+
unassignTeamFromArea(areaId: string, teamId: string) {
61+
this.token = store.getState().user.token;
62+
return this.fetch(`/${areaId}/team/${teamId}`, { method: "DELETE" });
63+
}
64+
6065
getAreaTeamIds(areaId: string) {
6166
this.token = store.getState().user.token;
6267
return this.fetchJSON(`/areaTeams/${areaId}`);

0 commit comments

Comments
 (0)