https://dev.kronoz.win/r/marzneshin.git
1import { HostType } from "@marzneshin/features/hosts";
2import { useMutation } from "@tanstack/react-query";
3import { fetch, queryClient } from "@marzneshin/utils";
4import { toast } from "sonner";
5import i18n from "@marzneshin/features/i18n";
6
7export async function fetchDeleteHost(host: HostType): Promise<HostType> {
8 return fetch(`/inbounds/hosts/${host.id}`, { method: 'delete' }).then((host) => {
9 return host;
10 });
11}
12
13const HostsDeleteFetchKey = "hosts";
14
15
16const handleError = (error: Error, value: HostType) => {
17 toast.error(
18 i18n.t('events.delete.error', { name: value.remark }),
19 {
20 description: error.message
21 })
22}
23
24const handleSuccess = (value: HostType) => {
25 toast.success(
26 i18n.t('events.delete.success.title', { name: value.remark }),
27 {
28 description: i18n.t('events.delete.success.desc')
29 })
30 queryClient.invalidateQueries({ queryKey: ["inbounds"] })
31}
32
33export const useHostsDeletionMutation = () => {
34 return useMutation({
35 mutationKey: [HostsDeleteFetchKey],
36 mutationFn: fetchDeleteHost,
37 onError: handleError,
38 onSuccess: handleSuccess,
39 })
40}