feat(WEB): FCM 푸시 알림 공통 모듈 및 기안함 연동

- FCM 공통 모듈 생성 (src/lib/actions/fcm.ts)
  - sendFcmNotification: 기본 FCM 발송 함수
  - sendApprovalNotification: 결재 알림 프리셋
  - sendWorkOrderNotification: 작업지시 알림 프리셋
  - sendNoticeNotification: 공지사항 알림 프리셋
- 기안함 페이지에 '문서완료' 버튼 추가
  - Bell 아이콘 + FCM 발송 기능
  - 발송 결과 토스트 메시지 표시
This commit is contained in:
2026-01-13 19:47:03 +09:00
parent fcba883f42
commit c56c140e4b
3 changed files with 173 additions and 1 deletions

View File

@@ -457,4 +457,4 @@ export async function cancelDraft(id: string): Promise<{ success: boolean; error
error: '서버 오류가 발생했습니다.',
};
}
}
}

View File

@@ -8,6 +8,7 @@ import {
Trash2,
Plus,
Pencil,
Bell,
} from 'lucide-react';
import { toast } from 'sonner';
import {
@@ -19,6 +20,7 @@ import {
submitDraft,
submitDrafts,
} from './actions';
import { sendApprovalNotification } from '@/lib/actions/fcm';
import { Button } from '@/components/ui/button';
import { Checkbox } from '@/components/ui/checkbox';
import { Badge } from '@/components/ui/badge';
@@ -243,6 +245,24 @@ export function DraftBox() {
router.push('/ko/approval/draft/new');
}, [router]);
// ===== FCM 알림 발송 핸들러 =====
const handleSendNotification = useCallback(async () => {
startTransition(async () => {
try {
const result = await sendApprovalNotification();
if (result.success) {
toast.success(`결재 알림을 발송했습니다. (${result.sentCount || 0}건)`);
} else {
toast.error(result.error || '알림 발송에 실패했습니다.');
}
} catch (error) {
if (isNextRedirectError(error)) throw error;
console.error('Notification error:', error);
toast.error('알림 발송 중 오류가 발생했습니다.');
}
});
}, []);
// ===== 문서 클릭/수정 핸들러 (조건부 로직) =====
// 임시저장 → 문서 작성 페이지 (수정 모드)
// 그 외 → 문서 상세 모달 (상세 API 호출하여 content 포함된 데이터 가져옴)
@@ -597,6 +617,10 @@ export function DraftBox() {
</Button>
</>
)}
<Button variant="outline" onClick={handleSendNotification}>
<Bell className="h-4 w-4 mr-2" />
</Button>
<Button onClick={handleNewDocument}>
<Plus className="h-4 w-4 mr-2" />