2022-09-07 19:28:43 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
2023-01-10 15:39:29 +00:00
|
|
|
import Shell from "@calcom/features/shell/Shell";
|
2022-08-24 20:18:42 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2023-02-16 22:39:57 +00:00
|
|
|
import type { RouterOutputs } from "@calcom/trpc/react";
|
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-01-10 15:39:29 +00:00
|
|
|
import { SkeletonText } from "@calcom/ui";
|
2022-08-24 20:18:42 +00:00
|
|
|
|
2022-12-15 20:19:35 +00:00
|
|
|
import useRouterQuery from "@lib/hooks/useRouterQuery";
|
|
|
|
|
2023-04-18 18:45:32 +00:00
|
|
|
import PageWrapper from "@components/PageWrapper";
|
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
type User = RouterOutputs["viewer"]["me"];
|
2022-08-24 20:18:42 +00:00
|
|
|
|
2022-09-07 19:28:43 +00:00
|
|
|
export interface IBusySlot {
|
2022-10-12 05:29:04 +00:00
|
|
|
start: string | Date;
|
|
|
|
end: string | Date;
|
2022-09-07 19:28:43 +00:00
|
|
|
title?: string;
|
|
|
|
source?: string | null;
|
|
|
|
}
|
|
|
|
|
2022-08-24 20:18:42 +00:00
|
|
|
const AvailabilityView = ({ user }: { user: User }) => {
|
2023-02-09 19:01:43 +00:00
|
|
|
const { t } = useLocale();
|
2022-12-15 20:19:35 +00:00
|
|
|
const { date, setQuery: setSelectedDate } = useRouterQuery("date");
|
|
|
|
const selectedDate = dayjs(date);
|
|
|
|
const formattedSelectedDate = selectedDate.format("YYYY-MM-DD");
|
2022-08-24 20:18:42 +00:00
|
|
|
|
2023-02-09 19:01:43 +00:00
|
|
|
const { data, isLoading } = trpc.viewer.availability.user.useQuery(
|
2022-11-10 23:40:01 +00:00
|
|
|
{
|
|
|
|
username: user.username!,
|
|
|
|
dateFrom: selectedDate.startOf("day").utc().format(),
|
|
|
|
dateTo: selectedDate.endOf("day").utc().format(),
|
|
|
|
withSource: true,
|
|
|
|
},
|
2022-09-07 19:28:43 +00:00
|
|
|
{
|
|
|
|
enabled: !!user.username,
|
|
|
|
}
|
|
|
|
);
|
2022-08-24 20:18:42 +00:00
|
|
|
|
2022-12-15 20:19:35 +00:00
|
|
|
const overrides =
|
|
|
|
data?.dateOverrides.reduce((acc, override) => {
|
|
|
|
if (
|
|
|
|
formattedSelectedDate !== dayjs(override.start).format("YYYY-MM-DD") &&
|
|
|
|
formattedSelectedDate !== dayjs(override.end).format("YYYY-MM-DD")
|
|
|
|
)
|
|
|
|
return acc;
|
|
|
|
acc.push({ ...override, source: "Date override" });
|
|
|
|
return acc;
|
|
|
|
}, [] as IBusySlot[]) || [];
|
|
|
|
|
2022-08-24 20:18:42 +00:00
|
|
|
return (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="bg-default max-w-xl overflow-hidden rounded-md shadow">
|
2023-02-09 19:01:43 +00:00
|
|
|
<div className="px-4 py-5 sm:p-6">
|
|
|
|
{t("overview_of_day")}{" "}
|
|
|
|
<input
|
|
|
|
type="date"
|
|
|
|
className="inline h-8 border-none p-0"
|
|
|
|
defaultValue={formattedSelectedDate}
|
|
|
|
onChange={(e) => {
|
|
|
|
if (e.target.value) setSelectedDate(e.target.value);
|
|
|
|
}}
|
2022-08-24 20:18:42 +00:00
|
|
|
/>
|
2023-04-05 18:14:46 +00:00
|
|
|
<small className="text-muted block">{t("hover_over_bold_times_tip")}</small>
|
2023-02-09 19:01:43 +00:00
|
|
|
<div className="mt-4 space-y-4">
|
|
|
|
<div className="bg-brand dark:bg-darkmodebrand overflow-hidden rounded-md">
|
|
|
|
<div className="text-brandcontrast dark:text-darkmodebrandcontrast px-4 py-2 sm:px-6">
|
|
|
|
{t("your_day_starts_at")} {convertMinsToHrsMins(user.startTime)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{(() => {
|
|
|
|
if (isLoading)
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<SkeletonText className="block h-16 w-full" />
|
|
|
|
<SkeletonText className="block h-16 w-full" />
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
|
|
|
|
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) => (
|
|
|
|
<div
|
|
|
|
key={dayjs(slot.start).format("HH:mm")}
|
2023-04-05 18:14:46 +00:00
|
|
|
className="bg-subtle overflow-hidden rounded-md"
|
2023-02-09 19:01:43 +00:00
|
|
|
data-testid="troubleshooter-busy-time">
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="text-emphasis px-4 py-5 sm:p-6">
|
2023-02-09 19:01:43 +00:00
|
|
|
{t("calendar_shows_busy_between")}{" "}
|
2023-04-05 18:14:46 +00:00
|
|
|
<span className="text-default font-medium" title={dayjs(slot.start).format("HH:mm")}>
|
2023-02-09 19:01:43 +00:00
|
|
|
{dayjs(slot.start).format("HH:mm")}
|
|
|
|
</span>{" "}
|
|
|
|
{t("and")}{" "}
|
2023-04-05 18:14:46 +00:00
|
|
|
<span className="text-default font-medium" title={dayjs(slot.end).format("HH:mm")}>
|
2023-02-09 19:01:43 +00:00
|
|
|
{dayjs(slot.end).format("HH:mm")}
|
|
|
|
</span>{" "}
|
|
|
|
{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 && <small>{` - (source: ${slot.source})`}</small>}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
));
|
|
|
|
return (
|
2023-04-05 18:14:46 +00:00
|
|
|
<div className="bg-subtle overflow-hidden rounded-md">
|
|
|
|
<div className="text-emphasis px-4 py-5 sm:p-6">{t("calendar_no_busy_slots")}</div>
|
2023-02-09 19:01:43 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})()}
|
|
|
|
|
|
|
|
<div className="bg-brand dark:bg-darkmodebrand overflow-hidden rounded-md">
|
|
|
|
<div className="text-brandcontrast dark:text-darkmodebrandcontrast px-4 py-2 sm:px-6">
|
|
|
|
{t("your_day_ends_at")} {convertMinsToHrsMins(user.endTime)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-08-24 20:18:42 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function Troubleshoot() {
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data, isLoading } = trpc.viewer.me.useQuery();
|
2022-08-24 20:18:42 +00:00
|
|
|
const { t } = useLocale();
|
|
|
|
return (
|
|
|
|
<div>
|
2023-04-19 20:17:54 +00:00
|
|
|
<Shell heading={t("troubleshoot")} hideHeadingOnMobile subtitle={t("troubleshoot_description")}>
|
2022-09-09 12:24:26 +00:00
|
|
|
{!isLoading && data && <AvailabilityView user={data} />}
|
2022-08-24 20:18:42 +00:00
|
|
|
</Shell>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2023-04-18 18:45:32 +00:00
|
|
|
Troubleshoot.PageWrapper = PageWrapper;
|
2023-02-09 19:01:43 +00:00
|
|
|
|
|
|
|
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}`;
|
|
|
|
}
|