Skip to content

Instantly share code, notes, and snippets.

@barianiluca
Created January 9, 2025 12:32
action wizard and prepopulate
return Action::make('subscribeMember')
->label(function (array $arguments) {
return ($arguments['member_id']) ? _('Subscribe Member') : __('Register new member');
})
->mountUsing(function (Form $form, array $arguments) {
$form->getComponent($form->getStatePath() . '.member_certificates')
->options(
fn() => MemberCertificate::whereMemberId($arguments['member_id'])
->pluck('id', 'expire_Date')
);
})
->fillForm(function (array $arguments) use ($local_competition) {
$_filled = array_merge(
($arguments['member_id']) ? Member::where('id', '=', $arguments['member_id'])->first()->toArray() : [],
[
'regulation_txt' => $local_competition->regulation_txt,
'privacy_txt' => $local_competition->privacy_txt,
'marketing_agency_txt' => $local_competition->marketing_agency_txt,
'marketing_partner_txt' => $local_competition->marketing_partner_txt
]
);
return $_filled;
})
->modalWidth('8xl')
->steps([
Step::make('Personal data')
->description('Check personal data before to procede')
->schema([
Toggle::make('is_main')
->label(__('This is the profile of the main account.'))
->disabled()
->required()
->visible(function ($record) {
if ((isset($is_main) && $record->is_main == 1))
return true;
})
->columnSpanFull(),
TextInput::make('firstname')
->translateLabel()
->required()
->maxLength(255),
TextInput::make('lastname')
->translateLabel()
->required()
->maxLength(255),
Select::make('gender')
->translateLabel()
->options([
'm' => __('Man'),
'w' => __('Woman')
])
->required(),
DatePicker::make('birth_date')
->translateLabel()
->required(),
TextInput::make('mobile')
->translateLabel()
->required()
->maxLength(255),
TextInput::make('email')
->translateLabel()
->email()
->required()
->maxLength(255),
Select::make('country_id')
->label(__('Country'))
->options(function () {
return Country::pluck('name', 'id')->all();
})
->afterStateUpdated(function (Set $set, Get $get, ?string $state) {
if (Region::where('country_id', $get('country_id'))->first() === null) {
$set('region_id', null);
$set('province_id', null);
}
return $state;
})
->live()
->required(),
Select::make('region_id')
->label(__('Region'))
->options(function (Get $get, Set $set, ?string $state): array {
if (($get('country_id') === null) || (Region::where('country_id', $get('country_id'))->first() === null)) {
return [];
}
return Region::where('country_id', $get('country_id'))->pluck('name', 'id')->all();
})
->live(),
Select::make('province_id')
->label(__('Province'))
->options(function (Get $get): array {
if (($get('region_id') === null) || (Province::where('region_id', $get('region_id'))->first() === null)) {
return [];
}
return Province::where('region_id', $get('region_id'))->pluck('name', 'id')->all();
})
->live(),
])
->columns(2),
Step::make('Documents')
->description('Please select or add the required documents')
->schema([
Section::make('Certificate')
->description('Select or add a valid certificate')
->schema([
Radio::make('member_certificates')
]),
Section::make('Cards')
->description('Add the card')
->schema([
Radio::make('member_cards')
->options(function () {
return MemberCard::where('member_id', '=', 940)->pluck('id', 'issuing_date')->toArray();
})
]),
]),
Step::make('Customize')
->description('Customize the subscription for this member')
->schema([
// ...
]),
Step::make('Agreements')
->description('Accept competition agreements and procede')
->schema([
Textarea::make('regulation_txt')
->readonly(),
Toggle::make('regulation_txt_accepted')
->label('Regulation')
->accepted(),
Textarea::make('privacy_txt')
->readonly(),
Toggle::make('privacy_txt_accepted')
->label('Privacy')
->accepted(),
Textarea::make('marketing_agency_txt')
->readonly(),
Toggle::make('marketing_agency_txt_accepted')
->label('Marketing Agency')
->accepted(),
Textarea::make('marketing_partner_txt')
->readonly(),
Toggle::make('marketing_partner_txt_accepted')
->label('Marketing Partner')
->accepted(),
]),
])
->action(function (array $data, Member $member): void {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment