feat: add investment query functionality to dashboard

This commit is contained in:
THIS ONE IS A LITTLE BIT TRICKY KRUB 2024-11-07 16:20:26 +07:00
parent a1158907fb
commit fa554bfb51
3 changed files with 14 additions and 0 deletions

View File

@ -9,6 +9,8 @@ import { createSupabaseClient } from "@/lib/supabase/clientComponentClient";
import useSession from "@/lib/supabase/useSession";
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";
const data = [
{
@ -69,6 +71,14 @@ export default function Dashboard() {
>([]);
const [isSuccess, setIsSuccess] = useState(false);
const [graphType, setGraphType] = useState("line");
const investmentDetail = useQuery(
getInvestmentByProjectsIds(
supabase,
projects.map((item) => {
return item.id.toString();
})
)
);
useEffect(() => {
const fetchProjects = async () => {
if (userId) {

View File

@ -10,6 +10,10 @@ export const getInvestmentCountsByProjectsIds = (client: SupabaseClient, project
.in("project_id", projectIds);
};
export const getInvestmentByProjectsIds = (client: SupabaseClient, projectIds: string[]) => {
return client.from("investment_deal").select("*").in("project_id", projectIds);
};
export const getInvestmentByUserId = (client: SupabaseClient, userId: string) => {
return client
.from("investment_deal")