diff --git a/src/modules/Docker/ContainerActionBar.tsx b/src/modules/Docker/ContainerActionBar.tsx index 4a8e98177..27dc4c400 100644 --- a/src/modules/Docker/ContainerActionBar.tsx +++ b/src/modules/Docker/ContainerActionBar.tsx @@ -10,56 +10,16 @@ import { IconRotateClockwise, IconTrash, } from '@tabler/icons-react'; -import axios from 'axios'; import Dockerode from 'dockerode'; import { useTranslation } from 'next-i18next'; import { useState } from 'react'; import { v4 as uuidv4 } from 'uuid'; +import { RouterInputs, api } from '~/utils/api'; import { useConfigContext } from '../../config/provider'; import { openContextModalGeneric } from '../../tools/mantineModalManagerExtensions'; import { MatchingImages, ServiceType, tryMatchPort } from '../../tools/types'; import { AppType } from '../../types/app'; -function sendDockerCommand( - action: string, - containerId: string, - containerName: string, - reload: () => void, - t: (key: string) => string, -) { - notifications.show({ - id: containerId, - loading: true, - title: `${t(`actions.${action}.start`)} ${containerName}`, - message: undefined, - autoClose: false, - withCloseButton: false, - }); - axios - .get(`/api/docker/container/${containerId}?action=${action}`) - .then((res) => { - notifications.show({ - id: containerId, - title: containerName, - message: `${t(`actions.${action}.end`)} ${containerName}`, - icon: , - autoClose: 2000, - }); - }) - .catch((err) => { - notifications.update({ - id: containerId, - color: 'red', - title: t('errors.unknownError.title'), - message: err.response.data.reason, - autoClose: 2000, - }); - }) - .finally(() => { - reload(); - }); -} - export interface ContainerActionBarProps { selected: Dockerode.ContainerInfo[]; reload: () => void; @@ -68,8 +28,9 @@ export interface ContainerActionBarProps { export default function ContainerActionBar({ selected, reload }: ContainerActionBarProps) { const { t } = useTranslation('modules/docker'); const [isLoading, setisLoading] = useState(false); - const { name: configName, config } = useConfigContext(); + const { config } = useConfigContext(); const getLowestWrapper = () => config?.wrappers.sort((a, b) => a.position - b.position)[0]; + const sendDockerCommand = useDockerActionMutation(); if (process.env.DISABLE_EDIT_MODE === 'true') { return null; @@ -96,11 +57,7 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction