feat: semester autofill updated#235
Conversation
|
@SrujanTag is attempting to deploy a commit to the mrimmortal09's projects Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughAdded a new Changes
Sequence Diagram(s)sequenceDiagram
participant Browser as Browser (Form)
participant Hook as useSemesterAutofill
participant Auth as NextAuth Session
participant State as Form State (setFormData)
Browser->>Auth: request session (useSession)
Auth-->>Browser: session with user.email
Browser->>Hook: call useSemesterAutofill(session, year, semester, setFormData)
Hook->>Hook: extract year from email (/\20\d{2}/)
Hook->>Hook: compute semester from current date (clamped 1–8)
alt year & semester are empty
Hook->>State: setFormData({ year, semester })
State-->>Browser: form updates (controlled selects show values)
else populated
Hook-->>Browser: no update (fields left for user)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/upload-papers/page.tsx (1)
401-444:⚠️ Potential issue | 🔴 CriticalCritical: Select components are missing
valueprop — auto-filled values won't display.The auto-fill effect updates
formData.yearandformData.semester, but these Select components don't have avalueprop bound to the state. The dropdowns will remain showing placeholders even after auto-fill succeeds.Compare with
upload-notes/page.tsx(lines 409-445) which correctly usesvalue={formData.year || ''}andvalue={formData.semester || ''}.🐛 Proposed fix to add value props
<Select + value={formData.year || undefined} onValueChange={(value: string) => handleSelectChange('year', value) } ><Select + value={formData.semester || undefined} onValueChange={(value: string) => handleSelectChange('semester', value) } >🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/upload-papers/page.tsx` around lines 401 - 444, The Select components for year and semester are missing bound values so auto-filled formData isn't shown; update the two Select elements to include value props bound to state (e.g., value={formData.year || ''} on the year Select and value={formData.semester || ''} on the semester Select) so the UI reflects auto-fill, keeping the existing onValueChange handler (handleSelectChange) intact.
🧹 Nitpick comments (1)
app/upload-papers/page.tsx (1)
78-105: Consider extracting auto-fill logic to a shared custom hook.This entire effect block is duplicated verbatim in
app/upload-notes/page.tsx(lines 75-102). Extracting to a shared hook (e.g.,useBatchSemesterAutofill) would reduce duplication and make future maintenance easier.♻️ Example shared hook
Create
hooks/useBatchSemesterAutofill.ts:import { useEffect } from 'react' import { useSession } from 'next-auth/react' export function useBatchSemesterAutofill( currentYear: string, currentSemester: string, onAutofill: (year: string, semester: string) => void ) { const { data: session } = useSession() useEffect(() => { if (session?.user?.email && currentYear === '' && currentSemester === '') { const yearMatch = session.user.email.match(/\d{4}/) const batchYear = yearMatch?.[0] if (!batchYear) return const today = new Date() const yearDiff = today.getFullYear() - parseInt(batchYear) let calcSem = today.getMonth() + 1 >= 8 ? yearDiff * 2 + 1 : yearDiff * 2 calcSem = Math.max(1, Math.min(8, calcSem)) onAutofill(batchYear, String(calcSem)) } }, [session, currentYear, currentSemester, onAutofill]) }Then use in both pages:
useBatchSemesterAutofill( formData.year, formData.semester, useCallback((year, semester) => { setFormData(prev => ({ ...prev, year, semester })) }, []) )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/upload-papers/page.tsx` around lines 78 - 105, The effect that auto-fills batch year/semester is duplicated; extract it into a reusable hook (e.g., useBatchSemesterAutofill) and replace the inline useEffect in app/upload-papers/page.tsx and app/upload-notes/page.tsx with a call to that hook. The hook should read session (useSession), compute batchYear from session.user.email (match(/\d{4}/)), calculate calcSem using current month/year and clamp to 1..8, and invoke a callback like onAutofill(year, semester); update the pages to call useBatchSemesterAutofill(formData.year, formData.semester, useCallback((y,s) => setFormData(prev => ({...prev, year: y, semester: s})), [])) so all logic (previously inside the useEffect) is centralized in useBatchSemesterAutofill.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@app/upload-papers/page.tsx`:
- Around line 401-444: The Select components for year and semester are missing
bound values so auto-filled formData isn't shown; update the two Select elements
to include value props bound to state (e.g., value={formData.year || ''} on the
year Select and value={formData.semester || ''} on the semester Select) so the
UI reflects auto-fill, keeping the existing onValueChange handler
(handleSelectChange) intact.
---
Nitpick comments:
In `@app/upload-papers/page.tsx`:
- Around line 78-105: The effect that auto-fills batch year/semester is
duplicated; extract it into a reusable hook (e.g., useBatchSemesterAutofill) and
replace the inline useEffect in app/upload-papers/page.tsx and
app/upload-notes/page.tsx with a call to that hook. The hook should read session
(useSession), compute batchYear from session.user.email (match(/\d{4}/)),
calculate calcSem using current month/year and clamp to 1..8, and invoke a
callback like onAutofill(year, semester); update the pages to call
useBatchSemesterAutofill(formData.year, formData.semester, useCallback((y,s) =>
setFormData(prev => ({...prev, year: y, semester: s})), [])) so all logic
(previously inside the useEffect) is centralized in useBatchSemesterAutofill.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ad255dbf-e5c9-441c-b5c4-4bfd77e81f68
📒 Files selected for processing (2)
app/upload-notes/page.tsxapp/upload-papers/page.tsx
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@coderabbitai full-review |
|
@coderabbitai Where is the data: session coming from? Do we store it? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainI'll fetch the changed files to perform a thorough review. 🏁 Script executed: Length of output: 38766
PR Review: Feat/semester autofill updatedThe screenshots confirm that the auto-fill logic is mathematically correct — Batch 2024 → Semester 4 and Batch 2023 → Semester 6 for April 2026 are both right. However, there is one critical bug and several issues that need attention before merging. 🔴 Critical Bug —
|
| Severity | File | Issue |
|---|---|---|
| 🔴 Critical | upload-papers/page.tsx |
Missing value prop on Year and Semester <Select> — auto-fill state is set but not displayed |
| 🟠 Major | Both files | Duplicated useEffect — should be extracted to a custom hook |
| 🟡 Minor | Both files | Regex /\d{4}/ too broad — use /20\d{2}/ |
| 🟡 Minor | Both files | parseInt missing radix argument |
| 🟡 Minor | Both files | Asymmetric guard condition for partial-empty state |
The critical bug in upload-papers/page.tsx must be fixed before merging — without the value prop, the auto-fill feature effectively doesn't work on that page despite the state being correctly computed.
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 39242 🏁 Script executed: Length of output: 5655
Where does
|
| What | Where |
|---|---|
| User record (name, email, roles, googleId, etc.) | ✅ Stored in MongoDB |
| Session itself | ❌ Not in DB — it's a stateless JWT in a browser cookie |
The config explicitly sets:
session: {
strategy: 'jwt', // stateless, no DB session table
maxAge: 24 * 60 * 60, // 24-hour expiry
}Relevance to this PR
The session.user.email used for autofill (e.g., [email protected]) comes directly from the JWT cookie set at login time. It's the IIITL institutional email that was validated during the Google sign-in flow (endsWith('@iiitl.ac.in') check in the signIn callback). No additional storage or fetch is needed to access it in the component.
@SrujanTag note |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@hooks/useSemesterAutofill.ts`:
- Around line 17-22: The semester calculation uses client-local Date (today,
currentYear, currentMonth) which causes timezone-dependent results; switch to
using UTC-based values (getUTCFullYear and getUTCMonth) so the month/year are
computed in a standardized timezone before computing yearDiff and calcSem (keep
the existing logic that treats month>=8 as the August cutoff and the clamp with
Math.min/Math.max); update references to
today/currentYear/currentMonth/yearDiff/calcSem/batchYear accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ec9972a0-9640-44f9-b5eb-ddf1eb1a333c
📒 Files selected for processing (3)
app/upload-notes/page.tsxapp/upload-papers/page.tsxhooks/useSemesterAutofill.ts
✅ Files skipped from review due to trivial changes (1)
- app/upload-notes/page.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- app/upload-papers/page.tsx
|
+5 for proper handling of merge conflicts |
Resolves #231 .
Description
Live Demo (if any)
Note for Maintainer
Checkout
Summary by CodeRabbit