Advertisement
Shell_Casing

ocms home

Oct 12th, 2020 (edited)
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useEffect } from 'react';
  2. import {Link, useNavigate} from "react-router-dom";
  3. import { useSelector, useDispatch } from "react-redux";
  4. import {
  5.     clearOCMSErrorsAction,
  6.     retrieveRoleNameAction
  7. } from "../../../store/actions/ocms-jobActions"; // for OCMS user role-name
  8. import classes from './home.module.css';
  9. import ADA_logo from "../../../assets/images/ADA_logo.png";
  10. import FooterLinks from "../../footer-links/footer-links";
  11.  
  12. const OCMS_Home = () => {
  13.  
  14.     // store data
  15.     const { id } = useSelector(state => state.auth.userData);
  16.     const ocmsRoles = useSelector(state => state.ocmsJobs.ocmsRoles) || [];
  17.     const isAuthenticated = useSelector(state => state.auth.isAuthenticated);
  18.  
  19.     const navigate = useNavigate();
  20.     const dispatch = useDispatch();
  21.     const goBack = () => navigate(-1);
  22.  
  23.     // clear errors
  24.     useEffect(() => {
  25.         dispatch(clearOCMSErrorsAction());
  26.     }, []);
  27.  
  28.     // retrieve OCMS user role-name
  29.     useEffect(() => {
  30.         dispatch(retrieveRoleNameAction(id));
  31.     }, [id]);
  32.  
  33.     useEffect(() => {
  34.         if(!isAuthenticated) {
  35.             navigate(`/login`);
  36.         }
  37.     }, [isAuthenticated]);
  38.  
  39.     let ocmsRole;
  40.  
  41.     if(ocmsRoles.length > 1) {
  42.         ocmsRole = (
  43.             <>
  44.                 <li className="">
  45.                     <Link to={`/ocms-checker-form`} className="rounded-t bg-gray-200 hover:bg-gray-400 py-2 px-4 block whitespace-no-wrap">
  46.                         <span className="text-gray-700">SRE</span>
  47.                     </Link>
  48.                 </li>
  49.                 <li className="">
  50.                     <Link to={`/ocms-maker-form`} className="rounded-t bg-gray-200 hover:bg-gray-400 py-2 px-4 block whitespace-no-wrap">
  51.                         <span className="text-gray-700">Application</span>
  52.                     </Link>
  53.                 </li>
  54.             </>
  55.         );
  56.     } else if(ocmsRoles.length == 1 && ocmsRoles.includes('SRE')) {
  57.         ocmsRole = (
  58.             <li className="">
  59.                 <Link to={`/ocms-checker-form`} className="rounded-t bg-gray-200 hover:bg-gray-400 py-2 px-4 block whitespace-no-wrap">
  60.                     <span className="text-gray-700">SRE</span>
  61.                 </Link>
  62.             </li>
  63.         );
  64.     } else if(ocmsRoles.length == 1 && ocmsRoles.includes('Application')) {
  65.         ocmsRole = (
  66.             <li className="">
  67.                 <Link to={`/ocms-maker-form`} className="rounded-t bg-gray-200 hover:bg-gray-400 py-2 px-4 block whitespace-no-wrap">
  68.                     <span className="text-gray-700">Application</span>
  69.                 </Link>
  70.             </li>
  71.         );
  72.     }
  73.  
  74.     const roleNamesDropdown = (
  75.         <div className="p-3 mb-3 mr-2">
  76.             <div className={`${classes.dropdown} inline-block relative`}>
  77.                 <button className="dbsMainButton font-semibold py-1 px-2 rounded inline-flex items-center">
  78.                     <span className="mr-1">Your role is</span>
  79.                     <svg className="fill-current h-4 w-4" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20">
  80.                         <path d="M9.293 12.95l.707.707L15.657 8l-1.414-1.414L10 10.828 5.757 6.586 4.343 8z" />
  81.                     </svg>
  82.                 </button>
  83.                 <ul className={`${classes.dropdownMenu} absolute hidden text-gray-700 pt-1`}>
  84.                     { ocmsRole }
  85.                 </ul>
  86.             </div>
  87.         </div>
  88.     );
  89.  
  90.     return (
  91.  
  92.         <div className={`${classes.outerContainer}`}>
  93.             <div className={`${classes.container} bg-blue-900 rounded`}>
  94.                 <div className={`${classes.wrapper} mb-10`}>
  95.                     <div className={`${classes.callToAction}`}>
  96.                         <h2 className={`text-gray-500 font-bold text-lg ml-3`}>Control & Monitoring Service</h2>
  97.                         { roleNamesDropdown }
  98.                     </div>
  99.                     <div className={`${classes.logoContainer} `}>
  100.                         <img src={ ADA_logo } alt={`ADA logo`} className={`${classes.logo} ml-4`} />
  101.                     </div>
  102.                 </div>
  103.                 <FooterLinks />
  104.             </div>
  105.         </div>
  106.     );
  107. }
  108.  
  109. export default OCMS_Home;
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement