Files
frontend/apps/cm/src/pages/dashboard/ui/notice-list.tsx
T

74 lines
2.3 KiB
TypeScript

"use client";
import { useRouter } from "next/navigation";
import { useQuery } from "@tanstack/react-query";
import { getCoreRowModel } from "@tanstack/react-table";
import { PostApi, type NoticePost } from "@/entities/post";
import { ENDPOINT } from "@/shared/config";
import { useDataTable } from "@/shared/lib";
import {
noticePostTableColumns,
} from "../model/table-columns";
import { Button } from "@common/components";
import { useDragHandle } from "./sortable-panel";
const NoticeList: React.FC = () => {
const { dragHandleProps, isDragging } = useDragHandle();
const router = useRouter();
const noticePostQuery = useQuery({
queryKey: [ENDPOINT.BOARD_SERVICE.POSTS],
queryFn: () =>
PostApi.getNoticePostList({
page: 0,
size: 3,
keywordType: "bbsTypeCd",
keyword: "BBSNOTICE",
}),
});
const handleNoticePostRowClick = (row: NoticePost) => {
router.push(`/cms/${row.bbsTypeCd.toLowerCase()}/${row.bbsId}/${row.pstNo}`);
};
const handleMoreClick = () => {
try {
router.push('/cms/bbsnotice/7');
} catch (error) {
console.error("공지사항 더보기 이동 실패", error);
}
};
const { tableComponent: noticePostTableComponent } = useDataTable({
query: noticePostQuery,
tableOptions: {
columns: noticePostTableColumns,
getCoreRowModel: getCoreRowModel(),
},
dataTableOptions: {
variant: "line",
onRowClick: handleNoticePostRowClick,
},
});
return (
<div className="card card-border !p-0" style={{ height: "220px" }}>
<div
className={`card-header !m-0 !border-none text-foreground cursor-grab active:cursor-grabbing ${isDragging ? 'opacity-50' : ''}`}
{...dragHandleProps}
title="헤더를 드래그하여 패널 순서 변경"
>
<h3 className="text-2xl font-medium">공지사항</h3>
<div
onPointerDown={(e) => e.stopPropagation()}
onClick={(e) => e.stopPropagation()}
>
<Button className="h-[3.2rem]" onClick={handleMoreClick}>더보기</Button>
</div>
</div>
{noticePostTableComponent}
</div>
);
};
export default NoticeList;