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

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Sep 23, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Partners Applications table now shows “-” when a partner has no group, preventing misleading default group display.
    • Bulk approval now consistently assigns a group (using the program’s default when none is specified) and applies associated rewards/discounts, ensuring accurate enrollment updates and records.

@vercel
Copy link
Contributor

vercel bot commented Sep 23, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Sep 23, 2025 7:53pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 23, 2025

Walkthrough

Consolidates 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

Cohort / File(s) Summary
Dashboard UI — Partner Group Display
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/applications/page-client.tsx
Group column now returns "-" if no valid groupId or matching group; removed DEFAULT_PARTNER_GROUP import and fallback; rendering occurs only when a found partnerGroup exists.
Backend Action — Bulk Approve Partners
apps/web/lib/actions/partners/bulk-approve-partners.ts
Always fetches group using groupId ?? program.defaultGroupId; enrollment updates always include group-related fields; simplified downstream logging by relying on updatedEnrollments.

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

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • steven-tey

Poem

A twitch of whiskers, a hop through code,
I nibbled defaults from the partner road.
Groups now chosen, clear as the moon,
Dashboards blink, approvals in tune.
With carrots of logic neatly arrayed—
Thump! Clean flows, no shadows portrayed. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Fix the bulk approve partner" succinctly captures the primary intent to fix the bulk-approve partner flow (it matches the bulk-approve changes in apps/web/lib/actions/partners/bulk-approve-partners.ts and the PR branch) and is specific enough for reviewers to understand the main change, though the phrasing is slightly awkward.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-groupId-missing

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

@devkiran devkiran requested a review from steven-tey September 23, 2025 17:33
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/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 groupById Map 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 createdAt on approval corrupts original creation timestamps. Remove it; rely on updatedAt (if present) or an explicit approvedAt field 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

📥 Commits

Reviewing files that changed from the base of the PR and between 18d42d6 and 3e374ee.

📒 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 groups is unset or the groupId lookup fails removes the hidden default and aligns with backend guarantees.

Comment on lines +38 to +41
const group = await getGroupOrThrow({
programId: program.id,
groupId: groupId ?? program.defaultGroupId,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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.

@steven-tey steven-tey merged commit d360f60 into main Sep 23, 2025
8 checks passed
@steven-tey steven-tey deleted the fix-groupId-missing branch September 23, 2025 20:59
@coderabbitai coderabbitai bot mentioned this pull request Nov 8, 2025
@coderabbitai coderabbitai bot mentioned this pull request Nov 24, 2025
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.

3 participants