|
| 1 | +import { useForm } from '@inertiajs/react' |
| 2 | +import { FormEvent } from 'react' |
| 3 | +import { router } from '@inertiajs/react' |
| 4 | + |
| 5 | +export default function Login() { |
| 6 | + const { data, setData, processing, errors } = useForm({ |
| 7 | + email: '', |
| 8 | + password: '', |
| 9 | + remember: false, |
| 10 | + }) |
| 11 | + |
| 12 | + function handleSubmit(e: FormEvent) { |
| 13 | + e.preventDefault() |
| 14 | + router.post('/login', data) |
| 15 | + } |
| 16 | + |
| 17 | + return ( |
| 18 | + <div className="min-h-screen flex items-center justify-center bg-gray-50"> |
| 19 | + <div className="max-w-md w-full space-y-8"> |
| 20 | + <div> |
| 21 | + <h2 className="mt-6 text-center text-3xl font-extrabold text-gray-900"> |
| 22 | + Sign in to your account |
| 23 | + </h2> |
| 24 | + </div> |
| 25 | + <form className="mt-8 space-y-6" onSubmit={handleSubmit}> |
| 26 | + <div className="rounded-md shadow-sm -space-y-px"> |
| 27 | + <div> |
| 28 | + <label htmlFor="email" className="sr-only"> |
| 29 | + Email address |
| 30 | + </label> |
| 31 | + <input |
| 32 | + id="email" |
| 33 | + name="email" |
| 34 | + type="email" |
| 35 | + required |
| 36 | + className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-t-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" |
| 37 | + placeholder="Email address" |
| 38 | + value={data.email} |
| 39 | + onChange={(e) => setData('email', e.target.value)} |
| 40 | + /> |
| 41 | + {errors.email && <p className="text-red-500 text-xs mt-1">{errors.email}</p>} |
| 42 | + </div> |
| 43 | + <div> |
| 44 | + <label htmlFor="password" className="sr-only"> |
| 45 | + Password |
| 46 | + </label> |
| 47 | + <input |
| 48 | + id="password" |
| 49 | + name="password" |
| 50 | + type="password" |
| 51 | + required |
| 52 | + className="appearance-none rounded-none relative block w-full px-3 py-2 border border-gray-300 placeholder-gray-500 text-gray-900 rounded-b-md focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 focus:z-10 sm:text-sm" |
| 53 | + placeholder="Password" |
| 54 | + value={data.password} |
| 55 | + onChange={(e) => setData('password', e.target.value)} |
| 56 | + /> |
| 57 | + {errors.password && <p className="text-red-500 text-xs mt-1">{errors.password}</p>} |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + |
| 61 | + <div className="flex items-center justify-between"> |
| 62 | + <div className="flex items-center"> |
| 63 | + <input |
| 64 | + id="remember" |
| 65 | + name="remember" |
| 66 | + type="checkbox" |
| 67 | + className="h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded" |
| 68 | + checked={data.remember} |
| 69 | + onChange={(e) => setData('remember', e.target.checked)} |
| 70 | + /> |
| 71 | + <label htmlFor="remember" className="ml-2 block text-sm text-gray-900"> |
| 72 | + Remember me |
| 73 | + </label> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + |
| 77 | + <div> |
| 78 | + <button |
| 79 | + type="submit" |
| 80 | + disabled={processing} |
| 81 | + className="group relative w-full flex justify-center py-2 px-4 border border-transparent text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500" |
| 82 | + > |
| 83 | + Sign in |
| 84 | + </button> |
| 85 | + </div> |
| 86 | + </form> |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + ) |
| 90 | +} |
0 commit comments