-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds contributors details page and private repo support (#7)
- Loading branch information
1 parent
fada939
commit 4f7ee45
Showing
9 changed files
with
221 additions
and
9 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
src/app/(dashboard)/contributors/[contributorUserName]/page.tsx
This file contains 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,100 @@ | ||
"use client"; | ||
|
||
import { ContributorDetailsDto } from "@/app/api/contributors/details/fetchContributorDetails"; | ||
import BreadCrumb from "@/components/breadcrumbs"; | ||
import { GithubRepoList } from "@/components/githubRepoList"; | ||
import { TeamCardList } from "@/components/teamCardList"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/components/ui/card"; | ||
import { Heading } from "@/components/ui/heading"; | ||
import { Separator } from "@/components/ui/separator"; | ||
import axios from "axios"; | ||
import React, { useEffect, useState } from "react"; | ||
|
||
interface ContributorDetailsPageProps { | ||
params: { contributorUserName: string }; | ||
} | ||
|
||
export default function ContributorDetailsPage({ | ||
params, | ||
}: ContributorDetailsPageProps) { | ||
const contributorUserName = params.contributorUserName; | ||
const breadcrumbItems = [ | ||
{ title: "Contributors", link: "/contributors" }, | ||
{ | ||
title: "Contributor details", | ||
link: `/contributors/${contributorUserName}`, | ||
}, | ||
]; | ||
const [contributorDetails, setContributorDetails] = | ||
useState<ContributorDetailsDto>(); | ||
|
||
useEffect(() => { | ||
if (contributorUserName) { | ||
handleFetchContributorDetails(); | ||
} | ||
}, []); | ||
|
||
const handleFetchContributorDetails = async () => { | ||
const { data } = await axios.get( | ||
"/api/contributors/details?contributor_username=" + contributorUserName, | ||
); | ||
console.log("fetched"); | ||
console.log(data); | ||
if (data.success) { | ||
setContributorDetails(data.contributorDetails); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="flex-1 space-y-4 p-4 md:p-8 pt-6"> | ||
<BreadCrumb items={breadcrumbItems} /> | ||
<div className="flex items-start justify-between"> | ||
<Heading | ||
title={contributorUserName} | ||
description={`View the details of your contributor`} | ||
/> | ||
</div> | ||
<Separator /> | ||
|
||
<div className="pt-16 grid gap-4 grid-cols-1 md:grid-cols-2 lg:grid-cols-7"> | ||
<Card className="col-span-4 md:col-span-3"> | ||
<CardHeader> | ||
<CardTitle>Teams</CardTitle> | ||
<CardDescription> | ||
This contributor is part of {contributorDetails?.teams.length}{" "} | ||
teams | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
{contributorDetails?.teams && ( | ||
<TeamCardList teamArray={contributorDetails?.teams} /> | ||
)} | ||
</CardContent> | ||
</Card> | ||
|
||
<Card className="col-span-4 md:col-span-3"> | ||
<CardHeader> | ||
<CardTitle>Repositories</CardTitle> | ||
<CardDescription> | ||
This contributor is part of{" "} | ||
{contributorDetails?.github_repositories.length} repositories | ||
</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
{contributorDetails?.github_repositories && ( | ||
<GithubRepoList | ||
githubRepos={contributorDetails?.github_repositories} | ||
/> | ||
)} | ||
</CardContent> | ||
</Card> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains 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 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
56 changes: 56 additions & 0 deletions
56
src/app/api/contributors/details/fetchContributorDetails.ts
This file contains 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,56 @@ | ||
import { GithubRepo, Team } from "@prisma/client"; | ||
import prisma from "db"; | ||
|
||
export type ContributorDetailsDto = { | ||
userName: string; | ||
teams: Team[]; | ||
github_repositories: GithubRepo[]; | ||
}; | ||
|
||
/** | ||
* Fetch contributor details by userName | ||
* Fetches the teams in which the username is a contributor (case insensitive) and the github repositories of those teams | ||
* @param {string} contributorUserName | ||
* @returns {Object} ContributorDetailsDto | ||
*/ | ||
export async function fetchContributorDetails( | ||
contributorUserName: string, | ||
): Promise<ContributorDetailsDto | null> { | ||
try { | ||
const foundContributorTeams = await prisma.team.findMany({ | ||
where: { | ||
ContributionCalculation: { | ||
some: { | ||
UserScore: { | ||
some: { | ||
username: { | ||
equals: contributorUserName, | ||
mode: "insensitive", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
const contributorTeams = foundContributorTeams.map((team) => team.name); | ||
const foundContributorRepositories = await prisma.githubRepo.findMany({ | ||
where: { | ||
Team: { | ||
name: { | ||
in: contributorTeams, | ||
}, | ||
}, | ||
}, | ||
}); | ||
const contributorDetailsDto: ContributorDetailsDto = { | ||
userName: contributorUserName, | ||
teams: foundContributorTeams, | ||
github_repositories: foundContributorRepositories, | ||
}; | ||
return contributorDetailsDto; | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
return null; | ||
} |
This file contains 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,17 @@ | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { fetchContributorDetails } from "./fetchContributorDetails"; | ||
|
||
export async function GET(req: NextRequest) { | ||
const contributorUserName = req.nextUrl.searchParams.get( | ||
"contributor_username", | ||
); | ||
if (contributorUserName) { | ||
const contributorDetails = | ||
await fetchContributorDetails(contributorUserName); | ||
return NextResponse.json({ | ||
success: true, | ||
contributorDetails: contributorDetails, | ||
}); | ||
} | ||
return NextResponse.json({ success: false, contributorDetails: null }); | ||
} |
This file contains 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 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 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 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,28 @@ | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
import { ScrollArea } from "./ui/scroll-area"; | ||
import { Team } from "@prisma/client"; | ||
|
||
interface TeamCardListProps { | ||
teamArray: Team[]; | ||
} | ||
|
||
export function TeamCardList({ teamArray }: TeamCardListProps) { | ||
return ( | ||
<ScrollArea className="h-72 rounded-md"> | ||
<div className="space-y-8"> | ||
{teamArray.map((team) => ( | ||
<div className="flex items-center"> | ||
<Avatar className="h-9 w-9"> | ||
<AvatarImage src="/avatars/01.png" alt="Avatar" /> | ||
<AvatarFallback>{team.name[0]}</AvatarFallback> | ||
</Avatar> | ||
<div className="ml-4 space-y-1"> | ||
<p className="text-sm font-medium leading-none">{team.name}</p> | ||
</div> | ||
<div className="ml-auto font-medium">Active</div> | ||
</div> | ||
))} | ||
</div> | ||
</ScrollArea> | ||
); | ||
} |