import { useRouter } from "next/router"; import { Suspense } from "react"; 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 { Meta, EmptyScreen, CreateButtonWithTeamsList } from "@calcom/ui"; import { Avatar } from "@calcom/ui"; import { Link as LinkIcon } from "@calcom/ui/components/icon"; import { getLayout } from "../../settings/layouts/SettingsLayout"; import { WebhookListItem, WebhookListSkeleton } from "../components"; const WebhooksView = () => { const { t } = useLocale(); const router = useRouter(); const { data } = trpc.viewer.webhook.getByViewer.useQuery(undefined, { suspense: true, enabled: router.isReady, }); return ( <> 0 ? ( { router.push(`webhooks/new${teamId ? `?teamId=${teamId}` : ""}`); }} data-testid="new_webhook" /> ) : ( <>> ) } /> }> {data && } > ); }; 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;