-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add archive partner functionality #2497
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 ↗︎
|
WalkthroughThe 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
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
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
🪧 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: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
archivedstatus 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
archivedpartners in theshowPartnerDetailscondition is consistent with the treatment ofbannedpartners - 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
notInfilters 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
BoxArchiveicon 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
usePartnerhook 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
usePartnerhook 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 === partnerIdensures that the fetched partner matches the requested partner ID before using it, preventing potential race conditions or stale data issues.
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
🧹 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
handleArchivefunction checks forprogramIdbut 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
📒 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
useCallbackanduseMemoto optimize re-renders. The component memoization pattern is well-implemented.
|
@CodeRabbit final review |
|
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 Implementation1. Database & Schema Design
2. Consistent API Filtering
3. Complete UI Implementation
4. Excellent Code Organization
5. Smart Refactoring
🎯 Architecture Highlightsgraph 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]
💡 Notable Implementation Details
🚀 Ready for ProductionThis implementation demonstrates:
The archive partner functionality is thoroughly implemented and ready for deployment. Great work on maintaining code quality while delivering a complete feature! |
Summary by CodeRabbit
New Features
Improvements
Refactor