| 1 | /** |
| 2 | * 关闭弹窗确认 Hook |
| 3 | * 统一处理发布弹窗关闭前的确认逻辑 |
| 4 | */ |
| 5 | |
| 6 | import { AlertCircle } from 'lucide-react' |
| 7 | import { useCallback } from 'react' |
| 8 | import { confirm } from '@/utils/ui/confirm' |
| 9 | |
| 10 | interface UseCloseDialogParams { |
| 11 | onClose: () => void |
| 12 | t: (key: string, params?: Record<string, string>) => string |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * 关闭弹窗确认 Hook |
| 17 | */ |
| 18 | export function useCloseDialog({ onClose, t }: UseCloseDialogParams) { |
| 19 | /** |
| 20 | * 关闭弹框确认 |
| 21 | * 弹出确认框,确认后关闭弹窗 |
| 22 | */ |
| 23 | const closeDialog = useCallback(() => { |
| 24 | confirm({ |
| 25 | title: t('confirmClose.title'), |
| 26 | icon: <AlertCircle className="h-5 w-5 text-yellow-500" />, |
| 27 | content: t('confirmClose.content'), |
| 28 | okType: 'destructive', |
| 29 | centered: true, |
| 30 | cancelText: t('buttons.cancel'), |
| 31 | onOk() { |
| 32 | onClose() |
| 33 | }, |
| 34 | }) |
| 35 | }, [onClose, t]) |
| 36 | |
| 37 | return { |
| 38 | closeDialog, |
| 39 | } |
| 40 | } |
| 41 |