diff --git a/src/app/api/dealApi.ts b/src/app/api/dealApi.ts index 7cdaa0d..cd56925 100644 --- a/src/app/api/dealApi.ts +++ b/src/app/api/dealApi.ts @@ -5,7 +5,6 @@ export type Deal = { created_time: Date; investor_id: string; }; -const supabase = createSupabaseClient(); export async function getDealList(userId: string | undefined) { if (!userId) { diff --git a/src/app/dashboard/hook.ts b/src/app/dashboard/hook.ts index 676d249..0b2cdb8 100644 --- a/src/app/dashboard/hook.ts +++ b/src/app/dashboard/hook.ts @@ -10,7 +10,7 @@ export function useDealList() { const fetchDealList = async () => { // set the state to the deal list of current business user setDealList(await getDealList(await getCurrentUserID())); - } + }; useEffect(() => { fetchDealList(); @@ -28,7 +28,7 @@ export function useGraphData() { if (dealList) { setGraphData(convertToGraphData(dealList)); } - } + }; useEffect(() => { fetchGraphData(); @@ -43,11 +43,11 @@ export function useRecentDealData() { const fetchRecentDealData = async () => { // set the state to the deal list of current business user setRecentDealData(await getRecentDealData(await getCurrentUserID())); - } + }; useEffect(() => { fetchRecentDealData(); }, []); return recentDealData; -} \ No newline at end of file +} diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index e59b7f3..d506482 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -6,18 +6,73 @@ import { Overview } from "@/components/ui/overview"; import { RecentFunds } from "@/components/recent-funds"; import { useState } from "react"; -import { useDealList, useGraphData, useRecentDealData } from "./hook"; -import { sumByKey } from "@/lib/utils"; +import { useDealList } from "./hook"; + +const data = [ + { + name: "Jan", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Feb", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Mar", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Apr", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "May", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Jun", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Jul", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Aug", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Sep", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Oct", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Nov", + value: Math.floor(Math.random() * 5000) + 1000, + }, + { + name: "Dec", + value: Math.floor(Math.random() * 5000) + 1000, + }, +]; export default function Dashboard() { const [graphType, setGraphType] = useState("line"); - const graphData = useGraphData(); const dealList = useDealList(); - // #TODO dependency injection refactor + define default value inside function (and not here) - const recentDealData = useRecentDealData() || []; + const totalDealAmount = dealList?.reduce((sum, deal) => sum + deal.deal_amount, 0) || 0; return ( <> + {dealList?.map((deal, index) => ( +
+

Deal Amount: {deal.deal_amount}

+

Created Time: {new Date(deal.created_time).toUTCString()}

+

Investor ID: {deal.investor_id}

+
+ ))}
-
${sumByKey(dealList, "deal_amount")}
+
${totalDealAmount}
{/*

+20.1% from last month

*/} @@ -150,7 +205,7 @@ export default function Dashboard() { Overview - + {/* tab to switch between line and bar graph */} @@ -170,7 +225,7 @@ export default function Dashboard() { You made {dealList?.length || 0} sales this month. - +
diff --git a/src/app/overview/page.tsx b/src/app/overview/page.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/page.tsx b/src/app/page.tsx index 5f586f6..19cc657 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -13,7 +13,7 @@ interface Project { id: number; project_name: string; project_short_description: string; - project_logo: string; + card_image_url: string; published_time: string; business: { location: string }[]; project_tag: { tag: { id: number; value: string }[] }[]; @@ -38,7 +38,7 @@ const TopProjects: FC = ({ projects }) => { diff --git a/src/app/portfolio/[uid]/hook.ts b/src/app/portfolio/[uid]/hook.ts index 7ce663c..4d59dfa 100644 --- a/src/app/portfolio/[uid]/hook.ts +++ b/src/app/portfolio/[uid]/hook.ts @@ -115,16 +115,6 @@ function overAllGraphData(deals: Deal[]): GraphData[] { return acc; } -interface Deal { - created_time: string | number | Date; - deal_amount: any; -} - -interface GraphData { - name: string; - value: number; -} - function fourYearGraphData(deals: Deal[]): GraphData[] { const currentYear = new Date().getFullYear(); const acc: GraphData[] = Array.from({ length: 4 }, (_, i) => ({ diff --git a/src/components/recent-funds.tsx b/src/components/recent-funds.tsx index 432c4b0..5a1c71b 100644 --- a/src/components/recent-funds.tsx +++ b/src/components/recent-funds.tsx @@ -1,8 +1,18 @@ import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; +export type RecentDealData = { + created_time: Date; + deal_amount: number; + investor_id: string; + username: string; + avatar_url?: string; + // email: string; +}; + interface RecentFundsProps { data?: { name?: string; amount?: number; avatar?: string; date?: Date }[]; } + export function RecentFunds(props: RecentFundsProps) { return (