1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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),
};
}
|