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 { FCWithDeps } from '../container/utils'; import { componentFactory, useDependencies } from '../container/utils'; 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'; type ManageServersProps = { servers: ServersMap; }; type ManageServersDeps = { ServersExporter: ServersExporter; ImportServersBtn: FC; useTimeoutToggle: TimeoutToggle; ManageServersRow: FC; }; const SHOW_IMPORT_MSG_TIME = 4000; const ManageServers: FCWithDeps = ({ servers }) => { const { ServersExporter: serversExporter, ImportServersBtn, useTimeoutToggle, ManageServersRow, } = useDependencies(ManageServers); 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.
)}
); }; export const ManageServersFactory = componentFactory(ManageServers, [ 'ServersExporter', 'ImportServersBtn', 'useTimeoutToggle', 'ManageServersRow', ]);