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.

105 lines
4.1 KiB

  1. import InputError from '@/Components/InputError';
  2. import InputLabel from '@/Components/InputLabel';
  3. import PrimaryButton from '@/Components/PrimaryButton';
  4. import TextInput from '@/Components/TextInput';
  5. import { Link, useForm, usePage } from '@inertiajs/react';
  6. import { Transition } from '@headlessui/react';
  7. import { FormEventHandler } from 'react';
  8. import { PageProps } from '@/types';
  9. export default function UpdateProfileInformation({ mustVerifyEmail, status, className = '' }: { mustVerifyEmail: boolean, status?: string, className?: string }) {
  10. const user = usePage<PageProps>().props.auth.user;
  11. const { data, setData, patch, errors, processing, recentlySuccessful } = useForm({
  12. name: user.name,
  13. email: user.email,
  14. });
  15. const submit: FormEventHandler = (e) => {
  16. e.preventDefault();
  17. patch(route('profile.update'));
  18. };
  19. return (
  20. <section className={className}>
  21. <header>
  22. <h2 className="text-lg font-medium text-gray-900">Profile Information</h2>
  23. <p className="mt-1 text-sm text-gray-600">
  24. Update your account's profile information and email address.
  25. </p>
  26. </header>
  27. <form onSubmit={submit} className="mt-6 space-y-6">
  28. <div>
  29. <InputLabel htmlFor="name" value="Name" />
  30. <TextInput
  31. id="name"
  32. className="mt-1 block w-full"
  33. value={data.name}
  34. onChange={(e) => setData('name', e.target.value)}
  35. required
  36. isFocused
  37. autoComplete="name"
  38. />
  39. <InputError className="mt-2" message={errors.name} />
  40. </div>
  41. <div>
  42. <InputLabel htmlFor="email" value="Email" />
  43. <TextInput
  44. id="email"
  45. type="email"
  46. className="mt-1 block w-full"
  47. value={data.email}
  48. onChange={(e) => setData('email', e.target.value)}
  49. required
  50. autoComplete="username"
  51. />
  52. <InputError className="mt-2" message={errors.email} />
  53. </div>
  54. {mustVerifyEmail && user.email_verified_at === null && (
  55. <div>
  56. <p className="text-sm mt-2 text-gray-800">
  57. Your email address is unverified.
  58. <Link
  59. href={route('verification.send')}
  60. method="post"
  61. as="button"
  62. 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"
  63. >
  64. Click here to re-send the verification email.
  65. </Link>
  66. </p>
  67. {status === 'verification-link-sent' && (
  68. <div className="mt-2 font-medium text-sm text-green-600">
  69. A new verification link has been sent to your email address.
  70. </div>
  71. )}
  72. </div>
  73. )}
  74. <div className="flex items-center gap-4">
  75. <PrimaryButton disabled={processing}>Save</PrimaryButton>
  76. <Transition
  77. show={recentlySuccessful}
  78. enter="transition ease-in-out"
  79. enterFrom="opacity-0"
  80. leave="transition ease-in-out"
  81. leaveTo="opacity-0"
  82. >
  83. <p className="text-sm text-gray-600">Saved.</p>
  84. </Transition>
  85. </div>
  86. </form>
  87. </section>
  88. );
  89. }