Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@steven-tey
Copy link
Collaborator

@steven-tey steven-tey commented Jun 6, 2025

Summary by CodeRabbit

  • New Features

    • Introduced an "Archived" status for program enrollments and partners, now visible in status badges and partner details.
    • Added a new "Archived" badge with distinct styling and icon.
    • Added an archive/unarchive partner modal for managing partner archival status via the UI.
  • Improvements

    • Partner and enrollment counts, groupings, and lists now consistently exclude "archived" statuses by default.
    • Updated visibility logic in partner details to support the new "Archived" status.
    • Renamed "View sales" menu item to "View commissions" with updated routing.
  • Refactor

    • Simplified partner data fetching and removed unnecessary dependencies on program identifiers in partner-related views.

@vercel
Copy link
Contributor

vercel bot commented Jun 6, 2025

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

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jun 6, 2025 11:14pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

Walkthrough

The changes introduce the "archived" status for program enrollments and partners, updating backend filtering logic, UI components, and status badges to recognize and handle this new status. The "programId" parameter was removed from several partner-related hooks and components, simplifying their interfaces and centralizing partner-fetching logic. Additionally, a query was modified to include previously excluded statuses in results. A new server action and modal were added to support archiving/unarchiving partners.

Changes

File(s) Change Summary
apps/web/app/(ee)/api/partners/count/route.ts
apps/web/lib/api/partners/get-partners.ts
Added "archived" to excluded statuses in partner/program enrollment filtering logic.
apps/web/lib/api/partners/get-partner-for-program.ts Removed exclusion of 'rejected' and 'banned' statuses from program enrollment query.
apps/web/lib/swr/use-partner.ts Removed programId from hook signature and SWR key; simplified fetch condition.
apps/web/lib/swr/use-partners.ts Removed useParams and programId from query and API call.
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/partners/partner-table.tsx Removed programId usage; refactored to use centralized usePartner logic; added archive partner modal and menu item; renamed "View sales" to "View commissions".
apps/web/ui/partners/partner-details-sheet.tsx Allowed "archived" status to display partner details.
apps/web/ui/partners/partner-status-badges.ts Added "archived" badge; changed "declined" badge styling and variant.
packages/prisma/schema/program.prisma Added archived value to ProgramEnrollmentStatus enum.
apps/web/lib/actions/partners/archive-partner.ts Added new server action to toggle partner archival status.
apps/web/lib/zod/schemas/partners.ts Added new archivePartnerSchema; relocated banPartnerSchema.
apps/web/ui/partners/archive-partner-modal.tsx Added new React modal component and hook for archiving/unarchiving partners with UI feedback and cache mutation.
apps/web/app/app.dub.co/(dashboard)/[slug]/links/[...link]/page-client.tsx Removed programId parameter from usePartner hook call.

Sequence Diagram(s)

sequenceDiagram
    participant UI as PartnerTable / RowMenuButton
    participant Modal as ArchivePartnerModal
    participant Action as archivePartnerAction
    participant DB as Database

    UI->>Modal: Open archive/unarchive modal
    Modal->>Action: Confirm archive/unarchive request
    Action->>DB: Fetch program enrollment for partner
    DB-->>Action: Return enrollment status
    Action->>DB: Update enrollment status (toggle archived/approved)
    DB-->>Action: Confirmation
    Action-->>Modal: Success response
    Modal-->>UI: Close modal, show toast, refresh partner data
Loading

Poem

🐇 In code's green meadow, partners play,
"Archived" now hops along the way.
Hooks trimmed clean, menus anew,
Badges gleam with colors true.
Modal pops with gentle cheer,
Archiving made bright and clear—
🗃️ A rabbit's dance, progress near!


📜 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 0dcadb5 and d23f787.

📒 Files selected for processing (1)
  • apps/web/ui/partners/archive-partner-modal.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/ui/partners/archive-partner-modal.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f4f5b3b and accb49a.

📒 Files selected for processing (8)
  • apps/web/app/(ee)/api/partners/count/route.ts (3 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/partners/partner-table.tsx (2 hunks)
  • apps/web/lib/api/partners/get-partners.ts (1 hunks)
  • apps/web/lib/swr/use-partner.ts (1 hunks)
  • apps/web/lib/swr/use-partners.ts (0 hunks)
  • apps/web/ui/partners/partner-details-sheet.tsx (1 hunks)
  • apps/web/ui/partners/partner-status-badges.ts (3 hunks)
  • packages/prisma/schema/program.prisma (1 hunks)
💤 Files with no reviewable changes (1)
  • apps/web/lib/swr/use-partners.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/partners/partner-table.tsx (1)
apps/web/lib/swr/use-partner.ts (1)
  • usePartner (6-31)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (9)
packages/prisma/schema/program.prisma (1)

13-13: LGTM! Clear enum addition with appropriate documentation.

The new archived status is well-documented and follows the existing enum pattern. This change will require a database migration to be applied.

apps/web/ui/partners/partner-details-sheet.tsx (1)

47-50: LGTM! Logical extension of partner details visibility.

Including archived partners in the showPartnerDetails condition is consistent with the treatment of banned partners - both represent established partner relationships where historical details remain relevant for viewing.

apps/web/app/(ee)/api/partners/count/route.ts (1)

56-56: LGTM! Consistent filtering logic for archived partners.

The addition of "archived" to the notIn filters is correctly implemented across all three query scenarios (country grouping, reward grouping, and absolute count). This ensures archived partners are consistently excluded from active partner metrics alongside rejected and banned partners.

Also applies to: 119-119, 168-168

apps/web/ui/partners/partner-status-badges.ts (3)

2-2: LGTM! Added appropriate icon for archived status.

The BoxArchive icon import supports the new archived status badge.


38-39: Good semantic improvement for declined status.

Changing the declined badge from "error" variant with gray styling to "neutral" variant with neutral styling is more semantically appropriate, as "declined" represents a neutral outcome rather than an error state.


48-53: LGTM! Well-configured archived status badge.

The archived badge uses appropriate neutral styling and the BoxArchive icon, consistent with the semantic meaning of archived partners.

apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/partners/partner-table.tsx (3)

6-6: LGTM! Import added for centralized partner fetching.

The usePartner hook import supports the refactoring to centralize partner fetching logic.


542-549: Well-implemented refactoring to use centralized hook.

The replacement of the manual SWR fetch with the usePartner hook improves code maintainability by centralizing partner fetching logic. The conditional logic correctly only fetches when the partner is not already available in the partners array.


551-553: Good defensive programming with partner ID validation.

The check fetchedPartner?.id === partnerId ensures that the fetched partner matches the requested partner ID before using it, preventing potential race conditions or stale data issues.

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

🧹 Nitpick comments (2)
apps/web/lib/actions/partners/archive-partner.ts (1)

10-35: LGTM! Consider returning operation details for better feedback.

The archive/unarchive logic is well-implemented with proper authentication, validation, and database operations. The status toggle logic correctly switches between "archived" and "approved" states.

Consider returning information about the operation performed to provide better feedback to the UI:

  await prisma.programEnrollment.update({
    where: {
      partnerId_programId: {
        programId,
        partnerId,
      },
    },
    data: {
      status:
        programEnrollment.status === "archived" ? "approved" : "archived",
    },
  });
+
+  return {
+    success: true,
+    action: programEnrollment.status === "archived" ? "unarchived" : "archived",
+  };
apps/web/ui/partners/archive-partner-modal.tsx (1)

41-50: Remove unnecessary programId dependency.

The handleArchive function checks for programId but the archive action doesn't use it - it derives the program ID from the workspace's default program. This check is unnecessary and creates a false dependency.

  const handleArchive = useCallback(async () => {
-   if (!workspaceId || !programId || !partner.id) {
+   if (!workspaceId || !partner.id) {
      return;
    }

    await executeAsync({
      workspaceId,
      partnerId: partner.id,
    });
- }, [executeAsync, partner.id, programId, workspaceId]);
+ }, [executeAsync, partner.id, workspaceId]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9387839 and 8d090ab.

📒 Files selected for processing (5)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/partners/partner-table.tsx (6 hunks)
  • apps/web/lib/actions/partners/archive-partner.ts (1 hunks)
  • apps/web/lib/zod/schemas/partners.ts (1 hunks)
  • apps/web/ui/partners/archive-partner-modal.tsx (1 hunks)
  • apps/web/ui/partners/partner-status-badges.ts (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/web/lib/zod/schemas/partners.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/programs/[programId]/partners/partner-table.tsx
  • apps/web/ui/partners/partner-status-badges.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/lib/actions/partners/archive-partner.ts (3)
apps/web/lib/actions/safe-action.ts (1)
  • authActionClient (33-81)
apps/web/lib/zod/schemas/partners.ts (1)
  • archivePartnerSchema (554-557)
apps/web/lib/api/programs/get-default-program-id-or-throw.ts (1)
  • getDefaultProgramIdOrThrow (4-17)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (2)
apps/web/ui/partners/archive-partner-modal.tsx (2)

52-56: LGTM! Dynamic action text and description logic is well-implemented.

The conditional logic for determining action text and description based on the partner's current status provides a good user experience.


110-134: LGTM! Well-structured custom hook with proper memoization.

The hook properly manages modal state and uses useCallback and useMemo to optimize re-renders. The component memoization pattern is well-implemented.

@steven-tey
Copy link
Collaborator Author

@CodeRabbit final review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

Tip

For best results, initiate chat on the files or code changes.

@steven-tey, this is an excellent and comprehensive implementation of the archive partner functionality! Here's my final review:

Strengths of the Implementation

1. Database & Schema Design

  • Clean addition of archived status to ProgramEnrollmentStatus enum
  • Proper integration into existing filtering logic across multiple API endpoints

2. Consistent API Filtering

  • All relevant endpoints (get-partners.ts, count/route.ts) properly exclude archived partners
  • The get-partner-for-program.ts change to remove status filtering makes sense for individual partner retrieval

3. Complete UI Implementation

  • Well-designed archive modal with clear confirmation flow
  • Status badges properly updated with neutral styling for archived state
  • Partner details sheet correctly handles archived status display
  • Menu integration in partner table is intuitive

4. Excellent Code Organization

  • Server action (archivePartnerAction) follows proper patterns with validation
  • Custom hook (useArchivePartnerModal) provides clean abstraction
  • Proper error handling and success feedback with toast notifications

5. Smart Refactoring

  • Removing programId from hooks simplifies the API surface
  • Centralizing partner fetching logic in usePartner hook improves maintainability

🎯 Architecture Highlights

graph TD
    A[Partner Table] --> B[Archive Modal]
    B --> C[Archive Action]
    C --> D[Database Update]
    D --> E[Cache Mutation]
    E --> F[UI Refresh]
    G[Status Filtering] --> H[API Endpoints]
    H --> I[Exclude Archived]
    J[Status Badges] --> K[Display Logic]
    K --> L[Archived Badge]
Loading

💡 Notable Implementation Details

  • Toggle Logic: Smart implementation that switches between "archived" ↔ "approved" states
  • Cache Management: Proper SWR cache mutation ensures immediate UI updates
  • User Experience: Clear labeling that adapts based on current partner status
  • Consistent Styling: Archived and declined badges both use neutral variant for visual consistency

🚀 Ready for Production

This implementation demonstrates:

  • ✅ Complete feature coverage (UI, API, database)
  • ✅ Proper error handling and user feedback
  • ✅ Consistent code patterns and architecture
  • ✅ No breaking changes to existing functionality
  • ✅ Clean separation of concerns

The archive partner functionality is thoroughly implemented and ready for deployment. Great work on maintaining code quality while delivering a complete feature!

@steven-tey steven-tey merged commit 54f7510 into main Jun 6, 2025
8 checks passed
@steven-tey steven-tey deleted the archive-partner branch June 6, 2025 23:22
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