>[] = SUMMARY_COLUMNS.map((key) => ({
+ key,
+ header: getSummaryColumnLabel(key),
+ headerClassName: key === "-1" || SUMMARY_CATEGORY_KEYS.includes(key as (typeof SUMMARY_CATEGORY_KEYS)[number])
+ ? "bg-summary"
+ : undefined,
+ align: "center",
+ }));
+ const categories = SUMMARY_COLUMNS.map(getSummaryColumnLabel);
+
+ const rows: TopChartTableRow[] =
+ selectedWaves.length === 0 || currentWave == null
+ ? []
+ : [
+ {
+ label: "응답건수",
+ values: SUMMARY_COLUMNS.map((key) => getSummarySampleCount(data, getSummaryDataKey(key), currentWave)),
+ preAppendCells: [
+ {
+ content: "",
+ width: 140,
+ className: "kfpa-table-border-none bg-transparent",
+ },
+ ],
+ labelClassName: "bg-gray-300 text-center font-bold",
+ cellClassName: "bg-gray-300",
+ labelWidth: 90,
+ decimalPlaces: 0,
+ },
+ {
+ label: GAP_WORDING,
+ values: SUMMARY_COLUMNS.map((key) =>
+ getSummaryGapValue(data, getSummaryDataKey(key), selectedWaves[0], currentWave)
+ ),
+ preAppendCells: [
+ {
+ content: DASHBOARD_METRIC_GROUP_LABEL_MAP.csi,
+ rowSpan: selectedWaves.length + 1,
+ width: 140,
+ className: "bg-csi text-center align-middle font-bold content-text-base",
+ },
+ ],
+ labelClassName: "bg-csi text-center font-bold",
+ labelWidth: 80,
+ },
+ ...selectedWaves.map((wave) => ({
+ label: getWaveLabel(wave),
+ values: SUMMARY_COLUMNS.map((key) => getSummaryCsiValue(data, getSummaryDataKey(key), wave)),
+ labelClassName: "bg-csi text-center font-bold",
+ labelWidth: 80,
+ })),
+ ];
+
+ const chartData: ChartData = {
+ categories,
+ series: selectedWaves.map((wave) => ({
+ name: getWaveLabel(wave),
+ data: SUMMARY_COLUMNS.map((key) => getSummaryCsiValue(data, getSummaryDataKey(key), wave) ?? null),
+ })),
+ };
+
+ return {
+ columns,
+ categories,
+ rows,
+ chartData,
+ };
+ }, [data]);
+
+ if (isLoading) {
+ return 데이터를 불러오는 중입니다.
;
+ }
+
+ if (isError) {
+ return 고객만족도 데이터를 불러오지 못했습니다.
;
+ }
+
+ if (rows.length === 0) {
+ return 표시할 고객만족도 데이터가 없습니다.
;
+ }
+
+ return (
+
+ value.toFixed(CUSTOMER_SATISFACTION_DECIMAL_PLACES)}
+ barMaxWidth={30}
+ showFocusLabel="all"
+ labelOptions={{ position: "top", distance: 4 }}
+ grid={{ left: 0, right: 0, top: 40, bottom: 5 }}
+ xAxis={{
+ type: "category",
+ data: categories,
+ axisLabel: { show: false },
+ axisTick: { show: false },
+ axisLine: { show: false },
+ }}
+ yAxis={{
+ type: "value",
+ min: 4,
+ max: 5,
+ axisLabel: { show: false },
+ axisTick: { show: false },
+ axisLine: { show: false },
+ splitLine: { show: false },
+ }}
+ />
+ }
+ />
+
+
+
+ );
+};
+
+export default CustomerSatisfactionSummary;
diff --git a/src/components/kfpa/CustomerSatisfactionTotal.tsx b/src/components/kfpa/CustomerSatisfactionTotal.tsx
new file mode 100644
index 0000000..a9ffaae
--- /dev/null
+++ b/src/components/kfpa/CustomerSatisfactionTotal.tsx
@@ -0,0 +1,244 @@
+"use client";
+
+import { useCallback, useMemo } from "react";
+import type { ChartData } from "@/components/chart/types";
+import TopChartTable from "@/components/combo/TopChartTable";
+import type { TopChartTableRow } from "@/components/combo/types";
+import { cn } from "@/lib/utils";
+import { useCsiDataQuery } from "@/query/statistics";
+import type { DashboardMetricConfig, DashboardMetricGroup } from "@/types/kfpa";
+import VerticalBar from "@/components/chart/VerticalBar";
+import type { DataColumn } from "@/components/table/types";
+import { GAP_WORDING } from "@/const/kfpa.const";
+import {
+ CUSTOMER_SATISFACTION_GAP_SIGN_STYLE,
+ DASHBOARD_METRIC_GROUP_LABEL_MAP,
+ DASHBOARD_TOTAL_TITLE_BY_CATEGORY,
+ REGION_KEY_MAP,
+ getDashboardMetricConfigs,
+ getDashboardTotalColumnEntries,
+ getDashboardTotalTableLayout,
+} from "@/config/kfpaConfig";
+import type { DashboardTotalTableLayout } from "@/config/kfpaConfig";
+import { useLayoutFilter } from "@/components/layout/LayoutCategoryContext";
+import {
+ getCsiDataByWave,
+ getCsiMetricGapValue,
+ getCsiMetricValue,
+ getWaveLabel,
+} from "@/lib/kfpa-util";
+
+const getGroupMetricCount = (metrics: readonly DashboardMetricConfig[], group: DashboardMetricGroup) =>
+ metrics.filter((metric) => metric.group === group).length;
+
+const isFirstMetricInGroup = (
+ metrics: readonly DashboardMetricConfig[],
+ metricIndex: number,
+ group: DashboardMetricGroup
+) => metrics.findIndex((metric) => metric.group === group) === metricIndex;
+
+const getPreAppendCells = (
+ metrics: readonly DashboardMetricConfig[],
+ metric: DashboardMetricConfig,
+ metricIndex: number,
+ waveIndex: number,
+ rowCountPerMetric: number,
+ tableLayout: DashboardTotalTableLayout
+): TopChartTableRow["preAppendCells"] => {
+ if (waveIndex !== 0) return undefined;
+
+ if (metric.group === "csi") {
+ return [
+ {
+ content: DASHBOARD_METRIC_GROUP_LABEL_MAP.csi,
+ colSpan: 2,
+ rowSpan: rowCountPerMetric,
+ width: tableLayout.csiLabelWidth,
+ className: "bg-csi text-center align-middle font-bold content-text-base",
+ },
+ ];
+ }
+
+ const cells: TopChartTableRow["preAppendCells"] = [];
+
+ if (isFirstMetricInGroup(metrics, metricIndex, metric.group)) {
+ cells.push({
+ content: DASHBOARD_METRIC_GROUP_LABEL_MAP[metric.group],
+ rowSpan: rowCountPerMetric * getGroupMetricCount(metrics, metric.group),
+ width: tableLayout.groupLabelWidth,
+ className: cn(`bg-${metric.group}`, "text-center align-middle font-bold content-text-base"),
+ });
+ }
+
+ cells.push({
+ content: metric.label,
+ rowSpan: rowCountPerMetric,
+ width: tableLayout.metricLabelWidth,
+ className: cn(`bg-${metric.group}`, "whitespace-pre-wrap text-left align-middle font-bold content-text-base"),
+ });
+
+ return cells;
+};
+
+const CustomerSatisfactionTotal = () => {
+ const { selectMenu, statisticsParams } = useLayoutFilter();
+ const categoryKey = statisticsParams.pkey;
+ const { data, isLoading, isError } = useCsiDataQuery(statisticsParams);
+ const metrics = useMemo(() => getDashboardMetricConfigs(categoryKey), [categoryKey]);
+ const tableLayout = useMemo(() => getDashboardTotalTableLayout(categoryKey), [categoryKey]);
+ const divisionColumns = useMemo(
+ () =>
+ getDashboardTotalColumnEntries(categoryKey).map(([key, label]) => ({
+ key,
+ label: key === "-1" ? label : REGION_KEY_MAP[key] ?? label,
+ })),
+ [categoryKey]
+ );
+
+ const { categoryColumns, categories, rows, verticalChartData } = useMemo(() => {
+ const waves = Array.from(
+ new Set(
+ Object.values(data ?? {})
+ .flat()
+ .map((item) => item.wave)
+ .filter((wave) => Number.isFinite(wave))
+ )
+ ).sort((a, b) => a - b);
+
+ const latestWave = waves.at(-1);
+ const selectedWaves = latestWave == null ? [] : [latestWave - 1, latestWave];
+ const categoryColumns: DataColumn>[] = divisionColumns.map((div) => ({
+ key: div.key,
+ header: div.label,
+ headerClassName: div.key === "-1" && div.label ? "bg-summary" : undefined,
+ align: "center",
+ }));
+ const categories = divisionColumns.map((div) => div.label);
+
+ const rows: TopChartTableRow[] =
+ selectedWaves.length === 0
+ ? []
+ : metrics.flatMap((metric, metricIndex) =>
+ [
+ {
+ label: GAP_WORDING,
+ values: divisionColumns.map((div) =>
+ getCsiMetricGapValue(data, div.key, selectedWaves[0], selectedWaves[1], metric.key)
+ ),
+ },
+ ...selectedWaves.map((wave) => ({
+ label: getWaveLabel(wave),
+ values: divisionColumns.map((div) => getCsiMetricValue(data, div.key, wave, metric.key)),
+ })),
+ ].map((row, rowIndex) => ({
+ ...row,
+ preAppendCells: getPreAppendCells(
+ metrics,
+ metric,
+ metricIndex,
+ rowIndex,
+ selectedWaves.length + 1,
+ tableLayout
+ ),
+ labelClassName: cn(`bg-${metric.group}`, "text-center", row.label !== GAP_WORDING && "font-bold"),
+ labelWidth: tableLayout.waveLabelWidth,
+ }))
+ );
+
+ const verticalChartData: ChartData = {
+ categories,
+ series: selectedWaves.map((wave) => ({
+ name: getWaveLabel(wave),
+ data: divisionColumns.map((div) => getCsiDataByWave(data, div.key, wave)?.csi ?? 0),
+ })),
+ };
+
+ return {
+ categoryColumns,
+ categories,
+ rows,
+ verticalChartData,
+ };
+ }, [data, divisionColumns, metrics, tableLayout]);
+
+ const handleChartClick = useCallback(
+ (params: unknown) => {
+ if (divisionColumns.length <= 1) return;
+
+ const dataIndex = typeof params === "object" && params !== null && "dataIndex" in params
+ ? Number((params as { dataIndex?: unknown }).dataIndex)
+ : NaN;
+ const divKey = divisionColumns[dataIndex]?.key;
+
+ if (divKey && divKey !== "-1") {
+ selectMenu(divKey);
+ }
+ },
+ [divisionColumns, selectMenu]
+ );
+
+ if (isLoading) {
+ return 데이터를 불러오는 중입니다.
;
+ }
+
+ if (isError) {
+ return 고객만족도 데이터를 불러오지 못했습니다.
;
+ }
+
+ if (rows.length === 0) {
+ return 표시할 고객만족도 데이터가 없습니다.
;
+ }
+
+ return (
+
+ 1 ? 1120 : 900}
+ maxWidth={tableLayout.tableWidth}
+ chartHeight={200}
+ chart={
+ value.toFixed(2)}
+ barMaxWidth={30}
+ showFocusLabel="all"
+ labelOptions={{ position: "top", distance: 4 }}
+ grid={{ left: 0, right: 0, top: 40, bottom: 5 }}
+ xAxis={{
+ type: "category",
+ data: categories,
+ axisLabel: { show: false },
+ axisTick: { show: false },
+ axisLine: { show: false },
+ }}
+ yAxis={{
+ type: "value",
+ min: 4,
+ max: 5,
+ axisLabel: { show: false },
+ axisTick: { show: false },
+ axisLine: { show: false },
+ splitLine: { show: false },
+ }}
+ onEvents={{ click: handleChartClick }}
+ />
+ }
+ />
+
+ );
+};
+
+export default CustomerSatisfactionTotal;
diff --git a/src/components/layout/Footer.tsx b/src/components/layout/Footer.tsx
new file mode 100644
index 0000000..a47c05c
--- /dev/null
+++ b/src/components/layout/Footer.tsx
@@ -0,0 +1,24 @@
+import Image from "next/image";
+
+const Footer = () => {
+ return (
+
+ );
+};
+
+export default Footer;
diff --git a/src/components/layout/Header.tsx b/src/components/layout/Header.tsx
index e5f2af2..a63c744 100644
--- a/src/components/layout/Header.tsx
+++ b/src/components/layout/Header.tsx
@@ -11,7 +11,9 @@ import {usePathname} from "next/navigation";
interface HeaderProps {
topMenus: TopMenuItem[];
userName: string;
+ isAdmin: boolean;
isAuthenticated: boolean;
+ baseDateLabel: string;
onNavigate: (path: string) => void;
onLogin: () => void;
onLogout: () => void;
@@ -20,7 +22,9 @@ interface HeaderProps {
const Header = ({
topMenus,
userName,
+ isAdmin,
isAuthenticated,
+ baseDateLabel,
onNavigate,
onLogin,
onLogout,
@@ -29,71 +33,74 @@ const Header = ({
return (
-
-
-
+
+
+
-
-
+
-
+
{SITE_TITLE}
-
- {
- /* 클라이언트 요청으로 로그인 제외
- {isAuthenticated && (
-
- {userName}
-
- )}
-
- */
- }
+
+ {isAdmin && (
+ <>
+
+ {userName}
+
+
+ >
+ )}
+
+
+
+ {baseDateLabel}
diff --git a/src/components/layout/LayoutCategoryContext.tsx b/src/components/layout/LayoutCategoryContext.tsx
index fbe4d5c..951f745 100644
--- a/src/components/layout/LayoutCategoryContext.tsx
+++ b/src/components/layout/LayoutCategoryContext.tsx
@@ -2,11 +2,14 @@
import React, { createContext, useCallback, useContext, useMemo, useRef } from "react";
import {DivKey} from "@/types/kfpa";
+import type {StatisticsQueryParams} from "@/query/statistics";
type ExcelExporter = (ctx: DivKey) => void | Promise
;
type LayoutCategoryContextValue = {
selectedDiv: DivKey;
+ statisticsParams: StatisticsQueryParams;
+ selectMenu: (menuId: string) => void;
registerExcelExporter: (exporter: ExcelExporter | null) => void;
requestExcelExport: () => Promise;
};
@@ -15,9 +18,13 @@ const LayoutCategoryContext = createContext(n
export const LayoutCategoryProvider = ({
selectedDiv,
+ statisticsParams,
+ onSelectMenu,
children,
}: {
selectedDiv: DivKey;
+ statisticsParams: StatisticsQueryParams;
+ onSelectMenu: (menuId: string) => void;
children: React.ReactNode;
}) => {
const exporterRef = useRef(null);
@@ -38,10 +45,12 @@ export const LayoutCategoryProvider = ({
const ctxValue = useMemo(
() => ({
selectedDiv,
+ statisticsParams,
+ selectMenu: onSelectMenu,
registerExcelExporter,
requestExcelExport,
}),
- [selectedDiv, registerExcelExporter, requestExcelExport]
+ [selectedDiv, statisticsParams, onSelectMenu, registerExcelExporter, requestExcelExport]
);
return {children};
diff --git a/src/components/layout/MainLayout.tsx b/src/components/layout/MainLayout.tsx
index ff66f47..c6121d2 100644
--- a/src/components/layout/MainLayout.tsx
+++ b/src/components/layout/MainLayout.tsx
@@ -1,18 +1,20 @@
"use client"
-import {ReactNode, useEffect, useState} from "react";
-import {useRouter, useSearchParams} from "next/navigation";
+import {ReactNode, useEffect, useMemo, useRef, useState} from "react";
+import {usePathname, useRouter, useSearchParams} from "next/navigation";
import {DivKey} from "@/types/kfpa";
import {useAuth} from "@/hooks/useAuth";
import {LayoutCategoryProvider} from "./LayoutCategoryContext";
import Header from "@/components/layout/Header";
import {useMounted} from "@/hooks/useMounted";
import {Sidebar} from "@/components/layout/Sidebar";
-import {TOP_MENUS, SIDE_MENUS} from "@/config/menu.data";
+import {TOP_MENUS, SIDE_MENUS_BY_TOP_MENU} from "@/config/menu.data";
import {useLogoutMutation} from "@/query/auth";
import {useDialog} from "@/hooks/useDialog";
import LoginDialog from "@/components/dialog/loginDialog";
import { appendAdminRouteParam, hasAdminRouteParam } from "@/lib/admin-route";
+import {useLayoutSelectedMenu} from "@/hooks/useLayoutSelectedMenu";
+import Footer from "@/components/layout/Footer";
type MainLayoutProps = {
children: ReactNode;
@@ -22,17 +24,63 @@ const getDivKey = () => {
return "-1";
}
+const padDatePart = (value: number) => String(value).padStart(2, "0");
+
+const formatStatisticsDt = (date: Date) =>
+ [
+ date.getFullYear(),
+ padDatePart(date.getMonth() + 1),
+ padDatePart(date.getDate()),
+ padDatePart(date.getHours()),
+ padDatePart(date.getMinutes()),
+ padDatePart(date.getSeconds()),
+ ].join("");
+
+const formatBaseDateLabel = (date: Date) =>
+ `최종 업데이트 일시 : ${String(date.getFullYear()).slice(-2)}년 ${date.getMonth() + 1}월 ${date.getDate()}일 ${padDatePart(date.getHours())}시 ${padDatePart(date.getMinutes())}분`;
+
const MainLayout = ({ children }: MainLayoutProps) => {
const { auth, logout } = useAuth();
const { showDialog } = useDialog();
const logoutMutation = useLogoutMutation();
const router = useRouter();
+ const pathname = usePathname();
const searchParams = useSearchParams();
const isMounted = useMounted();
+ const { selectedMenusByTopMenu, selectMenu } = useLayoutSelectedMenu();
+ const previousTopMenuIdRef = useRef(null);
const [menuOpen, setMenuOpen] = useState(true);
- const [selectedDiv, setSelectedDiv] = useState(getDivKey());
+ const [dataBaseDate, setDataBaseDate] = useState(() => new Date());
const isRouteAdmin = hasAdminRouteParam(searchParams);
+ const activeTopMenu = useMemo(
+ () => TOP_MENUS.find((topMenu) => topMenu.match?.(pathname) ?? pathname === topMenu.path) ?? TOP_MENUS[0],
+ [pathname]
+ );
+ const activeTopMenuId = activeTopMenu?.id ?? "";
+ const shouldShowFooter = activeTopMenuId === "-1";
+ const sideMenus = useMemo(
+ () => SIDE_MENUS_BY_TOP_MENU[activeTopMenuId] ?? [],
+ [activeTopMenuId]
+ );
+ const selectedMenuId = useMemo(() => {
+ if (!sideMenus.length) return getDivKey();
+
+ const storedMenuId = activeTopMenuId ? selectedMenusByTopMenu[activeTopMenuId] : undefined;
+ if (storedMenuId && sideMenus.some((menu) => menu.id === storedMenuId)) {
+ return storedMenuId;
+ }
+
+ return sideMenus[0].id;
+ }, [activeTopMenuId, selectedMenusByTopMenu, sideMenus]);
+ const statisticsParams = useMemo(
+ () => ({
+ pkey: activeTopMenuId,
+ dt: formatStatisticsDt(dataBaseDate),
+ }),
+ [activeTopMenuId, dataBaseDate]
+ );
+ const baseDateLabel = useMemo(() => formatBaseDateLabel(dataBaseDate), [dataBaseDate]);
const movePage = (path: string) => {
router.push(appendAdminRouteParam(path, searchParams));
@@ -46,6 +94,11 @@ const MainLayout = ({ children }: MainLayoutProps) => {
logoutMutation.mutate();
};
+ const handleSelectMenu = (menuId: string) => {
+ if (!activeTopMenuId) return;
+ selectMenu(activeTopMenuId, menuId);
+ };
+
useEffect(() => {
const handleAuthExpired = () => {
logout();
@@ -55,30 +108,59 @@ const MainLayout = ({ children }: MainLayoutProps) => {
return () => window.removeEventListener("auth:expired", handleAuthExpired);
}, [logout]);
+ useEffect(() => {
+ if (!activeTopMenuId) return;
+
+ setDataBaseDate(new Date());
+ }, [activeTopMenuId, selectedMenuId]);
+
+ useEffect(() => {
+ if (!activeTopMenuId) return;
+
+ if (previousTopMenuIdRef.current === null) {
+ previousTopMenuIdRef.current = activeTopMenuId;
+ return;
+ }
+
+ if (previousTopMenuIdRef.current === activeTopMenuId) return;
+
+ previousTopMenuIdRef.current = activeTopMenuId;
+ selectMenu(activeTopMenuId, getDivKey());
+ }, [activeTopMenuId, selectMenu]);
+
if(!isMounted) return null;
return (
-
+
-
+
-
diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx
index 04bcf0d..8249c91 100644
--- a/src/components/layout/Sidebar.tsx
+++ b/src/components/layout/Sidebar.tsx
@@ -2,20 +2,19 @@
import { cn } from "@/lib/utils";
import {SideMenuItem} from "@/config/menu.type";
-import {DivKey} from "@/types/kfpa";
interface SidebarProps {
sideMenus: SideMenuItem[];
isOpen: boolean;
- selectedDiv: DivKey;
- onChangeDiv: (div: DivKey) => void;
+ selectedMenuId: string;
+ onChangeMenu: (menuId: string) => void;
}
export const Sidebar = ({
sideMenus,
isOpen,
- selectedDiv,
- onChangeDiv,
+ selectedMenuId,
+ onChangeMenu,
}: SidebarProps) => {
const activeMenuClassName =
"text-foreground bg-muted shadow-[inset_4px_0_0_#ed1c24]";
@@ -35,13 +34,13 @@ export const Sidebar = ({