import Link from "next/link"; import { useRouter } from "next/router"; import { Suspense } from "react"; import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants"; 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 { Button, Meta, SkeletonText, EmptyScreen, Dropdown, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownItem, DropdownMenuLabel, } from "@calcom/ui"; import { Avatar } from "@calcom/ui"; import { Plus, 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, }); const profiles = data?.profiles.filter((profile) => !profile.readOnly); return ( <> 0 ? : <>} />
}> {data && }
); }; const NewWebhookButton = ({ teamId, profiles, }: { teamId?: number | null; profiles?: { readOnly?: boolean | undefined; slug: string | null; name: string | null; image?: string | undefined; teamId: number | null | undefined; }[]; }) => { const { t, isLocaleReady } = useLocale(); const url = new URL(`${WEBAPP_URL}/settings/developer/webhooks/new`); if (!!teamId) { url.searchParams.set("teamId", `${teamId}`); } const href = url.href; if (!profiles || profiles.length < 2) { return ( ); } return (
{t("create_for").toUpperCase()}
{profiles.map((profile, idx) => ( ( )}> {profile.name} ))}
); }; const WebhooksList = ({ webhooksByViewer }: { webhooksByViewer: WebhooksByViewer }) => { const { t } = useLocale(); const router = useRouter(); const { profiles, webhookGroups } = webhooksByViewer; 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 && ( } /> )} )} ); }; WebhooksView.getLayout = getLayout; export default WebhooksView;