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

90 lines
2.8 KiB
React

import React, { useEffect } from 'react';
import Button from '@/Components/Button';
import Guest from '@/Layouts/Guest';
3 years ago
import { Head, useForm } from '@inertiajs/inertia-react';
3 years ago
export default function Login({ status }) {
const { data, setData, post, processing, errors, reset } = useForm({
email: '',
password: '',
3 years ago
remember: false,
});
useEffect(() => {
return () => {
reset('password');
};
}, []);
const onHandleChange = (event) => {
3 years ago
setData(event.target.name, event.target.value);
};
const submit = (e) => {
e.preventDefault();
post(route('login'));
};
return (
<Guest>
<Head title="Log in" />
3 years ago
{status && (
<div className="mb-4 font-medium text-sm text-green-600">
{status}
</div>
)}
<form onSubmit={submit}>
3 years ago
<div className="form-control">
<label className="label">
<span className="label-text">Email</span>
</label>
<input
type="text"
name="email"
3 years ago
className={`input input-bordered ${
errors.email && 'input-error'
}`}
value={data.email}
autoComplete="username"
3 years ago
autoFocus={true}
onChange={onHandleChange}
/>
3 years ago
<label className="label">
<span className="label-text-alt">{errors.email}</span>
</label>
</div>
3 years ago
<div className="form-control">
<label className="label">
<span className="label-text">Password</span>
</label>
<input
type="password"
name="password"
3 years ago
className={`input input-bordered ${
errors.password && 'input-error'
}`}
value={data.password}
autoComplete="current-password"
3 years ago
onChange={onHandleChange}
/>
3 years ago
<label className="label">
<span className="label-text-alt">
{errors.password}
</span>
</label>
</div>
<div className="flex items-center justify-end mt-4">
<Button className="ml-4" processing={processing}>
Log in
</Button>
</div>
</form>
</Guest>
3 years ago
)
}