--
This commit is contained in:
parent
8fcc733093
commit
231adbe93f
123 changed files with 16683 additions and 62496 deletions
33
frontend/src/components/modules/NavBar.jsx
Normal file
33
frontend/src/components/modules/NavBar.jsx
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
|
||||
import React from 'react';
|
||||
import { Nav, Navbar, NavItem } from 'react-bootstrap';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import NavLinkItem from './NavLinkItem';
|
||||
import store from '../../redux/store';
|
||||
import LogOut from '../../auth/logout';
|
||||
|
||||
export default () => (
|
||||
<Navbar expand="lg" collapseOnSelect bg="dark" variant="dark" fixed="top">
|
||||
<Navbar.Brand>Geolosys Configurator</Navbar.Brand>
|
||||
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
|
||||
<Navbar.Collapse>
|
||||
<Nav className="mr-auto">
|
||||
<NavLinkItem name="Blog" dest="/" icon={faBook} />
|
||||
{store.getState().isAuthenticated && (
|
||||
<div>
|
||||
<NavLinkItem name="Your Configs" dest="/manage" icon={faEdit} />
|
||||
<NavItem style={{ cursor: 'pointer' }} onClick={LogOut}>
|
||||
<div className="nav-link nav-sign-out">
|
||||
<span>
|
||||
<FontAwesomeIcon icon={faSignOutAlt} />
|
||||
{' '}
|
||||
Sign Out
|
||||
</span>
|
||||
</div>
|
||||
</NavItem>
|
||||
</div>
|
||||
)}
|
||||
</Nav>
|
||||
</Navbar.Collapse>
|
||||
</Navbar>
|
||||
);
|
||||
18
frontend/src/components/modules/NavLinkItem.jsx
Normal file
18
frontend/src/components/modules/NavLinkItem.jsx
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import React from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import { NavItem } from 'react-bootstrap';
|
||||
|
||||
export default ({
|
||||
name, dest, icon,
|
||||
}) => (
|
||||
<NavItem>
|
||||
<NavLink exact className="nav-link" activeClassName="nav-link active" to={dest}>
|
||||
<span>
|
||||
{icon && (<FontAwesomeIcon icon={icon} />)}
|
||||
{' '}
|
||||
{name}
|
||||
</span>
|
||||
</NavLink>
|
||||
</NavItem>
|
||||
);
|
||||
21
frontend/src/components/modules/Notification.jsx
Normal file
21
frontend/src/components/modules/Notification.jsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import React from 'react';
|
||||
import { Modal } from 'react-bootstrap';
|
||||
|
||||
export default ({
|
||||
title, contents, show, onHide,
|
||||
}) => (
|
||||
<Modal
|
||||
show={show}
|
||||
onHide={onHide}
|
||||
>
|
||||
<Modal.Header closeButton>
|
||||
<Modal.Title className="text-center">
|
||||
{title}
|
||||
</Modal.Title>
|
||||
</Modal.Header>
|
||||
|
||||
<Modal.Body>
|
||||
{contents}
|
||||
</Modal.Body>
|
||||
</Modal>
|
||||
);
|
||||
90
frontend/src/components/view/Login.jsx
Normal file
90
frontend/src/components/view/Login.jsx
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import { Button, Container, Form } from 'react-bootstrap';
|
||||
import { connect } from 'react-redux';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faSignInAlt } from '@fortawesome/free-solid-svg-icons';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
import postLogin from '../../axios/Login';
|
||||
import Notification from '../modules/Notification';
|
||||
|
||||
const LoginComponent = ({
|
||||
isAuthenticated,
|
||||
}) => {
|
||||
const [state, setState] = useState({
|
||||
username: null,
|
||||
password: null,
|
||||
});
|
||||
|
||||
const [error, setError] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated) {
|
||||
window.location.reload();
|
||||
}
|
||||
}, [isAuthenticated]);
|
||||
|
||||
const submit = (evt) => {
|
||||
evt.preventDefault();
|
||||
|
||||
postLogin(state).catch((ex) => {
|
||||
setError(`${ex.response.data}`);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div>
|
||||
<div className="v-center">
|
||||
<Container
|
||||
className="mx-auto perfect-width"
|
||||
>
|
||||
<h2 className="text-center">
|
||||
Admin Login
|
||||
</h2>
|
||||
<Form onSubmit={submit}>
|
||||
<Form.Group>
|
||||
<Form.Label>
|
||||
Username
|
||||
</Form.Label>
|
||||
<Form.Control
|
||||
type="text"
|
||||
onChange={(evt) => { setState({ ...state, username: evt.target.value }); }}
|
||||
/>
|
||||
</Form.Group>
|
||||
<Form.Group>
|
||||
<Form.Label>
|
||||
Password
|
||||
</Form.Label>
|
||||
<Form.Control
|
||||
type="password"
|
||||
onChange={(evt) => { setState({ ...state, password: evt.target.value }); }}
|
||||
/>
|
||||
</Form.Group>
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
>
|
||||
<FontAwesomeIcon icon={faSignInAlt} />
|
||||
{' '}
|
||||
Log In
|
||||
</Button>
|
||||
</Form>
|
||||
</Container>
|
||||
</div>
|
||||
<Notification
|
||||
title="Failed to Log In"
|
||||
contents={error}
|
||||
show={!!error}
|
||||
onHide={() => setError(null)}
|
||||
/>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
isAuthenticated: state.isAuthenticated,
|
||||
user: state.user,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(LoginComponent);
|
||||
Loading…
Reference in a new issue