forked from laravel/react-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregister.tsx
119 lines (109 loc) · 4.72 KB
/
register.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { Head, useForm } from '@inertiajs/react';
import { LoaderCircle } from 'lucide-react';
import { FormEventHandler } from 'react';
import InputError from '@/components/input-error';
import TextLink from '@/components/text-link';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import AuthLayout from '@/layouts/auth-layout';
type RegisterForm = {
name: string;
email: string;
password: string;
password_confirmation: string;
}
export default function Register() {
const { data, setData, post, processing, errors, reset } = useForm<RegisterForm>({
name: '',
email: '',
password: '',
password_confirmation: '',
});
const submit: FormEventHandler = (e) => {
e.preventDefault();
post(route('register'), {
onFinish: () => reset('password', 'password_confirmation'),
});
};
return (
<AuthLayout title="Create an account" description="Enter your details below to create your account">
<Head title="Register" />
<form className="flex flex-col gap-6" onSubmit={submit}>
<div className="grid gap-6">
<div className="grid gap-2">
<Label htmlFor="name">Name</Label>
<Input
id="name"
type="text"
required
autoFocus
tabIndex={1}
autoComplete="name"
value={data.name}
onChange={(e) => setData('name', e.target.value)}
disabled={processing}
placeholder="Full name"
/>
<InputError message={errors.name} className="mt-2" />
</div>
<div className="grid gap-2">
<Label htmlFor="email">Email address</Label>
<Input
id="email"
type="email"
required
tabIndex={2}
autoComplete="email"
value={data.email}
onChange={(e) => setData('email', e.target.value)}
disabled={processing}
placeholder="[email protected]"
/>
<InputError message={errors.email} />
</div>
<div className="grid gap-2">
<Label htmlFor="password">Password</Label>
<Input
id="password"
type="password"
required
tabIndex={3}
autoComplete="new-password"
value={data.password}
onChange={(e) => setData('password', e.target.value)}
disabled={processing}
placeholder="Password"
/>
<InputError message={errors.password} />
</div>
<div className="grid gap-2">
<Label htmlFor="password_confirmation">Confirm password</Label>
<Input
id="password_confirmation"
type="password"
required
tabIndex={4}
autoComplete="new-password"
value={data.password_confirmation}
onChange={(e) => setData('password_confirmation', e.target.value)}
disabled={processing}
placeholder="Confirm password"
/>
<InputError message={errors.password_confirmation} />
</div>
<Button type="submit" className="mt-2 w-full" tabIndex={5} disabled={processing}>
{processing && <LoaderCircle className="h-4 w-4 animate-spin" />}
Create account
</Button>
</div>
<div className="text-muted-foreground text-center text-sm">
Already have an account?{' '}
<TextLink href={route('login')} tabIndex={6}>
Log in
</TextLink>
</div>
</form>
</AuthLayout>
);
}