home-erp

git clone git://archive.git.mtrnord.blog/MTRNord/home-erp.git
Log | Files | Refs | README

update-profile-information-form.blade.php (3705B)


      1 <?php
      2 
      3 use App\Models\User;
      4 use App\Providers\RouteServiceProvider;
      5 use Illuminate\Validation\Rule;
      6 use Livewire\Volt\Component;
      7 
      8 new class extends Component
      9 {
     10     public string $name = '';
     11 
     12     public string $email = '';
     13 
     14     public function mount(): void
     15     {
     16         $this->name = auth()->user()->name;
     17         $this->email = auth()->user()->email;
     18     }
     19 
     20     public function updateProfileInformation(): void
     21     {
     22         $user = auth()->user();
     23 
     24         $validated = $this->validate([
     25             'name' => ['required', 'string', 'max:255'],
     26             'email' => ['required', 'email', 'max:255', Rule::unique(User::class)->ignore($user->id)],
     27         ]);
     28 
     29         $user->fill($validated);
     30 
     31         if ($user->isDirty('email')) {
     32             $user->email_verified_at = null;
     33         }
     34 
     35         $user->save();
     36 
     37         $this->dispatch('profile-updated', name: $user->name);
     38     }
     39 
     40     public function sendVerification(): void
     41     {
     42         $user = auth()->user();
     43 
     44         if ($user->hasVerifiedEmail()) {
     45             $path = session('url.intended', RouteServiceProvider::HOME);
     46 
     47             $this->redirect($path);
     48 
     49             return;
     50         }
     51 
     52         $user->sendEmailVerificationNotification();
     53 
     54         session()->flash('status', 'verification-link-sent');
     55     }
     56 }; ?>
     57 
     58 <section>
     59     <header>
     60         <h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
     61             {{ __('Profile Information') }}
     62         </h2>
     63 
     64         <p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
     65             {{ __("Update your account's profile information and email address.") }}
     66         </p>
     67     </header>
     68 
     69     <form wire:submit="updateProfileInformation" class="mt-6 space-y-6">
     70         <div>
     71             <x-input-label for="name" :value="__('Name')" />
     72             <x-text-input wire:model="name" id="name" name="name" type="text" class="mt-1 block w-full" required autofocus autocomplete="name" />
     73             <x-input-error class="mt-2" :messages="$errors->get('name')" />
     74         </div>
     75 
     76         <div>
     77             <x-input-label for="email" :value="__('Email')" />
     78             <x-text-input wire:model="email" id="email" name="email" type="email" class="mt-1 block w-full" required autocomplete="username" />
     79             <x-input-error class="mt-2" :messages="$errors->get('email')" />
     80 
     81             @if (auth()->user() instanceof \Illuminate\Contracts\Auth\MustVerifyEmail && ! auth()->user()->hasVerifiedEmail())
     82                 <div>
     83                     <p class="text-sm mt-2 text-gray-800 dark:text-gray-200">
     84                         {{ __('Your email address is unverified.') }}
     85 
     86                         <button wire:click.prevent="sendVerification" class="underline text-sm text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-gray-100 rounded-md focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 dark:focus:ring-offset-gray-800">
     87                             {{ __('Click here to re-send the verification email.') }}
     88                         </button>
     89                     </p>
     90 
     91                     @if (session('status') === 'verification-link-sent')
     92                         <p class="mt-2 font-medium text-sm text-green-600 dark:text-green-400">
     93                             {{ __('A new verification link has been sent to your email address.') }}
     94                         </p>
     95                     @endif
     96                 </div>
     97             @endif
     98         </div>
     99 
    100         <div class="flex items-center gap-4">
    101             <x-primary-button>{{ __('Save') }}</x-primary-button>
    102 
    103             <x-action-message class="mr-3" on="profile-updated">
    104                 {{ __('Saved.') }}
    105             </x-action-message>
    106         </div>
    107     </form>
    108 </section>