Conversation
|
@edulelis is attempting to deploy a commit to the Inbox Zero OSS Program Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughAdds calendar connection awareness to Draft Replies settings. Introduces a CalendarConnectPrompt component, a useCalendar hook, a server action to check calendar status, a footer slot in SettingCard to display status/prompt, exposes linkSocial from auth client, and adds CALENDAR_SCOPES for Google Calendar. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant DraftReplies as DraftReplies.tsx
participant useAccount
participant useCalendar
participant Action as checkCalendarStatusAction
participant DB as Prisma
User->>DraftReplies: Open Draft Replies settings
DraftReplies->>useAccount: get emailAccountId
DraftReplies->>useCalendar: useCalendar(emailAccountId)
useCalendar->>Action: checkCalendarStatus(emailAccountId)
Action->>DB: find emailAccount + scopes
DB-->>Action: account, scopes
Action-->>useCalendar: { isConnected, hasCalendarScopes, provider, accountId? }
useCalendar-->>DraftReplies: status, isLoading
Note over DraftReplies: Render footer: loading / connected / prompt
sequenceDiagram
autonumber
actor User
participant Footer as SettingCard.footer
participant Prompt as CalendarConnectPrompt
participant Auth as linkSocial (auth-client)
participant Google as Google OAuth
participant Router as App Router
participant useCalendar as useCalendar
User->>Footer: Click "Connect your calendar"
Footer->>Prompt: onClick
Prompt->>Auth: linkSocial("google", CALENDAR_SCOPES, callbackURL)
Auth->>Google: Start OAuth with scopes
Google-->>Router: Redirect to callbackURL (?calendarLinked=true)
Router->>useCalendar: re-run checkStatus
useCalendar-->>Footer: Updated status (connected/scopes)
Note over Footer: Footer re-renders with success state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. ✨ Finishing touches
🧪 Generate unit tests
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: 4
🧹 Nitpick comments (5)
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx (2)
20-21: Trigger a status refresh when the connect CTA is clickedPass the hook’s refresh to CalendarConnectPrompt so the UI re-checks (useful for flows that don’t fully navigate).
Apply this diff:
- const { status: calendarStatus, isLoading: calendarLoading } = - useCalendar(emailAccountId); + const { + status: calendarStatus, + isLoading: calendarLoading, + checkStatus, + } = useCalendar(emailAccountId); @@ - <CalendarConnectPrompt /> + <CalendarConnectPrompt onConnect={checkStatus} />Also applies to: 53-71
53-71: Optional: use LoadingContent for the footer’s loading state for consistencyWrap the footer content in LoadingContent to match the rest of the app’s async UX.
apps/web/components/CalendarConnectPrompt.tsx (1)
31-35: Prefer absolute callbackURLUsing origin + pathname avoids edge cases with relative redirects.
Apply this diff:
- callbackURL: `${window.location.pathname}?calendarLinked=true`, + callbackURL: `${window.location.origin}${window.location.pathname}?calendarLinked=true`,apps/web/hooks/useCalendar.ts (1)
16-22: Guard against missing emailAccountId to avoid spurious callsDefensive early-return prevents unnecessary errors if the id is momentarily undefined.
Apply this diff:
const checkStatus = useCallback(async () => { try { setIsLoading(true); + if (!emailAccountId) { + setStatus(null); + setIsLoading(false); + return; + } const result = await checkCalendarStatusAction(emailAccountId);apps/web/utils/gmail/scopes.ts (1)
14-25: Mark CALENDAR_SCOPES as readonlyUse as const for stronger typing and to prevent accidental mutation.
Apply this diff:
export const CALENDAR_SCOPES = [ "https://www.googleapis.com/auth/calendar.events.readonly", "https://www.googleapis.com/auth/calendar.events", "https://www.googleapis.com/auth/calendar.readonly", "https://www.googleapis.com/auth/calendar", // Advanced calendar scopes for future use: // "https://www.googleapis.com/auth/calendar.events.freebusy", // Read free/busy information for events // "https://www.googleapis.com/auth/calendar.settings.readonly", // Read calendar settings (timezone, etc.) // "https://www.googleapis.com/auth/calendar.settings", // Read and modify calendar settings // "https://www.googleapis.com/auth/calendar.addons.execute", // Execute calendar add-ons // "https://www.googleapis.com/auth/calendar.freebusy", // Read free/busy information for calendars -]; +] as const;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx(2 hunks)apps/web/components/CalendarConnectPrompt.tsx(1 hunks)apps/web/components/SettingCard.tsx(2 hunks)apps/web/hooks/useCalendar.ts(1 hunks)apps/web/utils/actions/calendar.ts(1 hunks)apps/web/utils/auth-client.ts(1 hunks)apps/web/utils/gmail/scopes.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (25)
apps/web/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks
Path aliases: Use@/for imports from project root
Use proper error handling with try/catch blocks
Format code with Prettier
Leverage TypeScript inference for better DX
Files:
apps/web/utils/auth-client.tsapps/web/utils/gmail/scopes.tsapps/web/utils/actions/calendar.tsapps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsxapps/web/hooks/useCalendar.ts
!{.cursor/rules/*.mdc}
📄 CodeRabbit inference engine (.cursor/rules/cursor-rules.mdc)
Never place rule files in the project root, in subdirectories outside .cursor/rules, or in any other location
Files:
apps/web/utils/auth-client.tsapps/web/utils/gmail/scopes.tsapps/web/utils/actions/calendar.tsapps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsxapps/web/hooks/useCalendar.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/form-handling.mdc)
**/*.ts: The same validation should be done in the server action too
Define validation schemas using Zod
Files:
apps/web/utils/auth-client.tsapps/web/utils/gmail/scopes.tsapps/web/utils/actions/calendar.tsapps/web/hooks/useCalendar.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/logging.mdc)
**/*.{ts,tsx}: UsecreateScopedLoggerfor logging in backend TypeScript files
Typically add the logger initialization at the top of the file when usingcreateScopedLogger
Only use.with()on a logger instance within a specific function, not for a global loggerImport Prisma in the project using
import prisma from "@/utils/prisma";
**/*.{ts,tsx}: Don't use TypeScript enums.
Don't use TypeScript const enum.
Don't use the TypeScript directive @ts-ignore.
Don't use primitive type aliases or misleading types.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use implicit any type on variable declarations.
Don't let variables evolve into any type through reassignments.
Don't use non-null assertions with the ! postfix operator.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use user-defined types.
Use as const instead of literal types and type annotations.
Use export type for types.
Use import type for types.
Don't declare empty interfaces.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use TypeScript namespaces.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use parameter properties in class constructors.
Use either T[] or Array consistently.
Initialize each enum member value explicitly.
Make sure all enum members are literal values.
Files:
apps/web/utils/auth-client.tsapps/web/utils/gmail/scopes.tsapps/web/utils/actions/calendar.tsapps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsxapps/web/hooks/useCalendar.ts
apps/web/utils/**
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
Create utility functions in
utils/folder for reusable logic
Files:
apps/web/utils/auth-client.tsapps/web/utils/gmail/scopes.tsapps/web/utils/actions/calendar.ts
apps/web/utils/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
apps/web/utils/**/*.ts: Use lodash utilities for common operations (arrays, objects, strings)
Import specific lodash functions to minimize bundle size
Files:
apps/web/utils/auth-client.tsapps/web/utils/gmail/scopes.tsapps/web/utils/actions/calendar.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{js,jsx,ts,tsx}: Don't useelements in Next.js projects.
Don't use elements in Next.js projects.
Don't use namespace imports.
Don't access namespace imports dynamically.
Don't use global eval().
Don't use console.
Don't use debugger.
Don't use var.
Don't use with statements in non-strict contexts.
Don't use the arguments object.
Don't use consecutive spaces in regular expression literals.
Don't use the comma operator.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use useless this aliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names th...
Files:
apps/web/utils/auth-client.tsapps/web/utils/gmail/scopes.tsapps/web/utils/actions/calendar.tsapps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsxapps/web/hooks/useCalendar.ts
!pages/_document.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
!pages/_document.{js,jsx,ts,tsx}: Don't import next/document outside of pages/_document.jsx in Next.js projects.
Don't import next/document outside of pages/_document.jsx in Next.js projects.
Files:
apps/web/utils/auth-client.tsapps/web/utils/gmail/scopes.tsapps/web/utils/actions/calendar.tsapps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsxapps/web/hooks/useCalendar.ts
apps/web/utils/gmail/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/gmail-api.mdc)
Keep provider-specific implementation details isolated in the appropriate utils subfolder (e.g., 'apps/web/utils/gmail/')
Files:
apps/web/utils/gmail/scopes.ts
apps/web/utils/actions/**/*.ts
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
apps/web/utils/actions/**/*.ts: Use server actions for all mutations (create/update/delete operations)
next-safe-actionprovides centralized error handling
Use Zod schemas for validation on both client and server
UserevalidatePathin server actions for cache invalidation
apps/web/utils/actions/**/*.ts: Use server actions (withnext-safe-action) for all mutations (create/update/delete operations); do NOT use POST API routes for mutations.
UserevalidatePathin server actions to invalidate cache after mutations.
Files:
apps/web/utils/actions/calendar.ts
apps/web/utils/actions/*.ts
📄 CodeRabbit inference engine (.cursor/rules/server-actions.mdc)
apps/web/utils/actions/*.ts: Implement all server actions using thenext-safe-actionlibrary for type safety, input validation, context management, and error handling. Refer toapps/web/utils/actions/safe-action.tsfor client definitions (actionClient,actionClientUser,adminActionClient).
UseactionClientUserwhen only authenticated user context (userId) is needed.
UseactionClientwhen both authenticated user context and a specificemailAccountIdare needed. TheemailAccountIdmust be bound when calling the action from the client.
UseadminActionClientfor actions restricted to admin users.
Access necessary context (likeuserId,emailAccountId, etc.) provided by the safe action client via thectxobject in the.action()handler.
Server Actions are strictly for mutations (operations that change data, e.g., creating, updating, deleting). Do NOT use Server Actions for data fetching (GET operations). For data fetching, use dedicated GET API Routes combined with SWR Hooks.
UseSafeErrorfor expected/handled errors within actions if needed.next-safe-actionprovides centralized error handling.
Use the.metadata({ name: "actionName" })method to provide a meaningful name for monitoring. Sentry instrumentation is automatically applied viawithServerActionInstrumentationwithin the safe action clients.
If an action modifies data displayed elsewhere, userevalidatePathorrevalidateTagfromnext/cachewithin the action handler as needed.Server action files must start with
use server
Files:
apps/web/utils/actions/calendar.ts
apps/web/**/*.tsx
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
apps/web/**/*.tsx: Follow tailwindcss patterns with prettier-plugin-tailwindcss
Prefer functional components with hooks
Use shadcn/ui components when available
Ensure responsive design with mobile-first approach
Follow consistent naming conventions (PascalCase for components)
Use LoadingContent component for async data
Useresult?.serverErrorwithtoastErrorandtoastSuccess
UseLoadingContentcomponent to handle loading and error states consistently
Passloading,error, and children props toLoadingContent
Files:
apps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsx
apps/web/components/**/*.tsx
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
Use React Hook Form with Zod validation for form handling
Use the
LoadingContentcomponent to handle loading and error states consistently in data-fetching components.Use PascalCase for components (e.g.
components/Button.tsx)
Files:
apps/web/components/CalendarConnectPrompt.tsxapps/web/components/SettingCard.tsx
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/form-handling.mdc)
**/*.tsx: Use React Hook Form with Zod for validation
Validate form inputs before submission
Show validation errors inline next to form fields
Files:
apps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsx
**/*.{jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{jsx,tsx}: Don't destructure props inside JSX components in Solid projects.
Don't use both children and dangerouslySetInnerHTML props on the same element.
Don't use Array index in keys.
Don't assign to React component props.
Don't define React components inside other components.
Don't use event handlers on non-interactive elements.
Don't assign JSX properties multiple times.
Don't add extra closing tags for components without children.
Use <>...</> instead of ....
Don't insert comments as text nodes.
Don't use the return value of React.render.
Make sure all dependencies are correctly specified in React hooks.
Make sure all React hooks are called from the top level of component functions.
Don't use unnecessary fragments.
Don't pass children as props.
Use semantic elements instead of role attributes in JSX.
Files:
apps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsx
**/*.{html,jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{html,jsx,tsx}: Don't use or elements.
Don't use accessKey attribute on any HTML element.
Don't set aria-hidden="true" on focusable elements.
Don't add ARIA roles, states, and properties to elements that don't support them.
Only use the scope prop on elements.
Don't assign non-interactive ARIA roles to interactive HTML elements.
Make sure label elements have text content and are associated with an input.
Don't assign interactive ARIA roles to non-interactive HTML elements.
Don't assign tabIndex to non-interactive HTML elements.
Don't use positive integers for tabIndex property.
Don't include "image", "picture", or "photo" in img alt prop.
Don't use explicit role property that's the same as the implicit/default role.
Make static elements with click handlers use a valid role attribute.
Always include a title element for SVG elements.
Give all elements requiring alt text meaningful information for screen readers.
Make sure anchors have content that's accessible to screen readers.
Assign tabIndex to non-interactive HTML elements with aria-activedescendant.
Include all required ARIA attributes for elements with ARIA roles.
Make sure ARIA properties are valid for the element's supported roles.
Always include a type attribute for button elements.
Make elements with interactive roles and handlers focusable.
Give heading elements content that's accessible to screen readers (not hidden with aria-hidden).
Always include a lang attribute on the html element.
Always include a title attribute for iframe elements.
Accompany onClick with at least one of: onKeyUp, onKeyDown, or onKeyPress.
Accompany onMouseOver/onMouseOut with onFocus/onBlur.
Include caption tracks for audio and video elements.
Make sure all anchors are valid and navigable.
Ensure all ARIA properties (aria-*) are valid.
Use valid, non-abstract ARIA roles for elements with ARIA roles.
Use valid ARIA state and property values.
Use valid values for the autocomplete attribute on input eleme...Files:
apps/web/components/CalendarConnectPrompt.tsxapps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/components/SettingCard.tsxapps/web/app/**
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
NextJS app router structure with (app) directory
Files:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/app/(app)/*/**
📄 CodeRabbit inference engine (.cursor/rules/page-structure.mdc)
Components for the page are either put in page.tsx, or in the apps/web/app/(app)/PAGE_NAME folder
Files:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/app/(app)/*/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/page-structure.mdc)
If you need to use onClick in a component, that component is a client component and file must start with 'use client'
Files:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/app/(app)/*/**/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/page-structure.mdc)
If we're in a deeply nested component we will use swr to fetch via API
Files:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/app/**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
Components with
onClickmust be client components withuse clientdirectiveFiles:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsxapps/web/hooks/**/*.ts
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
Use SWR for efficient data fetching and caching
apps/web/hooks/**/*.ts: Use SWR for client-side data fetching and caching.
Callmutate()after successful mutations to refresh SWR data on the client.Files:
apps/web/hooks/useCalendar.tsapps/web/hooks/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
Call
mutate()after successful mutations to refresh dataFiles:
apps/web/hooks/useCalendar.tsapps/web/hooks/**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/hooks.mdc)
Place custom hooks in the
apps/web/hooks/directory.Files:
apps/web/hooks/useCalendar.tsapps/web/hooks/use*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/hooks.mdc)
apps/web/hooks/use*.{js,jsx,ts,tsx}: Name custom hooks with theuseprefix (e.g.,useAccounts.ts).
For fetching data from API endpoints in custom hooks, prefer usinguseSWR.
Create dedicated hooks for specific data types (e.g.,useAccounts,useLabels).
Custom hooks should encapsulate reusable stateful logic, especially for data fetching or complex UI interactions.
Keep custom hooks focused on a single responsibility.Files:
apps/web/hooks/useCalendar.ts🧠 Learnings (9)
📚 Learning: 2025-07-18T17:27:58.249Z
Learnt from: CR PR: elie222/inbox-zero#0 File: .cursor/rules/server-actions.mdc:0-0 Timestamp: 2025-07-18T17:27:58.249Z Learning: Applies to apps/web/utils/actions/*.ts : Use `actionClient` when both authenticated user context and a specific `emailAccountId` are needed. The `emailAccountId` must be bound when calling the action from the client.Applied to files:
apps/web/utils/actions/calendar.ts📚 Learning: 2025-07-18T17:27:58.249Z
Learnt from: CR PR: elie222/inbox-zero#0 File: .cursor/rules/server-actions.mdc:0-0 Timestamp: 2025-07-18T17:27:58.249Z Learning: Applies to apps/web/utils/actions/*.ts : Implement all server actions using the `next-safe-action` library for type safety, input validation, context management, and error handling. Refer to `apps/web/utils/actions/safe-action.ts` for client definitions (`actionClient`, `actionClientUser`, `adminActionClient`).Applied to files:
apps/web/utils/actions/calendar.ts📚 Learning: 2025-07-18T17:27:58.249Z
Learnt from: CR PR: elie222/inbox-zero#0 File: .cursor/rules/server-actions.mdc:0-0 Timestamp: 2025-07-18T17:27:58.249Z Learning: Applies to apps/web/utils/actions/*.ts : Use `adminActionClient` for actions restricted to admin users.Applied to files:
apps/web/utils/actions/calendar.ts📚 Learning: 2025-07-18T17:27:58.249Z
Learnt from: CR PR: elie222/inbox-zero#0 File: .cursor/rules/server-actions.mdc:0-0 Timestamp: 2025-07-18T17:27:58.249Z Learning: Applies to apps/web/utils/actions/*.ts : Access necessary context (like `userId`, `emailAccountId`, etc.) provided by the safe action client via the `ctx` object in the `.action()` handler.Applied to files:
apps/web/utils/actions/calendar.ts📚 Learning: 2025-07-18T15:04:30.467Z
Learnt from: CR PR: elie222/inbox-zero#0 File: apps/web/CLAUDE.md:0-0 Timestamp: 2025-07-18T15:04:30.467Z Learning: Applies to apps/web/**/*.tsx : Use `LoadingContent` component to handle loading and error states consistentlyApplied to files:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx📚 Learning: 2025-07-18T15:05:16.146Z
Learnt from: CR PR: elie222/inbox-zero#0 File: .cursor/rules/fullstack-workflow.mdc:0-0 Timestamp: 2025-07-18T15:05:16.146Z Learning: Applies to apps/web/components/**/*.tsx : Use the `LoadingContent` component to handle loading and error states consistently in data-fetching components.Applied to files:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx📚 Learning: 2025-07-18T15:04:30.467Z
Learnt from: CR PR: elie222/inbox-zero#0 File: apps/web/CLAUDE.md:0-0 Timestamp: 2025-07-18T15:04:30.467Z Learning: Applies to apps/web/**/*.tsx : Use LoadingContent component for async dataApplied to files:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx📚 Learning: 2025-07-19T17:50:22.078Z
Learnt from: CR PR: elie222/inbox-zero#0 File: .cursor/rules/ui-components.mdc:0-0 Timestamp: 2025-07-19T17:50:22.078Z Learning: Applies to components/**/*.tsx : Use the `LoadingContent` component to handle loading statesApplied to files:
apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx📚 Learning: 2025-07-18T15:05:41.705Z
Learnt from: CR PR: elie222/inbox-zero#0 File: .cursor/rules/hooks.mdc:0-0 Timestamp: 2025-07-18T15:05:41.705Z Learning: Applies to apps/web/hooks/use*.{js,jsx,ts,tsx} : Create dedicated hooks for specific data types (e.g., `useAccounts`, `useLabels`).Applied to files:
apps/web/hooks/useCalendar.ts🧬 Code graph analysis (5)
apps/web/utils/auth-client.ts (1)
apps/web/env.ts (1)
env(16-235)apps/web/utils/actions/calendar.ts (2)
apps/web/utils/logger.ts (1)
createScopedLogger(17-67)apps/web/utils/actions/safe-action.ts (1)
actionClient(46-86)apps/web/components/CalendarConnectPrompt.tsx (1)
apps/web/utils/gmail/scopes.ts (1)
CALENDAR_SCOPES(14-25)apps/web/app/(app)/[emailAccountId]/assistant/settings/DraftReplies.tsx (3)
apps/web/providers/EmailAccountProvider.tsx (1)
useAccount(72-82)apps/web/hooks/useCalendar.ts (1)
useCalendar(12-51)apps/web/components/CalendarConnectPrompt.tsx (1)
CalendarConnectPrompt(21-81)apps/web/hooks/useCalendar.ts (1)
apps/web/utils/actions/calendar.ts (1)
checkCalendarStatusAction(9-46)⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Static Code Analysis Js
- GitHub Check: cubic · AI code reviewer
- GitHub Check: Jit Security
🔇 Additional comments (2)
apps/web/utils/auth-client.ts (1)
6-17: LGTM: exposing linkSocial from the auth clientThe export addition looks correct and aligns with the usage in CalendarConnectPrompt. Base URL is sourced from env and plugins remain unchanged.
apps/web/components/SettingCard.tsx (1)
7-13: Footer slot addition is clean and unobtrusiveOptional footer prop is typed correctly and rendered conditionally with sensible spacing.
Also applies to: 24-24
|
|
||
| onConnect?.(); | ||
| } catch (error) { | ||
| console.error("Error connecting calendar:", error); |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Remove console usage in client code
Project rules disallow console in TS/TSX. Rely on toasts only.
Apply this diff:
- console.error("Error connecting calendar:", error);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| console.error("Error connecting calendar:", error); |
🤖 Prompt for AI Agents
In apps/web/components/CalendarConnectPrompt.tsx around line 43, remove the
console.error("Error connecting calendar:", error) call (project disallows
console in client code) and instead surface the error via the existing toast
mechanism: ensure the catch block calls the toast with a clear user-facing
message and include relevant error details (use error.message or safely
stringify the error) so debugging info is preserved in the toast; do not add any
console calls or new logging libraries.
| export function useCalendar(emailAccountId: string) { | ||
| const [status, setStatus] = useState<CalendarStatus | null>(null); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
|
|
||
| const checkStatus = useCallback(async () => { | ||
| try { | ||
| setIsLoading(true); | ||
| const result = await checkCalendarStatusAction(emailAccountId); | ||
|
|
||
| if (result?.serverError) { | ||
| toastError({ | ||
| title: "Error checking calendar status", | ||
| description: result.serverError, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| if (result?.data) { | ||
| setStatus(result.data); | ||
| } | ||
| } catch { | ||
| toastError({ | ||
| title: "Error", | ||
| description: "Failed to check calendar connection status", | ||
| }); | ||
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }, [emailAccountId]); | ||
|
|
||
| useEffect(() => { | ||
| checkStatus(); | ||
| }, [checkStatus]); | ||
|
|
||
| return { | ||
| status, | ||
| isLoading, | ||
| checkStatus, | ||
| }; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Migrate to SWR and a GET API for fetching status
Hooks should use SWR, and reads should come from a GET endpoint rather than a Server Action.
I can provide a minimal /api endpoint and SWR hook skeleton if you want this change in this PR.
| export const checkCalendarStatusAction = actionClient | ||
| .metadata({ name: "checkCalendarStatus" }) | ||
| .action(async ({ ctx: { emailAccountId } }) => { |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Use GET API + SWR for reads instead of Server Actions
Per project rules, Server Actions are for mutations only. Expose a GET route (e.g., app/api/accounts/[emailAccountId]/calendar/status/route.ts) and consume it via a SWR-based hook.
I can sketch the route handler and an updated SWR hook if helpful.
| const scope = emailAccount.account.scope || ""; | ||
| const hasCalendarScopes = | ||
| scope.includes("calendar.events") || | ||
| scope.includes("calendar.readonly") || | ||
| scope.includes("calendar"); |
There was a problem hiding this comment.
Fix scope detection: avoid substring false-positives; match exact Google Calendar scopes
Using substring checks like "calendar" will incorrectly flag scopes such as "calendar.addons.execute". Parse granted scopes and compare against the exact calendar scope URIs.
Apply this diff to harden detection:
- const scope = emailAccount.account.scope || "";
- const hasCalendarScopes =
- scope.includes("calendar.events") ||
- scope.includes("calendar.readonly") ||
- scope.includes("calendar");
+ const scope = emailAccount.account.scope ?? "";
+ const granted = new Set(scope.split(/\s+/).filter(Boolean));
+ const hasCalendarScopes = CALENDAR_SCOPES.some((s) => granted.has(s));Add this import near the top of the file:
import { CALENDAR_SCOPES } from "@/utils/gmail/scopes";🤖 Prompt for AI Agents
In apps/web/utils/actions/calendar.ts around lines 27 to 31, the scope detection
uses substring matching which yields false-positives (e.g.,
"calendar.addons.execute"); replace it with exact-scope comparison by importing
CALENDAR_SCOPES from "@/utils/gmail/scopes", split the stored scope string into
an array (by space), and check if any granted scope equals one of the
CALENDAR_SCOPES entries (use a Set for fast lookup) instead of using
scope.includes("calendar") or other substring checks.
There was a problem hiding this comment.
2 issues found across 7 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="apps/web/utils/gmail/scopes.ts">
<violation number="1" location="apps/web/utils/gmail/scopes.ts:18">
Bundling full-access Calendar scope with the read-only scope is unnecessary and over-privileged; request only what's needed or split scopes by access level.</violation>
</file>
<file name="apps/web/hooks/useCalendar.ts">
<violation number="1" location="apps/web/hooks/useCalendar.ts:38">
setIsLoading may run after unmount; add an isMounted/abort guard or cancel the async work to avoid post-unmount state updates.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
| "https://www.googleapis.com/auth/calendar.events.readonly", | ||
| "https://www.googleapis.com/auth/calendar.events", | ||
| "https://www.googleapis.com/auth/calendar.readonly", | ||
| "https://www.googleapis.com/auth/calendar", |
There was a problem hiding this comment.
Bundling full-access Calendar scope with the read-only scope is unnecessary and over-privileged; request only what's needed or split scopes by access level.
Prompt for AI agents
Address the following comment on apps/web/utils/gmail/scopes.ts at line 18:
<comment>Bundling full-access Calendar scope with the read-only scope is unnecessary and over-privileged; request only what's needed or split scopes by access level.</comment>
<file context>
@@ -10,3 +10,16 @@ export const SCOPES = [
+ "https://www.googleapis.com/auth/calendar.events.readonly",
+ "https://www.googleapis.com/auth/calendar.events",
+ "https://www.googleapis.com/auth/calendar.readonly",
+ "https://www.googleapis.com/auth/calendar",
+ // Advanced calendar scopes for future use:
+ // "https://www.googleapis.com/auth/calendar.events.freebusy", // Read free/busy information for events
</file context>
| description: "Failed to check calendar connection status", | ||
| }); | ||
| } finally { | ||
| setIsLoading(false); |
There was a problem hiding this comment.
setIsLoading may run after unmount; add an isMounted/abort guard or cancel the async work to avoid post-unmount state updates.
Prompt for AI agents
Address the following comment on apps/web/hooks/useCalendar.ts at line 38:
<comment>setIsLoading may run after unmount; add an isMounted/abort guard or cancel the async work to avoid post-unmount state updates.</comment>
<file context>
@@ -0,0 +1,51 @@
+ description: "Failed to check calendar connection status",
+ });
+ } finally {
+ setIsLoading(false);
+ }
+ }, [emailAccountId]);
</file context>
Summary by CodeRabbit
New Features
Chores