mirror of
https://github.com/portainer/portainer.git
synced 2025-11-26 14:06:05 +08:00
45 lines
1.0 KiB
TypeScript
45 lines
1.0 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
import { EnvironmentId } from '@/react/portainer/environments/types';
|
|
import axios, { parseAxiosError } from '@/portainer/services/axios';
|
|
import { withGlobalError } from '@/react-tools/react-query';
|
|
|
|
import { StackId } from '../types';
|
|
|
|
import { queryKeys } from './query-keys';
|
|
|
|
interface DeleteStackParams {
|
|
id?: StackId;
|
|
name?: string;
|
|
external: boolean;
|
|
environmentId: EnvironmentId;
|
|
}
|
|
|
|
export function useDeleteStackMutation() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: deleteStack,
|
|
onSuccess: () => queryClient.invalidateQueries(queryKeys.base()),
|
|
...withGlobalError('Unable to delete stack'),
|
|
});
|
|
}
|
|
|
|
async function deleteStack({
|
|
id,
|
|
name,
|
|
external,
|
|
environmentId,
|
|
}: DeleteStackParams) {
|
|
try {
|
|
await axios.delete(`/stacks/${id || name}`, {
|
|
params: {
|
|
external,
|
|
endpointId: environmentId,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
throw parseAxiosError(error, 'Unable to delete stack');
|
|
}
|
|
}
|