summaryrefslogtreecommitdiff
path: root/lib/email-template/validations.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/email-template/validations.ts')
-rw-r--r--lib/email-template/validations.ts82
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/email-template/validations.ts b/lib/email-template/validations.ts
new file mode 100644
index 00000000..ece5437e
--- /dev/null
+++ b/lib/email-template/validations.ts
@@ -0,0 +1,82 @@
+import {
+ createSearchParamsCache,
+ parseAsArrayOf,
+ parseAsInteger,
+ parseAsString,
+ parseAsStringEnum,
+} from "nuqs/server";
+import * as z from "zod";
+
+import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers";
+import { templateListView, type TemplateListView } from '@/db/schema';
+
+export const SearchParamsEmailTemplateCache = createSearchParamsCache({
+ // UI 모드나 플래그 관련
+ flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
+
+ // 페이징
+ page: parseAsInteger.withDefault(1),
+ perPage: parseAsInteger.withDefault(10),
+
+ // 정렬 (createdAt 기준 내림차순)
+ sort: getSortingStateParser<typeof templateListView>().withDefault([
+ { id: "updatedAt", desc: true }]),
+ filters: getFiltersStateParser().withDefault([]),
+ joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
+ search: parseAsString.withDefault(""),
+});
+export type GetEmailTemplateSchema = Awaited<ReturnType<typeof SearchParamsEmailTemplateCache.parse>>;
+
+
+// 카테고리 옵션과 유틸리티 함수들 (애플리케이션 레벨에서 처리)
+export const TEMPLATE_CATEGORY_OPTIONS = [
+ { label: '환영 메일', value: 'welcome-email' },
+ { label: '비밀번호 재설정', value: 'password-reset' },
+ { label: '알림', value: 'notification' },
+ { label: '청구서', value: 'invoice' },
+ { label: '마케팅', value: 'marketing' },
+ { label: '시스템', value: 'system' },
+] as const;
+
+// 카테고리 변환 함수 (애플리케이션 레벨)
+export function getCategoryDisplayName(category: string | null): string {
+ const categoryMap: Record<string, string> = {
+ 'welcome-email': '환영 메일',
+ 'password-reset': '비밀번호 재설정',
+ 'notification': '알림',
+ 'invoice': '청구서',
+ 'marketing': '마케팅',
+ 'system': '시스템',
+ };
+
+ return categoryMap[category || ''] || '미분류';
+}
+
+// 카테고리 변형(variant) 함수
+export function getCategoryVariant(category: string | null): 'default' | 'secondary' | 'destructive' | 'outline' {
+ const variantMap: Record<string, 'default' | 'secondary' | 'destructive' | 'outline'> = {
+ 'welcome-email': 'default',
+ 'password-reset': 'destructive',
+ 'notification': 'secondary',
+ 'invoice': 'outline',
+ 'marketing': 'default',
+ 'system': 'secondary',
+ };
+
+ return variantMap[category || ''] || 'outline';
+}
+
+// 확장된 템플릿 타입 (display name 포함)
+export type TemplateListViewWithDisplay = TemplateListView & {
+ categoryDisplayName: string;
+ categoryVariant: 'default' | 'secondary' | 'destructive' | 'outline';
+};
+
+// 유틸리티 함수: View 데이터에 display 정보 추가
+export function enhanceTemplateListView(template: TemplateListView): TemplateListViewWithDisplay {
+ return {
+ ...template,
+ categoryDisplayName: getCategoryDisplayName(template.category),
+ categoryVariant: getCategoryVariant(template.category),
+ };
+} \ No newline at end of file