Skip to content

Commit 3959d44

Browse files
committed
feat: added ui + state for viewing malicious reports
1 parent 9cfa29d commit 3959d44

File tree

4 files changed

+151
-0
lines changed

4 files changed

+151
-0
lines changed
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { useState, useEffect } from "react";
2+
import { useDispatch, useSelector } from "react-redux";
3+
import { Card, Container, Modal, Spinner } from "react-bootstrap";
4+
import {
5+
fetchMalicousReports,
6+
resetData,
7+
} from "../store/actions/viewMalicousReportActions";
8+
9+
const ViewMalicousReports = (props) => {
10+
const accessToken = useSelector((state) => state.auth.accessToken);
11+
const reports = useSelector((state) => state.malicousReport.reports);
12+
const loading = useSelector((state) => state.malicousReport.isLoading);
13+
const dispatch = useDispatch();
14+
15+
useEffect(() => {
16+
if (!props.show) {
17+
return;
18+
}
19+
20+
dispatch(fetchMalicousReports(accessToken));
21+
}, [props.show]);
22+
23+
const onExit = () => {
24+
dispatch(resetData());
25+
};
26+
27+
return (
28+
<Modal show={props.show} onHide={props.onHide} onExit={onExit}>
29+
<Modal.Header closeButton>
30+
<Modal.Title>View Malicious Reports</Modal.Title>
31+
</Modal.Header>
32+
<Modal.Body>
33+
{loading && (
34+
<div className="d-flex justify-content-center">
35+
<Spinner
36+
animation="border"
37+
role="status"
38+
style={{ alignItems: "center" }}
39+
>
40+
<span className="visually-hidden">Loading...</span>
41+
</Spinner>
42+
</div>
43+
)}
44+
{reports.map((report, index) => {
45+
return (
46+
<Card key={index}>
47+
<Card.Body>
48+
<h5>Namespace - {report.namespace}</h5>
49+
<h6>Package - {report.package}</h6>
50+
<p style={{ textAlign: "left" }}>{report.reason}</p>
51+
</Card.Body>
52+
</Card>
53+
);
54+
})}
55+
</Modal.Body>
56+
</Modal>
57+
);
58+
};
59+
60+
export default ViewMalicousReports;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import axios from "axios";
2+
3+
export const FETCH_MALICIOUS_REPORTS = "FETCH_MALICIOUS_REPORTS";
4+
export const FETCH_MALICIOUS_REPORTS_SUCCESS =
5+
"FETCH_MALICIOUS_REPORTS_SUCCESS";
6+
export const FETCH_MALICIOUS_REPORTS_ERROR = "FETCH_MALICIOUS_REPORTS_ERROR";
7+
export const RESET_DATA = "RESET_DATA";
8+
9+
export const fetchMalicousReports = (accessToken) => {
10+
return async (dispatch) => {
11+
dispatch({ type: FETCH_MALICIOUS_REPORTS });
12+
try {
13+
const result = await axios({
14+
method: "get",
15+
url: `${process.env.REACT_APP_REGISTRY_API_URL}/report/view`,
16+
headers: {
17+
Authorization: `Bearer ${accessToken}`,
18+
},
19+
});
20+
21+
dispatch({
22+
type: FETCH_MALICIOUS_REPORTS_SUCCESS,
23+
payload: {
24+
reports: result.data.reports,
25+
},
26+
});
27+
} catch (error) {
28+
dispatch({
29+
type: FETCH_MALICIOUS_REPORTS_ERROR,
30+
payload: {
31+
statuscode: error.response.data.code,
32+
message: error.response.data.message,
33+
},
34+
});
35+
}
36+
};
37+
};
38+
39+
export const resetData = () => (dispatch) => {
40+
dispatch({
41+
type: RESET_DATA,
42+
});
43+
};

frontend/src/store/reducers/rootReducer.js

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import addRemoveNamespaceAdminReducer from "./namespaceAdminReducer";
1818
import verifyEmailReducer from "./verifyEmailReducer";
1919
import userListReducer from "./userListReducer";
2020
import reportPackageReducer from "./reportPackageReducer";
21+
import viewMalicousReportsReducer from "./viewMalicousReportsReducer";
2122

2223
const rootReducer = combineReducers({
2324
auth: authReducer,
@@ -39,6 +40,7 @@ const rootReducer = combineReducers({
3940
userList: userListReducer,
4041
archives: archivesReducer,
4142
reportPackage: reportPackageReducer,
43+
malicousReport: viewMalicousReportsReducer,
4244
});
4345

4446
export default rootReducer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {
2+
FETCH_MALICIOUS_REPORTS,
3+
FETCH_MALICIOUS_REPORTS_SUCCESS,
4+
FETCH_MALICIOUS_REPORTS_ERROR,
5+
RESET_DATA,
6+
} from "../actions/viewMalicousReportActions";
7+
8+
const initialState = {
9+
reports: [],
10+
isLoading: false,
11+
error: null,
12+
};
13+
14+
const viewMalicousReportsReducer = (state = initialState, action) => {
15+
switch (action.type) {
16+
case FETCH_MALICIOUS_REPORTS:
17+
return {
18+
...state,
19+
isLoading: true,
20+
error: null,
21+
};
22+
case FETCH_MALICIOUS_REPORTS_SUCCESS:
23+
return {
24+
...state,
25+
reports: action.payload.reports,
26+
isLoading: false,
27+
error: null,
28+
};
29+
case FETCH_MALICIOUS_REPORTS_ERROR:
30+
return {
31+
...state,
32+
isLoading: false,
33+
error: action.payload.message,
34+
};
35+
case RESET_DATA:
36+
return {
37+
reports: [],
38+
isLoading: false,
39+
error: null,
40+
};
41+
default:
42+
return state;
43+
}
44+
};
45+
46+
export default viewMalicousReportsReducer;

0 commit comments

Comments
 (0)