This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathMain.tsx
More file actions
177 lines (161 loc) · 6.61 KB
/
Main.tsx
File metadata and controls
177 lines (161 loc) · 6.61 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import { useEffect, useState } from "react"
import { shallowEqual } from "react-redux"
import { Layout, Menu, Row, Col, Result, Button, Drawer, Avatar, Dropdown, Badge} from "antd"
import { SettingFilled } from "@ant-design/icons"
import { Helmet } from "react-helmet"
import { useAppSelector, useAppDispatch } from "../redux/hooks"
import { init, searchDeployments, searchReviews, fetchLicense, notifyDeploymentEvent, notifyReviewmentEvent, mainSlice as slice } from "../redux/main"
import { subscribeEvents } from "../apis"
import RecentActivities from "../components/RecentActivities"
import LicenseFooter from "../components/LicenseFooter"
import Logo from "../logo.svg"
const { Header, Content, Footer } = Layout
// eslint-disable-next-line
export default function Main(props: any) {
const {
available,
authorized,
expired,
user,
deployments,
reviews,
license,
} = useAppSelector(state => state.main, shallowEqual)
const dispatch = useAppDispatch()
useEffect(() => {
dispatch(init())
dispatch(searchDeployments())
dispatch(searchReviews())
dispatch(fetchLicense())
const sub = subscribeEvents((event) => {
dispatch(slice.actions.handleDeploymentEvent(event))
dispatch(slice.actions.handleReviewEvent(event))
dispatch(notifyDeploymentEvent(event))
dispatch(notifyReviewmentEvent(event))
})
return () => {
sub.close()
}
}, [dispatch])
const onClickRetry = () => {
dispatch(slice.actions.setAvailable(true))
dispatch(slice.actions.setExpired(false))
}
const [ isRecentActivitiesVisible, setRecentActivitiesVisible ] = useState(false)
const showRecentActivities = () => {
setRecentActivitiesVisible(true)
}
const onCloseRecentActivities = () => {
setRecentActivitiesVisible(false)
}
// Count of recent activities.
const countActivities = deployments.length + reviews.length
let content: React.ReactElement
if (!available) {
content = <Result
style={{paddingTop: '120px'}}
status="error"
title="Server Internal Error"
subTitle="Sorry, something went wrong. Contact administrator."
extra={[<Button key="console" type="primary" onClick={onClickRetry}>Retry</Button>]}
/>
} else if (!authorized) {
content = <Result
style={{paddingTop: '120px'}}
status="warning"
title="Unauthorized Error"
subTitle="Sorry, you are not authorized."
extra={[<Button key="console" type="primary" href="/">Sign in</Button>]}
/>
} else if (expired) {
content = <Result
style={{paddingTop: '120px'}}
status="warning"
title="License Expired"
subTitle="Sorry, the license is expired."
extra={[<Button key="console" type="primary" onClick={onClickRetry}>Retry</Button>]}
/>
} else {
content = props.children
}
return (
<Layout className="layout">
<Helmet>
<title>Gitploy</title>
{(deployments.length + reviews.length > 0)?
<link rel="icon" href="/spinner.ico" />:
<link rel="icon" href="/favicon.ico" />}
</Helmet>
<Header>
<Row>
<Col span="16">
<Menu theme="dark" mode="horizontal" >
<Menu.Item key={0}><a href="/"><img src={Logo} style={{width: 62}}/></a></Menu.Item>
<Menu.Item key={1}><a href="/">Home</a></Menu.Item>
{(user?.admin)? <Menu.Item key={2}><a href="/members">Members</a></Menu.Item>: null}
</Menu>
</Col>
<Col span="8" style={{textAlign: "right"}}>
<Badge
size="small"
count={countActivities}
>
<Button
type="primary"
shape="circle"
icon={<SettingFilled spin={countActivities !== 0 }/>}
onClick={showRecentActivities}
/>
</Badge>
<Drawer title="Recent Activities"
placement="right"
width={400}
visible={isRecentActivitiesVisible}
onClose={onCloseRecentActivities}
>
<RecentActivities
deployments={deployments}
reviews={reviews}
/>
</Drawer>
{/* Avatar */}
{(authorized) ?
<Dropdown overlay={
<Menu>
<Menu.Item key="0">
<a href="/settings">Settings</a>
</Menu.Item>
<Menu.Divider />
<Menu.Item key="1">
<a href="https://www.gitploy.io/docs/" target="_blank">Read Docs</a>
</Menu.Item>
<Menu.Item key="2">
<a href="/signout">Sign out</a>
</Menu.Item>
</Menu>
}>
<Avatar src={user?.avatar}/>
</ Dropdown>
: <a href="/" style={{color: "white"}}>Sign in</a>}
</Col>
</Row>
</Header>
<Content style={{ padding: '50px 50px' }}>
<Row>
<Col
span={22}
offset={1}
md={{span: 14, offset: 5}}
lg={{span: 10, offset: 7}}>
{content}
</Col>
</Row>
</Content>
<Footer style={{ textAlign: 'center' }}>
<LicenseFooter license={license} />
Gitploy ©2021 Created by Gitploy.IO
</Footer>
</Layout>
)
}