+
Skip to content

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

Merged
merged 3 commits into from
Jul 3, 2025
Merged

Conversation

TWilson023
Copy link
Collaborator

@TWilson023 TWilson023 commented Jul 3, 2025

Screenshot 2025-07-03 at 5 10 46 PM

Summary by CodeRabbit

  • New Features

    • Added a badge to the "Invitations" menu item in the sidebar showing the count of pending program invitations.
    • Introduced a new API endpoint to fetch the count of program enrollments for partners.
    • Added a React hook to retrieve and display program enrollment counts with optional status filtering.
  • Enhancements

    • Sidebar navigation dynamically updates the invitations count badge based on live data.

Copy link

vercel bot commented Jul 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jul 3, 2025 10:04pm

Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

Walkthrough

A 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

File(s) Change Summary
apps/web/app/(ee)/api/partner-profile/programs/count/route.ts Added GET API route to count program enrollments for a partner, with optional status filtering.
apps/web/lib/swr/use-program-enrollments-count.ts Introduced useProgramEnrollmentsCount React hook to fetch the enrollments count from the API.
apps/web/lib/zod/schemas/partner-profile.ts Added partnerProfileProgramsCountQuerySchema for validating count query parameters.
apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx Updated sidebar to show invitations count badge using the new hook and schema.

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
Loading

Poem

In the sidebar’s gentle light,
A count appears—what a sight!
Invitations tallied true,
With a shiny badge in view.
API and hook unite,
Zod ensures the query’s right,
Hopping forward, code delight! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86355a4 and 9a01085.

📒 Files selected for processing (1)
  • apps/web/lib/swr/use-program-enrollments-count.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/lib/swr/use-program-enrollments-count.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@TWilson023 TWilson023 requested a review from steven-tey July 3, 2025 21:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between fde6454 and 86355a4.

📒 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.

@steven-tey
Copy link
Collaborator

@CodeRabbit final review

Copy link
Contributor

coderabbitai bot commented Jul 3, 2025

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

  1. Clean Architecture: The implementation follows a clear separation of concerns with API → Hook → UI layers
  2. Type Safety: Proper use of Zod schemas for validation and TypeScript throughout
  3. Error Handling: The SWR hook provides built-in error handling and loading states
  4. Performance: 60-second deduplication interval prevents unnecessary API calls
  5. Security: Proper authentication with withPartnerProfile middleware
  6. Consistency: Follows existing patterns in the codebase

🔍 Code Quality Observations

  • The API route correctly handles optional status filtering
  • The React hook properly constructs query parameters and handles authentication
  • The sidebar integration is clean and doesn't break existing functionality
  • Zod schema reuse by picking from existing schema is efficient

📋 Minor Considerations

  1. Error States: The sidebar doesn't show error states if the count fails to load (which is fine for this use case)
  2. Loading States: The badge appears/disappears based on loading state, which provides good UX
  3. Caching: The 60-second deduplication is reasonable for this type of data

🚀 Ready to Ship

This 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:

#!/bin/bash
# Let's examine the actual implementation files to conduct a thorough review

echo "=== API Route Implementation ==="
cat "apps/web/app/(ee)/api/partner-profile/programs/count/route.ts"

echo -e "\n=== React Hook Implementation ==="
cat "apps/web/lib/swr/use-program-enrollments-count.ts"

echo -e "\n=== Zod Schema Implementation ==="
cat "apps/web/lib/zod/schemas/partner-profile.ts"

echo -e "\n=== Sidebar Component Implementation ==="
cat "apps/web/ui/layout/sidebar/partners-sidebar-nav.tsx"

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 Fix

1. API Response Format Mismatch

The 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 Handling

The 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

  • Clean architecture with proper separation of concerns
  • Proper authentication and authorization
  • Good use of TypeScript and Zod validation
  • Efficient SWR configuration
  • Consistent integration with existing patterns

🛠️ Recommended Fixes

  1. Fix the API response format in route.ts
  2. Update the hook's type expectation to match the API response
  3. Add explicit string conversion for query parameters

📋 Final Verdict

The architecture is solid and follows best practices, but the technical issues above should be fixed before merging to prevent runtime errors.

Recommendation: ⚠️ Approve with required fixes - address the API response format mismatch first, then merge.

@steven-tey steven-tey merged commit d837da1 into main Jul 3, 2025
5 of 7 checks passed
@steven-tey steven-tey deleted the sidebar-invitations-count branch July 3, 2025 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载