From d287f95d6143d64780f23e0a8d36e2afedef91a3 Mon Sep 17 00:00:00 2001
From: devendra <devendra@devendras-MacBook-Pro.local>
Date: Fri, 4 Nov 2022 15:18:13 +0530
Subject: [PATCH] Feat: Role lables are updated

---
 src/components/common/Header.tsx              | 11 +++++-----
 src/components/dashboard/Dashboard.js         | 13 ++++++-----
 src/components/form/FormViewer.js             | 22 +++++++++----------
 .../modal/InspectionScheduleModal.tsx         |  4 ++--
 src/components/status-bar/StatusBarLarge.tsx  |  4 ++--
 src/constants/AppConstants.ts                 |  7 ++++++
 src/helpers/util.ts                           | 17 ++++++++++++++
 src/layouts/Inspector/ConsentFormView.tsx     |  7 +++---
 .../Inspector/InspectionSummaryLayout.tsx     |  4 ++--
 .../Regulator/ReviewApplicationLayout.tsx     |  7 +++---
 src/layouts/reviewer/Users.tsx                |  3 ++-
 .../Regulator/RegulatorAllApplications.tsx    |  3 ++-
 src/pages/Reviewer/CreateUser.tsx             |  6 +++--
 src/pages/Reviewer/ReviewerApplications.tsx   |  6 +++--
 14 files changed, 74 insertions(+), 40 deletions(-)
 create mode 100644 src/helpers/util.ts

diff --git a/src/components/common/Header.tsx b/src/components/common/Header.tsx
index e78165e..0e07a5c 100644
--- a/src/components/common/Header.tsx
+++ b/src/components/common/Header.tsx
@@ -19,6 +19,7 @@ interface LoginState {
   userName: any;
   userInfo: any;
 }
+const userRole = Helper.getUserRole();
 class Header extends Component<LoginProps, LoginState> {
   constructor(props: any) {
     super(props);
@@ -140,7 +141,7 @@ class Header extends Component<LoginProps, LoginState> {
                       HOME
                     </Link>
                   </li>
-                  {Helper.getUserRole() === APP.ROLE.INSTITUTION && (
+                  {userRole === APP.ROLE.INSTITUTION && (
                     <li className="mr-3 mr-sm-2 mr-md-5 mr-lg-5">
                       <Link
                         to={"/applications"}
@@ -156,7 +157,7 @@ class Header extends Component<LoginProps, LoginState> {
                       </Link>
                     </li>
                   )}
-                  {Helper.getUserRole() === APP.ROLE.INSTITUTION && (
+                  {userRole === APP.ROLE.INSTITUTION && (
                     <li className="mr-3 mr-sm-2 mr-md-5 mr-lg-5">
                       <Link
                         to={"/available-forms"}
@@ -172,7 +173,7 @@ class Header extends Component<LoginProps, LoginState> {
                       </Link>
                     </li>
                   )}
-                  {Helper.getUserRole() === APP.ROLE.REGULATOR && (
+                  {(userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) && (
                     <>
                       <li className="mr-3 mr-sm-2 mr-md-5 mr-lg-5">
                         <Link
@@ -205,7 +206,7 @@ class Header extends Component<LoginProps, LoginState> {
                       </li>
                     </>
                   )}
-                  {Helper.getUserRole() === APP.ROLE.INSPECTOR && (
+                  {userRole === APP.ROLE.INSPECTOR && (
                     <li className="mr-3 mr-sm-2 mr-md-5 mr-lg-5">
                       <Link
                         to={"/all-applications"}
@@ -221,7 +222,7 @@ class Header extends Component<LoginProps, LoginState> {
                       </Link>
                     </li>
                   )}
-                  {Helper.getUserRole() === APP.ROLE.REGULATOR && (
+                  {(userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) && (
                     <li className="">
                       <Link
                         to={"/analytics"}
diff --git a/src/components/dashboard/Dashboard.js b/src/components/dashboard/Dashboard.js
index 230f998..18f3e69 100644
--- a/src/components/dashboard/Dashboard.js
+++ b/src/components/dashboard/Dashboard.js
@@ -12,7 +12,7 @@ import { CardTwo } from "../cards";
 /**
  * Dashboard component
  */
-
+const userRole = Helper.getUserRole();
 class Dashboard extends Component {
   constructor(props) {
     super(props);
@@ -43,7 +43,7 @@ class Dashboard extends Component {
   }
 
   getInstituteApplications = () => {
-    if (Helper.getUserRole() === APP.ROLE.INSTITUTION) {
+    if (userRole === APP.ROLE.INSTITUTION) {
       FormService.get().then(
         (response) => {
           if (response.statusInfo.statusCode === APP.CODE.SUCCESS) {
@@ -92,10 +92,11 @@ class Dashboard extends Component {
   };
 
   render() {
+
     return (
       <Fragment>
         <Header history={this.props.history} />
-        {Helper.getUserRole() === APP.ROLE.INSTITUTION && (
+        {userRole === APP.ROLE.INSTITUTION && (
           <Fragment>
             <div className="container-fluid main-container">
               <div className="container dashboard-inner-container pt-3 pb-3">
@@ -198,7 +199,7 @@ class Dashboard extends Component {
             </div>
           </Fragment>
         )}
-        {/* {Helper.getUserRole() === APP.ROLE.REGULATOR && (
+        {/* {(userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) && (
           <Fragment>
             <div className="container-fluid">
               <div className="container dashboard-inner-container">
@@ -294,9 +295,9 @@ class Dashboard extends Component {
         )} */}
 
         {/* Inspector portal */}
-        {Helper.getUserRole() === APP.ROLE.INSPECTOR && <InspectorHome />}
+        {userRole === APP.ROLE.INSPECTOR && <InspectorHome />}
         {/* Inspector portal */}
-        {Helper.getUserRole() === APP.ROLE.REGULATOR && <ReviewerHome />}
+        {(userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) && <ReviewerHome />}
       </Fragment>
     );
   }
diff --git a/src/components/form/FormViewer.js b/src/components/form/FormViewer.js
index 7fed818..4ee8056 100644
--- a/src/components/form/FormViewer.js
+++ b/src/components/form/FormViewer.js
@@ -22,7 +22,7 @@ import { CardThree } from "../cards";
 import { TextAreaField } from "../form-elements";
 // import { BtnTwo } from "../buttons";
 // const $ = window.$;
-
+const userRole = Helper.getUserRole();
 class FormViewer extends Component {
   constructor(props) {
     super(props);
@@ -61,7 +61,7 @@ class FormViewer extends Component {
       this.props.match.params.applicationId !== null &&
       this.props.match.params.applicationId !== undefined
     ) {
-      if (Helper.getUserRole() === APP.ROLE.INSTITUTION) {
+      if (userRole === APP.ROLE.INSTITUTION) {
         this.setState({
           breadCrumbData: [
             { title: "HOME", url: "/dashboard", icon: "" },
@@ -69,7 +69,7 @@ class FormViewer extends Component {
           ],
         });
       }
-      if (Helper.getUserRole() === APP.ROLE.REGULATOR) {
+      if (userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) {
         this.setState({
           breadCrumbData: [
             { title: "HOME", url: "/dashboard", icon: "" },
@@ -81,7 +81,7 @@ class FormViewer extends Component {
         this.populateForm(this.props.match.params.applicationId);
       }, 50);
     } else {
-      if (Helper.getUserRole() === APP.ROLE.INSTITUTION) {
+      if (userRole === APP.ROLE.INSTITUTION) {
         this.setState({
           breadCrumbData: [
             { title: "HOME", url: "/dashboard", icon: "" },
@@ -89,7 +89,7 @@ class FormViewer extends Component {
           ],
         });
       }
-      if (Helper.getUserRole() === APP.ROLE.REGULATOR) {
+      if (userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) {
         this.setState({
           breadCrumbData: [
             { title: "HOME", url: "/dashboard", icon: "" },
@@ -327,7 +327,7 @@ class FormViewer extends Component {
       this.props.match.params.applicationId !== undefined
     ) {
       // if regulator disable form
-      if (Helper.getUserRole() === APP.ROLE.REGULATOR) {
+      if (userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) {
         setTimeout(() => {
           this.disableFormElements();
         }, 300);
@@ -335,7 +335,7 @@ class FormViewer extends Component {
       // if institute,
       // if status: Draft - enable form edit & show 'save as draft'
       if (
-        Helper.getUserRole() === APP.ROLE.INSTITUTION &&
+        userRole === APP.ROLE.INSTITUTION &&
         (this.state.applicationDetails.status === LANG.FORM_STATUS.DRAFT ||
           this.state.applicationDetails.status === LANG.FORM_STATUS.RETURNED)
       ) {
@@ -350,7 +350,7 @@ class FormViewer extends Component {
       // if institute,
       // if status: not Draft - disable form edit & hide 'save as draft'
       if (
-        Helper.getUserRole() === APP.ROLE.INSTITUTION &&
+        userRole === APP.ROLE.INSTITUTION &&
         this.state.applicationDetails.status !== LANG.FORM_STATUS.DRAFT &&
         this.state.applicationDetails.status !== LANG.FORM_STATUS.RETURNED
       ) {
@@ -392,7 +392,7 @@ class FormViewer extends Component {
       (this.props.match.params.applicationId === null ||
         this.props.match.params.applicationId === undefined ||
         this.state.applicationDetails.status === LANG.FORM_STATUS.RETURNED) &&
-      Helper.getUserRole() === APP.ROLE.INSTITUTION
+      userRole === APP.ROLE.INSTITUTION
     ) {
       for (let index = 0; index <= this.state.headingIndex; index++) {
         if (!flag) break;
@@ -868,7 +868,7 @@ class FormViewer extends Component {
                             //   this.props.match.params.applicationId !== null &&
                             //   this.props.match.params.applicationId !== undefined
                             // ) &&
-                            Helper.getUserRole() === APP.ROLE.INSTITUTION &&
+                            userRole === APP.ROLE.INSTITUTION &&
                               this.state.showSaveAsDraft && (
                                 <button
                                   className="btn btn-outline smf-btn-default mb-3"
@@ -888,7 +888,7 @@ class FormViewer extends Component {
                             //   this.props.match.params.applicationId !== null &&
                             //   this.props.match.params.applicationId !== undefined
                             // ) &&
-                            Helper.getUserRole() === APP.ROLE.INSTITUTION &&
+                            userRole === APP.ROLE.INSTITUTION &&
                               this.state.showSaveAsDraft &&
                               this.state.headingIndex ===
                                 this.state.formHeadings.length - 1 && (
diff --git a/src/components/modal/InspectionScheduleModal.tsx b/src/components/modal/InspectionScheduleModal.tsx
index 9394dd6..9df24f8 100644
--- a/src/components/modal/InspectionScheduleModal.tsx
+++ b/src/components/modal/InspectionScheduleModal.tsx
@@ -400,7 +400,7 @@ export const InspectionScheduleModal = ({
               <div className="col-sm-12 col-md-12 col-lg-6">
                 <div className={`${stylesTwo.text_area_one} p-3`}>
                   <div className="mb-3">
-                    <HeadingFive heading="Add lead inspector" count={1} />
+                    <HeadingFive heading="Add lead assessor" count={1} />
                   </div>
                   <div className="row">
                     <div className="col-9">
@@ -480,7 +480,7 @@ export const InspectionScheduleModal = ({
 
                 <div className={`${stylesTwo.text_area_one} p-3 mt-3`}>
                   <div className="mb-3">
-                    <HeadingFive heading="Add assisting inspectors" count={2} />
+                    <HeadingFive heading="Add assisting assessor" count={2} />
                   </div>
                   <div className="row">
                     <div className="col-sm-12 col-md-9 col-lg-9">
diff --git a/src/components/status-bar/StatusBarLarge.tsx b/src/components/status-bar/StatusBarLarge.tsx
index aeb623f..3f92338 100644
--- a/src/components/status-bar/StatusBarLarge.tsx
+++ b/src/components/status-bar/StatusBarLarge.tsx
@@ -182,7 +182,7 @@ export const StatusBarLarge = ({
                 </div>
                 <div className="pt-2">
                   <label className={`${styles.status_bar_custom_heading}`}>
-                    Lead inspector
+                    Lead assessor
                   </label>
                   <div className="pt-3">
                     {inspectionData &&
@@ -214,7 +214,7 @@ export const StatusBarLarge = ({
                 </div>
                 <div className="pt-2">
                   <label className={`${styles.status_bar_custom_heading}`}>
-                    Assisting inspector
+                    Assisting assessor
                   </label>
                   <div className="pt-3">
                     {inspectionData &&
diff --git a/src/constants/AppConstants.ts b/src/constants/AppConstants.ts
index d351abd..ea5d593 100644
--- a/src/constants/AppConstants.ts
+++ b/src/constants/AppConstants.ts
@@ -12,6 +12,13 @@ export const APP = {
     INSTITUTION: "Institution",
     REGULATOR: "Regulator", // reviewer
     INSPECTOR: "Inspector",
+    SUPER_ADMIN: "Super Admin",
+  },
+  ROLE_LABEL: { //Update ROLE object with correct label once Inspector and assistant inspector is changes to Medical and Non-Medical assessor and assistant inspector role is removed
+    INSTITUTION: "Institute",
+    REGULATOR: "Admin", // reviewer
+    INSPECTOR: "Assessor",
+    SUPER_ADMIN: "Super Admin",
   },
   ROUTES: {
     DASHBOARD: "/dashboard",
diff --git a/src/helpers/util.ts b/src/helpers/util.ts
new file mode 100644
index 0000000..549bcae
--- /dev/null
+++ b/src/helpers/util.ts
@@ -0,0 +1,17 @@
+import { APP } from "../constants";
+
+const getRoleLabel = (roleName: string) => {
+
+    switch(roleName.toLowerCase()) {
+        case APP.ROLE.REGULATOR.toLowerCase(): 
+            return APP.ROLE_LABEL.REGULATOR;
+        case APP.ROLE.INSTITUTION.toLowerCase():
+            return APP.ROLE_LABEL.INSTITUTION;
+        case APP.ROLE.INSPECTOR.toLowerCase():
+            return APP.ROLE_LABEL.INSPECTOR;
+        case APP.ROLE.SUPER_ADMIN.toLowerCase():
+            return APP.ROLE_LABEL.SUPER_ADMIN;
+    }
+}
+
+export default { getRoleLabel };
\ No newline at end of file
diff --git a/src/layouts/Inspector/ConsentFormView.tsx b/src/layouts/Inspector/ConsentFormView.tsx
index 540f07d..02dcbf6 100644
--- a/src/layouts/Inspector/ConsentFormView.tsx
+++ b/src/layouts/Inspector/ConsentFormView.tsx
@@ -60,6 +60,7 @@ export const ConsentFormView = ({
     useRecoilState(sideMenuLabelAtom);
 
   const reviewerNote = useRecoilState(modalTwoTextAreaAtom);
+  const userRole = Helper.getUserRole();
 
   let history = useHistory();
 
@@ -596,7 +597,7 @@ export const ConsentFormView = ({
                   applicationId={applicationData.applicationId}
                 />
 
-                {Helper.getUserRole() === APP.ROLE.REGULATOR && (
+                {(userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) && (
                   <InspectionScheduleModal
                     id="sendToInspectionEdit"
                     showTextAreaLabel={false}
@@ -707,7 +708,7 @@ export const ConsentFormView = ({
                               <label
                                 className={`${styles.status_bar_custom_heading}`}
                               >
-                                Lead inspector
+                                Lead assessor
                               </label>
                               <div className="pt-3">
                                 {applicationData &&
@@ -747,7 +748,7 @@ export const ConsentFormView = ({
                               <label
                                 className={`${styles.status_bar_custom_heading}`}
                               >
-                                Assisting inspector
+                                Assisting assessor
                               </label>
                               <div className="pt-3">
                                 {applicationData &&
diff --git a/src/layouts/Inspector/InspectionSummaryLayout.tsx b/src/layouts/Inspector/InspectionSummaryLayout.tsx
index a304222..1659478 100644
--- a/src/layouts/Inspector/InspectionSummaryLayout.tsx
+++ b/src/layouts/Inspector/InspectionSummaryLayout.tsx
@@ -163,7 +163,7 @@ export const InspectionSummaryLayout = ({
         {/* Inspectors list */}
         <div className="pt-2">
           <label className={`${stylesThree.status_bar_custom_heading}`}>
-            Lead inspector
+            Lead assessor
           </label>
           <div className="pt-3">
             {data &&
@@ -199,7 +199,7 @@ export const InspectionSummaryLayout = ({
         </div>
         <div className="pt-2">
           <label className={`${stylesThree.status_bar_custom_heading}`}>
-            Assisting inspector
+            Assisting assessor
           </label>
           <div className="pt-3">
             {data &&
diff --git a/src/layouts/Regulator/ReviewApplicationLayout.tsx b/src/layouts/Regulator/ReviewApplicationLayout.tsx
index d09d74f..0a1d76b 100644
--- a/src/layouts/Regulator/ReviewApplicationLayout.tsx
+++ b/src/layouts/Regulator/ReviewApplicationLayout.tsx
@@ -54,6 +54,7 @@ export const ReviewApplicationLayout = ({
     useRecoilState(sideMenuLabelAtom);
 
   const reviewerNote = useRecoilState(modalTwoTextAreaAtom);
+  const userRole = Helper.getUserRole();
 
   let history = useHistory();
 
@@ -536,7 +537,7 @@ export const ReviewApplicationLayout = ({
                   applicationId={applicationData.applicationId}
                 />
 
-                {Helper.getUserRole() === APP.ROLE.REGULATOR && (
+                {(userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) && (
                   <InspectionScheduleModal
                     id="sendToInspectionEdit"
                     showTextAreaLabel={false}
@@ -634,7 +635,7 @@ export const ReviewApplicationLayout = ({
                               <label
                                 className={`${styles.status_bar_custom_heading}`}
                               >
-                                Lead inspector
+                                Lead assessor
                               </label>
                               <div className="pt-3">
                                 {applicationData &&
@@ -674,7 +675,7 @@ export const ReviewApplicationLayout = ({
                               <label
                                 className={`${styles.status_bar_custom_heading}`}
                               >
-                                Assisting inspector
+                                Assisting assessor
                               </label>
                               <div className="pt-3">
                                 {applicationData &&
diff --git a/src/layouts/reviewer/Users.tsx b/src/layouts/reviewer/Users.tsx
index 2dbeb89..ec18762 100644
--- a/src/layouts/reviewer/Users.tsx
+++ b/src/layouts/reviewer/Users.tsx
@@ -6,6 +6,7 @@ import { Link } from "react-router-dom";
 import { BtnTwo } from "../../components/buttons";
 import { APP } from "../../constants";
 import Notify from "../../helpers/notify";
+import Util from "../../helpers/util";
 import { UserService } from "../../services/user.service";
 
 interface userProps {
@@ -155,7 +156,7 @@ export const Users = ({ data }: userProps) => {
                     {user.roles.map((role, i) => {
                       return (
                         <span key={i}>
-                          <span>{role.name}</span>
+                          <span>{Util.getRoleLabel(role.name)}</span>
                           {i !== user.roles.length - 1 && <span>,</span>}
                         </span>
                       );
diff --git a/src/pages/Regulator/RegulatorAllApplications.tsx b/src/pages/Regulator/RegulatorAllApplications.tsx
index 04cfe04..1f42f98 100644
--- a/src/pages/Regulator/RegulatorAllApplications.tsx
+++ b/src/pages/Regulator/RegulatorAllApplications.tsx
@@ -29,6 +29,7 @@ export const RegulatorAllApplications = ({
     const [currentData, setCurrentData] = useRecoilState(selectedTabDataAtom);
     const [tabData, setTabData] = useState<any[]>([]);
     const [selectedTab, setSelectedTab] = useRecoilState(selectedTabAtom);
+    const userRole = Helper.getUserRole();
 
     let history = useHistory();
 
@@ -96,7 +97,7 @@ export const RegulatorAllApplications = ({
     }, [currentData]);
 
     const getSelectedTabData = () => {
-        if (Helper.getUserRole() === APP.ROLE.REGULATOR) {
+        if (userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) {
             let data = {
                 searchObjects: [],
             };
diff --git a/src/pages/Reviewer/CreateUser.tsx b/src/pages/Reviewer/CreateUser.tsx
index 799c583..500f748 100644
--- a/src/pages/Reviewer/CreateUser.tsx
+++ b/src/pages/Reviewer/CreateUser.tsx
@@ -7,6 +7,7 @@ import Header from "../../components/common/Header"
 import { HeadingOne } from "../../components/headings"
 import { APP } from "../../constants";
 import Notify from "../../helpers/notify";
+import Util from "../../helpers/util";
 import { UserService } from "../../services/user.service";
 
 interface userProps {
@@ -117,8 +118,9 @@ export const CreateUser = ({ data }: userProps) => {
             (response2) => {
                 if (response2.statusInfo && response2.statusInfo.statusCode === APP.CODE.SUCCESS) {
                     if (isEdit) {
-                        let rolesUpdated:any = []
+                        let rolesUpdated:any = [];
                         userEdit && userEdit.roles.map((role: any, index: number) => {
+
                             rolesUpdated = response2.responseData.map((r: IRole, i: number) => {
                                 if (r.id === role.id) {
                                     return { ...r, isChecked: true }
@@ -293,7 +295,7 @@ export const CreateUser = ({ data }: userProps) => {
                                                         }
                                                         checked={role.isChecked ? true : false} onChange={e => onAddingRole(e, key)}
                                                     />
-                                                    {" " + role.name}
+                                                    {" " + Util.getRoleLabel(role.name)}
                                                 </label>
                                             </div>
                                         ))}
diff --git a/src/pages/Reviewer/ReviewerApplications.tsx b/src/pages/Reviewer/ReviewerApplications.tsx
index 31ba0e7..1bb94d7 100644
--- a/src/pages/Reviewer/ReviewerApplications.tsx
+++ b/src/pages/Reviewer/ReviewerApplications.tsx
@@ -45,6 +45,8 @@ const FORM_STATUS = [
     "Approved"
 ];
 
+const userRole = Helper.getUserRole();
+
 class ReviewerApplications extends Component<ReviewerApplicationsProps, ReviewerApplicationsState> {
     constructor(props: any) {
         super(props);
@@ -58,7 +60,7 @@ class ReviewerApplications extends Component<ReviewerApplicationsProps, Reviewer
     }
 
     componentDidMount() {
-        if (Helper.getUserRole() === APP.ROLE.REGULATOR) {
+        if (userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) {
             let data = {
                 "searchObjects": [
                 ]
@@ -123,7 +125,7 @@ class ReviewerApplications extends Component<ReviewerApplicationsProps, Reviewer
             <Fragment>
                 <Header history={this.props.history} />
 
-                {Helper.getUserRole() === APP.ROLE.REGULATOR && (
+                {(userRole === APP.ROLE.REGULATOR || userRole === APP.ROLE.SUPER_ADMIN) && (
                     <Fragment>
                         <div className="container-fluid">
                             <div className="container dashboard-inner-container">
-- 
GitLab