Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdds project-scoped data flow to MulticalendarPage: reads/saves a session-scoped stored project, fetches projects via SWR using role-aware endpoints, normalizes projects with Changes
Sequence Diagram(s)sequenceDiagram
participant UI as MulticalendarPage
participant Auth as Auth/UserState
participant API as Projects API
participant Storage as localStorage
participant Assets as Assets/Bookings API
Auth->>UI: provide userId and role
UI->>Storage: readStoredProject(userId)
alt storedProject missing
UI->>API: fetch projects (role-dependent URL) via SWR
API-->>UI: return raw project list
UI->>UI: normalizeProjectList(raw list) -> ApiProject[]
alt projects exist
UI->>Storage: saveStoredProject(first project)
Storage-->>UI: storedProject persisted
end
end
UI->>Assets: fetch assets & bookings using resolved projectId
Assets-->>UI: return assets & bookings
UI-->>User: render calendar with assets/bookings
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/multicalendar/MulticalendarPage.tsx (1)
193-197:⚠️ Potential issue | 🟡 Minor"No project selected" error card flashes for new users while the project list is still loading.
When a user has no stored project (first-time use),
projectIdisnullwhile the projects SWR is in-flight. At that point:
errorevaluates to"No project selected"(line 195)loadingisfalse— the bookings SWR key isnull, so SWR never enters a loading statebookingsandavailableAssetsare both emptyAll conditions at line 284 are satisfied, so the error card with
"No project selected"is shown immediately, before the project fetch even completes.Consider distinguishing between "no project yet determined" (loading state) and "project confirmed missing" (genuine error):
🛠️ Proposed fix — introduce a projects-loading guard
+ const isProjectResolving = !storedProject?.id && !!projectsUrl; + const error = useMemo(() => { if (fetchError) return "Failed to fetch calendar data"; - if (userId && !projectId) return "No project selected"; + if (userId && !projectId && !isProjectResolving) return "No project selected"; return null; - }, [fetchError, userId, projectId]); + }, [fetchError, userId, projectId, isProjectResolving]);
projectsUrlbeing non-null signals that a fetch is in-progress/pending, so the "no project" message is suppressed until the fetch settles.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/multicalendar/MulticalendarPage.tsx` around lines 193 - 197, The "No project selected" message is shown too early because useMemo for error only checks projectId and not whether the projects request is still in-flight; update the error computation in the error useMemo (the const error = useMemo(...) block) to also check the projects fetch guard (e.g., projectsUrl or a projects-loading boolean) and return null while projectsUrl is non-null (fetch pending), so the "No project selected" message is suppressed until the projects SWR settles; keep existing checks for fetchError and the confirmed absence of projectId when projects are not loading.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/components/multicalendar/MulticalendarPage.tsx`:
- Around line 98-134: Replace the useMemo-storedProject with a stateful,
lazy-initialized value so writes to localStorage update in-session: change
storedProject from useMemo(() => readStoredProject(userId), [userId]) to
useState(() => readStoredProject(userId)) (or useState<ApiProject|null>(() =>
readStoredProject(userId))). After calling saveStoredProject(userId,
firstProject) inside the effect, call setStoredProject(firstProject) so the
component re-renders and projectsUrl (which currently reads storedProject?.id)
becomes null and stops SWR from refetching; also update any places that read
storedProject (projectsUrl, projectId, effect guards) to use the new state
variable and ensure hooks' dependency arrays reference the state variable (e.g.,
storedProject?.id) not the old memo.
---
Outside diff comments:
In `@src/components/multicalendar/MulticalendarPage.tsx`:
- Around line 193-197: The "No project selected" message is shown too early
because useMemo for error only checks projectId and not whether the projects
request is still in-flight; update the error computation in the error useMemo
(the const error = useMemo(...) block) to also check the projects fetch guard
(e.g., projectsUrl or a projects-loading boolean) and return null while
projectsUrl is non-null (fetch pending), so the "No project selected" message is
suppressed until the projects SWR settles; keep existing checks for fetchError
and the confirmed absence of projectId when projects are not loading.
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 `@src/components/multicalendar/MulticalendarPage.tsx`:
- Around line 121-125: The useSWR call that defines projectsRaw/projectsLoading
must also return the projects error and mutate so failures are surfaced and
retryable: update the hook invocation to destructure { data: projectsRaw, error:
projectsError, isLoading: projectsLoading, mutate: mutateProjects } from
useSWR(projectsUrl, swrFetcher, SWR_CONFIG); then update the UI branch that
currently shows "No project selected" to render the projectsError when present
(use projectsError to show the real fetch failure), and modify handleRefresh to
call mutateProjects() as part of the retry path so projects are refetched when
the user clicks Retry.
There was a problem hiding this comment.
♻️ Duplicate comments (2)
src/components/multicalendar/MulticalendarPage.tsx (2)
207-214: Previous silent-failure bug correctly remediated —projectsErroris now surfaced and loading state is correctly guarded.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/multicalendar/MulticalendarPage.tsx` around lines 207 - 214, The useMemo block should surface projectsError and avoid showing "No project selected" while projects are loading; ensure the conditional order and dependency array on useMemo include fetchError, projectsError, projectsUrl, projectsLoading, userId, and projectId (as currently in the useMemo) so that projectsError is returned when present and the projectsLoading guard prevents the "No project selected" message while projects are still loading; keep the conditions in useMemo exactly as written to preserve this behavior.
101-109: Previous perpetual-revalidation bug correctly resolved.Both the lazy-init state and the
userId-change effect are in place.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/multicalendar/MulticalendarPage.tsx` around lines 101 - 109, Remove the redundant useEffect that re-reads localStorage on userId change: the lazy-initialized useState with readStoredProject handles initial load, so delete the useEffect block referencing setStoredProject/readStoredProject and userId to avoid duplicate reads; keep the state variables (storedProject, setStoredProject) and the readStoredProject call only in the lazy initializer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/components/multicalendar/MulticalendarPage.tsx`:
- Around line 207-214: The useMemo block should surface projectsError and avoid
showing "No project selected" while projects are loading; ensure the conditional
order and dependency array on useMemo include fetchError, projectsError,
projectsUrl, projectsLoading, userId, and projectId (as currently in the
useMemo) so that projectsError is returned when present and the projectsLoading
guard prevents the "No project selected" message while projects are still
loading; keep the conditions in useMemo exactly as written to preserve this
behavior.
- Around line 101-109: Remove the redundant useEffect that re-reads localStorage
on userId change: the lazy-initialized useState with readStoredProject handles
initial load, so delete the useEffect block referencing
setStoredProject/readStoredProject and userId to avoid duplicate reads; keep the
state variables (storedProject, setStoredProject) and the readStoredProject call
only in the lazy initializer.
Summary by CodeRabbit
New Features
Bug Fixes