260515_01_ENH: 클라이언트 수정사항 반영 및 다른 조사들 data 연결
This commit is contained in:
177
src/components/kfpa/CustomerSatisfactionSummary.tsx
Normal file
177
src/components/kfpa/CustomerSatisfactionSummary.tsx
Normal file
@@ -0,0 +1,177 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import type { ChartData } from "@/components/chart/types";
|
||||
import TopChartTable from "@/components/combo/TopChartTable";
|
||||
import type { TopChartTableRow } from "@/components/combo/types";
|
||||
import VerticalBar from "@/components/chart/VerticalBar";
|
||||
import type { DataColumn } from "@/components/table/types";
|
||||
import { GAP_WORDING } from "@/const/kfpa.const";
|
||||
import {
|
||||
CUSTOMER_SATISFACTION_DECIMAL_PLACES,
|
||||
CUSTOMER_SATISFACTION_GAP_SIGN_STYLE,
|
||||
DASHBOARD_METRIC_GROUP_LABEL_MAP,
|
||||
DASHBOARD_TOTAL_TITLE_BY_CATEGORY, getDashboardTotalTableLayout,
|
||||
} from "@/config/kfpaConfig";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutCategoryContext";
|
||||
import { useCsiSummaryQuery } from "@/query/statistics";
|
||||
import {
|
||||
getSummaryColumnLabel,
|
||||
getSummaryCsiValue,
|
||||
getSummaryDataKey,
|
||||
getSummaryGapValue,
|
||||
getSummarySampleCount,
|
||||
getWaveLabel,
|
||||
} from "@/lib/kfpa-util";
|
||||
import CsiFormulaNote from "@/components/kfpa/CsiFormulaNote";
|
||||
|
||||
const SUMMARY_REGION_KEYS = ["-1", "1", "3", "2", "5", "6", "4"] as const;
|
||||
const SUMMARY_CATEGORY_KEYS = ["2604005_E", "2604005_D", "2604005_C", "2604005_A", "2604005_B"] as const;
|
||||
const SUMMARY_COLUMNS = [...SUMMARY_REGION_KEYS, ...SUMMARY_CATEGORY_KEYS] as const;
|
||||
|
||||
const CustomerSatisfactionSummary = () => {
|
||||
const { statisticsParams } = useLayoutFilter();
|
||||
const { data, isLoading, isError } = useCsiSummaryQuery({ dt: statisticsParams.dt });
|
||||
const tableLayout = useMemo(() => getDashboardTotalTableLayout("-1"), ["-1"]);
|
||||
|
||||
const { columns, categories, rows, chartData } = 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 currentWave = selectedWaves.at(-1);
|
||||
|
||||
const columns: DataColumn<Record<string, unknown>>[] = 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 <div className="content-text-sm text-muted-foreground">데이터를 불러오는 중입니다.</div>;
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return <div className="content-text-sm text-destructive">고객만족도 데이터를 불러오지 못했습니다.</div>;
|
||||
}
|
||||
|
||||
if (rows.length === 0) {
|
||||
return <div className="content-text-sm text-muted-foreground">표시할 고객만족도 데이터가 없습니다.</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
<TopChartTable
|
||||
title={DASHBOARD_TOTAL_TITLE_BY_CATEGORY["-1"] ?? "화재보험협회 주요 고객 만족도"}
|
||||
columns={columns}
|
||||
rows={rows}
|
||||
signStyle={CUSTOMER_SATISFACTION_GAP_SIGN_STYLE}
|
||||
minWidth={tableLayout.tableWidth}
|
||||
maxWidth={tableLayout.tableWidth}
|
||||
chartHeight={180}
|
||||
chart={
|
||||
<VerticalBar
|
||||
data={chartData}
|
||||
height="100%"
|
||||
paletteVarNames={["--chart-5", "--chart-7"]}
|
||||
valueFormatter={(value) => 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 },
|
||||
}}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
|
||||
<CsiFormulaNote />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default CustomerSatisfactionSummary;
|
||||
Reference in New Issue
Block a user