1
1
import React from 'react' ;
2
- import { observer } from 'mobx-react' ;
2
+ import { inject , observer } from 'mobx-react' ;
3
3
import { getSectionClassName } from 'app/pages/account/AccountUtils' ;
4
4
import { AvField , AvForm } from 'availity-reactstrap-validation' ;
5
5
import {
@@ -10,6 +10,7 @@ import {
10
10
LicenseModel ,
11
11
LicenseStatus ,
12
12
PAGE_ROUTE ,
13
+ REDIRECT_TIMEOUT_MILLISECONDS ,
13
14
} from 'app/config/constants' ;
14
15
import { Alert , Button , Col , Row } from 'react-bootstrap' ;
15
16
import {
@@ -67,11 +68,16 @@ import {
67
68
import UsageText from 'app/shared/texts/UsageText' ;
68
69
import { DateSelector } from 'app/components/dateSelector/DateSelector' ;
69
70
import { DownloadButton } from 'app/components/downloadButton/DownloadButton' ;
71
+ import { RouterStore } from 'mobx-react-router' ;
70
72
71
73
interface MatchParams {
72
74
id : string ;
73
75
}
74
76
77
+ interface ICompanyPage extends RouteComponentProps < MatchParams > {
78
+ routing : RouterStore ;
79
+ }
80
+
75
81
type SelectOptionType = {
76
82
label : string ;
77
83
value : string ;
@@ -97,18 +103,23 @@ const LICENSE_STATUS_UPDATE_MESSAGES = {
97
103
} ,
98
104
} ;
99
105
106
+ enum SimpleConfirmModalType {
107
+ NA ,
108
+ DELETE_COMPANY ,
109
+ UPDATE_COMPANY ,
110
+ }
111
+
112
+ @inject ( 'routing' )
100
113
@observer
101
- export default class CompanyPage extends React . Component <
102
- RouteComponentProps < MatchParams >
103
- > {
114
+ export default class CompanyPage extends React . Component < ICompanyPage > {
104
115
@observable getCompanyStatus = PromiseStatus . pending ;
105
116
@observable getCompanyUsersStatus = PromiseStatus . pending ;
106
117
@observable getDropdownUsersStatus = PromiseStatus . pending ;
107
118
108
119
@observable selectedLicenseStatus : LicenseStatus ;
109
120
@observable conflictingDomains : string [ ] = [ ] ;
110
121
111
- @observable showLicenseChangeModal = false ;
122
+ @observable showModal = false ;
112
123
@observable confirmLicenseChangeModalText = '' ;
113
124
@observable formValues : any ;
114
125
@@ -118,10 +129,13 @@ export default class CompanyPage extends React.Component<
118
129
@observable dropDownUsers : SelectOptionType [ ] = [ ] ;
119
130
@observable selectedUsersOptions : SelectOptionType [ ] = [ ] ;
120
131
132
+ @observable simpleConfirmModalType : SimpleConfirmModalType =
133
+ SimpleConfirmModalType . NA ;
134
+
121
135
@observable resourcesTypeToggleValue : ToggleValue =
122
136
ToggleValue . PUBLIC_RESOURCES ;
123
137
124
- constructor ( props : RouteComponentProps < MatchParams > ) {
138
+ constructor ( props : ICompanyPage ) {
125
139
super ( props ) ;
126
140
this . getCompany ( ) ;
127
141
this . getDropdownUsers ( ) ;
@@ -182,8 +196,8 @@ export default class CompanyPage extends React.Component<
182
196
}
183
197
184
198
@action . bound
185
- updateCompany ( ) {
186
- this . showLicenseChangeModal = false ;
199
+ onConfirmUpdateCompany ( ) {
200
+ this . showModal = false ;
187
201
this . getCompanyStatus = PromiseStatus . pending ;
188
202
this . getCompanyUsersStatus = PromiseStatus . pending ;
189
203
this . getDropdownUsersStatus = PromiseStatus . pending ;
@@ -218,6 +232,38 @@ export default class CompanyPage extends React.Component<
218
232
} ) ;
219
233
}
220
234
235
+ @autobind
236
+ onConfirmDeleteAccountButton ( ) {
237
+ this . showModal = false ;
238
+ client . deleteCompanyUsingDELETE ( { id : this . company . id } ) . then (
239
+ ( ) => {
240
+ notifySuccess (
241
+ 'Deleted company, we will redirect you to the company details page.'
242
+ ) ;
243
+ setTimeout ( ( ) => {
244
+ this . props . routing . history . push ( PAGE_ROUTE . ADMIN_COMPANY_DETAILS ) ;
245
+ } , REDIRECT_TIMEOUT_MILLISECONDS ) ;
246
+ } ,
247
+ ( error : Error ) => notifyError ( error )
248
+ ) ;
249
+ }
250
+
251
+ @autobind
252
+ onConfirmSimpleConfirmModal ( ) {
253
+ switch ( this . simpleConfirmModalType ) {
254
+ case SimpleConfirmModalType . UPDATE_COMPANY :
255
+ this . onConfirmUpdateCompany ( ) ;
256
+ break ;
257
+ case SimpleConfirmModalType . DELETE_COMPANY :
258
+ this . onConfirmDeleteAccountButton ( ) ;
259
+ break ;
260
+ case SimpleConfirmModalType . NA :
261
+ default :
262
+ break ;
263
+ }
264
+ this . simpleConfirmModalType = SimpleConfirmModalType . NA ;
265
+ }
266
+
221
267
@action . bound
222
268
async verifyUserEmail ( user : UserDTO ) {
223
269
try {
@@ -247,13 +293,13 @@ export default class CompanyPage extends React.Component<
247
293
this . company . licenseStatus !== this . selectedLicenseStatus &&
248
294
this . companyUsers . length > 0
249
295
) {
250
- this . showLicenseChangeModal = true ;
296
+ this . showModal = true ;
251
297
this . confirmLicenseChangeModalText =
252
298
LICENSE_STATUS_UPDATE_MESSAGES [ this . company . licenseStatus ] [
253
299
this . selectedLicenseStatus
254
300
] ;
255
301
} else {
256
- this . updateCompany ( ) ;
302
+ this . onConfirmUpdateCompany ( ) ;
257
303
}
258
304
}
259
305
@@ -323,23 +369,41 @@ export default class CompanyPage extends React.Component<
323
369
option => ! hideOptions . includes ( option . value )
324
370
) ;
325
371
}
372
+ @computed
373
+ get licenseChangeModalTitle ( ) {
374
+ if ( this . simpleConfirmModalType === SimpleConfirmModalType . UPDATE_COMPANY ) {
375
+ return 'Review Company Changes' ;
376
+ } else if (
377
+ this . simpleConfirmModalType === SimpleConfirmModalType . DELETE_COMPANY
378
+ ) {
379
+ return 'Confirm Deleting Company' ;
380
+ }
381
+ }
326
382
327
383
@computed
328
384
get licenseChangeModalBody ( ) {
329
- return (
330
- < >
331
- < div >
332
- Are you sure you want to change the company's license status from{ ' ' }
333
- < span className = "font-weight-bold" > { this . company . licenseStatus } </ span > { ' ' }
334
- to{ ' ' }
335
- < span className = "font-weight-bold" > { this . selectedLicenseStatus } </ span >
336
- ?
337
- </ div >
338
- < Alert variant = { 'warning' } style = { { marginTop : '20px' } } >
339
- Warning: { this . confirmLicenseChangeModalText }
340
- </ Alert >
341
- </ >
342
- ) ;
385
+ if ( this . simpleConfirmModalType === SimpleConfirmModalType . UPDATE_COMPANY ) {
386
+ return (
387
+ < >
388
+ < div >
389
+ Are you sure you want to change the company's license status from{ ' ' }
390
+ < span className = "font-weight-bold" >
391
+ { this . company . licenseStatus }
392
+ </ span > { ' ' }
393
+ to{ ' ' }
394
+ < span className = "font-weight-bold" >
395
+ { this . selectedLicenseStatus }
396
+ </ span >
397
+ ?
398
+ </ div >
399
+ < Alert variant = { 'warning' } style = { { marginTop : '20px' } } >
400
+ Warning: { this . confirmLicenseChangeModalText }
401
+ </ Alert >
402
+ </ >
403
+ ) ;
404
+ } else {
405
+ return undefined ;
406
+ }
343
407
}
344
408
345
409
@computed
@@ -876,13 +940,34 @@ export default class CompanyPage extends React.Component<
876
940
</ Button >
877
941
</ Col >
878
942
</ Row >
943
+ < Row >
944
+ < Col className = { getSectionClassName ( ) } >
945
+ < div className = { 'my-2 text-danger' } > Danger Zone</ div >
946
+ < div >
947
+ < Button
948
+ variant = "danger"
949
+ onClick = { ( ) => {
950
+ this . showModal = true ;
951
+ this . simpleConfirmModalType =
952
+ SimpleConfirmModalType . DELETE_COMPANY ;
953
+ } }
954
+ >
955
+ Delete Account
956
+ </ Button >
957
+ </ div >
958
+ </ Col >
959
+ </ Row >
879
960
</ AvForm >
880
961
< SimpleConfirmModal
881
- show = { this . showLicenseChangeModal }
882
- title = { 'Review Company Changes' }
962
+ key = "company-page-simple-confirm-modal"
963
+ show = { this . showModal }
964
+ title = { this . licenseChangeModalTitle }
883
965
body = { this . licenseChangeModalBody }
884
- onCancel = { ( ) => ( this . showLicenseChangeModal = false ) }
885
- onConfirm = { this . updateCompany }
966
+ onCancel = { ( ) => {
967
+ this . showModal = false ;
968
+ this . simpleConfirmModalType = SimpleConfirmModalType . NA ;
969
+ } }
970
+ onConfirm = { this . onConfirmSimpleConfirmModal }
886
971
/>
887
972
</ >
888
973
</ DocumentTitle >
0 commit comments