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

Skip to content

Conversation

@TWilson023
Copy link
Collaborator

@TWilson023 TWilson023 commented Sep 11, 2025

Screenshot 2025-09-11 at 5 06 56 PM

Summary by CodeRabbit

  • New Features

    • Added optional Product ID to commission creation, including a new field in the Create Commission form and propagation into sale metadata and commission processing.
  • Bug Fixes

    • Improved validation for bounty submission requirements when none are defined, avoiding errors and making image/URL optional if not specified.
    • Broadened cache refresh after approving a bounty submission to keep bounties data up to date.
    • Reduced accidental submissions when claiming a bounty by slightly delaying form opening.

@vercel
Copy link
Contributor

vercel bot commented Sep 11, 2025

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

Project Deployment Preview Updated (UTC)
dub Ready Ready Preview Sep 11, 2025 9:55pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 11, 2025

Walkthrough

Adds optional productId support to commission creation across schema, action, and UI. Adjusts SWR cache invalidation targets for bounty submission approval to /api/bounties. Safeguards bounty submission requirements parsing with a default array. Introduces a slight delay when opening the claim bounty form to avoid accidental submission.

Changes

Cohort / File(s) Summary
Bounties: SWR cache target update
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx, apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx
On approval success, mutate target changed from /api/bounties/${bountyId}/submissions to /api/bounties, broadening refreshed data scope.
Commissions: productId support
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx, apps/web/lib/actions/partners/create-commission.ts, apps/web/lib/zod/schemas/commissions.ts
Adds optional productId field in schema and UI; passes productId through action, includes in sale metadata (JSON) and commission context.
Bounty submission: requirements defaulting
apps/web/lib/actions/partners/create-bounty-submission.ts
Parses submission requirements with `bounty.submissionRequirements
UI: claim bounty open delay
apps/web/ui/partners/bounties/claim-bounty-modal.tsx
Adds 100ms delay before opening form to prevent accidental submission; other logic unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as CreateCommissionSheet (UI)
  participant Server as createCommissionAction
  participant Schema as createCommissionSchema
  participant Sales as recordSaleWithTimestamp
  participant Commissions as createPartnerCommission

  User->>UI: Submit commission form (amount, type, productId?)
  UI->>Server: POST createCommission (payload incl. productId?)
  Server->>Schema: Validate input (productId nullish allowed)
  Schema-->>Server: Parsed input
  alt productId provided
    Server->>Sales: recordSaleWithTimestamp(metadata: JSON{productId})
  else no productId
    Server->>Sales: recordSaleWithTimestamp(metadata: undefined)
  end
  Sales-->>Server: Sale record
  Server->>Commissions: createPartnerCommission({ sale: { productId? }, ... })
  Commissions-->>Server: Commission created
  Server-->>UI: Success response
  UI-->>User: Confirmation
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • steven-tey

Pre-merge checks (2 passed, 1 warning)

❌ 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 concisely highlights the primary change—adding a commission product ID—and signals additional smaller bounty-related fixes, so it is relevant and not misleading for the changeset.

Poem

I thump my paws—new fields arrive,
A productId hops in, alive.
Caches jump from rows to all,
Submissions safe from nullish fall.
A hundred milliseconds—wait!—then go,
Commissions bloom; that’s my show.
— Your diligent code rabbit 🥕✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch create-commission-product-id

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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx (1)

94-99: Bug: ternary precedence breaks sortBy

As written, the OR is evaluated before ?:, so any truthy searchParam forces metricColumnId. Use nullish coalescing with parentheses.

-  const sortBy =
-    searchParams.get("sortBy") || bounty?.type === "performance"
-      ? metricColumnId
-      : "createdAt";
+  const sortBy =
+    searchParams.get("sortBy") ?? (bounty?.type === "performance"
+      ? metricColumnId
+      : "createdAt");
♻️ Duplicate comments (1)
apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx (1)

48-49: LGTM: broader cache invalidation

Switching to mutatePrefix("/api/bounties") avoids memoization issues and refreshes related counts.

🧹 Nitpick comments (2)
apps/web/lib/zod/schemas/commissions.ts (1)

150-151: Add basic constraints to productId

Match invoiceId constraints and avoid unbounded strings; consider documenting.

-  productId: z.string().nullish(),
+  productId: z.string().max(190).nullish(),

Optionally add to COMMISSION_EXPORT_COLUMNS if you plan to export/filter by product.

apps/web/lib/actions/partners/create-commission.ts (1)

249-252: Avoid sending empty sale context

Skip sale when productId is nullish to reduce noise.

-            sale: {
-              productId,
-            },
+            ...(productId ? { sale: { productId } } : {}),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 98e7709 and 4456521.

📒 Files selected for processing (7)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submission-details-sheet.tsx (1 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx (1 hunks)
  • apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/commissions/create-commission-sheet.tsx (2 hunks)
  • apps/web/lib/actions/partners/create-bounty-submission.ts (1 hunks)
  • apps/web/lib/actions/partners/create-commission.ts (3 hunks)
  • apps/web/lib/zod/schemas/commissions.ts (1 hunks)
  • apps/web/ui/partners/bounties/claim-bounty-modal.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-08-26T14:32:33.851Z
Learnt from: TWilson023
PR: dubinc/dub#2736
File: apps/web/lib/actions/partners/create-bounty-submission.ts:105-112
Timestamp: 2025-08-26T14:32:33.851Z
Learning: Non-performance bounties are required to have submissionRequirements. In create-bounty-submission.ts, it's appropriate to let the parsing fail if submissionRequirements is null for non-performance bounties, as this indicates a data integrity issue that should be caught.

Applied to files:

  • apps/web/lib/actions/partners/create-bounty-submission.ts
📚 Learning: 2025-08-26T14:20:23.943Z
Learnt from: TWilson023
PR: dubinc/dub#2736
File: apps/web/app/api/workspaces/[idOrSlug]/notification-preferences/route.ts:13-14
Timestamp: 2025-08-26T14:20:23.943Z
Learning: The updateNotificationPreference action in apps/web/lib/actions/update-notification-preference.ts already handles all notification preference types dynamically, including newBountySubmitted, through its schema validation using the notificationTypes enum and Prisma's dynamic field update pattern.

Applied to files:

  • apps/web/lib/actions/partners/create-bounty-submission.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Vade Review
🔇 Additional comments (4)
apps/web/ui/partners/bounties/claim-bounty-modal.tsx (1)

447-452: Set explicit Button type and prevent form submission instead of using setTimeout

File: apps/web/ui/partners/bounties/claim-bounty-modal.tsx (around lines 447–452)

                   <Button
                     variant="primary"
                     text={isFormOpen ? "Submit proof" : "Claim bounty"}
                     className="grow rounded-lg"
+                    type={isFormOpen ? "submit" : "button"}
-                    onClick={
-                      isFormOpen
-                        ? undefined
-                        : // Delay open to prevent also submitting the form
-                          () => setTimeout(() => setIsFormOpen(true), 100)
-                    }
+                    onClick={
+                      isFormOpen
+                        ? undefined
+                        : (e) => {
+                            e.preventDefault();
+                            setIsFormOpen(true);
+                          }
+                    }
                     loading={isPending}

Search output did not locate the Button implementation to confirm its default type; set the prop explicitly to avoid relying on defaults.

apps/web/lib/actions/partners/create-bounty-submission.ts (1)

106-108: Defaulting to [] hides data integrity issues for non-performance bounties

Past decision was to fail parsing when requirements are missing to catch bad data. This change makes image/URL optional silently.

Apply if you want to preserve strictness:

-    const submissionRequirements = submissionRequirementsSchema.parse(
-      bounty.submissionRequirements || [],
-    );
+    if (!bounty.submissionRequirements) {
+      throw new Error("Submission requirements missing for this bounty.");
+    }
+    const submissionRequirements = submissionRequirementsSchema.parse(
+      bounty.submissionRequirements,
+    );

If relaxing is intentional, please confirm and add a comment explaining the rationale.

apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/[bountyId]/bounty-submissions-table.tsx (1)

429-430: LGTM: unify cache invalidation

Broadly mutating /api/bounties is consistent with the details sheet and keeps counts fresh.

apps/web/lib/actions/partners/create-commission.ts (1)

229-231: LGTM: include productId in sale metadata

Passing JSON metadata with productId to Tinybird is correct.

@steven-tey steven-tey merged commit 65df368 into main Sep 11, 2025
8 of 9 checks passed
@steven-tey steven-tey deleted the create-commission-product-id branch September 11, 2025 22:22
@coderabbitai coderabbitai bot mentioned this pull request Sep 22, 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