linking admin and login screens

This commit is contained in:
Roland Osborne 2022-06-03 11:49:01 -07:00
parent ca238ecc04
commit 36fc20f226
6 changed files with 37 additions and 2 deletions

View File

@ -3,7 +3,8 @@ import { Input, Button, Space } from 'antd';
import { AdminWrapper, LoginWrapper, TokenInput } from './Admin.styled'; import { AdminWrapper, LoginWrapper, TokenInput } from './Admin.styled';
import { useAdmin } from './useAdmin.hook'; import { useAdmin } from './useAdmin.hook';
import { Dashboard } from './Dashboard/Dashboard'; import { Dashboard } from './Dashboard/Dashboard';
import { UserOutlined } from '@ant-design/icons';
export function Admin() { export function Admin() {
const { state, actions } = useAdmin() const { state, actions } = useAdmin()
@ -28,6 +29,9 @@ export function Admin() {
if (!state.access) { if (!state.access) {
return ( return (
<LoginWrapper> <LoginWrapper>
<div class="user" onClick={() => actions.onUser()}>
<UserOutlined />
</div>
<div className="login"> <div className="login">
<Space> <Space>
<TokenInput placeholder="Admin Token" spellcheck="false" onChange={(e) => actions.setToken(e.target.value)} /> <TokenInput placeholder="Admin Token" spellcheck="false" onChange={(e) => actions.setToken(e.target.value)} />

View File

@ -40,6 +40,16 @@ export const LoginWrapper = styled.div`
background-color: #eeeeee; background-color: #eeeeee;
border-radius: 4px; border-radius: 4px;
} }
.user {
position: absolute;
top: 0px;
right: 0px;
padding: 16px;
color: #555555;
font-size: 20px;
cursor: pointer;
}
`; `;
export const TokenInput = styled(Input.Password)` export const TokenInput = styled(Input.Password)`

View File

@ -1,4 +1,5 @@
import { useContext, useState, useEffect } from 'react'; import { useContext, useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { getNodeStatus } from 'api/getNodeStatus'; import { getNodeStatus } from 'api/getNodeStatus';
import { setNodeStatus } from 'api/setNodeStatus'; import { setNodeStatus } from 'api/setNodeStatus';
import { getNodeConfig } from 'api/getNodeConfig'; import { getNodeConfig } from 'api/getNodeConfig';
@ -12,6 +13,8 @@ export function useAdmin() {
busy: false, busy: false,
}); });
const navigate = useNavigate();
const updateState = (value) => { const updateState = (value) => {
setState((s) => ({ ...s, ...value })); setState((s) => ({ ...s, ...value }));
} }
@ -56,6 +59,9 @@ export function useAdmin() {
window.alert(err); window.alert(err);
} }
}, },
onUser: () => {
navigate('/login');
}
}; };
return { state, actions }; return { state, actions };

View File

@ -1,5 +1,5 @@
import React from 'react' import React from 'react'
import { UserOutlined, LockOutlined } from '@ant-design/icons'; import { SettingOutlined, UserOutlined, LockOutlined } from '@ant-design/icons';
import { useLogin } from './useLogin.hook'; import { useLogin } from './useLogin.hook';
import { LoginWrapper, LoginInput, LoginPassword, LoginCreate, LoginEnter, LoginSpin } from './Login.styled'; import { LoginWrapper, LoginInput, LoginPassword, LoginCreate, LoginEnter, LoginSpin } from './Login.styled';
@ -15,6 +15,9 @@ export function Login(props) {
return( return(
<LoginWrapper> <LoginWrapper>
<div class="settings" onClick={() => actions.onSettings()}>
<SettingOutlined />
</div>
<div class="container"> <div class="container">
<div class="header">indicom</div> <div class="header">indicom</div>
<div class="subheader"> <div class="subheader">

View File

@ -40,6 +40,15 @@ export const LoginWrapper = styled.div`
width: 100%; width: 100%;
} }
.settings {
position: absolute;
top: 0px;
right: 0px;
padding: 16px;
color: #555555;
font-size: 20px;
cursor: pointer;
}
`; `;
export const LoginInput = styled(Input)` export const LoginInput = styled(Input)`

View File

@ -27,6 +27,9 @@ export function useLogin() {
} }
return false return false
}, },
onSettings: () => {
navigate('/admin');
},
onLogin: async () => { onLogin: async () => {
if (!state.spinning && state.username != '' && state.password != '') { if (!state.spinning && state.username != '' && state.password != '') {
actions.updateState({ spinning: true }) actions.updateState({ spinning: true })