-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix the bulk approve partner #2877
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 GitHub.
|
WalkthroughConsolidates partner group handling by removing default fallbacks in UI display and enforcing unconditional group-based updates in bulk approval. The UI now shows "-" when no valid group is found, and the backend always resolves a group via groupId or program.defaultGroupId before updating enrollments. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Admin
participant UI as Dashboard UI
participant Action as bulk-approve-partners
participant DB as DB
Admin->>UI: Approve selected partners
UI->>Action: POST partners + optional groupId
Action->>DB: Fetch program (includes defaultGroupId)
Action->>DB: Fetch group (groupId ?? defaultGroupId)
alt Group found
Action->>DB: Update enrollments with groupId and reward/discount fields
else Group missing
Action->>DB: (Same path) Update fails or no-op per DB constraints
end
Action->>DB: Persist logs/workflows using updatedEnrollments
Action-->>UI: Result (success/error)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the 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.
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/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx (1)
219-230: Micro-optimization: avoid O(n) lookup per row with a Map.Build a
groupByIdMap once and use O(1) lookups in the cell.Apply this diff in the cell:
- if (!groups || !row.original.groupId) { - return "-"; - } - - const partnerGroup = groups.find( - (g) => g.id === row.original.groupId, - ); - - if (!partnerGroup) { - return "-"; - } + const partnerGroup = groupById?.get(row.original.groupId!); + if (!partnerGroup) return "-";And add this near your other hooks (outside this block):
const groupById = useMemo( () => (groups ? new Map(groups.map((g) => [g.id, g])) : undefined), [groups], );apps/web/lib/actions/partners/bulk-approve-partners.ts (1)
43-58: Don’t overwrite createdAt during approval.Updating
createdAton approval corrupts original creation timestamps. Remove it; rely onupdatedAt(if present) or an explicitapprovedAtfield instead.Apply this diff:
data: { status: "approved", - createdAt: new Date(), groupId: group.id, clickRewardId: group.clickRewardId, leadRewardId: group.leadRewardId, saleRewardId: group.saleRewardId, discountId: group.discountId, },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx(1 hunks)apps/web/lib/actions/partners/bulk-approve-partners.ts(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: devkiran
PR: dubinc/dub#2735
File: apps/web/lib/actions/partners/update-discount.ts:60-66
Timestamp: 2025-08-14T05:57:35.546Z
Learning: In the partner groups system, discounts should always belong to a group. The partnerGroup relation should never be null when updating discounts, so optional chaining on partnerGroup?.id may be unnecessary defensive programming.
🔇 Additional comments (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx (1)
220-230: LGTM: explicit “no group” fallback is correct.Returning "-" when
groupsis unset or thegroupIdlookup fails removes the hidden default and aligns with backend guarantees.
| const group = await getGroupOrThrow({ | ||
| programId: program.id, | ||
| groupId: groupId ?? program.defaultGroupId, | ||
| }); |
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.
Gracefully handle missing group: throw a clear, user-facing error before fetching.
If neither groupId nor program.defaultGroupId is set, getGroupOrThrow will throw, likely as a generic 500. Guard and surface a clear message.
Apply this diff:
- const group = await getGroupOrThrow({
- programId: program.id,
- groupId: groupId ?? program.defaultGroupId,
- });
+ const effectiveGroupId = groupId ?? program.defaultGroupId;
+ if (!effectiveGroupId) {
+ throw new Error(
+ "No group selected and no default group configured for this program.",
+ );
+ }
+ const group = await getGroupOrThrow({
+ programId: program.id,
+ groupId: effectiveGroupId,
+ });📝 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.
| const group = await getGroupOrThrow({ | |
| programId: program.id, | |
| groupId: groupId ?? program.defaultGroupId, | |
| }); | |
| const effectiveGroupId = groupId ?? program.defaultGroupId; | |
| if (!effectiveGroupId) { | |
| throw new Error( | |
| "No group selected and no default group configured for this program.", | |
| ); | |
| } | |
| const group = await getGroupOrThrow({ | |
| programId: program.id, | |
| groupId: effectiveGroupId, | |
| }); |
🤖 Prompt for AI Agents
In apps/web/lib/actions/partners/bulk-approve-partners.ts around lines 38 to 41,
guard against both groupId and program.defaultGroupId being undefined before
calling getGroupOrThrow: if neither value exists, throw a clear, user-facing
error (e.g., a Validation/BadRequest error with a message like "No group
specified for this program; please provide groupId or set a defaultGroupId") so
the caller receives a 4xx with a helpful message instead of an uncaught 500;
otherwise continue to call getGroupOrThrow with the chosen id.
Summary by CodeRabbit