import { faFileDownload as exportIcon, faPlus as plusIcon } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Result, SearchField, SimpleCard } from '@shlinkio/shlink-frontend-kit'; import type { FC } from 'react'; import { useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { Button, Row } from 'reactstrap'; import { NoMenuLayout } from '../common/NoMenuLayout'; import type { TimeoutToggle } from '../utils/helpers/hooks'; import type { ServersMap } from './data'; import type { ImportServersBtnProps } from './helpers/ImportServersBtn'; import type { ManageServersRowProps } from './ManageServersRow'; import type { ServersExporter } from './services/ServersExporter'; interface ManageServersProps { servers: ServersMap; } const SHOW_IMPORT_MSG_TIME = 4000; export const ManageServers = ( serversExporter: ServersExporter, ImportServersBtn: FC, useTimeoutToggle: TimeoutToggle, ManageServersRow: FC, ): FC => ({ servers }) => { const allServers = Object.values(servers); const [serversList, setServersList] = useState(allServers); const filterServers = (searchTerm: string) => setServersList( allServers.filter(({ name, url }) => `${name} ${url}`.toLowerCase().match(searchTerm.toLowerCase())), ); const hasAutoConnect = serversList.some(({ autoConnect }) => !!autoConnect); const [errorImporting, setErrorImporting] = useTimeoutToggle(false, SHOW_IMPORT_MSG_TIME); useEffect(() => { setServersList(Object.values(servers)); }, [servers]); return (
Import servers {allServers.length > 0 && ( )}
{hasAutoConnect && {!serversList.length && } {serversList.map((server) => ( ))}
} Name Base URL
No servers found.
{errorImporting && (
The servers could not be imported. Make sure the format is correct.
)}
); };