-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathAlertContent.tsx
More file actions
112 lines (107 loc) · 4.26 KB
/
Copy pathAlertContent.tsx
File metadata and controls
112 lines (107 loc) · 4.26 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
import { ReactElement } from 'react'
import { tokens } from '@equinor/eds-tokens'
import { Mission } from 'models/Mission'
import { Icons } from 'utils/icons'
import { AlertType, AutoScheduleFailedMissionDict } from 'components/Contexts/AlertContext'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { AlertCategory } from './AlertsBanner'
import { AlertListContents } from './AlertsListItem'
import { AlertBannerLayout } from './AlertBannerLayout'
import { AutoScheduleFailContent } from './AutoScheduleFailAlert'
import { FailedMissionAlertContent, FailedMissionAlertListContent } from './FailedMissionAlert'
import { DockAlertContent, DockAlertListContent } from './DockAlert'
const dangerColor = tokens.colors.interactive.danger__resting.hex
const infoColor = tokens.colors.interactive.primary__resting.hex
export type AlertContent =
| { kind: 'failedMissions'; missions: Mission[] }
| { kind: 'autoScheduleFail'; failedMissions: AutoScheduleFailedMissionDict }
| { kind: 'dock'; dockType: AlertType }
| { kind: 'requestFail'; message: string }
| { kind: 'failure'; title: string; message: string }
| { kind: 'info'; title: string; message: string }
export const getAlertCategory = (content: AlertContent): AlertCategory => {
switch (content.kind) {
case 'dock':
return content.dockType === AlertType.RequestDock ? AlertCategory.WARNING : AlertCategory.INFO
case 'info':
return AlertCategory.INFO
default:
return AlertCategory.ERROR
}
}
export const AlertBannerContent = ({ content }: { content: AlertContent }): ReactElement => {
const { TranslateText } = useLanguageContext()
switch (content.kind) {
case 'failedMissions':
return <FailedMissionAlertContent missions={content.missions} />
case 'autoScheduleFail':
return <AutoScheduleFailContent failedMissions={content.failedMissions} />
case 'dock':
return <DockAlertContent alertType={content.dockType} />
case 'requestFail':
return (
<AlertBannerLayout
icon={Icons.Failed}
iconColor={dangerColor}
title={TranslateText('Request error')}
message={content.message}
/>
)
case 'failure':
return (
<AlertBannerLayout
icon={Icons.Failed}
iconColor={dangerColor}
title={content.title}
message={content.message}
/>
)
case 'info':
return (
<AlertBannerLayout
icon={Icons.Info}
iconColor={infoColor}
title={content.title}
message={content.message}
/>
)
}
}
export const AlertListItemContent = ({ content }: { content: AlertContent }): ReactElement => {
const { TranslateText } = useLanguageContext()
switch (content.kind) {
case 'failedMissions':
return <FailedMissionAlertListContent missions={content.missions} />
case 'autoScheduleFail':
return <AutoScheduleFailContent failedMissions={content.failedMissions} />
case 'dock':
return <DockAlertListContent alertType={content.dockType} />
case 'requestFail':
return (
<AlertListContents
icon={Icons.Failed}
iconColor={dangerColor}
alertTitle={TranslateText('Request error')}
alertText={content.message}
/>
)
case 'failure':
return (
<AlertListContents
icon={Icons.Failed}
iconColor={dangerColor}
alertTitle={TranslateText(content.title)}
alertText={TranslateText(content.message)}
/>
)
case 'info':
return (
<AlertListContents
icon={Icons.Info}
iconColor={infoColor}
alertTitle={content.title}
alertText={content.message}
/>
)
}
}