Skip to content

Conversation

hb1998
Copy link
Collaborator

@hb1998 hb1998 commented Jan 13, 2025

User description

image
image

Added time duration to assessment and created candidate token based on assessment duration.


PR Type

Enhancement, Bug fix


Description

  • Added dynamic token duration based on exam settings.

  • Implemented timeout handling and user notifications in assessments.

  • Enhanced UI for exam duration display and settings.

  • Updated backend to support exam-specific token durations.


Changes walkthrough 📝

Relevant files
Enhancement
11 files
CandidateAssessment.tsx
Added `examId` to candidate creation payload.                       
+2/-1     
QuestionsPage.tsx
Added timeout handling and navigation on assessment expiry.
+7/-1     
Timer.tsx
Enhanced timer with timeout logic and user notifications.
+28/-5   
ExamDetail.tsx
Added duration handling and saving logic for exams.           
+26/-3   
ExamList.tsx
Displayed exam duration in hours and minutes.                       
+3/-0     
ExamSettings.tsx
Updated exam settings to handle duration changes dynamically.
+11/-16 
Editor.tsx
Integrated timer into code editor for assessment timeout.
+13/-1   
schema.ts
Added `examId` to candidate schema and `duration` to exam schema.
+7/-1     
jwt.ts
Updated JWT creation to support custom durations.               
+3/-3     
index.ts
Adjusted candidate creation to include exam-specific token duration.
+6/-5     
Assessment.css
Updated timer styles for better visibility.                           
+4/-0     
Formatting
1 files
Exam.API.ts
Minor formatting update in exam API service.                         
+1/-0     

💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

@vercel
Copy link

vercel bot commented Jan 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
code-scrutinex ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 13, 2025 10:13pm

@codiumai-pr-agent-free
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 Security concerns

JWT Token Exposure:
The JWT token expiration time is calculated on the client side using jwt_decode, which could potentially expose sensitive token information. Consider handling token expiration server-side or using a more secure approach.

⚡ Recommended focus areas for review

Race Condition

The timer state updates and timeout handling could have race conditions since multiple useEffect hooks are modifying shared state. Consider consolidating timer logic into a single effect.

useEffect(() => {
    const timer = setInterval(() => {
        setTimeLeft((prevTimeLeft) => {
            if (prevTimeLeft === 0) return 0;
            return prevTimeLeft - 1;
        });
    }, 1000);

    return () => clearInterval(timer);
}, []);

useEffect(() => {
    const hours = Math.floor(timeLeft / 3600);
    const minutes = Math.floor((timeLeft % 3600) / 60);
    const seconds = timeLeft % 60;

    if (hours === 0 && minutes === 5 && seconds === 0) toast.warning('Only 5 minutes left');

    if (hours === 0 && minutes === 1 && seconds === 0) toast.warning('Only 1 minutes left');

    if(hours === 0 && minutes === 0 && seconds === 20) toast.warning("Assessment will be submitted automatically in 10 seconds");

    if(hours === 0 && minutes === 0 && seconds === 10){
        props.onTimeout();
        toast.success("Assessment submitted successfully!")
    }

}, [timeLeft]);

Input Validation
The duration time inputs lack validation to ensure valid hour/minute combinations. Should add validation to prevent invalid time combinations.

@codiumai-pr-agent-free
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Score
Possible issue
Add missing dependency to useEffect to prevent stale closure issues with callback functions

The onTimeout prop is not properly typed in the useEffect dependency array, which
could cause stale closure issues. Add it to the dependency array to ensure the
timeout handler stays current.

src/Modules/CandidateAssessment/components/Timer.tsx [29-45]

 useEffect(() => {
     if(hours === 0 && minutes === 0 && seconds === 10){
         props.onTimeout();
         toast.success("Assessment submitted successfully!")
     }
-}, [timeLeft]);
+}, [timeLeft, props.onTimeout]);
  • Apply this suggestion
Suggestion importance[1-10]: 8

Why: Critical fix for React hooks dependency array that could cause stale closures and incorrect timeout behavior, potentially affecting the assessment submission timing.

8
Prevent timer from displaying negative values by adding proper boundary check

The timer should handle the case when timeLeft becomes negative. Currently, it only
checks for zero, which could lead to negative countdown values. Add a check to
ensure timeLeft never goes below zero.

src/Modules/CandidateAssessment/components/Timer.tsx [20-23]

 setTimeLeft((prevTimeLeft) => {
-    if (prevTimeLeft === 0) return 0;
+    if (prevTimeLeft <= 0) return 0;
     return prevTimeLeft - 1;
 });
  • Apply this suggestion
Suggestion importance[1-10]: 7

Why: Important defensive programming fix that prevents potential display issues and ensures the timer behaves correctly at boundary conditions.

7
Add input validation to prevent runtime errors from malformed string inputs

The handleSettingsChange function doesn't validate the input value format, which
could cause runtime errors if the value string doesn't match the expected format of
"number space unit". Add input validation.

src/Modules/Exam/ExamDetail.tsx [53-59]

-const handleSettingsChange = (value) => {
-    const Timeduration = value.split(" ");
+const handleSettingsChange = (value: string) => {
+    if (!value || !value.includes(" ")) return;
+    const [duration, unit] = value.split(" ");
+    if (!duration || !unit) return;
     setTime({
         ...time,
-        [Timeduration[1]] : Number(Timeduration[0])
-    })
+        [unit]: Number(duration)
+    });
 };
Suggestion importance[1-10]: 7

Why: Important defensive programming enhancement that prevents potential runtime errors from invalid input formats in the exam duration settings.

7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants