fix: fix build fail and eslint

This commit is contained in:
Sosokker 2024-11-04 19:08:00 +07:00
parent a440110098
commit 2ead19ec67
7 changed files with 79 additions and 25 deletions

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -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) => (
<div key={index} className="deal-item">
<p>Deal Amount: {deal.deal_amount}</p>
<p>Created Time: {new Date(deal.created_time).toUTCString()}</p>
<p>Investor ID: {deal.investor_id}</p>
</div>
))}
<div className="md:hidden">
<Image
src="/examples/dashboard-light.png"
@ -63,7 +118,7 @@ export default function Dashboard() {
</svg>
</CardHeader>
<CardContent>
<div className="text-2xl font-bold">${sumByKey(dealList, "deal_amount")}</div>
<div className="text-2xl font-bold">${totalDealAmount}</div>
{/* <p className="text-xs text-muted-foreground">
+20.1% from last month
</p> */}
@ -150,7 +205,7 @@ export default function Dashboard() {
<CardTitle>Overview</CardTitle>
</CardHeader>
<CardContent className="pl-2">
<Overview graphType={graphType} graphData={graphData} />
<Overview graphType={graphType} data={data} />
{/* tab to switch between line and bar graph */}
<Tabs defaultValue="line" className="space-y-4 ml-[50%] mt-2">
<TabsList>
@ -170,7 +225,7 @@ export default function Dashboard() {
<CardDescription>You made {dealList?.length || 0} sales this month.</CardDescription>
</CardHeader>
<CardContent>
<RecentFunds recentDealData={recentDealData}></RecentFunds>
<RecentFunds></RecentFunds>
</CardContent>
</Card>
</div>

View File

@ -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<TopProjectsProps> = ({ projects }) => {
<ProjectCard
name={project.project_name}
description={project.project_short_description}
imageUri={project.project_logo}
imageUri={project.card_image_url}
joinDate={new Date(project.published_time).toLocaleDateString()}
location={project.business[0]?.location || ""}
tags={project.project_tag.flatMap((item: { tag: { id: number; value: string }[] }) =>

View File

@ -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) => ({

View File

@ -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 (
<div className="space-y-8">