import { Message } from '@shlinkio/shlink-frontend-kit'; import type { FC } from 'react'; import { useEffect } from 'react'; import { useParams } from 'react-router-dom'; import { NoMenuLayout } from '../../common/NoMenuLayout'; import type { SelectedServer } from '../data'; import { isNotFoundServer } from '../data'; interface WithSelectedServerProps { selectServer: (serverId: string) => void; selectedServer: SelectedServer; } export function withSelectedServer(WrappedComponent: FC, ServerError: FC) { return (props: WithSelectedServerProps & T) => { const params = useParams<{ serverId: string }>(); const { selectServer, selectedServer } = props; useEffect(() => { params.serverId && selectServer(params.serverId); }, [params.serverId, selectServer]); if (!selectedServer) { return ( ); } if (isNotFoundServer(selectedServer)) { return ; } return ; }; }