diff --git a/forms-flow-web/src/components/Form/Item/index.js b/forms-flow-web/src/components/Form/Item/index.js index b087f9da0e..8f1269f764 100644 --- a/forms-flow-web/src/components/Form/Item/index.js +++ b/forms-flow-web/src/components/Form/Item/index.js @@ -1,4 +1,4 @@ -import { Route, Switch, Redirect, useParams } from "react-router-dom"; +import { Route, Switch, Redirect, useParams, useLocation } from "react-router-dom"; import React, { useEffect } from "react"; import { Formio, getForm } from "react-formio"; import { useDispatch, useSelector } from "react-redux"; @@ -22,12 +22,14 @@ import { import Draft from "../../Draft"; import Loading from "../../../containers/Loading"; -import { getClientList } from "../../../apiManager/services/authorizationService"; +import { getClientList, getReviewerList } from "../../../apiManager/services/authorizationService"; import NotFound from "../../NotFound"; import { setApiCallError } from "../../../actions/ErroHandling"; const Item = React.memo(() => { const { formId } = useParams(); + const location = useLocation(); // React Router's hook to get the current location + const pathname = location.pathname; const userRoles = useSelector((state) => state.user.roles || []); const tenantKey = useSelector((state) => state?.tenants?.tenantId); const redirectUrl = MULTITENANCY_ENABLED ? `/tenant/${tenantKey}/` : "/"; @@ -36,7 +38,13 @@ const Item = React.memo(() => { const dispatch = useDispatch(); const formAuthVerify = (formId,successCallBack)=>{ - getClientList(formId).then(successCallBack).catch((err)=>{ + const isSubmissionRoute = pathname?.includes("/submission"); + const authFunction = isSubmissionRoute + ? userRoles.includes(STAFF_REVIEWER) + ? getReviewerList + : getClientList + : getClientList; + authFunction(formId).then(successCallBack).catch((err)=>{ const {response} = err; dispatch(setApiCallError({message:response?.data?.message || response.statusText,status:response.status}));