Skip to content

Commit 6d46f8d

Browse files
committed
build releated notifications handeled
1 parent 9c9b399 commit 6d46f8d

File tree

4 files changed

+30
-23
lines changed

4 files changed

+30
-23
lines changed

src/components/BuildList.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import { BuildStatusChip } from "./BuildStatusChip";
2424
import { SkeletonList } from "./SkeletonList";
2525
import { formatDateTime } from "../_helpers/format.helper";
26+
import { useSnackbar } from "notistack";
2627

2728
const useStyles = makeStyles((theme: Theme) =>
2829
createStyles({
@@ -42,6 +43,7 @@ const BuildList: FunctionComponent = () => {
4243
const history = useHistory();
4344
const { buildList, selectedBuildId, loading } = useBuildState();
4445
const buildDispatch = useBuildDispatch();
46+
const { enqueueSnackbar } = useSnackbar();
4547

4648
return (
4749
<List>
@@ -98,7 +100,17 @@ const BuildList: FunctionComponent = () => {
98100
>
99101
<IconButton
100102
onClick={() => {
101-
deleteBuild(buildDispatch, build.id);
103+
deleteBuild(buildDispatch, build.id)
104+
.then((b) =>
105+
enqueueSnackbar(`${b.id} removed`, {
106+
variant: "success",
107+
})
108+
)
109+
.catch((err) =>
110+
enqueueSnackbar(err, {
111+
variant: "error",
112+
})
113+
);
102114
}}
103115
>
104116
<Delete />

src/contexts/build.context.tsx

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function buildReducer(state: State, action: IAction): State {
9393
...state,
9494
buildList: state.buildList.map((p) => {
9595
if (p.id === action.payload.id) {
96-
return action.payload
96+
return action.payload;
9797
}
9898
return p;
9999
}),
@@ -134,27 +134,16 @@ function useBuildDispatch() {
134134
async function getBuildList(dispatch: Dispatch, id: string) {
135135
dispatch({ type: "request" });
136136

137-
buildsService
138-
.getList(id)
139-
.then((items) => {
140-
dispatch({ type: "get", payload: items });
141-
})
142-
.catch((error) => {
143-
console.log(error.toString());
144-
});
137+
return buildsService.getList(id).then((items) => {
138+
dispatch({ type: "get", payload: items });
139+
});
145140
}
146141

147142
async function deleteBuild(dispatch: Dispatch, id: string) {
148-
buildsService
149-
.remove(id)
150-
.then((isDeleted) => {
151-
if (isDeleted) {
152-
dispatch({ type: "delete", payload: id });
153-
}
154-
})
155-
.catch((error) => {
156-
console.log(error.toString());
157-
});
143+
return buildsService.remove(id).then((build) => {
144+
dispatch({ type: "delete", payload: id });
145+
return build;
146+
});
158147
}
159148

160149
async function selectBuild(dispatch: Dispatch, id: string) {

src/pages/ProjectPage.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
selectTestRun,
2828
getTestRunList,
2929
} from "../contexts";
30+
import { useSnackbar } from "notistack";
3031

3132
const getQueryParams = (guery: string) => {
3233
const queryParams = qs.parse(guery, { ignoreQueryPrefix: true });
@@ -67,6 +68,7 @@ const ProjectPage = () => {
6768
const { projectId } = useParams();
6869
const location = useLocation();
6970
const history = useHistory();
71+
const { enqueueSnackbar } = useSnackbar();
7072
const { buildList, selectedBuildId } = useBuildState();
7173
const buildDispatch = useBuildDispatch();
7274
const {
@@ -87,9 +89,13 @@ const ProjectPage = () => {
8789

8890
useEffect(() => {
8991
if (projectId) {
90-
getBuildList(buildDispatch, projectId);
92+
getBuildList(buildDispatch, projectId).catch((err) =>
93+
enqueueSnackbar(err, {
94+
variant: "error",
95+
})
96+
);
9197
}
92-
}, [projectId, buildDispatch]);
98+
}, [projectId, buildDispatch, enqueueSnackbar]);
9399

94100
useEffect(() => {
95101
if (selectedBuildId) {

src/services/builds.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function getList(projectId: string): Promise<Build[]> {
2020
);
2121
}
2222

23-
function remove(id: string): Promise<number> {
23+
function remove(id: string): Promise<Build> {
2424
const requestOptions = {
2525
method: "DELETE",
2626
headers: authHeader(),

0 commit comments

Comments
 (0)