From eebf34d28bff125d1f1f2b6a727bb6036f26fb56 Mon Sep 17 00:00:00 2001 From: Arpit Gupta Date: Thu, 9 Apr 2026 20:28:18 +0530 Subject: [PATCH] refactor: use owner email from tasks response --- components/TasksPage/TasksList.tsx | 53 ++++-------------------------- lib/tasks/getTasks.ts | 3 +- 2 files changed, 8 insertions(+), 48 deletions(-) diff --git a/components/TasksPage/TasksList.tsx b/components/TasksPage/TasksList.tsx index 9bd21c38c..2165ed3f7 100644 --- a/components/TasksPage/TasksList.tsx +++ b/components/TasksPage/TasksList.tsx @@ -1,14 +1,8 @@ -import { Tables } from "@/types/database.types"; import { Task } from "@/lib/tasks/getTasks"; import TaskCard from "@/components/VercelChat/tools/tasks/TaskCard"; import TaskSkeleton from "./TaskSkeleton"; import TaskDetailsDialog from "@/components/VercelChat/dialogs/tasks/TaskDetailsDialog"; -import { useArtistProvider } from "@/providers/ArtistProvider"; import { useUserProvider } from "@/providers/UserProvder"; -import { useMemo } from "react"; -import { useQuery } from "@tanstack/react-query"; - -type AccountEmail = Tables<"account_emails">; interface TasksListProps { tasks: Task[]; @@ -18,45 +12,13 @@ interface TasksListProps { const TasksList: React.FC = ({ tasks, isLoading, isError }) => { const { userData } = useUserProvider(); - const { selectedArtist } = useArtistProvider(); - - // Extract unique account IDs from tasks - const accountIds = useMemo( - () => [...new Set(tasks.map(task => task.account_id))], - [tasks] - ); - - // Batch fetch emails for all task owners - const { data: accountEmails = [] } = useQuery({ - queryKey: ["task-owner-emails", accountIds], - queryFn: async () => { - if (accountIds.length === 0 || !userData) return []; - const params = new URLSearchParams(); - accountIds.forEach(id => params.append("accountIds", id)); - params.append("currentAccountId", userData.id); - if (selectedArtist) { - params.append("artistAccountId", selectedArtist.account_id); - } - const response = await fetch(`/api/account-emails?${params}`); - if (!response.ok) throw new Error("Failed to fetch emails"); - return response.json(); - }, - enabled: accountIds.length > 0 && !!userData, - }); - - // Create lookup map for O(1) email access - const emailByAccountId = useMemo(() => { - const map = new Map(); - accountEmails.forEach(ae => { - if (ae.account_id && ae.email) { - map.set(ae.account_id, ae.email); - } - }); - return map; - }, [accountEmails]); if (isError) { - return
Failed to load tasks
; + return ( +
+ Failed to load tasks +
+ ); } if (isLoading || !userData) { @@ -88,10 +50,7 @@ const TasksList: React.FC = ({ tasks, isLoading, isError }) => { index !== tasks.length - 1 ? "border-b border-border " : "" } > - + ))} diff --git a/lib/tasks/getTasks.ts b/lib/tasks/getTasks.ts index cbc6b3e28..de25477e1 100644 --- a/lib/tasks/getTasks.ts +++ b/lib/tasks/getTasks.ts @@ -7,6 +7,7 @@ type ScheduledAction = Tables<"scheduled_actions">; export type Task = ScheduledAction & { recent_runs?: TaskRunItem[]; upcoming?: string[]; + owner_email?: string | null; }; export interface GetTasksParams { @@ -27,7 +28,7 @@ export interface GetTasksResponse { */ export async function getTasks( accessToken: string, - params?: GetTasksParams + params?: GetTasksParams, ): Promise { try { const url = new URL(`${getClientApiBaseUrl()}/api/tasks`);