misc_pterodactyl-panel/resources/scripts/components/admin/overview/OverviewContainer.tsx

90 lines
4.3 KiB
TypeScript
Raw Normal View History

2021-01-07 16:33:01 +00:00
import React, { useEffect, useState } from 'react';
import tw from 'twin.macro';
2021-01-07 16:33:01 +00:00
import useFlash from '@/plugins/useFlash';
import AdminContentBlock from '@/components/admin/AdminContentBlock';
2021-01-07 16:33:01 +00:00
import FlashMessageRender from '@/components/FlashMessageRender';
import Spinner from '@/components/elements/Spinner';
import getVersion, { VersionData } from '@/api/admin/getVersion';
const Code = ({ children }: { children: React.ReactNode }) => {
return (
<code css={tw`text-sm font-mono bg-neutral-900 rounded`} style={{ padding: '2px 6px' }}>
{children}
</code>
);
};
export default () => {
2021-01-07 16:33:01 +00:00
const { clearFlashes, clearAndAddHttpError } = useFlash();
const [ loading, setLoading ] = useState<boolean>(true);
const [ versionData, setVersionData ] = useState<VersionData | undefined>(undefined);
useEffect(() => {
clearFlashes('overview');
getVersion()
.then(versionData => setVersionData(versionData))
.catch(error => {
console.error(error);
2021-01-08 17:02:49 +00:00
clearAndAddHttpError({ key: 'overview', error });
2021-01-07 16:33:01 +00:00
})
.then(() => setLoading(false));
}, []);
return (
2021-01-07 16:44:24 +00:00
<AdminContentBlock title={'Overview'}>
2021-01-07 16:33:01 +00:00
<div css={tw`flex flex-col mb-8`}>
<h2 css={tw`text-2xl text-neutral-50 font-header font-medium`}>Overview</h2>
<p css={tw`text-base text-neutral-400`}>A quick glance at your system.</p>
</div>
2021-01-07 16:33:01 +00:00
<FlashMessageRender byKey={'overview'} css={tw`mb-4`}/>
<div css={tw`flex flex-col w-full rounded-lg shadow-md bg-neutral-700`}>
{ loading ?
<div css={tw`w-full flex flex-col items-center justify-center`} style={{ height: '16rem' }}>
<Spinner size={'base'}/>
</div>
:
<div css={tw`rounded shadow-md bg-neutral-700`}>
<div css={tw`bg-neutral-900 rounded-t border-b border-black p-3`}>
<p css={tw`text-sm uppercase`}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" css={tw`inline-block mr-2`} style={{ height: '1rem' }}>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 3v2m6-2v2M9 19v2m6-2v2M5 9H3m2 6H3m18-6h-2m2 6h-2M7 19h10a2 2 0 002-2V7a2 2 0 00-2-2H7a2 2 0 00-2 2v10a2 2 0 002 2zM9 9h6v6H9V9z"/>
</svg>
System Information
</p>
</div>
<div css={tw`p-3`}>
{versionData?.panel.current === 'canary' ?
<p css={tw`text-neutral-200`}>
I hope you enjoy living on the edge because you are
running a <Code>{versionData?.panel.current}</Code> version
of Pterodactyl.
</p>
: versionData?.panel.latest === versionData?.panel.current
?
<p css={tw`text-neutral-200`}>
Your panel is <span css={tw`text-neutral-100`}>up-to-date</span>.
The latest version
is <Code>{versionData?.panel.latest}</Code> and you are
running version <Code>{versionData?.panel.current}</Code>.
</p>
:
<p css={tw`text-neutral-200`}>
Your panel is <span css={tw`text-neutral-100`}>not up-to-date</span>.
The latest version
is <Code>{versionData?.panel.latest}</Code> and you are
running version <Code>{versionData?.panel.current}</Code>.
</p>
}
</div>
</div>
}
</div>
</AdminContentBlock>
);
};