import React, { useState } from 'react' import { useRouter } from 'next/router' import Head from 'next/head' import Footer from '../../components/footer' import Header from '../../components/header' import Input from '../../components/input' import { getBaseURL } from '../../helpers/url' export default function Home() { const router = useRouter() const [username, setUsername] = useState('') const [password, setPassword] = useState('') const isValid = !!username.length && !!password.length async function onSubmit(event: React.FormEvent) { event.preventDefault() try { await fetch('/api/admin/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ username, password, }), }).then((response) => { if (!response.ok) { console.error('Unable to login', response.status, response.statusText) return } const redirect = Array.isArray(router.query?.redirect) ? router.query.redirect[0] : router.query?.redirect router.push(redirect || getBaseURL()) }) } catch (error) { console.error('Unable to login', error) } } return ( <> Pfadi Bussle Admin
) => setUsername(event.target.value) } /> ) => setPassword(event.target.value) } />