'use client' import {useLayoutFilter} from "@/components/layout/LayoutFilterContext"; import { apiPurchaseChannelByYear, apiPurchaseChannelSummaryByYear } from "@/config/sample.data"; import {useEffect, useMemo} from "react"; import {PageData, ServerBannerRow} from "@/types/lg"; import {CategoryByData} from "@/components/lge-dashboard"; import {BANNER_GROUP, BANNER_KEY_MAP, SITE_TITLE, YEARS} from "@/const/lgConst"; import {CategoryTypeValue} from "@/components/layout/CategoryFilter"; import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel"; const PurchaseChannel = () => { const { filterValue, registerExcelExporter } = useLayoutFilter(); console.log(filterValue); const tableDataArray = useMemo[]>(() => [ { title: "구매 채널(온/오프라인)", chartMode: "reverseStack", data: apiPurchaseChannelSummaryByYear, }, { title: "구매 채널(상세)", chartMode: "horizontal", data: apiPurchaseChannelByYear, chartHeight: 550, }, ], []); useEffect(() => { registerExcelExporter(async (payload) => { const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_구매 채널` const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP); type AnyRow = Record; const sections: Section[] = tableDataArray.flatMap((tableData) => { const years = [YEARS.at(-1), YEARS.at(-2)]; return years.map((year) => ({ title: `${tableData.title}_${year}년`, header: h3, rows: tableData.data.filter((d) => d.year === year) as AnyRow[], rowGap: 1, })); }); await exportDashboardExcel({ fileName: `${SITE_TITLE}(${sheetName}).xlsx`, sheetName: sheetName, sections: sections, }); }); return () => registerExcelExporter(null); }, [registerExcelExporter]); return (
{tableDataArray.map((tableData) => ( ))}
); } export default PurchaseChannel;