You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.5 KiB

  1. import { useEffect, FormEventHandler } from 'react';
  2. import Checkbox from '@/Components/Checkbox';
  3. import GuestLayout from '@/Layouts/GuestLayout';
  4. import InputError from '@/Components/InputError';
  5. import InputLabel from '@/Components/InputLabel';
  6. import PrimaryButton from '@/Components/PrimaryButton';
  7. import TextInput from '@/Components/TextInput';
  8. import { Head, Link, useForm } from '@inertiajs/react';
  9. export default function Login({ status, canResetPassword }: { status?: string, canResetPassword: boolean }) {
  10. const { data, setData, post, processing, errors, reset } = useForm({
  11. email: '',
  12. password: '',
  13. remember: false,
  14. });
  15. useEffect(() => {
  16. return () => {
  17. reset('password');
  18. };
  19. }, []);
  20. const submit: FormEventHandler = (e) => {
  21. e.preventDefault();
  22. post(route('login'));
  23. };
  24. return (
  25. <GuestLayout>
  26. <Head title="Log in" />
  27. {status && <div className="mb-4 font-medium text-sm text-green-600">{status}</div>}
  28. <form onSubmit={submit}>
  29. <div>
  30. <InputLabel htmlFor="email" value="Email" />
  31. <TextInput
  32. id="email"
  33. type="email"
  34. name="email"
  35. value={data.email}
  36. className="mt-1 block w-full"
  37. autoComplete="username"
  38. isFocused={true}
  39. onChange={(e) => setData('email', e.target.value)}
  40. />
  41. <InputError message={errors.email} className="mt-2" />
  42. </div>
  43. <div className="mt-4">
  44. <InputLabel htmlFor="password" value="Password" />
  45. <TextInput
  46. id="password"
  47. type="password"
  48. name="password"
  49. value={data.password}
  50. className="mt-1 block w-full"
  51. autoComplete="current-password"
  52. onChange={(e) => setData('password', e.target.value)}
  53. />
  54. <InputError message={errors.password} className="mt-2" />
  55. </div>
  56. <div className="block mt-4">
  57. <label className="flex items-center">
  58. <Checkbox
  59. name="remember"
  60. checked={data.remember}
  61. onChange={(e) => setData('remember', e.target.checked)}
  62. />
  63. <span className="ms-2 text-sm text-gray-600">Remember me</span>
  64. </label>
  65. </div>
  66. <div className="flex items-center justify-end mt-4">
  67. {canResetPassword && (
  68. <Link
  69. href={route('password.request')}
  70. className="underline text-sm text-gray-600 hover:text-gray-900 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
  71. >
  72. Forgot your password?
  73. </Link>
  74. )}
  75. <PrimaryButton className="ms-4" disabled={processing}>
  76. Log in
  77. </PrimaryButton>
  78. </div>
  79. </form>
  80. </GuestLayout>
  81. );
  82. }