-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
958554a
commit 193a119
Showing
4 changed files
with
101 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
import { useEffect } from "react"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import DataReportView from "../views/DataReportView"; | ||
import { fetchDataReport } from "../store/interface/dataReport"; | ||
|
||
function DataReport(props) { | ||
return <DataReportView />; | ||
const dataReport = useSelector((state) => state.interface.dataReport); | ||
const userInfo = useSelector((state) => state.interface.authenticate.userInfo); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
dispatch(fetchDataReport()); | ||
}, [dispatch]); | ||
|
||
return <DataReportView data={dataReport.data} status={dataReport.status} />; | ||
} | ||
|
||
export default DataReport; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { createAsyncThunk } from "@reduxjs/toolkit"; | ||
import { fetchResolvedCB } from "./utilities"; | ||
|
||
const apiUrl = import.meta.env.VITE_API_URL; | ||
|
||
export const dataReportInitalState = { | ||
dataReport: { | ||
status: "idle", | ||
requestId: null, | ||
error: null, | ||
data: null, | ||
}, | ||
}; | ||
|
||
export const fetchDataReport = createAsyncThunk("interface/fetchDataReport", async (_, { getState, abort, requestId }) => { | ||
const state = getState().interface; | ||
|
||
if (state.dataReport.requestId !== requestId) return abort("Request already in progress."); | ||
|
||
return await fetch(apiUrl + "/api/data_report", { | ||
method: "POST", | ||
headers: { | ||
"Content-type": "application/json; charset=UTF-8", | ||
}, | ||
credentials: "include", | ||
}).then(fetchResolvedCB); | ||
}); | ||
|
||
export function dataReportBuilder(builder) { | ||
builder | ||
.addCase(fetchDataReport.pending, (state, action) => { | ||
if (state.dataReport.requestId === null) { | ||
state.dataReport.status = "loading"; | ||
state.dataReport.requestId = action.meta.requestId; | ||
} | ||
}) | ||
.addCase(fetchDataReport.fulfilled, (state, action) => { | ||
if (state.dataReport.requestId === action.meta.requestId) { | ||
state.dataReport.status = "idle"; | ||
state.dataReport.requestId = null; | ||
state.dataReport.data = { | ||
agreements: action.payload.agreements, | ||
loginLogs: action.payload.login_logs, | ||
reportLogs: action.payload.report_logs, | ||
favoriteLines: action.payload.favorite_lines, | ||
userData: action.payload.userData, | ||
}; | ||
} | ||
}) | ||
.addCase(fetchDataReport.rejected, (state, action) => { | ||
if (state.dataReport.requestId === action.meta.requestId) { | ||
state.dataReport.status = "failed"; | ||
state.dataReport.requestId = null; | ||
state.dataReport.error = action.error.message; | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters