Skip to content

Commit 5a7364f

Browse files
FWF-4550:[Feature] - Updated keycloak set up in mf and pr agent fixes.
1 parent 1966bcb commit 5a7364f

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

forms-flow-nav/src/Navbar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ const isUserManager = userRoles?.includes("manage_users");
438438
className={`nav-menu-item py-md-3 px-0 mx-2 ${
439439
pathname.match(createURLPathMatchExp("metrics", baseUrl)) ||
440440
pathname.match(createURLPathMatchExp("insights", baseUrl)) ||
441-
pathname.match(createURLPathMatchExp("submisssions", baseUrl))
441+
pathname.match(createURLPathMatchExp("submissions", baseUrl))
442442
? "active"
443443
: ""
444444
}`}

forms-flow-submissions/src/Routes/SubmissionListing.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { push } from "connected-react-router";
77
import { getSubmissionList } from "../api/queryServices/analyzeSubmissionServices";
88
import { formatDate } from "../helper/helper";
99
import {
10-
setAnalizeSubmissionSort,
10+
setAnalyzeSubmissionSort,
1111
setAnalyzeSubmissionPage,
1212
} from "../actions/analyzeSubmissionActions";
1313
import {
@@ -97,7 +97,7 @@ const TaskSubmissionList: React.FC = () => {
9797
{ sortOrder: k === key ? newOrder : "asc" },
9898
])
9999
);
100-
dispatch(setAnalizeSubmissionSort({ ...updatedSort, activeKey: key }));
100+
dispatch(setAnalyzeSubmissionSort({ ...updatedSort, activeKey: key }));
101101
},
102102
[dispatch, sortParams]
103103
);

forms-flow-submissions/src/actions/analyzeSubmissionActions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ACTION_CONSTANTS from "../constants/actionConstants";
22

3-
export const setAnalizeSubmissionSort = (data) => (dispatch) => {
3+
export const setAnalyzeSubmissionSort = (data) => (dispatch) => {
44
dispatch({
55
type: ACTION_CONSTANTS.UPDATE_SUBMISSION_SORT_PARAMS,
66
payload: data,

forms-flow-submissions/src/index.tsx

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useEffect, useState, useMemo } from "react";
22
import { Route, Switch, Redirect, useParams } from "react-router-dom";
33
import { KeycloakService, StorageService } from "@formsflow/service";
44
import {
55
KEYCLOAK_URL_AUTH,
66
KEYCLOAK_URL_REALM,
77
KEYCLOAK_CLIENT,
8-
} from "./endpoints/config";
8+
} from "./endpoints/config";
99
import { BASE_ROUTE, MULTITENANCY_ENABLED } from "./constants";
1010
import i18n from "./config/i18n";
1111
import "./index.scss";
@@ -16,14 +16,18 @@ const authorizedRoles = new Set(["create_submissions", "view_submissions"]);
1616

1717
interface SubmissionsProps {
1818
publish?: (event: string, data?: any) => void;
19-
subscribe?: (event: string, callback: (msg: string, data: any) => void) => void;
19+
subscribe?: (
20+
event: string,
21+
callback: (msg: string, data: any) => void
22+
) => void;
2023
getKcInstance: () => any;
2124
}
2225

2326
const Submissions: React.FC<SubmissionsProps> = React.memo((props) => {
2427
const { publish = () => {}, subscribe = () => {} } = props;
2528
const { tenantId } = useParams<{ tenantId?: string }>();
26-
const [isAuth, setIsAuth] = useState(false);
29+
const instance = useMemo(() => props.getKcInstance(), []);
30+
const [isAuth, setIsAuth] = useState(instance?.isAuthenticated());
2731
const [isClient, setIsClient] = useState(false);
2832

2933
const baseUrl = MULTITENANCY_ENABLED ? `/tenant/${tenantId}/` : "/";
@@ -40,23 +44,26 @@ const Submissions: React.FC<SubmissionsProps> = React.memo((props) => {
4044
}, [tenantId]);
4145

4246
useEffect(() => {
43-
const kcInstance = KeycloakService.getInstance(
44-
KEYCLOAK_URL_AUTH,
45-
KEYCLOAK_URL_REALM,
46-
KEYCLOAK_CLIENT,
47-
tenantId
48-
);
49-
50-
kcInstance.initKeycloak(() => {
51-
setIsAuth(kcInstance.isAuthenticated());
52-
publish("FF_AUTH", kcInstance);
53-
});
47+
if (!isAuth) {
48+
const kcInstance = KeycloakService.getInstance(
49+
KEYCLOAK_URL_AUTH,
50+
KEYCLOAK_URL_REALM,
51+
KEYCLOAK_CLIENT,
52+
tenantId
53+
);
54+
kcInstance.initKeycloak(() => {
55+
setIsAuth(kcInstance.isAuthenticated());
56+
publish("FF_AUTH", kcInstance);
57+
});
58+
}
5459
}, []);
5560

5661
useEffect(() => {
5762
if (!isAuth) return;
5863

59-
const roles = JSON.parse(StorageService.get(StorageService.User.USER_ROLE) ?? "[]");
64+
const roles = JSON.parse(
65+
StorageService.get(StorageService.User.USER_ROLE) ?? "[]"
66+
);
6067
if (roles.some((role: any) => authorizedRoles.has(role))) {
6168
setIsClient(true);
6269
}

0 commit comments

Comments
 (0)