-
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.
Payment DB model and fetching (#143)
* Adds payment address api * Adds fetching current registered payment for project * Create onboarding flow * Fix lint issues * Added sliders * Lint issues * Remove table header * Add migrations for tables * Update accrding to PR comments * lint --------- Co-authored-by: Alec <alecerasmus2@gmail.com>
- Loading branch information
1 parent
36f2846
commit 0835464
Showing
15 changed files
with
578 additions
and
19 deletions.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
prisma/migrations/20240506143734_add_payment_address_tables/migration.sql
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,29 @@ | ||
-- CreateTable | ||
CREATE TABLE "PaymentAddress" ( | ||
"id" TEXT NOT NULL, | ||
"chain_id" VARCHAR(255) NOT NULL, | ||
"team_id" TEXT NOT NULL, | ||
"wallet_address" VARCHAR(255) NOT NULL, | ||
"created_at" TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "PaymentAddress_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "PaymentRecipient" ( | ||
"id" TEXT NOT NULL, | ||
"wallet_address" VARCHAR(255) NOT NULL, | ||
"payment_percentage" DOUBLE PRECISION NOT NULL, | ||
"payment_address_id" TEXT NOT NULL, | ||
|
||
CONSTRAINT "PaymentRecipient_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "PaymentAddress_team_id_key" ON "PaymentAddress"("team_id"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "PaymentAddress" ADD CONSTRAINT "PaymentAddress_team_id_fkey" FOREIGN KEY ("team_id") REFERENCES "Team"("id") ON DELETE CASCADE ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "PaymentRecipient" ADD CONSTRAINT "PaymentRecipient_payment_address_id_fkey" FOREIGN KEY ("payment_address_id") REFERENCES "PaymentAddress"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
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
29 changes: 24 additions & 5 deletions
29
src/app/(dashboard)/projects/[projectId]/payments/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 |
---|---|---|
@@ -1,20 +1,39 @@ | ||
import PaymentsOnboarding from "@/components/onboarding/onboardingTutorial"; | ||
"use client"; | ||
|
||
import { PaymentAddressDto } from "@/app/api/payments/service/paymentAddress"; | ||
import PaymentsOnboarding from "@/components/payments/paymentsOnboarding"; | ||
import axios from "axios"; | ||
import { useState } from "react"; | ||
|
||
interface PageProps { | ||
params: { projectId: string }; | ||
} | ||
|
||
export default function ProjectPaymentsPage({ params }: PageProps) { | ||
const teamId = params.projectId; | ||
const projectId = params.projectId; | ||
const breadcrumbItems = [ | ||
{ title: "Projects", link: "/projects" }, | ||
{ title: "Project details", link: `/projects/${teamId}` }, | ||
{ title: "Project Payments", link: `/projects/${teamId}/payments` }, | ||
{ title: "Project details", link: `/projects/${projectId}` }, | ||
{ title: "Project Payments", link: `/projects/${projectId}/payments` }, | ||
]; | ||
const [projectPaymentAddress, setProjectPaymentAddress] = useState< | ||
PaymentAddressDto | undefined | ||
>(); | ||
|
||
const handleFetchProjectPaymentAddress = async () => { | ||
const { data } = await axios.get("/api/payments?team_id=" + projectId); | ||
if (data.success && data.paymentAddress) { | ||
setProjectPaymentAddress(data.paymentAddress); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<PaymentsOnboarding></PaymentsOnboarding> | ||
{projectPaymentAddress != null ? ( | ||
<>WIP: Payment coming soon</> | ||
) : ( | ||
<PaymentsOnboarding projectId={projectId}></PaymentsOnboarding> | ||
)} | ||
</> | ||
); | ||
} |
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,17 @@ | ||
import { getServerSession } from "next-auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { options } from "../../auth/[...nextauth]/options"; | ||
import { fetchUserPaymentContributorsByTeam } from "../fetchUserContributors"; | ||
|
||
export async function GET(req: NextRequest) { | ||
const teamId = req.nextUrl.searchParams.get("team_id"); | ||
const session = await getServerSession(options); | ||
if (session?.userId && teamId) { | ||
const contributorsArray = await fetchUserPaymentContributorsByTeam(teamId); | ||
return NextResponse.json({ | ||
success: true, | ||
contributors: contributorsArray, | ||
}); | ||
} | ||
return NextResponse.json({ success: false, gitRepos: [] }); | ||
} |
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,21 @@ | ||
import { getServerSession } from "next-auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { options } from "../auth/[...nextauth]/options"; | ||
import { fetchTeamPaymentAddresses } from "./service/paymentAddress"; | ||
|
||
export async function GET(req: NextRequest) { | ||
const session = await getServerSession(options); | ||
const teamId = req.nextUrl.searchParams.get("team_id"); | ||
if (session?.userId && teamId) { | ||
const paymentAddress = await fetchTeamPaymentAddresses(teamId); | ||
return NextResponse.json({ | ||
success: true, | ||
paymentAddress: paymentAddress, | ||
}); | ||
} else { | ||
return NextResponse.json({ | ||
success: false, | ||
paymentAddress: [], | ||
}); | ||
} | ||
} |
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,44 @@ | ||
import prisma from "db"; | ||
|
||
export type PaymentAddressDto = { | ||
id: string; | ||
chain_id: string; | ||
team_id: string; | ||
wallet_address: string; | ||
created_at: Date; | ||
payment_receipents: PaymentRecipientDto[]; | ||
}; | ||
|
||
export type PaymentRecipientDto = { | ||
id: string; | ||
wallet_address: string; | ||
payment_percentage: number; | ||
}; | ||
|
||
export async function fetchTeamPaymentAddresses( | ||
teamId: string, | ||
): Promise<PaymentAddressDto | undefined> { | ||
try { | ||
const foundPaymentAddresses = await prisma.paymentAddress.findUnique({ | ||
where: { | ||
team_id: teamId, | ||
}, | ||
}); | ||
if (!foundPaymentAddresses) { | ||
return; | ||
} else { | ||
const paymentRecipients = await prisma.paymentRecipient.findMany({ | ||
where: { | ||
payment_address_id: foundPaymentAddresses.id, | ||
}, | ||
}); | ||
return { | ||
...foundPaymentAddresses, | ||
payment_receipents: paymentRecipients ? paymentRecipients : [], | ||
}; | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
return; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/components/payments/contributors/contributorsColumns.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,70 @@ | ||
"use client"; | ||
|
||
import { ColumnDef } from "@tanstack/react-table"; | ||
import { ContributorDto } from "@/app/api/contributors/fetchUserContributors"; | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
import PaymentSlider from "./paymentSlider"; | ||
|
||
export const ProjectContributorsColumns: ColumnDef<ContributorDto>[] = [ | ||
{ | ||
id: "avatar", | ||
cell: ({ row }) => { | ||
const contributor = row.original; | ||
return ( | ||
<div> | ||
<Avatar className="h-8 w-8"> | ||
<AvatarImage | ||
src={`https://github.com/${contributor.userName}.png?size=100`} | ||
alt={contributor.userName} | ||
/> | ||
<AvatarFallback>{contributor.userName[0]}</AvatarFallback> | ||
</Avatar> | ||
</div> | ||
); | ||
}, | ||
}, | ||
{ | ||
accessorKey: "userName", | ||
header: () => <></>, | ||
}, | ||
{ | ||
accessorKey: "contributionScorePercentage", | ||
header: () => { | ||
return <></>; | ||
}, | ||
cell: ({ row }) => { | ||
const contributor = row.original; | ||
return ( | ||
<div className="text-xl font-bold text-left pl-4"> | ||
{contributor.contributionScorePercentage.toFixed(2) + "%"} | ||
</div> | ||
); | ||
}, | ||
}, | ||
{ | ||
accessorKey: "contributionScore", | ||
header: () => { | ||
return <></>; | ||
}, | ||
cell: ({ row }) => { | ||
const contributor = row.original; | ||
return ( | ||
<div className="text-xl font-bold text-left pl-14"> | ||
{contributor.contributionScore.toFixed(2)} | ||
</div> | ||
); | ||
}, | ||
}, | ||
{ | ||
id: "actions", | ||
cell: ({ row }) => { | ||
return ( | ||
<div className="flex "> | ||
<PaymentSlider | ||
onChange={() => console.log("I change")} | ||
></PaymentSlider> | ||
</div> | ||
); | ||
}, | ||
}, | ||
]; |
Oops, something went wrong.