Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.

Commit 4e48553

Browse files
author
Anisha1234
committed
adds login modal to overview page
1 parent c07eee5 commit 4e48553

File tree

4 files changed

+89
-10
lines changed

4 files changed

+89
-10
lines changed

src/components/LoginHint/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Title, Button } from '@patternfly/react-core';
77
store,
88
auth: auth.auth,
99
}))
10-
class Overview extends Component {
10+
class LoginHint extends Component {
1111
navigateToAuth = () => {
1212
const { dispatch } = this.props;
1313
dispatch(routerRedux.push(`/auth`));
@@ -33,4 +33,4 @@ class Overview extends Component {
3333
}
3434
}
3535

36-
export default Overview;
36+
export default LoginHint;

src/components/LoginModal/index.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React from 'react';
2+
import {
3+
Modal,
4+
ModalVariant,
5+
Button,
6+
TextContent,
7+
Text,
8+
TextVariants,
9+
} from '@patternfly/react-core';
10+
import { routerRedux } from 'dva/router';
11+
import { connect } from 'dva';
12+
13+
@connect(auth => ({
14+
auth: auth.auth,
15+
}))
16+
class LoginModal extends React.Component {
17+
constructor(props) {
18+
super(props);
19+
this.state = {
20+
isModalOpen: false,
21+
};
22+
}
23+
24+
componentDidMount() {
25+
this.handleModalToggle();
26+
}
27+
28+
handleModalToggle = () => {
29+
this.setState(({ isModalOpen }) => ({
30+
isModalOpen: !isModalOpen,
31+
}));
32+
};
33+
34+
handleModalCancel = () => {
35+
const { dispatch } = this.props;
36+
this.setState(({ isModalOpen }) => ({
37+
isModalOpen: !isModalOpen,
38+
}));
39+
dispatch(routerRedux.push(`/`));
40+
};
41+
42+
handleLoginModal = () => {
43+
const { dispatch } = this.props;
44+
this.setState(({ isModalOpen }) => ({
45+
isModalOpen: !isModalOpen,
46+
}));
47+
dispatch(routerRedux.push(`/auth`));
48+
};
49+
50+
render() {
51+
const { isModalOpen } = this.state;
52+
53+
return (
54+
<React.Fragment>
55+
<Modal
56+
variant={ModalVariant.small}
57+
isOpen={isModalOpen}
58+
onClose={this.handleModalCancel}
59+
showClose="false"
60+
actions={[
61+
<Button key="confirm" variant="primary" onClick={this.handleLoginModal}>
62+
Proceed
63+
</Button>,
64+
<Button key="cancel" variant="link" onClick={this.handleModalCancel}>
65+
Cancel
66+
</Button>,
67+
]}
68+
>
69+
<TextContent>
70+
<Text component={TextVariants.h4}>
71+
This action requires login. Please login to Pbench Dashboard to continue.
72+
</Text>
73+
</TextContent>
74+
</Modal>
75+
</React.Fragment>
76+
);
77+
}
78+
}
79+
80+
export default LoginModal;

src/pages/Overview/index.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
.dropdownContent {
7777
position: absolute;
7878
background-color: #f1f1f1;
79-
margin-right: -2%;
80-
min-width: 160px;
79+
margin-left: -5%;
80+
min-width: 130px;
8181
overflow: auto;
8282
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
8383
}

src/pages/PrivateRoute/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import React, { Component, Fragment } from 'react';
2-
import AuthLayout from '@/components/AuthLayout';
3-
import { routerRedux } from 'dva/router';
2+
// import AuthLayout from '@/components/AuthLayout';
3+
// import { routerRedux } from 'dva/router';
44
import { connect } from 'dva';
5+
import LoginModal from '@/components/LoginModal';
56

67
@connect(auth => ({
78
auth: auth.auth,
89
}))
910
class PrivateRoute extends Component {
1011
render() {
11-
const { children, auth, dispatch } = this.props;
12+
const { children, auth } = this.props;
1213

1314
if (auth.auth.username === 'admin') {
1415
return <Fragment>{children}</Fragment>;
1516
}
16-
17-
dispatch(routerRedux.push(`/auth`));
18-
return <AuthLayout />;
17+
return <LoginModal />;
1918
}
2019
}
2120
export default PrivateRoute;

0 commit comments

Comments
 (0)