mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 16:46:38 +01:00
30 lines
1019 B
TypeScript
30 lines
1019 B
TypeScript
import { useMutation } from '@tanstack/react-query';
|
|
import type { Environment } from '@yaakapp/api';
|
|
import { InlineCode } from '../components/core/InlineCode';
|
|
import { trackEvent } from '../lib/analytics';
|
|
import { invokeCmd } from '../lib/tauri';
|
|
import { useConfirm } from './useConfirm';
|
|
|
|
export function useDeleteEnvironment(environment: Environment | null) {
|
|
const confirm = useConfirm();
|
|
|
|
return useMutation<Environment | null, string>({
|
|
mutationKey: ['delete_environment', environment?.id],
|
|
mutationFn: async () => {
|
|
const confirmed = await confirm({
|
|
id: 'delete-environment',
|
|
title: 'Delete Environment',
|
|
variant: 'delete',
|
|
description: (
|
|
<>
|
|
Permanently delete <InlineCode>{environment?.name}</InlineCode>?
|
|
</>
|
|
),
|
|
});
|
|
if (!confirmed) return null;
|
|
return invokeCmd('cmd_delete_environment', { environmentId: environment?.id });
|
|
},
|
|
onSettled: () => trackEvent('environment', 'delete'),
|
|
});
|
|
}
|