forked from openshift-assisted/assisted-installer-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResetSingleClusterModal.tsx
103 lines (95 loc) · 2.56 KB
/
ResetSingleClusterModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React from 'react';
import {
Button,
Modal,
ModalVariant,
ButtonVariant,
Text,
TextContent,
Stack,
StackItem,
Alert,
} from '@patternfly/react-core';
import { useModalDialogsContext, ClustersService } from '@openshift-assisted/ui-lib/ocm';
import {
getApiErrorMessage,
handleApiError,
useTranslation,
} from '@openshift-assisted/ui-lib/common';
import { useNavigate } from 'react-router-dom-v5-compat';
const ResetSingleClusterModal: React.FC = () => {
const navigate = useNavigate();
const [isLoading, setIsLoading] = React.useState(false);
const [error, setError] = React.useState<{ title: string; message: string }>();
const { resetSingleClusterDialog } = useModalDialogsContext();
const { data, isOpen, close: onClose } = resetSingleClusterDialog;
const cluster = data?.cluster;
const { t } = useTranslation();
if (!cluster) {
return null;
}
const handleClose = () => {
setError(undefined);
onClose();
};
const handleResetAsync = async () => {
try {
setError(undefined);
setIsLoading(true);
await ClustersService.remove(cluster.id);
navigate(`/`);
} catch (e) {
handleApiError(e, () => {
setError({
title: t('ai:Failed to reset cluster installation'),
message: getApiErrorMessage(e),
});
});
} finally {
setIsLoading(false);
}
};
const actions = [
<Button
key="reset"
variant={ButtonVariant.danger}
onClick={() => void handleResetAsync()}
isDisabled={isLoading}
isLoading={isLoading}
>
{t('ai:Reset')}
</Button>,
<Button key="cancel" variant={ButtonVariant.link} onClick={handleClose} isDisabled={isLoading}>
{t('ai:Cancel')}
</Button>,
];
return (
<Modal
title={t('ai:Reset cluster')}
titleIconVariant="warning"
isOpen={isOpen}
variant={ModalVariant.small}
actions={actions}
onClose={handleClose}
>
<Stack hasGutter>
<StackItem>
<TextContent>
<Text component="p">
{t('ai:This will remove all current configurations and will revert to the defaults.')}
</Text>
<Text component="p">{t('ai:Are you sure you want to reset the cluster?')}</Text>
</TextContent>
</StackItem>
{error && (
<StackItem>
<Alert isInline variant="danger" title={error.title}>
{error.message}
</Alert>
</StackItem>
)}
</Stack>
</Modal>
);
};
export default ResetSingleClusterModal;