Skip to content

Commit

Permalink
Merge pull request #484 from code4romania/450-risk-factors
Browse files Browse the repository at this point in the history
Risk factors - 2
  • Loading branch information
gheorghelupu17 authored Jan 13, 2025
2 parents f9c6d90 + ee37643 commit 8a65040
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
use App\Services\Breadcrumb\BeneficiaryBreadcrumb;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Group;
use Filament\Forms\Components\Hidden;
use Filament\Forms\Components\Radio;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Forms\Set;
use Filament\Infolists\Components\Group as InfolistGroup;
use Filament\Infolists\Components\Section as InfolistSection;
use Filament\Infolists\Components\TextEntry;
Expand Down Expand Up @@ -131,7 +133,21 @@ public static function getSocialSupportSchema(): array

Checkbox::make('extended_family_can_not_provide')
->label(__('beneficiary.section.initial_evaluation.labels.extended_family_can_not_provide'))
->afterStateUpdated(
function ($state, Get $get, Set $set) {
if ($state) {
$set('extended_family_can_provide_old_values', $get('extended_family_can_provide'));
$set('extended_family_can_provide', null);

return;
}

$set('extended_family_can_provide', $get('extended_family_can_provide_old_values'));
}
)
->live(),

Hidden::make('extended_family_can_provide_old_values'),
]),

Group::make()
Expand All @@ -144,7 +160,22 @@ public static function getSocialSupportSchema(): array

Checkbox::make('friends_can_not_provide')
->label(__('beneficiary.section.initial_evaluation.labels.friends_can_not_provide'))
->afterStateUpdated(
function ($state, Get $get, Set $set) {
if ($state) {
$set('friends_can_provide_old_values', $get('friends_can_provide'));
$set('friends_can_provide', null);

return;
}

$set('friends_can_provide', $get('friends_can_provide_old_values'));
}
)
->live(),

Hidden::make('friends_can_provide_old_values'),

]),

];
Expand Down
13 changes: 0 additions & 13 deletions app/Models/RiskFactors.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,14 @@ protected static function boot()
{
parent::boot();
self::creating(function (RiskFactors $model) {
self::formatSocialSupport($model);
self::calculateRiskLevel($model);
});

self::updating(function (RiskFactors $model) {
self::formatSocialSupport($model);
self::calculateRiskLevel($model);
});
}

public static function formatSocialSupport(self $model): void
{
if ($model->extended_family_can_not_provide) {
$model->extended_family_can_provide = [];
}

if ($model->friends_can_not_provide) {
$model->friends_can_provide = [];
}
}

public static function calculateRiskLevel(self $model): void
{
if (self::hasHighRiskLevel($model->risk_factors)) {
Expand Down
2 changes: 1 addition & 1 deletion database/factories/RiskFactorsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function definition(): array
foreach (fake()->randomElements($riskFactors, rand(1, \count($riskFactors))) as $riskFactor) {
$selectedRiskFactors[$riskFactor] = [
'value' => fake()->randomElement(Ternary::values()),
'description' => fake()->text(),
'description' => fake()->text(100),
];
}

Expand Down

0 comments on commit 8a65040

Please sign in to comment.