1
|
|
|
import React from "react"; |
2
|
|
|
import { useIntl, defineMessages } from "react-intl"; |
3
|
|
|
import { navigate } from "../../helpers/router"; |
4
|
|
|
|
5
|
|
|
interface ProgressTrackerItemProps { |
6
|
|
|
link: string; |
7
|
|
|
state: "active" | "complete" | "error" | "null"; |
8
|
|
|
label: string; |
9
|
|
|
title: string; |
10
|
|
|
fontColor?: string; |
11
|
|
|
dataIsLoading?: boolean; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
export const messages = defineMessages({ |
15
|
|
|
unreachableStep: { |
16
|
|
|
id: "progressTracker.unreachableStep", |
17
|
|
|
defaultMessage: "Must complete previous steps.", |
18
|
|
|
description: |
19
|
|
|
"Tooltip informing user to complete previous steps, before step it can become clickable.", |
20
|
|
|
}, |
21
|
|
|
}); |
22
|
|
|
|
23
|
|
|
const ProgressTrackerItem: React.FunctionComponent<ProgressTrackerItemProps> = ({ |
24
|
|
|
link, |
25
|
|
|
label, |
26
|
|
|
title, |
27
|
|
|
state, |
28
|
|
|
fontColor, |
29
|
|
|
dataIsLoading, |
30
|
|
|
}): React.ReactElement => { |
31
|
|
|
const intl = useIntl(); |
32
|
|
|
return ( |
33
|
|
|
<li |
34
|
|
|
className="tracker-item" |
35
|
|
|
data-tc-tracker-state={state} |
36
|
|
|
data-c-alignment="base(left)" |
37
|
|
|
data-c-color={fontColor} |
38
|
|
|
aria-hidden="true" |
39
|
|
|
> |
40
|
|
|
<span |
41
|
|
|
className="tracker-item-connect" |
42
|
|
|
style={{ |
43
|
|
|
backgroundColor: `${!dataIsLoading && |
44
|
|
|
(state === "null" ? "#969696" : "#008000")}`, |
45
|
|
|
}} |
46
|
|
|
/> |
47
|
|
|
{!dataIsLoading ? ( |
48
|
|
|
<div className="tracker-icon"> |
49
|
|
|
{state === "active" && <i className="fas fa-arrow-down" />} |
50
|
|
|
{state === "complete" && <i className="fas fa-check" />} |
51
|
|
|
{state === "error" && <i className="fas fa-exclamation-triangle" />} |
52
|
|
|
</div> |
53
|
|
|
) : ( |
54
|
|
|
<div className="tracker-icon"> |
55
|
|
|
{state !== "active" && <div className="spinner-loader" />} |
56
|
|
|
{state === "active" && <i className="fas fa-arrow-down" />} |
57
|
|
|
</div> |
58
|
|
|
)} |
59
|
|
|
{state !== "null" ? ( |
60
|
|
|
<a |
61
|
|
|
href={link} |
62
|
|
|
title={title} |
63
|
|
|
onClick={e => { |
64
|
|
|
e.preventDefault(); |
65
|
|
|
navigate(link); |
66
|
|
|
}} |
67
|
|
|
> |
68
|
|
|
<div className="tracker-title"> |
69
|
|
|
<span data-c-font-size="small">{label}</span> |
70
|
|
|
<span data-c-font-weight="bold">{title}</span> |
71
|
|
|
</div> |
72
|
|
|
</a> |
73
|
|
|
) : ( |
74
|
|
|
<div |
75
|
|
|
className="tracker-title" |
76
|
|
|
title={intl.formatMessage(messages.unreachableStep)} |
77
|
|
|
> |
78
|
|
|
<span data-c-font-size="small">{label}</span> |
79
|
|
|
<span data-c-font-weight="bold">{title}</span> |
80
|
|
|
</div> |
81
|
|
|
)} |
82
|
|
|
</li> |
83
|
|
|
); |
84
|
|
|
}; |
85
|
|
|
|
86
|
|
|
export default ProgressTrackerItem; |
87
|
|
|
|