mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-17 04:53:49 +00:00
Stop injecting dependencies in selectServer action
This commit is contained in:
@@ -2,34 +2,37 @@ import { Message } from '@shlinkio/shlink-frontend-kit';
|
||||
import type { FC } from 'react';
|
||||
import { useEffect } from 'react';
|
||||
import { useParams } from 'react-router';
|
||||
import type { ShlinkApiClientBuilder } from '../../api/services/ShlinkApiClientBuilder';
|
||||
import { NoMenuLayout } from '../../common/NoMenuLayout';
|
||||
import type { FCWithDeps } from '../../container/utils';
|
||||
import { useDependencies } from '../../container/utils';
|
||||
import type { SelectedServer } from '../data';
|
||||
import { isNotFoundServer } from '../data';
|
||||
import type { SelectServerOptions } from '../reducers/selectedServer';
|
||||
|
||||
export type WithSelectedServerProps = {
|
||||
selectServer: (serverId: string) => void;
|
||||
selectServer: (options: SelectServerOptions) => void;
|
||||
selectedServer: SelectedServer;
|
||||
};
|
||||
|
||||
type WithSelectedServerPropsDeps = {
|
||||
export type WithSelectedServerPropsDeps = {
|
||||
ServerError: FC;
|
||||
buildShlinkApiClient: ShlinkApiClientBuilder;
|
||||
};
|
||||
|
||||
export function withSelectedServer<T extends object>(
|
||||
WrappedComponent: FCWithDeps<WithSelectedServerProps & T, WithSelectedServerPropsDeps>,
|
||||
) {
|
||||
const ComponentWrapper: FCWithDeps<WithSelectedServerProps & T, WithSelectedServerPropsDeps> = (props) => {
|
||||
const { ServerError } = useDependencies(ComponentWrapper);
|
||||
const { ServerError, buildShlinkApiClient } = useDependencies(ComponentWrapper);
|
||||
const params = useParams<{ serverId: string }>();
|
||||
const { selectServer, selectedServer } = props;
|
||||
|
||||
useEffect(() => {
|
||||
if (params.serverId) {
|
||||
selectServer(params.serverId);
|
||||
selectServer({ serverId: params.serverId, buildShlinkApiClient });
|
||||
}
|
||||
}, [params.serverId, selectServer]);
|
||||
}, [buildShlinkApiClient, params.serverId, selectServer]);
|
||||
|
||||
if (!selectedServer) {
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user