All files / laravel-saas/resources/js/Pages/Profile/Partials UpdateProfileInformationForm.tsx

0% Statements 0/83
0% Branches 0/1
0% Functions 0/1
0% Lines 0/83

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                                                                                                                                                                                                                           
import { Button } from '@/Components/ui/Button';
import { Input } from '@/Components/ui/Input';
import { Alert } from '@/Components/ui/Alert';
import { FormField } from '@/Components/molecules/FormField';
import { Transition } from '@headlessui/react';
import { Link, useForm, usePage } from '@inertiajs/react';
import { FormEventHandler } from 'react';
 
export default function UpdateProfileInformation({
    mustVerifyEmail,
    status,
    className = '',
}: {
    mustVerifyEmail: boolean;
    status?: string;
    className?: string;
}) {
    const user = usePage().props.auth.user;
 
    const { data, setData, patch, errors, processing, recentlySuccessful } =
        useForm({
            name: user.name,
            email: user.email,
        });
 
    const submit: FormEventHandler = (e) => {
        e.preventDefault();
 
        patch(route('profile.update'));
    };
 
    return (
        <section className={className}>
            <header>
                <h2 className="text-lg font-medium text-foreground">
                    Profile Information
                </h2>
 
                <p className="mt-1 text-sm text-muted-foreground">
                    Update your account's profile information and email address.
                </p>
            </header>
 
            <form onSubmit={submit} className="mt-6 space-y-6">
                <FormField label="Name" error={errors.name} required>
                    <Input
                        id="name"
                        value={data.name}
                        onChange={(e) => setData('name', e.target.value)}
                        autoComplete="name"
                        autoFocus
                        className="w-full"
                    />
                </FormField>
 
                <FormField label="Email" error={errors.email} required>
                    <Input
                        id="email"
                        type="email"
                        value={data.email}
                        onChange={(e) => setData('email', e.target.value)}
                        autoComplete="username"
                        className="w-full"
                    />
                </FormField>
 
                {mustVerifyEmail && user.email_verified_at === null && (
                    <div>
                        <p className="mt-2 text-sm text-foreground">
                            Your email address is unverified.
                            <Link
                                href={route('verification.send')}
                                method="post"
                                as="button"
                                className="rounded-md text-sm text-muted-foreground underline hover:text-foreground focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2"
                            >
                                Click here to re-send the verification email.
                            </Link>
                        </p>
 
                        {status === 'verification-link-sent' && (
                            <Alert variant="success" className="mt-2">
                                A new verification link has been sent to your email address.
                            </Alert>
                        )}
                    </div>
                )}
 
                <div className="flex items-center gap-4">
                    <Button type="submit" disabled={processing} loading={processing}>
                        {processing ? 'Saving...' : 'Save'}
                    </Button>
 
                    <Transition
                        show={recentlySuccessful}
                        enter="transition ease-in-out"
                        enterFrom="opacity-0"
                        leave="transition ease-in-out"
                        leaveTo="opacity-0"
                    >
                        <p className="text-sm font-medium text-green-600 dark:text-green-400">
                            Saved successfully!
                        </p>
                    </Transition>
                </div>
            </form>
        </section>
    );
}