dashboard/src/modules/login/Login.tsx

67 lines
2 KiB
TypeScript
Raw Normal View History

2022-01-18 10:14:29 +00:00
import React from 'react';
import { RouteComponentProps } from '@reach/router';
2021-09-27 12:17:33 +02:00
import clsx from 'clsx';
import { LockClosedIcon } from '@heroicons/react/solid';
2022-01-18 10:14:29 +00:00
import { performApiCall } from 'src/services/api';
2021-09-27 12:17:33 +02:00
type LoginProps = RouteComponentProps;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export function Login(_: LoginProps) {
2022-01-18 10:14:29 +00:00
const handleSubmit = async () => {
try {
const { data } = await performApiCall({
path: '/login',
method: 'POST',
});
2021-09-27 12:17:33 +02:00
2022-01-18 10:14:29 +00:00
if (data.authorizationUrl) {
window.location.href = data.authorizationUrl;
}
} catch (e: any) {
// continue
}
2021-09-27 12:17:33 +02:00
// @ts-ignore
2022-01-18 10:14:29 +00:00
// if (res.ok) {
// showToast('Logged in!');
// } else {
// showToast('Username or password incorrect', ToastType.Error);
// }
};
2021-09-27 12:17:33 +02:00
2022-01-18 10:14:29 +00:00
// useEffect(() => {
// if (isValid(auth)) {
// navigate('/dashboard');
// }
// }, [auth]);
2021-09-27 12:17:33 +02:00
2022-01-18 10:14:29 +00:00
// if (isValid(auth)) {
// return null;
// }
2021-09-27 12:17:33 +02:00
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50 py-12 px-4 sm:px-6 lg:px-8">
<div className="max-w-md w-full space-y-8">
<div className="flex justify-center">
2022-01-18 10:14:29 +00:00
<img className="lg:block" src="assets/logo.svg" alt="Stackspin" />
2021-09-27 12:17:33 +02:00
<h2 className="mt-6 text-center text-xl font-bold text-gray-900 sr-only">Sign in</h2>
</div>
2022-01-18 10:14:29 +00:00
<button
onClick={handleSubmit}
type="button"
className={clsx(
'group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-primary-dark hover:bg-primary-dark focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-primary-500',
)}
>
<span className="absolute left-0 inset-y-0 flex items-center pl-3">
<LockClosedIcon className="h-5 w-5 text-white group-hover:text-primary-light" aria-hidden="true" />
</span>
Sign in
</button>
2021-09-27 12:17:33 +02:00
</div>
</div>
);
}