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.

117 lines
4.1 KiB

  1. import { useEffect, FormEventHandler } from 'react';
  2. import GuestLayout from '@/Layouts/GuestLayout';
  3. import InputError from '@/Components/InputError';
  4. import InputLabel from '@/Components/InputLabel';
  5. import PrimaryButton from '@/Components/PrimaryButton';
  6. import TextInput from '@/Components/TextInput';
  7. import { Head, Link, useForm } from '@inertiajs/react';
  8. export default function Register() {
  9. const { data, setData, post, processing, errors, reset } = useForm({
  10. name: '',
  11. email: '',
  12. password: '',
  13. password_confirmation: '',
  14. });
  15. useEffect(() => {
  16. return () => {
  17. reset('password', 'password_confirmation');
  18. };
  19. }, []);
  20. const submit: FormEventHandler = (e) => {
  21. e.preventDefault();
  22. post(route('register'));
  23. };
  24. return (
  25. <GuestLayout>
  26. <Head title="Register" />
  27. <form onSubmit={submit}>
  28. <div>
  29. <InputLabel htmlFor="name" value="Name" />
  30. <TextInput
  31. id="name"
  32. name="name"
  33. value={data.name}
  34. className="mt-1 block w-full"
  35. autoComplete="name"
  36. isFocused={true}
  37. onChange={(e) => setData('name', e.target.value)}
  38. required
  39. />
  40. <InputError message={errors.name} className="mt-2" />
  41. </div>
  42. <div className="mt-4">
  43. <InputLabel htmlFor="email" value="Email" />
  44. <TextInput
  45. id="email"
  46. type="email"
  47. name="email"
  48. value={data.email}
  49. className="mt-1 block w-full"
  50. autoComplete="username"
  51. onChange={(e) => setData('email', e.target.value)}
  52. required
  53. />
  54. <InputError message={errors.email} className="mt-2" />
  55. </div>
  56. <div className="mt-4">
  57. <InputLabel htmlFor="password" value="Password" />
  58. <TextInput
  59. id="password"
  60. type="password"
  61. name="password"
  62. value={data.password}
  63. className="mt-1 block w-full"
  64. autoComplete="new-password"
  65. onChange={(e) => setData('password', e.target.value)}
  66. required
  67. />
  68. <InputError message={errors.password} className="mt-2" />
  69. </div>
  70. <div className="mt-4">
  71. <InputLabel htmlFor="password_confirmation" value="Confirm Password" />
  72. <TextInput
  73. id="password_confirmation"
  74. type="password"
  75. name="password_confirmation"
  76. value={data.password_confirmation}
  77. className="mt-1 block w-full"
  78. autoComplete="new-password"
  79. onChange={(e) => setData('password_confirmation', e.target.value)}
  80. required
  81. />
  82. <InputError message={errors.password_confirmation} className="mt-2" />
  83. </div>
  84. <div className="flex items-center justify-end mt-4">
  85. <Link
  86. href={route('login')}
  87. 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"
  88. >
  89. Already registered?
  90. </Link>
  91. <PrimaryButton className="ms-4" disabled={processing}>
  92. Register
  93. </PrimaryButton>
  94. </div>
  95. </form>
  96. </GuestLayout>
  97. );
  98. }