Trigger a modal action from within Repeater extraItemActions

Hello, I have something like this:
Repeater::make('reports_samples_ids')
->columnSpanFull()
->extraItemActions([
Action::make('generare_raport_grupa')
->icon(Heroicon::Envelope)
->action(function (array $arguments, $state, $context, Repeater $component, Order $itemRecord): void {

$itemData = $component->getItemState($arguments['item']);


$pdfExists = self::findPdf($itemRecord->id, $arguments['item']);

// here i want to check if pdfExists and if so, i want to open a modal action with submit and cance footer actions

self::confirmReportGeneration($arguments['item'], $itemRecord->id);

}),
])
Repeater::make('reports_samples_ids')
->columnSpanFull()
->extraItemActions([
Action::make('generare_raport_grupa')
->icon(Heroicon::Envelope)
->action(function (array $arguments, $state, $context, Repeater $component, Order $itemRecord): void {

$itemData = $component->getItemState($arguments['item']);


$pdfExists = self::findPdf($itemRecord->id, $arguments['item']);

// here i want to check if pdfExists and if so, i want to open a modal action with submit and cance footer actions

self::confirmReportGeneration($arguments['item'], $itemRecord->id);

}),
])
any idea if this is possible?
5 Replies
jamesro
jamesroOP4w ago
I've tried something like using notification, but when i click :
if ($pdfExists) {
// PDF exists -> show confirmation modal
Notification::make()
->title('Raport exists already')
->body('Report exists already, do you want a new one?')
->warning()
->actions([
Action::make('generateNew')
->label('Generate new report')
->action(fn() => self::generateAndDownloadReport($itemRecord->id, $arguments['item'])),
])
->send();
} else {
self::generateAndDownloadReport($itemRecord->id, $arguments['item']);
}
if ($pdfExists) {
// PDF exists -> show confirmation modal
Notification::make()
->title('Raport exists already')
->body('Report exists already, do you want a new one?')
->warning()
->actions([
Action::make('generateNew')
->label('Generate new report')
->action(fn() => self::generateAndDownloadReport($itemRecord->id, $arguments['item'])),
])
->send();
} else {
self::generateAndDownloadReport($itemRecord->id, $arguments['item']);
}
when i click on "Generate new report" action in the notification it shows this error
Unable to call component method. Public method [mountAction] not found on component
Unable to call component method. Public method [mountAction] not found on component
ralphjsmit
ralphjsmit4w ago
Look at the $livewire->replaceMountedAction() function You'll need to figure out the exact arguments to pass to it depending on where your second modal action is defined
jamesro
jamesroOP4w ago
@ralphjsmit you refer for case when i'm trying to trigger another action ? i think there's a but with actions on repeater in v4 🙁
ralphjsmit
ralphjsmit4w ago
Yes
jamesro
jamesroOP4w ago
ended up doing something like this
->action(function ($action, $arguments, Repeater $component, Order $itemRecord) {
if(isset($arguments['actual']) && $arguments['actual']) {
return self::downloadGeneratedReport($itemRecord->id, $arguments['item']);
}
return self::generateAndDownloadReport($itemRecord->id, $arguments['item']);
})
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['actual' => true])->label('Download actual report'),
]),
->action(function ($action, $arguments, Repeater $component, Order $itemRecord) {
if(isset($arguments['actual']) && $arguments['actual']) {
return self::downloadGeneratedReport($itemRecord->id, $arguments['item']);
}
return self::generateAndDownloadReport($itemRecord->id, $arguments['item']);
})
->extraModalFooterActions(fn (Action $action): array => [
$action->makeModalSubmitAction('createAnother', arguments: ['actual' => true])->label('Download actual report'),
]),

Did you find this page helpful?