Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 61 additions & 4 deletions app/profile/[userId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,45 @@ import Link from "next/link";
import { useParams } from "next/navigation";
import { useMemo } from "react";
import { useCompletionHistory } from "@/hooks/use-reputation";
import type { MilestoneFlowState } from "@/types/milestone-flow";

function getMilestoneClaimForUser(
bountyId: string,
viewerId: string,
): { status: string; nextMilestone?: string } | null {
if (typeof window === "undefined") return null;

const key = `milestone_flow_${bountyId}`;
const serialized = window.localStorage.getItem(key);
if (!serialized) return null;

try {
const flow = JSON.parse(serialized) as MilestoneFlowState;
const participant = flow.participants.find(
(item) => item.contributorId === viewerId,
);

if (!participant) return null;

const milestone = flow.milestones[participant.currentMilestoneIndex];

if (participant.status === "COMPLETED") {
return { status: "completed" };
}

if (participant.status === "REJECTED") {
return { status: "disputed" };
}

if (participant.status === "SUBMITTED") {
return { status: "submitted", nextMilestone: milestone?.title };
}

return { status: "in-progress", nextMilestone: milestone?.title };
} catch {
return null;
}
}

export default function ProfilePage() {
const params = useParams();
Expand All @@ -42,10 +81,11 @@ export default function ProfilePage() {

const myClaims = useMemo<MyClaim[]>(() => {
const bounties = bountyResponse?.data ?? [];
const claimMap = new Map<string, MyClaim>();

return bounties
bounties
.filter((bounty) => bounty.createdBy === userId)
.map((bounty) => {
.forEach((bounty) => {
let status = "unknown";

if (bounty.status === "COMPLETED") {
Expand All @@ -64,13 +104,30 @@ export default function ProfilePage() {
status = "open";
}

return {
claimMap.set(bounty.id, {
bountyId: bounty.id,
title: bounty.title,
status,
rewardAmount: bounty.rewardAmount ?? undefined,
};
});
});

bounties
.filter((bounty) => bounty.type === "MILESTONE_BASED")
.forEach((bounty) => {
const milestoneClaim = getMilestoneClaimForUser(bounty.id, userId);
if (!milestoneClaim) return;

claimMap.set(bounty.id, {
bountyId: bounty.id,
title: bounty.title,
status: milestoneClaim.status,
nextMilestone: milestoneClaim.nextMilestone,
rewardAmount: bounty.rewardAmount ?? undefined,
});
});

return Array.from(claimMap.values());
}, [bountyResponse?.data, userId]);

const earningsSummary = useMemo<EarningsSummaryType>(() => {
Expand Down
Loading
Loading