diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index eb7638b..4c777c3 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -11,16 +11,27 @@ import { getProjectByUserId } from "@/lib/data/projectQuery"; import { Loader } from "@/components/loading/loader"; import { getInvestmentByProjectsIds } from "@/lib/data/investmentQuery"; import { useQuery } from "@supabase-cache-helpers/postgrest-react-query"; -import { getLatestInvestment, overAllGraphData, Deal } from "../portfolio/[uid]/query"; +import { usePathname } from "next/navigation"; +import { overAllGraphData, Deal } from "../portfolio/[uid]/query"; +import { getUserProfile } from "@/lib/data/userQuery"; +import { Item } from "@radix-ui/react-navigation-menu"; export default function Dashboard() { - let supabase = createSupabaseClient(); + const supabase = createSupabaseClient(); + const pathname = usePathname(); const userId = useSession().session?.user.id; const [projects, setProjects] = useState< { id: number; project_name: string; business_id: { user_id: number }[]; dataroom_id: number }[] >([]); const [latestInvestment, setLatestInvestment] = useState< - { projectId: number; name: any; amount: number; date: Date; logo_url: string; status: string }[] + { + avatarUrl: string; + createdTime: Date; + dealAmount: number; + dealStatus: string; + investorId: string; + username: string; + }[] >([]); const [isSuccess, setIsSuccess] = useState(false); const [graphType, setGraphType] = useState("line"); @@ -34,36 +45,38 @@ export default function Dashboard() { ) ); useEffect(() => { - const fetchLatestInvestment = async () => { - const latest = await getLatestInvestment( - supabase, - investmentDetail?.data?.map((deal) => { - return { - project_id: deal.project_id, - deal_amount: deal.deal_amount, - created_time: deal.created_time, - }; - }) || [] - ); - const resolvedLatest = await Promise.all( - latest.map(async (investment) => ({ - ...investment, - logo_url: await investment.logo_url, - })) - ); - setLatestInvestment( - resolvedLatest.map((investment) => ({ - projectId: investment.projectId, - name: investment.name, - amount: investment.amount, - date: investment.date, - logo_url: investment.logo_url, - status: investmentDetail?.data?.find((deal) => deal.project_id === investment.projectId)?.deal_status.value, - })) - ); - // console.table(investmentDetail); + const setTopLatestInvestment = () => { + if (investmentDetail?.data) { + setLatestInvestment( + investmentDetail.data + .slice(0, 8) + .map((item) => { + // set the project according to current project id + if (item.project_id === currentProjectId) { + return { + avatarUrl: item.avatar_url, + createdTime: item.created_time, + dealAmount: item.deal_amount, + dealStatus: item.deal_status, + investorId: item.investor_id, + username: item.username, + }; + } + return undefined; + }) + .filter((item) => item !== undefined) as { + avatarUrl: string; + createdTime: Date; + dealAmount: number; + dealStatus: string; + investorId: string; + username: string; + }[] + ); + console.table(latestInvestment) + } }; - fetchLatestInvestment(); + setTopLatestInvestment(); }, [supabase, investmentDetail]); useEffect(() => { const fetchProjects = async () => { @@ -88,7 +101,7 @@ export default function Dashboard() { // console.table(latestInvestment); return ( - <> +
Recent Funds - { - if (item.projectId === currentProjectId) { - return { - name: item.name, - amount: item.amount, - avatar: item.logo_url, - date: item.date, - status: item.status, - }; - } - return undefined; - }) - .filter((item) => item !== undefined)} - /> + { + return { + name: item.username, + amount: item.dealAmount, + avatar: item.avatarUrl, + date: new Date(item.createdTime), + status: item.dealStatus, + profile_url: `/profile/${item.investorId}`, + }; + })} + />
@@ -289,6 +298,6 @@ export default function Dashboard() {
- + ); } diff --git a/src/app/dashboard/query.ts b/src/app/dashboard/query.ts index e69de29..8b13789 100644 --- a/src/app/dashboard/query.ts +++ b/src/app/dashboard/query.ts @@ -0,0 +1 @@ + diff --git a/src/app/portfolio/[uid]/query.ts b/src/app/portfolio/[uid]/query.ts index 47bb06f..aac9153 100644 --- a/src/app/portfolio/[uid]/query.ts +++ b/src/app/portfolio/[uid]/query.ts @@ -26,7 +26,7 @@ function getTotalInvestment(deals: { deal_amount: number }[]) { } async function getLatestInvestment( supabase: SupabaseClient, - deals: { project_id: number; deal_amount: number; created_time: Date }[] + deals: { project_id: number; deal_amount: number; created_time: Date;}[] ) { const llist = []; const count = 8; diff --git a/src/app/project/apply/page.tsx b/src/app/project/apply/page.tsx index 0509058..e5d184e 100644 --- a/src/app/project/apply/page.tsx +++ b/src/app/project/apply/page.tsx @@ -117,7 +117,7 @@ export default function ApplyProject() { confirmButtonColor: error == null ? "green" : "red", }).then((result) => { if (result.isConfirmed) { - // window.location.href = "/"; + window.location.href = "/"; } }); }; diff --git a/src/components/recent-funds.tsx b/src/components/recent-funds.tsx index 5902524..dd47e91 100644 --- a/src/components/recent-funds.tsx +++ b/src/components/recent-funds.tsx @@ -1,4 +1,5 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; +import Link from "next/link"; export type RecentDealData = { created_time: Date; @@ -11,42 +12,122 @@ export type RecentDealData = { }; interface RecentFundsProps { - data?: { name?: string; amount?: number; avatar?: string; date?: Date; logo_url?: string; status?: string }[]; + data?: { name?: string; amount?: number; avatar?: string; date?: Date; logo_url?: string; status?: string; profile_url?: string }[]; } export function RecentFunds(props: RecentFundsProps) { + const content = ( +
+ +
+ ) return (
{(props?.data || []).map((deal, index) => ( -
- - - {(deal.name ?? "").slice(0, 2)} - -
-

{deal.name}

-

{deal?.date?.toLocaleDateString()}

- {deal.status && ( -
- - - - -

- {deal?.status} -

+
+ {deal.profile_url ? ( + + + + {(deal.name ?? "").slice(0, 2)} + +
+

{deal.name}

+

{deal?.date?.toLocaleDateString()}

+ {deal.status && ( +
+ + + + +

+ {deal?.status} +

+
+ )}
- )} -
-
+${deal.amount}
+
+${deal.amount}
+ + ) : ( +
+ + + {(deal.name ?? "").slice(0, 2)} + +
+

{deal.name}

+

{deal?.date?.toLocaleDateString()}

+ {deal.status && ( +
+ + + + +

+ {deal?.status} +

+
+ )} +
+
+${deal.amount}
+
+ )}
))}
); + } diff --git a/src/lib/data/investmentQuery.ts b/src/lib/data/investmentQuery.ts index 9cae764..df9a944 100644 --- a/src/lib/data/investmentQuery.ts +++ b/src/lib/data/investmentQuery.ts @@ -16,14 +16,21 @@ export const getInvestmentByProjectsIds = (client: SupabaseClient, projectIds: s .select( ` id, - deal_status:deal_status_id(value), + ...deal_status_id( + deal_status:value + ), project_id, deal_amount, - investor:users_id(email), - created_time + created_time, + ...profiles ( + investor_id:id, + username, + avatar_url + ) ` ) - .in("project_id", projectIds); + .in("project_id", projectIds) + .order("created_time", { ascending: false }); }; export const getInvestmentByUserId = (client: SupabaseClient, userId: string) => {