haixunMaster/lib/use-action-feedback.ts

42 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useCallback, useState } from "react";
import type { InlineAlertType } from "@/components/ui/inline-alert";
export interface ActionFeedback {
type: InlineAlertType;
message: string;
title?: string;
}
/** 直接操作儲存、刪除、驗證用頁面內提示AI背景任務才進通知中心。 */
export function useActionFeedback() {
const [feedback, setFeedback] = useState<ActionFeedback | null>(null);
const clearFeedback = useCallback(() => setFeedback(null), []);
const showError = useCallback((message: string, title?: string) => {
setFeedback({ type: "error", message, title });
}, []);
const showSuccess = useCallback((message: string, title?: string) => {
setFeedback({ type: "success", message, title });
}, []);
const showWarning = useCallback((message: string, title?: string) => {
setFeedback({ type: "warning", message, title });
}, []);
const showInfo = useCallback((message: string, title?: string) => {
setFeedback({ type: "info", message, title });
}, []);
return {
feedback,
clearFeedback,
showError,
showSuccess,
showWarning,
showInfo,
};
}