forked from skupperproject/openshift-site-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSummaryPage.tsx
More file actions
136 lines (118 loc) · 3.9 KB
/
SummaryPage.tsx
File metadata and controls
136 lines (118 loc) · 3.9 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { useState, useEffect } from 'react';
import { I18nNamespace } from '@config/config';
import { useWatchedSkupperResource } from '@hooks/useSkupperWatchResource';
import { Icon, Bullseye, Spinner, TextContent, Text, TextVariants, Flex, FlexItem } from '@patternfly/react-core';
import { CheckCircleIcon, ExclamationCircleIcon } from '@patternfly/react-icons';
import { useTranslation } from 'react-i18next';
import { useLinkForm } from './hooks/useLinkForm';
const WizardContentHeight = '400px';
export const SummaryPage = function () {
const { t } = useTranslation(I18nNamespace);
const {
state: { name, fileName },
setIsLoading: setExternalLoading,
validated: error,
setValidated
} = useLinkForm();
const [isLoading, setIsLoading] = useState(true);
const { data: accessTokens, error: accessTokenError } = useWatchedSkupperResource({
kind: 'AccessToken',
isList: false,
name: name || fileName
});
const accessToken = accessTokens?.[0]?.rawData;
const { data: links } = useWatchedSkupperResource({ kind: 'Link', isList: false, name: name || fileName });
const link = links?.[0]?.rawData;
const hasStatus = accessToken?.status?.status || link?.status?.status;
const isConfigured = link?.status?.conditions.find(({ type, status }) => type === 'Configured' && status === 'True');
const hasError =
accessToken?.status?.status === 'Error' ||
(accessToken?.status?.status && link?.status?.status && link?.status?.status === 'Error');
const errorMessage = link?.status?.status || accessToken?.status?.message;
useEffect(() => {
if (accessTokenError) {
setIsLoading(false);
setExternalLoading(false);
setValidated('Generic error');
}
if (hasError) {
setIsLoading(false);
setExternalLoading(false);
setValidated(errorMessage);
}
if (isConfigured) {
setValidated(undefined);
setIsLoading(false);
setExternalLoading(false);
return;
}
if (!hasStatus) {
return;
}
}, [
setValidated,
setIsLoading,
setExternalLoading,
accessTokenError,
isConfigured,
hasError,
hasStatus,
errorMessage
]);
if (isLoading) {
return (
<div style={{ height: WizardContentHeight }}>
<Bullseye>
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
<Spinner />
<p>{t('Creating link...Click Dismiss to leave the page')}</p>
</div>
</Bullseye>
</div>
);
}
if (error) {
return (
<div style={{ height: WizardContentHeight }}>
<Bullseye>
<Flex alignItems={{ default: 'alignItemsCenter' }} direction={{ default: 'column' }}>
<FlexItem>
<Icon size="xl" status="danger">
<ExclamationCircleIcon />
</Icon>
</FlexItem>
<FlexItem>
<TextContent style={{ textAlign: 'center' }}>
<Text component={TextVariants.h2} style={{ textAlign: 'center' }}>
{t('It seems there was an error while creating the link')}
</Text>
<Text>{error}</Text>
</TextContent>
</FlexItem>
</Flex>
</Bullseye>
</div>
);
}
return (
<div style={{ height: WizardContentHeight }}>
<Bullseye>
<Flex alignItems={{ default: 'alignItemsCenter' }} direction={{ default: 'column' }}>
<FlexItem>
<Icon size="xl" status="success">
<CheckCircleIcon />
</Icon>
</FlexItem>
<FlexItem>
<TextContent>
<Text component={TextVariants.h2} style={{ textAlign: 'center' }}>
{t('Link created')}
</Text>
<Text>{t('Click Done to close the window')}</Text>
</TextContent>
</FlexItem>
</Flex>
</Bullseye>
</div>
);
};