From ee57cc221ff2edafd3c0f12a181214c602ed257e Mon Sep 17 00:00:00 2001 From: dujinkim Date: Tue, 22 Jul 2025 02:57:00 +0000 Subject: (대표님, 최겸) 이메일 템플릿, 벤더데이터 변경사항 대응, 기술영업 변경요구사항 구현 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor/template-content-editor.tsx | 9 ++++---- lib/email-template/service.ts | 9 +++++--- .../table/template-table-columns.tsx | 14 ++++++------ lib/email-template/table/update-template-sheet.tsx | 26 +++++++++++++++------- 4 files changed, 36 insertions(+), 22 deletions(-) (limited to 'lib/email-template') diff --git a/lib/email-template/editor/template-content-editor.tsx b/lib/email-template/editor/template-content-editor.tsx index 4d31753c..08de53d2 100644 --- a/lib/email-template/editor/template-content-editor.tsx +++ b/lib/email-template/editor/template-content-editor.tsx @@ -167,7 +167,7 @@ export function TemplateContentEditor({ template, onUpdate }: TemplateContentEdi subject, content, sampleData, - version: template.version + 1 + version: template.version ? template.version + 1 :0 }) } else { toast.error(result.error || '저장에 실패했습니다.') @@ -188,12 +188,13 @@ export function TemplateContentEditor({ template, onUpdate }: TemplateContentEdi template.slug, sampleData, content, - // subject // 주석 해제 + subject // 주석 해제 ) - if (result.success) { + + if (result.success && result.data) { setPreviewHtml(result.data.html) - setPreviewSubject(result.data.subject) + setPreviewSubject(result.data.subjectHtml) if (!silent) toast.success('미리보기가 생성되었습니다.') } else { if (!silent) toast.error(result.error || '미리보기 생성에 실패했습니다.') diff --git a/lib/email-template/service.ts b/lib/email-template/service.ts index 13aba77b..e3ab9bed 100644 --- a/lib/email-template/service.ts +++ b/lib/email-template/service.ts @@ -789,7 +789,7 @@ export async function updateTemplateAction(slug: string, data: { content?: string; description?: string; sampleData?: Record; - updatedBy: string; + updatedBy: number; }) { try { if (data.content) { @@ -850,14 +850,17 @@ export async function previewTemplateAction( slug: string, data: Record, customContent?: string, - // subject: string + subject?: string ) { try { + + const html = await previewTemplate(slug, data, customContent); + const subjectHtml = await previewTemplate(slug, data, subject); return { success: true, - data: { html } + data: { html , subjectHtml} }; } catch (error) { return { diff --git a/lib/email-template/table/template-table-columns.tsx b/lib/email-template/table/template-table-columns.tsx index d20739cc..a678a20a 100644 --- a/lib/email-template/table/template-table-columns.tsx +++ b/lib/email-template/table/template-table-columns.tsx @@ -248,20 +248,20 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef - + - { setRowAction({ type: "update", row }) }} > + 업데이트 + */} { @@ -269,7 +269,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef @@ -281,7 +281,7 @@ export function getColumns({ setRowAction }: GetColumnsProps): ColumnDef diff --git a/lib/email-template/table/update-template-sheet.tsx b/lib/email-template/table/update-template-sheet.tsx index 58da0626..d3df93f0 100644 --- a/lib/email-template/table/update-template-sheet.tsx +++ b/lib/email-template/table/update-template-sheet.tsx @@ -7,6 +7,7 @@ import { Loader } from "lucide-react" import { useForm } from "react-hook-form" import { toast } from "sonner" import { z } from "zod" +import { useSession } from "next-auth/react" import { Button } from "@/components/ui/button" import { @@ -55,6 +56,13 @@ interface UpdateTemplateSheetProps export function UpdateTemplateSheet({ template, ...props }: UpdateTemplateSheetProps) { const [isUpdatePending, startUpdateTransition] = React.useTransition() + const { data: session } = useSession(); + + // 또는 더 안전하게 + if (!session?.user?.id) { + toast.error("로그인이 필요합니다") + return + } const form = useForm({ resolver: zodResolver(updateTemplateSchema), @@ -85,8 +93,10 @@ export function UpdateTemplateSheet({ template, ...props }: UpdateTemplateSheetP const { error } = await updateTemplateAction(template.slug, { name: input.name, description: input.description || undefined, + category: input.category === "none" ? undefined : input.category, // 여기서 변환 + // category는 일반적으로 수정하지 않는 것이 좋지만, 필요시 포함 - updatedBy: currentUserId, + updatedBy: Number(session.user.id), }) if (error) { @@ -165,13 +175,13 @@ export function UpdateTemplateSheet({ template, ...props }: UpdateTemplateSheetP - 카테고리 없음 - {TEMPLATE_CATEGORY_OPTIONS.map((option) => ( - - {option.label} - - ))} - + 카테고리 없음 + {TEMPLATE_CATEGORY_OPTIONS.map((option) => ( + + {option.label} + + ))} + -- cgit v1.2.3