2022-09-06 18:34:29 +00:00
|
|
|
/**
|
|
|
|
* @deprecated modifications to this file should be v2 only
|
|
|
|
* Use `/apps/web/pages/v2/availability/index.tsx` instead
|
|
|
|
*/
|
2022-09-08 14:21:46 +00:00
|
|
|
import { ScheduleListItem } from "@calcom/features/schedules/components/ScheduleListItem";
|
2022-03-17 16:48:23 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-03-16 23:36:43 +00:00
|
|
|
import showToast from "@calcom/lib/notification";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { inferQueryOutput, trpc } from "@calcom/trpc/react";
|
2022-06-01 17:24:41 +00:00
|
|
|
import EmptyScreen from "@calcom/ui/EmptyScreen";
|
2022-07-27 02:24:00 +00:00
|
|
|
import { Icon } from "@calcom/ui/Icon";
|
2022-07-28 19:58:26 +00:00
|
|
|
import Shell from "@calcom/ui/Shell";
|
2022-03-16 23:36:43 +00:00
|
|
|
|
2022-04-14 21:49:51 +00:00
|
|
|
import { withQuery } from "@lib/QueryCell";
|
2022-03-17 16:48:23 +00:00
|
|
|
import { HttpError } from "@lib/core/http/error";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2022-03-17 16:48:23 +00:00
|
|
|
import { NewScheduleButton } from "@components/availability/NewScheduleButton";
|
2022-04-25 17:01:51 +00:00
|
|
|
import SkeletonLoader from "@components/availability/SkeletonLoader";
|
2021-09-30 21:37:52 +00:00
|
|
|
|
2022-09-06 22:58:16 +00:00
|
|
|
/**
|
|
|
|
* @deprecated modifications to this file should be v2 only
|
|
|
|
* Use `/apps/web/pages/v2/availability/index.tsx` instead
|
|
|
|
*/
|
2022-03-17 16:48:23 +00:00
|
|
|
export function AvailabilityList({ schedules }: inferQueryOutput<"viewer.availability.list">) {
|
2022-05-14 18:47:23 +00:00
|
|
|
const { t } = useLocale();
|
2022-03-23 23:23:18 +00:00
|
|
|
const utils = trpc.useContext();
|
2022-03-17 16:48:23 +00:00
|
|
|
const deleteMutation = trpc.useMutation("viewer.availability.schedule.delete", {
|
|
|
|
onSuccess: async () => {
|
2022-03-23 23:23:18 +00:00
|
|
|
await utils.invalidateQueries(["viewer.availability.list"]);
|
2022-03-17 16:48:23 +00:00
|
|
|
showToast(t("schedule_deleted_successfully"), "success");
|
|
|
|
},
|
|
|
|
onError: (err) => {
|
|
|
|
if (err instanceof HttpError) {
|
|
|
|
const message = `${err.statusCode}: ${err.message}`;
|
|
|
|
showToast(message, "error");
|
|
|
|
}
|
2021-11-10 11:16:32 +00:00
|
|
|
},
|
|
|
|
});
|
2021-07-18 13:12:18 +00:00
|
|
|
return (
|
2022-03-17 19:13:39 +00:00
|
|
|
<>
|
|
|
|
{schedules.length === 0 ? (
|
|
|
|
<EmptyScreen
|
2022-08-03 16:01:29 +00:00
|
|
|
Icon={Icon.FiClock}
|
2022-03-17 19:13:39 +00:00
|
|
|
headline={t("new_schedule_heading")}
|
|
|
|
description={t("new_schedule_description")}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="-mx-4 mb-16 overflow-hidden rounded-sm border border-gray-200 bg-white sm:mx-0">
|
|
|
|
<ul className="divide-y divide-neutral-200" data-testid="schedules">
|
|
|
|
{schedules.map((schedule) => (
|
2022-05-14 18:47:23 +00:00
|
|
|
<ScheduleListItem
|
|
|
|
key={schedule.id}
|
|
|
|
schedule={schedule}
|
|
|
|
deleteFunction={deleteMutation.mutate}
|
|
|
|
isDeleting={deleteMutation.isLoading}
|
|
|
|
/>
|
2022-03-17 19:13:39 +00:00
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</>
|
2021-11-10 11:16:32 +00:00
|
|
|
);
|
|
|
|
}
|
2021-04-08 14:20:38 +00:00
|
|
|
|
2022-04-14 21:49:51 +00:00
|
|
|
const WithQuery = withQuery(["viewer.availability.list"]);
|
|
|
|
|
2022-03-17 16:48:23 +00:00
|
|
|
export default function AvailabilityPage() {
|
2021-11-10 11:16:32 +00:00
|
|
|
const { t } = useLocale();
|
|
|
|
return (
|
|
|
|
<div>
|
2022-09-05 19:06:34 +00:00
|
|
|
<Shell heading={t("availability")} subtitle={t("configure_availability")} CTA={<NewScheduleButton />}>
|
2022-04-25 17:01:51 +00:00
|
|
|
<WithQuery success={({ data }) => <AvailabilityList {...data} />} customLoader={<SkeletonLoader />} />
|
2021-07-18 13:12:18 +00:00
|
|
|
</Shell>
|
|
|
|
</div>
|
|
|
|
);
|
2021-04-08 14:20:38 +00:00
|
|
|
}
|