Initial commit: 용산 공중케이블 주민 안전 협의회 홈페이지

- Next.js 16 App Router + TypeScript + Tailwind CSS 4
- Prisma/SQLite 기반 공지사항·자료실·관리자·문의/제보
- 네이버 블로그 RSS 최신 글 5개 노출
- OCI 운영 배포 스크립트 및 문서
This commit is contained in:
user01
2026-10-26 00:52:53 +09:00
commit 46bc36a1f5
88 changed files with 11750 additions and 0 deletions
@@ -0,0 +1,201 @@
import type { Metadata } from "next";
import Link from "next/link";
import { ChevronDown, Mail, Phone, Trash2 } from "lucide-react";
import { deleteInquiryAction, updateInquiryStatusAction } from "@/actions/inquiries";
import { ConfirmForm } from "@/components/admin/confirm-form";
import { Pagination } from "@/components/site/pagination";
import { ADMIN_PAGE_SIZE, formatDateTime, INQUIRY_STATUSES } from "@/lib/constants";
import { prisma } from "@/lib/db";
export const metadata: Metadata = { title: "문의·제보 관리" };
export const dynamic = "force-dynamic";
type SearchParams = Promise<{
status?: string;
page?: string;
updated?: string;
deleted?: string;
error?: string;
}>;
const STATUS_STYLES: Record<string, string> = {
NEW: "bg-rose-50 text-rose-600",
IN_PROGRESS: "bg-amber-50 text-amber-700",
DONE: "bg-emerald-50 text-emerald-700",
};
export default async function AdminInquiriesPage({ searchParams }: { searchParams: SearchParams }) {
const params = await searchParams;
const status = ["NEW", "IN_PROGRESS", "DONE"].includes(params.status ?? "") ? params.status! : "";
const page = Math.max(1, Number.parseInt(params.page ?? "1", 10) || 1);
const where = status ? { status } : {};
const [total, inquiries, counts] = await Promise.all([
prisma.inquiry.count({ where }),
prisma.inquiry.findMany({
where,
orderBy: { createdAt: "desc" },
skip: (page - 1) * ADMIN_PAGE_SIZE,
take: ADMIN_PAGE_SIZE,
}),
prisma.inquiry.groupBy({ by: ["status"], _count: { _all: true } }),
]);
const countByStatus = Object.fromEntries(counts.map((row) => [row.status, row._count._all]));
const totalPages = Math.max(1, Math.ceil(total / ADMIN_PAGE_SIZE));
const notice = params.updated
? "문의 상태가 변경되었습니다."
: params.deleted
? "문의가 삭제되었습니다."
: "";
return (
<div className="space-y-5">
<div>
<h1 className="text-2xl font-black tracking-tight text-brand-950">문의·제보 관리</h1>
<p className="mt-1 text-sm text-slate-500">홈페이지를 통해 접수된 문의와 제보를 확인하고 처리 상태를 관리합니다.</p>
</div>
{params.error ? (
<p role="alert" className="rounded-xl bg-rose-50 px-4 py-3 text-sm font-semibold text-rose-700">
잘못된 요청입니다. 다시 시도해 주세요.
</p>
) : null}
{notice ? (
<p role="status" className="rounded-xl bg-emerald-50 px-4 py-3 text-sm font-semibold text-emerald-700">
{notice}
</p>
) : null}
<div className="flex flex-wrap items-center gap-2">
{[
{ value: "", label: "전체", count: Object.values(countByStatus).reduce((sum, value) => sum + value, 0) },
{ value: "NEW", label: "접수", count: countByStatus.NEW ?? 0 },
{ value: "IN_PROGRESS", label: "처리중", count: countByStatus.IN_PROGRESS ?? 0 },
{ value: "DONE", label: "완료", count: countByStatus.DONE ?? 0 },
].map((item) => (
<Link
key={item.value || "all"}
href={item.value ? `/admin/inquiries?status=${item.value}` : "/admin/inquiries"}
className={`rounded-full px-3.5 py-1.5 text-xs font-bold transition ${
status === item.value
? "bg-brand-900 text-white"
: "border border-slate-200 bg-white text-slate-600 hover:border-brand-200"
}`}
>
{item.label} {item.count.toLocaleString("ko-KR")}
</Link>
))}
</div>
<ul className="space-y-3">
{inquiries.map((inquiry) => (
<li key={inquiry.id} className="overflow-hidden rounded-xl border border-slate-200 bg-white">
<details className="group">
<summary className="flex cursor-pointer list-none items-start justify-between gap-3 px-5 py-4 [&::-webkit-details-marker]:hidden">
<div className="min-w-0">
<div className="flex flex-wrap items-center gap-2">
<span
className={`rounded-md px-2 py-0.5 text-[10px] font-bold ${
STATUS_STYLES[inquiry.status] ?? "bg-slate-100 text-slate-500"
}`}
>
{INQUIRY_STATUSES[inquiry.status as keyof typeof INQUIRY_STATUSES] ?? inquiry.status}
</span>
<span className="text-[11px] text-slate-400">#{inquiry.id}</span>
</div>
<p className="mt-2 truncate text-sm font-bold text-slate-700">{inquiry.title}</p>
<p className="mt-1 text-[11px] text-slate-400">
{inquiry.name} · {inquiry.email} · {formatDateTime(inquiry.createdAt)}
</p>
</div>
<ChevronDown
className="mt-1 h-4 w-4 shrink-0 text-slate-400 transition group-open:rotate-180"
aria-hidden
/>
</summary>
<div className="border-t border-slate-100 px-5 py-4">
<div className="flex flex-wrap gap-4 text-xs text-slate-500">
<span className="inline-flex items-center gap-1.5">
<Mail className="h-3.5 w-3.5" aria-hidden />
<a href={`mailto:${inquiry.email}`} className="hover:text-brand-700">
{inquiry.email}
</a>
</span>
{inquiry.phone ? (
<span className="inline-flex items-center gap-1.5">
<Phone className="h-3.5 w-3.5" aria-hidden />
<a href={`tel:${inquiry.phone}`} className="hover:text-brand-700">
{inquiry.phone}
</a>
</span>
) : null}
{inquiry.ip ? <span className="text-slate-400">IP {inquiry.ip}</span> : null}
</div>
<div className="mt-3 whitespace-pre-wrap rounded-lg bg-slate-50 px-4 py-3 text-sm leading-7 text-slate-700">
{inquiry.content}
</div>
<div className="mt-4 flex flex-wrap items-end justify-between gap-3">
<form action={updateInquiryStatusAction} className="flex items-end gap-2">
<input type="hidden" name="id" value={inquiry.id} />
<div>
<label htmlFor={`status-${inquiry.id}`} className="mb-1 block text-[11px] font-bold text-slate-500">
처리 상태
</label>
<select
id={`status-${inquiry.id}`}
name="status"
defaultValue={inquiry.status}
className="h-9 rounded-lg border border-slate-200 bg-white px-2.5 text-sm text-slate-700"
>
<option value="NEW">접수</option>
<option value="IN_PROGRESS">처리중</option>
<option value="DONE">완료</option>
</select>
</div>
<button
type="submit"
className="h-9 rounded-lg bg-brand-900 px-3.5 text-xs font-bold text-white transition hover:bg-brand-800"
>
상태 변경
</button>
</form>
<ConfirmForm action={deleteInquiryAction} message="이 문의를 삭제하시겠습니까? 삭제 후 복구할 수 없습니다.">
<input type="hidden" name="id" value={inquiry.id} />
<button
type="submit"
className="inline-flex h-9 items-center gap-1.5 rounded-lg border border-slate-200 px-3 text-xs font-bold text-slate-500 transition hover:border-rose-200 hover:text-rose-600"
>
<Trash2 className="h-3.5 w-3.5" aria-hidden />
삭제
</button>
</ConfirmForm>
</div>
</div>
</details>
</li>
))}
{inquiries.length === 0 ? (
<li className="rounded-xl border border-dashed border-slate-300 bg-white px-5 py-16 text-center text-sm text-slate-400">
접수된 문의가 없습니다.
</li>
) : null}
</ul>
<Pagination
currentPage={page}
totalPages={totalPages}
basePath="/admin/inquiries"
query={{ status: status || undefined }}
/>
</div>
);
}
+54
View File
@@ -0,0 +1,54 @@
import type { Metadata } from "next";
import Link from "next/link";
import { Menu } from "lucide-react";
import { AdminNav } from "@/components/admin/admin-nav";
import { requireAdmin } from "@/lib/auth";
export const metadata: Metadata = {
title: {
default: "관리자",
template: "%s | 관리자",
},
robots: { index: false, follow: false },
};
export const dynamic = "force-dynamic";
export default async function AdminDashboardLayout({ children }: { children: React.ReactNode }) {
const admin = await requireAdmin();
return (
<div className="min-h-screen bg-slate-100 lg:grid lg:grid-cols-[15rem_1fr]">
<aside className="hidden bg-brand-950 lg:sticky lg:top-0 lg:block lg:h-screen">
<AdminNav adminName={admin.name} loginId={admin.loginId} />
</aside>
<div className="min-w-0">
<header className="sticky top-0 z-30 border-b border-slate-200 bg-white lg:hidden">
<div className="flex items-center justify-between gap-3 px-4 py-3">
<Link href="/admin" className="flex items-center gap-2">
<span className="grid h-8 w-8 place-items-center rounded-lg bg-brand-900 text-[9px] font-black text-white">
용공협
</span>
<span className="text-sm font-bold text-brand-950">관리자</span>
</Link>
<details className="relative">
<summary className="flex h-9 w-9 cursor-pointer list-none items-center justify-center rounded-lg border border-slate-200 text-slate-600 [&::-webkit-details-marker]:hidden">
<Menu className="h-5 w-5" aria-hidden />
<span className="sr-only">관리자 메뉴 열기</span>
</summary>
<div className="absolute right-0 top-11 w-60 overflow-hidden rounded-xl border border-slate-200 bg-brand-950 shadow-2xl">
<AdminNav adminName={admin.name} loginId={admin.loginId} />
</div>
</details>
</div>
</header>
<main className="p-4 sm:p-6 lg:p-8">
<div className="mx-auto max-w-5xl">{children}</div>
</main>
</div>
</div>
);
}
+199
View File
@@ -0,0 +1,199 @@
import Link from "next/link";
import {
ArrowRight,
FileText,
FolderOpen,
MessageSquare,
Plus,
Settings,
} from "lucide-react";
import { formatDate, formatDateTime, INQUIRY_STATUSES } from "@/lib/constants";
import { prisma } from "@/lib/db";
import { getDashboardCounts } from "@/lib/posts";
export const dynamic = "force-dynamic";
export default async function AdminDashboardPage() {
const [counts, recentInquiries, recentPosts] = await Promise.all([
getDashboardCounts(),
prisma.inquiry.findMany({ orderBy: { createdAt: "desc" }, take: 5 }),
prisma.post.findMany({
orderBy: { createdAt: "desc" },
take: 6,
include: { author: { select: { name: true } } },
}),
]);
const stats = [
{
label: "공지사항",
value: counts.noticeCount,
href: "/admin/posts?type=NOTICE",
icon: FileText,
},
{
label: "자료실",
value: counts.archiveCount,
href: "/admin/posts?type=ARCHIVE",
icon: FolderOpen,
},
{
label: "새 문의",
value: counts.inquiryNew,
href: "/admin/inquiries?status=NEW",
icon: MessageSquare,
accent: counts.inquiryNew > 0,
},
{
label: "전체 문의",
value: counts.inquiryTotal,
href: "/admin/inquiries",
icon: MessageSquare,
},
];
return (
<div className="space-y-6">
<div className="flex flex-wrap items-end justify-between gap-3">
<div>
<h1 className="text-2xl font-black tracking-tight text-brand-950">대시보드</h1>
<p className="mt-1 text-sm text-slate-500">게시글과 문의 현황을 한눈에 확인하세요.</p>
</div>
<div className="flex gap-2">
<Link
href="/admin/posts/new?type=NOTICE"
className="inline-flex items-center gap-1.5 rounded-lg bg-brand-900 px-3.5 py-2 text-sm font-bold text-white transition hover:bg-brand-800"
>
<Plus className="h-4 w-4" aria-hidden />
새 공지
</Link>
<Link
href="/admin/posts/new?type=ARCHIVE"
className="inline-flex items-center gap-1.5 rounded-lg border border-slate-200 bg-white px-3.5 py-2 text-sm font-bold text-slate-600 transition hover:border-brand-200 hover:text-brand-800"
>
<Plus className="h-4 w-4" aria-hidden />
새 자료
</Link>
</div>
</div>
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
{stats.map((stat) => (
<Link
key={stat.label}
href={stat.href}
className={`rounded-xl border bg-white p-5 transition hover:border-brand-200 hover:shadow-sm ${
stat.accent ? "border-accent-300" : "border-slate-200"
}`}
>
<div className="flex items-center justify-between">
<span className="text-xs font-bold text-slate-500">{stat.label}</span>
<stat.icon className="h-4 w-4 text-brand-500" aria-hidden />
</div>
<p className="mt-2 text-3xl font-black text-brand-950">{stat.value.toLocaleString("ko-KR")}</p>
</Link>
))}
</div>
<div className="grid gap-5 lg:grid-cols-2">
<section className="min-w-0 overflow-hidden rounded-xl border border-slate-200 bg-white">
<div className="flex items-center justify-between border-b border-slate-100 px-5 py-4">
<h2 className="text-sm font-bold text-brand-950">최근 문의</h2>
<Link href="/admin/inquiries" className="inline-flex items-center gap-1 text-xs font-bold text-brand-700 hover:text-brand-500">
전체보기
<ArrowRight className="h-3.5 w-3.5" aria-hidden />
</Link>
</div>
<ul className="divide-y divide-slate-100">
{recentInquiries.map((inquiry) => (
<li key={inquiry.id} className="px-5 py-3.5">
<div className="flex items-center justify-between gap-3">
<p className="min-w-0 flex-1 truncate text-sm font-semibold text-slate-700">{inquiry.title}</p>
<span
className={`shrink-0 rounded-md px-2 py-0.5 text-[10px] font-bold ${
inquiry.status === "NEW"
? "bg-rose-50 text-rose-600"
: inquiry.status === "IN_PROGRESS"
? "bg-amber-50 text-amber-700"
: "bg-emerald-50 text-emerald-700"
}`}
>
{INQUIRY_STATUSES[inquiry.status as keyof typeof INQUIRY_STATUSES] ?? inquiry.status}
</span>
</div>
<p className="mt-1 text-[11px] text-slate-400">
{inquiry.name} · {formatDateTime(inquiry.createdAt)}
</p>
</li>
))}
{recentInquiries.length === 0 ? (
<li className="px-5 py-10 text-center text-sm text-slate-400">접수된 문의가 없습니다.</li>
) : null}
</ul>
</section>
<section className="min-w-0 overflow-hidden rounded-xl border border-slate-200 bg-white">
<div className="flex items-center justify-between border-b border-slate-100 px-5 py-4">
<h2 className="text-sm font-bold text-brand-950">최근 게시글</h2>
<Link href="/admin/posts" className="inline-flex items-center gap-1 text-xs font-bold text-brand-700 hover:text-brand-500">
전체보기
<ArrowRight className="h-3.5 w-3.5" aria-hidden />
</Link>
</div>
<ul className="divide-y divide-slate-100">
{recentPosts.map((post) => (
<li key={post.id} className="px-5 py-3.5">
<div className="flex items-center justify-between gap-3">
<Link
href={`/admin/posts/${post.id}/edit`}
className="min-w-0 flex-1 truncate text-sm font-semibold text-slate-700 hover:text-brand-800"
>
{post.title}
</Link>
<span className="shrink-0 rounded-md bg-slate-100 px-2 py-0.5 text-[10px] font-bold text-slate-500">
{post.type === "NOTICE" ? "공지" : "자료"}
</span>
</div>
<p className="mt-1 text-[11px] text-slate-400">
{post.status === "DRAFT" ? "임시저장 · " : ""}
{formatDate(post.publishedAt)} · {post.author?.name ?? "관리자"}
</p>
</li>
))}
{recentPosts.length === 0 ? (
<li className="px-5 py-10 text-center text-sm text-slate-400">등록된 게시글이 없습니다.</li>
) : null}
</ul>
</section>
</div>
<section className="rounded-xl border border-slate-200 bg-white p-5">
<h2 className="text-sm font-bold text-brand-950">빠른 작업</h2>
<div className="mt-3 grid gap-2 sm:grid-cols-3">
<Link
href="/admin/posts/new?type=NOTICE"
className="flex items-center gap-2 rounded-lg border border-slate-200 px-3 py-2.5 text-sm font-semibold text-slate-600 transition hover:border-brand-200 hover:text-brand-800"
>
<FileText className="h-4 w-4" aria-hidden />
공지사항 작성
</Link>
<Link
href="/admin/posts/new?type=ARCHIVE"
className="flex items-center gap-2 rounded-lg border border-slate-200 px-3 py-2.5 text-sm font-semibold text-slate-600 transition hover:border-brand-200 hover:text-brand-800"
>
<FolderOpen className="h-4 w-4" aria-hidden />
자료실 자료 등록
</Link>
<Link
href="/admin/settings"
className="flex items-center gap-2 rounded-lg border border-slate-200 px-3 py-2.5 text-sm font-semibold text-slate-600 transition hover:border-brand-200 hover:text-brand-800"
>
<Settings className="h-4 w-4" aria-hidden />
사이트 정보 수정
</Link>
</div>
</section>
</div>
);
}
@@ -0,0 +1,107 @@
import type { Metadata } from "next";
import Link from "next/link";
import { notFound } from "next/navigation";
import { ArrowLeft, ExternalLink } from "lucide-react";
import { updatePostAction } from "@/actions/posts";
import { PostForm } from "@/components/admin/post-form";
import { formatDateTime } from "@/lib/constants";
import { prisma } from "@/lib/db";
export const metadata: Metadata = { title: "게시글 수정" };
export const dynamic = "force-dynamic";
type Params = Promise<{ id: string }>;
type SearchParams = Promise<{ error?: string; deletedAttachment?: string }>;
export default async function EditPostPage({
params,
searchParams,
}: {
params: Params;
searchParams: SearchParams;
}) {
const [{ id }, query] = await Promise.all([params, searchParams]);
const postId = Number(id);
if (!Number.isInteger(postId) || postId <= 0) notFound();
const post = await prisma.post.findUnique({
where: { id: postId },
include: { attachments: { orderBy: { id: "asc" } } },
});
if (!post) notFound();
const type = post.type === "ARCHIVE" ? "ARCHIVE" : "NOTICE";
const typeLabel = type === "NOTICE" ? "공지사항" : "자료실";
const publicHref = type === "NOTICE" ? `/news/notice/${post.id}` : `/archive/${post.id}`;
return (
<div className="space-y-5">
<div className="flex flex-wrap items-end justify-between gap-3">
<div>
<Link
href={`/admin/posts?type=${type}`}
className="inline-flex items-center gap-1.5 text-xs font-bold text-slate-500 transition hover:text-brand-700"
>
<ArrowLeft className="h-3.5 w-3.5" aria-hidden />
게시글 목록
</Link>
<h1 className="mt-3 text-2xl font-black tracking-tight text-brand-950">게시글 수정</h1>
<p className="mt-1 text-xs text-slate-400">
{typeLabel} · #{post.id} · 최종 수정 {formatDateTime(post.updatedAt)}
</p>
</div>
{post.status === "PUBLISHED" ? (
<Link
href={publicHref}
target="_blank"
rel="noreferrer"
className="inline-flex items-center gap-1.5 rounded-lg border border-slate-200 bg-white px-3.5 py-2 text-sm font-bold text-slate-600 transition hover:border-brand-200 hover:text-brand-800"
>
<ExternalLink className="h-4 w-4" aria-hidden />
사이트에서 보기
</Link>
) : (
<span className="rounded-lg border border-slate-200 bg-slate-50 px-3.5 py-2 text-sm font-semibold text-slate-400">
임시저장 상태 (공개되지 않음)
</span>
)}
</div>
{query.error ? (
<p role="alert" className="rounded-xl bg-rose-50 px-4 py-3 text-sm font-semibold text-rose-700">
{query.error}
</p>
) : null}
{query.deletedAttachment ? (
<p role="status" className="rounded-xl bg-emerald-50 px-4 py-3 text-sm font-semibold text-emerald-700">
첨부파일이 삭제되었습니다.
</p>
) : null}
<PostForm
action={updatePostAction}
defaultType={type}
submitLabel="수정 내용 저장"
cancelHref={`/admin/posts?type=${type}`}
post={{
id: post.id,
type: post.type,
category: post.category,
title: post.title,
content: post.content,
isPinned: post.isPinned,
status: post.status,
attachments: post.attachments.map((attachment) => ({
id: attachment.id,
originalName: attachment.originalName,
size: attachment.size,
})),
}}
/>
</div>
);
}
@@ -0,0 +1,46 @@
import type { Metadata } from "next";
import Link from "next/link";
import { ArrowLeft } from "lucide-react";
import { createPostAction } from "@/actions/posts";
import { PostForm } from "@/components/admin/post-form";
export const metadata: Metadata = { title: "새 게시글" };
export const dynamic = "force-dynamic";
type SearchParams = Promise<{ type?: string; error?: string }>;
export default async function NewPostPage({ searchParams }: { searchParams: SearchParams }) {
const params = await searchParams;
const type = params.type === "ARCHIVE" ? "ARCHIVE" : "NOTICE";
const typeLabel = type === "NOTICE" ? "공지사항" : "자료실";
return (
<div className="space-y-5">
<div>
<Link
href={`/admin/posts?type=${type}`}
className="inline-flex items-center gap-1.5 text-xs font-bold text-slate-500 transition hover:text-brand-700"
>
<ArrowLeft className="h-3.5 w-3.5" aria-hidden />
게시글 목록
</Link>
<h1 className="mt-3 text-2xl font-black tracking-tight text-brand-950">{typeLabel} 작성</h1>
<p className="mt-1 text-sm text-slate-500">제목과 내용을 입력하고 첨부파일을 등록하세요.</p>
</div>
{params.error ? (
<p role="alert" className="rounded-xl bg-rose-50 px-4 py-3 text-sm font-semibold text-rose-700">
{params.error}
</p>
) : null}
<PostForm
action={createPostAction}
defaultType={type}
submitLabel="게시글 등록"
cancelHref={`/admin/posts?type=${type}`}
/>
</div>
);
}
+230
View File
@@ -0,0 +1,230 @@
import type { Metadata } from "next";
import Link from "next/link";
import { Eye, Paperclip, Pencil, Pin, Plus, Search, Trash2 } from "lucide-react";
import { deletePostAction } from "@/actions/posts";
import { ConfirmForm } from "@/components/admin/confirm-form";
import { Pagination } from "@/components/site/pagination";
import { ADMIN_PAGE_SIZE, formatDate } from "@/lib/constants";
import { prisma } from "@/lib/db";
export const metadata: Metadata = { title: "게시글 관리" };
export const dynamic = "force-dynamic";
type SearchParams = Promise<{
type?: string;
page?: string;
q?: string;
status?: string;
created?: string;
updated?: string;
deleted?: string;
error?: string;
}>;
export default async function AdminPostsPage({ searchParams }: { searchParams: SearchParams }) {
const params = await searchParams;
const type = params.type === "ARCHIVE" ? "ARCHIVE" : "NOTICE";
const page = Math.max(1, Number.parseInt(params.page ?? "1", 10) || 1);
const query = (params.q ?? "").trim();
const status = ["PUBLISHED", "DRAFT"].includes(params.status ?? "") ? params.status! : "";
const where = {
type,
...(status ? { status } : {}),
...(query ? { OR: [{ title: { contains: query } }, { content: { contains: query } }] } : {}),
};
const [total, posts] = await Promise.all([
prisma.post.count({ where }),
prisma.post.findMany({
where,
orderBy: [{ isPinned: "desc" }, { publishedAt: "desc" }, { id: "desc" }],
skip: (page - 1) * ADMIN_PAGE_SIZE,
take: ADMIN_PAGE_SIZE,
include: {
author: { select: { name: true } },
_count: { select: { attachments: true } },
},
}),
]);
const totalPages = Math.max(1, Math.ceil(total / ADMIN_PAGE_SIZE));
const typeLabel = type === "NOTICE" ? "공지사항" : "자료실";
const basePath = "/admin/posts";
const listQuery = { type, q: query || undefined, status: status || undefined };
const notice = params.created
? "게시글이 등록되었습니다."
: params.updated
? "게시글이 수정되었습니다."
: params.deleted
? "게시글이 삭제되었습니다."
: "";
return (
<div className="space-y-5">
<div className="flex flex-wrap items-end justify-between gap-3">
<div>
<h1 className="text-2xl font-black tracking-tight text-brand-950">게시글 관리</h1>
<p className="mt-1 text-sm text-slate-500">공지사항과 자료실 게시글을 작성·수정·삭제합니다.</p>
</div>
<Link
href={`/admin/posts/new?type=${type}`}
className="inline-flex items-center gap-1.5 rounded-lg bg-brand-900 px-3.5 py-2 text-sm font-bold text-white transition hover:bg-brand-800"
>
<Plus className="h-4 w-4" aria-hidden />
{typeLabel} 작성
</Link>
</div>
{params.error ? (
<p role="alert" className="rounded-xl bg-rose-50 px-4 py-3 text-sm font-semibold text-rose-700">
{params.error}
</p>
) : null}
{notice ? (
<p role="status" className="rounded-xl bg-emerald-50 px-4 py-3 text-sm font-semibold text-emerald-700">
{notice}
</p>
) : null}
<div className="flex flex-wrap items-center justify-between gap-3">
<div className="inline-flex rounded-xl border border-slate-200 bg-white p-1">
{(["NOTICE", "ARCHIVE"] as const).map((item) => (
<Link
key={item}
href={`/admin/posts?type=${item}`}
className={`rounded-lg px-3.5 py-1.5 text-sm font-bold transition ${
type === item ? "bg-brand-900 text-white" : "text-slate-500 hover:text-brand-800"
}`}
>
{item === "NOTICE" ? "공지사항" : "자료실"}
</Link>
))}
</div>
<form action={basePath} method="get" className="flex flex-wrap items-center gap-2">
<input type="hidden" name="type" value={type} />
<select
name="status"
defaultValue={status}
className="h-9 rounded-lg border border-slate-200 bg-white px-2.5 text-sm text-slate-600"
aria-label="공개 상태"
>
<option value="">전체 상태</option>
<option value="PUBLISHED">공개</option>
<option value="DRAFT">임시저장</option>
</select>
<div className="relative">
<input
name="q"
defaultValue={query}
placeholder="제목·내용 검색"
className="h-9 w-52 rounded-lg border border-slate-200 bg-white pl-8 pr-3 text-sm text-slate-700 placeholder:text-slate-400"
aria-label="검색어"
/>
<Search className="pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-slate-400" aria-hidden />
</div>
<button
type="submit"
className="h-9 rounded-lg bg-slate-900 px-3 text-sm font-bold text-white transition hover:bg-slate-700"
>
검색
</button>
</form>
</div>
<p className="text-sm text-slate-500">
전체 <span className="font-bold text-brand-800">{total.toLocaleString("ko-KR")}</span>건
</p>
<div className="overflow-hidden rounded-xl border border-slate-200 bg-white">
<div className="overflow-x-auto">
<table className="w-full min-w-[46rem] border-collapse text-left text-sm">
<caption className="sr-only">{typeLabel} 게시글 목록</caption>
<thead>
<tr className="border-b border-slate-200 bg-slate-50 text-xs font-bold text-slate-500">
<th scope="col" className="w-16 px-4 py-3">번호</th>
<th scope="col" className="w-20 px-4 py-3">분류</th>
<th scope="col" className="px-4 py-3">제목</th>
<th scope="col" className="w-20 px-4 py-3">상태</th>
<th scope="col" className="w-28 px-4 py-3">작성일</th>
<th scope="col" className="w-24 px-4 py-3 text-right">관리</th>
</tr>
</thead>
<tbody className="divide-y divide-slate-100">
{posts.map((post) => (
<tr key={post.id} className="align-middle hover:bg-slate-50/70">
<td className="px-4 py-3 text-xs text-slate-400">{post.id}</td>
<td className="px-4 py-3">
<span className="inline-flex items-center gap-1 rounded-md bg-slate-100 px-2 py-0.5 text-[11px] font-bold text-slate-600">
{post.isPinned ? <Pin className="h-3 w-3 text-accent-600" aria-hidden /> : null}
{post.category || "미분류"}
</span>
</td>
<td className="px-4 py-3">
<Link href={`/admin/posts/${post.id}/edit`} className="line-clamp-1 font-semibold text-slate-700 hover:text-brand-800">
{post.title}
</Link>
<span className="mt-0.5 flex items-center gap-3 text-[11px] text-slate-400">
<span className="inline-flex items-center gap-1">
<Eye className="h-3 w-3" aria-hidden />
{post.viewCount.toLocaleString("ko-KR")}
</span>
<span className="inline-flex items-center gap-1">
<Paperclip className="h-3 w-3" aria-hidden />
{post._count.attachments}
</span>
<span>{post.author?.name ?? "관리자"}</span>
</span>
</td>
<td className="px-4 py-3">
<span
className={`rounded-md px-2 py-0.5 text-[11px] font-bold ${
post.status === "PUBLISHED" ? "bg-emerald-50 text-emerald-700" : "bg-slate-100 text-slate-500"
}`}
>
{post.status === "PUBLISHED" ? "공개" : "임시저장"}
</span>
</td>
<td className="px-4 py-3 text-xs text-slate-400">{formatDate(post.publishedAt)}</td>
<td className="px-4 py-3">
<div className="flex items-center justify-end gap-1">
<Link
href={`/admin/posts/${post.id}/edit`}
className="grid h-8 w-8 place-items-center rounded-lg border border-slate-200 text-slate-500 transition hover:border-brand-200 hover:text-brand-700"
aria-label={`${post.title} 수정`}
>
<Pencil className="h-3.5 w-3.5" aria-hidden />
</Link>
<ConfirmForm action={deletePostAction} message={`"${post.title}" 게시글을 삭제하시겠습니까?`}>
<input type="hidden" name="id" value={post.id} />
<button
type="submit"
className="grid h-8 w-8 place-items-center rounded-lg border border-slate-200 text-slate-400 transition hover:border-rose-200 hover:text-rose-600"
aria-label={`${post.title} 삭제`}
>
<Trash2 className="h-3.5 w-3.5" aria-hidden />
</button>
</ConfirmForm>
</div>
</td>
</tr>
))}
{posts.length === 0 ? (
<tr>
<td colSpan={6} className="px-4 py-14 text-center text-sm text-slate-400">
{query ? "검색 결과가 없습니다." : `등록된 ${typeLabel} 게시글이 없습니다.`}
</td>
</tr>
) : null}
</tbody>
</table>
</div>
</div>
<Pagination currentPage={page} totalPages={totalPages} basePath={basePath} query={listQuery} />
</div>
);
}
+161
View File
@@ -0,0 +1,161 @@
import type { Metadata } from "next";
import { Save } from "lucide-react";
import { updateSettingsAction } from "@/actions/settings";
import { getSettings } from "@/lib/settings";
export const metadata: Metadata = { title: "사이트 설정" };
export const dynamic = "force-dynamic";
type SearchParams = Promise<{ saved?: string; error?: string }>;
const inputClass =
"h-11 w-full rounded-lg border border-slate-200 bg-white px-3.5 text-sm text-slate-800 placeholder:text-slate-400 focus:border-brand-400 focus:outline-none";
const labelClass = "mb-1.5 block text-xs font-bold text-slate-600";
export default async function AdminSettingsPage({ searchParams }: { searchParams: SearchParams }) {
const [params, settings] = await Promise.all([searchParams, getSettings()]);
return (
<div className="space-y-5">
<div>
<h1 className="text-2xl font-black tracking-tight text-brand-950">사이트 설정</h1>
<p className="mt-1 text-sm text-slate-500">
홈페이지 상단·하단에 표시되는 사이트 정보와 외부 링크를 관리합니다.
</p>
</div>
{params.error ? (
<p role="alert" className="rounded-xl bg-rose-50 px-4 py-3 text-sm font-semibold text-rose-700">
{params.error}
</p>
) : null}
{params.saved ? (
<p role="status" className="rounded-xl bg-emerald-50 px-4 py-3 text-sm font-semibold text-emerald-700">
설정이 저장되었습니다. 홈페이지에 바로 반영됩니다.
</p>
) : null}
<form action={updateSettingsAction} className="space-y-5">
<section className="grid gap-4 rounded-xl border border-slate-200 bg-white p-5 sm:grid-cols-2">
<div className="sm:col-span-2">
<h2 className="text-sm font-bold text-brand-950">기본 정보</h2>
<p className="mt-1 text-xs text-slate-400">사이트 이름은 헤더·푸터·검색 결과에 사용됩니다.</p>
</div>
<div>
<label htmlFor="siteName" className={labelClass}>
사이트 이름
</label>
<input id="siteName" name="siteName" required defaultValue={settings.siteName} maxLength={100} className={inputClass} />
</div>
<div>
<label htmlFor="shortName" className={labelClass}>
약칭
</label>
<input id="shortName" name="shortName" required defaultValue={settings.shortName} maxLength={30} className={inputClass} />
</div>
<div className="sm:col-span-2">
<label htmlFor="description" className={labelClass}>
사이트 설명
</label>
<textarea
id="description"
name="description"
rows={3}
defaultValue={settings.description}
maxLength={300}
className="w-full resize-y rounded-lg border border-slate-200 bg-white px-3.5 py-3 text-sm leading-6 text-slate-800 focus:border-brand-400 focus:outline-none"
/>
</div>
<div className="sm:col-span-2">
<label htmlFor="footerText" className={labelClass}>
푸터 문구
</label>
<input id="footerText" name="footerText" defaultValue={settings.footerText} maxLength={300} className={inputClass} />
</div>
</section>
<section className="grid gap-4 rounded-xl border border-slate-200 bg-white p-5 sm:grid-cols-2">
<div className="sm:col-span-2">
<h2 className="text-sm font-bold text-brand-950">연락처</h2>
<p className="mt-1 text-xs text-slate-400">입력한 정보는 푸터와 문의·제보 페이지에 표시됩니다.</p>
</div>
<div>
<label htmlFor="contactPhone" className={labelClass}>
전화번호
</label>
<input
id="contactPhone"
name="contactPhone"
defaultValue={settings.contactPhone}
maxLength={50}
placeholder="02-000-0000"
className={inputClass}
/>
</div>
<div>
<label htmlFor="contactEmail" className={labelClass}>
이메일
</label>
<input
id="contactEmail"
name="contactEmail"
type="email"
defaultValue={settings.contactEmail}
maxLength={200}
placeholder="contact@example.com"
className={inputClass}
/>
</div>
<div className="sm:col-span-2">
<label htmlFor="address" className={labelClass}>
주소
</label>
<input id="address" name="address" defaultValue={settings.address} maxLength={200} className={inputClass} />
</div>
</section>
<section className="grid gap-4 rounded-xl border border-slate-200 bg-white p-5">
<div>
<h2 className="text-sm font-bold text-brand-950">외부 링크</h2>
<p className="mt-1 text-xs text-slate-400">
조사 현황 지도와 네이버 블로그 주소입니다. 2차 지도 통합 전까지 기존 지도 주소를 사용합니다.
</p>
</div>
<div>
<label htmlFor="mapUrl" className={labelClass}>
조사 현황 지도 URL
</label>
<input id="mapUrl" name="mapUrl" type="url" required defaultValue={settings.mapUrl} maxLength={300} className={inputClass} />
</div>
<div>
<label htmlFor="blogUrl" className={labelClass}>
네이버 블로그 URL
</label>
<input id="blogUrl" name="blogUrl" type="url" required defaultValue={settings.blogUrl} maxLength={300} className={inputClass} />
</div>
</section>
<div className="flex justify-end">
<button
type="submit"
className="inline-flex items-center gap-2 rounded-lg bg-brand-900 px-5 py-2.5 text-sm font-bold text-white transition hover:bg-brand-800"
>
<Save className="h-4 w-4" aria-hidden />
설정 저장
</button>
</div>
</form>
</div>
);
}
+50
View File
@@ -0,0 +1,50 @@
import type { Metadata } from "next";
import Link from "next/link";
import { redirect } from "next/navigation";
import { ArrowLeft, ShieldCheck } from "lucide-react";
import { LoginForm } from "@/components/admin/login-form";
import { getSession } from "@/lib/auth";
export const metadata: Metadata = {
title: "관리자 로그인",
robots: { index: false, follow: false },
};
export const dynamic = "force-dynamic";
export default async function AdminLoginPage() {
const session = await getSession();
if (session) redirect("/admin");
return (
<main className="grid min-h-screen place-items-center bg-brand-950 px-4 py-12">
<div className="w-full max-w-sm">
<div className="mb-6 text-center">
<span className="mx-auto grid h-12 w-12 place-items-center rounded-2xl bg-white/10 text-[11px] font-black text-white">
용공협
</span>
<h1 className="mt-4 text-xl font-black tracking-tight text-white">관리자 로그인</h1>
<p className="mt-2 flex items-center justify-center gap-1.5 text-xs text-slate-400">
<ShieldCheck className="h-3.5 w-3.5" aria-hidden />
허가된 관리자만 접속할 수 있습니다.
</p>
</div>
<div className="rounded-2xl border border-white/10 bg-white p-6 shadow-2xl">
<LoginForm />
</div>
<div className="mt-5 text-center">
<Link
href="/"
className="inline-flex items-center gap-1.5 text-xs font-semibold text-slate-400 transition hover:text-white"
>
<ArrowLeft className="h-3.5 w-3.5" aria-hidden />
홈페이지로 돌아가기
</Link>
</div>
</div>
</main>
);
}