Close Modal After Bulk Action

I have a confirmation modal for a custom bulk action. I neeed to close this modal when process is done. How I can do this?
18 Replies
Daniel Reales
Daniel RealesOPβ€’2y ago
This is my Bulk Action: ->bulkActions([ Tables\Actions\BulkAction::make('download') ->action(function (Collection $records, array $data) { self::saveRelationPublicityCustomers($records, $data['product_id']); self::downloadCustomersWithAddressForWord($records->load('city', 'province')->whereNotNull('address')); }) ->deselectRecordsAfterCompletion() ->icon('heroicon-o-document-download') ->label('Exportar a etiquetas') ->form([ Forms\Components\Select::make('product_id') ->reactive() ->options(Product::query()->pluck(column: 'name', key: 'id')) ->required() ->label('Producto'), ]) ]);
Thijmen
Thijmenβ€’2y ago
You could try to dispatch the browser event
Thijmen
Thijmenβ€’2y ago
GitHub
filament/packages/admin/src/Pages/Concerns/HasActions.php at 1afcb8...
Admin panel, form builder and table builder for Laravel. Built with the TALL stack. Designed for humans. - filament/packages/admin/src/Pages/Concerns/HasActions.php at 1afcb8e2f6cef0f04223423adedc2...
Daniel Reales
Daniel RealesOPβ€’2y ago
I don't know how I have to use this in my code... If I try to do this: ->after(fn(Component $livewire) => $livewire->dispatchBrowserEvent('close-modal', [ 'id' => $livewire->id ])) It's not works
Dan Harrin
Dan Harrinβ€’2y ago
where are you defining the modal in blade
Daniel Reales
Daniel RealesOPβ€’2y ago
No, My modal is in the table for Customer Resource. I did this: ->after(fn(Component $livewire) => $livewire->dispatchBrowserEvent('close-modal', [ 'id' => $livewire->id.'-table-bulk-action' ])) And now it works!
Dan Harrin
Dan Harrinβ€’2y ago
ohhhh it should close after the process is done anyway... you shouldnt need to tell it to thats very weird
LeandroFerreira
LeandroFerreiraβ€’2y ago
weird you could try this instead of $livewire:
->after(fn (Tables\Actions\BulkAction $action) => $action->cancel())
->after(fn (Tables\Actions\BulkAction $action) => $action->cancel())
Dan Harrin
Dan Harrinβ€’2y ago
it should still close....
Daniel Reales
Daniel RealesOPβ€’2y ago
@Dan Harrin @leandro_ferreira I think it's not closing the modal properly because at the end of the process I have the following: if(Storage::disk('public')->exists($nameFile)) { $urlFile = Storage::disk('public')->url($nameFile); return redirect($urlFile); } Redirect is the problem I think. But it's the only way I have managed to download the .docx file after the entire process.
Dan Harrin
Dan Harrinβ€’2y ago
try return response()->download($urlFile)
Dan Harrin
Dan Harrinβ€’2y ago
Livewire
File Downloads | Livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Daniel Reales
Daniel RealesOPβ€’2y ago
With this I' getting this error: APP_ENV('URL')/storage/clientes.docx does not exist. If I write this URL in the browser directly, it's working πŸ˜΅β€πŸ’«
Dan Harrin
Dan Harrinβ€’2y ago
maybe you need a path to the file instead of the url check the docs i sent
Daniel Reales
Daniel RealesOPβ€’2y ago
I try: return response()->download(Storage::disk('public')->path($nameFile)); return Storage::disk('public')->download($nameFile); And nothing... the process end correctly, but not downloaded in the browser
Dan Harrin
Dan Harrinβ€’2y ago
I don't know, sorry
Daniel Reales
Daniel RealesOPβ€’2y ago
thank you for your help!
awcodes
awcodesβ€’2y ago
Maybe let the modal close naturally and send a Notification with a link / action to download the file.
Want results from more Discord servers?
Add your server