2022-09-07 19:28:43 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
2023-02-03 16:43:52 +00:00
|
|
|
import { Calendar } from "@calcom/features/calendars/weeklyview";
|
2023-01-10 15:39:29 +00:00
|
|
|
import Shell from "@calcom/features/shell/Shell";
|
2023-02-03 16:43:52 +00:00
|
|
|
import { yyyymmdd } from "@calcom/lib/date-fns";
|
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 }) => {
|
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-03 16:43:52 +00:00
|
|
|
const { data } = trpc.viewer.availability.user.useQuery(
|
2022-11-10 23:40:01 +00:00
|
|
|
{
|
2023-02-03 16:43:52 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
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-02-03 16:43:52 +00:00
|
|
|
<div className="max-w-xl overflow-hidden rounded-md border border-gray-200 bg-white">
|
|
|
|
<div className="px-4">
|
|
|
|
<Calendar
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
// @ts-ignore
|
|
|
|
events={[...(data?.busy || []), ...overrides]
|
|
|
|
.sort((a: IBusySlot, b: IBusySlot) => (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"
|
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>
|
|
|
|
<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>
|
|
|
|
);
|
|
|
|
}
|