Advertisement
Fahim_7861

exam details

Jul 1st, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.32 KB | None | 0 0
  1. const theme = useTheme();
  2.  
  3. const isWeb = useMediaQuery(theme.breakpoints.up("sm"));
  4.  
  5. const classes = useStyles();
  6.  
  7. const [openSnackbar, setOpenSnackbar] = React.useState(false);
  8.  
  9. const [joinClick,setJoinClick] = React.useState(false);
  10.  
  11. const vertical= 'bottom', horizontal='center';
  12.  
  13. const handleSnackBarClick = () => {
  14. setOpenSnackbar(true);
  15. };
  16.  
  17. const handleSnackBarClose = () => {
  18. setOpenSnackbar(false);
  19. };
  20.  
  21.  
  22. const [modalState, setModalState] = useState(SHOWMODAL);
  23.  
  24. const [modalIsOpen, setIsOpen] = React.useState(false);
  25.  
  26. const { id, program, examState } = useParams();
  27.  
  28. const {programs} = useSelector((state) => state.initData);
  29.  
  30. let programTitle = "";
  31.  
  32. const history = useHistory();
  33.  
  34. const isSignedIn = useSelector((state) => state.auth.isSignedIn);
  35.  
  36. const token = useSelector((state) => state.auth.userId.token);
  37.  
  38. const auth = useSelector(state =>state.auth);
  39.  
  40. let purchasedExamList = [];
  41.  
  42. if(auth!=undefined && auth.userId!=undefined && auth.userId.user_info!=undefined && auth.userId.user_info.billing_profile!=undefined )
  43. {
  44. if(auth.userId.user_info.billing_profile.purchased_exams!=undefined)
  45. {
  46. purchasedExamList = auth.userId.user_info.billing_profile.purchased_exams;
  47. }
  48. }
  49.  
  50.  
  51. const dispatch = useDispatch();
  52.  
  53. let currentExam;
  54.  
  55.  
  56.  
  57. if(programs!==undefined)
  58. {
  59. const temp = programs.find(pg=> pg.id==program);
  60.  
  61. if(temp!==undefined)
  62. programTitle = temp.title;
  63. }
  64.  
  65.  
  66.  
  67.  
  68. const archievedCurrentExam = useSelector(
  69. (state) => state.archievedData.exams
  70. );
  71.  
  72. const currentUpcomingRunning = useSelector((state) => state.initData.exams);
  73.  
  74. if (currentUpcomingRunning !== undefined)
  75. currentExam = currentUpcomingRunning.filter((ex) => ex.id == id)[0];
  76.  
  77. if (currentExam === undefined && archievedCurrentExam !== undefined)
  78. currentExam = archievedCurrentExam.filter((ex) => ex.id == id)[0];
  79.  
  80. const getEndTime = () => {
  81. if (currentExam === undefined || currentExam.end_time === undefined)
  82. return new Date().getTime();
  83. else return currentExam.end_time;
  84. };
  85.  
  86. const [timeLeft, setTimeLeft] = useState(
  87. new Date(getEndTime()).getTime() - new Date().getTime()
  88. );
  89.  
  90. useEffect(() => {
  91. if (0>timeLeft) {
  92. return;
  93. }
  94.  
  95.  
  96.  
  97. if(0<timeLeft && timeLeft<Need_StartTimer)
  98.  
  99. {
  100. const intervalId = setInterval(() => {
  101. console.log(timeLeft,'shojib');
  102. if(0<timeLeft && timeLeft<Need_StartTimer)
  103. setTimeLeft(timeLeft - 1000);
  104. }, 1000);
  105.  
  106.  
  107. return () => clearInterval(intervalId);
  108. }
  109.  
  110.  
  111.  
  112. }, [timeLeft]);
  113.  
  114.  
  115. React.useEffect(()=>
  116. {
  117. const check = purchasedExamList.some(ex=>ex==id);
  118.  
  119. if(check && joinClick){
  120.  
  121. history.replace(mcqExam(program, id, examState));
  122.  
  123.  
  124.  
  125. }
  126.  
  127. return ()=>
  128. {
  129. setJoinClick(false);
  130. }
  131.  
  132. },[purchasedExamList.length])
  133.  
  134.  
  135. if (currentExam === undefined) {
  136. return <LoaderComponent />;
  137. }
  138.  
  139. const routeChange = () => {
  140. if (examState === upcoming) return;
  141.  
  142. else if (examState === running) {
  143. if (currentExam.purchased)
  144. handleSnackBarClick()
  145. else {
  146. dispatch(purchaseExamAction(token, { exam: id }));
  147.  
  148.  
  149.  
  150. dispatch(mcqAnsActions(EXAMID, { exam: id }));
  151.  
  152.  
  153. }
  154. return;
  155. }
  156. else
  157. {
  158. if (currentExam.purchased) {
  159. dispatch(mcqAnsActions(EXAMID, { exam: id }));
  160. history.replace(mcqExam(program, id, examState));
  161.  
  162. }
  163. else {
  164. dispatch(purchaseExamAction(token, { exam: id }));
  165.  
  166. dispatch(mcqAnsActions(EXAMID, { exam: id }));
  167.  
  168.  
  169. }
  170. }
  171. }
  172.  
  173.  
  174.  
  175.  
  176. // if (!isSignedIn) return <Redirect to={"/login"} />;
  177.  
  178. const { state, title, syllabus, total_marks, cost, duration } = currentExam;
  179.  
  180. const type = state;
  181.  
  182. const { total_examinees, standings , passed_examinees} = currentExam.statistics;
  183.  
  184. const ColoredLine = ({ color }) => (
  185. <span
  186. style={{
  187. borderLeft: `3px solid ${color}`,
  188.  
  189. textAlign: "right",
  190. alignItems: "right",
  191. }}
  192. />
  193. );
  194.  
  195.  
  196.  
  197.  
  198.  
  199. let createdDate = new Date(currentExam.end_time);
  200.  
  201. const date = createdDate.getDate();
  202.  
  203. const year = createdDate.getFullYear();
  204.  
  205. const month = createdDate.toLocaleString("default", { month: "long" });
  206.  
  207. const durationConvert = (duration) => {
  208.  
  209. // return '1h 20 Min';
  210. duration /= 60000;
  211.  
  212. if (duration >= 60) {
  213. if (duration % 60)
  214. return `${parseInt(duration / 60)}h ${duration % 60} Min`;
  215.  
  216. return `${parseInt(duration / 60)}h`;
  217. }
  218.  
  219. return `${duration} Min`;
  220. };
  221.  
  222. const TimeShow = (timeleft) => {
  223. if (type == archieved) return false;
  224.  
  225. const minLeft = timeLeft / 60000;
  226.  
  227. if (minLeft <= 2880) return true;
  228.  
  229. return false;
  230. };
  231.  
  232.  
  233.  
  234. function openModal() {
  235. if (examState === running) {
  236.  
  237. if (currentExam.purchased)
  238. {
  239.  
  240.  
  241. return handleSnackBarClick()
  242. }
  243. }
  244.  
  245. setModalState(SHOWMODAL);
  246.  
  247. setIsOpen(true);
  248. }
  249.  
  250. function afterOpenModal() {
  251. // references are now sync'd and can be accessed.
  252. }
  253.  
  254. function closeModal(str) {
  255. if (str === "close") setIsOpen(false);
  256. }
  257.  
  258. function JoinExam() {
  259.  
  260. setJoinClick(true);
  261.  
  262. setIsOpen(false);
  263.  
  264. routeChange();
  265.  
  266.  
  267. }
  268.  
  269.  
  270.  
  271. const modalCall=(modal)=>
  272. {
  273. setModalState(modal);
  274. setIsOpen(true);
  275.  
  276. }
  277.  
  278. const rankResultSolutionRoute = (path) => {
  279. console.log(upcoming, examState,path,currentExam);
  280.  
  281. if (examState === upcoming) {
  282. setModalState(upcoming);
  283.  
  284. setIsOpen(true);
  285.  
  286. return;
  287. }
  288.  
  289. else if (currentExam === undefined) return;
  290.  
  291. else if(examState===running)
  292. {
  293. if (path === "rankList") {
  294.  
  295. if (currentExam.standing_visibility)
  296. history.push(resultDetails(id, examStandings));
  297.  
  298. else {
  299.  
  300. modalCall(RUNNING);
  301. }
  302. }
  303. else if(path==="result")
  304. {
  305. if(currentExam.purchased)
  306. {
  307. if(currentExam.result_visibility)
  308. history.push(resultDetails(id));
  309.  
  310. else modalCall(RUNNING);
  311.  
  312.  
  313.  
  314.  
  315.  
  316. }
  317. else modalCall(NOT_PARTICIPATE);
  318.  
  319.  
  320.  
  321.  
  322. }
  323. else if(path==="solution")
  324. {
  325. if(currentExam.purchased)
  326. {
  327. if(currentExam.solution_visibility)
  328. history.push(resultDetails(id, answersheet));
  329.  
  330. else{
  331. modalCall(RUNNING);
  332. }
  333.  
  334.  
  335. }
  336. else
  337. {
  338.  
  339. modalCall(NOT_PARTICIPATE);
  340.  
  341. }
  342.  
  343. }
  344.  
  345. }
  346.  
  347. else if(examState===archieved)
  348. {
  349.  
  350. if (path === "rankList")
  351. history.push(resultDetails(id, examStandings));
  352.  
  353.  
  354. else if(currentExam.purchased)
  355. {
  356. if(path==='solution')
  357. history.push(resultDetails(id, answersheet));
  358.  
  359.  
  360.  
  361. else if(path==='result')
  362. modalCall(NOT_AVAILABLE)
  363. }
  364. else{
  365.  
  366. modalCall(NOT_PARTICIPATE);
  367.  
  368.  
  369. }
  370.  
  371.  
  372.  
  373.  
  374. }
  375.  
  376. return ;
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement