From 0cc15443a5912583a19b31efdb76bfcd80d08a5d Mon Sep 17 00:00:00 2001 From: Mathew E <105732593+MathewEm@users.noreply.github.com> Date: Mon, 30 Dec 2024 11:05:25 -0330 Subject: [PATCH] feat(librarium): Reset password action (#888) * feat(librarium): added Password Reset button * feat(librarium): implement password reset action closes #816 --- app/Filament/Resources/UserResource.php | 7 +++++-- .../Resources/UserResource/Pages/EditUser.php | 18 ++++++++++++++++++ resources/src/auto-imports.d.ts | 3 --- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Filament/Resources/UserResource.php b/app/Filament/Resources/UserResource.php index bf8af034..5e3a581b 100644 --- a/app/Filament/Resources/UserResource.php +++ b/app/Filament/Resources/UserResource.php @@ -51,9 +51,12 @@ public static function form(Form $form): Form ->hidden(fn ($record) => $record && ! $record->email_verified_at) ->onColor('success'), Forms\Components\Actions::make([ + Forms\Components\Actions\Action::make('reset_password') + ->label('Send Password Reset Email') + ->action('sendPasswordReset'), Forms\Components\Actions\Action::make('verify_email') - ->label('Activate & Verify') - ->hidden(fn ($record) => $record && $record->email_verified_at) + ->label('Activate User & Verify Email') + ->disabled(fn ($record) => isset($record->email_verified_at)) ->action('setVerifiedEmail'), ]), ]), diff --git a/app/Filament/Resources/UserResource/Pages/EditUser.php b/app/Filament/Resources/UserResource/Pages/EditUser.php index de6c23fd..b77f355e 100644 --- a/app/Filament/Resources/UserResource/Pages/EditUser.php +++ b/app/Filament/Resources/UserResource/Pages/EditUser.php @@ -4,7 +4,9 @@ use App\Filament\Resources\UserResource; use Filament\Actions; +use Filament\Notifications\Notification; use Filament\Resources\Pages\EditRecord; +use Illuminate\Support\Facades\Password; class EditUser extends EditRecord { @@ -61,5 +63,21 @@ public function setVerifiedEmail(): void } $this->record->markEmailAsVerified(); $this->refreshFormData(['active']); + Notification::make() + ->title('User\'s email is verified!') + ->success() + ->send(); + } + + /** + * Call the Reset Password Email process + */ + public function sendPasswordReset(): void + { + Password::sendResetLink(['email' => $this->data['email']]); + Notification::make() + ->title('Reset password email sent!') + ->success() + ->send(); } } diff --git a/resources/src/auto-imports.d.ts b/resources/src/auto-imports.d.ts index 3cb857ef..961162db 100644 --- a/resources/src/auto-imports.d.ts +++ b/resources/src/auto-imports.d.ts @@ -334,9 +334,6 @@ declare global { // @ts-ignore export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' import('vue') - // @ts-ignore - export type { Locale } from './stores/LocaleStore' - import('./stores/LocaleStore') } // for vue template auto import