working leantime widget 76
This commit is contained in:
parent
1187ceb65b
commit
12695cc58f
@ -16,6 +16,7 @@ interface Task {
|
||||
editorId: string;
|
||||
editorFirstname: string | null;
|
||||
editorLastname: string | null;
|
||||
userId: number;
|
||||
}
|
||||
|
||||
interface ProjectSummary {
|
||||
@ -71,27 +72,17 @@ export function Flow() {
|
||||
|
||||
const fetchTasks = async (isRefresh = false) => {
|
||||
try {
|
||||
if (isRefresh) setRefreshing(true);
|
||||
|
||||
setLoading(true);
|
||||
const response = await fetch('/api/leantime/tasks');
|
||||
if (!response.ok) throw new Error('Failed to fetch tasks');
|
||||
|
||||
const data = await response.json();
|
||||
console.log('Tasks API response:', data);
|
||||
|
||||
if (!data.tasks || !Array.isArray(data.tasks)) {
|
||||
console.warn('No tasks found in response:', data);
|
||||
setTasks([]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Sort tasks by status and date
|
||||
// Filter and sort tasks
|
||||
const sortedTasks = data.tasks
|
||||
.filter((task: Task) =>
|
||||
task.headline &&
|
||||
typeof task.headline === 'string' &&
|
||||
task.status !== 5 && // Not done
|
||||
task.editorId === '2' // Only tasks assigned to user 2
|
||||
(task.editorId === '2' || task.userId === 2) // Tasks assigned to or owned by user 2
|
||||
)
|
||||
.sort((a: Task, b: Task) => {
|
||||
// Get valid dates for comparison
|
||||
@ -99,19 +90,12 @@ export function Flow() {
|
||||
if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') {
|
||||
return new Date(task.dateToFinish).getTime();
|
||||
}
|
||||
return Number.MAX_SAFE_INTEGER; // Put tasks without due date at the end
|
||||
return Number.MAX_SAFE_INTEGER;
|
||||
};
|
||||
|
||||
const dateA = getValidDate(a);
|
||||
const dateB = getValidDate(b);
|
||||
|
||||
// Sort by date first
|
||||
if (dateA !== dateB) {
|
||||
return dateA - dateB;
|
||||
}
|
||||
|
||||
// If dates are equal, sort by status
|
||||
return a.status - b.status;
|
||||
return dateA - dateB;
|
||||
});
|
||||
|
||||
console.log('Filtered and sorted tasks:', sortedTasks);
|
||||
@ -122,7 +106,6 @@ export function Flow() {
|
||||
setError('Failed to fetch tasks');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
setRefreshing(false);
|
||||
}
|
||||
};
|
||||
|
||||
@ -131,14 +114,14 @@ export function Flow() {
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Card className="transition-transform duration-500 ease-in-out transform hover:scale-105 bg-white/50 backdrop-blur-sm">
|
||||
<Card className="transition-transform duration-500 ease-in-out transform hover:scale-105 bg-white/80 backdrop-blur-sm">
|
||||
<CardHeader className="flex flex-row items-center justify-between pb-2">
|
||||
<CardTitle className="text-xl font-bold">Flow</CardTitle>
|
||||
<CardTitle className="text-2xl font-bold">Flow</CardTitle>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
onClick={() => fetchTasks(true)}
|
||||
className="h-8 w-8 p-0 hover:bg-gray-100 rounded-full"
|
||||
className="h-8 w-8 p-0 hover:bg-gray-100/50 rounded-full"
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" />
|
||||
</Button>
|
||||
@ -157,28 +140,25 @@ export function Flow() {
|
||||
{tasks.map((task) => (
|
||||
<div
|
||||
key={task.id}
|
||||
className="p-4 rounded-lg border border-gray-100 hover:border-gray-200 transition-all duration-200 bg-white/70"
|
||||
className="p-4 rounded-2xl bg-white/90 shadow-sm hover:shadow-md transition-all duration-200"
|
||||
>
|
||||
<div className="space-y-2.5">
|
||||
<div className="space-y-2">
|
||||
<a
|
||||
href={`https://agilite.slm-lab.net/tickets/showTicket/${task.id}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-blue-600 hover:text-blue-700 font-medium block text-base"
|
||||
className="text-blue-500 hover:text-blue-600 font-medium block text-lg"
|
||||
>
|
||||
{task.headline}
|
||||
</a>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center text-gray-500">
|
||||
<Folder className="h-4 w-4 mr-1.5 opacity-70" />
|
||||
<span className="text-sm font-medium">{task.projectName}</span>
|
||||
</div>
|
||||
<Badge
|
||||
variant="secondary"
|
||||
className="text-xs font-medium bg-gray-100 text-gray-600 hover:bg-gray-200"
|
||||
>
|
||||
Unknown
|
||||
</Badge>
|
||||
<div className="flex items-center text-gray-500">
|
||||
<Folder className="h-4 w-4 mr-2 opacity-70" />
|
||||
<span className="text-sm">{task.projectName}</span>
|
||||
{task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00' && (
|
||||
<span className="ml-4 text-sm">
|
||||
Due: {new Date(task.dateToFinish).toLocaleDateString()}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user