import { Button, Group } from '@mantine/core'; import { notifications } from '@mantine/notifications'; import { IconCheck, IconPlayerPlay, IconPlayerStop, IconPlus, IconRefresh, IconRotateClockwise, IconTrash, } from '@tabler/icons-react'; import Dockerode from 'dockerode'; import { useTranslation } from 'next-i18next'; import { RouterInputs, api } from '~/utils/api'; import { openDockerSelectBoardModal } from './docker-select-board.modal'; export interface ContainerActionBarProps { selected: Dockerode.ContainerInfo[]; reload: () => void; isLoading: boolean; } export default function ContainerActionBar({ selected, reload, isLoading, }: ContainerActionBarProps) { const { t } = useTranslation('modules/docker'); const sendDockerCommand = useDockerActionMutation(); return ( ); } const useDockerActionMutation = () => { const { t } = useTranslation('modules/docker'); const utils = api.useContext(); const mutation = api.docker.action.useMutation(); return async ( container: Dockerode.ContainerInfo, action: RouterInputs['docker']['action']['action'] ) => { const containerName = container.Names[0].substring(1); notifications.show({ id: container.Id, loading: true, title: `${t(`actions.${action}.start`)} ${containerName}`, message: undefined, autoClose: false, withCloseButton: false, }); await mutation.mutateAsync( { action, id: container.Id }, { onSuccess: () => { notifications.update({ id: container.Id, title: containerName, message: `${t(`actions.${action}.end`)} ${containerName}`, icon: , autoClose: 2000, }); }, onError: (err) => { notifications.update({ id: container.Id, color: 'red', title: t('errors.unknownError.title'), message: err.message, autoClose: 2000, }); }, onSettled: () => { utils.docker.containers.invalidate(); }, } ); }; };