* feat: Don't allow unavailable slot's booking form to be visible - Send back to slots listing * Improvements * feat: Add env variables and strategies to prevent booking failures - Added new environment variables for configuring slot reservation and availability checks - Implemented strategies to handle concurrent bookings and slot availability - Updated Booker component and related files to support new reservation and slot checking mechanisms - Added README with detailed explanation of booking prevention strategies - Configured dynamic intervals for slot and reservation queries * docs: Update Booker README with detailed slot reservation and availability explanation - Clarified slot reservation behavior when multiple users access the same booking page - Added details about `getSchedule` refetching strategies and timing - Explained how slot availability is detected and communicated to users * Support for skip confirmation form flow * feat: Enhance slot availability and reservation mechanism - Refactored slot availability checking to support multiple slots - Added tentative selected timeslots to improve booking UX - Updated trpc handler to check availability for multiple slots - Introduced new store methods for managing tentative slot selections - Improved slot reservation and availability status tracking * refactor: Improve slot availability quick check mechanism - Renamed and restructured slot availability check parameters - Extracted quick availability checks into a separate hook - Updated type definitions for slot status and availability checks - Simplified slot availability logic in Booker and related components - Maintained cached state for quick availability checks * Support minimu booking check too * change data-testid * Rneame * Fix race condition with uid cookie not set * fix tests * Remove unsded variable --------- Co-authored-by: Hariom Balhara <hariombalhara@gmgmail.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
44 lines
1.8 KiB
TypeScript
44 lines
1.8 KiB
TypeScript
// Basic ISO format validation using string checks
|
|
// Without RegExp check, to keep it fast and simple
|
|
export const isValidISOFormat = (dateStr: string) => {
|
|
if (dateStr.length < 16) return false;
|
|
|
|
// Check for required separators
|
|
return dateStr[4] === "-" && dateStr[7] === "-" && dateStr[10] === "T" && dateStr[13] === ":";
|
|
};
|
|
|
|
/**
|
|
* Compares two time slots for equality, optionally ignoring seconds
|
|
* @param slotTimeInIso - The available time slot to check
|
|
* @param slotToCheckInIso - The slot to compare against
|
|
* @returns boolean indicating if the slots match
|
|
*/
|
|
export const isSlotEquivalent = ({
|
|
slotTimeInIso,
|
|
slotToCheckInIso,
|
|
}: {
|
|
slotTimeInIso: string;
|
|
slotToCheckInIso: string;
|
|
}): boolean => {
|
|
// String comparison is faster than date comparison. So, compare string equality first
|
|
if (slotTimeInIso === slotToCheckInIso) {
|
|
return true;
|
|
}
|
|
|
|
if (!isValidISOFormat(slotTimeInIso) || !isValidISOFormat(slotToCheckInIso)) {
|
|
console.log("Invalid ISO string format detected", { slotTimeInIso, slotToCheckInIso });
|
|
// Consider slots equivalent
|
|
return true;
|
|
}
|
|
|
|
// We ignore seconds and see if the minutes match
|
|
// For very short duration slots, we seem to have some bug that creates timeslots with seconds in them which isn't normally the case
|
|
// Till, we handle that, we ignore seconds explicitly. It could be better to have this even after that.
|
|
// It allows "confirm" button to be not disabled in such case.
|
|
// Actual booking confirmation, can still reject the booking if we allow a non-bookable slot to be considered available here.
|
|
// 2025-02-08T14:23:45Z -> 2025-02-08T14:23
|
|
const availableSlotIgnoringSeconds = slotTimeInIso.slice(0, 16);
|
|
const slotToCheckIgnoringSeconds = slotToCheckInIso.slice(0, 16);
|
|
return availableSlotIgnoringSeconds === slotToCheckIgnoringSeconds;
|
|
};
|