1
1
import { Button as MuiButton , CircularProgress } from '@mui/material' ;
2
- import React , { forwardRef , Ref } from 'react' ;
2
+ import React , { forwardRef , Ref , useState } from 'react' ;
3
3
import { useTranslation } from 'react-i18next' ;
4
4
import { Link as RouterLink } from 'react-router-dom' ;
5
5
import { buildLoginUrl } from '../../../../main/routing/urlBuilders' ;
6
6
import { AddOutlined } from '@mui/icons-material' ;
7
- import RootThemeProvider from '../../../../core/ui/themes/RootThemeProvider' ;
8
- import useDirectMessageDialog from '../../../communication/messaging/DirectMessaging/useDirectMessageDialog' ;
7
+ import { DirectMessageDialog } from '../../../communication/messaging/DirectMessaging/DirectMessageDialog' ;
9
8
10
9
export interface OpportunityApplicationButtonProps {
11
10
isAuthenticated ?: boolean ;
12
11
isMember : boolean ;
13
12
isParentMember ?: boolean ;
14
13
parentUrl ?: string ;
14
+ sendMessageToCommunityLeads : ( message : string ) => Promise < void > ;
15
15
leadUsers : {
16
16
id : string ;
17
17
displayName ?: string ;
18
18
city ?: string ;
19
19
country ?: string ;
20
20
avatarUri ?: string ;
21
21
} [ ] ;
22
- adminUsers : {
23
- id : string ;
24
- displayName ?: string ;
25
- city ?: string ;
26
- country ?: string ;
27
- avatarUri ?: string ;
28
- } [ ] ;
29
22
loading : boolean ;
30
23
component ?: typeof MuiButton ;
31
24
extended ?: boolean ;
@@ -41,23 +34,21 @@ export const OpportunityApplicationButton = forwardRef<
41
34
isMember = false ,
42
35
isParentMember = false ,
43
36
parentUrl,
37
+ sendMessageToCommunityLeads,
44
38
leadUsers,
45
- adminUsers,
46
39
loading = false ,
47
40
component : Button = MuiButton ,
48
41
extended = false ,
49
42
} ,
50
43
ref
51
44
) => {
52
45
const { t } = useTranslation ( ) ;
53
- const { sendMessage, directMessageDialog } = useDirectMessageDialog ( {
54
- dialogTitle : t ( 'send-message-dialog.direct-message-title' ) ,
55
- } ) ;
56
-
57
- const contactUsers = leadUsers . length > 0 ? leadUsers : adminUsers ;
58
-
59
- const handleSendMessageToParentLeads = ( ) => {
60
- sendMessage ( 'user' , ...contactUsers ) ;
46
+ const [ isContactLeadUsersDialogOpen , setIsContactLeadUsersDialogOpen ] = useState ( false ) ;
47
+ const openContactLeadsDialog = ( ) => {
48
+ setIsContactLeadUsersDialogOpen ( true ) ;
49
+ } ;
50
+ const closeContactLeadsDialog = ( ) => {
51
+ setIsContactLeadUsersDialogOpen ( false ) ;
61
52
} ;
62
53
63
54
const renderApplicationButton = ( ) => {
@@ -99,29 +90,33 @@ export const OpportunityApplicationButton = forwardRef<
99
90
) ;
100
91
}
101
92
102
- if ( contactUsers . length === 0 ) {
93
+ if ( leadUsers . length === 0 ) {
103
94
return null ;
104
95
}
105
96
106
97
return (
107
- < Button
108
- ref = { ref as Ref < HTMLButtonElement > }
109
- startIcon = { extended ? < AddOutlined /> : undefined }
110
- onClick = { handleSendMessageToParentLeads }
111
- variant = "contained"
112
- sx = { extended ? { textTransform : 'none' } : undefined }
113
- >
114
- { t ( `components.application-button.contactOpportunityLeads.${ extended ? 'full' : 'short' } ` as const ) }
115
- </ Button >
98
+ < >
99
+ < Button
100
+ ref = { ref as Ref < HTMLButtonElement > }
101
+ startIcon = { extended ? < AddOutlined /> : undefined }
102
+ onClick = { openContactLeadsDialog }
103
+ variant = "contained"
104
+ sx = { extended ? { textTransform : 'none' } : undefined }
105
+ >
106
+ { t ( `components.application-button.contactOpportunityLeads.${ extended ? 'full' : 'short' } ` as const ) }
107
+ </ Button >
108
+ < DirectMessageDialog
109
+ title = { t ( 'send-message-dialog.community-message-title' , { contact : t ( 'community.leads' ) } ) }
110
+ open = { isContactLeadUsersDialogOpen }
111
+ onClose = { closeContactLeadsDialog }
112
+ onSendMessage = { sendMessageToCommunityLeads }
113
+ messageReceivers = { leadUsers }
114
+ />
115
+ </ >
116
116
) ;
117
117
} ;
118
118
119
- return (
120
- < >
121
- { renderApplicationButton ( ) }
122
- < RootThemeProvider > { directMessageDialog } </ RootThemeProvider >
123
- </ >
124
- ) ;
119
+ return < > { renderApplicationButton ( ) } </ > ;
125
120
}
126
121
) ;
127
122
0 commit comments