import React, { useEffect, useState } from 'react'; import { Helmet } from 'react-helmet'; import getServerDatabases from '@/api/server/getServerDatabases'; import { ServerContext } from '@/state/server'; import { httpErrorToHuman } from '@/api/http'; import FlashMessageRender from '@/components/FlashMessageRender'; import DatabaseRow from '@/components/server/databases/DatabaseRow'; import Spinner from '@/components/elements/Spinner'; import CreateDatabaseButton from '@/components/server/databases/CreateDatabaseButton'; import Can from '@/components/elements/Can'; import useFlash from '@/plugins/useFlash'; import useServer from '@/plugins/useServer'; import PageContentBlock from '@/components/elements/PageContentBlock'; import tw from 'twin.macro'; import Fade from '@/components/elements/Fade'; export default () => { const { uuid, featureLimits, name: serverName } = useServer(); const { addError, clearFlashes } = useFlash(); const [ loading, setLoading ] = useState(true); const databases = ServerContext.useStoreState(state => state.databases.data); const setDatabases = ServerContext.useStoreActions(state => state.databases.setDatabases); useEffect(() => { setLoading(!databases.length); clearFlashes('databases'); getServerDatabases(uuid) .then(databases => setDatabases(databases)) .catch(error => { console.error(error); addError({ key: 'databases', message: httpErrorToHuman(error) }); }) .then(() => setLoading(false)); }, []); return ( {serverName} | Databases {(!databases.length && loading) ? : <> {databases.length > 0 ? databases.map((database, index) => ( 0 ? 'mt-1' : undefined} /> )) :

{featureLimits.databases > 0 ? 'It looks like you have no databases.' : 'Databases cannot be created for this server.' }

} {(featureLimits.databases > 0 && databases.length > 0) &&

{databases.length} of {featureLimits.databases} databases have been allocated to this server.

} {featureLimits.databases > 0 && featureLimits.databases !== databases.length &&
}
}
); };