Spaces:
Build error
Build error
File size: 7,992 Bytes
17cf14d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 | 'use client'
import { useState } from 'react'
interface ChecklistItemProps {
id: string
itemName: string
status: string
owner: { id: string; name: string } | null
phase: string
onUpdate: () => void
}
export function InteractiveChecklistItem({
id,
itemName,
status,
owner,
phase,
onUpdate,
}: ChecklistItemProps) {
const [isEditing, setIsEditing] = useState(false)
const [editName, setEditName] = useState(itemName)
const [isUpdating, setIsUpdating] = useState(false)
const handleStatusChange = async (newStatus: string) => {
setIsUpdating(true)
try {
const response = await fetch(`/api/checklist/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ status: newStatus }),
})
if (response.ok) {
onUpdate()
}
} catch (error) {
console.error('Failed to update status:', error)
} finally {
setIsUpdating(false)
}
}
const handleNameUpdate = async () => {
if (editName.trim() === itemName) {
setIsEditing(false)
return
}
setIsUpdating(true)
try {
const response = await fetch(`/api/checklist/${id}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ itemName: editName.trim() }),
})
if (response.ok) {
setIsEditing(false)
onUpdate()
}
} catch (error) {
console.error('Failed to update name:', error)
} finally {
setIsUpdating(false)
}
}
const handleDelete = async () => {
if (!confirm('Delete this checklist item?')) return
setIsUpdating(true)
try {
const response = await fetch(`/api/checklist/${id}`, {
method: 'DELETE',
})
if (response.ok) {
onUpdate()
}
} catch (error) {
console.error('Failed to delete item:', error)
} finally {
setIsUpdating(false)
}
}
const statusOptions = ['Not Started', 'In Progress', 'Blocked', 'Complete']
return (
<div
className={`flex items-center gap-4 p-4 rounded-xl transition-all ${
status === 'Complete'
? 'bg-gradient-to-r from-green-50 to-emerald-50 border border-green-200'
: status === 'In Progress'
? 'bg-gradient-to-r from-blue-50 to-indigo-50 border border-blue-200'
: status === 'Blocked'
? 'bg-gradient-to-r from-red-50 to-pink-50 border border-red-200'
: 'bg-white border border-gray-200'
} ${isUpdating ? 'opacity-50' : ''}`}
>
{/* Status Dropdown */}
<select
value={status}
onChange={(e) => handleStatusChange(e.target.value)}
disabled={isUpdating}
className="px-3 py-2 rounded-lg border-2 border-gray-300 focus:border-blue-500 focus:outline-none bg-white text-sm font-medium cursor-pointer hover:border-blue-400 transition-all"
>
{statusOptions.map((s) => (
<option key={s} value={s}>
{s === 'Not Started' ? '⚪' : s === 'In Progress' ? '🔵' : s === 'Blocked' ? '🔴' : '✅'} {s}
</option>
))}
</select>
{/* Item Name - Editable */}
<div className="flex-1">
{isEditing ? (
<div className="flex items-center gap-2">
<input
type="text"
value={editName}
onChange={(e) => setEditName(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') handleNameUpdate()
if (e.key === 'Escape') {
setEditName(itemName)
setIsEditing(false)
}
}}
className="flex-1 px-3 py-2 rounded-lg border-2 border-blue-500 focus:outline-none"
autoFocus
/>
<button
onClick={handleNameUpdate}
className="px-3 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 text-sm"
>
Save
</button>
<button
onClick={() => {
setEditName(itemName)
setIsEditing(false)
}}
className="px-3 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 text-sm"
>
Cancel
</button>
</div>
) : (
<div
className="flex items-center gap-2 cursor-pointer group"
onClick={() => setIsEditing(true)}
>
<span className={`${status === 'Complete' ? 'line-through text-gray-500' : 'text-gray-900'}`}>
{itemName}
</span>
<span className="opacity-0 group-hover:opacity-100 text-xs text-gray-400">✏️ Click to edit</span>
</div>
)}
</div>
{/* Owner */}
<div className="text-sm text-gray-600 min-w-[120px]">
<span className="text-xs text-gray-500">Owner:</span> {owner?.name || 'Unassigned'}
</div>
{/* Delete Button */}
<button
onClick={handleDelete}
disabled={isUpdating}
className="p-2 text-red-500 hover:bg-red-50 rounded-lg transition-all"
title="Delete item"
>
🗑️
</button>
</div>
)
}
interface AddChecklistItemProps {
rfpId: string
phase: string
onAdd: () => void
}
export function AddChecklistItem({ rfpId, phase, onAdd }: AddChecklistItemProps) {
const [isAdding, setIsAdding] = useState(false)
const [newItemName, setNewItemName] = useState('')
const [isSubmitting, setIsSubmitting] = useState(false)
const handleAdd = async () => {
if (!newItemName.trim()) return
setIsSubmitting(true)
try {
const response = await fetch('/api/checklist', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
rfpId,
itemName: newItemName.trim(),
phase,
status: 'Not Started',
}),
})
if (response.ok) {
setNewItemName('')
setIsAdding(false)
onAdd()
}
} catch (error) {
console.error('Failed to add item:', error)
} finally {
setIsSubmitting(false)
}
}
if (!isAdding) {
return (
<button
onClick={() => setIsAdding(true)}
className="w-full p-3 border-2 border-dashed border-gray-300 rounded-xl text-gray-600 hover:border-blue-400 hover:text-blue-600 hover:bg-blue-50/50 transition-all text-sm font-medium"
>
+ Add Custom Item to {phase}
</button>
)
}
return (
<div className="flex items-center gap-2 p-3 border-2 border-blue-300 rounded-xl bg-blue-50/50">
<input
type="text"
value={newItemName}
onChange={(e) => setNewItemName(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') handleAdd()
if (e.key === 'Escape') {
setNewItemName('')
setIsAdding(false)
}
}}
placeholder="Enter checklist item name..."
className="flex-1 px-3 py-2 rounded-lg border-2 border-gray-300 focus:border-blue-500 focus:outline-none"
autoFocus
/>
<button
onClick={handleAdd}
disabled={isSubmitting || !newItemName.trim()}
className="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 disabled:opacity-50 text-sm font-medium"
>
Add
</button>
<button
onClick={() => {
setNewItemName('')
setIsAdding(false)
}}
className="px-4 py-2 bg-gray-200 text-gray-700 rounded-lg hover:bg-gray-300 text-sm"
>
Cancel
</button>
</div>
)
}
|