-
Notifications
You must be signed in to change notification settings - Fork 44
feat/Implement Spark Credits UI #156
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
Open
Oluwatos94
wants to merge
2
commits into
boundlessfi:main
Choose a base branch
from
Oluwatos94:Spark-Credits-UI
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { SparkCreditsService } from "@/lib/services/spark-credits"; | ||
|
|
||
| export async function GET( | ||
| request: NextRequest, | ||
| context: { params: Promise<{ userId: string }> }, | ||
| ) { | ||
| const { userId } = await context.params; | ||
| const { searchParams } = request.nextUrl; | ||
| const rawLimit = Number(searchParams.get("limit") ?? "20"); | ||
| const rawOffset = Number(searchParams.get("offset") ?? "0"); | ||
| const limit = Number.isFinite(rawLimit) | ||
| ? Math.min(Math.max(rawLimit, 1), 100) | ||
| : 20; | ||
| const offset = Number.isFinite(rawOffset) ? Math.max(rawOffset, 0) : 0; | ||
| const history = await SparkCreditsService.getCreditHistory( | ||
| userId, | ||
| limit, | ||
| offset, | ||
| ); | ||
| return NextResponse.json(history); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { NextRequest, NextResponse } from "next/server"; | ||
| import { SparkCreditsService } from "@/lib/services/spark-credits"; | ||
|
|
||
| export async function GET( | ||
| _request: NextRequest, | ||
| context: { params: Promise<{ userId: string }> }, | ||
| ) { | ||
| const { userId } = await context.params; | ||
| const balance = await SparkCreditsService.getBalance(userId); | ||
| return NextResponse.json(balance); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| "use client"; | ||
|
|
||
| import { useSparkCreditsBalance } from "@/hooks/use-spark-credits"; | ||
| import { | ||
| Tooltip, | ||
| TooltipContent, | ||
| TooltipProvider, | ||
| TooltipTrigger, | ||
| } from "@/components/ui/tooltip"; | ||
| import { Skeleton } from "@/components/ui/skeleton"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { Zap } from "lucide-react"; | ||
|
|
||
| interface CreditBalanceProps { | ||
| userId: string; | ||
| className?: string; | ||
| } | ||
|
|
||
| export function CreditBalance({ userId, className }: CreditBalanceProps) { | ||
| const { data, isLoading, isError } = useSparkCreditsBalance(userId); | ||
|
|
||
| if (isLoading) { | ||
| return <Skeleton className="h-6 w-14 rounded-full" />; | ||
| } | ||
|
|
||
| if (isError) { | ||
| return ( | ||
| <div | ||
| className={cn( | ||
| "flex items-center gap-1 px-2 py-1 rounded-full text-sm font-medium border border-border/50 bg-secondary/10 text-muted-foreground", | ||
| className, | ||
| )} | ||
| > | ||
| <Zap className="h-3.5 w-3.5" /> | ||
| <span>—</span> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const balance = data?.balance ?? 0; | ||
| const isLow = balance <= 1; | ||
|
|
||
| return ( | ||
| <TooltipProvider> | ||
| <Tooltip> | ||
| <TooltipTrigger asChild> | ||
| <div | ||
| className={cn( | ||
| "flex items-center gap-1 px-2 py-1 rounded-full text-sm font-medium border", | ||
| isLow | ||
| ? "border-destructive/40 bg-destructive/5 text-destructive" | ||
| : "border-border/50 bg-secondary/10 text-foreground", | ||
| className, | ||
| )} | ||
| > | ||
| <Zap className="h-3.5 w-3.5 fill-current" /> | ||
| <span>{balance}</span> | ||
| </div> | ||
| </TooltipTrigger> | ||
| <TooltipContent side="bottom" className="max-w-56 text-xs"> | ||
| <p className="font-semibold mb-1">Spark Credits</p> | ||
| <p className="text-muted-foreground"> | ||
| Each FCFS bounty claim costs 1 Spark Credit. Earn credits by | ||
| completing bounties. | ||
| </p> | ||
| {isLow && balance === 0 && ( | ||
| <p className="mt-1 text-destructive font-medium"> | ||
| No credits remaining — complete a bounty to earn more. | ||
| </p> | ||
| )} | ||
| {isLow && balance === 1 && ( | ||
| <p className="mt-1 text-destructive font-medium"> | ||
| Only 1 credit left — consider completing a bounty soon. | ||
| </p> | ||
| )} | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| </TooltipProvider> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; | ||
| import { cn } from "@/lib/utils"; | ||
| import { Zap, Trophy, CheckCircle, AlertCircle } from "lucide-react"; | ||
|
|
||
| interface CreditExplainerProps { | ||
| className?: string; | ||
| } | ||
|
|
||
| export function CreditExplainer({ className }: CreditExplainerProps) { | ||
| return ( | ||
| <Card className={cn("border-border/50", className)}> | ||
| <CardHeader className="pb-3 border-b border-border/50 bg-secondary/10"> | ||
| <CardTitle className="flex items-center gap-2 text-base"> | ||
| <Zap className="h-4 w-4 fill-current text-yellow-500" /> | ||
| About Spark Credits | ||
| </CardTitle> | ||
| </CardHeader> | ||
| <CardContent className="p-4 space-y-5"> | ||
| <p className="text-sm text-muted-foreground"> | ||
| Spark Credits are application credits that prevent spam while ensuring | ||
| quality contributors always have opportunities. | ||
| </p> | ||
|
|
||
| {/* How to earn */} | ||
| <div className="space-y-2"> | ||
| <h4 className="text-sm font-semibold flex items-center gap-1.5"> | ||
| <Trophy className="h-4 w-4 text-yellow-500" /> | ||
| How to Earn Credits | ||
| </h4> | ||
| <ul className="space-y-1.5 text-sm text-muted-foreground"> | ||
| <li className="flex items-start gap-2"> | ||
| <CheckCircle className="h-3.5 w-3.5 mt-0.5 flex-shrink-0 text-green-500" /> | ||
| <span>Complete a bounty — earn 1 credit per completion</span> | ||
| </li> | ||
| <li className="flex items-start gap-2"> | ||
| <CheckCircle className="h-3.5 w-3.5 mt-0.5 flex-shrink-0 text-green-500" /> | ||
| <span>Win a competition bounty — earn bonus credits</span> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
|
|
||
| {/* Costs */} | ||
| <div className="space-y-2"> | ||
| <h4 className="text-sm font-semibold flex items-center gap-1.5"> | ||
| <Zap className="h-4 w-4 text-yellow-500" /> | ||
| Credit Costs | ||
| </h4> | ||
| <div className="rounded-lg border border-border/50 divide-y divide-border/50"> | ||
| <div className="flex items-center justify-between px-3 py-2 text-sm"> | ||
| <span className="text-muted-foreground">Claim a FCFS bounty</span> | ||
| <span className="flex items-center gap-1 font-medium"> | ||
| <Zap className="h-3.5 w-3.5 fill-current text-yellow-500" />1 | ||
| credit | ||
| </span> | ||
| </div> | ||
| <div className="flex items-center justify-between px-3 py-2 text-sm"> | ||
| <span className="text-muted-foreground">Enter a competition</span> | ||
| <span className="text-muted-foreground text-xs italic">Free</span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| {/* Tips */} | ||
| <div className="space-y-2"> | ||
| <h4 className="text-sm font-semibold flex items-center gap-1.5"> | ||
| <AlertCircle className="h-4 w-4 text-blue-500" /> | ||
| Tips | ||
| </h4> | ||
| <ul className="space-y-1.5 text-sm text-muted-foreground"> | ||
| <li className="flex items-start gap-2"> | ||
| <span className="mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-center text-xs font-bold text-blue-500"> | ||
| • | ||
| </span> | ||
| <span> | ||
| Complete bounties before claiming new ones to keep your credit | ||
| balance healthy. | ||
| </span> | ||
| </li> | ||
| <li className="flex items-start gap-2"> | ||
| <span className="mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-center text-xs font-bold text-blue-500"> | ||
| • | ||
| </span> | ||
| <span> | ||
| Your credit balance is shown in the navbar so you always know | ||
| your current standing. | ||
| </span> | ||
| </li> | ||
| <li className="flex items-start gap-2"> | ||
| <span className="mt-0.5 h-3.5 w-3.5 flex-shrink-0 text-center text-xs font-bold text-blue-500"> | ||
| • | ||
| </span> | ||
| <span> | ||
| Credits cannot be purchased — they can only be earned through | ||
| contributions. | ||
| </span> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </CardContent> | ||
| </Card> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.