1
- import React , { useEffect , useRef } from 'react' ;
2
- import { StationLoginPresentationalProps } from './station-login.types' ;
3
-
1
+ import React , { useEffect , useRef } from 'react' ;
2
+ import { StationLoginPresentationalProps } from './station-login.types' ;
4
3
import './station-login.style.scss' ;
4
+ import { MULTIPLE_SIGN_IN_ALERT_MESSAGE , MULTIPLE_SIGN_IN_ALERT_TITLE } from './constants' ;
5
+ import './alert-modal.scss' ;
5
6
6
7
const StationLoginPresentational : React . FunctionComponent < StationLoginPresentationalProps > = ( props ) => {
7
- const {
8
- name,
9
- teams,
10
- loginOptions,
11
- login,
12
- logout,
13
- relogin,
14
- setDeviceType,
15
- setDialNumber,
16
- setTeam,
17
- isAgentLoggedIn,
18
- deviceType
19
- } = props ; // TODO: Use the loginSuccess, loginFailure, logoutSuccess props returned fromthe API response via helper file to reflect UI changes
8
+ const { name, teams, loginOptions, login, logout, relogin, setDeviceType, setDialNumber, setTeam, isAgentLoggedIn, deviceType, showMultipleLoginAlert, handleContinue} = props ; // TODO: Use the loginSuccess, loginFailure, logoutSuccess props returned fromthe API response via helper file to reflect UI changes
9
+ const modalRef = useRef < HTMLDialogElement > ( null ) ;
20
10
21
11
useEffect ( ( ) => {
22
12
const teamsDropdown = document . getElementById ( 'teamsDropdown' ) as HTMLSelectElement ;
@@ -37,7 +27,7 @@ const StationLoginPresentational: React.FunctionComponent<StationLoginPresentati
37
27
}
38
28
}
39
29
if ( loginOptions . length > 0 ) {
40
- loginOptions . forEach ( ( options ) => {
30
+ loginOptions . forEach ( ( options ) => {
41
31
const option = document . createElement ( 'option' ) ;
42
32
option . text = options ;
43
33
option . value = options ;
@@ -46,6 +36,13 @@ const StationLoginPresentational: React.FunctionComponent<StationLoginPresentati
46
36
}
47
37
} , [ teams , loginOptions ] ) ;
48
38
39
+ useEffect ( ( ) => {
40
+ const modal = modalRef . current ;
41
+ if ( showMultipleLoginAlert && modal ) {
42
+ modal . showModal ( ) ;
43
+ }
44
+ } , [ showMultipleLoginAlert , modalRef ] ) ;
45
+
49
46
useEffect ( ( ) => {
50
47
if ( ! isAgentLoggedIn ) return ;
51
48
const agentLogin = document . querySelector ( '#LoginOption' ) as HTMLSelectElement ;
@@ -56,7 +53,7 @@ const StationLoginPresentational: React.FunctionComponent<StationLoginPresentati
56
53
}
57
54
} , [ isAgentLoggedIn ] ) ;
58
55
59
- const selectLoginOption = ( event : { target : { value : string ; } ; } ) => {
56
+ const selectLoginOption = ( event : { target : { value : string } } ) => {
60
57
const dialNumber = document . querySelector ( '#dialNumber' ) as HTMLInputElement ;
61
58
const deviceType = event . target . value ;
62
59
setDeviceType ( deviceType ) ;
@@ -67,41 +64,80 @@ const StationLoginPresentational: React.FunctionComponent<StationLoginPresentati
67
64
}
68
65
} ;
69
66
67
+ const continueClicked = ( ) => {
68
+ const modal = modalRef . current ;
69
+ if ( modal ) {
70
+ modal . close ( ) ;
71
+ handleContinue ( ) ;
72
+ }
73
+ } ;
74
+
70
75
function updateDN ( ) {
71
76
const dialNumber = document . querySelector ( '#dialNumber' ) as HTMLInputElement ;
72
77
setDialNumber ( dialNumber . value ) ;
73
78
}
74
79
75
80
return (
76
- < > < h1 data-testid = "station-login-heading" > { name } </ h1 >
77
- < div className = 'box' >
78
- < section className = "section-box" >
79
- < fieldset className = 'fieldset' >
80
- < legend className = 'legend-box' > Agent</ legend >
81
- < div style = { { display : 'flex' , flexDirection : 'column' , flexGrow : 1 } } >
82
- < div style = { { display : 'flex' , gap : '1rem' } } >
83
- < fieldset style = { { border : '1px solid #ccc' , borderRadius : '5px' , padding : '10px' , marginBottom : '20px' , flex : 0.69 } } >
84
- < legend className = 'legend-box' > Select Team</ legend >
85
- < select id = "teamsDropdown" className = 'select' > Teams</ select >
86
- </ fieldset >
87
- < fieldset className = 'fieldset' >
88
- < legend className = 'legend-box' > Agent Login</ legend >
89
- < select name = "LoginOption" id = "LoginOption" className = 'select' onChange = { selectLoginOption } >
90
- < option value = "" hidden > Choose Agent Login Option...</ option >
91
- </ select >
92
- < input className = 'input' id = "dialNumber" name = "dialNumber" placeholder = "Extension/Dial Number" type = "text" onInput = { updateDN } />
93
- { isAgentLoggedIn ? (
94
- < button id = "logoutAgent" className = 'btn' onClick = { logout } > Logout</ button >
95
- ) : (
96
- < button id = "AgentLogin" className = 'btn' onClick = { login } > Login</ button >
97
- ) }
98
- </ fieldset >
99
- </ div >
81
+ < div >
82
+ { showMultipleLoginAlert && (
83
+ < dialog ref = { modalRef } className = "modal" >
84
+ < h2 > { MULTIPLE_SIGN_IN_ALERT_TITLE } </ h2 >
85
+ < p > { MULTIPLE_SIGN_IN_ALERT_MESSAGE } </ p >
86
+ < div className = 'modal-content' >
87
+ < button id = "ContinueButton" data-testid = "ContinueButton" onClick = { continueClicked } > Continue</ button >
100
88
</ div >
101
- </ fieldset >
102
- </ section >
103
- </ div > </ >
89
+ </ dialog >
90
+ ) }
91
+ < h1 data-testid = "station-login-heading" > { name } </ h1 >
92
+ < div className = "box" >
93
+ < section className = "section-box" >
94
+ < fieldset className = "fieldset" >
95
+ < legend className = "legend-box" > Agent</ legend >
96
+ < div style = { { display : 'flex' , flexDirection : 'column' , flexGrow : 1 } } >
97
+ < div style = { { display : 'flex' , gap : '1rem' } } >
98
+ < fieldset
99
+ style = { {
100
+ border : '1px solid #ccc' ,
101
+ borderRadius : '5px' ,
102
+ padding : '10px' ,
103
+ marginBottom : '20px' ,
104
+ flex : 0.69 ,
105
+ } }
106
+ >
107
+ < legend className = "legend-box" > Select Team</ legend >
108
+ < select id = "teamsDropdown" className = "select" >
109
+ Teams
110
+ </ select >
111
+ </ fieldset >
112
+ < fieldset className = "fieldset" >
113
+ < legend className = "legend-box" > Agent Login</ legend >
114
+ < select name = "LoginOption" id = "LoginOption" className = "select" onChange = { selectLoginOption } >
115
+ < option value = "" hidden >
116
+ Choose Agent Login Option...
117
+ </ option >
118
+ </ select >
119
+ < input
120
+ className = "input"
121
+ id = "dialNumber"
122
+ name = "dialNumber"
123
+ placeholder = "Extension/Dial Number"
124
+ type = "text"
125
+ onInput = { updateDN }
126
+ />
127
+ < button id = "AgentLogin" className = "btn" onClick = { login } >
128
+ Login
129
+ </ button >
130
+ < button id = "logoutAgent" className = "btn" onClick = { logout } >
131
+ Logout
132
+ </ button >
133
+ </ fieldset >
134
+ </ div >
135
+ </ div >
136
+ </ fieldset >
137
+ </ section >
138
+ </ div >
139
+ </ div >
104
140
) ;
105
141
} ;
106
142
107
- export default StationLoginPresentational ;
143
+ export default StationLoginPresentational ;
0 commit comments