import React, { useState, useEffect } from 'react';

import { Redirect } from "react-router-dom";

import _auth from '@netuno/auth-client';

import _service from '@netuno/service-client';

import { Spin } from 'antd';

export default ()=> {
    if (!_auth.isLogged()) {
        return <Redirect to="/login" />;
    }
    const [ userInfo, setUserInfo ] = useState(null);
    useEffect(() => {
        _service({
            url: 'public/info',
            success: (response) => {
                setUserInfo(response.json);
            },
            fail: (e) => {
                console.error('Service Info Error', e);
            }
        });
    }, []);
    if (userInfo == null) {
        return <Spin/>;
    }
    return (
        <div>
            <h1>Principal</h1>
            Olá {userInfo.name}
        </div>
    );
};