Skip to content

feat: cut manual segment creation to dedicated POST /api/artists/{id}/segments#1679

Closed
arpitgupta1214 wants to merge 2 commits into
testfrom
feat/chat-cutover-post-segments
Closed

feat: cut manual segment creation to dedicated POST /api/artists/{id}/segments#1679
arpitgupta1214 wants to merge 2 commits into
testfrom
feat/chat-cutover-post-segments

Conversation

@arpitgupta1214
Copy link
Copy Markdown
Collaborator

@arpitgupta1214 arpitgupta1214 commented Apr 15, 2026

Summary

Cuts hooks/useCreateSegments over to the new dedicated POST /api/artists/{id}/segments endpoint and removes the now-unused local app/api/segments/create/route.ts.

This is the chat PR in the Create capability 3-PR stack.

Changes

  • hooks/useCreateSegments.ts — POST to ${getClientApiBaseUrl()}/api/artists/{artist_account_id}/segments with Privy bearer auth; body is now { prompt } only (artist is path-encoded). Success-gate switched to data.status === "success"; error path still surfaces data.error via the existing react-toastify toasts. Pattern mirrors lib/artists/deleteArtist.ts + hooks/useDeleteArtist.ts.
  • app/api/segments/create/route.ts — deleted.

The sole consumer (components/Segments/NoSegmentsFound.tsx) is unchanged — it keeps its createSegments(refetch) call signature and loading flag.

Dependency

Left in place (intentional, out of scope)

  • lib/segments/createSegments.ts and downstream helpers remain — still imported by lib/tools/createSegments.ts (the AI tool wrapper). Note: lib/tools/createSegments.ts itself has no importers in chat, but removing it is a separate dead-code sweep, not this migration.

Verification

  • npx eslint hooks/useCreateSegments.ts components/Segments/ — clean
  • grep -rn "/api/segments/create" . — zero matches
  • npx tsc --noEmit — only pre-existing unrelated errors (spotify png module, emails test)

Test plan

  • api PR feat: POST /api/artists/{id}/segments (manual segment creation) api#444 merged to test
  • On a preview build, open an artist with no segments → "Create Fan Groups" in NoSegmentsFound triggers segment generation and shows the success toast
  • Artist with no Instagram socials → 409 path surfaces the feedback message via data.error in the error toast
  • Auth: signed-out state shows "Please sign in to generate segments" (no network call)

Summary by cubic

Moves segment creation to the dedicated POST /api/artists/{id}/segments endpoint with Privy bearer auth and deletes the old local route. Extracts the network call to lib/artists/createArtistSegments.ts; UI behavior stays the same.

  • Refactors
    • Added lib/artists/createArtistSegments.ts to call ${getClientApiBaseUrl()}/api/artists/{artistId}/segments with Authorization: Bearer; sends { prompt }; succeeds on { status: "success" }, throws on data.error.
    • Updated hooks/useCreateSegments to use usePrivy().getAccessToken() from @privy-io/react-auth and delegate to createArtistSegments(...); success/error toasts unchanged.
    • Removed app/api/segments/create/route.ts; components/Segments/NoSegmentsFound.tsx unchanged.

Written for commit 07ffb22. Summary will update on new commits.

…ents

Migrate `hooks/useCreateSegments` from the local `POST /api/segments/create`
route to the dedicated `POST /api/artists/{id}/segments` endpoint with Privy
bearer auth (matches the pattern in `lib/artists/deleteArtist.ts`). The artist
target is now path-encoded and only `prompt` goes in the body.

Success is now `{ status: "success" }`-gated rather than response-level
`error` presence. Error toast surfacing is unchanged — `data.error` still
carries the handler message (including the 409 no-socials/no-fans case).

Deletes `app/api/segments/create/route.ts` since the sole caller
(`components/Segments/NoSegmentsFound.tsx` via the hook) is now cut over.
Grep confirms zero remaining references to `/api/segments/create`.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 15, 2026

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

Project Deployment Actions Updated (UTC)
recoup-chat Ready Ready Preview Apr 15, 2026 9:17pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

Warning

Rate limit exceeded

@arpitgupta1214 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 24 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 59 minutes and 24 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b2143b2a-be39-4785-8106-e800e47393d4

📥 Commits

Reviewing files that changed from the base of the PR and between ab21089 and 07ffb22.

📒 Files selected for processing (3)
  • app/api/segments/create/route.ts
  • hooks/useCreateSegments.ts
  • lib/artists/createArtistSegments.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/chat-cutover-post-segments

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.

Following project pattern (fetchArtists, deleteArtist) — network call lives
in lib/artists/*, the hook just wires Privy auth + toast feedback.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: This is an API migration and refactor that changes the authentication method and network path for a core business feature (segment creation).

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.

1 participant