Skip to content

Commit

Permalink
feat: add children identity form schema
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Dec 14, 2023
1 parent 788bc88 commit 87fafe4
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ protected function getSteps(): array

Step::make('children')
->label(__('beneficiary.wizard.children.label'))
->schema([
// ...
]),
->schema(EditBeneficiaryIdentity::getChildrenIdentityFormSchema()),

Step::make('personal_information')
->label(__('beneficiary.wizard.personal_information.label'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Forms\Components\Location;
use App\Forms\Components\Spacer;
use App\Rules\ValidCNP;
use Awcodes\FilamentTableRepeater\Components\TableRepeater;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Grid;
Expand Down Expand Up @@ -44,7 +45,7 @@ public function form(Form $form): Form
Tabs\Tab::make(__('beneficiary.section.identity.tab.beneficiary'))
->schema(static::getBeneficiaryIdentityFormSchema()),
Tabs\Tab::make(__('beneficiary.section.identity.tab.children'))
->schema([]),
->schema(static::getChildrenIdentityFormSchema()),

]),
]);
Expand Down Expand Up @@ -123,7 +124,7 @@ public static function getBeneficiaryIdentityFormSchema(): array
->relationship('citizenship', 'name')
->nullable(),

Select::make('ethnicity')
Select::make('ethnicity_id')
->label(__('field.ethnicity'))
->placeholder(__('placeholder.ethnicity'))
->relationship('ethnicity', 'name')
Expand Down Expand Up @@ -217,4 +218,101 @@ public static function getBeneficiaryIdentityFormSchema(): array
]),
];
}

public static function getChildrenIdentityFormSchema(): array
{
return [
Checkbox::make('doesnt_have_children')
->label(__('field.doesnt_have_children'))
->live()
->columnSpanFull()
->afterStateUpdated(function (bool $state, Set $set) {
if ($state) {
$set('children_total_count', null);
$set('children_care_count', null);
$set('children_under_10_care_count', null);
$set('children_10_18_care_count', null);
$set('children_18_care_count', null);
$set('children_accompanying_count', null);
$set('children', null);
$set('children_notes', null);
}
}),

Grid::make()
->maxWidth('3xl')
->disabled(fn (Get $get) => $get('doesnt_have_children'))
->schema([
TextInput::make('children_total_count')
->label(__('field.children_total_count'))
->placeholder(__('placeholder.number'))
->numeric()
->minValue(0)
->maxValue(99),

TextInput::make('children_care_count')
->label(__('field.children_care_count'))
->placeholder(__('placeholder.number'))
->numeric()
->minValue(0)
->maxValue(99),

TextInput::make('children_under_10_care_count')
->label(__('field.children_under_10_care_count'))
->placeholder(__('placeholder.number'))
->numeric()
->minValue(0)
->maxValue(99),

TextInput::make('children_10_18_care_count')
->label(__('field.children_10_18_care_count'))
->placeholder(__('placeholder.number'))
->numeric()
->minValue(0)
->maxValue(99),

TextInput::make('children_18_care_count')
->label(__('field.children_18_care_count'))
->placeholder(__('placeholder.number'))
->numeric()
->minValue(0)
->maxValue(99),

TextInput::make('children_accompanying_count')
->label(__('field.children_accompanying_count'))
->placeholder(__('placeholder.number'))
->numeric()
->minValue(0)
->maxValue(99),
]),

TableRepeater::make('children')
->reorderable(false)
->columnSpanFull()
->hideLabels()
->addActionLabel(__('beneficiary.action.add_child'))
->disabled(fn (Get $get) => $get('doesnt_have_children'))
->emptyLabel(false)
->schema([
TextInput::make('name')
->label(__('field.child_name')),

TextInput::make('age')
->label(__('field.age')),

TextInput::make('address')
->label(__('field.current_address')),

TextInput::make('status')
->label(__('field.child_status')),
]),

Textarea::make('children_notes')
->label(__('field.children_notes'))
->placeholder(__('placeholder.other_relevant_details'))
->disabled(fn (Get $get) => $get('doesnt_have_children'))
->nullable()
->columnSpanFull(),
];
}
}
27 changes: 27 additions & 0 deletions app/Models/Beneficiary.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ class Beneficiary extends Model
'contact_notes',

'status',

'has_children',
'doesnt_have_children',
'children_total_count',
'children_care_count',
'children_under_10_care_count',
'children_10_18_care_count',
'children_18_care_count',
'children_accompanying_count',
'children',
'children_notes',
];

protected $casts = [
Expand All @@ -68,6 +79,14 @@ class Beneficiary extends Model
'effective_residence_environment' => ResidenceEnvironment::class,
'same_as_legal_residence' => 'boolean',
'status' => CaseStatus::class,
'has_children' => 'boolean',
'children_total_count' => 'integer',
'children_care_count' => 'integer',
'children_under_10_care_count' => 'integer',
'children_10_18_care_count' => 'integer',
'children_18_care_count' => 'integer',
'children_accompanying_count' => 'integer',
'children' => 'collection',
];

public function legalResidenceCounty(): BelongsTo
Expand All @@ -86,4 +105,12 @@ public function age(): Attribute
get: fn () => $this->birthdate?->age,
);
}

public function doesntHaveChildren(): Attribute
{
return Attribute::make(
get: fn () => ! $this->has_children,
set: fn ($value) => dd($value) && $this->has_children = ! $value,
);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"require": {
"php": "^8.2",
"alcea/cnp": "^3.0",
"awcodes/filament-table-repeater": "^2.0",
"blade-ui-kit/blade-icons": "^1.5",
"filament/filament": "^3.1",
"filament/spatie-laravel-media-library-plugin": "^3.1",
Expand Down
77 changes: 76 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 25 additions & 1 deletion database/factories/BeneficiaryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BeneficiaryFactory extends Factory
public function definition(): array
{
$birthdate = fake()
->dateTimeBetween('1900-01-01', '2099-12-31')
->dateTimeBetween('1900-01-01', 'now')
->format('Y-m-d');

$gender = fake()->randomElement(Gender::values());
Expand All @@ -45,6 +45,7 @@ public function definition(): array
'backup_phone' => fake()->boolean(25) ? fake()->phoneNumber() : null,

'status' => fake()->randomElement(CaseStatus::values()),
'has_children' => false,
];
}

Expand Down Expand Up @@ -104,4 +105,27 @@ public function withContactNotes(): static
'contact_notes' => fake()->paragraphs(asText: true),
]);
}

public function withChildren(): static
{
return $this->state(fn (array $attributes) => [
'has_children' => true,
'children_total_count' => fake()->numberBetween(1, 10),
'children_care_count' => fake()->numberBetween(1, 10),
'children_under_10_care_count' => fake()->numberBetween(1, 10),
'children_10_18_care_count' => fake()->numberBetween(1, 10),
'children_18_care_count' => fake()->numberBetween(1, 10),
'children_accompanying_count' => fake()->numberBetween(1, 10),

'children' => collect(range(1, 10))
->map(fn () => [
'name' => fake()->name(),
'age' => fake()->boolean() ? fake()->numberBetween(0, 20) : null,
'current_address' => fake()->boolean() ? fake()->address() : null,
'status' => fake()->boolean() ? fake()->words(asText: true) : null,
])
->toJson(),

]);
}
}
5 changes: 5 additions & 0 deletions database/factories/OrganizationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,22 @@ public function configure(): static
Beneficiary::factory()
->count(5)
->withContactNotes()
->withChildren()
->for($organization)
->create();

Beneficiary::factory()
->count(5)
->for($organization)
->withCNP()
->withChildren()
->create();

Beneficiary::factory()
->count(5)
->for($organization)
->withID()
->withChildren()
->create();

Beneficiary::factory()
Expand All @@ -91,13 +94,15 @@ public function configure(): static
->count(5)
->for($organization)
->withEffectiveResidence()
->withChildren()
->create();

Beneficiary::factory()
->count(5)
->for($organization)
->withLegalResidence()
->withEffectiveResidence()
->withChildren()
->create();

Service::query()
Expand Down
Loading

0 comments on commit 87fafe4

Please sign in to comment.