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 | 'use client' import * as Dialog from '@radix-ui/react-dialog' import { useCallback, useState } from 'react' import { useTheme } from '@/contexts/ThemeContext' import { Z_INDEX } from '@/constants/zIndex' import { css } from '../../../styled-system/css' interface AddStudentByFamilyCodeModalProps { isOpen: boolean onClose: () => void classroomId: string } interface PlayerPreview { id: string name: string emoji: string color: string } /** * Modal for teachers to add a student to their classroom using a family code * * Flow: * 1. Teacher enters family code * 2. System looks up student and creates enrollment request * 3. Parent receives notification to approve */ export function AddStudentByFamilyCodeModal({ isOpen, onClose, classroomId, }: AddStudentByFamilyCodeModalProps) { const { resolvedTheme } = useTheme() const isDark = resolvedTheme === 'dark' const [familyCode, setFamilyCode] = useState('') const [isSubmitting, setIsSubmitting] = useState(false) const [error, setError] = useState<string | null>(null) const [success, setSuccess] = useState(false) const [playerPreview, setPlayerPreview] = useState<PlayerPreview | null>(null) const handleSubmit = useCallback(async () => { if (!familyCode.trim()) { setError('Please enter a family code') return } setIsSubmitting(true) setError(null) try { const response = await fetch(`/api/classrooms/${classroomId}/enroll-by-family-code`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ familyCode: familyCode.trim() }), }) const data = await response.json() if (!data.success) { setError(data.error || 'Failed to add student') return } setPlayerPreview(data.player) setSuccess(true) } catch (err) { setError('Failed to add student. Please try again.') } finally { setIsSubmitting(false) } }, [familyCode, classroomId]) const handleClose = useCallback(() => { setFamilyCode('') setError(null) setSuccess(false) setPlayerPreview(null) onClose() }, [onClose]) return ( <Dialog.Root open={isOpen} onOpenChange={(open) => !open && handleClose()}> <Dialog.Portal> <Dialog.Overlay className={css({ position: 'fixed', inset: 0, backgroundColor: 'rgba(0, 0, 0, 0.5)', backdropFilter: 'blur(4px)', zIndex: Z_INDEX.MODAL, })} /> <Dialog.Content data-component="add-student-by-family-code-modal" className={css({ position: 'fixed', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', backgroundColor: isDark ? 'gray.800' : 'white', borderRadius: '16px', padding: '24px', width: 'calc(100% - 2rem)', maxWidth: '400px', boxShadow: '0 20px 50px -12px rgba(0, 0, 0, 0.4)', zIndex: Z_INDEX.MODAL + 1, outline: 'none', })} > {success && playerPreview ? ( /* Success state */ <> <div className={css({ textAlign: 'center', marginBottom: '24px', })} > <div className={css({ width: '64px', height: '64px', borderRadius: '50%', display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: '2rem', margin: '0 auto 16px', })} style={{ backgroundColor: playerPreview.color }} > {playerPreview.emoji} </div> <Dialog.Title className={css({ fontSize: '1.25rem', fontWeight: 'bold', color: isDark ? 'white' : 'gray.900', marginBottom: '8px', })} > Enrollment Request Sent! </Dialog.Title> <Dialog.Description className={css({ fontSize: '0.9375rem', color: isDark ? 'gray.400' : 'gray.600', })} > <strong>{playerPreview.name}</strong> will be added to your classroom once their parent approves the request. </Dialog.Description> </div> <button type="button" onClick={handleClose} data-action="close-success" className={css({ width: '100%', padding: '12px', backgroundColor: isDark ? 'green.700' : 'green.500', color: 'white', border: 'none', borderRadius: '8px', fontSize: '1rem', fontWeight: 'medium', cursor: 'pointer', _hover: { backgroundColor: isDark ? 'green.600' : 'green.600', }, })} > Done </button> </> ) : ( /* Input state */ <> <Dialog.Title className={css({ fontSize: '1.25rem', fontWeight: 'bold', color: isDark ? 'white' : 'gray.900', marginBottom: '8px', })} > Add Student by Family Code </Dialog.Title> <Dialog.Description className={css({ fontSize: '0.875rem', color: isDark ? 'gray.400' : 'gray.600', marginBottom: '20px', })} > Enter a student's family sharing code to send an enrollment request. Their parent will need to approve before they're added to your classroom. </Dialog.Description> <div className={css({ marginBottom: '16px' })}> <label htmlFor="family-code" className={css({ display: 'block', fontSize: '0.875rem', fontWeight: 'medium', color: isDark ? 'gray.300' : 'gray.700', marginBottom: '6px', })} > Family Code </label> <input id="family-code" type="text" value={familyCode} onChange={(e) => { setFamilyCode(e.target.value.toUpperCase()) setError(null) }} placeholder="e.g., ABCD-1234" data-element="family-code-input" className={css({ width: '100%', padding: '12px', fontSize: '1.25rem', fontFamily: 'monospace', textAlign: 'center', letterSpacing: '0.1em', backgroundColor: isDark ? 'gray.700' : 'gray.50', border: '2px solid', borderColor: error ? isDark ? 'red.500' : 'red.400' : isDark ? 'gray.600' : 'gray.300', borderRadius: '8px', color: isDark ? 'white' : 'gray.900', outline: 'none', _focus: { borderColor: 'blue.500', boxShadow: '0 0 0 3px rgba(59, 130, 246, 0.2)', }, _placeholder: { color: isDark ? 'gray.500' : 'gray.400', }, })} /> </div> {error && ( <div data-element="error-message" className={css({ padding: '12px', backgroundColor: isDark ? 'red.900/30' : 'red.50', border: '1px solid', borderColor: isDark ? 'red.700' : 'red.200', borderRadius: '8px', color: isDark ? 'red.300' : 'red.700', fontSize: '0.875rem', marginBottom: '16px', })} > {error} </div> )} <div className={css({ display: 'flex', gap: '12px' })}> <Dialog.Close asChild> <button type="button" disabled={isSubmitting} data-action="cancel" className={css({ flex: 1, padding: '12px', backgroundColor: isDark ? 'gray.700' : 'gray.200', color: isDark ? 'gray.300' : 'gray.700', border: 'none', borderRadius: '8px', fontSize: '1rem', fontWeight: 'medium', cursor: 'pointer', _hover: { backgroundColor: isDark ? 'gray.600' : 'gray.300', }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} > Cancel </button> </Dialog.Close> <button type="button" onClick={handleSubmit} disabled={isSubmitting || !familyCode.trim()} data-action="submit" className={css({ flex: 1, padding: '12px', backgroundColor: isDark ? 'blue.700' : 'blue.500', color: 'white', border: 'none', borderRadius: '8px', fontSize: '1rem', fontWeight: 'medium', cursor: 'pointer', _hover: { backgroundColor: isDark ? 'blue.600' : 'blue.600', }, _disabled: { opacity: 0.5, cursor: 'not-allowed' }, })} > {isSubmitting ? 'Adding...' : 'Add Student'} </button> </div> </> )} </Dialog.Content> </Dialog.Portal> </Dialog.Root> ) } |