Create a dynamic calendar view for an event-booking use case
This example shows you how you can implement a calendar view with a custom workflow involving dynamic API calls.

In our example, we want to manage the bookings for a sports court where:
We have a list of court opening dates. Each date can be subject to a price increase if the period is busy. These dates come from a collection called
availableDatesA list of available slots appears after selecting a date and duration. These available slots come from a smart collection called
availableSlotsThe user can book a specific slot using a smart action called
book.
How it works
Smart view definition
Learn more about smart views. File template.hbs
This file contains the HTML and CSS needed to build the view.
File template.js
This file contains all the logic needed to handle events and actions.
Available dates model
File models/available-dates.js
This file contains the model definition for the collection availableDates. It is located in the models folder, at the root of the admin backend.
Available slots smart collection
To create a smart collection that returns records built from an API call, two files need to be created:
a file
available-slots.jsinside the folderforestto declare the collectiona file
available-slots.jsinside theroutesfolder to implement theGETlogic for the collection
File forest/available-slots.js
This file includes the smart collection definition.
File routes/available-slots.js
This file includes the logic implemented to retrieve the available slots from an API call and return them serialized to the UI.
Book smart action
To create the action to book a slot, two files need to be updated:
the file
available-slots.jsinside the folderforestto declare the actionthe file
available-slots.jsinside theroutesfolder to implement the logic for the action
File forest/available-slots.js
This file includes the smart action definition. The action form is pre-filled with the start and end date. The last step is to select the user associated with this booking.
File routes/available-slots.js
This file includes the logic of the smart action. It basically creates a record from the bookings collection with the information passed on by the user input form.
Last updated
Was this helpful?