Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 | 'use client' import { useCallback, useState } from 'react' import { PRACTICE_TYPES, type PracticeTypeId } from '@/constants/practiceTypes' import { css } from '../../../styled-system/css' import { PhotoUploadZone } from './PhotoUploadZone' interface OfflineSessionModalProps { /** Player ID to create session for */ playerId: string /** Whether modal is open */ isOpen: boolean /** Close modal callback */ onClose: () => void /** Callback when session is successfully created */ onComplete?: (sessionId: string) => void } /** * Modal for logging offline practice sessions with photos. * * Allows selecting: * - Date of practice (defaults to today) * - Practice types performed (abacus, visualize, linear) * - Photos of student work (multiple) */ export function OfflineSessionModal({ playerId, isOpen, onClose, onComplete, }: OfflineSessionModalProps) { // Form state const [date, setDate] = useState(() => { const today = new Date() return today.toISOString().split('T')[0] // YYYY-MM-DD format }) const [selectedTypes, setSelectedTypes] = useState<Set<PracticeTypeId>>(new Set(['abacus'])) const [photos, setPhotos] = useState<File[]>([]) // Submission state const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState<string | null>(null) const toggleType = useCallback((type: PracticeTypeId) => { setSelectedTypes((prev) => { const next = new Set(prev) if (next.has(type)) { next.delete(type) } else { next.add(type) } return next }) }, []) const handleSubmit = useCallback(async () => { if (selectedTypes.size === 0) { setError('Please select at least one practice type') return } setIsSubmitting(true) setError(null) try { const formData = new FormData() formData.append('date', date) formData.append('practiceTypes', JSON.stringify(Array.from(selectedTypes))) for (const photo of photos) { formData.append('photos', photo) } const response = await fetch(`/api/curriculum/${playerId}/offline-sessions`, { method: 'POST', body: formData, }) if (!response.ok) { const data = await response.json() throw new Error(data.error || 'Failed to create session') } const result = await response.json() onComplete?.(result.sessionId) onClose() // Reset form setPhotos([]) setSelectedTypes(new Set(['abacus'])) setDate(new Date().toISOString().split('T')[0]) } catch (err) { setError(err instanceof Error ? err.message : 'Failed to create session') } finally { setIsSubmitting(false) } }, [playerId, date, selectedTypes, photos, onComplete, onClose]) const handleClose = useCallback(() => { if (!isSubmitting) { onClose() } }, [isSubmitting, onClose]) if (!isOpen) return null return ( <div data-component="offline-session-modal" className={css({ position: 'fixed', inset: 0, bg: 'rgba(0, 0, 0, 0.5)', display: 'flex', alignItems: 'center', justifyContent: 'center', zIndex: 10000, p: 4, })} onClick={handleClose} > <div className={css({ bg: 'white', borderRadius: 'xl', maxW: '500px', w: '100%', maxH: '90vh', overflowY: 'auto', boxShadow: 'xl', })} onClick={(e) => e.stopPropagation()} > {/* Header */} <div className={css({ p: 5, borderBottom: '1px solid', borderColor: 'gray.200', display: 'flex', justifyContent: 'space-between', alignItems: 'center', })} > <h2 className={css({ fontSize: 'xl', fontWeight: 'bold', color: 'gray.800', })} > Log Offline Practice </h2> <button type="button" onClick={handleClose} disabled={isSubmitting} className={css({ fontSize: '2xl', color: 'gray.400', cursor: 'pointer', _hover: { color: 'gray.600' }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} > × </button> </div> {/* Content */} <div className={css({ p: 5 })}> {/* Date picker */} <div className={css({ mb: 5 })}> <label className={css({ display: 'block', fontSize: 'sm', fontWeight: 'medium', color: 'gray.700', mb: 2, })} > When did the practice happen? </label> <input type="date" value={date} onChange={(e) => setDate(e.target.value)} max={new Date().toISOString().split('T')[0]} disabled={isSubmitting} className={css({ w: '100%', px: 3, py: 2, border: '1px solid', borderColor: 'gray.300', borderRadius: 'md', fontSize: 'md', _focus: { outline: 'none', borderColor: 'blue.500', boxShadow: '0 0 0 1px var(--colors-blue-500)', }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} /> </div> {/* Practice types */} <div className={css({ mb: 5 })}> <label className={css({ display: 'block', fontSize: 'sm', fontWeight: 'medium', color: 'gray.700', mb: 2, })} > What types of practice were done? </label> <div className={css({ display: 'flex', flexDirection: 'column', gap: 2, })} > {PRACTICE_TYPES.map((type) => { const isSelected = selectedTypes.has(type.id) return ( <button key={type.id} type="button" onClick={() => toggleType(type.id)} disabled={isSubmitting} className={css({ display: 'flex', alignItems: 'center', gap: 3, p: 3, border: '2px solid', borderColor: isSelected ? 'blue.500' : 'gray.200', borderRadius: 'lg', bg: isSelected ? 'blue.50' : 'white', cursor: 'pointer', textAlign: 'left', transition: 'all 0.15s', _hover: { borderColor: isSelected ? 'blue.600' : 'gray.300', }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} > {/* Checkbox indicator */} <div className={css({ width: '20px', height: '20px', borderRadius: 'sm', border: '2px solid', borderColor: isSelected ? 'blue.500' : 'gray.300', bg: isSelected ? 'blue.500' : 'white', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'white', fontSize: 'xs', fontWeight: 'bold', flexShrink: 0, })} > {isSelected && '✓'} </div> {/* Icon */} <span className={css({ fontSize: 'xl', flexShrink: 0 })}>{type.icon}</span> {/* Label */} <div> <div className={css({ fontWeight: 'medium', color: 'gray.800', })} > {type.label} </div> <div className={css({ fontSize: 'sm', color: 'gray.500', })} > {type.description} </div> </div> </button> ) })} </div> </div> {/* Photo upload */} <div className={css({ mb: 5 })}> <label className={css({ display: 'block', fontSize: 'sm', fontWeight: 'medium', color: 'gray.700', mb: 2, })} > Photos of student work{' '} <span className={css({ color: 'gray.400', fontWeight: 'normal' })}>(optional)</span> </label> <PhotoUploadZone photos={photos} onPhotosChange={setPhotos} disabled={isSubmitting} /> </div> {/* Error message */} {error && ( <div className={css({ mb: 4, p: 3, bg: 'red.50', border: '1px solid', borderColor: 'red.200', borderRadius: 'md', color: 'red.700', fontSize: 'sm', })} > {error} </div> )} {/* Actions */} <div className={css({ display: 'flex', gap: 3 })}> <button type="button" onClick={handleClose} disabled={isSubmitting} className={css({ flex: 1, py: 3, border: '1px solid', borderColor: 'gray.300', borderRadius: 'md', color: 'gray.700', fontWeight: 'medium', cursor: 'pointer', _hover: { bg: 'gray.50' }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} > Cancel </button> <button type="button" onClick={handleSubmit} disabled={isSubmitting || selectedTypes.size === 0} className={css({ flex: 1, py: 3, bg: 'blue.500', color: 'white', borderRadius: 'md', fontWeight: 'medium', cursor: 'pointer', _hover: { bg: 'blue.600' }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} > {isSubmitting ? 'Saving...' : 'Log Practice'} </button> </div> </div> </div> </div> ) } |