working leantime widget 72
This commit is contained in:
parent
f3ead86bde
commit
bead369139
@ -169,14 +169,14 @@ export async function GET(request: NextRequest) {
|
||||
const taskEditorId = String(task.editorId).trim();
|
||||
const currentUserId = String(userId).trim();
|
||||
|
||||
// Check if the user is the editor or if editorId is empty (unassigned)
|
||||
const isEditor = taskEditorId === currentUserId || taskEditorId === '';
|
||||
|
||||
// Also check if the user is in the assignedTo array if it exists
|
||||
const isAssignedToUser = Array.isArray(task.assignedTo) &&
|
||||
task.assignedTo.some((id: any) => String(id).trim() === currentUserId);
|
||||
|
||||
return isEditor || isAssignedToUser;
|
||||
// Show tasks where:
|
||||
// 1. The user is the editor
|
||||
// 2. The task is unassigned (empty editorId)
|
||||
// 3. The user is in the assignedTo array
|
||||
return taskEditorId === currentUserId ||
|
||||
taskEditorId === '' ||
|
||||
(Array.isArray(task.assignedTo) &&
|
||||
task.assignedTo.some((id: any) => String(id).trim() === currentUserId));
|
||||
})
|
||||
.map((task: any) => ({
|
||||
id: task.id.toString(),
|
||||
|
||||
@ -89,15 +89,37 @@ export function Flow() {
|
||||
.filter((task: Task) =>
|
||||
task.headline &&
|
||||
typeof task.headline === 'string' &&
|
||||
task.status !== 5 // Not done
|
||||
task.status !== 3 // Not completed
|
||||
)
|
||||
.sort((a: Task, b: Task) => {
|
||||
// First sort by status (new tasks first)
|
||||
// Define priority order for tasks
|
||||
const priorityOrder = [
|
||||
'Mettre en ligne site wix SLM-SA',
|
||||
'Bi-Dimension Investment',
|
||||
'Draft Pax Index Mvt 4 CARE',
|
||||
'Finaliser Pax Index Mvt 5 Data Intelligence Governance DIG',
|
||||
'Continuous Improving Cycle : Risk Monitoring + Model Assessments + Learning Machine',
|
||||
'Rediger pétition ODD18 et intégration au site CLM',
|
||||
'complete ressources background and quote'
|
||||
];
|
||||
|
||||
const aIndex = priorityOrder.indexOf(a.headline);
|
||||
const bIndex = priorityOrder.indexOf(b.headline);
|
||||
|
||||
// If both tasks are in the priority list, sort by their position
|
||||
if (aIndex !== -1 && bIndex !== -1) {
|
||||
return aIndex - bIndex;
|
||||
}
|
||||
|
||||
// If only one task is in the priority list, it comes first
|
||||
if (aIndex !== -1) return -1;
|
||||
if (bIndex !== -1) return 1;
|
||||
|
||||
// For tasks not in the priority list, sort by status and date
|
||||
if (a.status !== b.status) {
|
||||
return a.status - b.status;
|
||||
}
|
||||
|
||||
// Then sort by due date
|
||||
const dateA = a.dateToFinish && a.dateToFinish !== '0000-00-00 00:00:00'
|
||||
? new Date(a.dateToFinish).getTime()
|
||||
: Number.MAX_SAFE_INTEGER;
|
||||
@ -109,7 +131,7 @@ export function Flow() {
|
||||
});
|
||||
|
||||
console.log('Filtered and sorted tasks:', sortedTasks);
|
||||
setTasks(sortedTasks.slice(0, 6));
|
||||
setTasks(sortedTasks); // Remove the slice(0, 6) to show all tasks
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
console.error('Error fetching tasks:', err);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user