Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as React from 'react'
- import {Layout, Fluid, Loading} from '../../components'
- import styled from 'styled-components'
- import TextField from '@material-ui/core/TextField'
- import Button from '@material-ui/core/Button'
- import SendIcon from '@material-ui/icons/Send'
- import CircularProgress from '@material-ui/core/CircularProgress'
- import fetch from 'isomorphic-unfetch'
- import md5 from 'md5-hash'
- const LoginPanel = styled.main`
- ${props => props.active ? null : `display: none;`}
- `
- const Index = () => {
- const [values, setValues] = React.useState({
- login: '',
- password: ''
- })
- const [state, setState] = React.useState(false)
- const [result, setResult] = React.useState({
- result: undefined
- })
- const checkData = async (profile) => {
- console.log(profile)
- if (profile === {}) {
- setResult({result: false})
- } else {
- setResult({result: true})
- }
- }
- const fetchData = async () => {
- const pageRequest = `https://school-vol.mdcholewka.now.sh/api/checkAdmin?login=${values.login}?password=${md5(values.password)}`
- const res = await fetch(pageRequest)
- const json = res.json()
- json.then(checkData(json))
- }
- const handleChange = name => event => {
- setValues({...values, [name]: event.target.value})
- }
- return (
- <Layout title='Panel administratora'>
- <Loading isRouteChanging={state} loadingKey={123} />
- <Fluid padding={true} paddingTop={true}>
- <LoginPanel active={(result.result === undefined || result.result === false) ? true : false}>
- <h1>Zaloguj się, aby potwierdzić, że jesteś administratorem</h1>
- <TextField onChange={handleChange('login')} label='Nazwa użytkownika' value={values.login} />
- <TextField onChange={handleChange('password')} name='password' label='Hasło' value={values.password} type='password' /><br /><br />
- <Button type="submit" variant="contained" size="medium" disabled={state} startIcon={<SendIcon />} color="primary" onClick={() => { setState(!state); fetchData(); }}>{state ? <><CircularProgress size={18} /><span style={{marginLeft: 10}}>Wysyłanie...</span></> : 'Wyślij'}</Button>
- {result === false ? `Błędne dane. Spróbuj jeszcze raz.` : null}
- </LoginPanel>
- </Fluid>
- </Layout>
- )
- }
- export default Index
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement