home-erp

git clone git://archive.git.mtrnord.blog/MTRNord/home-erp.git
Log | Files | Refs | README

commit f35b0039c11c7bd6dace4f8fa2039a059f4e8658
parent 740ae2397603677d6f11edf1b7183283364e894d
Author: MTRNord <mtrnord1@gmail.com>
Date:   Sat, 21 Oct 2023 21:28:14 +0200

Handle errors on room creation

Diffstat:
Mresources/views/livewire/dashboard/overview.blade.php | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/resources/views/livewire/dashboard/overview.blade.php b/resources/views/livewire/dashboard/overview.blade.php @@ -18,11 +18,17 @@ new class extends Component { public function createRoom(): void { $this->validate(); - Room::create([ - 'name' => $this->roomname, - 'description' => $this->description, - ]); - $this->dispatch('close'); + try { + Room::firstOrCreate([ + 'name' => $this->roomname, + 'description' => $this->description, + ]); + $this->roomname = ''; + $this->description = ''; + $this->dispatch('close'); + } catch (\Exception $e) { + $this->addError('create-error', 'Failed to create Room. Please notify the admin'); + } } public function with(): array @@ -82,6 +88,7 @@ new class extends Component { <x-primary-button class="ml-3"> {{ __('Create Room') }} </x-primary-button> + <x-input-error :messages="$errors->get('create-error')" class="mt-2" /> </div> </form> </x-modal>