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.

90 lines
3.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, useForm } from '@inertiajs/react';
  8. export default function ResetPassword({ token, email }: { token: string, email: string }) {
  9. const { data, setData, post, processing, errors, reset } = useForm({
  10. token: token,
  11. email: 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('password.store'));
  23. };
  24. return (
  25. <GuestLayout>
  26. <Head title="Reset Password" />
  27. <form onSubmit={submit}>
  28. <div>
  29. <InputLabel htmlFor="email" value="Email" />
  30. <TextInput
  31. id="email"
  32. type="email"
  33. name="email"
  34. value={data.email}
  35. className="mt-1 block w-full"
  36. autoComplete="username"
  37. onChange={(e) => setData('email', e.target.value)}
  38. />
  39. <InputError message={errors.email} className="mt-2" />
  40. </div>
  41. <div className="mt-4">
  42. <InputLabel htmlFor="password" value="Password" />
  43. <TextInput
  44. id="password"
  45. type="password"
  46. name="password"
  47. value={data.password}
  48. className="mt-1 block w-full"
  49. autoComplete="new-password"
  50. isFocused={true}
  51. onChange={(e) => setData('password', e.target.value)}
  52. />
  53. <InputError message={errors.password} className="mt-2" />
  54. </div>
  55. <div className="mt-4">
  56. <InputLabel htmlFor="password_confirmation" value="Confirm Password" />
  57. <TextInput
  58. type="password"
  59. name="password_confirmation"
  60. value={data.password_confirmation}
  61. className="mt-1 block w-full"
  62. autoComplete="new-password"
  63. onChange={(e) => setData('password_confirmation', e.target.value)}
  64. />
  65. <InputError message={errors.password_confirmation} className="mt-2" />
  66. </div>
  67. <div className="flex items-center justify-end mt-4">
  68. <PrimaryButton className="ms-4" disabled={processing}>
  69. Reset Password
  70. </PrimaryButton>
  71. </div>
  72. </form>
  73. </GuestLayout>
  74. );
  75. }