From ba8cd44a0ed2c613a5f2cee06bfc9bd0f61f21c7 Mon Sep 17 00:00:00 2001 From: dujinkim Date: Fri, 7 Nov 2025 08:39:04 +0000 Subject: (최겸) 입찰/견적 수정사항 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/bidding/bidding-notice-editor.tsx | 99 +++++++++++++++++++++++++---------- 1 file changed, 70 insertions(+), 29 deletions(-) (limited to 'lib/bidding/bidding-notice-editor.tsx') diff --git a/lib/bidding/bidding-notice-editor.tsx b/lib/bidding/bidding-notice-editor.tsx index 03b993b9..8d0f1e35 100644 --- a/lib/bidding/bidding-notice-editor.tsx +++ b/lib/bidding/bidding-notice-editor.tsx @@ -8,15 +8,30 @@ 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 { saveBiddingNoticeTemplate, saveBiddingNotice } from './service' import TiptapEditor from '@/components/qna/tiptap-editor' interface BiddingNoticeEditorProps { initialData: BiddingNoticeTemplate | null + biddingId?: number // 입찰 ID (있으면 일반 입찰공고, 없으면 템플릿) + templateType?: string // 템플릿 타입 (템플릿 저장 시 사용) + onSaveSuccess?: () => void // 저장 성공 시 콜백 + onTemplateUpdate?: (template: BiddingNoticeTemplate) => void // 템플릿 업데이트 콜백 } -export function BiddingNoticeEditor({ initialData }: BiddingNoticeEditorProps) { - const [title, setTitle] = useState(initialData?.title || '표준 입찰공고문') +export function BiddingNoticeEditor({ initialData, biddingId, templateType, onSaveSuccess, onTemplateUpdate }: BiddingNoticeEditorProps) { + const getDefaultTitle = (type?: string) => { + switch (type) { + case 'facility': + return '시설재 입찰공고문' + case 'unit_price': + return '단가계약 입찰공고문' + default: + return '표준 입찰공고문' + } + } + + const [title, setTitle] = useState(initialData?.title || getDefaultTitle(templateType)) const [content, setContent] = useState(initialData?.content || getDefaultTemplate()) const [isPending, startTransition] = useTransition() const { toast } = useToast() @@ -43,12 +58,47 @@ export function BiddingNoticeEditor({ initialData }: BiddingNoticeEditorProps) { startTransition(async () => { try { - await saveBiddingNoticeTemplate({ title, content }) - toast({ - title: '성공', - description: '입찰공고문 템플릿이 저장되었습니다.', - }) + if (biddingId) { + // 일반 입찰공고 저장 + await saveBiddingNotice(biddingId, { title, content }) + toast({ + title: '성공', + description: '입찰공고문이 저장되었습니다.', + }) + } else { + // 템플릿 저장 + if (!templateType) { + toast({ + title: '오류', + description: '템플릿 타입이 지정되지 않았습니다.', + variant: 'destructive', + }) + return + } + + const savedTemplate = await saveBiddingNoticeTemplate({ title, content, type: templateType }) + toast({ + title: '성공', + description: '입찰공고문 템플릿이 저장되었습니다.', + }) + + // 템플릿 업데이트 콜백 호출 + if (onTemplateUpdate && savedTemplate) { + // 저장된 템플릿 데이터를 가져와서 콜백 호출 + const updatedTemplate = { + ...initialData, + title, + content, + type: templateType, + updatedAt: new Date(), + } as BiddingNoticeTemplate + onTemplateUpdate(updatedTemplate) + } + } router.refresh() + + // 저장 성공 시 콜백 호출 + onSaveSuccess?.() } catch (error) { toast({ title: '오류', @@ -59,16 +109,16 @@ export function BiddingNoticeEditor({ initialData }: BiddingNoticeEditorProps) { }) } - const handleReset = () => { - if (confirm('기본 템플릿으로 초기화하시겠습니까? 현재 내용은 삭제됩니다.')) { - setTitle('표준 입찰공고문') - setContent(getDefaultTemplate()) - toast({ - title: '초기화 완료', - description: '기본 템플릿으로 초기화되었습니다.', - }) - } - } + // const handleReset = () => { + // if (confirm('기본 템플릿으로 초기화하시겠습니까? 현재 내용은 삭제됩니다.')) { + // setTitle(getDefaultTitle(templateType)) + // setContent(getDefaultTemplate()) + // toast({ + // title: '초기화 완료', + // description: '기본 템플릿으로 초기화되었습니다.', + // }) + // } + // } return (
@@ -117,13 +167,13 @@ export function BiddingNoticeEditor({ initialData }: BiddingNoticeEditorProps) { )} - + */} {initialData && (
@@ -131,15 +181,6 @@ export function BiddingNoticeEditor({ initialData }: BiddingNoticeEditorProps) {
)}
- - {/* 미리보기 힌트 */} -
-

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

-
) } -- cgit v1.2.3