Skip to main content

Rendering a Calendar

Rendering Rows and Columns

Data

Each instance of the Sesami SDK will contain a data object with the following structure:

PropertyTypeDescription
labelsArray<Date>An array of Date objects.
rowsArray<Array<SesamiDayObject>>A 2D array containing SesamiDayObject arrays.
type Data = {
labels: Date[]
rows: SesamiDayObject[][]
}

SesamiDayObject

PropertyTypeDescription
dateDateRepresents the day.
isCurrentMonthBooleanIndicates if the day is in the current month.
isCurrentWeekBooleanIndicates if the day is in the current week.
isPastBooleanIndicates if the day is in the past.
isTodayBooleanIndicates if the day is today.
getAvailabilities()async functionResolves to an array of available slots (Promise<Array<SesamiSlotObject>>).
onLoad(callback)FunctionReceives cell availabilities for the selected range when autoLoad is enabled. (This method will only trigger a network request when the data is not already available).
onError(callback)FunctionReceives errors when fetching cell availabilities.
SesamiDayObject
{
labels: [
Sun Dec 05 2021 00:00:00 {},
Mon Nov 29 2021 00:00:00 {},
...
],
rows: [
[
{
date: Sun Nov 28 2021 00:00:00 {},
isCurrentMonth: false,
isCurrentWeek: false,
isPast: true,
isToday: false,
getAvailabilities: async ƒ (),
onLoad: ƒ (callback: ƒ ()),
onError: ƒ (callback: ƒ ())
},
...
]
...
]
}

Example to display the calendar labels:

const dayName = (date) => new Intl.DateTimeFormat('en-US', { weekday: 'short' }).format(date)

window.sesami.data.labels.forEach(dateString => {
calendarLabels.innerHTML += `<li>${dayName(new Date(dateString))}</li>`
})

Example to display the calendar rows:

window.sesami.data.rows.forEach(row => {

row.forEach(async day => {
const className = day.isPast ? 'inactive' : 'active'
const dayElement = document.createElement('li')
dayElement.className = className
dayElement.textContent = new Date(day.date).getDate()
days.appendChild(dayElement)

try{
const availabilities = await day.getAvailabilities()
console.log(`Availabilities for ${day.date}:`, availabilities)
}catch(error){
console.error(`Error fetching availabilities for ${day.date}:`, error)
}

dayElement.addEventListener('click', () => {
if(!day.isPast){
selectDay(day)
}
})

})

})

Getting Availabilities

Each day object contains a getAvailabilities() method, which returns available slots.

type getAvailabilities = () => SesamiSlotObject[]

SesamiSlotObject

PropertyTypeDescription
startTimeStringStarting date and time in the format YYYY-MM-DD HH:mm.
durationNumberSlot duration in minutes.
statusStringCurrent slot status ("available" for storefront integrations).
remainingSlotsNumberRemaining slots at the selected time (always 1 except for group appointments).

Example

[
{
"startTime": "2022-12-30 10:00",
"duration": 15,
"status": "available",
"remainingSlots": 1
},
{
"startTime": "2022-12-30 10:15",
"duration": 15,
"status": "available",
"remainingSlots": 3
},
...
]