260826_01_ENH: notihub 수정으로 인한 후속 조치 #15

Merged
gitadmin merged 1 commits from develop into master 2026-08-26 12:29:18 +09:00
6 changed files with 148 additions and 7 deletions

View File

@@ -251,6 +251,17 @@ When implementation is complete, report in Korean:
- Validate external data at runtime; a shared TypeScript type alone does not validate an API response or persisted value.
- Prefer named public exports and retain the consumer project's current module system and bundler conventions.
### React Compiler and Manual Memoization
- `createKriNextConfig` enables `reactCompiler: true` unless the project overrides it; confirm the effective configuration.
- When enabled, rely on React Compiler instead of adding `useMemo`, `useCallback`, or `React.memo` as a routine performance precaution.
- Use manual memoization only for required reference stability, an Effect or third-party contract, compiler-incompatible code, or a measured performance problem.
- Preserve existing memoization unless approved and verified for removal. Use `"use memo"` or `"use no memo"` only for a documented compiler boundary.
### Project Instruction Budget
- Keep `.agent/project.md` at or below 8 KiB (8,192 bytes) as the normal target. Do not delete material rules merely to meet the budget; move schemas, endpoint inventories, examples, and temporary issue history to linked project documentation, and keep concise read-routing instructions here.
### Change Safety
- Pin or constrain the package version according to the consumer repository's dependency policy and commit its lockfile changes.

View File

@@ -4,6 +4,7 @@ import {errorToResponse} from "@/lib/http-util";
import {createNotiHubApi} from "@/lib/server-api";
import {
BulkSendResponse,
CreateTemplateRequest,
SaveTemplateRequest,
SendSmsBulkRequest,
Template,
@@ -15,14 +16,31 @@ export const GET = async (
) => {
try {
const {slug = []} = await context.params;
const [action, templateIdx] = slug;
const [action, second, third, fourth] = slug;
if (action !== "template" || !templateIdx) {
if (action !== "template") {
return NextResponse.json({ message: "Not found" }, { status: 404 });
}
const notiHubApi = await createNotiHubApi();
const template = await notiHubApi.get<Template>(`/template/${encodeURIComponent(templateIdx)}`);
let path: string;
if (second === "list") {
if (slug.length !== 4 || !third || !fourth) {
return NextResponse.json({ message: "Not found" }, { status: 404 });
}
path = `/template/list/${encodeURIComponent(third)}/${encodeURIComponent(fourth)}`;
} else {
if (slug.length !== 2 || !second) {
return NextResponse.json({ message: "Not found" }, { status: 404 });
}
path = `/template/${encodeURIComponent(second)}`;
}
if (!path) {
return NextResponse.json({ message: "Not found" }, { status: 404 });
}
const template = await notiHubApi.get<Template | Template[]>(path);
return NextResponse.json(template, { status: 200 });
} catch (error: unknown) {
@@ -30,6 +48,35 @@ export const GET = async (
}
};
export const PUT = async (
req: NextRequest,
context: RouteContext
) => {
try {
const {slug = []} = await context.params;
if (slug.length !== 1 || slug[0] !== "template") {
return NextResponse.json({ message: "Not found" }, { status: 404 });
}
const formData = await req.formData();
const templatePart = formData.get("template");
const body = templatePart instanceof Blob
? JSON.parse(await templatePart.text()) as CreateTemplateRequest
: null;
if (!body || !body.itrntPrjctCd || body.tmplatTy == null || !body.tmplatNm || !body.tmplatBody || !body.sendTel || !body.sendNm) {
return NextResponse.json({ message: "Template request body is invalid." }, { status: 400 });
}
const notiHubApi = await createNotiHubApi();
const backendForm = new FormData();
backendForm.append("template", new Blob([JSON.stringify(body)], {type: "application/json"}));
const created = await notiHubApi.putForm<Template>("/template", backendForm);
return NextResponse.json(created, { status: 200 });
} catch (error: unknown) {
return errorToResponse(error);
}
};
export const PATCH = async (
req: NextRequest,
context: RouteContext
@@ -56,6 +103,7 @@ export const PATCH = async (
const next: Template = {
...current,
tmplatNm: body.tmplatNm,
tmplatPurpose: body.tmplatPurpose ?? current.tmplatPurpose ?? 0,
tmplatTitle: body.tmplatTitle,
tmplatBody: body.tmplatBody,
sendTel: body.sendTel,

View File

@@ -24,10 +24,11 @@ import {SaveTemplateRequest, Template} from "@/types/notification";
import {UserCompact} from "@/types/gwcf";
import {getDetailValue} from "@/lib/gwcf/view";
import {useAuth} from "@/hooks/useAuth";
import {buildUserMsgParam} from "@/lib/gwcf/notification";
import {buildTemplatePreviewBody, buildUserMsgParam, getSmsByteLength, isPhoneVerificationSupported} from "@/lib/gwcf/notification";
import {getSmsParamLabel} from "@/lib/gwcf/field-labels";
import {TMPLAT_PURPOSE} from "@/types/notification";
type TemplateDraft = Pick<Template, "tmplatIdx" | "tmplatNm" | "tmplatTitle" | "tmplatBody" | "sendTel">;
type TemplateDraft = Pick<Template, "tmplatIdx" | "tmplatTy" | "tmplatPurpose" | "tmplatNm" | "tmplatTitle" | "tmplatBody" | "sendTel">;
const EMPTY_DENY_PARAM_KEYS: string[] = [];
@@ -35,6 +36,8 @@ const toText = (value: string | null | undefined) => value ?? "";
const toDraft = (template: Template, isNewMessage = false): TemplateDraft => ({
tmplatIdx: template.tmplatIdx,
tmplatTy: template.tmplatTy,
tmplatPurpose: isPhoneVerificationSupported(template) ? template.tmplatPurpose ?? TMPLAT_PURPOSE.NORMAL : TMPLAT_PURPOSE.NORMAL,
tmplatNm: toText(template.tmplatNm),
tmplatTitle: isNewMessage ? "" : toText(template.tmplatTitle),
tmplatBody: isNewMessage ? "" : toText(template.tmplatBody),
@@ -163,6 +166,7 @@ export function SmsSendDialog({
const payload: SaveTemplateRequest = {
tmplatIdx: draft.tmplatIdx,
tmplatPurpose: draft.tmplatPurpose,
tmplatNm: draft.tmplatNm,
tmplatTitle: draft.tmplatTitle,
tmplatBody: draft.tmplatBody,
@@ -205,6 +209,9 @@ export function SmsSendDialog({
setDraft(null);
};
const previewBody = draft ? buildTemplatePreviewBody(draft) : "";
const isSmsOrLms = draft ? isPhoneVerificationSupported(draft) : false;
const send = async () => {
if (!draft) return;
@@ -306,6 +313,7 @@ export function SmsSendDialog({
{templatesQuery.data.map((template) => (
<SelectItem key={template.tmplatIdx} value={String(template.tmplatIdx)}>
{toText(template.tmplatNm) || `${template.tmplatIdx}`}
{template.tmplatPurpose === TMPLAT_PURPOSE.PHONE_VERIFICATION && " (인증)"}
</SelectItem>
))}
</SelectContent>
@@ -320,6 +328,24 @@ export function SmsSendDialog({
<span className="font-medium">제목</span>
<Input value={draft.tmplatTitle} disabled={!canEdit || isBusy} onChange={(event) => updateDraft("tmplatTitle", event.target.value)} />
</label>
{isSmsOrLms && (
<label className="space-y-1 text-sm">
<span className="font-medium">템플릿 용도</span>
<Select
value={String(draft.tmplatPurpose)}
onValueChange={(value) => updateDraft("tmplatPurpose", Number(value))}
disabled={!canEdit || isBusy}
>
<SelectTrigger className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value={String(TMPLAT_PURPOSE.NORMAL)}>일반</SelectItem>
<SelectItem value={String(TMPLAT_PURPOSE.PHONE_VERIFICATION)}>휴대전화번호 인증</SelectItem>
</SelectContent>
</Select>
</label>
)}
<label className="space-y-1 text-sm">
<span className="font-medium">내용</span>
<textarea
@@ -330,6 +356,11 @@ export function SmsSendDialog({
className="min-h-80 w-full rounded-md border border-input bg-background p-3 text-sm disabled:cursor-not-allowed disabled:opacity-70"
/>
</label>
<div className="space-y-1 rounded-md border bg-muted/20 p-3 text-sm">
<div className="font-medium">미리보기</div>
<div className="whitespace-pre-wrap text-muted-foreground">{previewBody}</div>
{isSmsOrLms && <div className="text-xs text-muted-foreground">{getSmsByteLength(previewBody)} bytes</div>}
</div>
{msgParamKeys.length > 0 && (
<div className="space-y-1 text-sm">
<div className="font-medium text-muted-foreground">사용 가능 변수값</div>

View File

@@ -1,4 +1,18 @@
import {PerformanceFull, UserCompact} from "@/types/gwcf";
import {TMPLAT_PURPOSE, Template} from "@/types/notification";
export const PHONE_VERIFICATION_PREVIEW = "인증번호는 [######] 입니다.";
export const isPhoneVerificationSupported = (template: Pick<Template, "tmplatTy">) =>
template.tmplatTy === 10 || template.tmplatTy === 20;
export const buildTemplatePreviewBody = (template: Pick<Template, "tmplatBody" | "tmplatPurpose">) =>
template.tmplatPurpose === TMPLAT_PURPOSE.PHONE_VERIFICATION
? `${template.tmplatBody}\n${PHONE_VERIFICATION_PREVIEW}`
: template.tmplatBody;
export const getSmsByteLength = (value: string) =>
Array.from(value).reduce((total, character) => total + (character.charCodeAt(0) > 0x7f ? 2 : 1), 0);
export const toNotificationParamValue = (value: unknown) => value == null ? "" : String(value);

View File

@@ -2,7 +2,7 @@
import {useMutation, useQueries, useQuery} from "@tanstack/react-query";
import {nextApi} from "@/lib/http-client";
import {BulkSendResponse, SaveTemplateRequest, SendSmsBulkRequest, Template} from "@/types/notification";
import {BulkSendResponse, CreateTemplateRequest, SaveTemplateRequest, SendSmsBulkRequest, Template, TemplateListItem} from "@/types/notification";
export const SMS_TEMPLATE_IDS = {
ACCOUNT_MONITORING: 45,
@@ -37,6 +37,28 @@ export function useNotificationTemplatesQuery(templateIdxList: number[], enabled
});
}
export function useNotificationTemplateListQuery(chnnlTy: number, itrntPrjctCd: string, enabled = true) {
return useQuery({
queryKey: ["notification", "template-list", chnnlTy, itrntPrjctCd],
queryFn: () => nextApi.get<TemplateListItem[]>(`/notification/template/list/${encodeURIComponent(chnnlTy)}/${encodeURIComponent(itrntPrjctCd)}`),
enabled: enabled && Boolean(itrntPrjctCd),
});
}
export function useCreateNotificationTemplateMutation() {
return useMutation({
mutationFn: (data: CreateTemplateRequest) => {
const formData = new FormData();
formData.append(
"template",
new Blob([JSON.stringify(data)], {type: "application/json"})
);
return nextApi.putForm<Template>("/notification/template", formData);
},
});
}
export function useSaveNotificationTemplateMutation() {
return useMutation({
mutationFn: (data: SaveTemplateRequest) => {

View File

@@ -1,6 +1,7 @@
export type Template = {
itrntPrjctCd: string;
tmplatTy: number;
tmplatPurpose: number;
tmplatNm: string;
tmplatTitle: string;
tmplatBody: string;
@@ -15,6 +16,18 @@ export type Template = {
tmplatIdx: number;
};
export const TMPLAT_PURPOSE = {
NORMAL: 0,
PHONE_VERIFICATION: 1,
} as const;
export type TemplatePurpose = (typeof TMPLAT_PURPOSE)[keyof typeof TMPLAT_PURPOSE];
export type CreateTemplateRequest = Pick<
Template,
"itrntPrjctCd" | "tmplatTy" | "tmplatPurpose" | "tmplatNm" | "tmplatBody" | "sendTel" | "sendNm"
>;
export type SmsDestination = {
sid?: string;
destTel: string;
@@ -22,7 +35,9 @@ export type SmsDestination = {
msgParam?: Record<string, string>;
};
export type SaveTemplateRequest = Pick<Template, "tmplatIdx" | "tmplatNm" | "tmplatTitle" | "tmplatBody" | "sendTel">;
export type SaveTemplateRequest = Pick<Template, "tmplatIdx" | "tmplatPurpose" | "tmplatNm" | "tmplatTitle" | "tmplatBody" | "sendTel">;
export type TemplateListItem = Pick<Template, "tmplatIdx" | "tmplatNm" | "tmplatPurpose">;
export type SendSmsBulkRequest = {
templateIdx: number;