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.

104 lines
4.0 KiB
React

1 year ago
import React, { useEffect, useRef, useState } from 'react';
import InputError from '@/Components/Defaults/InputError';
import InputLabel from '@/Components/Defaults/InputLabel';
import PrimaryButton from '@/Components/Defaults/PrimaryButton';
import TextInput from '@/Components/Defaults/TextInput';
import { Link, useForm, usePage } from '@inertiajs/react';
import { Transition } from '@headlessui/react';
export default function UpdateProfileInformation({ mustVerifyEmail, status, className }) {
const user = usePage().props.auth.user;
const { data, setData, patch, errors, processing, recentlySuccessful } = useForm({
username: user.username,
email: user.email,
});
const submit = (e) => {
e.preventDefault();
patch(route('profile.update'));
};
return (
<section className={className}>
<header>
<h2 className="text-lg font-medium text-gray-900">Profile Information</h2>
<p className="mt-1 text-sm text-gray-600">
Update your account's profile information and email address.
</p>
</header>
<form onSubmit={submit} className="mt-6 space-y-6">
<div>
<InputLabel for="name" value="Name" />
<TextInput
id="username"
type="text"
className="mt-1 block w-full"
value={data.username}
handleChange={(e) => setData('username', e.target.value)}
required
autofocus
autocomplete="name"
/>
<InputError className="mt-2" message={errors.username} />
</div>
<div>
<InputLabel for="email" value="Email" />
<TextInput
id="email"
type="email"
className="mt-1 block w-full"
value={data.email}
handleChange={(e) => setData('email', e.target.value)}
required
autocomplete="email"
/>
<InputError className="mt-2" message={errors.email} />
</div>
{mustVerifyEmail && user.email_verified_at === null && (
<div>
<p className="text-sm mt-2 text-gray-800">
Your email address is unverified.
<Link
href={route('verification.send')}
method="post"
as="button"
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"
>
Click here to re-send the verification email.
</Link>
</p>
{status === 'verification-link-sent' && (
<div className="mt-2 font-medium text-sm text-green-600">
A new verification link has been sent to your email address.
</div>
)}
</div>
)}
<div className="flex items-center gap-4">
<PrimaryButton processing={processing}>Save</PrimaryButton>
<Transition
show={recentlySuccessful}
enterFrom="opacity-0"
leaveTo="opacity-0"
className="transition ease-in-out"
>
<p className="text-sm text-gray-600">Saved.</p>
</Transition>
</div>
</form>
</section>
);
}