working leantime widget 77
This commit is contained in:
parent
12695cc58f
commit
3443805c7b
@ -160,8 +160,8 @@ export async function GET(request: NextRequest) {
|
|||||||
status: task.status
|
status: task.status
|
||||||
});
|
});
|
||||||
|
|
||||||
// Skip completed tasks (status 3)
|
// Skip completed tasks (status 5)
|
||||||
if (task.status === 3) {
|
if (task.status === 5) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,8 +173,10 @@ export async function GET(request: NextRequest) {
|
|||||||
// 1. The user is the editor
|
// 1. The user is the editor
|
||||||
// 2. The task is unassigned (empty editorId)
|
// 2. The task is unassigned (empty editorId)
|
||||||
// 3. The user is in the assignedTo array
|
// 3. The user is in the assignedTo array
|
||||||
|
// 4. The task's userId matches the current user
|
||||||
return taskEditorId === currentUserId ||
|
return taskEditorId === currentUserId ||
|
||||||
taskEditorId === '' ||
|
taskEditorId === '' ||
|
||||||
|
task.userId === userId ||
|
||||||
(Array.isArray(task.assignedTo) &&
|
(Array.isArray(task.assignedTo) &&
|
||||||
task.assignedTo.some((id: any) => String(id).trim() === currentUserId));
|
task.assignedTo.some((id: any) => String(id).trim() === currentUserId));
|
||||||
})
|
})
|
||||||
|
|||||||
@ -10,13 +10,17 @@ interface Task {
|
|||||||
id: number;
|
id: number;
|
||||||
headline: string;
|
headline: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
dateToFinish: string;
|
||||||
|
date: string;
|
||||||
|
projectId: number;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
status: number;
|
status: number;
|
||||||
dateToFinish: string;
|
editorId?: string;
|
||||||
editorId: string;
|
editorFirstname?: string;
|
||||||
editorFirstname: string | null;
|
editorLastname?: string;
|
||||||
editorLastname: string | null;
|
authorFirstname: string;
|
||||||
userId: number;
|
authorLastname: string;
|
||||||
|
milestoneHeadline?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ProjectSummary {
|
interface ProjectSummary {
|
||||||
@ -70,39 +74,34 @@ export function Flow() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchTasks = async (isRefresh = false) => {
|
const fetchTasks = async () => {
|
||||||
try {
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
try {
|
||||||
const response = await fetch('/api/leantime/tasks');
|
const response = await fetch('/api/leantime/tasks');
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Failed to fetch tasks');
|
||||||
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
// Filter and sort tasks
|
if (!Array.isArray(data)) {
|
||||||
const sortedTasks = data.tasks
|
console.warn('No tasks found in response', data as unknown);
|
||||||
.filter((task: Task) =>
|
setTasks([]);
|
||||||
task.headline &&
|
return;
|
||||||
typeof task.headline === 'string' &&
|
|
||||||
task.status !== 5 && // Not done
|
|
||||||
(task.editorId === '2' || task.userId === 2) // Tasks assigned to or owned by user 2
|
|
||||||
)
|
|
||||||
.sort((a: Task, b: Task) => {
|
|
||||||
// Get valid dates for comparison
|
|
||||||
const getValidDate = (task: Task) => {
|
|
||||||
if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') {
|
|
||||||
return new Date(task.dateToFinish).getTime();
|
|
||||||
}
|
}
|
||||||
return Number.MAX_SAFE_INTEGER;
|
|
||||||
};
|
|
||||||
|
|
||||||
const dateA = getValidDate(a);
|
// Sort tasks by due date (oldest first)
|
||||||
const dateB = getValidDate(b);
|
const sortedTasks = data
|
||||||
|
.sort((a: Task, b: Task) => {
|
||||||
|
const dateA = a.dateToFinish ? new Date(a.dateToFinish).getTime() : new Date(a.date).getTime();
|
||||||
|
const dateB = b.dateToFinish ? new Date(b.dateToFinish).getTime() : new Date(b.date).getTime();
|
||||||
return dateA - dateB;
|
return dateA - dateB;
|
||||||
});
|
})
|
||||||
|
.slice(0, 6); // Limit to 6 tasks
|
||||||
|
|
||||||
console.log('Filtered and sorted tasks:', sortedTasks);
|
console.log('Sorted and filtered tasks:', sortedTasks);
|
||||||
setTasks(sortedTasks);
|
setTasks(sortedTasks);
|
||||||
setError(null);
|
} catch (error) {
|
||||||
} catch (err) {
|
console.error('Error fetching tasks:', error);
|
||||||
console.error('Error fetching tasks:', err);
|
|
||||||
setError('Failed to fetch tasks');
|
setError('Failed to fetch tasks');
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@ -120,7 +119,7 @@ export function Flow() {
|
|||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => fetchTasks(true)}
|
onClick={() => fetchTasks()}
|
||||||
className="h-8 w-8 p-0 hover:bg-gray-100/50 rounded-full"
|
className="h-8 w-8 p-0 hover:bg-gray-100/50 rounded-full"
|
||||||
>
|
>
|
||||||
<RefreshCw className="h-4 w-4" />
|
<RefreshCw className="h-4 w-4" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user