dashboard/src/modules/login/Login.tsx

48 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-01-18 10:14:29 +00:00
import React from 'react';
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';
2022-01-19 09:22:52 +01:00
import { showToast, ToastType } from 'src/common/util/show-toast';
2021-09-27 12:17:33 +02:00
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2022-02-09 09:03:44 +00:00
export function Login() {
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) {
2022-01-19 09:22:52 +01:00
showToast('Something went wrong', ToastType.Error);
2022-01-18 10:14:29 +00:00
}
};
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>
);
}