-
Notifications
You must be signed in to change notification settings - Fork 35
feat:implement user dashboard-my claims #87
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
Merged
Merged
Changes from 1 commit
Commits
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
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,37 @@ | ||
| import { CLAIM_SECTIONS, getClaimsBySection, normalizeStatus, type MyClaim } from "@/components/reputation/my-claims"; | ||
| import { describe, expect, it } from "@jest/globals"; | ||
|
|
||
| describe("My Claims helpers", () => { | ||
| it("normalizes status values consistently", () => { | ||
| expect(normalizeStatus(" In Review ")).toBe("in-review"); | ||
| expect(normalizeStatus("UNDER_REVIEW")).toBe("under-review"); | ||
| expect(normalizeStatus("in_review")).toBe("in-review"); | ||
| }); | ||
|
|
||
| it("groups claims into Active Claims, In Review, and Completed by status", () => { | ||
| const claims: MyClaim[] = [ | ||
| { bountyId: "1", title: "Active A", status: "active" }, | ||
| { bountyId: "2", title: "Active B", status: "claimed" }, | ||
| { bountyId: "3", title: "Review A", status: "in review" }, | ||
| { bountyId: "4", title: "Review B", status: "UNDER_REVIEW" }, | ||
| { bountyId: "5", title: "Completed A", status: "completed" }, | ||
| { bountyId: "6", title: "Completed B", status: "closed" }, | ||
| { bountyId: "7", title: "Unknown", status: "queued" }, | ||
| ]; | ||
|
|
||
| const groups = getClaimsBySection(claims); | ||
|
|
||
| expect(groups).toHaveLength(CLAIM_SECTIONS.length); | ||
|
|
||
| const activeGroup = groups.find((group) => group.section.title === "Active Claims"); | ||
| const reviewGroup = groups.find((group) => group.section.title === "In Review"); | ||
| const completedGroup = groups.find((group) => group.section.title === "Completed"); | ||
|
|
||
| expect(activeGroup?.claims.map((claim) => claim.bountyId)).toEqual(["1", "2"]); | ||
| expect(reviewGroup?.claims.map((claim) => claim.bountyId)).toEqual(["3", "4"]); | ||
| expect(completedGroup?.claims.map((claim) => claim.bountyId)).toEqual(["5", "6"]); | ||
|
|
||
| const groupedIds = new Set(groups.flatMap((group) => group.claims.map((claim) => claim.bountyId))); | ||
| expect(groupedIds.has("7")).toBe(false); | ||
| }); | ||
| }); |
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,103 @@ | ||
| import Link from "next/link"; | ||
| import { Badge } from "@/components/ui/badge"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; | ||
| import { formatCurrency } from "@/helpers/format.helper"; | ||
|
|
||
| export type MyClaim = { | ||
| bountyId: string; | ||
| title: string; | ||
| status: string; | ||
| nextMilestone?: string; | ||
| rewardAmount?: number; | ||
| }; | ||
|
|
||
| interface MyClaimsProps { | ||
| claims: MyClaim[]; | ||
| } | ||
|
|
||
| export const CLAIM_SECTIONS: { title: string; statuses: string[] }[] = [ | ||
| { title: "Active Claims", statuses: ["active", "claimed", "in-progress"] }, | ||
| { title: "In Review", statuses: ["in-review", "in review", "review", "pending", "under-review"] }, | ||
| { title: "Completed", statuses: ["completed", "closed", "accepted", "done"] }, | ||
| ]; | ||
|
|
||
| export function normalizeStatus(status: string) { | ||
| return status.trim().toLowerCase().replace(/[\s_]+/g, "-"); | ||
| } | ||
|
|
||
| function formatStatusLabel(status: string) { | ||
| return status | ||
| .replace(/[-_]+/g, " ") | ||
| .replace(/\b\w/g, (char) => char.toUpperCase()); | ||
| } | ||
|
|
||
| export function getClaimsBySection(claims: MyClaim[]) { | ||
| return CLAIM_SECTIONS.map((section) => ({ | ||
| section, | ||
| claims: claims.filter((claim) => { | ||
| const normalizedClaimStatus = normalizeStatus(claim.status); | ||
| return section.statuses.some((status) => normalizeStatus(status) === normalizedClaimStatus); | ||
| }), | ||
| })); | ||
| } | ||
|
|
||
| export function MyClaims({ claims }: MyClaimsProps) { | ||
| return ( | ||
| <div className="space-y-6"> | ||
| {getClaimsBySection(claims).map(({ section, claims: sectionClaims }) => { | ||
|
|
||
| return ( | ||
| <Card key={section.title} className="gap-4 py-5"> | ||
| <CardHeader className="px-5"> | ||
| <CardTitle className="text-lg">{section.title}</CardTitle> | ||
| <CardDescription> | ||
| {sectionClaims.length === 0 | ||
| ? "No claims in this section." | ||
| : `${sectionClaims.length} claim${sectionClaims.length === 1 ? "" : "s"}`} | ||
| </CardDescription> | ||
| </CardHeader> | ||
| <CardContent className="px-5"> | ||
| {sectionClaims.length === 0 ? ( | ||
| <p className="text-sm text-muted-foreground">No opportunities yet.</p> | ||
| ) : ( | ||
| <div className="space-y-3"> | ||
| {sectionClaims.map((claim) => ( | ||
| <div | ||
| key={`${section.title}-${claim.bountyId}`} | ||
| className="rounded-lg border border-border/60 bg-secondary/5 p-4" | ||
| > | ||
| <div className="flex items-start justify-between gap-3"> | ||
| <div className="min-w-0 space-y-2"> | ||
| <h4 className="truncate text-sm font-semibold" title={claim.title}> | ||
| {claim.title} | ||
| </h4> | ||
| <div className="flex flex-wrap items-center gap-2"> | ||
| <Badge variant="outline">{formatStatusLabel(claim.status)}</Badge> | ||
| {typeof claim.rewardAmount === "number" && ( | ||
| <span className="text-sm text-muted-foreground"> | ||
| {formatCurrency(claim.rewardAmount, "$")} | ||
| </span> | ||
| )} | ||
| </div> | ||
| {claim.nextMilestone && ( | ||
| <p className="text-xs text-muted-foreground"> | ||
| Next milestone: {claim.nextMilestone} | ||
| </p> | ||
| )} | ||
| </div> | ||
| <Button asChild variant="outline" size="sm" className="shrink-0"> | ||
| <Link href={`/bounty/${claim.bountyId}`}>View Opportunity</Link> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| )} | ||
| </CardContent> | ||
| </Card> | ||
| ); | ||
| })} | ||
| </div> | ||
| ); | ||
| } |
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.