feat: update Portfolio and DataTable components to enhance deal data handling and improve rendering

This commit is contained in:
THIS ONE IS A LITTLE BIT TRICKY KRUB 2024-11-12 22:24:35 +07:00
parent ef6e8cf6c0
commit 00c4080b21
5 changed files with 66 additions and 22 deletions

View File

@ -57,6 +57,7 @@ export default async function Portfolio({ params }: { params: { uid: string } })
if (investorDealError) { if (investorDealError) {
console.error(investorDealError); console.error(investorDealError);
} }
const { data: localUser, error: localUserError } = await supabase.auth.getUser(); const { data: localUser, error: localUserError } = await supabase.auth.getUser();
if (localUserError) { if (localUserError) {
console.error("Error while fetching user" + error); console.error("Error while fetching user" + error);
@ -82,6 +83,7 @@ export default async function Portfolio({ params }: { params: { uid: string } })
deals.map((deal) => ({ deals.map((deal) => ({
...deal, ...deal,
status: deal.deal_status, status: deal.deal_status,
project_id: deal.project_id,
})) }))
) )
).map(async (deal) => ({ ).map(async (deal) => ({
@ -96,6 +98,7 @@ export default async function Portfolio({ params }: { params: { uid: string } })
? await Promise.all(deals.map(async (item) => await getBusinessTypeName(supabase, item.project_id))) ? await Promise.all(deals.map(async (item) => await getBusinessTypeName(supabase, item.project_id)))
: []; : [];
const countedBusinessType = countValues(businessType.filter((item) => item !== null)); const countedBusinessType = countValues(businessType.filter((item) => item !== null));
console.table(deals);
return ( return (
<div className="container max-w-screen-xl"> <div className="container max-w-screen-xl">
<div className="text-center py-4"> <div className="text-center py-4">
@ -244,17 +247,17 @@ export default async function Portfolio({ params }: { params: { uid: string } })
<CardContent className="mt-5 grid grid-flow-row-dense"> <CardContent className="mt-5 grid grid-flow-row-dense">
<RecentFunds data={latestDeals} /> <RecentFunds data={latestDeals} />
<div className="mt-5 flex justify-center"> <div className="mt-5 flex justify-center">
{/* {latestDeals.length} */} {deals?.length}
{deals && deals.length ? ( {deals && deals.length > 5 ? (
<Modal <Modal
data={latestDeals.map((item) => { data={deals.map((item) => {
return { return {
date: item.date, date: item.created_time,
name: item.name, name: item.username,
amount: item.amount, amount: item.deal_amount,
status: item.status, status: item.deal_status,
logoURL: item.logo_url, logoURL: Array.isArray(item.avatar_url) ? item.avatar_url[0] : item.avatar_url,
profileURL: `deals/${item.projectId}` profileURL: `deals/${item.project_id}` as string,
}; };
})} })}
/> />

View File

@ -26,7 +26,7 @@ function getTotalInvestment(deals: { deal_amount: number }[]) {
} }
async function getLatestInvestment( async function getLatestInvestment(
supabase: SupabaseClient, supabase: SupabaseClient,
deals: { project_id: number; deal_amount: number; created_time: Date; status: string}[] deals: { project_id: number; deal_amount: number; created_time: Date; status: string }[]
) { ) {
const llist = []; const llist = [];
const count = 5; const count = 5;

View File

@ -25,6 +25,8 @@ import {
} from "@/components/ui/dropdown-menu"; } from "@/components/ui/dropdown-menu";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
import Link from "next/link";
export type ModalProps = { export type ModalProps = {
date: Date; date: Date;
@ -66,7 +68,25 @@ export const columns: ColumnDef<ModalProps>[] = [
</Button> </Button>
); );
}, },
cell: ({ row }) => <div className="lowercase">{row.getValue("name")}</div>, cell: ({ row }) => (
<div className="flex items-center gap-2">
<Link href={`/deals/${(row.getValue("profileURL") as string).split("/").pop()}`} className="flex items-center">
<Avatar className="h-9 w-9">
<AvatarImage src={row.getValue("logoURL")} />
<AvatarFallback>{(row.getValue("name") as string).slice(0, 2)}</AvatarFallback>
</Avatar>
<span className="ml-2">{row.getValue("name")}</span>
</Link>
</div>
),
},
{
accessorKey: "date",
header: () => <div className="text-left">Date</div>,
cell: ({ row }) => {
const formatted = new Date(row.getValue("date")).toUTCString();
return <div className=" font-medium">{formatted}</div>;
},
}, },
{ {
accessorKey: "status", accessorKey: "status",
@ -101,16 +121,19 @@ export const columns: ColumnDef<ModalProps>[] = [
? "text-green-500" ? "text-green-500"
: "text-yellow-500" : "text-yellow-500"
}`} }`}
> ></p>
</p>
<div className={`capitalize ${ <div
row.getValue("status") === "In Progress" className={`capitalize ${
? "text-sky-500" row.getValue("status") === "In Progress"
: row.getValue("status") === "Completed" ? "text-sky-500"
? "text-green-500" : row.getValue("status") === "Completed"
: "text-yellow-500" ? "text-green-500"
}`}>{row.getValue("status")}</div> : "text-yellow-500"
}`}
>
{row.getValue("status")}
</div>
</div> </div>
), ),
}, },
@ -129,6 +152,18 @@ export const columns: ColumnDef<ModalProps>[] = [
return <div className="text-right font-medium">{formatted}</div>; return <div className="text-right font-medium">{formatted}</div>;
}, },
}, },
{
accessorKey: "logoURL",
id: "logoURL",
header: () => null,
cell: () => null,
},
{
accessorKey: "profileURL",
id: "profileURL",
header: () => null,
cell: () => null,
},
]; ];
export function DataTable({ data }: { data: ModalProps[] }) { export function DataTable({ data }: { data: ModalProps[] }) {
@ -151,7 +186,10 @@ export function DataTable({ data }: { data: ModalProps[] }) {
state: { state: {
sorting, sorting,
columnFilters, columnFilters,
columnVisibility, columnVisibility: {
profileURL: false,
logoURL: false,
},
rowSelection, rowSelection,
}, },
}); });

View File

@ -20,7 +20,7 @@ export function Modal({ data }: { data: ModalProps[] }) {
<DialogTrigger asChild> <DialogTrigger asChild>
<Button>View More</Button> <Button>View More</Button>
</DialogTrigger> </DialogTrigger>
<DialogContent> <DialogContent className="max-w-screen-lg ">
<DataTable data={data} /> <DataTable data={data} />
</DialogContent> </DialogContent>
</Dialog> </Dialog>

View File

@ -63,6 +63,9 @@ export function getInvestorDeal(client: SupabaseClient, userId: string) {
deal_status:value deal_status:value
), ),
project_id, project_id,
...project_id (
project_name
),
deal_amount, deal_amount,
created_time, created_time,
...profiles ( ...profiles (