|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import ContinueButton from './ContinueButton'; |
| 3 | + |
| 4 | +const PostQuestionnaire = ({ onSubmit }) => { |
| 5 | + const [formData, setFormData] = useState({ |
| 6 | + difficulty: '', |
| 7 | + hasVisualImpairments: '', |
| 8 | + visualImpairmentsSpecify: '', |
| 9 | + hadReadingProblems: '', |
| 10 | + readingProblemsSpecify: '', |
| 11 | + completedTimely: '', |
| 12 | + thingsLiked: '', |
| 13 | + thingsDisliked: '', |
| 14 | + otherComments: '' |
| 15 | + }); |
| 16 | + |
| 17 | + const handleInputChange = (field, value) => { |
| 18 | + setFormData(prev => ({ |
| 19 | + ...prev, |
| 20 | + [field]: value |
| 21 | + })); |
| 22 | + }; |
| 23 | + |
| 24 | + const handleSubmit = (e) => { |
| 25 | + e.preventDefault(); |
| 26 | + const finalData = { |
| 27 | + ...formData, |
| 28 | + timestamp: new Date().toISOString() |
| 29 | + }; |
| 30 | + onSubmit?.(finalData); |
| 31 | + }; |
| 32 | + |
| 33 | + const isFormValid = formData.difficulty && |
| 34 | + formData.hasVisualImpairments && |
| 35 | + formData.hadReadingProblems && |
| 36 | + formData.completedTimely; |
| 37 | + |
| 38 | + return ( |
| 39 | + <div style={styles.container}> |
| 40 | + <h2 style={styles.title}>Post-Study Questionnaire</h2> |
| 41 | + <form onSubmit={handleSubmit} style={styles.form}> |
| 42 | + |
| 43 | + <div style={styles.fieldRow}> |
| 44 | + <label style={styles.sideLabel}>Overall, how difficult did you find the study?</label> |
| 45 | + <div style={styles.radioGroup}> |
| 46 | + {[1, 2, 3, 4, 5].map(level => ( |
| 47 | + <label key={level} style={styles.radioLabel}> |
| 48 | + <input |
| 49 | + type="radio" |
| 50 | + name="difficulty" |
| 51 | + value={level} |
| 52 | + checked={formData.difficulty === String(level)} |
| 53 | + onChange={(e) => handleInputChange('difficulty', e.target.value)} |
| 54 | + style={styles.radio} |
| 55 | + required |
| 56 | + /> |
| 57 | + {level} {level === 1 ? '(Very Easy)' : level === 5 ? '(Very Hard)' : ''} |
| 58 | + </label> |
| 59 | + ))} |
| 60 | + </div> |
| 61 | + </div> |
| 62 | + |
| 63 | + <div style={styles.fieldRow}> |
| 64 | + <label style={styles.sideLabel}>Do you have any visual impairments?</label> |
| 65 | + <div style={styles.optionsContainer}> |
| 66 | + <div style={styles.radioGroup}> |
| 67 | + {['Yes', 'No'].map(answer => ( |
| 68 | + <label key={answer} style={styles.radioLabel}> |
| 69 | + <input |
| 70 | + type="radio" |
| 71 | + name="hasVisualImpairments" |
| 72 | + value={answer} |
| 73 | + checked={formData.hasVisualImpairments === answer} |
| 74 | + onChange={(e) => handleInputChange('hasVisualImpairments', e.target.value)} |
| 75 | + style={styles.radio} |
| 76 | + required |
| 77 | + /> |
| 78 | + {answer} |
| 79 | + </label> |
| 80 | + ))} |
| 81 | + </div> |
| 82 | + {formData.hasVisualImpairments === 'Yes' && ( |
| 83 | + <textarea |
| 84 | + placeholder="Please specify" |
| 85 | + value={formData.visualImpairmentsSpecify} |
| 86 | + onChange={(e) => handleInputChange('visualImpairmentsSpecify', e.target.value)} |
| 87 | + style={styles.textarea} |
| 88 | + rows={3} |
| 89 | + /> |
| 90 | + )} |
| 91 | + </div> |
| 92 | + </div> |
| 93 | + |
| 94 | + <div style={styles.fieldRow}> |
| 95 | + <label style={styles.sideLabel}>Did you have any problems reading the text?</label> |
| 96 | + <div style={styles.optionsContainer}> |
| 97 | + <div style={styles.radioGroup}> |
| 98 | + {['Yes', 'No'].map(answer => ( |
| 99 | + <label key={answer} style={styles.radioLabel}> |
| 100 | + <input |
| 101 | + type="radio" |
| 102 | + name="hadReadingProblems" |
| 103 | + value={answer} |
| 104 | + checked={formData.hadReadingProblems === answer} |
| 105 | + onChange={(e) => handleInputChange('hadReadingProblems', e.target.value)} |
| 106 | + style={styles.radio} |
| 107 | + required |
| 108 | + /> |
| 109 | + {answer} |
| 110 | + </label> |
| 111 | + ))} |
| 112 | + </div> |
| 113 | + {formData.hadReadingProblems === 'Yes' && ( |
| 114 | + <textarea |
| 115 | + placeholder="Please specify" |
| 116 | + value={formData.readingProblemsSpecify} |
| 117 | + onChange={(e) => handleInputChange('readingProblemsSpecify', e.target.value)} |
| 118 | + style={styles.textarea} |
| 119 | + rows={3} |
| 120 | + /> |
| 121 | + )} |
| 122 | + </div> |
| 123 | + </div> |
| 124 | + |
| 125 | + <div style={styles.fieldRow}> |
| 126 | + <label style={styles.sideLabel}>Did you complete the tasks in a reasonably timely manner?</label> |
| 127 | + <div style={styles.radioGroup}> |
| 128 | + {['Yes', 'No'].map(answer => ( |
| 129 | + <label key={answer} style={styles.radioLabel}> |
| 130 | + <input |
| 131 | + type="radio" |
| 132 | + name="completedTimely" |
| 133 | + value={answer} |
| 134 | + checked={formData.completedTimely === answer} |
| 135 | + onChange={(e) => handleInputChange('completedTimely', e.target.value)} |
| 136 | + style={styles.radio} |
| 137 | + required |
| 138 | + /> |
| 139 | + {answer} |
| 140 | + </label> |
| 141 | + ))} |
| 142 | + </div> |
| 143 | + </div> |
| 144 | + |
| 145 | + <div style={styles.fieldRow}> |
| 146 | + <label style={styles.sideLabel}>What are things you liked about this study?</label> |
| 147 | + <textarea |
| 148 | + value={formData.thingsLiked} |
| 149 | + onChange={(e) => handleInputChange('thingsLiked', e.target.value)} |
| 150 | + style={styles.textarea} |
| 151 | + rows={4} |
| 152 | + placeholder="Please share what you liked about the study" |
| 153 | + /> |
| 154 | + </div> |
| 155 | + |
| 156 | + <div style={styles.fieldRow}> |
| 157 | + <label style={styles.sideLabel}>What are things you disliked about this study?</label> |
| 158 | + <textarea |
| 159 | + value={formData.thingsDisliked} |
| 160 | + onChange={(e) => handleInputChange('thingsDisliked', e.target.value)} |
| 161 | + style={styles.textarea} |
| 162 | + rows={4} |
| 163 | + placeholder="Please share what you disliked about the study" |
| 164 | + /> |
| 165 | + </div> |
| 166 | + |
| 167 | + <div style={styles.fieldRow}> |
| 168 | + <label style={styles.sideLabel}>Please write any other comments or concerns</label> |
| 169 | + <textarea |
| 170 | + value={formData.otherComments} |
| 171 | + onChange={(e) => handleInputChange('otherComments', e.target.value)} |
| 172 | + style={styles.textarea} |
| 173 | + rows={4} |
| 174 | + placeholder="Any additional comments or concerns" |
| 175 | + /> |
| 176 | + </div> |
| 177 | + |
| 178 | + <ContinueButton type="submit" disabled={!isFormValid} /> |
| 179 | + </form> |
| 180 | + </div> |
| 181 | + ); |
| 182 | +}; |
| 183 | + |
| 184 | +const styles = { |
| 185 | + container: { |
| 186 | + display: 'flex', |
| 187 | + flexDirection: 'column', |
| 188 | + alignItems: 'center', |
| 189 | + justifyContent: 'flex-start', |
| 190 | + minHeight: '100vh', |
| 191 | + width: '100%', |
| 192 | + fontFamily: 'Arial, sans-serif', |
| 193 | + backgroundColor: '#fff', |
| 194 | + overflowY: 'auto', |
| 195 | + padding: '20px', |
| 196 | + boxSizing: 'border-box', |
| 197 | + }, |
| 198 | + title: { |
| 199 | + marginBottom: '30px', |
| 200 | + fontSize: '24px', |
| 201 | + color: '#2c3e50', |
| 202 | + }, |
| 203 | + form: { |
| 204 | + width: '100%', |
| 205 | + maxWidth: '800px', |
| 206 | + display: 'flex', |
| 207 | + flexDirection: 'column', |
| 208 | + gap: '15px', |
| 209 | + }, |
| 210 | + fieldRow: { |
| 211 | + display: 'flex', |
| 212 | + alignItems: 'flex-start', |
| 213 | + gap: '20px', |
| 214 | + minHeight: '40px', |
| 215 | + }, |
| 216 | + sideLabel: { |
| 217 | + fontSize: '16px', |
| 218 | + fontWeight: 'bold', |
| 219 | + color: '#2c3e50', |
| 220 | + minWidth: '200px', |
| 221 | + paddingTop: '8px', |
| 222 | + textAlign: 'right', |
| 223 | + }, |
| 224 | + optionsContainer: { |
| 225 | + flex: 1, |
| 226 | + display: 'flex', |
| 227 | + flexDirection: 'column', |
| 228 | + gap: '8px', |
| 229 | + }, |
| 230 | + textarea: { |
| 231 | + flex: 1, |
| 232 | + padding: '10px', |
| 233 | + fontSize: '14px', |
| 234 | + border: '1px solid #ccc', |
| 235 | + borderRadius: '4px', |
| 236 | + outline: 'none', |
| 237 | + fontFamily: 'Arial, sans-serif', |
| 238 | + resize: 'vertical', |
| 239 | + minHeight: '80px', |
| 240 | + }, |
| 241 | + radioGroup: { |
| 242 | + display: 'flex', |
| 243 | + flexDirection: 'column', |
| 244 | + gap: '6px', |
| 245 | + }, |
| 246 | + radioLabel: { |
| 247 | + display: 'flex', |
| 248 | + alignItems: 'center', |
| 249 | + gap: '8px', |
| 250 | + fontSize: '14px', |
| 251 | + cursor: 'pointer', |
| 252 | + }, |
| 253 | + radio: { |
| 254 | + margin: 0, |
| 255 | + }, |
| 256 | +}; |
| 257 | + |
| 258 | +export default PostQuestionnaire; |
| 259 | + |
0 commit comments