11import React , { useContext , useEffect , useState } from 'react' ;
22import { styled } from '@mui/material/styles' ;
3- import { Autocomplete , Avatar , Button , Checkbox , Chip , TextField , Typography } from '@mui/material' ;
3+ import { Autocomplete , Avatar , Button , Checkbox , Chip , TextField , Typography , Dialog , DialogActions , DialogContent , DialogTitle } from '@mui/material' ;
44import FeedbackResponseCard from './feedback_response_card/FeedbackResponseCard' ;
55import { getQuestionsAndAnswers } from '../../api/feedbackanswer' ;
66import { getFeedbackRequestById } from '../../api/feedback' ;
@@ -50,15 +50,13 @@ const Root = styled('div')({
5050 marginRight : '3em' ,
5151 width : '350px' ,
5252 [ '@media (max-width: 800px)' ] : {
53- // eslint-disable-line no-useless-computed-key
5453 marginRight : 0 ,
5554 width : '100%'
5655 }
5756 } ,
5857 [ `& .${ classes . responderField } ` ] : {
5958 minWidth : '500px' ,
6059 [ '@media (max-width: 800px)' ] : {
61- // eslint-disable-line no-useless-computed-key
6260 minWidth : 0 ,
6361 width : '100%'
6462 }
@@ -79,6 +77,28 @@ const ViewFeedbackResponses = () => {
7977 useState ( [ ] ) ;
8078 const [ isLoading , setIsLoading ] = useState ( true ) ;
8179
80+ // Dialog state for denying feedback
81+ const [ denialPopupOpen , setDenialPopupOpen ] = useState ( false ) ;
82+ const [ denialReason , setDenialReason ] = useState ( '' ) ;
83+ const [ currentResponder , setCurrentResponder ] = useState ( null ) ; // Track the responder being denied
84+
85+ const handleDenyClick = ( responderId ) => {
86+ console . log ( `Denial process initiated for responder: ${ responderId } ` ) ;
87+ setCurrentResponder ( responderId ) ; // Track the current responder
88+ setDenialPopupOpen ( true ) ;
89+ } ;
90+
91+ const handleDenialClose = ( ) => {
92+ setDenialPopupOpen ( false ) ;
93+ console . log ( "Denial popup closed" ) ;
94+ } ;
95+
96+ const handleDenialSubmit = ( ) => {
97+ console . log ( `Denial reason for responder ${ currentResponder } :` , denialReason ) ;
98+ setDenialPopupOpen ( false ) ;
99+ // Here, you'd normally send the reason to the backend or handle it appropriately
100+ } ;
101+
82102 useEffect ( ( ) => {
83103 setQuery ( queryString . parse ( location ?. search ) ) ;
84104 } , [ location . search ] ) ;
@@ -136,7 +156,6 @@ const ViewFeedbackResponses = () => {
136156 } ) ;
137157 } , [ csrf , query . request ] ) ;
138158
139- // Sets the options for filtering by responders
140159 useEffect ( ( ) => {
141160 let allResponders = [ ] ;
142161 questionsAndAnswers . forEach ( ( { answers } ) => {
@@ -147,7 +166,6 @@ const ViewFeedbackResponses = () => {
147166 setResponderOptions ( allResponders ) ;
148167 } , [ state , questionsAndAnswers ] ) ;
149168
150- // Populate all responders as selected by default
151169 useEffect ( ( ) => {
152170 setSelectedResponders ( responderOptions ) ;
153171 } , [ responderOptions ] ) ;
@@ -156,12 +174,10 @@ const ViewFeedbackResponses = () => {
156174 let responsesToDisplay = [ ...questionsAndAnswers ] ;
157175
158176 responsesToDisplay = responsesToDisplay . map ( response => {
159- // Filter based on selected responders
160177 let filteredAnswers = response . answers . filter ( answer =>
161178 selectedResponders . includes ( answer . responder )
162179 ) ;
163180 if ( searchText . trim ( ) ) {
164- // Filter based on search text
165181 filteredAnswers = filteredAnswers . filter (
166182 ( { answer } ) =>
167183 answer &&
@@ -172,7 +188,7 @@ const ViewFeedbackResponses = () => {
172188 } ) ;
173189
174190 setFilteredQuestionsAndAnswers ( responsesToDisplay ) ;
175- } , [ searchText , selectedResponders ] ) ; // eslint-disable-line react-hooks/exhaustive-deps
191+ } , [ searchText , selectedResponders ] ) ;
176192
177193 useEffect ( ( ) => {
178194 if ( isLoading && filteredQuestionsAndAnswers . length > 0 ) {
@@ -310,15 +326,37 @@ const ViewFeedbackResponses = () => {
310326 answer = { answer . answer || '' }
311327 inputType = { question . inputType }
312328 sentiment = { answer . sentiment }
329+ handleDenyClick = { ( ) => handleDenyClick ( answer . responder ) } // Pass responderId
313330 />
314331 ) ) }
315332 </ div >
316333 ) ;
317334 } ) }
335+
336+ { /* Dialog for denial reason */ }
337+ < Dialog open = { denialPopupOpen } onClose = { handleDenialClose } >
338+ < DialogTitle > Feedback Request Denial Explanation</ DialogTitle >
339+ < DialogContent >
340+ < TextField
341+ autoFocus
342+ margin = "dense"
343+ label = "Denial Reason"
344+ type = "text"
345+ fullWidth
346+ variant = "standard"
347+ value = { denialReason }
348+ onChange = { ( e ) => setDenialReason ( e . target . value ) }
349+ />
350+ </ DialogContent >
351+ < DialogActions >
352+ < Button onClick = { handleDenialClose } > Cancel</ Button >
353+ < Button onClick = { handleDenialSubmit } > Send</ Button >
354+ </ DialogActions >
355+ </ Dialog >
318356 </ Root >
319357 ) : (
320358 < h3 > { noPermission } </ h3 >
321359 ) ;
322360} ;
323361
324- export default ViewFeedbackResponses ;
362+ export default ViewFeedbackResponses ;
0 commit comments