Skip to content

Commit 59f651a

Browse files
committed
fix: applies fix on kanban view
1 parent 4973330 commit 59f651a

5 files changed

Lines changed: 60 additions & 18 deletions

File tree

src/components/Projects/KanbanBoardView.tsx

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface KanbanBoardProps {
2222
initialColleagues?: DigitalColleague[]
2323
// Task handlers
2424
onAddTask?: (newTask: Omit<Task, 'id' | 'createdAt' | 'updatedAt'>) => void
25-
onUpdateTask?: (taskId: string, updates: Partial<Task>) => void
25+
onUpdateTask?: (taskId: string, updates: Partial<Task>) => Promise<Task>
2626
onDeleteTask?: (taskId: string) => void
2727
onTaskClick?: (task: Task) => void
2828
// Epic handlers
@@ -63,7 +63,7 @@ export const KanbanBoardView: React.FC<KanbanBoardProps> = ({
6363
const selectedEpics = epics.filter((epic) => true).map((epic) => epic.id)
6464
const selectedSprint = sprints.find((sprint) => sprint.isSelected)
6565

66-
// selectedEpics.push(0)
66+
selectedEpics.push(0)
6767

6868
useEffect(() => {
6969
setTasks(initialTasks)
@@ -120,11 +120,12 @@ export const KanbanBoardView: React.FC<KanbanBoardProps> = ({
120120

121121
// Filter tasks by selected epics and sprint
122122
const filteredTasks = tasks.filter((task) => {
123-
const isEpicSelected = selectedEpics.includes(extractId(task.epic)) || extractId(task.epic) < 0
124-
if (!selectedSprint) return isEpicSelected
125-
if (selectedSprint.name === 'all-tasks') return isEpicSelected
126-
if (selectedSprint.name === 'backlog') return isEpicSelected && !extractId(task.sprint)
127-
return isEpicSelected && extractId(task.sprint) === extractId(selectedSprint)
123+
// const isEpicSelected = selectedEpics.includes(extractId(task.epic)) || extractId(task.epic) < 0
124+
// if (!selectedSprint) return isEpicSelected
125+
// if (selectedSprint.name === 'all-tasks') return isEpicSelected
126+
// if (selectedSprint.name === 'backlog') return isEpicSelected && !extractId(task.sprint)
127+
// return isEpicSelected && extractId(task.sprint) === extractId(selectedSprint)
128+
return true
128129
})
129130

130131
const getTasksByStatus = (status: Task['status']) => {
@@ -171,7 +172,7 @@ export const KanbanBoardView: React.FC<KanbanBoardProps> = ({
171172
prev.map((task) => (task.id === Number(taskId) ? { ...task, ...updates } : task)),
172173
)
173174
if (onUpdateTask) {
174-
await onUpdateTask(taskId, updates)
175+
return await onUpdateTask(taskId, updates)
175176
}
176177
const task = tasks.find((task) => task.id === Number(taskId))
177178
if (!task) {
@@ -246,6 +247,8 @@ export const KanbanBoardView: React.FC<KanbanBoardProps> = ({
246247
const columnTasks = getTasksByStatus(column.status)
247248
const tasksByEpic = getTasksByEpic(columnTasks)
248249

250+
// console.log('col', col)
251+
249252
return (
250253
<KanbanColumn
251254
key={column.id}
@@ -256,6 +259,17 @@ export const KanbanBoardView: React.FC<KanbanBoardProps> = ({
256259
isCompact={column.status === 'done'}
257260
height={calculatedHeight}
258261
>
262+
{tasksByEpic['no-epic'].map((task) => {
263+
return (
264+
<TaskCard
265+
epic={null}
266+
task={task}
267+
onDragStart={handleDragStart}
268+
onTaskClick={handleTaskClick}
269+
isCompact={column.status === 'done'}
270+
/>
271+
)
272+
})}
259273
{selectedEpics.map((epicId) => {
260274
const epic = epics.find((e) => e.id === epicId)
261275
const epicTasks = tasksByEpic[epicId] || []

src/components/Projects/TaskCard.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React from 'react'
22
import { Card } from '@/components/ui/card'
3-
import { User, AlertCircle, Bug, Zap, BookOpen } from 'lucide-react'
3+
import { User, AlertCircle, Bug, Zap, BookOpen, Calendar } from 'lucide-react'
44
import { Task, Epic } from '../Foundary/types'
55

66
interface TaskCardProps {
77
task: Task
8-
epic: Epic
8+
epic: Epic | null
99
onDragStart: (task: Task) => void
1010
onTaskClick: (task: Task) => void
1111
isCompact?: boolean
@@ -132,10 +132,10 @@ export const TaskCard: React.FC<TaskCardProps> = ({
132132
<User className="h-4 w-4" />
133133
<span>{(task.assignee as any)?.value?.name}</span>
134134
</div>
135-
{/* <div className="flex items-center gap-1">
135+
<div className="flex items-center gap-1">
136136
<Calendar className="h-4 w-4" />
137-
<span>{task.createdAt.toLocaleDateString()}</span>
138-
</div> */}
137+
<span>{new Date(task.createdAt).toLocaleDateString()}</span>
138+
</div>
139139
</div>
140140
</Card>
141141
)

src/components/Projects/TaskDetailsModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export const TaskDetailsModal: React.FC<TaskDetailsModalProps> = ({
7272
// Reset to idle after showing success
7373
setTimeout(() => setUpdateState('idle'), 1500)
7474
} catch (error) {
75+
console.log('error', error)
7576
setUpdateState('error')
7677
// Reset to idle after showing error
7778
setTimeout(() => setUpdateState('idle'), 3000)

src/components/Projects/TaskSidebar.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { useCallback, useEffect, useRef, useState } from 'react'
22
import { Avatar, AvatarFallback } from '@/components/ui/avatar'
33
import { Label } from '@/components/ui/label'
44
import { Button } from '@/components/ui/button'
@@ -138,6 +138,28 @@ export const TaskSidebar: React.FC<TaskSidebarProps> = ({
138138
deleteState = 'idle',
139139
teamMembers,
140140
}) => {
141+
const [storyPoints, setStoryPoints] = useState(task.storyPoints)
142+
const debounceTimeoutRef = useRef<NodeJS.Timeout | null>(null)
143+
144+
// Debounced version of onUpdateTask for story points
145+
const debouncedUpdateTask = useCallback(
146+
(fieldName: string, value: string) => {
147+
if (debounceTimeoutRef.current) {
148+
clearTimeout(debounceTimeoutRef.current)
149+
}
150+
151+
debounceTimeoutRef.current = setTimeout(() => {
152+
onUpdateTask(fieldName, value)
153+
}, 500) // 500ms delay
154+
},
155+
[onUpdateTask],
156+
)
157+
158+
useEffect(() => {
159+
// setStoryPoints(task.storyPoints)
160+
debouncedUpdateTask('storyPoints', storyPoints?.toString() || '1')
161+
}, [storyPoints])
162+
141163
const getInitials = (name: string) => {
142164
return name
143165
.split(' ')
@@ -275,8 +297,13 @@ export const TaskSidebar: React.FC<TaskSidebarProps> = ({
275297
type="number"
276298
min="1"
277299
max="100"
278-
value={task.storyPoints || 1}
279-
onChange={(e) => onUpdateTask('points', e.target.value)}
300+
value={storyPoints || 1}
301+
onChange={(e) => {
302+
const val = Number(e.target.value)
303+
if (val < 1) setStoryPoints(1)
304+
else if (val > 100) setStoryPoints(100)
305+
else setStoryPoints(val)
306+
}}
280307
className="w-full h-8 px-2 text-xs border border-border rounded-md focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent bg-background text-foreground disabled:opacity-50 disabled:cursor-not-allowed"
281308
disabled={isUpdating}
282309
/>

src/utils/extract-id.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const extractId = (field: any): number => {
2-
if (!field) return -1
2+
if (!field) return 0
33
if (typeof field === 'number') return field
44
if (typeof field === 'object' && field && 'id' in field) return field.id
5-
return -1
5+
return 0
66
}

0 commit comments

Comments
 (0)