@@ -35,6 +35,7 @@ export const ExtensionDetailReviews: FunctionComponent<ExtensionDetailReviewsPro
3535 const [ loading , setLoading ] = useState < boolean > ( true ) ;
3636 const [ revoked , setRevoked ] = useState < boolean > ( false ) ;
3737 const [ removeDialogOpen , setRemoveDialogOpen ] = useState ( false ) ;
38+ const [ removeCommentFromUser , setRemoveCommentFromUser ] = useState < UserData | undefined > ( undefined ) ;
3839 const [ removeReviewSet , setRemoveReviewSet ] = useState ( new Set < string > ( ) ) ;
3940 const context = useContext ( MainContext ) ;
4041 const abortController = useRef < AbortController > ( new AbortController ( ) ) ;
@@ -111,58 +112,66 @@ export const ExtensionDetailReviews: FunctionComponent<ExtensionDetailReviewsPro
111112 }
112113 } ;
113114
114- const handleAdminRemoveReviewButton = async ( r : ExtensionReview ) => {
115- addRemoveReviewRequest ( r . user . loginName ) ;
115+ const handleAdminRemoveReviewButton = async ( ) => {
116+ if ( removeCommentFromUser === undefined ) {
117+ return ;
118+ }
119+ addRemoveReviewRequest ( removeCommentFromUser . loginName ) ;
116120 try {
117- const result = await context . service . deleteUserReview ( abortController . current , props . extension , r . user ) ;
121+ const result = await context . service . deleteUserReview ( abortController . current , props . extension , removeCommentFromUser ) ;
118122 if ( isError ( result ) ) {
119123 throw result ;
120124 }
121125 saveCompleted ( ) ;
126+ setRemoveDialogOpen ( false ) ;
122127 } catch ( err ) {
123128 context . handleError ( err ) ;
124129 } finally {
125- deleteRemoveReviewRequest ( r . user . loginName ) ;
130+ deleteRemoveReviewRequest ( removeCommentFromUser . loginName ) ;
126131 }
127132 } ;
128133
129134 const renderAdminRemoveButton = ( r : ExtensionReview ) : ReactNode => {
130- return < >
131- < Button
132- variant = 'contained'
133- color = 'error'
134- onClick = { ( ) => setRemoveDialogOpen ( true ) } >
135- Remove review
136- </ Button >
137- < Dialog
138- open = { removeDialogOpen }
139- onClose = { ( ) => setRemoveDialogOpen ( false ) } >
140- < DialogTitle > Remove Review</ DialogTitle >
141- < DialogContent >
142- < DialogContentText component = 'div' >
143- < Typography > Confirm removal of review comment from < code > { r . user . loginName } </ code > ?</ Typography >
144- </ DialogContentText >
145- </ DialogContent >
146- < DialogActions >
147- < Button
148- variant = 'contained'
149- color = 'primary'
150- onClick = { ( ) => setRemoveDialogOpen ( false ) } >
151- Cancel
152- </ Button >
153- < ButtonWithProgress
154- autoFocus
155- color = 'error'
156- sx = { { ml : 1 } }
157- working = { removeReviewSet . has ( r . user . loginName ) }
158- onClick = { ( ) => handleAdminRemoveReviewButton ( r ) } >
159- Remove review
160- </ ButtonWithProgress >
161- </ DialogActions >
162- </ Dialog >
163- </ > ;
135+ return < Button
136+ variant = 'contained'
137+ color = 'error'
138+ sx = { { ml : 1 } }
139+ onClick = { ( ) => {
140+ setRemoveCommentFromUser ( r . user ) ;
141+ setRemoveDialogOpen ( true ) } } >
142+ Remove review
143+ </ Button > ;
164144 } ;
165145
146+ const renderAdminRemoveDialog = ( ) => {
147+ return < Dialog
148+ open = { removeDialogOpen }
149+ onClose = { ( ) => setRemoveDialogOpen ( false ) } >
150+ < DialogTitle > Remove Review</ DialogTitle >
151+ < DialogContent >
152+ < DialogContentText component = 'div' >
153+ < Typography > Confirm removal of review comment from < code > { removeCommentFromUser ?. loginName } </ code > ?</ Typography >
154+ </ DialogContentText >
155+ </ DialogContent >
156+ < DialogActions >
157+ < Button
158+ variant = 'contained'
159+ color = 'primary'
160+ onClick = { ( ) => setRemoveDialogOpen ( false ) } >
161+ Cancel
162+ </ Button >
163+ < ButtonWithProgress
164+ autoFocus
165+ color = 'error'
166+ sx = { { ml : 1 } }
167+ working = { removeReviewSet . has ( removeCommentFromUser ?. loginName ?? '' ) }
168+ onClick = { ( ) => handleAdminRemoveReviewButton ( ) } >
169+ Remove review
170+ </ ButtonWithProgress >
171+ </ DialogActions >
172+ </ Dialog >
173+ }
174+
166175 const renderReviewList = ( list ?: ExtensionReviewList ) : ReactNode => {
167176 if ( ! list ) {
168177 return '' ;
@@ -251,6 +260,7 @@ export const ExtensionDetailReviews: FunctionComponent<ExtensionDetailReviewsPro
251260 < Box >
252261 < DelayedLoadIndicator loading = { loading } />
253262 { renderReviewList ( reviewList ) }
263+ { context . user ?. role === 'admin' && renderAdminRemoveDialog ( ) }
254264 </ Box >
255265 </ > ;
256266
0 commit comments