70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { getCoreRowModel } from "@tanstack/react-table";
|
|
import { ENDPOINT } from "@/shared/config";
|
|
import { useDataTable } from "@/shared/lib";
|
|
import {
|
|
scheduleTableColumns,
|
|
} from "../model/table-columns";
|
|
import { getScheduleList } from "../api/schedule-service";
|
|
|
|
// 날짜를 YYYY-MM-DD 형식으로 포맷팅
|
|
const formatDate = (date: Date): string => {
|
|
const year = date.getFullYear();
|
|
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
const day = String(date.getDate()).padStart(2, "0");
|
|
return `${year}-${month}-${day}`;
|
|
};
|
|
|
|
// 오늘부터 한 달 후까지의 날짜 계산
|
|
const getDateRange = () => {
|
|
const today = new Date();
|
|
const oneMonthLater = new Date();
|
|
oneMonthLater.setMonth(today.getMonth() + 1);
|
|
|
|
return {
|
|
startDate: formatDate(today),
|
|
endDate: formatDate(oneMonthLater),
|
|
};
|
|
};
|
|
|
|
const ScheduleList: React.FC = () => {
|
|
const router = useRouter();
|
|
const { startDate, endDate } = getDateRange();
|
|
|
|
const scheduleQuery = useQuery({
|
|
queryKey: [ENDPOINT.BOARD_SERVICE.POSTS, startDate, endDate],
|
|
queryFn: () =>
|
|
getScheduleList({
|
|
siteId: "",
|
|
schdlTtl: "",
|
|
schdlSeCd: "",
|
|
schdlBgngYmd: startDate,
|
|
schdlEndYmd: endDate,
|
|
reptYn: "",
|
|
commSchdlYn: "Y",
|
|
}),
|
|
});
|
|
|
|
|
|
const { tableComponent: scheduleTableComponent } = useDataTable({
|
|
query: scheduleQuery,
|
|
tableOptions: {
|
|
columns: scheduleTableColumns,
|
|
getCoreRowModel: getCoreRowModel(),
|
|
},
|
|
dataTableOptions: {
|
|
variant: "line",
|
|
},
|
|
});
|
|
|
|
return (
|
|
<div className="card card-border !p-0" style={{ height: "300px" }}>
|
|
{scheduleTableComponent}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ScheduleList; |