Skip to content

Commit

Permalink
### 26. Disabling-unavailable-dates
Browse files Browse the repository at this point in the history
### 26. Disabling-unavailable-dates

- This plugin lock the date that we cannot use.
- Define out the plugins that we want to use
- We can define the option under the lockPlugin key
- The minimum would be the current date and time
- Filter the date whether it is pickup or not
- A $avaialbleDates variable was created in checkoutController whether the $availability(dates or slots) has the particular slots.
- The hasSlots method was implemented in the app\Bookings\DateCollection class
- Die and dump the $avaialableDates
- Grab the date and grab the date object for the value of the lets grab the slots count, and casts this to an array
- Die and dump the $avaialableDates
- Grab the date and grab the date object for the value of the lets grab the slots count, and casts this to an array
- Die and dump the $avaialableDates
- The result will be the weekend will be escaped from the array
- Remove the dd
- Make $availableDates in the blade views to work as json encoded with in JavaScript, in the CheckoutController __invoke method, use the inside the calender
- Output the about data by json encoding the PHP array
- Check the available dates
- Check the output in the console
- Output the not available dates
- Change the appointment according to the day you are checking.
  • Loading branch information
lessandsass committed Oct 5, 2024
1 parent 813b47e commit 6b958a5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/Bookings/DateCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public function hasSlots()
return !$date->slots->isEmpty();
});
}

}
13 changes: 11 additions & 2 deletions app/Http/Controllers/CheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace App\Http\Controllers;

use App\Bookings\ServiceSlotAvailability;
use App\Models\Employee;
use App\Bookings\Date;
use App\Models\Service;
use App\Models\Employee;
use Illuminate\Http\Request;
use App\Bookings\ServiceSlotAvailability;

class CheckoutController extends Controller
{
Expand All @@ -20,10 +21,18 @@ public function __invoke(Employee $employee, Service $service)
now()->addMonth()->endOfDay()
);

$availableDates = $availability
->hasSlots()
->mapWithKeys(fn (Date $date) => [
$date->date->toDateString() => $date->slots->count()
])
->toArray();

return view('bookings.checkout', [
'employee' => $employee,
'service' => $service,
'firstAvailableDate' => $availability->firstAvailableDate()->date->toDateString(),
'availableDates' => $availableDates,
]);
}
}
14 changes: 12 additions & 2 deletions resources/views/bookings/checkout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

<div
x-data="{
picker: null
picker: null,
availableDates: {{ json_encode($availableDates) }},
}"
x-init="
this.picker = new easepick.create({
Expand All @@ -36,7 +37,16 @@
date: '{{ $firstAvailableDate }}',
css: [
'https://cdn.jsdelivr.net/npm/@easepick/[email protected]/dist/index.css',
]
],
plugins: [
'LockPlugin'
],
LockPlugin: {
minDate: new Date(),
filter (date, picked) {
return !Object.keys(availableDates).includes(date.format('YYYY-MM-DD'))
}
}
})
"
>
Expand Down

0 comments on commit 6b958a5

Please sign in to comment.