|
16 | 16 | use SolutionForest\InspireCms\Filament\Clusters\Settings; |
17 | 17 | use SolutionForest\InspireCms\Filament\Concerns\ClusterSectionResourceTrait; |
18 | 18 | use SolutionForest\InspireCms\Filament\Contracts\ClusterSectionResource; |
19 | | -use SolutionForest\InspireCms\Filament\Forms\Components\Actions\DownloadSampleAction; |
20 | 19 | use SolutionForest\InspireCms\Filament\Infolists\Components\Actions\DownloadAction; |
21 | 20 | use SolutionForest\InspireCms\Helpers\ImportDataHelper; |
22 | 21 | use SolutionForest\InspireCms\Helpers\UIHelper; |
23 | 22 | use SolutionForest\InspireCms\Helpers\UrlHelper; |
24 | 23 | use SolutionForest\InspireCms\InspireCmsConfig; |
25 | 24 | use SolutionForest\InspireCms\Models\Contracts\Import; |
| 25 | +use SolutionForest\InspireCms\Services\ImportServiceInterface; |
26 | 26 |
|
27 | 27 | class ImportResource extends Resource implements ClusterSectionResource |
28 | 28 | { |
@@ -146,8 +146,26 @@ public static function form(Form $form): Form |
146 | 146 | ->preserveFilenames(false), |
147 | 147 |
|
148 | 148 | Forms\Components\Actions::make([ |
149 | | - DownloadSampleAction::make() |
150 | | - ->url(fn () => UrlHelper::attemptToGetRoute('inspirecms.import.sample')), |
| 149 | + Forms\Components\Actions\Action::make('download_sample') |
| 150 | + ->label(__('inspirecms::buttons.download_sample.label')) |
| 151 | + ->icon(FilamentIcon::resolve('inspirecms::download')) |
| 152 | + ->button() |
| 153 | + ->outlined() |
| 154 | + ->color('warning') |
| 155 | + ->failureNotificationTitle('Download Failed') |
| 156 | + ->action(function (Forms\Components\Actions\Action $action) { |
| 157 | + try { |
| 158 | + $importService = app(ImportServiceInterface::class); |
| 159 | + |
| 160 | + $file = $importService->buildSampleZip(); |
| 161 | + |
| 162 | + return response() |
| 163 | + ->download($file, 'import-sample-' . uniqid() . '.zip') |
| 164 | + ->deleteFileAfterSend(true); |
| 165 | + } catch (\Throwable $th) { |
| 166 | + $action->failure(); |
| 167 | + } |
| 168 | + }), |
151 | 169 | ])->alignEnd(), |
152 | 170 | Forms\Components\Placeholder::make('file_structure_instructions') |
153 | 171 | ->label(__('inspirecms::resources/import.file_structure_instructions.label')) |
|
0 commit comments