diff --git a/apps/web/pages/availability/troubleshoot.tsx b/apps/web/pages/availability/troubleshoot.tsx index d85147e490..e39e75d122 100644 --- a/apps/web/pages/availability/troubleshoot.tsx +++ b/apps/web/pages/availability/troubleshoot.tsx @@ -1,7 +1,5 @@ import dayjs from "@calcom/dayjs"; -import { Calendar } from "@calcom/features/calendars/weeklyview"; import Shell from "@calcom/features/shell/Shell"; -import { yyyymmdd } from "@calcom/lib/date-fns"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { RouterOutputs, trpc } from "@calcom/trpc/react"; import { SkeletonText } from "@calcom/ui"; @@ -18,13 +16,13 @@ export interface IBusySlot { } const AvailabilityView = ({ user }: { user: User }) => { + const { t } = useLocale(); const { date, setQuery: setSelectedDate } = useRouterQuery("date"); const selectedDate = dayjs(date); const formattedSelectedDate = selectedDate.format("YYYY-MM-DD"); - const { data } = trpc.viewer.availability.user.useQuery( + const { data, isLoading } = trpc.viewer.availability.user.useQuery( { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion username: user.username!, dateFrom: selectedDate.startOf("day").utc().format(), dateTo: selectedDate.endOf("day").utc().format(), @@ -47,26 +45,70 @@ const AvailabilityView = ({ user }: { user: User }) => { }, [] as IBusySlot[]) || []; return ( -
-
- (a.start > b.start ? -1 : 1)) - .map((slot) => ({ - // TODO: Modify the Calendar view to be better at displaying blocks. - id: undefined, - title: - (slot.title ? `(${slot.title}) - ` : "") + (slot.source ? `(source: ${slot.source})` : ""), - start: new Date(slot.start), - end: new Date(slot.end), - }))} - onDateChange={(e) => setSelectedDate(yyyymmdd(e))} - startDate={selectedDate.startOf("day").toDate()} - endDate={selectedDate.endOf("day").toDate()} - view="day" +
+
+ {t("overview_of_day")}{" "} + { + if (e.target.value) setSelectedDate(e.target.value); + }} /> + {t("hover_over_bold_times_tip")} +
+
+
+ {t("your_day_starts_at")} {convertMinsToHrsMins(user.startTime)} +
+
+ {(() => { + if (isLoading) + return ( + <> + + + + ); + + if (data && (data.busy.length > 0 || overrides.length > 0)) + return [...data.busy, ...overrides] + .sort((a: IBusySlot, b: IBusySlot) => (a.start > b.start ? -1 : 1)) + .map((slot: IBusySlot) => ( +
+
+ {t("calendar_shows_busy_between")}{" "} + + {dayjs(slot.start).format("HH:mm")} + {" "} + {t("and")}{" "} + + {dayjs(slot.end).format("HH:mm")} + {" "} + {t("on")} {dayjs(slot.start).format("D")}{" "} + {t(dayjs(slot.start).format("MMMM").toLowerCase())} {dayjs(slot.start).format("YYYY")} + {slot.title && ` - (${slot.title})`} + {slot.source && {` - (source: ${slot.source})`}} +
+
+ )); + return ( +
+
{t("calendar_no_busy_slots")}
+
+ ); + })()} + +
+
+ {t("your_day_ends_at")} {convertMinsToHrsMins(user.endTime)} +
+
+
); @@ -83,3 +125,11 @@ export default function Troubleshoot() {
); } + +function convertMinsToHrsMins(mins: number) { + const h = Math.floor(mins / 60); + const m = mins % 60; + const hs = h < 10 ? "0" + h : h; + const ms = m < 10 ? "0" + m : m; + return `${hs}:${ms}`; +} diff --git a/apps/web/playwright/availability.e2e.ts b/apps/web/playwright/availability.e2e.ts index 81ddd9ab6d..4bebb0f0d8 100644 --- a/apps/web/playwright/availability.e2e.ts +++ b/apps/web/playwright/availability.e2e.ts @@ -32,16 +32,15 @@ test.describe("Availablity tests", () => { await page.locator('[form="availability-form"][type="submit"]').click(); }); - // The troubleshooter is unaware of the selected schedule, kept the override logic for now but needs rework. - // await test.step("Date override is displayed in troubleshooter", async () => { - // const response = await page.waitForResponse("**/api/trpc/viewer.availability.schedule.update?batch=1"); - // const json = await response.json(); - // // @ts-expect-error trust me bro - // const date = json[0].result.data.json.schedule.availability.find((a) => !!a.date); - // const troubleshooterURL = `/availability/troubleshoot?date=${dayjs(date.date).format("YYYY-MM-DD")}`; - // await page.goto(troubleshooterURL); - // await expect(page.locator('[data-testid="troubleshooter-busy-time"]')).toHaveCount(1); - // }); + await test.step("Date override is displayed in troubleshooter", async () => { + const response = await page.waitForResponse("**/api/trpc/viewer.availability.schedule.update?batch=1"); + const json = await response.json(); + // @ts-expect-error trust me bro + const date = json[0].result.data.json.schedule.availability.find((a) => !!a.date); + const troubleshooterURL = `/availability/troubleshoot?date=${dayjs(date.date).format("YYYY-MM-DD")}`; + await page.goto(troubleshooterURL); + await expect(page.locator('[data-testid="troubleshooter-busy-time"]')).toHaveCount(1); + }); }); test("Availablity pages", async ({ page }) => { diff --git a/packages/features/calendars/weeklyview/components/heading/SchedulerHeading.tsx b/packages/features/calendars/weeklyview/components/heading/SchedulerHeading.tsx index d9715f6a85..e712c22fad 100644 --- a/packages/features/calendars/weeklyview/components/heading/SchedulerHeading.tsx +++ b/packages/features/calendars/weeklyview/components/heading/SchedulerHeading.tsx @@ -14,8 +14,7 @@ export function SchedulerHeading() { return (

- {startDate.format("MMM DD")} - {!startDate.isSame(endDate, "day") ? `-${endDate.format("DD")}` : ""} + {startDate.format("MMM DD")}-{endDate.format("DD")} ,{startDate.format("YYYY")}