From 8bd72147b9fcfc6a341bc73d248cc09d45627ab1 Mon Sep 17 00:00:00 2001 From: Ivan Moroz Date: Fri, 29 May 2026 20:38:17 +0300 Subject: [PATCH] CONV-080: Add upload error states --- app/Livewire/Dashboard/DashboardConverter.php | 30 +++++++++++++++---- .../dashboard/dashboard-converter.blade.php | 4 +++ .../Livewire/DashboardConverterUploadTest.php | 13 ++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/app/Livewire/Dashboard/DashboardConverter.php b/app/Livewire/Dashboard/DashboardConverter.php index 33aec3b..16782b3 100644 --- a/app/Livewire/Dashboard/DashboardConverter.php +++ b/app/Livewire/Dashboard/DashboardConverter.php @@ -3,6 +3,8 @@ namespace App\Livewire\Dashboard; use App\Actions\Files\StoreUploadedFileAction; +use App\Exceptions\Files\FileStorageException; +use App\Exceptions\Files\UnsupportedFileFormatException; use App\Models\FileRecord; use App\Support\Files\UploadedFileRules; use Livewire\Component; @@ -26,13 +28,31 @@ public function storeUpload(StoreUploadedFileAction $storeUploadedFile): void $this->uploadError = null; $this->validate([ - 'upload' => UploadedFileRules::rules(), + 'upload' => [ + 'required', + 'file', + 'max:'.UploadedFileRules::MAX_FILE_KILOBYTES, + ], + ], [ + 'upload.max' => 'This file is too large. Max upload size is '.(UploadedFileRules::MAX_FILE_KILOBYTES / 1024).' MB.', ]); - $fileRecord = $storeUploadedFile->handle( - user: auth()->user(), - file: $this->upload, - ); + try { + $fileRecord = $storeUploadedFile->handle( + user: auth()->user(), + file: $this->upload, + ); + } catch (UnsupportedFileFormatException) { + $this->uploadError = 'This file type is not supported in beta. Upload PNG, JPG, WEBP or PDF.'; + $this->step = 'upload'; + + return; + } catch (FileStorageException) { + $this->uploadError = 'We could not store your file. Please try again.'; + $this->step = 'upload'; + + return; + } $this->currentFileId = $fileRecord->id; $this->step = 'format'; diff --git a/resources/views/livewire/dashboard/dashboard-converter.blade.php b/resources/views/livewire/dashboard/dashboard-converter.blade.php index 6dca2e6..9b7a367 100644 --- a/resources/views/livewire/dashboard/dashboard-converter.blade.php +++ b/resources/views/livewire/dashboard/dashboard-converter.blade.php @@ -32,6 +32,10 @@ class="flex flex-col items-center justify-center gap-4 rounded-[var(--ca-radius- @error('upload')

{{ $message }}

@enderror + + @if ($uploadError) +

{{ $uploadError }}

+ @endif @endif diff --git a/tests/Feature/Livewire/DashboardConverterUploadTest.php b/tests/Feature/Livewire/DashboardConverterUploadTest.php index 1ae9ee2..5836286 100644 --- a/tests/Feature/Livewire/DashboardConverterUploadTest.php +++ b/tests/Feature/Livewire/DashboardConverterUploadTest.php @@ -55,6 +55,19 @@ ->assertDontSee('remove-me.png'); }); +it('shows an error for unsupported upload format', function () { + Storage::fake('local'); + + $user = User::factory()->create(); + + Livewire::actingAs($user) + ->test(DashboardConverter::class) + ->set('upload', UploadedFile::fake()->create('notes.txt', 10, 'text/plain')) + ->call('storeUpload') + ->assertSet('step', 'upload') + ->assertSee('not supported'); +}); + it('shows uploaded file summary after upload', function () { Storage::fake('local');