mirror of
https://github.com/Sosokker/B2D-Ventures.git
synced 2025-12-20 14:34:05 +01:00
refactor: remove unuse variable and import missing module
This commit is contained in:
parent
bf46b2f765
commit
2221b5be69
@ -11,20 +11,22 @@ export async function getDealList() {
|
|||||||
const supabase = createSupabaseClient();
|
const supabase = createSupabaseClient();
|
||||||
// get id of investor who invests in the business
|
// get id of investor who invests in the business
|
||||||
const { data: dealData, error: dealError } = await supabase
|
const { data: dealData, error: dealError } = await supabase
|
||||||
.from('business')
|
.from("business")
|
||||||
.select(`
|
.select(
|
||||||
|
`
|
||||||
project (
|
project (
|
||||||
investment_deal (
|
investment_deal (
|
||||||
investor_id
|
investor_id
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
`)
|
`
|
||||||
.eq('user_id', await getCurrentUserID())
|
)
|
||||||
|
.eq("user_id", await getCurrentUserID())
|
||||||
.single();
|
.single();
|
||||||
|
|
||||||
if (dealError) {
|
if (dealError) {
|
||||||
alert(JSON.stringify(dealError));
|
alert(JSON.stringify(dealError));
|
||||||
console.error('Error fetching deal list:', dealError);
|
console.error("Error fetching deal list:", dealError);
|
||||||
return; // Exit on error
|
return; // Exit on error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,27 +35,29 @@ export async function getDealList() {
|
|||||||
return; // Exit if there's no data
|
return; // Exit if there's no data
|
||||||
}
|
}
|
||||||
|
|
||||||
const investorIdList = dealData.project[0].investment_deal.map(deal => deal.investor_id);
|
const investorIdList = dealData.project[0].investment_deal.map((deal) => deal.investor_id);
|
||||||
|
|
||||||
// get investment_deal data then sort by created_time
|
// get investment_deal data then sort by created_time
|
||||||
const { data: sortedDealData, error: sortedDealDataError } = await supabase
|
const { data: sortedDealData, error: sortedDealDataError } = await supabase
|
||||||
.from("investment_deal")
|
.from("investment_deal")
|
||||||
.select(`
|
.select(
|
||||||
|
`
|
||||||
deal_amount,
|
deal_amount,
|
||||||
created_time,
|
created_time,
|
||||||
investor_id
|
investor_id
|
||||||
`)
|
`
|
||||||
.in('investor_id', investorIdList)
|
)
|
||||||
.order('created_time', { ascending: false })
|
.in("investor_id", investorIdList)
|
||||||
|
.order("created_time", { ascending: false });
|
||||||
|
|
||||||
if (sortedDealDataError) {
|
if (sortedDealDataError) {
|
||||||
alert(JSON.stringify(sortedDealDataError));
|
alert(JSON.stringify(sortedDealDataError));
|
||||||
console.error('Error sorting deal list:', sortedDealDataError);
|
console.error("Error sorting deal list:", sortedDealDataError);
|
||||||
return; // Exit on error
|
return; // Exit on error
|
||||||
}
|
}
|
||||||
|
|
||||||
return sortedDealData;
|
return sortedDealData;
|
||||||
};
|
}
|
||||||
|
|
||||||
// #TODO fix query to be non unique
|
// #TODO fix query to be non unique
|
||||||
export async function getRecentDealData() {
|
export async function getRecentDealData() {
|
||||||
@ -68,15 +72,17 @@ export async function getRecentDealData() {
|
|||||||
|
|
||||||
// get 5 most recent investor
|
// get 5 most recent investor
|
||||||
const recentDealList = dealList.slice(0, 5);
|
const recentDealList = dealList.slice(0, 5);
|
||||||
const recentInvestorIdList = recentDealList.map(deal => deal.investor_id);
|
const recentInvestorIdList = recentDealList.map((deal) => deal.investor_id);
|
||||||
|
|
||||||
const { data: recentUserData, error: recentUserError } = await supabase
|
const { data: recentUserData, error: recentUserError } = await supabase
|
||||||
.from("profiles")
|
.from("profiles")
|
||||||
.select(`
|
.select(
|
||||||
|
`
|
||||||
username,
|
username,
|
||||||
avatar_url
|
avatar_url
|
||||||
`)
|
`
|
||||||
.in('id', recentInvestorIdList);
|
)
|
||||||
|
.in("id", recentInvestorIdList);
|
||||||
|
|
||||||
if (!recentUserData) {
|
if (!recentUserData) {
|
||||||
alert("No recent users available");
|
alert("No recent users available");
|
||||||
@ -101,17 +107,22 @@ export async function getRecentDealData() {
|
|||||||
// #TODO move to util
|
// #TODO move to util
|
||||||
export function convertToGraphData(deals: Deal[]): Record<string, number> {
|
export function convertToGraphData(deals: Deal[]): Record<string, number> {
|
||||||
// group by year & month
|
// group by year & month
|
||||||
let graphData = deals.reduce((acc, deal) => {
|
let graphData = deals.reduce(
|
||||||
const monthYear = new Date(deal.created_time).toISOString().slice(0, 7); // E.g., '2024-10'
|
(acc, deal) => {
|
||||||
acc[monthYear] = (acc[monthYear] || 0) + deal.deal_amount; // Sum the deal_amount
|
const monthYear = new Date(deal.created_time).toISOString().slice(0, 7); // E.g., '2024-10'
|
||||||
return acc;
|
acc[monthYear] = (acc[monthYear] || 0) + deal.deal_amount; // Sum the deal_amount
|
||||||
}, {} as Record<string, number>); // Change type to Record<string, number>
|
return acc;
|
||||||
|
},
|
||||||
|
{} as Record<string, number>
|
||||||
|
); // Change type to Record<string, number>
|
||||||
|
|
||||||
// Sort keys in ascending order
|
// Sort keys in ascending order
|
||||||
const sortedKeys = Object.keys(graphData).sort((a, b) => (a > b ? 1 : -1));
|
const sortedKeys = Object.keys(graphData).sort((a, b) => (a > b ? 1 : -1));
|
||||||
|
|
||||||
// Create a sorted graph data object
|
// Create a sorted graph data object
|
||||||
const sortedGraphData: Record<string, number> = {};
|
const sortedGraphData: Record<string, number> = {};
|
||||||
sortedKeys.forEach((key) => {sortedGraphData[key] = graphData[key]});
|
sortedKeys.forEach((key) => {
|
||||||
|
sortedGraphData[key] = graphData[key];
|
||||||
|
});
|
||||||
return sortedGraphData;
|
return sortedGraphData;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import React from "react";
|
||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import { Montserrat } from "next/font/google";
|
import { Montserrat } from "next/font/google";
|
||||||
import { ThemeProvider } from "@/components/theme-provider";
|
import { ThemeProvider } from "@/components/theme-provider";
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Input } from "@/components/ui/input";
|
import { Input } from "@/components/ui/input";
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
type IconProps = React.HTMLAttributes<SVGElement>;
|
|
||||||
|
|
||||||
export const Icons = {
|
export const Icons = {
|
||||||
userLogo: (props: IconProps) => (
|
userLogo: () => (
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
width="24"
|
width="24"
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import {
|
|||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
DropdownMenuLabel,
|
|
||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu";
|
} from "@/components/ui/dropdown-menu";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user