Skip to content

Commit

Permalink
Merge pull request #2 from kdrmlhcn/main
Browse files Browse the repository at this point in the history
Add shouldShowDeleteAccountForm functionality
  • Loading branch information
joaopaulolndev authored May 20, 2024
2 parents 500f25a + 8fdcc69 commit c3b53ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ if you want to show for specific parameters to sort, icon, title, navigation gro
->setSort(10)
->canAccess(fn () => auth()->user()->id === 1)
->shouldRegisterNavigation(false)
->shouldShowDeleteAccountForm(false)
])
```

Expand Down
8 changes: 5 additions & 3 deletions resources/views/filament/pages/edit-profile-page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
/>
</x-filament-panels::form>

<x-filament-panels::form>
{{ $this->deleteAccountForm }}
</x-filament-panels::form>
@if($this->shouldShowDeleteAccountForm())
<x-filament-panels::form>
{{ $this->deleteAccountForm }}
</x-filament-panels::form>
@endif
</x-filament-panels::page>
14 changes: 14 additions & 0 deletions src/FilamentEditProfilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class FilamentEditProfilePlugin implements Plugin

public Closure | string $navigationLabel = '';

public Closure | bool $shouldShowDeleteAccountForm = true;

public function getId(): string
{
return 'filament-edit-profile';
Expand Down Expand Up @@ -146,4 +148,16 @@ public function getShouldRegisterNavigation(): bool
{
return $this->evaluate($this->shouldRegisterNavigation);
}

public function shouldShowDeleteAccountForm(Closure | bool $value = true): static
{
$this->shouldShowDeleteAccountForm = $value;

return $this;
}

public function getShouldShowDeleteAccountForm(): bool
{
return $this->evaluate($this->shouldShowDeleteAccountForm);
}
}
7 changes: 7 additions & 0 deletions src/Pages/EditProfilePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ public static function canAccess(): bool
return $plugin->getCanAccess();
}

public static function shouldShowDeleteAccountForm()
{
$plugin = Filament::getCurrentPanel()?->getPlugin('filament-edit-profile');

return $plugin->getShouldShowDeleteAccountForm();
}

public ?array $profileData = [];

public ?array $passwordData = [];
Expand Down

0 comments on commit c3b53ce

Please sign in to comment.