Skip to content

feat: add live Twitter/X stats under submission details panel in spon…#1427

Open
mansiverma897993 wants to merge 2 commits into
SuperteamDAO:mainfrom
mansiverma897993:feature/x-stats-1422
Open

feat: add live Twitter/X stats under submission details panel in spon…#1427
mansiverma897993 wants to merge 2 commits into
SuperteamDAO:mainfrom
mansiverma897993:feature/x-stats-1422

Conversation

@mansiverma897993

@mansiverma897993 mansiverma897993 commented Jul 1, 2026

Copy link
Copy Markdown

…sor dashboard

What does this PR do?

Where should the reviewer start?

How should this be manually tested?

Any background context you want to provide?

What are the relevant issues?

Screenshots (if appropriate)

Summary by CodeRabbit

  • New Features
    • Added tweet engagement stats to submission details when a valid X/Twitter status URL is detected (from the linked URL or tweet field).
    • Displays views, likes, reposts, and replies with clear loading, error, and results states.
  • Bug Fixes
    • Improved URL validation to only show stats for properly formatted tweet status links.
    • Enhanced handling when engagement data can’t be retrieved, showing an “Unavailable” badge and safe default metrics.

@vercel

vercel Bot commented Jul 1, 2026

Copy link
Copy Markdown

@mansiverma897993 is attempting to deploy a commit to the Superteam Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Adds a Twitter/X tweet stats API route, a TweetStats component for engagement metrics, and conditional rendering of that component in the sponsor dashboard submission details view.

Changes

Tweet Engagement Stats

Layer / File(s) Summary
Tweet stats API route
src/pages/api/twitter/tweet-stats.ts
Adds tweet URL parsing, request validation, bearer-token Twitter API fetching with timeout handling, zeroed fallback responses, and authenticated route export.
TweetStats component UI
src/features/sponsor-dashboard/components/Submissions/TweetStats.tsx
Adds a component that fetches metrics from the new API, handles loading and error states, formats counts, and renders engagement stats with availability badges.
Details view integration
src/features/sponsor-dashboard/components/Submissions/Details.tsx
Adds tweet-status URL validation and conditionally renders TweetStats for submission link and tweet fields.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DetailsView
  participant TweetStats
  participant TweetStatsAPI
  participant TwitterAPI

  DetailsView->>TweetStats: render with tweet URL
  TweetStats->>TweetStatsAPI: GET /api/twitter/tweet-stats?url=...
  TweetStatsAPI->>TweetStatsAPI: validate and extract tweet ID
  alt token missing or fetch fails
    TweetStatsAPI-->>TweetStats: zeroed metrics, unavailable
  else success
    TweetStatsAPI->>TwitterAPI: fetch public_metrics
    TwitterAPI-->>TweetStatsAPI: public_metrics
    TweetStatsAPI-->>TweetStats: mapped engagement metrics
  end
  TweetStats-->>DetailsView: render stats
Loading

Possibly related issues

Possibly related PRs

  • SuperteamDAO/earn#1357: Related around verify-external-payment.ts, which is the same endpoint area touched by the formatting-only changes in this PR.

Poem

I’m a bunny with a dashboard grin,
Watching tweet counts hop right in.
Views and likes in tidy rows,
Replies and reposts as the metric glows.
If tokens nap, I still can tell,
“Unavailable” — and that’s okay as well.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding live Twitter/X stats to the submission details panel.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (9)
src/features/sponsor-dashboard/components/Submissions/TweetStats.tsx (2)

31-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Avoid any for the caught error.

As per coding guidelines: "Outside of generic functions, use any type extremely sparingly."

♻️ Proposed fix
-      } catch (err: any) {
+      } catch (err: unknown) {
         if (active) {
-          setError(err.message || 'Error loading stats');
+          setError(err instanceof Error ? err.message : 'Error loading stats');
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/sponsor-dashboard/components/Submissions/TweetStats.tsx` at line
31, The catch block in TweetStats should not use any for the thrown error.
Update the error handling in the component’s try/catch to use a safer
caught-error type (or narrow from unknown) and adjust any references inside the
catch body accordingly, keeping the change localized to the TweetStats
component.

Source: Coding guidelines


4-10: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Mark TweetMetrics fields as readonly.

As per coding guidelines: "Use readonly properties for object types by default in TypeScript to prevent accidental mutation at runtime."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/sponsor-dashboard/components/Submissions/TweetStats.tsx` around
lines 4 - 10, The TweetMetrics interface currently allows mutation of its
fields, which should be avoided by default. Update the TweetMetrics type in
TweetStats to mark each property as readonly, preserving the existing field
names (views, likes, retweets, comments, isMocked) while preventing accidental
reassignment.

Source: Coding guidelines

src/pages/api/twitter/tweet-stats.ts (5)

5-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Use top-level import type instead of inline type in a named import.

As per path instructions: "Prefer top-level import type over inline import { type ... } syntax."

♻️ Proposed fix
-import { type NextApiRequestWithUser } from '`@/features/auth/types`';
+import type { NextApiRequestWithUser } from '`@/features/auth/types`';
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/api/twitter/tweet-stats.ts` at line 5, The import in tweet-stats.ts
uses inline type syntax inside a named import, which should be converted to
top-level type-only import style. Update the import that brings in
NextApiRequestWithUser so it uses import type at the top level instead of import
{ type ... }, matching the project’s import conventions and keeping type-only
dependencies explicit.

Source: Path instructions


46-62: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate mock-metric generation logic.

The seed/views/likes/retweets/comments computation is duplicated verbatim in the no-token branch and the API-error fallback branch. Extract into a shared helper.

♻️ Proposed fix
+function generateMockMetrics(tweetId: string) {
+  const seed = parseInt(tweetId.slice(-4), 10) || 1234;
+  const views = Math.floor(seed * 1.5) + 120;
+  const likes = Math.floor(views * 0.08) + 5;
+  const retweets = Math.floor(likes * 0.15) + 1;
+  const comments = Math.floor(likes * 0.1) + 1;
+  return { views, likes, retweets, comments, isMocked: true };
+}

Then call res.status(200).json(generateMockMetrics(tweetId)); in both branches.

Also applies to: 74-89

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/api/twitter/tweet-stats.ts` around lines 46 - 62, The mock metric
calculation is duplicated in the bearer-token fallback and the API-error
fallback inside tweet-stats.ts. Extract the seed/views/likes/retweets/comments
logic into a shared helper (for example, a generateMockMetrics function) and
have both the no-token path and the error-handling path call it, then return its
result via res.status(200).json(...) to keep the behavior identical in both
branches.

32-32: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Declare explicit return type for the handler function.

handler is a top-level module function; it should declare its return type.

As per coding guidelines: "Declare return types for top-level module functions in TypeScript (exception: React components returning JSX)."

♻️ Proposed fix
-async function handler(req: NextApiRequestWithUser, res: NextApiResponse) {
+async function handler(req: NextApiRequestWithUser, res: NextApiResponse): Promise<void> {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/api/twitter/tweet-stats.ts` at line 32, The top-level API route
function handler is missing an explicit return type, so update its signature to
declare the return type directly on handler and keep the type aligned with
NextApiResponse usage. Use the handler symbol in tweet-stats.ts as the place to
add the return annotation, following the project rule that top-level module
functions must declare return types.

Source: Coding guidelines


106-107: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Log error using safeStringify before returning 500.

As per path instructions: "Always wrap main logic in try-catch blocks and log errors using safeStringify before returning 500 status."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/api/twitter/tweet-stats.ts` around lines 106 - 107, The error
handling in the Twitter/X metrics API handler should log the caught exception
with safeStringify before sending the 500 response. Update the try-catch around
the main logic in tweet-stats.ts so the logger.error call serializes the error
via safeStringify instead of passing the raw error object, then keep returning
the existing 500 JSON response. Use the existing logger and safeStringify
utilities in the tweet stats request handler.

Source: Path instructions


8-30: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Hostname check is bypassable via substring matching.

host.includes('twitter.com') also matches spoofed hosts like nottwitter.com or twitter.com.evil.com. No SSRF impact today since the outbound fetch always targets api.twitter.com using only the numeric tweetId, but this loosens the intended domain validation and this same logic is duplicated in Details.tsx's isTweetStatusUrl.

♻️ Proposed fix
-    if (!host.includes('twitter.com') && !host.includes('x.com')) {
+    if (
+      host !== 'twitter.com' && !host.endsWith('.twitter.com') &&
+      host !== 'x.com' && !host.endsWith('.x.com')
+    ) {
       return null;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/api/twitter/tweet-stats.ts` around lines 8 - 30, The hostname
validation in extractTweetId is too loose because host.includes(...) can accept
spoofed domains; tighten it to only allow the exact Twitter/X hostnames or their
proper subdomains, and apply the same fix to the duplicated isTweetStatusUrl
logic in Details.tsx. Update the shared parsing/validation behavior so both
places reject lookalike hosts such as nottwitter.com or twitter.com.evil.com
while still accepting valid twitter.com and x.com URLs.
src/features/sponsor-dashboard/components/Submissions/Details.tsx (2)

65-67: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Non-null assertions on selectedSubmission.

Safe today since isTweetStatusUrl only returns true when selectedSubmission?.link/.tweet is truthy (implying selectedSubmission itself is defined), but the double non-null assertion (selectedSubmission!.link!) is fragile if the check logic changes later.

Also applies to: 76-78

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/sponsor-dashboard/components/Submissions/Details.tsx` around
lines 65 - 67, The `Details` component is relying on fragile non-null assertions
for `selectedSubmission` in the tweet and Bluesky stats branches. Replace
`selectedSubmission!.link!`/similar usage with a safe local guard or derived
variable after the `isTweetStatusUrl`/bluesky check, and pass the verified link
directly to `TweetStats` and the related component so the code stays safe if the
predicate logic changes.

19-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate URL-validation logic vs. extractTweetId in tweet-stats.ts.

This function reimplements the same host/status-id parsing already present in src/pages/api/twitter/tweet-stats.ts (Lines 8-30), including the same .includes() hostname bypass (e.g. nottwitter.com passes). Extract a single shared utility (e.g. parseTweetStatusUrl) usable by both the API route and this component to avoid drift.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/sponsor-dashboard/components/Submissions/Details.tsx` around
lines 19 - 40, The URL parsing logic in isTweetStatusUrl duplicates the tweet-id
extraction already used by extractTweetId in tweet-stats.ts, so consolidate both
into a shared helper such as parseTweetStatusUrl. Update Details.tsx and the
tweet-stats API to call the shared utility instead of maintaining separate
hostname/status parsing, and fix the host check so it validates the actual
Twitter/X domains rather than relying on a loose .includes() match.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/pages/api/twitter/tweet-stats.ts`:
- Around line 35-42: The tweet-stats API handler does not match the endpoint
response conventions: update the logic in the tweet URL validation and
downstream success/error branches in tweet-stats.ts so success returns { data:
result, message: 'Operation successful' } and all error responses include both
error and message fields. Replace the manual tweetUrl checks and tweetId
validation with a Zod schema using safeParse, and return 403 on validation
failure with the schema errors in the error payload. Ensure the same response
shape is used consistently in the main handler paths that build the final tweet
stats response.
- Around line 65-72: The Twitter API call in tweet-stats should not wait
indefinitely; add an AbortController-based timeout around the fetch in the
tweet-stats handler. Update the logic around the external request to
api.twitter.com so the request is aborted after a short, defined duration, and
make sure the handler uses the timeout-aware fetch result/error path in the same
function that builds the tweet stats response.

---

Nitpick comments:
In `@src/features/sponsor-dashboard/components/Submissions/Details.tsx`:
- Around line 65-67: The `Details` component is relying on fragile non-null
assertions for `selectedSubmission` in the tweet and Bluesky stats branches.
Replace `selectedSubmission!.link!`/similar usage with a safe local guard or
derived variable after the `isTweetStatusUrl`/bluesky check, and pass the
verified link directly to `TweetStats` and the related component so the code
stays safe if the predicate logic changes.
- Around line 19-40: The URL parsing logic in isTweetStatusUrl duplicates the
tweet-id extraction already used by extractTweetId in tweet-stats.ts, so
consolidate both into a shared helper such as parseTweetStatusUrl. Update
Details.tsx and the tweet-stats API to call the shared utility instead of
maintaining separate hostname/status parsing, and fix the host check so it
validates the actual Twitter/X domains rather than relying on a loose
.includes() match.

In `@src/features/sponsor-dashboard/components/Submissions/TweetStats.tsx`:
- Line 31: The catch block in TweetStats should not use any for the thrown
error. Update the error handling in the component’s try/catch to use a safer
caught-error type (or narrow from unknown) and adjust any references inside the
catch body accordingly, keeping the change localized to the TweetStats
component.
- Around line 4-10: The TweetMetrics interface currently allows mutation of its
fields, which should be avoided by default. Update the TweetMetrics type in
TweetStats to mark each property as readonly, preserving the existing field
names (views, likes, retweets, comments, isMocked) while preventing accidental
reassignment.

In `@src/pages/api/twitter/tweet-stats.ts`:
- Line 5: The import in tweet-stats.ts uses inline type syntax inside a named
import, which should be converted to top-level type-only import style. Update
the import that brings in NextApiRequestWithUser so it uses import type at the
top level instead of import { type ... }, matching the project’s import
conventions and keeping type-only dependencies explicit.
- Around line 46-62: The mock metric calculation is duplicated in the
bearer-token fallback and the API-error fallback inside tweet-stats.ts. Extract
the seed/views/likes/retweets/comments logic into a shared helper (for example,
a generateMockMetrics function) and have both the no-token path and the
error-handling path call it, then return its result via
res.status(200).json(...) to keep the behavior identical in both branches.
- Line 32: The top-level API route function handler is missing an explicit
return type, so update its signature to declare the return type directly on
handler and keep the type aligned with NextApiResponse usage. Use the handler
symbol in tweet-stats.ts as the place to add the return annotation, following
the project rule that top-level module functions must declare return types.
- Around line 106-107: The error handling in the Twitter/X metrics API handler
should log the caught exception with safeStringify before sending the 500
response. Update the try-catch around the main logic in tweet-stats.ts so the
logger.error call serializes the error via safeStringify instead of passing the
raw error object, then keep returning the existing 500 JSON response. Use the
existing logger and safeStringify utilities in the tweet stats request handler.
- Around line 8-30: The hostname validation in extractTweetId is too loose
because host.includes(...) can accept spoofed domains; tighten it to only allow
the exact Twitter/X hostnames or their proper subdomains, and apply the same fix
to the duplicated isTweetStatusUrl logic in Details.tsx. Update the shared
parsing/validation behavior so both places reject lookalike hosts such as
nottwitter.com or twitter.com.evil.com while still accepting valid twitter.com
and x.com URLs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fa30014e-69d0-45a9-9cd3-5c499e36dfe5

📥 Commits

Reviewing files that changed from the base of the PR and between 3d93374 and 7f38761.

📒 Files selected for processing (3)
  • src/features/sponsor-dashboard/components/Submissions/Details.tsx
  • src/features/sponsor-dashboard/components/Submissions/TweetStats.tsx
  • src/pages/api/twitter/tweet-stats.ts

Comment thread src/pages/api/twitter/tweet-stats.ts Outdated
Comment thread src/pages/api/twitter/tweet-stats.ts
Comment thread src/pages/api/twitter/tweet-stats.ts Outdated
Comment on lines +47 to +62
logger.warn('Twitter/X API bearer token is not configured. Returning simulated mock metrics.');
// Generate deterministic mock stats based on the tweetId
const seed = parseInt(tweetId.slice(-4), 10) || 1234;
const views = Math.floor(seed * 1.5) + 120;
const likes = Math.floor(views * 0.08) + 5;
const retweets = Math.floor(likes * 0.15) + 1;
const comments = Math.floor(likes * 0.10) + 1;

return res.status(200).json({
views,
likes,
retweets,
comments,
isMocked: true,
});
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why are we falling back to showing false stats, if it fails it should either show 0 or no stats available, rather thn showing mock stats

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

"Done! I've removed the false/mock stats fallback. Now, if the API call fails or if the bearer token is not configured, it returns 0 metrics, and the UI displays an 'Unavailable' badge instead."

Comment thread src/pages/api/twitter/tweet-stats.ts Outdated
Comment on lines +76 to +89
// Fallback to mock data if API limits or errors occur
const seed = parseInt(tweetId.slice(-4), 10) || 1234;
const views = Math.floor(seed * 1.5) + 120;
const likes = Math.floor(views * 0.08) + 5;
const retweets = Math.floor(likes * 0.15) + 1;
const comments = Math.floor(likes * 0.10) + 1;
return res.status(200).json({
views,
likes,
retweets,
comments,
isMocked: true,
});
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

similarly here as well

@mansiverma897993

Copy link
Copy Markdown
Author

Hi @RevTpark, I have updated the PR to resolve all the requested changes:

Removed False Stats: Replaced the deterministic mock stats fallback entirely. If the API token is not configured or if the request fails, the API now returns 0 metrics with isAvailable: false, and the UI displays an "Unavailable" badge.
Added Fetch Timeout: Added an AbortController-based 5-second timeout to the Twitter/X fetch request to prevent any blocking/timeouts.
Zod Validation & Response Format: Standardized query validation using Zod (safeParse returning a 403 status on failure) and structured all API responses to follow the project's standard { data, message } format.
Please take another look. Thank you!

@RevTpark

RevTpark commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

hey @mansiverma897993 i think you forgot to push the changes, i can only see 1 commit on this branch.

@mansiverma897993

Copy link
Copy Markdown
Author

Hi @RevTpark,

Apologies for the oversight! I have successfully pushed the latest changes to the branch now.

Here is a summary of the fixes updated in the PR:

  1. Removed False/Mock Stats: Completely removed the mock/deterministic stats fallback. If the API token is not configured or if the request fails, the API returns zero metrics with isAvailable: false, and the UI displays an "Unavailable" badge.
  2. Added Fetch Timeout: Implemented a 5-second timeout using AbortController to prevent potential request blocking or resource exhaustion.
  3. Zod Validation & Standardized Response Format: Standardized query validation using Zod (safeParse returning a 403 status with validation messages on failure) and structured all API responses to follow the project's standard { data, message } format.

Please take another look. Thank you!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/pages/api/twitter/tweet-stats.ts (2)

47-47: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Declare an explicit return type for handler.

Top-level module functions should have declared return types. Add Promise<void>.

♻️ Proposed change
-async function handler(req: NextApiRequestWithUser, res: NextApiResponse) {
+async function handler(
+  req: NextApiRequestWithUser,
+  res: NextApiResponse,
+): Promise<void> {

As per coding guidelines: "Declare return types for top-level module functions in TypeScript (exception: React components returning JSX)".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/api/twitter/tweet-stats.ts` at line 47, The top-level module
function handler is missing an explicit return type, so add Promise<void> to its
declaration. Update the handler signature in the NextApiRequestWithUser /
NextApiResponse API route so it clearly declares its return type while
preserving the existing logic and async behavior.

Source: Coding guidelines


71-147: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Set cache headers on responses via setCacheHeaders.

None of the response paths set caching headers. Beyond the path-instruction requirement, the Twitter/X API v2 enforces tight rate limits, and this endpoint is hit on every dashboard Details view; short-lived response caching would materially reduce upstream calls and the risk of hitting those limits.

As per path instructions: "Use setCacheHeaders utility for setting appropriate caching headers on responses in Next.js API endpoints".

#!/bin/bash
# Confirm the setCacheHeaders utility and its expected signature/usage
rg -nP -C3 'export\s+(function|const)\s+setCacheHeaders' 
rg -nP -C2 'setCacheHeaders\s*\(' -g 'src/pages/api/**'
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/api/twitter/tweet-stats.ts` around lines 71 - 147, The Twitter
stats API responses in tweet-stats should use setCacheHeaders instead of
returning uncached JSON from each branch. Update the main success path and every
fallback path in the tweet stats handler to call setCacheHeaders on the Next.js
response before res.status(...).json(...), using the existing setCacheHeaders
utility with an appropriate short-lived cache policy. Make sure the change is
applied consistently in the tweet stats endpoint’s fetch success, non-ok
response, missing metrics, and early-return paths so all responses share the
same caching behavior.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/pages/api/twitter/tweet-stats.ts`:
- Line 47: The top-level module function handler is missing an explicit return
type, so add Promise<void> to its declaration. Update the handler signature in
the NextApiRequestWithUser / NextApiResponse API route so it clearly declares
its return type while preserving the existing logic and async behavior.
- Around line 71-147: The Twitter stats API responses in tweet-stats should use
setCacheHeaders instead of returning uncached JSON from each branch. Update the
main success path and every fallback path in the tweet stats handler to call
setCacheHeaders on the Next.js response before res.status(...).json(...), using
the existing setCacheHeaders utility with an appropriate short-lived cache
policy. Make sure the change is applied consistently in the tweet stats
endpoint’s fetch success, non-ok response, missing metrics, and early-return
paths so all responses share the same caching behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 19028a97-399b-4fe5-96f7-9c743ae1e19f

📥 Commits

Reviewing files that changed from the base of the PR and between 7f38761 and 0d934e5.

📒 Files selected for processing (4)
  • src/features/sponsor-dashboard/components/Submissions/Details.tsx
  • src/features/sponsor-dashboard/components/Submissions/TweetStats.tsx
  • src/pages/api/sponsor-dashboard/listings/verify-external-payment.ts
  • src/pages/api/twitter/tweet-stats.ts
✅ Files skipped from review due to trivial changes (1)
  • src/pages/api/sponsor-dashboard/listings/verify-external-payment.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/features/sponsor-dashboard/components/Submissions/Details.tsx
  • src/features/sponsor-dashboard/components/Submissions/TweetStats.tsx

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.

Add stats from Twitter under the submission details panel in Sponsor Dashboard

2 participants