Fixed test console.

This commit is contained in:
Mike Cao 2023-10-19 17:01:21 -07:00
parent b9477db1a2
commit 9aa2830d2b
2 changed files with 7 additions and 12 deletions

View File

@ -7,19 +7,15 @@ import WebsiteChart from '../../(main)/websites/[id]/WebsiteChart';
import useApi from 'components/hooks/useApi'; import useApi from 'components/hooks/useApi';
import Head from 'next/head'; import Head from 'next/head';
import Link from 'next/link'; import Link from 'next/link';
import { useRouter } from 'next/navigation'; import useNavigation from 'components/hooks/useNavigation';
import Script from 'next/script'; import Script from 'next/script';
import { Button } from 'react-basics'; import { Button } from 'react-basics';
import styles from './TestConsole.module.css'; import styles from './TestConsole.module.css';
export function TestConsole() { export function TestConsole({ websiteId }) {
const { get, useQuery } = useApi(); const { get, useQuery } = useApi();
const { data, isLoading, error } = useQuery(['websites:me'], () => get('/me/websites')); const { data, isLoading, error } = useQuery(['websites:me'], () => get('/me/websites'));
const router = useRouter(); const { router } = useNavigation();
const {
basePath,
query: { id },
} = router;
function handleChange(value) { function handleChange(value) {
router.push(`/console/${value}`); router.push(`/console/${value}`);
@ -72,7 +68,6 @@ export function TestConsole() {
return null; return null;
} }
const [websiteId] = id || [];
const website = data?.data.find(({ id }) => websiteId === id); const website = data?.data.find(({ id }) => websiteId === id);
return ( return (
@ -87,8 +82,8 @@ export function TestConsole() {
<> <>
<Script <Script
async async
data-website-id={website.id} data-website-id={websiteId}
src={`${basePath}/script.js`} src={`${process.env.basePath}/script.js`}
data-cache="true" data-cache="true"
/> />
<div className={styles.test}> <div className={styles.test}>

View File

@ -5,14 +5,14 @@ async function getEnabled() {
return !!process.env.ENABLE_TEST_CONSOLE; return !!process.env.ENABLE_TEST_CONSOLE;
} }
export default async function ConsolePage() { export default async function ({ params: { id } }) {
const enabled = await getEnabled(); const enabled = await getEnabled();
if (!enabled) { if (!enabled) {
return null; return null;
} }
return <TestConsole />; return <TestConsole websiteId={id?.[0]} />;
} }
export const metadata: Metadata = { export const metadata: Metadata = {