Skip to content

Commit eebf34d

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

2 files changed

Lines changed: 8 additions & 48 deletions

File tree

components/TasksPage/TasksList.tsx

Lines changed: 6 additions & 47 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,45 +12,13 @@ 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) {
59-
return <div className="text-sm text-red-600 dark:text-red-400">Failed to load tasks</div>;
17+
return (
18+
<div className="text-sm text-red-600 dark:text-red-400">
19+
Failed to load tasks
20+
</div>
21+
);
6022
}
6123

6224
if (isLoading || !userData) {
@@ -88,10 +50,7 @@ const TasksList: React.FC<TasksListProps> = ({ tasks, isLoading, isError }) => {
8850
index !== tasks.length - 1 ? "border-b border-border " : ""
8951
}
9052
>
91-
<TaskCard
92-
task={task}
93-
ownerEmail={emailByAccountId.get(task.account_id)}
94-
/>
53+
<TaskCard task={task} ownerEmail={task.owner_email ?? undefined} />
9554
</div>
9655
</TaskDetailsDialog>
9756
))}

lib/tasks/getTasks.ts

Lines changed: 2 additions & 1 deletion
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 {
@@ -27,7 +28,7 @@ export interface GetTasksResponse {
2728
*/
2829
export async function getTasks(
2930
accessToken: string,
30-
params?: GetTasksParams
31+
params?: GetTasksParams,
3132
): Promise<Task[]> {
3233
try {
3334
const url = new URL(`${getClientApiBaseUrl()}/api/tasks`);

0 commit comments

Comments
 (0)