'use client' import { useState, useTransition } from 'react' import { useRouter } from 'next/navigation' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { useToast } from '@/hooks/use-toast' import { Save, RefreshCw } from 'lucide-react' import { BiddingNoticeTemplate } from '@/db/schema/bidding' import { saveBiddingNoticeTemplate } from './service' import TiptapEditor from '@/components/qna/tiptap-editor' interface BiddingNoticeEditorProps { initialData: BiddingNoticeTemplate | null } export function BiddingNoticeEditor({ initialData }: BiddingNoticeEditorProps) { const [title, setTitle] = useState(initialData?.title || '표준 입찰공고문') const [content, setContent] = useState(initialData?.content || getDefaultTemplate()) const [isPending, startTransition] = useTransition() const { toast } = useToast() const router = useRouter() const handleSave = () => { if (!title.trim()) { toast({ title: '오류', description: '제목을 입력해주세요.', variant: 'destructive', }) return } if (!content.trim()) { toast({ title: '오류', description: '내용을 입력해주세요.', variant: 'destructive', }) return } startTransition(async () => { try { await saveBiddingNoticeTemplate({ title, content }) toast({ title: '성공', description: '입찰공고문 템플릿이 저장되었습니다.', }) router.refresh() } catch (error) { toast({ title: '오류', description: error instanceof Error ? error.message : '저장에 실패했습니다.', variant: 'destructive', }) } }) } const handleReset = () => { if (confirm('기본 템플릿으로 초기화하시겠습니까? 현재 내용은 삭제됩니다.')) { setTitle('표준 입찰공고문') setContent(getDefaultTemplate()) toast({ title: '초기화 완료', description: '기본 템플릿으로 초기화되었습니다.', }) } } return (
{/* 제목 입력 */}
setTitle(e.target.value)} placeholder="입찰공고문 제목을 입력하세요" disabled={isPending} />
{/* 에디터 */}
{/* 액션 버튼 */}
{initialData && (
마지막 업데이트: {new Date(initialData.updatedAt).toLocaleString('ko-KR')}
)}
{/* 미리보기 힌트 */}

💡 사용 팁: 이 템플릿은 실제 입찰 공고 작성 시 기본값으로 사용됩니다. 회사 정보, 표준 조건, 서식 등을 미리 작성해두면 편리합니다.

) } // 기본 템플릿 함수 function getDefaultTemplate(): string { return `

입찰공고

1. 입찰 개요

2. 입찰 참가자격

3. 입찰 일정

구분 일시 장소
입찰 공고 [YYYY.MM.DD] -
현장설명 [YYYY.MM.DD HH:MM] [현장 주소]
입찰서 접수 [YYYY.MM.DD HH:MM까지] [접수 장소]
개찰 [YYYY.MM.DD HH:MM] [개찰 장소]

4. 입찰 대상

5. 제출 서류

6. 기타 사항

문의처:
담당자: [담당자명]
전화: [전화번호]
이메일: [이메일주소]

`.trim() }