Chain table headerActions

I have a headerAction in a table with two fields. I want to call a modal's method from the submit button of the first action, and paint the result as an Infolist in other action's modal with RepeatableEntries. Until now, I've never achieved to show the second modal. What am I doing wrong? πŸ€”
1 Reply
victorcamposramirez
victorcamposramirezOPβ€’3mo ago
This is my approach:
Action::make('effective_schedule')
->modalWidth('lg')
->modalHeading('Effective schedule')
->form([
DatePicker::make('date_from')
->required(),
DatePicker::make('date_to')
->required(),
])
->action(function (array $data) {
$store = $this->getOwnerRecord();
$dateFrom = $data['date_from'] ?? null;
$dateTo = $data['date_to'] ?? null;

// Get effective schedule
$effectiveSchedule = Schedule::effectiveSchedule($store->id, $dateFrom, $dateTo);
$effectiveSchedule = $effectiveSchedule->map(function (array $schedule) {
return [
'weekday' => $this->localeWeekdays()[$schedule['weekday']],
'from' => Date::parse($schedule['from'])->format('H:i'),
'to' => Date::parse($schedule['to'])->format('H:i'),
];
});

if ($effectiveSchedule->isEmpty()) {
Notification::make()
->title('There are no effective schedules in the selected range.')
->warning()
->send();
return;
}

// Call new action to show results
$this->replaceMountedAction('show_effective_schedule', [
'schedule' => $effectiveSchedule,
'date_from' => $dateFrom ? Date::parse($dateFrom)->format('d/m/Y') : 'N/A',
'date_to' => $dateTo ? Date::parse($dateTo)->format('d/m/Y') : 'N/A',
]);
}),
Action::make('show_effective_schedule')
->modalHeading('Effective schedule')
->modalWidth('lg')
->infolist([
RepeatableEntry::make('effective_schedule')
->columns(2)
->schema([
TextEntry::make('weekday'),
TextEntry::make('from'),
TextEntry::make('to'),
]),
])
->visible(false),
Action::make('effective_schedule')
->modalWidth('lg')
->modalHeading('Effective schedule')
->form([
DatePicker::make('date_from')
->required(),
DatePicker::make('date_to')
->required(),
])
->action(function (array $data) {
$store = $this->getOwnerRecord();
$dateFrom = $data['date_from'] ?? null;
$dateTo = $data['date_to'] ?? null;

// Get effective schedule
$effectiveSchedule = Schedule::effectiveSchedule($store->id, $dateFrom, $dateTo);
$effectiveSchedule = $effectiveSchedule->map(function (array $schedule) {
return [
'weekday' => $this->localeWeekdays()[$schedule['weekday']],
'from' => Date::parse($schedule['from'])->format('H:i'),
'to' => Date::parse($schedule['to'])->format('H:i'),
];
});

if ($effectiveSchedule->isEmpty()) {
Notification::make()
->title('There are no effective schedules in the selected range.')
->warning()
->send();
return;
}

// Call new action to show results
$this->replaceMountedAction('show_effective_schedule', [
'schedule' => $effectiveSchedule,
'date_from' => $dateFrom ? Date::parse($dateFrom)->format('d/m/Y') : 'N/A',
'date_to' => $dateTo ? Date::parse($dateTo)->format('d/m/Y') : 'N/A',
]);
}),
Action::make('show_effective_schedule')
->modalHeading('Effective schedule')
->modalWidth('lg')
->infolist([
RepeatableEntry::make('effective_schedule')
->columns(2)
->schema([
TextEntry::make('weekday'),
TextEntry::make('from'),
TextEntry::make('to'),
]),
])
->visible(false),

Did you find this page helpful?