2022-07-14 00:10:45 +00:00
|
|
|
import { useSession } from "next-auth/react";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { useRouter } from "next/router";
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2023-01-10 15:39:29 +00:00
|
|
|
import Shell from "@calcom/features/shell/Shell";
|
2022-07-15 16:55:59 +00:00
|
|
|
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
2022-11-23 02:55:25 +00:00
|
|
|
import { HttpError } from "@calcom/lib/http-error";
|
2022-07-22 17:27:06 +00:00
|
|
|
import { trpc } from "@calcom/trpc/react";
|
2023-01-23 23:08:01 +00:00
|
|
|
import { Button, showToast } from "@calcom/ui";
|
|
|
|
import { FiPlus } from "@calcom/ui/components/icon";
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
import LicenseRequired from "../../common/components/v2/LicenseRequired";
|
|
|
|
import SkeletonLoader from "../components/SkeletonLoaderList";
|
2022-07-28 19:58:26 +00:00
|
|
|
import WorkflowList from "../components/WorkflowListPage";
|
2022-07-14 00:10:45 +00:00
|
|
|
|
|
|
|
function WorkflowsPage() {
|
|
|
|
const { t } = useLocale();
|
|
|
|
|
|
|
|
const session = useSession();
|
2022-11-23 02:55:25 +00:00
|
|
|
const router = useRouter();
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2022-11-10 23:40:01 +00:00
|
|
|
const { data, isLoading } = trpc.viewer.workflows.list.useQuery();
|
2022-07-14 00:10:45 +00:00
|
|
|
|
2022-11-23 02:55:25 +00:00
|
|
|
const createMutation = trpc.viewer.workflows.createV2.useMutation({
|
|
|
|
onSuccess: async ({ workflow }) => {
|
|
|
|
await router.replace("/workflows/" + workflow.id);
|
|
|
|
},
|
|
|
|
onError: (err) => {
|
|
|
|
if (err instanceof HttpError) {
|
|
|
|
const message = `${err.statusCode}: ${err.message}`;
|
|
|
|
showToast(message, "error");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err.data?.code === "UNAUTHORIZED") {
|
|
|
|
const message = `${err.data.code}: You are not able to create this workflow`;
|
|
|
|
showToast(message, "error");
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-12-07 20:53:44 +00:00
|
|
|
return (
|
2022-07-14 00:10:45 +00:00
|
|
|
<Shell
|
2022-12-07 20:53:44 +00:00
|
|
|
heading={t("workflows")}
|
2022-11-23 02:55:25 +00:00
|
|
|
title={t("workflows")}
|
2022-12-07 20:53:44 +00:00
|
|
|
subtitle={t("workflows_to_automate_notifications")}
|
2022-11-23 02:55:25 +00:00
|
|
|
CTA={
|
|
|
|
session.data?.hasValidLicense && data?.workflows && data?.workflows.length > 0 ? (
|
|
|
|
<Button
|
2023-01-19 14:55:32 +00:00
|
|
|
variant="fab"
|
2023-01-23 23:08:01 +00:00
|
|
|
StartIcon={FiPlus}
|
2022-11-23 02:55:25 +00:00
|
|
|
onClick={() => createMutation.mutate()}
|
|
|
|
loading={createMutation.isLoading}>
|
|
|
|
{t("new")}
|
|
|
|
</Button>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
)
|
|
|
|
}>
|
2022-07-14 00:10:45 +00:00
|
|
|
<LicenseRequired>
|
|
|
|
{isLoading ? (
|
2022-11-23 02:55:25 +00:00
|
|
|
<SkeletonLoader />
|
2022-07-14 00:10:45 +00:00
|
|
|
) : (
|
|
|
|
<>
|
2022-11-23 02:55:25 +00:00
|
|
|
<WorkflowList workflows={data?.workflows} />
|
2022-07-14 00:10:45 +00:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</LicenseRequired>
|
|
|
|
</Shell>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default WorkflowsPage;
|