-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add invitations count to sidebar #2606
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughA new API endpoint and supporting React hook were added to count program enrollments for a partner, with optional filtering by status. A Zod schema for query validation was introduced. The sidebar navigation was updated to display the count of pending program invitations as a badge in the "Invitations" menu item. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Sidebar
participant useProgramEnrollmentsCount
participant API
participant DB
User->>Sidebar: Load PartnersSidebarNav
Sidebar->>useProgramEnrollmentsCount: Fetch invitations count (status="invited")
useProgramEnrollmentsCount->>API: GET /api/partner-profile/programs/count?status=invited
API->>DB: Count programEnrollments for partner with status "invited"
DB-->>API: Return count
API-->>useProgramEnrollmentsCount: Respond with { count }
useProgramEnrollmentsCount-->>Sidebar: Provide invitationsCount
Sidebar->>User: Display sidebar with invitations badge
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
apps/web/app/(ee)/api/partner-profile/programs/count/route.ts
(1 hunks)apps/web/lib/swr/use-program-enrollments-count.ts
(1 hunks)apps/web/lib/zod/schemas/partner-profile.ts
(1 hunks)apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx
(6 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx (1)
Learnt from: devkiran
PR: dubinc/dub#2448
File: packages/email/src/templates/partner-program-summary.tsx:0-0
Timestamp: 2025-05-29T04:45:18.504Z
Learning: In the PartnerProgramSummary email template (packages/email/src/templates/partner-program-summary.tsx), the stat titles are hardcoded constants ("Clicks", "Leads", "Sales", "Earnings") that will always match the ICONS object keys after toLowerCase() conversion, so icon lookup failures are not possible.
🧬 Code Graph Analysis (2)
apps/web/app/(ee)/api/partner-profile/programs/count/route.ts (2)
apps/web/lib/auth/partner.ts (1)
withPartnerProfile
(26-85)apps/web/lib/zod/schemas/partner-profile.ts (1)
partnerProfileProgramsCountQuerySchema
(126-127)
apps/web/lib/swr/use-program-enrollments-count.ts (1)
apps/web/lib/zod/schemas/partner-profile.ts (1)
partnerProfileProgramsCountQuerySchema
(126-127)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (5)
apps/web/lib/zod/schemas/partner-profile.ts (1)
126-127
: Well-designed schema reuse pattern.The new schema correctly picks the
status
field from the existing schema, maintaining type safety and consistency across the API surface.apps/web/app/(ee)/api/partner-profile/programs/count/route.ts (1)
1-18
: Clean and well-structured API endpoint.The implementation correctly follows established patterns with proper authentication, schema validation, and conditional filtering in the database query.
apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx (3)
34-34
: Good type extension for the sidebar data.The optional
invitationsCount
property is appropriately added to support the new badge functionality.
245-247
: Clean integration of the invitations count.The hook usage is correct, fetching the count for "invited" status program enrollments to display as a badge.
89-89
: Appropriate badge display with fallback.The
|| undefined
fallback ensures the badge only appears when there's a valid count, maintaining clean UI behavior.
@CodeRabbit final review |
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@steven-tey This PR looks well-structured and follows good patterns! Here's my final review: ✅ Strengths
🔍 Code Quality Observations
📋 Minor Considerations
🚀 Ready to ShipThis implementation is production-ready. The code is clean, follows best practices, and integrates well with the existing codebase. The invitations count feature will provide valuable visibility into pending program enrollments. Recommendation: ✅ Approve and merge 🏁 Script executed:
Length of output: 11782 @steven-tey After examining the actual code implementation, I found a few technical issues that should be addressed: 🚨 Critical Issues to Fix1. API Response Format MismatchThe API route returns a raw number, but it should return an object for consistency: // Current (problematic)
return NextResponse.json(count);
// Should be
return NextResponse.json({ count }); 2. Query Parameter Type HandlingThe hook doesn't explicitly convert query values to strings: // Current implementation works but could be more explicit
const { data: count, isLoading } = useSWR<number>(
partnerId &&
`/api/partner-profile/programs/count?${new URLSearchParams(query)}`,
fetcher,
{
dedupingInterval: 60000,
},
);
// Better approach - ensure string conversion
const { data: count, isLoading } = useSWR<number>(
partnerId &&
`/api/partner-profile/programs/count?${new URLSearchParams(
Object.fromEntries(
Object.entries(query).map(([key, value]) => [key, String(value)])
)
)}`,
fetcher,
{
dedupingInterval: 60000,
},
); ✅ What's Working Well
🛠️ Recommended Fixes
📋 Final VerdictThe architecture is solid and follows best practices, but the technical issues above should be fixed before merging to prevent runtime errors. Recommendation: |
Summary by CodeRabbit
New Features
Enhancements