88 Text ,
99 Textarea ,
1010} from '@codesandbox/components' ;
11+ import { hasPermission } from '@codesandbox/common/lib/utils/permission' ;
1112import css from '@styled-system/css' ;
1213import {
1314 DIALOG_TRANSITION_DURATION ,
@@ -254,9 +255,15 @@ const DragHandle: React.FC<{
254255) ;
255256
256257const DialogHeader = ( { comment, hasShadow } ) => {
257- const { actions } = useOvermind ( ) ;
258+ const {
259+ state : { editor, user } ,
260+ actions : { comments } ,
261+ } = useOvermind ( ) ;
258262
259- const closeDialog = ( ) => actions . comments . closeComment ( ) ;
263+ const closeDialog = ( ) => comments . closeComment ( ) ;
264+ const canResolve =
265+ hasPermission ( editor . currentSandbox . authorization , 'write_project' ) ||
266+ comment . user . id === user . id ;
260267
261268 return (
262269 < Stack
@@ -278,25 +285,27 @@ const DialogHeader = ({ comment, hasShadow }) => {
278285 Comment
279286 </ Text >
280287 < Stack align = "center" >
281- < IconButton
282- onClick = { ( ) =>
283- actions . comments . resolveComment ( {
284- commentId : comment . id ,
285- isResolved : ! comment . isResolved ,
286- } )
287- }
288- name = "check"
289- size = { 14 }
290- title = { comment . isResolved ? 'Unresolve Comment' : 'Resolve Comment' }
291- css = { css ( {
292- transition : 'color' ,
293- transitionDuration : theme => theme . speeds [ 1 ] ,
294- color : comment . isResolved ? 'green' : 'mutedForeground' ,
295- ':hover:not(:disabled), :focus:not(:disabled)' : {
296- color : comment . isResolved ? 'green' : 'foreground' ,
297- } ,
298- } ) }
299- />
288+ { canResolve && (
289+ < IconButton
290+ onClick = { ( ) =>
291+ comments . resolveComment ( {
292+ commentId : comment . id ,
293+ isResolved : ! comment . isResolved ,
294+ } )
295+ }
296+ name = "check"
297+ size = { 14 }
298+ title = { comment . isResolved ? 'Unresolve Comment' : 'Resolve Comment' }
299+ css = { css ( {
300+ transition : 'color' ,
301+ transitionDuration : theme => theme . speeds [ 1 ] ,
302+ color : comment . isResolved ? 'green' : 'mutedForeground' ,
303+ ':hover:not(:disabled), :focus:not(:disabled)' : {
304+ color : comment . isResolved ? 'green' : 'foreground' ,
305+ } ,
306+ } ) }
307+ />
308+ ) }
300309 < IconButton
301310 name = "cross"
302311 size = { 10 }
@@ -309,7 +318,10 @@ const DialogHeader = ({ comment, hasShadow }) => {
309318} ;
310319
311320const CommentBody = ( { comment, editing, setEditing, hasReplies } ) => {
312- const { state, actions } = useOvermind ( ) ;
321+ const {
322+ state,
323+ actions : { comments } ,
324+ } = useOvermind ( ) ;
313325
314326 return (
315327 < Stack direction = "vertical" gap = { 4 } >
@@ -330,8 +342,8 @@ const CommentBody = ({ comment, editing, setEditing, hasReplies }) => {
330342 </ Menu . Item >
331343 < Menu . Item
332344 onSelect = { ( ) => {
333- actions . comments . closeComment ( ) ;
334- actions . comments . deleteComment ( {
345+ comments . closeComment ( ) ;
346+ comments . deleteComment ( {
335347 commentId : comment . id ,
336348 } ) ;
337349 } }
@@ -360,7 +372,7 @@ const CommentBody = ({ comment, editing, setEditing, hasReplies }) => {
360372 < EditComment
361373 initialValue = { comment . content }
362374 onSave = { async newValue => {
363- await actions . comments . updateComment ( {
375+ await comments . updateComment ( {
364376 commentId : comment . id ,
365377 content : newValue ,
366378 } ) ;
0 commit comments