diff --git a/src/UIs/bff/reactjs/src/containers/AuditLogs/AuditLogs.tsx b/src/UIs/bff/reactjs/src/containers/AuditLogs/AuditLogs.tsx index 98bb454e5..5ec8407c2 100644 --- a/src/UIs/bff/reactjs/src/containers/AuditLogs/AuditLogs.tsx +++ b/src/UIs/bff/reactjs/src/containers/AuditLogs/AuditLogs.tsx @@ -1,29 +1,38 @@ import { useState, useEffect } from "react"; -import { useDispatch, useSelector } from "react-redux"; import Pagination from "../../components/Pagination/Pagination"; -import * as actions from "./actions"; +import axios from "./axios"; const AuditLogs = () => { const [pageTitle] = useState("Audit Logs"); const [currentPage, setCurrentPage] = useState(1); + const [auditLogs, setAuditLogs] = useState([]); + const [totalItems, setTotalItems] = useState(0); const pageSize = 5; - const dispatch = useDispatch(); - - const { auditLogs, totalItems } = useSelector((state: any) => state.auditLog); useEffect(() => { - dispatch(actions.fetchAuditLogs(currentPage, pageSize)); - }, [dispatch]); + fetchAuditLogs(currentPage, pageSize); + }, []); + + const fetchAuditLogs = async (currentPage: number, pageSize: number) => { + try { + const response = await axios.get("paged?page=" + currentPage + "&pageSize=" + pageSize); + const data = response.data; + setAuditLogs(data.items); + setTotalItems(data.totalItems); + } catch (error) { + // + } + }; - const formatDateTime = (value) => { + const formatDateTime = (value: string) => { if (!value) return value; - var date = new Date(value); + const date = new Date(value); return date.toLocaleDateString() + " " + date.toLocaleTimeString(); }; - const pageSelected = (page) => { + const pageSelected = async (page: number) => { setCurrentPage(page); - dispatch(actions.fetchAuditLogs(page, pageSize)); + await fetchAuditLogs(page, pageSize); }; const rows = auditLogs?.map((auditLog) => ( diff --git a/src/UIs/bff/reactjs/src/containers/AuditLogs/actionTypes.tsx b/src/UIs/bff/reactjs/src/containers/AuditLogs/actionTypes.tsx deleted file mode 100644 index 52e257d4c..000000000 --- a/src/UIs/bff/reactjs/src/containers/AuditLogs/actionTypes.tsx +++ /dev/null @@ -1,4 +0,0 @@ -export const FETCH_AUDIT_LOGS = "FETCH_AUDIT_LOGS"; -export const FETCH_AUDIT_LOGS_START = "FETCH_AUDIT_LOGS_START"; -export const FETCH_AUDIT_LOGS_SUCCESS = "FETCH_AUDIT_LOGS_SUCCESS"; -export const FETCH_AUDIT_LOGS_FAIL = "FETCH_AUDIT_LOGS_FAIL"; diff --git a/src/UIs/bff/reactjs/src/containers/AuditLogs/actions.tsx b/src/UIs/bff/reactjs/src/containers/AuditLogs/actions.tsx deleted file mode 100644 index a19e986bc..000000000 --- a/src/UIs/bff/reactjs/src/containers/AuditLogs/actions.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import * as actionTypes from "./actionTypes"; - -/// FETCH AUDIT LOGS -export const fetchAuditLogsSuccess = (auditLogs) => { - return { - type: actionTypes.FETCH_AUDIT_LOGS_SUCCESS, - auditLogs: auditLogs.items, - totalItems: auditLogs.totalItems - }; -}; - -export const fetchAuditLogsFail = (error) => { - return { - type: actionTypes.FETCH_AUDIT_LOGS_FAIL, - error: error, - }; -}; - -export const fetchAuditLogsStart = () => { - return { - type: actionTypes.FETCH_AUDIT_LOGS_START, - }; -}; - -export const fetchAuditLogs = (page: number, pageSize: number) => { - return { - type: actionTypes.FETCH_AUDIT_LOGS, - page, - pageSize - }; -}; -/// FETCH AUDIT LOGS diff --git a/src/UIs/bff/reactjs/src/containers/AuditLogs/reducer.tsx b/src/UIs/bff/reactjs/src/containers/AuditLogs/reducer.tsx deleted file mode 100644 index 8da2117f7..000000000 --- a/src/UIs/bff/reactjs/src/containers/AuditLogs/reducer.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { updateObject } from "../../shared/utility"; -import * as actionTypes from "./actionTypes"; - -const initialState = { - auditLogs: [], - totalItems: 0, - loading: false, - error: null, -}; - -const reducer = (state = initialState, action) => { - switch (action.type) { - case actionTypes.FETCH_AUDIT_LOGS_START: - return updateObject(state, { - loading: true, - }); - case actionTypes.FETCH_AUDIT_LOGS_SUCCESS: - return updateObject(state, { - auditLogs: action.auditLogs, - totalItems: action.totalItems, - loading: false, - }); - case actionTypes.FETCH_AUDIT_LOGS_FAIL: - return updateObject(state, { - error: action.error, - loading: false, - }); - default: - return state; - } -}; - -export default reducer; diff --git a/src/UIs/bff/reactjs/src/containers/AuditLogs/sagas.tsx b/src/UIs/bff/reactjs/src/containers/AuditLogs/sagas.tsx deleted file mode 100644 index b9fedc536..000000000 --- a/src/UIs/bff/reactjs/src/containers/AuditLogs/sagas.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { put, takeEvery } from "redux-saga/effects"; -import axios from "./axios"; - -import * as actionTypes from "./actionTypes"; -import * as actions from "./actions"; - -export function* fetchAuditLogsSaga(action) { - yield put(actions.fetchAuditLogsStart()); - try { - const response = yield axios.get("paged?page=" + action.page + "&pageSize=" + action.pageSize); - const fetchedAuditLogs = response.data; - yield put(actions.fetchAuditLogsSuccess(fetchedAuditLogs)); - } catch (error) { - yield put(actions.fetchAuditLogsFail(error)); - } -} - -export function* watchAuditLog() { - yield takeEvery(actionTypes.FETCH_AUDIT_LOGS, fetchAuditLogsSaga); -} diff --git a/src/UIs/bff/reactjs/src/containers/Files/ListFiles/ListFiles.tsx b/src/UIs/bff/reactjs/src/containers/Files/ListFiles/ListFiles.tsx index d50b22f2d..652077ff0 100644 --- a/src/UIs/bff/reactjs/src/containers/Files/ListFiles/ListFiles.tsx +++ b/src/UIs/bff/reactjs/src/containers/Files/ListFiles/ListFiles.tsx @@ -3,19 +3,17 @@ import { NavLink } from "react-router-dom"; import { Modal, Button } from "react-bootstrap"; import axios from "../axios"; -type Props = {}; - type State = { pageTitle: string; showDeleteModal: boolean; - deletingFile: any; + deletingFile: {}; showAuditLogsModal: boolean; - files: any; - auditLogs: any; - errorMessage: any; + files: []; + auditLogs: []; + errorMessage: string; }; -class ListFiles extends Component { +class ListFiles extends Component { state = { pageTitle: "Files", showDeleteModal: false, @@ -79,7 +77,7 @@ class ListFiles extends Component { } }; - formatDateTime = (value) => { + formatDateTime = (value: string) => { if (!value) return value; const date = new Date(value); return date.toLocaleDateString() + " " + date.toLocaleTimeString(); diff --git a/src/UIs/bff/reactjs/src/index.tsx b/src/UIs/bff/reactjs/src/index.tsx index 3da82c9de..947b7bcca 100644 --- a/src/UIs/bff/reactjs/src/index.tsx +++ b/src/UIs/bff/reactjs/src/index.tsx @@ -9,8 +9,6 @@ import "./index.css"; import App from "./App"; import { loadUser, isAuthenticated } from "./containers/Auth/authService"; import authReducer from "./containers/Auth/reducer"; -import auditLogReducer from "./containers/AuditLogs/reducer"; -import { watchAuditLog } from "./containers/AuditLogs/sagas"; import configurationEntryReducer from "./containers/Settings/reducer"; import { watchConfigurationEntry } from "./containers/Settings/sagas"; import productReducer from "./containers/Products/reducer"; @@ -23,7 +21,6 @@ const rootReducer = combineReducers({ configurationEntry: configurationEntryReducer, product: productReducer, user: userReducer, - auditLog: auditLogReducer, }); const sagaMiddleware = createSagaMiddleware(); @@ -38,27 +35,26 @@ const store = configureStore({ sagaMiddleware.run(watchConfigurationEntry); sagaMiddleware.run(watchProduct); sagaMiddleware.run(watchUser); -sagaMiddleware.run(watchAuditLog); loadUser() - .then((user) => { - if (isAuthenticated()) { - store.dispatch({ - type: "LOGIN", - user: { access_token: user!.access_token, expires_in: user!.expires_in }, - }); - } - }) - .finally(() => { - const container = document.getElementById("root"); - const root = createRoot(container!); - root.render( - - - - - - - - ); - }); + .then((user) => { + if (isAuthenticated()) { + store.dispatch({ + type: "LOGIN", + user: { access_token: user!.access_token, expires_in: user!.expires_in }, + }); + } + }) + .finally(() => { + const container = document.getElementById("root"); + const root = createRoot(container!); + root.render( + + + + + + + + ); + }); diff --git a/src/UIs/reactjs/src/containers/AuditLogs/AuditLogs.tsx b/src/UIs/reactjs/src/containers/AuditLogs/AuditLogs.tsx index 98bb454e5..5ec8407c2 100644 --- a/src/UIs/reactjs/src/containers/AuditLogs/AuditLogs.tsx +++ b/src/UIs/reactjs/src/containers/AuditLogs/AuditLogs.tsx @@ -1,29 +1,38 @@ import { useState, useEffect } from "react"; -import { useDispatch, useSelector } from "react-redux"; import Pagination from "../../components/Pagination/Pagination"; -import * as actions from "./actions"; +import axios from "./axios"; const AuditLogs = () => { const [pageTitle] = useState("Audit Logs"); const [currentPage, setCurrentPage] = useState(1); + const [auditLogs, setAuditLogs] = useState([]); + const [totalItems, setTotalItems] = useState(0); const pageSize = 5; - const dispatch = useDispatch(); - - const { auditLogs, totalItems } = useSelector((state: any) => state.auditLog); useEffect(() => { - dispatch(actions.fetchAuditLogs(currentPage, pageSize)); - }, [dispatch]); + fetchAuditLogs(currentPage, pageSize); + }, []); + + const fetchAuditLogs = async (currentPage: number, pageSize: number) => { + try { + const response = await axios.get("paged?page=" + currentPage + "&pageSize=" + pageSize); + const data = response.data; + setAuditLogs(data.items); + setTotalItems(data.totalItems); + } catch (error) { + // + } + }; - const formatDateTime = (value) => { + const formatDateTime = (value: string) => { if (!value) return value; - var date = new Date(value); + const date = new Date(value); return date.toLocaleDateString() + " " + date.toLocaleTimeString(); }; - const pageSelected = (page) => { + const pageSelected = async (page: number) => { setCurrentPage(page); - dispatch(actions.fetchAuditLogs(page, pageSize)); + await fetchAuditLogs(page, pageSize); }; const rows = auditLogs?.map((auditLog) => ( diff --git a/src/UIs/reactjs/src/containers/AuditLogs/actionTypes.tsx b/src/UIs/reactjs/src/containers/AuditLogs/actionTypes.tsx deleted file mode 100644 index 52e257d4c..000000000 --- a/src/UIs/reactjs/src/containers/AuditLogs/actionTypes.tsx +++ /dev/null @@ -1,4 +0,0 @@ -export const FETCH_AUDIT_LOGS = "FETCH_AUDIT_LOGS"; -export const FETCH_AUDIT_LOGS_START = "FETCH_AUDIT_LOGS_START"; -export const FETCH_AUDIT_LOGS_SUCCESS = "FETCH_AUDIT_LOGS_SUCCESS"; -export const FETCH_AUDIT_LOGS_FAIL = "FETCH_AUDIT_LOGS_FAIL"; diff --git a/src/UIs/reactjs/src/containers/AuditLogs/actions.tsx b/src/UIs/reactjs/src/containers/AuditLogs/actions.tsx deleted file mode 100644 index a19e986bc..000000000 --- a/src/UIs/reactjs/src/containers/AuditLogs/actions.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import * as actionTypes from "./actionTypes"; - -/// FETCH AUDIT LOGS -export const fetchAuditLogsSuccess = (auditLogs) => { - return { - type: actionTypes.FETCH_AUDIT_LOGS_SUCCESS, - auditLogs: auditLogs.items, - totalItems: auditLogs.totalItems - }; -}; - -export const fetchAuditLogsFail = (error) => { - return { - type: actionTypes.FETCH_AUDIT_LOGS_FAIL, - error: error, - }; -}; - -export const fetchAuditLogsStart = () => { - return { - type: actionTypes.FETCH_AUDIT_LOGS_START, - }; -}; - -export const fetchAuditLogs = (page: number, pageSize: number) => { - return { - type: actionTypes.FETCH_AUDIT_LOGS, - page, - pageSize - }; -}; -/// FETCH AUDIT LOGS diff --git a/src/UIs/reactjs/src/containers/AuditLogs/reducer.tsx b/src/UIs/reactjs/src/containers/AuditLogs/reducer.tsx deleted file mode 100644 index 8da2117f7..000000000 --- a/src/UIs/reactjs/src/containers/AuditLogs/reducer.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { updateObject } from "../../shared/utility"; -import * as actionTypes from "./actionTypes"; - -const initialState = { - auditLogs: [], - totalItems: 0, - loading: false, - error: null, -}; - -const reducer = (state = initialState, action) => { - switch (action.type) { - case actionTypes.FETCH_AUDIT_LOGS_START: - return updateObject(state, { - loading: true, - }); - case actionTypes.FETCH_AUDIT_LOGS_SUCCESS: - return updateObject(state, { - auditLogs: action.auditLogs, - totalItems: action.totalItems, - loading: false, - }); - case actionTypes.FETCH_AUDIT_LOGS_FAIL: - return updateObject(state, { - error: action.error, - loading: false, - }); - default: - return state; - } -}; - -export default reducer; diff --git a/src/UIs/reactjs/src/containers/AuditLogs/sagas.tsx b/src/UIs/reactjs/src/containers/AuditLogs/sagas.tsx deleted file mode 100644 index b9fedc536..000000000 --- a/src/UIs/reactjs/src/containers/AuditLogs/sagas.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { put, takeEvery } from "redux-saga/effects"; -import axios from "./axios"; - -import * as actionTypes from "./actionTypes"; -import * as actions from "./actions"; - -export function* fetchAuditLogsSaga(action) { - yield put(actions.fetchAuditLogsStart()); - try { - const response = yield axios.get("paged?page=" + action.page + "&pageSize=" + action.pageSize); - const fetchedAuditLogs = response.data; - yield put(actions.fetchAuditLogsSuccess(fetchedAuditLogs)); - } catch (error) { - yield put(actions.fetchAuditLogsFail(error)); - } -} - -export function* watchAuditLog() { - yield takeEvery(actionTypes.FETCH_AUDIT_LOGS, fetchAuditLogsSaga); -} diff --git a/src/UIs/reactjs/src/containers/Files/ListFiles/ListFiles.tsx b/src/UIs/reactjs/src/containers/Files/ListFiles/ListFiles.tsx index d50b22f2d..652077ff0 100644 --- a/src/UIs/reactjs/src/containers/Files/ListFiles/ListFiles.tsx +++ b/src/UIs/reactjs/src/containers/Files/ListFiles/ListFiles.tsx @@ -3,19 +3,17 @@ import { NavLink } from "react-router-dom"; import { Modal, Button } from "react-bootstrap"; import axios from "../axios"; -type Props = {}; - type State = { pageTitle: string; showDeleteModal: boolean; - deletingFile: any; + deletingFile: {}; showAuditLogsModal: boolean; - files: any; - auditLogs: any; - errorMessage: any; + files: []; + auditLogs: []; + errorMessage: string; }; -class ListFiles extends Component { +class ListFiles extends Component { state = { pageTitle: "Files", showDeleteModal: false, @@ -79,7 +77,7 @@ class ListFiles extends Component { } }; - formatDateTime = (value) => { + formatDateTime = (value: string) => { if (!value) return value; const date = new Date(value); return date.toLocaleDateString() + " " + date.toLocaleTimeString(); diff --git a/src/UIs/reactjs/src/index.tsx b/src/UIs/reactjs/src/index.tsx index 291a2beb1..6a8a7b470 100644 --- a/src/UIs/reactjs/src/index.tsx +++ b/src/UIs/reactjs/src/index.tsx @@ -9,8 +9,6 @@ import "./index.css"; import App from "./App"; import { loadUser, isAuthenticated } from "./containers/Auth/authService"; import authReducer from "./containers/Auth/reducer"; -import auditLogReducer from "./containers/AuditLogs/reducer"; -import { watchAuditLog } from "./containers/AuditLogs/sagas"; import configurationEntryReducer from "./containers/Settings/reducer"; import { watchConfigurationEntry } from "./containers/Settings/sagas"; import productReducer from "./containers/Products/reducer"; @@ -23,7 +21,6 @@ const rootReducer = combineReducers({ configurationEntry: configurationEntryReducer, product: productReducer, user: userReducer, - auditLog: auditLogReducer, }); const sagaMiddleware = createSagaMiddleware(); @@ -38,7 +35,6 @@ const store = configureStore({ sagaMiddleware.run(watchConfigurationEntry); sagaMiddleware.run(watchProduct); sagaMiddleware.run(watchUser); -sagaMiddleware.run(watchAuditLog); loadUser().then((user) => { if (isAuthenticated()) {