import { useSession } from "next-auth/react"; import { useRouter } from "next/navigation"; import classNames from "@calcom/lib/classNames"; import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants"; import { useBookerUrl } from "@calcom/lib/hooks/useBookerUrl"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { trpc } from "@calcom/trpc/react"; import type { WebhooksByViewer } from "@calcom/trpc/server/routers/viewer/webhook/getByViewer.handler"; import { Avatar, CreateButtonWithTeamsList, EmptyScreen, Meta, SkeletonContainer, SkeletonText, } from "@calcom/ui"; import { Link as LinkIcon } from "@calcom/ui/components/icon"; import { getLayout } from "../../settings/layouts/SettingsLayout"; import { WebhookListItem } from "../components"; const SkeletonLoader = ({ title, description, borderInShellHeader, }: { title: string; description: string; borderInShellHeader: boolean; }) => { return ( ); }; const WebhooksView = () => { const { t } = useLocale(); const router = useRouter(); const session = useSession(); const { data, isLoading } = trpc.viewer.webhook.getByViewer.useQuery(undefined, { enabled: session.status === "authenticated", }); if (isLoading || !data) { return ( ); } return ( <> 0 ? ( { router.push(`webhooks/new${teamId ? `?teamId=${teamId}` : ""}`); }} data-testid="new_webhook" /> ) : ( <>> ) } borderInShellHeader={data && data.profiles.length === 1} /> > ); }; const WebhooksList = ({ webhooksByViewer }: { webhooksByViewer: WebhooksByViewer }) => { const { t } = useLocale(); const router = useRouter(); const { profiles, webhookGroups } = webhooksByViewer; const bookerUrl = useBookerUrl(); const hasTeams = profiles && profiles.length > 1; return ( <> {webhookGroups && ( <> {!!webhookGroups.length && ( {webhookGroups.map((group) => ( {hasTeams && ( {group.profile.name || ""} )} {group.webhooks.map((webhook, index) => ( router.push(`${WEBAPP_URL}/settings/developer/webhooks/${webhook.id} `) } /> ))} ))} )} {!webhookGroups.length && ( { router.push(`webhooks/new${teamId ? `?teamId=${teamId}` : ""}`); }} data-testid="new_webhook" /> } /> )} > )} > ); }; WebhooksView.getLayout = getLayout; export default WebhooksView;