Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add renew tokens feature and fix duplicate lines in tables #110

Merged
merged 3 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sonor",
"version": "0.5.34",
"version": "0.5.35",
"private": true,
"dependencies": {
"@tanstack/react-query": "4.0.5",
Expand Down
4 changes: 2 additions & 2 deletions src/Authentication/useAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function initializeOidc (config) {
* Retrieve authentication status based of Oidc
*/
export function useIsAuthenticated() {
const { login, isUserLoggedIn, oidcTokens } = useOidc({ assertUserLoggedIn: false });
const { login, isUserLoggedIn, oidcTokens, renewTokens} = useOidc({ assertUserLoggedIn: false });

useEffect(() => {
if (!login) {
Expand All @@ -47,5 +47,5 @@ export function useIsAuthenticated() {
});
}, [login]);

return { isAuthenticated: isUserLoggedIn, tokens: oidcTokens };
return { isAuthenticated: isUserLoggedIn, tokens: oidcTokens, renewTokens };
}
37 changes: 35 additions & 2 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import React, { useEffect, useState, useRef } from "react";
import { useIsAuthenticated } from "../../Authentication/useAuth";
import D from "../../i18n";
import View from "../View/View";
Expand All @@ -9,8 +9,41 @@ export const App = () => {
const [authenticated, setAuthenticated] = useState(false);
const [contactFailed, setContactFailed] = useState(false);
const [data, setData] = useState(null);
const timeoutIdRef = useRef(null);

const { tokens } = useIsAuthenticated();
const { tokens, renewTokens } = useIsAuthenticated();

useEffect(() => {
const resetInactivityTimeout = () => {
if (timeoutIdRef.current) {
clearTimeout(timeoutIdRef.current);
}
timeoutIdRef.current = setTimeout(renewTokens, 5 * 60 * 1000);
};

const events = [
"mousemove",
"mousedown",
"keypress",
"touchstart",
"click",
];

events.forEach((event) => {
window.addEventListener(event, resetInactivityTimeout);
});

resetInactivityTimeout();

return () => {
if (timeoutIdRef.current) {
clearTimeout(timeoutIdRef.current);
}
events.forEach((event) => {
window.removeEventListener(event, resetInactivityTimeout);
});
};
}, [renewTokens]);

useEffect(() => {
if (window.localStorage.getItem("AUTHENTICATION_MODE") === ANONYMOUS) {
Expand Down
10 changes: 4 additions & 6 deletions src/components/CollectionTable/CollectionTableDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,10 @@ function CollectionTableDisplay({
(pagination.page - 1) * pagination.size,
Math.min(pagination.page * pagination.size, displayedLines.length),
)
.map((line) => (
<CollectionTableDisplayLine
key={line.id || line.interviewerId || line.survey || line.site}
data={line}
/>
))}
.map((line) => (
<CollectionTableDisplayLine key={line.id || line.interviewerId || line.site || line.campaignId} data={line} />
)
)}
</tbody>
{tableFooter}
</Table>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MonitoringTable/FollowUpTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function FollowUpTable({
Math.min(pagination.page * pagination.size, displayedLines.length),
)
.map((line) => (
<FollowUpTableLine key={line.interviewerId || line.survey || line.site} data={line} />
<FollowUpTableLine key={line.campaignId || line.interviewerId || line.site} data={line} />
))}
</tbody>
{tableFooter}
Expand Down
7 changes: 7 additions & 0 deletions src/tests/mocks/formattedDataMonitoringTableBysurvey.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const val = {
"linesDetails": [
{
"completionRate": 0.057692307692307696,
"campaignId": "simpsons2020x00",
"total": 82,
"notStarted": 22,
"onGoing": 76,
Expand All @@ -17,6 +18,7 @@ const val = {
},
{
"completionRate": 0.057692307692307696,
"campaignId": "simpsosfqns2020x00",
"total": 82,
"notStarted": 22,
"onGoing": 76,
Expand All @@ -31,6 +33,7 @@ const val = {
},
{
"completionRate": 0.057692307692307696,
"campaignId": "vqs2fsqe021x00",
"total": 82,
"notStarted": 22,
"onGoing": 76,
Expand All @@ -45,6 +48,7 @@ const val = {
},
{
"completionRate": 0.057692307692307696,
"campaignId": "simpsonqsdfsqes2020x00",
"total": 82,
"notStarted": 22,
"onGoing": 76,
Expand All @@ -59,6 +63,7 @@ const val = {
},
{
"completionRate": 0.057692307692307696,
"campaignId": "vqs2qfsdfsqe021x00",
"total": 82,
"notStarted": 22,
"onGoing": 76,
Expand All @@ -73,6 +78,7 @@ const val = {
},
{
"completionRate": 0.057692307692307696,
"campaignId": "simpsonkgs2020x00",
"total": 82,
"notStarted": 22,
"onGoing": 76,
Expand All @@ -87,6 +93,7 @@ const val = {
},
{
"completionRate": 0.057692307692307696,
"campaignId": "vqs202fgd1x00",
"total": 82,
"notStarted": 22,
"onGoing": 76,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/DataFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ class DataFormatter {
res.map((x) => {
const obj = Utils.formatForMonitoringTable(x);
obj.survey = x.campaign.label;
obj.campaignId = x.campaign.id;
return obj;
})
);
Expand Down Expand Up @@ -674,7 +675,7 @@ class DataFormatter {
.filter((camp) => camp.total)
.map((camp) =>
Utils.formatForCollectionTable(
{ survey: camp.campaign.label },
{ survey: camp.campaign.label, campaignId: camp.campaign?.id },
data[0].find((c) => c.campaign.id === camp.campaign.id),
camp
)
Expand Down
4 changes: 0 additions & 4 deletions src/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ class Utils {
line.appointmentTaken = stateCount.apsCount;
line.interviewStarted = stateCount.insCount;

line.interviewerFirstName = stateCount.interviewerFirstName;
line.interviewerFirstName = stateCount.interviewerLastName;
line.interviewerId = stateCount.interviewerId;

return line;
}

Expand Down
Loading