summaryrefslogtreecommitdiff
path: root/components/notice
diff options
context:
space:
mode:
Diffstat (limited to 'components/notice')
-rw-r--r--components/notice/notice-client.tsx37
-rw-r--r--components/notice/notice-create-dialog.tsx22
-rw-r--r--components/notice/notice-edit-sheet.tsx23
3 files changed, 76 insertions, 6 deletions
diff --git a/components/notice/notice-client.tsx b/components/notice/notice-client.tsx
index e32a40c9..e5c05d84 100644
--- a/components/notice/notice-client.tsx
+++ b/components/notice/notice-client.tsx
@@ -1,6 +1,8 @@
"use client"
import { useState, useEffect, useTransition } from "react"
+import { useParams } from "next/navigation"
+import { useTranslation } from "@/i18n/client"
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import {
@@ -55,6 +57,25 @@ type SortField = "title" | "pagePath" | "createdAt"
type SortDirection = "asc" | "desc"
export function NoticeClient({ initialData = [], currentUserId }: NoticeClientProps) {
+ const params = useParams()
+ const lng = (params?.lng as string) || 'ko'
+ const { t } = useTranslation(lng, 'menu')
+
+ // 안전한 번역 함수 (키가 없을 때 원본 키 반환)
+ const safeTranslate = (key: string): string => {
+ try {
+ const translated = t(key)
+ // 번역 키가 그대로 반환되는 경우 원본 키 사용
+ if (translated === key) {
+ return key
+ }
+ return translated || key
+ } catch (error) {
+ console.warn(`Translation failed for key: ${key}`, error)
+ return key
+ }
+ }
+
const [notices, setNotices] = useState<NoticeWithAuthor[]>(initialData)
const [loading, setLoading] = useState(false)
const [searchQuery, setSearchQuery] = useState("")
@@ -172,7 +193,7 @@ export function NoticeClient({ initialData = [], currentUserId }: NoticeClientPr
const paths = await getPagePathList()
const options = paths.map(path => ({
value: path.pagePath,
- label: `${path.pageName} (${path.pagePath})`
+ label: path.pageName // i18n 키를 그대로 저장 (화면에서 번역)
}))
setPagePathOptions(options)
} catch (error) {
@@ -325,9 +346,17 @@ export function NoticeClient({ initialData = [], currentUserId }: NoticeClientPr
</div>
</TableCell>
<TableCell>
- <span className="font-mono text-sm max-w-[200px] truncate block">
- {notice.pagePath}
- </span>
+ <div className="max-w-[200px]">
+ <div className="font-mono text-xs text-muted-foreground truncate">
+ {notice.pagePath}
+ </div>
+ <div className="text-sm truncate">
+ {(() => {
+ const pageOption = pagePathOptions.find(opt => opt.value === notice.pagePath)
+ return pageOption ? safeTranslate(pageOption.label) : notice.pagePath
+ })()}
+ </div>
+ </div>
</TableCell>
<TableCell>
<div className="flex flex-col">
diff --git a/components/notice/notice-create-dialog.tsx b/components/notice/notice-create-dialog.tsx
index e3ce16a1..21cd46f6 100644
--- a/components/notice/notice-create-dialog.tsx
+++ b/components/notice/notice-create-dialog.tsx
@@ -4,6 +4,8 @@ import * as React from "react"
import { useState } from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
+import { useParams } from "next/navigation"
+import { useTranslation } from "@/i18n/client"
import { toast } from "sonner"
import { Loader } from "lucide-react"
import { Button } from "@/components/ui/button"
@@ -49,6 +51,24 @@ export function NoticeCreateDialog({
currentUserId,
onSuccess,
}: NoticeCreateDialogProps) {
+ const params = useParams()
+ const lng = (params?.lng as string) || 'ko'
+ const { t } = useTranslation(lng, 'menu')
+
+ // 안전한 번역 함수 (키가 없을 때 원본 키 반환)
+ const safeTranslate = (key: string): string => {
+ try {
+ const translated = t(key)
+ // 번역 키가 그대로 반환되는 경우 원본 키 사용
+ if (translated === key) {
+ return key
+ }
+ return translated || key
+ } catch (error) {
+ console.warn(`Translation failed for key: ${key}`, error)
+ return key
+ }
+ }
const [isLoading, setIsLoading] = useState(false)
const form = useForm<CreateNoticeSchema>({
@@ -127,7 +147,7 @@ export function NoticeCreateDialog({
<SelectContent>
{pagePathOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
- {option.label}
+ {safeTranslate(option.label)}
</SelectItem>
))}
</SelectContent>
diff --git a/components/notice/notice-edit-sheet.tsx b/components/notice/notice-edit-sheet.tsx
index 91bcae3b..dc83d23a 100644
--- a/components/notice/notice-edit-sheet.tsx
+++ b/components/notice/notice-edit-sheet.tsx
@@ -3,6 +3,8 @@
import * as React from "react"
import { zodResolver } from "@hookform/resolvers/zod"
import { useForm } from "react-hook-form"
+import { useParams } from "next/navigation"
+import { useTranslation } from "@/i18n/client"
import { toast } from "sonner"
import { Button } from "@/components/ui/button"
@@ -57,6 +59,25 @@ export function UpdateNoticeSheet({
pagePathOptions,
onSuccess
}: UpdateNoticeSheetProps) {
+ const params = useParams()
+ const lng = (params?.lng as string) || 'ko'
+ const { t } = useTranslation(lng, 'menu')
+
+ // 안전한 번역 함수 (키가 없을 때 원본 키 반환)
+ const safeTranslate = (key: string): string => {
+ try {
+ const translated = t(key)
+ // 번역 키가 그대로 반환되는 경우 원본 키 사용
+ if (translated === key) {
+ return key
+ }
+ return translated || key
+ } catch (error) {
+ console.warn(`Translation failed for key: ${key}`, error)
+ return key
+ }
+ }
+
const [isUpdatePending, startUpdateTransition] = React.useTransition()
const form = useForm<UpdateNoticeSchema>({
@@ -149,7 +170,7 @@ export function UpdateNoticeSheet({
<SelectContent>
{pagePathOptions.map((option) => (
<SelectItem key={option.value} value={option.value}>
- {option.label}
+ {safeTranslate(option.label)}
</SelectItem>
))}
</SelectContent>