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";
|
2022-11-10 23:40:01 +00:00
|
|
|
import { RouterOutputs, 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";
|
|
|
|
|
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 }) => {
|
|
|
|
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
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data, isLoading } = trpc.viewer.availability.user.useQuery(
|
|
|
|
{
|
|
|
|
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 (
|
|
|
|
<div className="max-w-xl overflow-hidden rounded-md bg-white shadow">
|
|
|
|
<div className="px-4 py-5 sm:p-6">
|
|
|
|
{t("overview_of_day")}{" "}
|
|
|
|
<input
|
|
|
|
type="date"
|
|
|
|
className="inline h-8 border-none p-0"
|
2022-12-15 20:19:35 +00:00
|
|
|
defaultValue={formattedSelectedDate}
|
2022-08-24 20:18:42 +00:00
|
|
|
onChange={(e) => {
|
2022-12-15 20:19:35 +00:00
|
|
|
if (e.target.value) setSelectedDate(e.target.value);
|
2022-08-24 20:18:42 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<small className="block text-neutral-400">{t("hover_over_bold_times_tip")}</small>
|
|
|
|
<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>
|
2022-12-15 20:19:35 +00:00
|
|
|
{(() => {
|
|
|
|
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")}
|
|
|
|
className="overflow-hidden rounded-md bg-neutral-100"
|
|
|
|
data-testid="troubleshooter-busy-time">
|
|
|
|
<div className="px-4 py-5 text-black sm:p-6">
|
|
|
|
{t("calendar_shows_busy_between")}{" "}
|
|
|
|
<span
|
|
|
|
className="font-medium text-neutral-800"
|
|
|
|
title={dayjs(slot.start).format("HH:mm")}>
|
|
|
|
{dayjs(slot.start).format("HH:mm")}
|
|
|
|
</span>{" "}
|
|
|
|
{t("and")}{" "}
|
|
|
|
<span className="font-medium text-neutral-800" title={dayjs(slot.end).format("HH:mm")}>
|
|
|
|
{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>
|
2022-09-07 19:28:43 +00:00
|
|
|
</div>
|
2022-12-15 20:19:35 +00:00
|
|
|
));
|
|
|
|
return (
|
|
|
|
<div className="overflow-hidden rounded-md bg-neutral-100">
|
|
|
|
<div className="px-4 py-5 text-black sm:p-6">{t("calendar_no_busy_slots")}</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})()}
|
2022-08-24 20:18:42 +00:00
|
|
|
|
|
|
|
<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>
|
|
|
|
</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>
|
|
|
|
<Shell heading={t("troubleshoot")} 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>
|
|
|
|
);
|
|
|
|
}
|
2022-09-07 19:28: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}`;
|
|
|
|
}
|