import { Suspense } from 'react';
import { getIntegrationsApiV1IntegrationGet } from "@/client/sdk.gen";
import { getServerAccessToken,getServerAuthProvider } from '@/lib/auth/server';
import logger from '@/lib/logger';
import CreateIntegrationButton from "./CreateIntegrationButton";
export const dynamic = 'force-dynamic';
// Server component for integration list
async function IntegrationList() {
const authProvider = getServerAuthProvider();
const accessToken = await getServerAccessToken();
if (!accessToken) {
const { redirect } = await import('next/navigation');
if (authProvider === 'stack') {
redirect('/');
} else {
// For OSS mode, this shouldn't happen as token is auto-generated
return (
Authentication required. Please refresh the page.
);
}
}
try {
const response = await getIntegrationsApiV1IntegrationGet({
headers: {
'Authorization': `Bearer ${accessToken}`,
},
});
const integrationData = response.data ? (Array.isArray(response.data) ? response.data : [response.data]) : [];
const integrations = [...integrationData].sort((a, b) =>
new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
);
if (integrations.length === 0) {
return (
No integrations found. Create your first integration to get started.
);
}
return (
|
Provider
|
Channel
|
Action
|
Created At
|
{integrations.map((integration) => (
|
{integration.provider}
|
{integration.provider === 'slack' && integration.provider_data ? (integration.provider_data.channel as string) || '-' : '-'}
|
{integration.action}
|
{new Date(integration.created_at).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
})}
|
))}
);
} catch (err) {
logger.error(`Error fetching integrations: ${err}`);
return (
Failed to load Integrations. Please Try Again Later.
);
}
}
async function PageContent() {
const integrationList = await IntegrationList();
return (
Your Integrations
{integrationList}
);
}
function IntegrationsLoading() {
return (
|
Integration ID
|
Channel
|
Action
|
Created At
|
{Array.from({ length: 5 }, (_, i) => (
|
|
|
|
|
))}
);
}
export default function IntegrationsPage() {
return (
}>
);
}