@@ -14,8 +14,10 @@ const QuestionForm = ({question, index, eventHandler}) => {
1414 const [ addingOption , setAddingOption ] = useState ( false ) ;
1515 const optionInputRef = useRef ( null ) ;
1616
17+ const userRole = localStorage . getItem ( 'userRole' ) ;
18+
1719 const editQuestion = ( ) => {
18- if ( editMode && questionText . trim ( ) === '' ) {
20+ if ( editMode && questionText . trim ( ) === '' || userRole === 'viewer' ) {
1921 return ;
2022 }
2123 triggerUpdateEvent ( ) ;
@@ -61,7 +63,7 @@ const QuestionForm = ({question, index, eventHandler}) => {
6163 < Box key = { index } sx = { { mb : 1 , p : 2 , border : '1px solid' , borderColor : 'grey.300' , borderRadius : 1 } } >
6264 < Grid container spacing = { 2 } alignItems = "center" >
6365 < Grid size = { { xs : 12 , md : 9 } } >
64- < EditIcon sx = { { borderRadius : "50%" , display : "inline-block" , float : "left" , mr : 1 , fontSize : "0.9rem" , border : 1 , borderColor : "grey.200" , color : "grey.400" , padding : "4px" , cursor : "pointer" , ':hover' : { backgroundColor : "primary.main" , color : "white" , borderColor : "primary.main" } } } onClick = { editQuestion } />
66+ { userRole !== 'viewer' && < EditIcon sx = { { borderRadius : "50%" , display : "inline-block" , float : "left" , mr : 1 , fontSize : "0.9rem" , border : 1 , borderColor : "grey.200" , color : "grey.400" , padding : "4px" , cursor : "pointer" , ':hover' : { backgroundColor : "primary.main" , color : "white" , borderColor : "primary.main" } } } onClick = { editQuestion } /> }
6567 { ! editMode ? (
6668 < Typography onClick = { editQuestion } > { index + 1 } . { questionText } </ Typography >
6769 ) : (
@@ -77,12 +79,12 @@ const QuestionForm = ({question, index, eventHandler}) => {
7779 ) }
7880 </ Grid >
7981 < Grid size = { { xs : 12 , md : 3 } } sx = { { textAlign : 'right' } } >
80- < Button variant = "outlined" color = "primary" sx = { { fontSize : '0.75rem' , mt : 1 } } onClick = { ( ) => setAddingOption ( true ) } >
82+ { userRole !== 'viewer' && < > < Button variant = "outlined" color = "primary" sx = { { fontSize : '0.75rem' , mt : 1 } } onClick = { ( ) => setAddingOption ( true ) } >
8183 < RuleIcon /> < Typography variant = "button" sx = { { ml : 1 , fontSize : '0.75rem' } } > Add Option</ Typography >
8284 </ Button >
8385 < Button variant = "outlined" onClick = { deleteCallback } sx = { { ml : 1 , mt : 1 , fontSize : '0.75rem' } } >
8486 Delete
85- </ Button >
87+ </ Button > </ > }
8688 </ Grid >
8789 { addingOption && ( < >
8890 < Grid size = { { xs : 9 } } sx = { { display : 'flex' , alignItems : 'center' } } >
@@ -125,7 +127,7 @@ const QuestionForm = ({question, index, eventHandler}) => {
125127 < TableRow >
126128 < TableCell > Options</ TableCell >
127129 < TableCell > Correct Answer</ TableCell >
128- < TableCell align = 'right' > Actions</ TableCell >
130+ { userRole !== 'viewer' && < TableCell align = 'right' > Actions</ TableCell > }
129131 </ TableRow >
130132 </ TableHead >
131133 < TableBody >
@@ -146,16 +148,16 @@ const QuestionForm = ({question, index, eventHandler}) => {
146148 } }
147149 />
148150 ) } </ TableCell >
149- < TableCell > < Switch onChange = { ( e ) => updateOption ( idx , e . target . checked ) } checked = { option . isCorrect } /> </ TableCell >
150- < TableCell align = 'right' >
151+ < TableCell > < Switch onChange = { ( e ) => updateOption ( idx , e . target . checked ) } checked = { option . isCorrect } disabled = { userRole === 'viewer' } /> </ TableCell >
152+ { userRole !== 'viewer' && < TableCell align = 'right' >
151153 < EditIcon sx = { { cursor : 'pointer' , mr : 1 } } onClick = { ( ) => {
152154 setOptions ( options . map ( ( opt , i ) => i === idx ? { ...opt , editMode : ! opt . editMode } : opt ) ) ;
153155 } } />
154156 < ClearIcon sx = { { cursor : 'pointer' } } onClick = { ( ) => {
155157 const updatedOptions = options . filter ( ( _ , i ) => i !== idx ) ;
156158 setOptions ( updatedOptions ) ;
157159 } } />
158- </ TableCell >
160+ </ TableCell > }
159161 </ TableRow >
160162 ) ) }
161163 </ TableBody >
0 commit comments