diff --git a/src/app/[locale]/(protected)/sales/order-management-sales/page.tsx b/src/app/[locale]/(protected)/sales/order-management-sales/page.tsx index f788b144..7de2188a 100644 --- a/src/app/[locale]/(protected)/sales/order-management-sales/page.tsx +++ b/src/app/[locale]/(protected)/sales/order-management-sales/page.tsx @@ -10,7 +10,7 @@ * - API 연동 완료 (2025-01-08) */ -import { useState, useRef, useEffect, useCallback } from "react"; +import { useState, useRef, useEffect, useCallback, useTransition } from "react"; import { useRouter } from "next/navigation"; import { FileText, @@ -22,6 +22,7 @@ import { Truck, Eye, Loader2, + Bell, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; @@ -58,6 +59,8 @@ import { type OrderStatus, type OrderStats, } from "@/components/orders/actions"; +import { sendSalesOrderNotification } from "@/lib/actions/fcm"; +import { isNextRedirectError } from "@/lib/utils/redirect-error"; // 상태 뱃지 헬퍼 함수 @@ -83,6 +86,7 @@ function getOrderStatusBadge(status: OrderStatus) { export default function OrderManagementSalesPage() { const router = useRouter(); + const [isPending, startTransition] = useTransition(); const [searchTerm, setSearchTerm] = useState(""); const [filterType, setFilterType] = useState("all"); const [selectedItems, setSelectedItems] = useState>(new Set()); @@ -390,6 +394,23 @@ export default function OrderManagementSalesPage() { } }; + // FCM 알림 발송 핸들러 + const handleSendNotification = useCallback(async () => { + startTransition(async () => { + try { + const result = await sendSalesOrderNotification(); + if (result.success) { + toast.success(`수주완료 알림을 발송했습니다. (${result.sentCount || 0}건)`); + } else { + toast.error(result.error || "알림 발송에 실패했습니다."); + } + } catch (error) { + if (isNextRedirectError(error)) throw error; + toast.error("알림 발송 중 오류가 발생했습니다."); + } + }); + }, []); + // 탭 구성 const tabs: TabOption[] = [ { @@ -620,10 +641,16 @@ export default function OrderManagementSalesPage() { description="수주 관리 및 생산지시 연동" icon={FileText} headerActions={ - +
+ + +
} stats={stats} searchValue={searchTerm} diff --git a/src/lib/actions/fcm.ts b/src/lib/actions/fcm.ts index 3f41ceea..352c178f 100644 --- a/src/lib/actions/fcm.ts +++ b/src/lib/actions/fcm.ts @@ -160,4 +160,19 @@ export async function sendNewClientNotification( channel_id: 'push_urgent', ...customParams, }); +} + +/** + * 수주 알림 발송 (프리셋) + */ +export async function sendSalesOrderNotification( + customParams?: Partial +): Promise { + return sendFcmNotification({ + title: '수주 알림', + body: '수주가 완료되었습니다.', + type: 'sales_order', + channel_id: 'push_sales_order', + ...customParams, + }); } \ No newline at end of file