9
9
AUTH_LOGIN_URL ,
10
10
preview ,
11
11
} from "constants/routesURL" ;
12
- import { User } from "constants/userConstants" ;
12
+ import { CurrentUser , User } from "constants/userConstants" ;
13
13
import {
14
14
CommonTextLabel ,
15
15
CustomModal ,
@@ -56,6 +56,8 @@ import { EditorContext } from "../../comps/editorState";
56
56
import Tooltip from "antd/es/tooltip" ;
57
57
import { LockOutlined , ExclamationCircleOutlined } from '@ant-design/icons' ;
58
58
import Avatar from 'antd/es/avatar' ;
59
+ import UserApi from "@lowcoder-ee/api/userApi" ;
60
+ import { validateResponse } from "@lowcoder-ee/api/apiUtils" ;
59
61
60
62
61
63
const StyledLink = styled . a `
@@ -343,12 +345,26 @@ export default function Header(props: HeaderProps) {
343
345
const [ editName , setEditName ] = useState ( false ) ;
344
346
const [ editing , setEditing ] = useState ( false ) ;
345
347
const [ permissionDialogVisible , setPermissionDialogVisible ] = useState ( false ) ;
348
+ const [ editingUser , setEditingUser ] = useState < CurrentUser > ( ) ;
346
349
347
350
const isModule = appType === AppTypeEnum . Module ;
351
+ const blockEditing = useMemo (
352
+ ( ) => user . id !== application ?. editingUserId ,
353
+ [ application ?. editingUserId ]
354
+ ) ;
348
355
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 ) ;
352
368
353
369
const editorModeOptions = [
354
370
{
@@ -491,7 +507,7 @@ export default function Header(props: HeaderProps) {
491
507
) : (
492
508
< >
493
509
{ /* Display a hint about who is editing the app */ }
494
- { concurrentAppEditingState && (
510
+ { blockEditing && (
495
511
< Tooltip
496
512
title = "Changes will not be saved while another user is editing this app."
497
513
color = "red"
@@ -500,7 +516,8 @@ export default function Header(props: HeaderProps) {
500
516
< EditingNoticeWrapper >
501
517
< Avatar size = "small" src = { user . avatarUrl } />
502
518
< 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` }
504
521
</ EditingHintText >
505
522
< WarningIcon />
506
523
</ EditingNoticeWrapper >
@@ -534,7 +551,7 @@ export default function Header(props: HeaderProps) {
534
551
< DropdownMenuStyled
535
552
style = { { minWidth : "110px" , borderRadius : "4px" } }
536
553
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
538
555
if ( e . key === "deploy" ) {
539
556
dispatch ( publishApplication ( { applicationId } ) ) ;
540
557
} else if ( e . key === "snapshot" ) {
@@ -546,31 +563,31 @@ export default function Header(props: HeaderProps) {
546
563
key : "deploy" ,
547
564
label : (
548
565
< 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" } } >
551
568
{ trans ( "header.deploy" ) }
552
569
</ CommonTextLabel >
553
570
</ div >
554
571
) ,
555
- disabled : concurrentAppEditingState ,
572
+ disabled : blockEditing ,
556
573
} ,
557
574
{
558
575
key : "snapshot" ,
559
576
label : (
560
577
< 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" } } >
563
580
{ trans ( "header.snapshot" ) }
564
581
</ CommonTextLabel >
565
582
</ div >
566
583
) ,
567
- disabled : concurrentAppEditingState ,
584
+ disabled : blockEditing ,
568
585
} ,
569
586
] }
570
587
/>
571
588
) }
572
589
>
573
- < PackUpBtn buttonType = "primary" disabled = { concurrentAppEditingState } >
590
+ < PackUpBtn buttonType = "primary" disabled = { blockEditing } >
574
591
< PackUpIcon />
575
592
</ PackUpBtn >
576
593
</ Dropdown >
@@ -583,7 +600,8 @@ export default function Header(props: HeaderProps) {
583
600
showAppSnapshot ,
584
601
applicationId ,
585
602
permissionDialogVisible ,
586
- concurrentAppEditingState , // Include the state in the dependency array
603
+ blockEditing , // Include the state in the dependency array
604
+ editingUser ?. name ,
587
605
] ) ;
588
606
589
607
return (
0 commit comments