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 { useAdmin } from './useAdmin.hook';
import { Dashboard } from './Dashboard/Dashboard';
import { UserOutlined } from '@ant-design/icons';
export function Admin() {
const { state, actions } = useAdmin()
@ -28,6 +29,9 @@ export function Admin() {
if (!state.access) {
return (
<LoginWrapper>
<div class="user" onClick={() => actions.onUser()}>
<UserOutlined />
</div>
<div className="login">
<Space>
<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;
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)`

View File

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

View File

@ -1,5 +1,5 @@
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 { LoginWrapper, LoginInput, LoginPassword, LoginCreate, LoginEnter, LoginSpin } from './Login.styled';
@ -15,6 +15,9 @@ export function Login(props) {
return(
<LoginWrapper>
<div class="settings" onClick={() => actions.onSettings()}>
<SettingOutlined />
</div>
<div class="container">
<div class="header">indicom</div>
<div class="subheader">

View File

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

View File

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