import * as AlertDialog from '@radix-ui/react-alert-dialog' import { useMutation, useQueryClient } from '@tanstack/react-query' import { devicesApi } from '../api' import toast from 'react-hot-toast' import type { AxiosError } from 'axios' import type { Device } from '../types/api' interface DeleteDeviceDialogProps { device: Device open: boolean onOpenChange: (open: boolean) => void onDeleted?: () => void } export default function DeleteDeviceDialog({ device, open, onOpenChange, onDeleted }: DeleteDeviceDialogProps) { const queryClient = useQueryClient() const deleteMutation = useMutation({ mutationFn: () => devicesApi.delete(device.id), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['devices'] }) queryClient.invalidateQueries({ queryKey: ['device', device.id] }) toast.success(`Device "${device.name}" deleted successfully`) onDeleted?.() onOpenChange(false) }, onError: (error) => { const axiosError = error as AxiosError<{ detail?: string }> const message = axiosError.response?.data?.detail || axiosError.message toast.error(`Failed to delete device: ${message}`) }, }) return ( Delete Device Are you sure you want to delete {device.name}? This action cannot be undone. All associated telemetry data and certificates will be permanently removed.
) }