diff --git a/apps/mgmt-ui/src/components/settings/WebhookTabPanel.tsx b/apps/mgmt-ui/src/components/settings/WebhookTabPanel.tsx index 3f987051d..e5d2b08e6 100644 --- a/apps/mgmt-ui/src/components/settings/WebhookTabPanel.tsx +++ b/apps/mgmt-ui/src/components/settings/WebhookTabPanel.tsx @@ -1,8 +1,38 @@ import { Box } from '@mui/material'; +import { useEffect, useState } from 'react'; +import { Svix } from 'svix'; import { AppPortal } from 'svix-react'; import 'svix-react/style.css'; -export default function WebhookTabPanel({ svixDashboardUrl }: { svixDashboardUrl: string }) { +import Spinner from '../Spinner'; + +export default function WebhookTabPanel({ + applicationId, + svixApiToken, +}: { + applicationId: string; + svixApiToken?: string; +}) { + const [svixDashboardUrl, setSvixDashboardUrl] = useState(null); + + useEffect(() => { + const getDashboardUrl = async () => { + if (svixApiToken) { + const svix = new Svix(svixApiToken, { + serverUrl: process.env.NEXT_PUBLIC_SVIX_SERVER_URL, + }); + const dashboardUrl = (await svix.authentication.appPortalAccess(applicationId, {})).url; + setSvixDashboardUrl(dashboardUrl); + } + }; + + void getDashboardUrl(); + }, [applicationId]); + + if (!svixDashboardUrl) { + return ; + } + return ( { +export const getServerSideProps: GetServerSideProps = async ({ req, res, resolvedUrl }) => { let session: Session | null = null; - const applicationId = query.applicationId as string; if (!IS_CLOUD) { session = await getServerSession(req, res, authOptions); @@ -77,12 +76,6 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res, query, } } - let svixDashboardUrl: string | null = null; - if (process.env.SVIX_API_TOKEN) { - const svix = new Svix(process.env.SVIX_API_TOKEN, { serverUrl: process.env.SVIX_SERVER_URL }); - svixDashboardUrl = (await svix.authentication.appPortalAccess(applicationId, {})).url; - } - // Lekko defaults let homeCtaButtonConfig: HomeCtaButton = { buttonMessage: 'Quickstart Guide', @@ -131,12 +124,12 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res, query, props: { session, signedIn: true, - svixDashboardUrl, ...buildClerkProps(req), API_HOST, IS_CLOUD, CLERK_ACCOUNT_URL, CLERK_ORGANIZATION_URL, + SVIX_API_TOKEN, lekko: { homeCtaButtonConfig, entitiesWhitelistConfig, schemasWhitelistConfig }, }, }; diff --git a/apps/mgmt-ui/src/pages/applications/[applicationId]/settings/[...tab].tsx b/apps/mgmt-ui/src/pages/applications/[applicationId]/settings/[...tab].tsx index a188ed47c..685b709ef 100644 --- a/apps/mgmt-ui/src/pages/applications/[applicationId]/settings/[...tab].tsx +++ b/apps/mgmt-ui/src/pages/applications/[applicationId]/settings/[...tab].tsx @@ -33,8 +33,8 @@ export default function Home(props: SupaglueProps) { const [mobileOpen, setMobileOpen] = useState(false); const { tab = [] } = router.query; const [value, setValue] = React.useState(0); - const { svixDashboardUrl } = props; const activeApplicationId = useActiveApplicationId(); + const enableWebhooksTab = !!props.SVIX_API_TOKEN; React.useEffect(() => { const tabIndex = settingsHeaderTabs.findIndex((settingsHeaderTab) => settingsHeaderTab.value === tab[0]); @@ -51,7 +51,7 @@ export default function Home(props: SupaglueProps) { {...props} tabs={ - {svixDashboardUrl ? ( + {enableWebhooksTab ? ( { @@ -71,9 +71,9 @@ export default function Home(props: SupaglueProps) { onDrawerToggle={handleDrawerToggle} /> - {svixDashboardUrl ? ( + {enableWebhooksTab ? ( - + ) : null}