99 AUTH_LOGIN_URL ,
1010 preview ,
1111} from "constants/routesURL" ;
12- import { User } from "constants/userConstants" ;
12+ import { CurrentUser , User } from "constants/userConstants" ;
1313import {
1414 CommonTextLabel ,
1515 CustomModal ,
@@ -56,6 +56,8 @@ import { EditorContext } from "../../comps/editorState";
5656import Tooltip from "antd/es/tooltip" ;
5757import { LockOutlined , ExclamationCircleOutlined } from '@ant-design/icons' ;
5858import Avatar from 'antd/es/avatar' ;
59+ import UserApi from "@lowcoder-ee/api/userApi" ;
60+ import { validateResponse } from "@lowcoder-ee/api/apiUtils" ;
5961
6062
6163const StyledLink = styled . a `
@@ -343,12 +345,26 @@ export default function Header(props: HeaderProps) {
343345 const [ editName , setEditName ] = useState ( false ) ;
344346 const [ editing , setEditing ] = useState ( false ) ;
345347 const [ permissionDialogVisible , setPermissionDialogVisible ] = useState ( false ) ;
348+ const [ editingUser , setEditingUser ] = useState < CurrentUser > ( ) ;
346349
347350 const isModule = appType === AppTypeEnum . Module ;
351+ const blockEditing = useMemo (
352+ ( ) => user . id !== application ?. editingUserId ,
353+ [ application ?. editingUserId ]
354+ ) ;
348355
349- // Raheel: Todo - get concurrent editing state by API
350- // maybe via editorState.getConcurrentAppEditingState(); as a new function?
351- const [ concurrentAppEditingState , setConcurrentAppEditingState ] = useState ( true ) ;
356+ useEffect ( ( ) => {
357+ if ( blockEditing && application && Boolean ( application ?. editingUserId ) ) {
358+ UserApi . getUserDetail ( application . editingUserId ! )
359+ . then ( resp => {
360+ if ( validateResponse ( resp ) ) {
361+ console . log ( resp . data . data ) ;
362+ setEditingUser ( resp . data . data ) ;
363+ }
364+ } ) ;
365+ }
366+ } , [ blockEditing ] ) ;
367+ console . log ( user . id , application ?. editingUserId ) ;
352368
353369 const editorModeOptions = [
354370 {
@@ -491,7 +507,7 @@ export default function Header(props: HeaderProps) {
491507 ) : (
492508 < >
493509 { /* Display a hint about who is editing the app */ }
494- { concurrentAppEditingState && (
510+ { blockEditing && (
495511 < Tooltip
496512 title = "Changes will not be saved while another user is editing this app."
497513 color = "red"
@@ -500,7 +516,8 @@ export default function Header(props: HeaderProps) {
500516 < EditingNoticeWrapper >
501517 < Avatar size = "small" src = { user . avatarUrl } />
502518 < EditingHintText >
503- { `${ user . username } is currently editing this app.` }
519+ { /* {`${user.username} is currently editing this app.` } */ }
520+ { `${ editingUser ?. name || 'Someone' } is currently editing this app` }
504521 </ EditingHintText >
505522 < WarningIcon />
506523 </ EditingNoticeWrapper >
@@ -534,7 +551,7 @@ export default function Header(props: HeaderProps) {
534551 < DropdownMenuStyled
535552 style = { { minWidth : "110px" , borderRadius : "4px" } }
536553 onClick = { ( e ) => {
537- if ( concurrentAppEditingState ) return ; // Prevent clicks if the app is being edited by someone else
554+ if ( blockEditing ) return ; // Prevent clicks if the app is being edited by someone else
538555 if ( e . key === "deploy" ) {
539556 dispatch ( publishApplication ( { applicationId } ) ) ;
540557 } else if ( e . key === "snapshot" ) {
@@ -546,31 +563,31 @@ export default function Header(props: HeaderProps) {
546563 key : "deploy" ,
547564 label : (
548565 < div style = { { display : 'flex' , alignItems : 'center' } } >
549- { concurrentAppEditingState && < LockOutlined style = { { marginRight : '8px' } } /> }
550- < CommonTextLabel style = { { color : concurrentAppEditingState ? "#ccc" : "#222" } } >
566+ { blockEditing && < LockOutlined style = { { marginRight : '8px' } } /> }
567+ < CommonTextLabel style = { { color : blockEditing ? "#ccc" : "#222" } } >
551568 { trans ( "header.deploy" ) }
552569 </ CommonTextLabel >
553570 </ div >
554571 ) ,
555- disabled : concurrentAppEditingState ,
572+ disabled : blockEditing ,
556573 } ,
557574 {
558575 key : "snapshot" ,
559576 label : (
560577 < div style = { { display : 'flex' , alignItems : 'center' } } >
561- { concurrentAppEditingState && < LockOutlined style = { { marginRight : '8px' } } /> }
562- < CommonTextLabel style = { { color : concurrentAppEditingState ? "#ccc" : "#222" } } >
578+ { blockEditing && < LockOutlined style = { { marginRight : '8px' } } /> }
579+ < CommonTextLabel style = { { color : blockEditing ? "#ccc" : "#222" } } >
563580 { trans ( "header.snapshot" ) }
564581 </ CommonTextLabel >
565582 </ div >
566583 ) ,
567- disabled : concurrentAppEditingState ,
584+ disabled : blockEditing ,
568585 } ,
569586 ] }
570587 />
571588 ) }
572589 >
573- < PackUpBtn buttonType = "primary" disabled = { concurrentAppEditingState } >
590+ < PackUpBtn buttonType = "primary" disabled = { blockEditing } >
574591 < PackUpIcon />
575592 </ PackUpBtn >
576593 </ Dropdown >
@@ -583,7 +600,8 @@ export default function Header(props: HeaderProps) {
583600 showAppSnapshot ,
584601 applicationId ,
585602 permissionDialogVisible ,
586- concurrentAppEditingState , // Include the state in the dependency array
603+ blockEditing , // Include the state in the dependency array
604+ editingUser ?. name ,
587605 ] ) ;
588606
589607 return (
0 commit comments