Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(token): token duration update #19

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

NarendranKT
Copy link

@NarendranKT NarendranKT commented May 20, 2024

User description

image
image

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


PR Type

Enhancement, Bug fix


Description

  • Included examId in candidate creation data.
  • Implemented timeout handling and navigation in QuestionsPage.
  • Added timeout handling and warnings in Timer component.
  • Implemented exam duration handling and saving in ExamDetail.
  • Displayed exam duration in the exam list.
  • Updated ExamSettings to handle duration changes.
  • Added Timer component and handled assessment timeout in Editor.
  • Updated schema to include examId and duration.
  • Modified createJWT to accept custom duration.
  • Included examId and duration in candidate creation.
  • Updated timer style to use brand color.

Changes walkthrough 📝

Relevant files
Enhancement
11 files
CandidateAssessment.tsx
Include examId in candidate creation data.                             

src/Modules/CandidateAssessment/CandidateAssessment.tsx

  • Added examId to userData object.
+2/-1     
QuestionsPage.tsx
Handle assessment timeout and navigation.                               

src/Modules/CandidateAssessment/QuestionsPage.tsx

  • Added navigate for navigation.
  • Implemented handleTimeout function to clear assessment and navigate to
    assessment over page.
  • Passed handleTimeout to Timer component.
  • +7/-1     
    Timer.tsx
    Add timeout handling and warnings in Timer component.       

    src/Modules/CandidateAssessment/components/Timer.tsx

  • Added onTimeout prop to Timer component.
  • Implemented warnings for remaining time.
  • Called onTimeout and displayed success message when time is up.
  • +28/-5   
    ExamDetail.tsx
    Implement exam duration handling and saving.                         

    src/Modules/Exam/ExamDetail.tsx

  • Added Time interface for handling exam duration.
  • Implemented handleSettingsChange to update duration.
  • Added saveDuration function to save updated duration.
  • Passed duration and handleSettingsChange to ExamSettings.
  • +26/-3   
    ExamList.tsx
    Display exam duration in exam list.                                           

    src/Modules/Exam/ExamList.tsx

    • Displayed exam duration in the exam list.
    +3/-0     
    ExamSettings.tsx
    Update ExamSettings to handle duration changes.                   

    src/Modules/Exam/components/ExamSettings.tsx

  • Updated ExamSettings to handle duration changes.
  • Passed duration and addDuration to Select components.
  • +11/-16 
    Editor.tsx
    Add Timer component and handle assessment timeout.             

    src/Modules/common/CodeEditor/Editor.tsx

  • Added Timer component to display remaining time.
  • Implemented handleTimeout to submit assessment on timeout.
  • +13/-1   
    schema.ts
    Update schema to include examId and duration.                       

    src/types/schema.ts

  • Added examId to candidate table schema.
  • Added duration to exam table schema.
  • +7/-1     
    jwt.ts
    Modify createJWT to accept custom duration.                           

    supabase/functions/_shared/jwt.ts

  • Modified createJWT to accept duration and set expiration accordingly.
  • +3/-3     
    index.ts
    Include examId and duration in candidate creation.             

    supabase/functions/create-candidate/index.ts

  • Added examId to candidate creation request.
  • Fetched exam duration and passed it to createJWT.
  • +6/-5     
    Assessment.css
    Update timer style to use brand color.                                     

    src/Modules/CandidateAssessment/styles/Assessment.css

    • Updated .timer class to use brand color.
    +4/-0     
    Miscellaneous
    1 files
    Exam.API.ts
    Minor formatting change.                                                                 

    src/Modules/Exam/services/Exam.API.ts

    • Minor formatting change.
    +1/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Copy link

    vercel bot commented May 20, 2024

    @NarendranKT is attempting to deploy a commit to the lumel Team on Vercel.

    A member of the Team first needs to authorize it.

    @codiumai-pr-agent-free codiumai-pr-agent-free bot added enhancement New feature or request Bug fix labels May 20, 2024
    Copy link

    PR Description updated to latest commit (827bd3c)

    Copy link

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    3, because the PR includes multiple changes across various components related to handling exam duration and candidate token creation based on the exam duration. The changes are spread across multiple files and involve both frontend and backend modifications, requiring a thorough review to ensure all parts work together seamlessly.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Possible Bug: In Timer.tsx, the toast message for "Assessment will be submitted automatically in 10 seconds" appears when there are 20 seconds left, which might confuse users. Consider adjusting the timing or the message to reflect accurate information.

    Data Handling: The handleSettingsChange in ExamDetail.tsx directly modifies state based on the input string format, which could lead to errors if the input format is unexpected. Robust parsing and error handling are recommended.

    Inconsistent Behavior: The createJWT function in jwt.ts now depends on the duration parameter to set the token expiration. If duration is not provided or is zero, it defaults to a fixed duration, which might not always be the desired behavior in all use cases.

    🔒 Security concerns

    No

    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Improve the countdown logic to handle cases when the time left is less than one second

    The setTimeLeft function should handle the case when prevTimeLeft is less than 1 to avoid
    negative countdowns. This can be achieved by checking if prevTimeLeft is less than or
    equal to 1 and then returning 0.

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

     setTimeLeft((prevTimeLeft) => {
    -    if (prevTimeLeft === 0) return 0;
    +    if (prevTimeLeft <= 1) return 0;
         return prevTimeLeft - 1;
     });
     
    Suggestion importance[1-10]: 8

    Why: This suggestion addresses a potential bug where the countdown could go negative, which is a significant issue. The proposed change ensures the countdown stops at zero, improving the robustness of the timer functionality.

    8
    Enhancement
    Improve the robustness of time string parsing in the settings change handler

    The handleSettingsChange function should parse the time string more robustly to avoid
    potential bugs with different string formats. Using a regular expression to extract
    numbers and units can make this parsing more reliable.

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

     const handleSettingsChange = (value) => {
    -    const Timeduration = value.split(" ");
    -    setTime({
    -        ...time,
    -        [Timeduration[1]] : Number(Timeduration[0])
    -    })
    +    const matches = value.match(/(\d+)\s*(hr|min)/);
    +    if (matches) {
    +        setTime({
    +            ...time,
    +            [matches[2]]: Number(matches[1])
    +        });
    +    }
     };
     
    Suggestion importance[1-10]: 7

    Why: This suggestion improves the robustness of the time string parsing, which can prevent potential bugs due to different string formats. It enhances the reliability of the function, making it more maintainable.

    7
    Add a conditional check to ensure examId is not undefined before adding it to the userData object

    The object userData should include a check to ensure examId is not undefined before adding
    it to the object, to prevent potential issues with undefined values being sent to the API.

    src/Modules/CandidateAssessment/CandidateAssessment.tsx [76-79]

     const userData = {
         emailId: values.email,
         name: values.name,
    -    examId: examId
    +    ...(examId ? { examId: examId } : {})
     };
     
    Suggestion importance[1-10]: 7

    Why: This suggestion adds a conditional check to ensure examId is not undefined, which can prevent potential issues with undefined values being sent to the API. It enhances the robustness of the data being sent.

    7
    Maintainability
    Refactor the onChange handlers of the Select components to handle hours and minutes updates separately

    The Select components in ExamSettings should have a unified onChange handler to update the
    state correctly based on the selected hour and minute. This can be done by passing a type
    identifier to the handler.

    src/Modules/Exam/components/ExamSettings.tsx [12-25]

    -<Select placeholder="No hour limit" value={`${duration.hr} hr`} style={{ width: 180 }} onChange={addDuration}>
    -<Select placeholder="No minute limit" value={`${duration.min} min`} style={{ width: 180 }} onChange={addDuration}>
    +<Select placeholder="No hour limit" value={`${duration.hr} hr`} style={{ width: 180 }} onChange={(value) => addDuration(value, 'hr')}>
    +<Select placeholder="No minute limit" value={`${duration.min} min`} style={{ width: 180 }} onChange={(value) => addDuration(value, 'min')}>
     
    Suggestion importance[1-10]: 6

    Why: This suggestion improves maintainability by unifying the onChange handlers for the Select components. It makes the code cleaner and easier to manage, although the current implementation is functional.

    6

    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.

    1 participant