Begin enabling config fetching/parsing errors to be displayed

This commit is contained in:
2023-11-16 17:58:38 -06:00
parent a05ef4bb49
commit 7c9051193e
2 changed files with 59 additions and 2 deletions

View File

@@ -0,0 +1,48 @@
import { ExclamationTriangleIcon } from '@heroicons/react/20/solid';
import clsx from 'clsx';
import { FunctionComponent } from 'react';
// type AccentColors = 'red' | 'yellow' | 'green';
// type AccentColorClass = { base: string; text: string; hover: string };
type AccentedAlertProps = {
className?: string;
// color?: AccentColors;
text: string;
};
const AccentedAlert: FunctionComponent<AccentedAlertProps> = ({
className,
text
}) => {
return (
<div
className={clsx(
className,
'border-l-4 border-yellow-600 bg-yellow-1000 p-4'
)}
>
<div className="flex">
<div className="flex-shrink-0">
<ExclamationTriangleIcon
className="h-5 w-5 text-yellow-400"
aria-hidden="true"
/>
</div>
<div className="ml-3">
<p className="text-sm text-yellow-500">
{text}
{/* <a */}
{/* href="#" */}
{/* className="font-medium text-yellow-700 underline hover:text-yellow-600" */}
{/* > */}
{/* Upgrade your account to add more credits. */}
{/* </a> */}
</p>
</div>
</div>
</div>
);
};
export default AccentedAlert;

View File

@@ -10,9 +10,11 @@ import Layout from '@/components/Layout';
import ConfigurationList from '@/components/ConfigurationList'; import ConfigurationList from '@/components/ConfigurationList';
import superjson from 'superjson'; import superjson from 'superjson';
import type { Configuration } from '@/timing'; import type { Configuration } from '@/timing';
import AccentedAlert from '@/components/AccentedAlert';
type IndexPageProps = { type IndexPageProps = {
json: string; json: string;
error?: string;
}; };
export async function getServerSideProps({ export async function getServerSideProps({
@@ -26,7 +28,8 @@ export async function getServerSideProps({
const config = await fetchConfiguration({ times: [] }, true); const config = await fetchConfiguration({ times: [] }, true);
return { return {
props: { props: {
json: superjson.stringify(config) json: superjson.stringify(config),
error: 'NetworkError occurred while fetching resource.'
} }
}; };
} }
@@ -39,10 +42,16 @@ export async function getServerSideProps({
}; };
} }
const IndexPage: NextPage<IndexPageProps> = ({ json }) => { const IndexPage: NextPage<IndexPageProps> = ({ error, json }) => {
const config = superjson.parse<Configuration>(json); const config = superjson.parse<Configuration>(json);
const errorElement =
error != undefined ? (
<AccentedAlert className="mb-2" text={`An error has occured. ${error}`} />
) : undefined;
return ( return (
<Layout className="max-h-screen flex flex-col items-center"> <Layout className="max-h-screen flex flex-col items-center">
{errorElement}
<ConfigurationList configs={config} /> <ConfigurationList configs={config} />
</Layout> </Layout>
); );