@@ -14,6 +14,7 @@ import { AnimationType } from '@TutorShared/hooks/useAnimation';
1414import { useDebounce } from '@TutorShared/hooks/useDebounce' ;
1515import { useSelectKeyboardNavigation } from '@TutorShared/hooks/useSelectKeyboardNavigation' ;
1616
17+ import { type CourseDetailsResponse } from '@CourseBuilderServices/course' ;
1718import Show from '@TutorShared/controls/Show' ;
1819import { withVisibilityControl } from '@TutorShared/hoc/withVisibilityControl' ;
1920import type { User } from '@TutorShared/services/users' ;
@@ -45,6 +46,7 @@ type FormSelectUserProps = {
4546 helpText ?: string ;
4647 emptyStateText ?: string ;
4748 isInstructorMode ?: boolean ;
49+ postAuthor ?: CourseDetailsResponse [ 'post_author' ] ;
4850} & FormControllerProps < UserOption | UserOption [ ] | null > ;
4951
5052const userPlaceholderData : UserOption = {
@@ -54,6 +56,8 @@ const userPlaceholderData: UserOption = {
5456 avatar_url : 'https://gravatar.com/avatar' ,
5557} ;
5658
59+ const currentUser = tutorConfig . current_user ;
60+
5761const FormSelectUser = ( {
5862 field,
5963 fieldState,
@@ -70,10 +74,12 @@ const FormSelectUser = ({
7074 helpText,
7175 emptyStateText = __ ( 'No user selected' , __TUTOR_TEXT_DOMAIN__ ) ,
7276 isInstructorMode = false ,
77+ postAuthor,
7378} : FormSelectUserProps ) => {
7479 const inputValue = field . value ?? ( isMultiSelect ? [ ] : userPlaceholderData ) ;
7580 const selectedIds = Array . isArray ( inputValue ) ? inputValue . map ( ( item ) => String ( item . id ) ) : [ String ( inputValue . id ) ] ;
76- const isCurrentUserAdmin = tutorConfig . current_user . roles ?. includes ( TutorRoles . ADMINISTRATOR ) ;
81+ const isCurrentUserAdmin = currentUser . roles ?. includes ( TutorRoles . ADMINISTRATOR ) ;
82+ const isCurrentUserAuthor = String ( currentUser . data . id ) === String ( postAuthor ?. ID || '' ) ;
7783
7884 const triggerRef = useRef < HTMLDivElement > ( null ) ;
7985 const [ isOpen , setIsOpen ] = useState ( false ) ;
@@ -257,7 +263,7 @@ const FormSelectUser = ({
257263 </ button >
258264 }
259265 >
260- < Show when = { isCurrentUserAdmin || instructor . isRemoveAble } >
266+ < Show when = { isCurrentUserAdmin || isCurrentUserAuthor || instructor . isRemoveAble } >
261267 < button
262268 type = "button"
263269 onClick = { ( ) => handleDeleteSelection ( instructor . id ) }
0 commit comments