Refactor and fix main app tests

This commit is contained in:
Alejandro Celaya
2023-08-04 08:56:06 +02:00
parent c794ff8b58
commit c4d7ac272b
29 changed files with 162 additions and 160 deletions

View File

@@ -0,0 +1,46 @@
import type { FC } from 'react';
import { useEffect } from 'react';
import type { Settings, ShlinkWebComponentType } from '../../shlink-web-component/src';
import type { ShlinkApiClientBuilder } from '../api/services/ShlinkApiClientBuilder';
import { isReachableServer } from '../servers/data';
import { withSelectedServer } from '../servers/helpers/withSelectedServer';
import { NotFound } from './NotFound';
import './ShlinkWebComponentContainer.scss';
interface ShlinkWebComponentContainerProps {
sidebarPresent: Function;
sidebarNotPresent: Function;
settings: Settings;
}
export const ShlinkWebComponentContainer = (
buildShlinkApiClient: ShlinkApiClientBuilder,
ShlinkWebComponent: ShlinkWebComponentType,
ServerError: FC,
) => withSelectedServer<ShlinkWebComponentContainerProps>((
{ selectedServer, sidebarNotPresent, sidebarPresent, settings },
) => {
const selectedServerIsReachable = isReachableServer(selectedServer);
const routesPrefix = selectedServerIsReachable ? `/server/${selectedServer.id}` : '';
useEffect(() => {
selectedServerIsReachable && sidebarPresent();
return () => sidebarNotPresent();
}, []);
if (!selectedServerIsReachable) {
return <ServerError />;
}
return (
<ShlinkWebComponent
serverVersion={selectedServer.version}
apiClient={buildShlinkApiClient(selectedServer)}
settings={settings}
routesPrefix={routesPrefix}
createNotFound={(nonPrefixedHomePath) => (
<NotFound to={`${routesPrefix}${nonPrefixedHomePath}`}>List short URLs</NotFound>
)}
/>
);
}, ServerError);