Skip to content

Commit

Permalink
fix: organization area callback types (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio authored Jan 9, 2024
1 parent 85ef9ea commit 87c9225
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
23 changes: 23 additions & 0 deletions app/Concerns/Enums/Comparable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace App\Concerns\Enums;

use BackedEnum;

trait Comparable
{
/**
Expand All @@ -17,4 +19,25 @@ public function is(mixed $enum): bool

return $this->value === $enum;
}

/**
* Check if this enum doesn't match the given enum instance or value.
*/
public function isNot(mixed $enum): bool
{
return ! $this->is($enum);
}

public static function isValue(mixed $subject, BackedEnum $enum): bool
{
if ($subject === null) {
return false;
}

if (! $subject instanceof self) {
$subject = self::tryFrom(\is_int($enum->value) ? (int) $subject : (string) $subject);
}

return $subject?->is($enum) ?? false;
}
}
8 changes: 4 additions & 4 deletions app/Filament/Resources/OrganisationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ public static function form(Form $form): Form
->label(__('organisation.field.area'))
->options(OrganisationAreaType::options())
->reactive()
->afterStateUpdated(function (array $state, callable $set) {
->afterStateUpdated(function (string $state, callable $set) {
if (
! \in_array(OrganisationAreaType::regional->value, $state) &&
! \in_array(OrganisationAreaType::local->value, $state)
OrganisationAreaType::regional->isNot($state) &&
OrganisationAreaType::local->isNot($state)
) {
$set('activity_counties', []);
}

if (! \in_array(OrganisationAreaType::local->value, $state)) {
if (OrganisationAreaType::local->isNot($state)) {
$set('activity_cities', []);
}
}),
Expand Down

0 comments on commit 87c9225

Please sign in to comment.