Skip to content

Commit 59302c6

Browse files
refactor: use owner email from tasks response
1 parent ee82aa4 commit 59302c6

2 files changed

Lines changed: 2 additions & 43 deletions

File tree

components/TasksPage/TasksList.tsx

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
import { Tables } from "@/types/database.types";
21
import { Task } from "@/lib/tasks/getTasks";
32
import TaskCard from "@/components/VercelChat/tools/tasks/TaskCard";
43
import TaskSkeleton from "./TaskSkeleton";
54
import TaskDetailsDialog from "@/components/VercelChat/dialogs/tasks/TaskDetailsDialog";
6-
import { useArtistProvider } from "@/providers/ArtistProvider";
75
import { useUserProvider } from "@/providers/UserProvder";
8-
import { useMemo } from "react";
9-
import { useQuery } from "@tanstack/react-query";
10-
11-
type AccountEmail = Tables<"account_emails">;
126

137
interface TasksListProps {
148
tasks: Task[];
@@ -18,42 +12,6 @@ interface TasksListProps {
1812

1913
const TasksList: React.FC<TasksListProps> = ({ tasks, isLoading, isError }) => {
2014
const { userData } = useUserProvider();
21-
const { selectedArtist } = useArtistProvider();
22-
23-
// Extract unique account IDs from tasks
24-
const accountIds = useMemo(
25-
() => [...new Set(tasks.map(task => task.account_id))],
26-
[tasks]
27-
);
28-
29-
// Batch fetch emails for all task owners
30-
const { data: accountEmails = [] } = useQuery<AccountEmail[]>({
31-
queryKey: ["task-owner-emails", accountIds],
32-
queryFn: async () => {
33-
if (accountIds.length === 0 || !userData) return [];
34-
const params = new URLSearchParams();
35-
accountIds.forEach(id => params.append("accountIds", id));
36-
params.append("currentAccountId", userData.id);
37-
if (selectedArtist) {
38-
params.append("artistAccountId", selectedArtist.account_id);
39-
}
40-
const response = await fetch(`/api/account-emails?${params}`);
41-
if (!response.ok) throw new Error("Failed to fetch emails");
42-
return response.json();
43-
},
44-
enabled: accountIds.length > 0 && !!userData,
45-
});
46-
47-
// Create lookup map for O(1) email access
48-
const emailByAccountId = useMemo(() => {
49-
const map = new Map<string, string>();
50-
accountEmails.forEach(ae => {
51-
if (ae.account_id && ae.email) {
52-
map.set(ae.account_id, ae.email);
53-
}
54-
});
55-
return map;
56-
}, [accountEmails]);
5715

5816
if (isError) {
5917
return <div className="text-sm text-red-600 dark:text-red-400">Failed to load tasks</div>;
@@ -90,7 +48,7 @@ const TasksList: React.FC<TasksListProps> = ({ tasks, isLoading, isError }) => {
9048
>
9149
<TaskCard
9250
task={task}
93-
ownerEmail={emailByAccountId.get(task.account_id)}
51+
ownerEmail={task.owner_email ?? undefined}
9452
/>
9553
</div>
9654
</TaskDetailsDialog>

lib/tasks/getTasks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ type ScheduledAction = Tables<"scheduled_actions">;
77
export type Task = ScheduledAction & {
88
recent_runs?: TaskRunItem[];
99
upcoming?: string[];
10+
owner_email?: string | null;
1011
};
1112

1213
export interface GetTasksParams {

0 commit comments

Comments
 (0)