Skip to content

Commit 769119a

Browse files
committed
added delete account button
1 parent 8070dc0 commit 769119a

File tree

1 file changed

+83
-9
lines changed

1 file changed

+83
-9
lines changed

src/main/webapp/app/pages/companyPage/CompanyPage.tsx

+83-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { observer } from 'mobx-react';
2+
import { inject, observer } from 'mobx-react';
33
import { getSectionClassName } from 'app/pages/account/AccountUtils';
44
import { AvField, AvForm } from 'availity-reactstrap-validation';
55
import {
@@ -10,6 +10,7 @@ import {
1010
LicenseModel,
1111
LicenseStatus,
1212
PAGE_ROUTE,
13+
REDIRECT_TIMEOUT_MILLISECONDS,
1314
} from 'app/config/constants';
1415
import { Alert, Button, Col, Row } from 'react-bootstrap';
1516
import {
@@ -67,11 +68,16 @@ import {
6768
import UsageText from 'app/shared/texts/UsageText';
6869
import { DateSelector } from 'app/components/dateSelector/DateSelector';
6970
import { DownloadButton } from 'app/components/downloadButton/DownloadButton';
71+
import { RouterStore } from 'mobx-react-router';
7072

7173
interface MatchParams {
7274
id: string;
7375
}
7476

77+
interface ICompanyPage extends RouteComponentProps<MatchParams> {
78+
routing: RouterStore;
79+
}
80+
7581
type SelectOptionType = {
7682
label: string;
7783
value: string;
@@ -97,10 +103,15 @@ const LICENSE_STATUS_UPDATE_MESSAGES = {
97103
},
98104
};
99105

106+
enum SimpleConfirmModalType {
107+
NA,
108+
DELETE_COMPANY,
109+
UPDATE_COMPANY,
110+
}
111+
112+
@inject('routing')
100113
@observer
101-
export default class CompanyPage extends React.Component<
102-
RouteComponentProps<MatchParams>
103-
> {
114+
export default class CompanyPage extends React.Component<ICompanyPage> {
104115
@observable getCompanyStatus = PromiseStatus.pending;
105116
@observable getCompanyUsersStatus = PromiseStatus.pending;
106117
@observable getDropdownUsersStatus = PromiseStatus.pending;
@@ -118,10 +129,13 @@ export default class CompanyPage extends React.Component<
118129
@observable dropDownUsers: SelectOptionType[] = [];
119130
@observable selectedUsersOptions: SelectOptionType[] = [];
120131

132+
@observable simpleConfirmModalType: SimpleConfirmModalType =
133+
SimpleConfirmModalType.NA;
134+
121135
@observable resourcesTypeToggleValue: ToggleValue =
122136
ToggleValue.PUBLIC_RESOURCES;
123137

124-
constructor(props: RouteComponentProps<MatchParams>) {
138+
constructor(props: ICompanyPage) {
125139
super(props);
126140
this.getCompany();
127141
this.getDropdownUsers();
@@ -182,7 +196,7 @@ export default class CompanyPage extends React.Component<
182196
}
183197

184198
@action.bound
185-
updateCompany() {
199+
onConfirmUpdateCompany() {
186200
this.showLicenseChangeModal = false;
187201
this.getCompanyStatus = PromiseStatus.pending;
188202
this.getCompanyUsersStatus = PromiseStatus.pending;
@@ -218,6 +232,37 @@ export default class CompanyPage extends React.Component<
218232
});
219233
}
220234

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+
221266
@action.bound
222267
async verifyUserEmail(user: UserDTO) {
223268
try {
@@ -253,7 +298,7 @@ export default class CompanyPage extends React.Component<
253298
this.selectedLicenseStatus
254299
];
255300
} else {
256-
this.updateCompany();
301+
this.onConfirmUpdateCompany();
257302
}
258303
}
259304

@@ -876,13 +921,42 @@ export default class CompanyPage extends React.Component<
876921
</Button>
877922
</Col>
878923
</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>
879940
</AvForm>
880941
<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"
881952
show={this.showLicenseChangeModal}
882953
title={'Review Company Changes'}
883954
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}
886960
/>
887961
</>
888962
</DocumentTitle>

0 commit comments

Comments
 (0)