Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, { memo, useEffect, useRef, useState } from "react";
- import { useDispatch, useSelector } from "react-redux";
- import { Redirect, useHistory, useParams } from "react-router";
- import swal from "sweetalert";
- import {
- answersheet,
- archieved,
- examStandings,
- Need_StartTimer,
- NOT_PARTICIPATE,
- RUNNING,
- running,
- SHOWMODAL,
- upcoming,
- } from "../../constants/constants";
- import purchaseExamAction from "../../redux/actions/purchaseExamAction";
- import { mcqExam, resultDetails } from "../../urls";
- import "./ExamDetails.css";
- import runningState from "../../assets/images/running.png";
- import examinee from "../../assets/images/examinee.png";
- import coins from "../../assets/images/coins.png";
- import score from "../../assets/images/score.png";
- import clock from "../../assets/images/clock.png";
- import grade from "../../assets/images/grade.png";
- import solution from "../../assets/images/solution.png";
- import rank from "../../assets/images/rank.png";
- import document from "../../assets/images/document.png";
- import { BiLogInCircle } from "react-icons/bi";
- import LoaderComponent from "../../Components/LoaderComponent/LoaderComponent";
- import { getTimeFormat } from "../../utils/getTimeFormat";
- import archiveDateicon from "../../assets/images/archiveDateicon.png";
- import schedule from "../../assets/images/schedule.png";
- import JoinModal from "../../Components/JoinModal/JoinModal";
- import {
- Button,
- Grid,
- makeStyles,
- Paper,
- Typography,
- Snackbar,
- useTheme,
- useMediaQuery,Card
- } from "@material-ui/core";
- import VerticalBar from "../../Components/VerticalBar/VerticalBar";
- import { mcqAnsActions } from "../../redux/actions/mcqAnsActions";
- import { EXAMID } from "../../constants/types";
- import { useWindowSize } from "use-window-size-hook";
- import userParticipatedExamAction from './../../redux/actions/userParticipatedExamAction';
- import { examDetailsAction } from './../../redux/actions/examDetailsAction';
- const useStyles = makeStyles((theme) => ({
- rootBox: {
- width : "98%",margin : "0px auto",
- [theme.breakpoints.up('sm')] : {
- display : "flex",
- minHeight : "80vh",
- alignItems : "center"
- }
- },
- paperStyleExam : {
- backgroundColor: "#EDF3FF",
- margin: "10px auto",
- padding: "10px",
- width : "95%",
- [theme.breakpoints.up('sm')] : {
- margin: "0px auto",
- width : "85%",
- flexGrow : 1
- }
- },
- mainDiv : {
- width : "100%",margin : "auto",
- [theme.breakpoints.up('sm')] : {
- width : "45%",
- flexGrow : 1,
- height : "100%",
- }
- },
- titleStyle: {
- fontSize: 23,
- color: "#54595C",
- },
- iconSize1: {
- height: "20px",
- width: "20px",
- },
- textSize1: {
- fontSize: "14px",
- padding : "0 2px",
- fontWeight: "bold",
- marginLeft : "1px",
- [theme.breakpoints.up('sm')] : {
- marginLeft : "5px",
- }
- },
- textSize2: {
- fontSize: "16px",
- padding : "0 2px",
- fontWeight: "bold",
- [theme.breakpoints.up('sm')] : {
- marginLeft : "5px",
- }
- },
- buttonStyle1 : {
- backgroundColor: "white",
- color: "black",
- height: "35px",
- width: "95%",
- textTransform : 'none'
- },
- buttonImg1 : {
- height: "14px", width: "14px",
- [theme.breakpoints.up('sm')] : {
- height: "16px", width: "16px",
- }
- },
- buttontxt1 : {
- fontSize: "11.5px", paddingLeft: "2px" ,
- [theme.breakpoints.up('sm')] : {
- fontSize: "13px", paddingLeft: "6px" ,
- }
- },
- joinButtonStyle : {
- width : '100%',
- backgroundColor : "#3F68B3",
- color : 'white',
- textTransform : 'none'
- },
- syllabusStyle : {
- fontSize: "13px", textAlign : "center",whiteSpace : "pre-wrap",wordBreak : "kepp-all",
- [theme.breakpoints.up('sm')] : {
- fontSize : "13px"
- }
- },
- ExamDetailCard : {
- backgroundColor: "#EDF3FF",
- margin: "auto",
- marginTop: "70px",
- padding: "10px",
- },
- bottomStyle : {
- [theme.breakpoints.only('sm')] : {
- marginBottom : "40px"
- }
- },
- programTitleStyle : {
- textAlign : "center",fontSize : "22px",margin : "10px 0px 10px 0px",
- [theme.breakpoints.up('md')] : {
- margin : "5px 0px 30px 0px",
- }
- },
- syllabusImage : {
- height: "20px", width: "20px" ,
- // [theme.breakpoints.up('sm')] : {
- // height: "20px", width: "20px" ,
- // }
- },
- syllabusText : {
- fontSize: "17px", padding: "0px 5px" ,
- // [theme.breakpoints.up('sm')] : {
- // fontSize : '17px'
- // }
- }
- }));
- const ExamDetails = () => {
- let isWeb = false
- const { width } = useWindowSize();
- if(width>599)isWeb=true;
- const classes = useStyles();
- const [openSnackbar, setOpenSnackbar] = React.useState(false);
- const vertical= 'bottom', horizontal='center';
- const handleSnackBarClick = () => {
- setOpenSnackbar(true);
- };
- const handleSnackBarClose = () => {
- setOpenSnackbar(false);
- };
- const [modalState, setModalState] = useState(SHOWMODAL);
- const [modalIsOpen, setIsOpen] = React.useState(false);
- const { id, program, examState } = useParams();
- const {programs,results} = useSelector((state) => state.initData);
- let programTitle = "";
- const history = useHistory();
- const isSignedIn = useSelector((state) => state.auth.isSignedIn);
- const token = useSelector((state) => state.auth.userId.token);
- const dispatch = useDispatch();
- let currentExam;
- if(programs!==undefined)
- {
- const temp = programs.find(pg=> pg.id==program);
- if(temp!==undefined)
- programTitle = temp.title;
- }
- const archievedCurrentExam = useSelector(
- (state) => state.archievedData.exams
- );
- const currentUpcomingRunning = useSelector((state) => state.initData.exams);
- const userParticipatedExam = useSelector(state=>state.initData.userParticipatedExam);
- if (currentUpcomingRunning !== undefined)
- currentExam = currentUpcomingRunning.filter((ex) => ex.id == id)[0];
- if (currentExam === undefined && archievedCurrentExam !== undefined)
- currentExam = archievedCurrentExam.filter((ex) => ex.id == id)[0];
- if (currentExam === undefined && userParticipatedExam !== undefined)
- currentExam = userParticipatedExam.filter((ex) => ex.id == id)[0];
- const getEndTime = () => {
- if (currentExam === undefined || currentExam.end_time === undefined)
- return new Date().getTime();
- else return currentExam.end_time;
- };
- const [timeLeft, setTimeLeft] = useState(
- new Date(getEndTime()).getTime() - new Date().getTime()
- );
- const mounted = useRef(false);
- useEffect(() => {
- mounted.current = true;
- return () => (mounted.current = false);
- });
- useEffect(() => {
- if (timeLeft<1) {
- return;
- }
- }, [timeLeft]);
- let intervalId;
- useEffect(()=>
- {
- if(0<timeLeft && timeLeft<Need_StartTimer && mounted.current){
- intervalId = setInterval(() => {
- setTimeLeft(timeLeft=>timeLeft - 1000);
- }, 1000);
- }
- return () => clearInterval(intervalId);
- },[])
- useEffect(()=>
- {
- dispatch(examDetailsAction(token,id));
- },[id])
- if (currentExam === undefined) {
- return <LoaderComponent />;
- }
- const routeChange = () => {
- // console.log(examState);
- if (examState === upcoming) return;
- else if (examState === running) {
- // console.log(('2222 ',results[id]));
- if (currentExam.purchased && (results!==undefined && results[id]!==undefined))
- handleSnackBarClick()
- else {
- dispatch(purchaseExamAction(token, { exam: id }));
- dispatch(mcqAnsActions(EXAMID, { exam: id }));
- history.replace(mcqExam(program, id, examState));
- }
- return;
- }
- else {
- if (currentExam.purchased) {
- dispatch(mcqAnsActions(EXAMID, { exam: id }));
- history.replace(mcqExam(program, id, examState));
- } else {
- dispatch(purchaseExamAction(token, { exam: id }));
- dispatch(mcqAnsActions(EXAMID, { exam: id }));
- history.replace(mcqExam(program, id, examState));
- }
- }
- };
- if (!isSignedIn) return <Redirect to={"/login"} />;
- const { state, title, syllabus, total_marks, cost, duration } = currentExam;
- const type = state;
- const { total_examinees, standings , passed_examinees} = currentExam.statistics;
- const ColoredLine = ({ color }) => (
- <span
- style={{
- borderLeft: `3px solid ${color}`,
- textAlign: "right",
- alignItems: "right",
- }}
- />
- );
- let createdDate = new Date(currentExam.end_time);
- const date = createdDate.getDate();
- const year = createdDate.getFullYear();
- const month = createdDate.toLocaleString("default", { month: "long" });
- const durationConvert = (duration) => {
- // return '1h 20 Min';
- duration /= 60000;
- if (duration >= 60) {
- if (duration % 60)
- return `${parseInt(duration / 60)}h ${duration % 60} Min`;
- return `${parseInt(duration / 60)}h`;
- }
- return `${duration} Min`;
- };
- const TimeShow = (timeleft) => {
- if (type == archieved) return false;
- const minLeft = timeLeft / 60000;
- if (minLeft <= 2880) return true;
- return false;
- };
- function openModal() {
- if (examState === running) {
- // console.log(results[id]);
- if (currentExam.purchased && (results!==undefined && results[id]!==undefined))
- {
- return handleSnackBarClick()
- }
- }
- setModalState(SHOWMODAL);
- setIsOpen(true);
- }
- function closeModal(str) {
- if (str === "close") setIsOpen(false);
- }
- function JoinExam() {
- setIsOpen(false);
- routeChange();
- }
- const modalCall=(modal)=>
- {
- setModalState(modal);
- setIsOpen(true);
- }
- const rankResultSolutionRoute = (path) => {
- if (examState === upcoming) {
- setModalState(upcoming);
- setIsOpen(true);
- return;
- }
- else if (currentExam === undefined) return;
- else if(examState===running)
- {
- if (path === "rankList") {
- if (currentExam.standing_visibility)
- history.push(resultDetails(id, examStandings));
- else {
- modalCall(RUNNING);
- }
- }
- else if(path==="result")
- {
- if (currentExam.purchased && (results!==undefined && results[id]!==undefined))
- {
- if(currentExam.result_visibility)
- history.push(resultDetails(id));
- else modalCall(RUNNING);
- }
- else modalCall(NOT_PARTICIPATE);
- }
- else if(path==="solution")
- {
- if (currentExam.purchased && (results!==undefined && results[id]!==undefined))
- {
- if(currentExam.solution_visibility)
- history.push(resultDetails(id, answersheet));
- else{
- modalCall(RUNNING);
- }
- }
- else
- {
- modalCall(NOT_PARTICIPATE);
- }
- }
- }
- else if(examState===archieved)
- {
- if (path === "rankList")
- history.push(resultDetails(id, examStandings));
- else if(currentExam.purchased)
- {
- if(path==='solution')
- history.push(resultDetails(id, answersheet));
- else if(path==='result')
- modalCall(NOT_PARTICIPATE)
- }
- else{
- modalCall(NOT_PARTICIPATE);
- }
- }
- return ;
- };
- return (
- <div className={classes.rootBox}>
- <JoinModal
- modalState={modalState}
- modalIsOpen={modalIsOpen}
- JoinExam={JoinExam}
- closeModal={closeModal}
- />
- <div style={{flexGrow : 1}}>
- { (isWeb && mounted.current) ?
- <Typography className ={classes.programTitleStyle}>{programTitle}</Typography> : <></>
- }
- <Grid container >
- <Grid item xs={12} sm={12} md={6} >
- <Paper
- className = {classes.paperStyleExam}
- elevation={1}
- >
- <Grid container justify="center" alignItems="center">
- <Grid container item xs={12} justify="flex-end" alignItems="center">
- <Grid item style={{ padding: "5px" }}>
- {type === archieved ? (
- <img
- style={{ height: "18px", width: "18px" }}
- src={archiveDateicon}
- alt="" ></img>
- ) : type === upcoming ? (
- <img
- style={{ height: "18px", width: "18px" }}
- src={schedule}
- alt="" ></img>
- ) : (
- <img
- style={{ height: "18px", width: "18px" }}
- src={runningState}
- alt="" ></img>
- )}
- </Grid>
- <Grid item>
- <Grid item style={{ fontWeight: "bold", fontSize: "12px",textAlign: "center", }}>
- {state[0].toUpperCase() + state.slice(1)}
- </Grid>
- <Grid
- item
- style={{
- fontSize: "11px",
- textAlign: "center",
- fontWeight : 'bold',
- fontFamily: "Arial, Helvetica, sans-serif",
- }}
- >
- {type === upcoming ? (
- TimeShow() ? (
- <> {getTimeFormat(timeLeft)} </>
- ) : (
- <>
- {month.substring(0, 3)} {("0" + date).slice(-2)}, {year}
- </>
- )
- ) : type === archieved ? (
- <>
- {month.substring(0, 3)} {("0" + date).slice(-2)}, {year}
- </>
- ) : (
- <>{getTimeFormat(timeLeft)}</>
- )}
- </Grid>
- </Grid>
- </Grid>
- </Grid>
- <Grid container style={{ marginTop: "15px" }}>
- <Grid item xs={12}>
- <Typography className={classes.titleStyle}>{title}</Typography>
- </Grid>
- </Grid>
- <div
- style={{ width: "90%", margin: "auto" ,marginTop : '10px',
- alignItems : "center",
- justifyContent : "center",
- display : "flex",
- flexWrap : "wrap"
- }}
- >
- <div style={{flexGrow : 1}}>
- <div
- style={{
- display: "flex",
- flexWrap: "wrap",
- alignItems: "center",
- justifyContent: "center",
- flexDirection: "row",
- textAlign : 'center'
- }}
- >
- <div style={{ flexGrow: 1}}>
- <img className={classes.iconSize1} src={examinee}alt="" ></img>
- <span className={classes.textSize1}>
- {total_examinees || 0}
- </span>
- </div>
- <div style={{ flexGrow: 1 }}>
- <ColoredLine color="black"></ColoredLine>
- </div>
- </div>
- </div>
- <div style={{flexGrow : 1}}>
- <div
- style={{
- display: "flex",
- flexWrap: "wrap",
- alignItems: "center",
- justifyContent: "center",
- flexDirection: "row",
- textAlign : 'center'
- }}
- >
- <div style={{ flexGrow: 1 }}>
- <img className={classes.iconSize1} src={score}alt="" ></img>
- <span className={classes.textSize1}>
- {(total_marks===0 && examState===upcoming) ? " ?" : total_marks}
- </span>
- </div>
- <div style={{ flexGrow: 1 }}>
- <ColoredLine color="black"></ColoredLine>
- </div>
- </div>
- </div>
- <div style={{flexGrow : 1}}>
- <div
- style={{
- display: "flex",
- flexWrap: "wrap",
- alignItems: "center",
- justifyContent: "center",
- flexDirection: "row",
- textAlign : 'center'
- }}
- >
- <div style={{ flexGrow: 1 }}>
- <img className={classes.iconSize1} src={clock}alt="" ></img>
- <span className={classes.textSize1}>
- {(duration===0 && examState===upcoming) ? " ? Min" : durationConvert(duration)}
- </span>
- </div>
- </div>
- </div>
- </div>
- <Grid container
- alignItems="center"
- justify="center"
- style={{ width: "85%",margin : 'auto', textAlign : 'center'}} >
- <Grid item xs={4} >
- <div
- style={{
- display: "flex",
- flexWrap: "wrap",
- alignItems: "center",
- justifyContent: "center",
- textAlign : "center",
- flexDirection: "row",
- marginTop : "5px"
- }}
- >
- <div style={{ flexGrow: 1}}>
- <img className={classes.iconSize1} src={coins}alt="" ></img>
- <span className={classes.textSize2}>
- {cost}
- </span>
- </div>
- </div>
- </Grid>
- </Grid>
- <div
- style={{
- backgroundColor: "white",
- maxHeight: "130px",
- minHeight : "90px",
- width : '95%',
- marginTop : "15px",
- overflow : 'auto',
- borderRadius : '10px'
- }}
- className='container'
- >
- <div
- style={{ padding: "7px 0px",textAlign : "center" ,
- alignItems : 'center',justifyContent : 'center'}}
- className="d-flex justify-content-center"
- >
- <img
- className={classes.syllabusImage}
- src={document}
- alt="" ></img>
- <span className={classes.syllabusText}>
- Syllabus
- </span>
- </div>
- <div className ={classes.syllabusStyle}>
- {syllabus}
- </div>
- </div>
- <div style={{width : '95%',margin : 'auto',textAlign : 'center',marginTop : '10px'}}>
- <Grid container justify='center' alignItems='center' >
- <Grid item xs={4} >
- <Button
- className={classes.buttonStyle1}
- onClick={() => rankResultSolutionRoute("rankList")}
- >
- <img
- className = {classes.buttonImg1}
- src={rank}
- alt="" ></img>
- <span className = {classes.buttontxt1}>
- Rank List
- </span>
- </Button>
- </Grid>
- <Grid item xs={4} >
- <Button
- className={classes.buttonStyle1}
- onClick={() => rankResultSolutionRoute("result")}
- >
- <img
- className = {classes.buttonImg1}
- src={grade}
- alt="" ></img>
- <span className = {classes.buttontxt1}>
- Result
- </span>
- </Button>
- </Grid>
- <Grid item xs={4} >
- <Button
- className = {classes.buttonStyle1}
- onClick={() => rankResultSolutionRoute("solution")}
- >
- <img
- className = {classes.buttonImg1}
- src={solution}
- alt="" ></img>
- <span className={classes.buttontxt1}>
- Solution
- </span>
- </Button>
- </Grid>
- </Grid>
- </div>
- <div style={{width : '95%' ,margin : '10px auto'}}>
- <Typography style={{fontSize : '13px',color : "#828691"}}>
- *Once you click the start you won't be allowed to participate again
- </Typography>
- </div>
- { examState !== upcoming && <div style={{width : '95%',margin : '10px auto'}}>
- <Button variant='contained'
- className = {classes.joinButtonStyle}
- onClick={openModal}
- >
- <BiLogInCircle size={27} />
- <span
- style={{
- paddingLeft: "7px",
- fontWeight: "1700px",
- fontSize: "19px",
- }}
- >
- Join
- </span>
- </Button>
- </div>}
- </Paper>
- </Grid>
- {
- (isWeb && mounted.current) ? <Grid item sm={12} md={6} className={classes.bottomStyle} >
- <VerticalBar total_examinees={total_examinees} passed_examinees={passed_examinees}/>
- </Grid>
- : <></>
- }
- </Grid>
- </div>
- <Snackbar
- autoHideDuration={2000}
- anchorOrigin={{ vertical, horizontal }}
- open={openSnackbar}
- onClose={handleSnackBarClose}
- message="You have already participated in this exam"
- key={vertical + horizontal}
- />
- </div>
- );
- };
- export default ExamDetails;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement