From 5d609213ee415ce1b9fa3f6ced3e682993901c92 Mon Sep 17 00:00:00 2001 From: Rangga Adithia Date: Thu, 21 Dec 2023 14:04:52 +0800 Subject: [PATCH 1/4] Add imports and variables to LabController.php, update LabController@show method, add Livewire event handler to LabSchedule.php, update composer.json, update index.blade.php and lab.blade.php, and update lab-schedule.blade.php --- app/Http/Controllers/LabController.php | 9 ++++--- app/Livewire/LabSchedule.php | 5 ++++ composer.json | 2 +- resources/views/home/index.blade.php | 7 ----- resources/views/home/lab.blade.php | 27 +++++++++++++++++++ .../views/livewire/lab-schedule.blade.php | 13 ++++++++- 6 files changed, 51 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/LabController.php b/app/Http/Controllers/LabController.php index 30532f6..36bf611 100644 --- a/app/Http/Controllers/LabController.php +++ b/app/Http/Controllers/LabController.php @@ -2,12 +2,13 @@ namespace App\Http\Controllers; +use Mpdf\Tag\Time; use App\Models\Lab; -use App\Utilities\TimeMappings; use Illuminate\Support\Str; use Illuminate\Http\Request; +use App\Utilities\TimeMappings; +use Illuminate\Support\Facades\Route; use Illuminate\Database\QueryException; -use Mpdf\Tag\Time; class LabController extends Controller { @@ -52,7 +53,9 @@ public function store(Request $request) */ public function show(Lab $lab) { - return view('home.lab', compact('lab')); + $labs = Lab::all(); + $timeMappings = TimeMappings::$timeMappings; + return view('home.lab', compact('lab', 'labs', 'timeMappings')); } /** diff --git a/app/Livewire/LabSchedule.php b/app/Livewire/LabSchedule.php index 8c0b1be..d14182c 100644 --- a/app/Livewire/LabSchedule.php +++ b/app/Livewire/LabSchedule.php @@ -44,6 +44,11 @@ public function previousWeek() $this->mount(); } + #[On('success-booking-lab')] + public function updateSchedule($schedule) + { + } + public function mount() { $this->startDate = Carbon::now()->startOfWeek()->addWeeks($this->currentWeek - 1); diff --git a/composer.json b/composer.json index 1871b23..08ee162 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "laravel/framework": "^10.10", "laravel/sanctum": "^3.2", "laravel/tinker": "^2.8", - "livewire/livewire": "^3.0", + "livewire/livewire": "3.0,7", "maatwebsite/excel": "^3.1", "psr/simple-cache": "^2.0" }, diff --git a/resources/views/home/index.blade.php b/resources/views/home/index.blade.php index 0bc5a11..c2e9b10 100644 --- a/resources/views/home/index.blade.php +++ b/resources/views/home/index.blade.php @@ -33,13 +33,6 @@ }); Livewire.on('success-booking', function () { - // const toasty = document.getElementById('static-example'); - // toasty.classList.replace('data-[te-toast-show]:hidden', 'data-[te-toast-show]:block') - - // setTimeout(() => { - // toasty.classList.replace('data-[te-toast-show]:block', 'data-[te-toast-show]:hidden') - // }, 5000); - Swal.fire({ position: "top-end", title: 'Success!', diff --git a/resources/views/home/lab.blade.php b/resources/views/home/lab.blade.php index cac5f2b..5b56ee9 100644 --- a/resources/views/home/lab.blade.php +++ b/resources/views/home/lab.blade.php @@ -7,5 +7,32 @@ +@auth + +@endauth + +@push('scripts') + + +@endpush @endsection \ No newline at end of file diff --git a/resources/views/livewire/lab-schedule.blade.php b/resources/views/livewire/lab-schedule.blade.php index 27248ae..c8e7578 100644 --- a/resources/views/livewire/lab-schedule.blade.php +++ b/resources/views/livewire/lab-schedule.blade.php @@ -75,7 +75,7 @@ class="inline-block whitespace-nowrap rounded-[0.27rem] bg-neutral-50 px-[0.65em @php $totalRowspan = ceil((strtotime($booking['end_time']) - strtotime($booking['start_time'])) / 3600); @endphp -
+
{{ $booking['reason_to_booking'] }} {{ $booking['user']['name'] }} ({{ $booking['user']['role'] }}) {{ $booking['start_time'] }} - {{ $booking['end_time'] }} @@ -84,5 +84,16 @@ class="inline-block whitespace-nowrap rounded-[0.27rem] bg-neutral-50 px-[0.65em
+ @auth + @include('components.modal-button') + @else + + + + @endauth
+ From 7cf1396616efa5f3a6d2edbc9a00b8195dfefc89 Mon Sep 17 00:00:00 2001 From: Rangga Adithia Date: Thu, 21 Dec 2023 14:09:29 +0800 Subject: [PATCH 2/4] add selected lab --- app/Livewire/ModalBooking.php | 2 ++ .../views/livewire/modal-booking.blade.php | 20 ++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/app/Livewire/ModalBooking.php b/app/Livewire/ModalBooking.php index 0c5ba89..acc13e4 100644 --- a/app/Livewire/ModalBooking.php +++ b/app/Livewire/ModalBooking.php @@ -4,6 +4,7 @@ use Carbon\Carbon; +use App\Models\Lab; use Livewire\Component; use App\Models\LabsBooking; use App\Models\ClassSchedule; @@ -81,6 +82,7 @@ public function bookingLab() $this->dispatch('close-modal'); $this->dispatch('success-booking', schedule: $data['user_id']); + $this->dispatch('success-booking-lab', schedule: $data['lab_id']); $this->resetForm(); } } diff --git a/resources/views/livewire/modal-booking.blade.php b/resources/views/livewire/modal-booking.blade.php index 7423ce8..d78ecd8 100644 --- a/resources/views/livewire/modal-booking.blade.php +++ b/resources/views/livewire/modal-booking.blade.php @@ -94,12 +94,15 @@ class="peer block min-h-[auto] w-full rounded border-0 bg-neutral-100 px-3 py-[0
+
@error('lab_id'){{ $message }} @enderror
@@ -185,13 +188,6 @@ class="flex flex-shrink-0 flex-wrap items-center justify-end rounded-b-md border class="ml-1 inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-sm font-medium uppercase leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]" data-te-ripple-init data-te-ripple-color="light"> -
- -
Pinjam From f85992177423d11656536af2ac4ff3d69b738cda Mon Sep 17 00:00:00 2001 From: Rangga Adithia Date: Thu, 21 Dec 2023 14:28:04 +0800 Subject: [PATCH 3/4] chose lab --- app/Livewire/ModalBooking.php | 10 ++++++++++ resources/views/livewire/modal-booking.blade.php | 2 ++ 2 files changed, 12 insertions(+) diff --git a/app/Livewire/ModalBooking.php b/app/Livewire/ModalBooking.php index acc13e4..8d6d19b 100644 --- a/app/Livewire/ModalBooking.php +++ b/app/Livewire/ModalBooking.php @@ -22,6 +22,16 @@ public function mount($labs, $user, $timeMappings) $this->labs = $labs; $this->user = $user; $this->timeMappings = $timeMappings; + + if (request()->routeIs('lab.view')) { + $currentSlug = request()->segment(2); + + // Find the lab with the matching slug + $lab = Lab::where('slug', $currentSlug)->first(); + + // Set lab_id to the ID of the lab with the matching slug + $this->lab_id = optional($lab)->id; + } } public $lab_id; diff --git a/resources/views/livewire/modal-booking.blade.php b/resources/views/livewire/modal-booking.blade.php index d78ecd8..0863981 100644 --- a/resources/views/livewire/modal-booking.blade.php +++ b/resources/views/livewire/modal-booking.blade.php @@ -94,7 +94,9 @@ class="peer block min-h-[auto] w-full rounded border-0 bg-neutral-100 px-3 py-[0