Files
calendar/packages/features/bookings/lib/useCheckOverlapWithOverlay.tsx
T
b4c6388ce0 feat: overlay your calendar (#11693)
* Init header + login modal component

* Add calendar settings for authed user

* Local storage and using query params for toggle

* Toggle connect screen if query param present and no session

* Local storage + store + way more than that should be in single commit

* Display busy events on weekly view

* Confirm booking slot of overlap exists

* use chevron right when on column view

* Show hover card - overlapping date times

* Invalidate on switch

* FIx clearing local storage when you login to another account

* Force re-render on url state (atom quirks)

* Add loading screen

* Add dialog close

* Remove extra grid config

* Translations

* [WIP] - tests

* fix: google calendar busy times (#11696)

Co-authored-by: CarinaWolli <wollencarina@gmail.com>

* New Crowdin translations by Github Action

* fix: rescheduled value DB update on reschedule and insights view cancelleds (#11474)

* v3.3.5

* fix minutes string (#11703)

Co-authored-by: CarinaWolli <wollencarina@gmail.com>

* Regenerated yarn.lock

* Add error component + loader

* await tests

* disable tests - add note

* Refactor to include selected time

* use no-scrollbar

* Fix i18n

* Fix tablet toolbar

* overflow + i18n

* Export empty object as test is TODO

* Uses booker timezone

* Fix hiding switch too early

* Handle selected timezone

* Fix timezone issues

* Fix timezone issues

---------

Co-authored-by: Carina Wollendorfer <30310907+CarinaWolli@users.noreply.github.com>
Co-authored-by: CarinaWolli <wollencarina@gmail.com>
Co-authored-by: Crowdin Bot <support+bot@crowdin.com>
Co-authored-by: alannnc <alannnc@gmail.com>
Co-authored-by: Alex van Andel <me@alexvanandel.com>
Co-authored-by: Peer Richelsen <peer@cal.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
2023-10-10 12:05:20 +01:00

42 lines
1.5 KiB
TypeScript

import type { Dayjs } from "@calcom/dayjs";
import dayjs from "@calcom/dayjs";
import { useOverlayCalendarStore } from "../Booker/components/OverlayCalendar/store";
function getCurrentTime(date: Date) {
const hours = date.getHours().toString().padStart(2, "0");
const minutes = date.getMinutes().toString().padStart(2, "0");
return `${hours}:${minutes}`;
}
export function useCheckOverlapWithOverlay(start: Dayjs, selectedDuration: number | null, offset: number) {
const overlayBusyDates = useOverlayCalendarStore((state) => state.overlayBusyDates);
let overlappingTimeStart: string | null = null;
let overlappingTimeEnd: string | null = null;
const isOverlapping =
overlayBusyDates &&
overlayBusyDates.some((busyDate) => {
const busyDateStart = dayjs(busyDate.start);
const busyDateEnd = dayjs(busyDate.end);
const selectedEndTime = dayjs(start.add(offset, "hours")).add(selectedDuration ?? 0, "minute");
const isOverlapping =
(selectedEndTime.isSame(busyDateStart) || selectedEndTime.isAfter(busyDateStart)) &&
start.add(offset, "hours") < busyDateEnd &&
selectedEndTime > busyDateStart;
overlappingTimeStart = isOverlapping ? getCurrentTime(busyDateStart.toDate()) : null;
overlappingTimeEnd = isOverlapping ? getCurrentTime(busyDateEnd.toDate()) : null;
return isOverlapping;
});
return { isOverlapping, overlappingTimeStart, overlappingTimeEnd } as {
isOverlapping: boolean;
overlappingTimeStart: string | null;
overlappingTimeEnd: string | null;
};
}