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,10 +103,15 @@ 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 ;
@@ -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,7 +196,7 @@ export default class CompanyPage extends React.Component<
182
196
}
183
197
184
198
@action . bound
185
- updateCompany ( ) {
199
+ onConfirmUpdateCompany ( ) {
186
200
this . showLicenseChangeModal = false ;
187
201
this . getCompanyStatus = PromiseStatus . pending ;
188
202
this . getCompanyUsersStatus = PromiseStatus . pending ;
@@ -218,6 +232,37 @@ export default class CompanyPage extends React.Component<
218
232
} ) ;
219
233
}
220
234
235
+ @autobind
236
+ onConfirmDeleteAccountButton ( ) {
237
+ client . deleteCompanyDomainUsingDELETE ( { id : this . company . id } ) . then (
238
+ deletedUser => {
239
+ notifySuccess (
240
+ 'Deleted company, we will redirect you to the users page.'
241
+ ) ;
242
+ setTimeout ( ( ) => {
243
+ this . props . routing . history . push ( PAGE_ROUTE . ADMIN_USER_DETAILS ) ;
244
+ } , REDIRECT_TIMEOUT_MILLISECONDS ) ;
245
+ } ,
246
+ ( error : Error ) => notifyError ( error )
247
+ ) ;
248
+ }
249
+
250
+ @autobind
251
+ onConfirmSimpleConfirmModal ( ) {
252
+ switch ( this . simpleConfirmModalType ) {
253
+ case SimpleConfirmModalType . UPDATE_COMPANY :
254
+ this . onConfirmUpdateCompany ( ) ;
255
+ break ;
256
+ case SimpleConfirmModalType . DELETE_COMPANY :
257
+ this . onConfirmDeleteAccountButton ( ) ;
258
+ break ;
259
+ case SimpleConfirmModalType . NA :
260
+ default :
261
+ break ;
262
+ }
263
+ this . simpleConfirmModalType = SimpleConfirmModalType . NA ;
264
+ }
265
+
221
266
@action . bound
222
267
async verifyUserEmail ( user : UserDTO ) {
223
268
try {
@@ -253,7 +298,7 @@ export default class CompanyPage extends React.Component<
253
298
this . selectedLicenseStatus
254
299
] ;
255
300
} else {
256
- this . updateCompany ( ) ;
301
+ this . onConfirmUpdateCompany ( ) ;
257
302
}
258
303
}
259
304
@@ -876,13 +921,42 @@ export default class CompanyPage extends React.Component<
876
921
</ Button >
877
922
</ Col >
878
923
</ Row >
924
+ < Row >
925
+ < Col className = { getSectionClassName ( ) } >
926
+ < div className = { 'my-2 text-danger' } > Danger Zone</ div >
927
+ < div >
928
+ < Button
929
+ variant = "danger"
930
+ onClick = { ( ) => {
931
+ this . simpleConfirmModalType =
932
+ SimpleConfirmModalType . DELETE_COMPANY ;
933
+ } }
934
+ >
935
+ Delete Account
936
+ </ Button >
937
+ </ div >
938
+ </ Col >
939
+ </ Row >
879
940
</ AvForm >
880
941
< SimpleConfirmModal
942
+ key = "company-page-simple-confirm-modal"
943
+ show = { this . showLicenseChangeModal }
944
+ onCancel = { ( ) =>
945
+ ( this . simpleConfirmModalType =
946
+ SimpleConfirmModalType . NA )
947
+ }
948
+ onConfirm = { this . onConfirmSimpleConfirmModal }
949
+ />
950
+ < SimpleConfirmModal
951
+ key = "company-page-simple-confirm-modal"
881
952
show = { this . showLicenseChangeModal }
882
953
title = { 'Review Company Changes' }
883
954
body = { this . licenseChangeModalBody }
884
- onCancel = { ( ) => ( this . showLicenseChangeModal = false ) }
885
- onConfirm = { this . updateCompany }
955
+ onCancel = { ( ) =>
956
+ ( this . simpleConfirmModalType =
957
+ SimpleConfirmModalType . NA )
958
+ }
959
+ onConfirm = { this . onConfirmUpdateCompany }
886
960
/>
887
961
</ >
888
962
</ DocumentTitle >
0 commit comments