Web:Client:DeleteProfileEverDialog: rewrite to functional component

This commit is contained in:
Timofey Boyko 2023-04-05 10:52:38 +03:00
parent 5b5834294c
commit d036879037

View File

@ -17,17 +17,12 @@ import { combineUrl } from "@docspace/common/utils";
const { deleteUser } = api.people; //TODO: Move to action
const { Filter } = api;
class DeleteProfileEverDialogComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
isRequestRunning: false,
};
}
onDeleteProfileEver = () => {
const { user, t, history, homepage, setFilter, onClose } = this.props;
const DeleteProfileEverDialogComponent = (props) => {
const { user, t, history, homepage, setFilter, onClose, tReady, visible } =
props;
const [isRequestRunning, setIsRequestRunning] = React.useState(false);
const onDeleteProfileEver = () => {
const filter = Filter.getDefault();
const params = filter.toUrlParams();
@ -37,66 +32,55 @@ class DeleteProfileEverDialogComponent extends React.Component {
`/accounts/filter?${params}`
);
this.setState({ isRequestRunning: true }, () => {
deleteUser(user.id)
.then((res) => {
toastr.success(t("SuccessfullyDeleteUserInfoMessage"));
history.push(url, params);
setFilter(filter);
return;
})
.catch((error) => toastr.error(error))
.finally(() => onClose());
});
setIsRequestRunning(true);
deleteUser(user.id)
.then((res) => {
toastr.success(t("SuccessfullyDeleteUserInfoMessage"));
history.push(url, params);
setFilter(filter);
return;
})
.catch((error) => toastr.error(error))
.finally(() => onClose());
};
render() {
console.log("DeleteProfileEverDialog render");
const { t, tReady, visible, user, onClose, userCaption } = this.props;
const { isRequestRunning } = this.state;
return (
<ModalDialogContainer
isLoading={!tReady}
visible={visible}
onClose={onClose}
>
<ModalDialog.Header>{t("DeleteUser")}</ModalDialog.Header>
<ModalDialog.Body>
<Text>
<Trans
i18nKey="DeleteUserMessage"
ns="DeleteProfileEverDialog"
t={t}
>
{{ userCaption: t("Common:User") }}{" "}
<strong>{{ user: user.displayName }}</strong>
will be deleted. User personal documents which are available to
others will be deleted.
</Trans>
</Text>
</ModalDialog.Body>
<ModalDialog.Footer>
<Button
key="OKBtn"
label={t("Common:Delete")}
size="normal"
primary={true}
scale
onClick={this.onDeleteProfileEver}
isLoading={isRequestRunning}
/>
<Button
label={t("Common:CancelButton")}
size="normal"
scale
onClick={onClose}
/>
</ModalDialog.Footer>
</ModalDialogContainer>
);
}
}
return (
<ModalDialogContainer
isLoading={!tReady}
visible={visible}
onClose={onClose}
>
<ModalDialog.Header>{t("DeleteUser")}</ModalDialog.Header>
<ModalDialog.Body>
<Text>
<Trans i18nKey="DeleteUserMessage" ns="DeleteProfileEverDialog" t={t}>
{{ userCaption: t("Common:User") }}{" "}
<strong>{{ user: user.displayName }}</strong>
will be deleted. User personal documents which are available to
others will be deleted.
</Trans>
</Text>
</ModalDialog.Body>
<ModalDialog.Footer>
<Button
key="OKBtn"
label={t("Common:Delete")}
size="normal"
primary={true}
scale
onClick={onDeleteProfileEver}
isLoading={isRequestRunning}
/>
<Button
label={t("Common:CancelButton")}
size="normal"
scale
onClick={onClose}
/>
</ModalDialog.Footer>
</ModalDialogContainer>
);
};
const DeleteProfileEverDialog = withTranslation([
"DeleteProfileEverDialog",