diff options
Diffstat (limited to 'lib/bidding/bidding-notice-editor.tsx')
| -rw-r--r-- | lib/bidding/bidding-notice-editor.tsx | 99 |
1 files changed, 70 insertions, 29 deletions
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 ( <div className="space-y-6"> @@ -117,13 +167,13 @@ export function BiddingNoticeEditor({ initialData }: BiddingNoticeEditorProps) { )} </Button> - <Button + {/* <Button variant="outline" onClick={handleReset} disabled={isPending} > 기본 템플릿으로 초기화 - </Button> + </Button> */} {initialData && ( <div className="ml-auto text-sm text-muted-foreground"> @@ -131,15 +181,6 @@ export function BiddingNoticeEditor({ initialData }: BiddingNoticeEditorProps) { </div> )} </div> - - {/* 미리보기 힌트 */} - <div className="bg-muted/50 p-4 rounded-lg"> - <p className="text-sm text-muted-foreground"> - <strong>💡 사용 팁:</strong> - 이 템플릿은 실제 입찰 공고 작성 시 기본값으로 사용됩니다. - 회사 정보, 표준 조건, 서식 등을 미리 작성해두면 편리합니다. - </p> - </div> </div> ) } |
