Skip to content

Commit

Permalink
[Bugfix] Form options showed ALL options instead of the configured op…
Browse files Browse the repository at this point in the history
…tions (#5)

* Add getLabel method to TwoFactorType enum and fix code style

* style: formatting
  • Loading branch information
CodeWithDennis authored Aug 21, 2024
1 parent 4ec5a78 commit 424cedf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Enums/TwoFactorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Vormkracht10\TwoFactorAuth\Enums;

use Filament\Support\Contracts\HasLabel;
use Vormkracht10\TwoFactorAuth\Traits\EnumArraySerializableTrait;

enum TwoFactorType: string
enum TwoFactorType: string implements HasLabel
{
use EnumArraySerializableTrait;

Expand All @@ -17,7 +18,7 @@ public static function values(): array
return array_map(fn ($type) => $type->label(), self::cases());

Check failure on line 18 in src/Enums/TwoFactorType.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Vormkracht10\TwoFactorAuth\Enums\TwoFactorType::authenticator|Vormkracht10\TwoFactorAuth\Enums\TwoFactorType::email|Vormkracht10\TwoFactorAuth\Enums\TwoFactorType::phone::label().

Check failure on line 18 in src/Enums/TwoFactorType.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Vormkracht10\TwoFactorAuth\Enums\TwoFactorType::authenticator|Vormkracht10\TwoFactorAuth\Enums\TwoFactorType::email|Vormkracht10\TwoFactorAuth\Enums\TwoFactorType::phone::label().
}

public function label(): string
public function getLabel(): ?string
{
return match ($this) {
self::email => __('Email'),
Expand Down
5 changes: 3 additions & 2 deletions src/Pages/TwoFactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ public function twoFactorOptionForm(Form $form): Form
Radio::make('option')
->label(__('Authentication method'))
->hiddenLabel()
->options(TwoFactorType::array()),
->options(collect(config('filament-two-factor-auth.options'))->mapWithKeys(function ($option) {
return [$option->value => $option->getLabel()];
})),
])->statePath('twoFactorData');
}

Expand Down Expand Up @@ -120,7 +122,6 @@ public function enableAction(): Action
->label(__('Activate'))
->color('primary')
->action(function ($data) {

$formData = [];

if (isset($data['email'])) {
Expand Down

0 comments on commit 424cedf

Please sign in to comment.