Compare commits
10 Commits
d1b2dce9ee
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fcf8c805f6 | |||
| ea5d1744a7 | |||
| 7fe713e299 | |||
| 5502415825 | |||
| 85f2b99345 | |||
| 32758f32d3 | |||
| 632b4d3de4 | |||
| e55ba7ac01 | |||
| 5e53663b24 | |||
| 24d917ac7b |
@@ -2,4 +2,5 @@ NEXT_PUBLIC_ENV=prod
|
||||
NEXT_PUBLIC_API_BASE=https://test-kfpa-dash.kric.com/api
|
||||
|
||||
ENV=prod
|
||||
API_BACK_SERVER=http://127.0.0.1:6103/api/v1
|
||||
API_BACK_SERVER=http://127.0.0.1:6103/api/v1
|
||||
IP_WHITELIST=127.0.0.1,::1,211.37.10.198,211.254.145.130,1.235.195.3
|
||||
@@ -2,4 +2,5 @@ NEXT_PUBLIC_ENV=local
|
||||
NEXT_PUBLIC_API_BASE=http://localhost:6102/api
|
||||
|
||||
ENV=local
|
||||
API_BACK_SERVER=http://localhost:6103/api/v1
|
||||
API_BACK_SERVER=http://localhost:6103/api/v1
|
||||
IP_WHITELIST=127.0.0.1,::1
|
||||
@@ -2,4 +2,5 @@ NEXT_PUBLIC_ENV=prod
|
||||
NEXT_PUBLIC_API_BASE=https://kfpa-dash.kric.com/api
|
||||
|
||||
ENV=prod
|
||||
API_BACK_SERVER=http://127.0.0.1:6103/api/v1
|
||||
API_BACK_SERVER=http://127.0.0.1:6103/api/v1
|
||||
IP_WHITELIST=127.0.0.1,::1,211.37.10.198,211.254.145.130,1.235.195.3
|
||||
@@ -14,6 +14,7 @@ const BridgePlatformPage = () => {
|
||||
selectedDiv={selectedDiv}
|
||||
viewSubTitle={false}
|
||||
sectionTitleSuffix={COMMENT_TABLE_TITLE}
|
||||
widthClassName="w-[1200px]"
|
||||
/>;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import CustomerSatisfactionDetail from "@/components/kfpa/CustomerSatisfactionDe
|
||||
const ConsultingPage = () => {
|
||||
const { selectedDiv } = useLayoutFilter();
|
||||
|
||||
return selectedDiv === "-1" ? <CustomerSatisfactionTotal /> : <CustomerSatisfactionDetail selectedDiv={selectedDiv} />;
|
||||
return selectedDiv === "-1" ? <CustomerSatisfactionTotal /> : <CustomerSatisfactionDetail selectedDiv={selectedDiv} widthClassName="w-[1200px]"/>;
|
||||
};
|
||||
|
||||
export default ConsultingPage;
|
||||
|
||||
@@ -7,7 +7,7 @@ import CustomerSatisfactionDetail from "@/components/kfpa/CustomerSatisfactionDe
|
||||
const FireInvestigationPage = () => {
|
||||
const { selectedDiv } = useLayoutFilter();
|
||||
|
||||
return selectedDiv === "-1" ? <CustomerSatisfactionTotal /> : <CustomerSatisfactionDetail selectedDiv={selectedDiv} />;
|
||||
return selectedDiv === "-1" ? <CustomerSatisfactionTotal /> : <CustomerSatisfactionDetail selectedDiv={selectedDiv} widthClassName="w-[1200px]"/>;
|
||||
};
|
||||
|
||||
export default FireInvestigationPage;
|
||||
|
||||
@@ -7,7 +7,7 @@ import CustomerSatisfactionDetail from "@/components/kfpa/CustomerSatisfactionDe
|
||||
const InsuranceOperationsPage = () => {
|
||||
const { selectedDiv } = useLayoutFilter();
|
||||
|
||||
return selectedDiv === "-1" ? <CustomerSatisfactionTotal /> : <CustomerSatisfactionDetail selectedDiv={selectedDiv} />;
|
||||
return selectedDiv === "-1" ? <CustomerSatisfactionTotal /> : <CustomerSatisfactionDetail selectedDiv={selectedDiv} widthClassName="w-[1200px]"/>;
|
||||
};
|
||||
|
||||
export default InsuranceOperationsPage;
|
||||
|
||||
@@ -7,7 +7,12 @@ import CustomerSatisfactionDetail from "@/components/kfpa/CustomerSatisfactionDe
|
||||
const SafetyInspectionPage = () => {
|
||||
const { selectedDiv } = useLayoutFilter();
|
||||
|
||||
return selectedDiv === "-1" ? <CustomerSatisfactionTotal /> : <CustomerSatisfactionDetail selectedDiv={selectedDiv} />;
|
||||
return selectedDiv === "-1"
|
||||
? <CustomerSatisfactionTotal />
|
||||
: <CustomerSatisfactionDetail
|
||||
selectedDiv={selectedDiv}
|
||||
//widthClassName="w-[1553px]"
|
||||
/>;
|
||||
};
|
||||
|
||||
export default SafetyInspectionPage;
|
||||
|
||||
@@ -14,6 +14,7 @@ const UcisPage = () => {
|
||||
selectedDiv={selectedDiv}
|
||||
viewSubTitle={false}
|
||||
sectionTitleSuffix={COMMENT_TABLE_TITLE}
|
||||
widthClassName="w-[1200px]"
|
||||
/>;
|
||||
};
|
||||
|
||||
|
||||
21
src/app/403/page.tsx
Normal file
21
src/app/403/page.tsx
Normal file
@@ -0,0 +1,21 @@
|
||||
import type { Metadata } from "next";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "403 Forbidden",
|
||||
};
|
||||
|
||||
const ForbiddenPage = () => {
|
||||
return (
|
||||
<main className="flex min-h-dvh items-center justify-center bg-background px-6">
|
||||
<section className="w-full max-w-md border border-border bg-card p-8 text-center shadow-sm">
|
||||
<p className="text-sm font-semibold text-primary">403</p>
|
||||
<h1 className="mt-3 text-2xl font-bold text-foreground">외부에서 접속할 수 없습니다.</h1>
|
||||
<p className="mt-4 text-sm leading-6 text-muted-foreground">
|
||||
해당 사이트는 외부의 접근을 허용하지 않습니다.
|
||||
</p>
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
};
|
||||
|
||||
export default ForbiddenPage;
|
||||
@@ -122,6 +122,8 @@
|
||||
--kfpa-red-100: #f2a8b5;
|
||||
--kfpa-red-50: #fae6ea;
|
||||
|
||||
--kfpa-null: #9a9a9a;
|
||||
|
||||
/* =============================
|
||||
Surface
|
||||
============================= */
|
||||
@@ -357,6 +359,7 @@
|
||||
.border-border { border-color: var(--border); }
|
||||
|
||||
.text-zero { color: var(--kfpa-black-150) !important; }
|
||||
.text-null { color: var(--kfpa-null) !important; }
|
||||
|
||||
/* KFPA neutral scale */
|
||||
.bg-black-600 { background-color: var(--kfpa-black-600) !important; }
|
||||
@@ -410,6 +413,7 @@
|
||||
.bg-csi { background-color: var(--kfpa-csi) !important; }
|
||||
.bg-direct { background-color: var(--kfpa-direct) !important; }
|
||||
.bg-indirect { background-color: var(--kfpa-indirect) !important; }
|
||||
.bg-null { background-color: var(--kfpa-null) !important; }
|
||||
|
||||
/* =============================
|
||||
Content Text Size Utilities
|
||||
@@ -599,10 +603,11 @@
|
||||
|
||||
.kfpa-detail-table {
|
||||
--kfpa-detail-table-head-height: 56px;
|
||||
--kfpa-detail-table-row-height: 56px;
|
||||
--kfpa-detail-comment-table-row-height: 112px;
|
||||
}
|
||||
|
||||
.kfpa-detail-rank-table {
|
||||
--kfpa-detail-table-row-height: 56px;
|
||||
min-width: 285px !important;
|
||||
}
|
||||
|
||||
@@ -618,6 +623,7 @@
|
||||
}
|
||||
|
||||
.kfpa-detail-comment-table tbody td {
|
||||
min-height: var(--kfpa-detail-comment-table-row-height);
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,8 +15,8 @@ const geistMono = Geist_Mono({
|
||||
});
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "화재보험협회 대시보드",
|
||||
description: "화재보험협회 CX 대시보드",
|
||||
title: "고객 관점 성과관리 대시보드",
|
||||
description: "고객 관점 성과관리 대시보드",
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
|
||||
@@ -35,9 +35,52 @@ type Props = {
|
||||
position?: "top" | "insideTop" | "right" | "insideRight";
|
||||
color?: string;
|
||||
distance?: number;
|
||||
minPositionValue?: number;
|
||||
};
|
||||
};
|
||||
|
||||
type ChartCallbackParam = {
|
||||
data?: unknown;
|
||||
value?: unknown;
|
||||
axisValueLabel?: string;
|
||||
name?: string;
|
||||
marker?: string;
|
||||
seriesName?: string;
|
||||
};
|
||||
|
||||
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
||||
typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
|
||||
const toChartCallbackParam = (value: unknown): ChartCallbackParam =>
|
||||
isRecord(value) ? value : {};
|
||||
|
||||
const getActualValue = (param: unknown) => {
|
||||
const data = toChartCallbackParam(param).data;
|
||||
|
||||
if (isRecord(data) && "actualValue" in data) {
|
||||
return data.actualValue;
|
||||
}
|
||||
|
||||
return toChartCallbackParam(param).value;
|
||||
};
|
||||
|
||||
const createLabelPositionTooltip = (fmt: ValueFormatter): EChartsOption["tooltip"] => ({
|
||||
trigger: "axis",
|
||||
axisPointer: { type: "shadow" },
|
||||
formatter: (params: unknown) => {
|
||||
const items = (Array.isArray(params) ? params : [params]).map(toChartCallbackParam);
|
||||
const title = items[0]?.axisValueLabel ?? items[0]?.name ?? "";
|
||||
const lines = items.map((item) => {
|
||||
const value = getActualValue(item);
|
||||
const text = typeof value === "number" ? fmt(value) : value == null ? "-" : String(value);
|
||||
|
||||
return `${item.marker ?? ""}${item.seriesName} ${text}`;
|
||||
});
|
||||
|
||||
return [title, ...lines].join("<br/>");
|
||||
},
|
||||
});
|
||||
|
||||
const VerticalBar = ({
|
||||
data,
|
||||
height,
|
||||
@@ -58,21 +101,31 @@ const VerticalBar = ({
|
||||
|
||||
const option: EChartsOption = useMemo(() => {
|
||||
const fmt = valueFormatter ?? ((v: number) => String(v));
|
||||
const minPositionValue = labelOptions?.minPositionValue;
|
||||
|
||||
return {
|
||||
color: palette,
|
||||
tooltip: tooltip ?? createDefaultTooltip(fmt),
|
||||
tooltip: tooltip ?? (typeof minPositionValue === "number" ? createLabelPositionTooltip(fmt) : createDefaultTooltip(fmt)),
|
||||
legend: legend ?? createDefaultLegend(),
|
||||
grid: grid ?? createDefaultGrid(),
|
||||
xAxis: xAxis ?? createCategoryAxis(data.categories, false, { axisTick: { alignWithLabel: true } }),
|
||||
yAxis: yAxis ?? createValueAxis(),
|
||||
series: data.series.map((s, index) => {
|
||||
const showLabel = getIsShowLabel(showFocusLabel, index, data.series.length);
|
||||
const seriesData = s.data.map((value) =>
|
||||
typeof minPositionValue === "number" &&
|
||||
typeof value === "number" &&
|
||||
Number.isFinite(value) &&
|
||||
value > 0.00 &&
|
||||
value < minPositionValue
|
||||
? { value: minPositionValue, actualValue: value }
|
||||
: value
|
||||
);
|
||||
|
||||
return {
|
||||
name: s.name,
|
||||
type: "bar",
|
||||
data: s.data,
|
||||
data: seriesData,
|
||||
emphasis: { disabled: true },
|
||||
barMaxWidth: barMaxWidth ?? BAR_WIDTHS.DEFAULT,
|
||||
label: showLabel
|
||||
@@ -81,7 +134,10 @@ const VerticalBar = ({
|
||||
position: labelOptions?.position ?? "right",
|
||||
color: labelOptions?.color,
|
||||
distance: labelOptions?.distance,
|
||||
formatter: (p: any) => (typeof p?.value === "number" ? fmt(p.value) : (p?.value ?? "")) as any,
|
||||
formatter: (p: unknown) => {
|
||||
const value = getActualValue(p);
|
||||
return typeof value === "number" ? fmt(value) : value == null ? "" : String(value);
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
}
|
||||
|
||||
@@ -1,301 +1,310 @@
|
||||
"use client";
|
||||
|
||||
import React, { useMemo } from "react";
|
||||
import { cn, parseNumber } from "@/lib/utils";
|
||||
import React, {useMemo} from "react";
|
||||
import {cn, parseNumber} from "@/lib/utils";
|
||||
import BaseTableHeader from "../table/core/BaseTableHeader";
|
||||
import {
|
||||
formatSignedValue, getSignTextClass,
|
||||
resolveSignStyle,
|
||||
toCssSize,
|
||||
toRoundedNumber
|
||||
formatSignedValue, getSignTextClass,
|
||||
resolveSignStyle,
|
||||
toCssSize,
|
||||
toRoundedNumber
|
||||
} from "../table/core/table-core.helpers";
|
||||
import {
|
||||
TopChartTablePreAppendCell,
|
||||
TopChartTablePreAppendCellConfig,
|
||||
TopChartTableRow,
|
||||
TopChartTableSectionRow
|
||||
TopChartTablePreAppendCell,
|
||||
TopChartTablePreAppendCellConfig,
|
||||
TopChartTableRow,
|
||||
TopChartTableSectionRow
|
||||
} from "./types";
|
||||
import {ChartData} from "../chart/types";
|
||||
import {CHART_HEIGHTS, TABLE_DIMENSIONS} from "../chart/chart.config";
|
||||
import type {DataColumn, SignStyle} from "@/components/table/types";
|
||||
import { KFPA_DECIMAL_POINT } from "@/config/kfpa.config";
|
||||
import {KFPA_DECIMAL_POINT} from "@/config/kfpa.config";
|
||||
|
||||
export type TopChartTableProps = {
|
||||
title?: string;
|
||||
columns: DataColumn<Record<string, unknown>>[];
|
||||
rows: TopChartTableRow[];
|
||||
sectionRows?: TopChartTableSectionRow[];
|
||||
chart?:
|
||||
| React.ReactNode
|
||||
| ((ctx: {
|
||||
chartData: ChartData;
|
||||
}) => React.ReactNode);
|
||||
chartHeight?: number | string;
|
||||
minWidthPx?: number;
|
||||
minWidth?: number;
|
||||
maxWidth?: number;
|
||||
subLabelHeader?: string;
|
||||
rowHeaderWidth?: number | string;
|
||||
categoryColumnWidth?: number | string;
|
||||
categoryColumnWidths?: Array<number | string | undefined>;
|
||||
tableClassName?: string;
|
||||
wrapperClassName?: string;
|
||||
signStyle?: SignStyle<TopChartTableRow>;
|
||||
title?: string;
|
||||
columns: DataColumn<Record<string, unknown>>[];
|
||||
rows: TopChartTableRow[];
|
||||
sectionRows?: TopChartTableSectionRow[];
|
||||
chart?:
|
||||
| React.ReactNode
|
||||
| ((ctx: {
|
||||
chartData: ChartData;
|
||||
}) => React.ReactNode);
|
||||
chartHeight?: number | string;
|
||||
minWidthPx?: number;
|
||||
minWidth?: number;
|
||||
maxWidth?: number;
|
||||
subLabelHeader?: string;
|
||||
rowHeaderWidth?: number | string;
|
||||
categoryColumnWidth?: number | string;
|
||||
categoryColumnWidths?: Array<number | string | undefined>;
|
||||
tableClassName?: string;
|
||||
wrapperClassName?: string;
|
||||
signStyle?: SignStyle<TopChartTableRow>;
|
||||
};
|
||||
|
||||
const isPreAppendCellConfig = (
|
||||
cell: TopChartTablePreAppendCell
|
||||
cell: TopChartTablePreAppendCell
|
||||
): cell is TopChartTablePreAppendCellConfig =>
|
||||
typeof cell === "object" &&
|
||||
cell !== null &&
|
||||
!Array.isArray(cell) &&
|
||||
"content" in cell;
|
||||
typeof cell === "object" &&
|
||||
cell !== null &&
|
||||
!Array.isArray(cell) &&
|
||||
"content" in cell;
|
||||
|
||||
const renderPreAppendCell = (cell: TopChartTablePreAppendCell, index: number) => {
|
||||
if (!isPreAppendCellConfig(cell)) {
|
||||
return <td key={`pre-append-${index}`}>{cell}</td>;
|
||||
}
|
||||
if (!isPreAppendCellConfig(cell)) {
|
||||
return <td key={`pre-append-${index}`}>{cell}</td>;
|
||||
}
|
||||
|
||||
return (
|
||||
<td
|
||||
key={`pre-append-${index}`}
|
||||
className={cell.className}
|
||||
colSpan={cell.colSpan}
|
||||
rowSpan={cell.rowSpan}
|
||||
style={{ width: toCssSize(cell.width), minWidth: toCssSize(cell.width) }}
|
||||
>
|
||||
{cell.content}
|
||||
</td>
|
||||
);
|
||||
return (
|
||||
<td
|
||||
key={`pre-append-${index}`}
|
||||
className={cell.className}
|
||||
colSpan={cell.colSpan}
|
||||
rowSpan={cell.rowSpan}
|
||||
style={{width: toCssSize(cell.width), minWidth: toCssSize(cell.width)}}
|
||||
>
|
||||
{cell.content}
|
||||
</td>
|
||||
);
|
||||
};
|
||||
|
||||
const getLeadingColumnWidths = (rows: TopChartTableRow[], preAppendColumnCount: number) => {
|
||||
const widths = Array<string | undefined>(preAppendColumnCount).fill(undefined);
|
||||
const widths = Array<string | undefined>(preAppendColumnCount).fill(undefined);
|
||||
|
||||
rows.forEach((row) => {
|
||||
let columnIndex = 0;
|
||||
rows.forEach((row) => {
|
||||
let columnIndex = 0;
|
||||
|
||||
row.preAppendCells?.forEach((cell) => {
|
||||
const colSpan = isPreAppendCellConfig(cell) ? cell.colSpan ?? 1 : 1;
|
||||
const width = isPreAppendCellConfig(cell) ? toCssSize(cell.width) : undefined;
|
||||
row.preAppendCells?.forEach((cell) => {
|
||||
const colSpan = isPreAppendCellConfig(cell) ? cell.colSpan ?? 1 : 1;
|
||||
const width = isPreAppendCellConfig(cell) ? toCssSize(cell.width) : undefined;
|
||||
|
||||
if (width && colSpan === 1 && !widths[columnIndex]) {
|
||||
widths[columnIndex] = width;
|
||||
}
|
||||
if (width && colSpan === 1 && !widths[columnIndex]) {
|
||||
widths[columnIndex] = width;
|
||||
}
|
||||
|
||||
columnIndex += colSpan;
|
||||
columnIndex += colSpan;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return widths;
|
||||
return widths;
|
||||
};
|
||||
|
||||
const getLabelColumnWidth = (rows: TopChartTableRow[]) =>
|
||||
rows.map((row) => toCssSize(row.labelWidth)).find(Boolean);
|
||||
rows.map((row) => toCssSize(row.labelWidth)).find(Boolean);
|
||||
|
||||
const getColumnKey = (column: DataColumn<Record<string, unknown>>) =>
|
||||
String(column.id ?? ("key" in column ? column.key : column.header));
|
||||
String(column.id ?? ("key" in column ? column.key : column.header));
|
||||
|
||||
const getColumnLabel = (column: DataColumn<Record<string, unknown>>) =>
|
||||
typeof column.header === "string" ? column.header : getColumnKey(column);
|
||||
typeof column.header === "string" ? column.header : getColumnKey(column);
|
||||
|
||||
export default function TopChartTable({
|
||||
title,
|
||||
rows,
|
||||
sectionRows = [],
|
||||
columns,
|
||||
chart,
|
||||
chartHeight = CHART_HEIGHTS.DEFAULT,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.STANDARD,
|
||||
minWidth,
|
||||
maxWidth,
|
||||
subLabelHeader = "",
|
||||
rowHeaderWidth,
|
||||
categoryColumnWidth,
|
||||
categoryColumnWidths,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
}: Readonly<TopChartTableProps>) {
|
||||
const resolvedSignStyle = resolveSignStyle(signStyle, {
|
||||
positiveTextClassName: "kfpa-num-pos",
|
||||
negativeTextClassName: "kfpa-num-neg",
|
||||
zeroTextClassName: "text-zero",
|
||||
arrowWithNumber: true,
|
||||
valueFormatter: (value) => value.toFixed(KFPA_DECIMAL_POINT),
|
||||
});
|
||||
title,
|
||||
rows,
|
||||
sectionRows = [],
|
||||
columns,
|
||||
chart,
|
||||
chartHeight = CHART_HEIGHTS.DEFAULT,
|
||||
minWidthPx = TABLE_DIMENSIONS.MIN_WIDTH.STANDARD,
|
||||
minWidth,
|
||||
maxWidth,
|
||||
subLabelHeader = "",
|
||||
rowHeaderWidth,
|
||||
categoryColumnWidth,
|
||||
categoryColumnWidths,
|
||||
tableClassName,
|
||||
wrapperClassName,
|
||||
signStyle,
|
||||
}: Readonly<TopChartTableProps>) {
|
||||
const resolvedSignStyle = resolveSignStyle(signStyle, {
|
||||
positiveTextClassName: "kfpa-num-pos",
|
||||
negativeTextClassName: "kfpa-num-neg",
|
||||
zeroTextClassName: "text-zero",
|
||||
arrowWithNumber: true,
|
||||
valueFormatter: (value) => value.toFixed(KFPA_DECIMAL_POINT),
|
||||
});
|
||||
|
||||
const maxPreAppendCellCount = useMemo(
|
||||
() => Math.max(0, ...rows.map((row) => row.preAppendCells?.length ?? 0)),
|
||||
[rows]
|
||||
);
|
||||
const leadingColumnCount = maxPreAppendCellCount + 1;
|
||||
const leadingColumnWidths = useMemo(
|
||||
() => [...getLeadingColumnWidths(rows, maxPreAppendCellCount), getLabelColumnWidth(rows)],
|
||||
[maxPreAppendCellCount, rows]
|
||||
);
|
||||
const columnLabels = useMemo(() => columns.map(getColumnLabel), [columns]);
|
||||
const maxPreAppendCellCount = useMemo(
|
||||
() => Math.max(0, ...rows.map((row) => row.preAppendCells?.length ?? 0)),
|
||||
[rows]
|
||||
);
|
||||
const leadingColumnCount = maxPreAppendCellCount + 1;
|
||||
const leadingColumnWidths = useMemo(
|
||||
() => [...getLeadingColumnWidths(rows, maxPreAppendCellCount), getLabelColumnWidth(rows)],
|
||||
[maxPreAppendCellCount, rows]
|
||||
);
|
||||
const columnLabels = useMemo(() => columns.map(getColumnLabel), [columns]);
|
||||
|
||||
const chartData: ChartData = useMemo(
|
||||
() => ({
|
||||
categories: columnLabels,
|
||||
series: rows.map((row) => ({
|
||||
name: row.label,
|
||||
data: row.values.map((value) => parseNumber(value) ?? null),
|
||||
})),
|
||||
}),
|
||||
[columnLabels, rows]
|
||||
);
|
||||
const chartData: ChartData = useMemo(
|
||||
() => ({
|
||||
categories: columnLabels,
|
||||
series: rows.map((row) => ({
|
||||
name: row.label,
|
||||
data: row.values.map((value) => parseNumber(value) ?? null),
|
||||
})),
|
||||
}),
|
||||
[columnLabels, rows]
|
||||
);
|
||||
|
||||
const chartNode = useMemo(() => {
|
||||
if (!chart) {
|
||||
return null;
|
||||
}
|
||||
return typeof chart === "function" ? chart({ chartData }) : chart;
|
||||
}, [chart, chartData]);
|
||||
const chartNode = useMemo(() => {
|
||||
if (!chart) {
|
||||
return null;
|
||||
}
|
||||
return typeof chart === "function" ? chart({chartData}) : chart;
|
||||
}, [chart, chartData]);
|
||||
|
||||
const rowHeaderStyle = useMemo(() => {
|
||||
const width = toCssSize(rowHeaderWidth);
|
||||
return width ? { width, minWidth: width } : undefined;
|
||||
}, [rowHeaderWidth]);
|
||||
const rowHeaderStyle = useMemo(() => {
|
||||
const width = toCssSize(rowHeaderWidth);
|
||||
return width ? {width, minWidth: width} : undefined;
|
||||
}, [rowHeaderWidth]);
|
||||
|
||||
const hasCategoryHeaderRow = useMemo(
|
||||
() => subLabelHeader.trim().length > 0 || columns.some((column) => getColumnLabel(column).trim().length > 0),
|
||||
[columns, subLabelHeader]
|
||||
);
|
||||
const hasCategoryHeaderRow = useMemo(
|
||||
() => subLabelHeader.trim().length > 0 || columns.some((column) => getColumnLabel(column).trim().length > 0),
|
||||
[columns, subLabelHeader]
|
||||
);
|
||||
|
||||
return (
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
<BaseTableHeader title={title} />
|
||||
return (
|
||||
<div className={cn("w-full", wrapperClassName)}>
|
||||
<BaseTableHeader title={title}/>
|
||||
|
||||
<div className="overflow-x-auto">
|
||||
<table className={cn("kfpa-table kfpa-table", tableClassName)} style={{ minWidth: `${minWidth ?? minWidthPx}px` , maxWidth: maxWidth ? `${maxWidth}px` : undefined}}>
|
||||
<colgroup>
|
||||
{leadingColumnWidths.map((width, index) => (
|
||||
<col key={`leading-col-${index}`} style={width ? { width, minWidth: width } : undefined} />
|
||||
))}
|
||||
{columns.map((column, index) => {
|
||||
const width = toCssSize(categoryColumnWidths?.[index] ?? column.width ?? categoryColumnWidth);
|
||||
return (
|
||||
<col
|
||||
key={`category-col-${getColumnKey(column)}`}
|
||||
style={width ? { width, minWidth: width } : undefined}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr className="kfpa-table__chart-row border-none">
|
||||
<th
|
||||
colSpan={leadingColumnCount}
|
||||
className={cn(rowHeaderWidth ? undefined : "w-44", "border-none")}
|
||||
style={{ whiteSpace: "nowrap", ...rowHeaderStyle }}
|
||||
/>
|
||||
<td colSpan={columns.length} style={{ padding: 0, height: chartNode ? chartHeight : 0 }}>
|
||||
{chartNode ? <div style={{ width: "100%", height: "100%" }}>{chartNode}</div> : null}
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{hasCategoryHeaderRow && (
|
||||
<tr className="kfpa-table__subhead kfpa-table__subhead kfpa-table__after-chart-row">
|
||||
<th
|
||||
colSpan={leadingColumnCount}
|
||||
className={"kfpa-table-border-none content-text-base bg-transparent"}
|
||||
style={rowHeaderStyle}
|
||||
>
|
||||
{subLabelHeader}
|
||||
</th>
|
||||
{columns.map((column) => {
|
||||
<div className="overflow-x-auto">
|
||||
<table className={cn("kfpa-table kfpa-table", tableClassName)} style={{
|
||||
minWidth: `${minWidth ?? minWidthPx}px`,
|
||||
maxWidth: maxWidth ? `${maxWidth}px` : undefined
|
||||
}}>
|
||||
<colgroup>
|
||||
{leadingColumnWidths.map((width, index) => (
|
||||
<col key={`leading-col-${index}`}
|
||||
style={width ? {width, minWidth: width} : undefined}/>
|
||||
))}
|
||||
{columns.map((column, index) => {
|
||||
const width = toCssSize(categoryColumnWidths?.[index] ?? column.width ?? categoryColumnWidth);
|
||||
return (
|
||||
<th
|
||||
key={getColumnKey(column)}
|
||||
className={cn(column.headerClassName, "content-text-base")}
|
||||
style={{ textAlign: column.align }}
|
||||
>
|
||||
{column.header}
|
||||
</th>
|
||||
)
|
||||
<col
|
||||
key={`category-col-${getColumnKey(column)}`}
|
||||
style={width ? {width, minWidth: width} : undefined}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr className="kfpa-table__chart-row border-none">
|
||||
<th
|
||||
colSpan={leadingColumnCount}
|
||||
className={cn(rowHeaderWidth ? undefined : "w-44", "border-none")}
|
||||
style={{whiteSpace: "nowrap", ...rowHeaderStyle}}
|
||||
/>
|
||||
<td colSpan={columns.length}
|
||||
style={{padding: 0, height: chartNode ? chartHeight : 0}}>
|
||||
{chartNode ? <div style={{width: "100%", height: "100%"}}>{chartNode}</div> : null}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
{rows.map((row, rowIndex) => {
|
||||
const signRow = !!signStyle?.rowSelector?.(row, rowIndex);
|
||||
const preAppendCells = row.preAppendCells ?? [];
|
||||
const sectionRowsAfterCurrentRow = sectionRows.filter(
|
||||
(sectionRow) => sectionRow.afterRowIndex === rowIndex
|
||||
);
|
||||
|
||||
return (
|
||||
<React.Fragment key={`${row.label}-${rowIndex}`}>
|
||||
<tr>
|
||||
{preAppendCells.map(renderPreAppendCell)}
|
||||
{hasCategoryHeaderRow && (
|
||||
<tr className="kfpa-table__subhead kfpa-table__subhead kfpa-table__after-chart-row">
|
||||
<th
|
||||
scope="row"
|
||||
className={cn(
|
||||
"kfpa-table__rowhead kfpa-table__sep-r kfpa-table__sep-r content-text-base",
|
||||
row.labelClassName
|
||||
)}
|
||||
style={{
|
||||
width: toCssSize(row.labelWidth),
|
||||
minWidth: toCssSize(row.labelWidth),
|
||||
}}
|
||||
colSpan={leadingColumnCount}
|
||||
className={"kfpa-table-border-none content-text-base bg-transparent"}
|
||||
style={rowHeaderStyle}
|
||||
>
|
||||
{row.label}
|
||||
{subLabelHeader}
|
||||
</th>
|
||||
|
||||
{columns.map((column, categoryIndex) => {
|
||||
const rawValue = row.values?.[categoryIndex];
|
||||
const decimalPlaces = row.decimalPlaces ?? KFPA_DECIMAL_POINT;
|
||||
const roundedValue = toRoundedNumber(rawValue, decimalPlaces);
|
||||
|
||||
if (roundedValue === null) {
|
||||
return <td key={getColumnKey(column)} className={cn(column.cellClassName, row.cellClassName)} style={{ textAlign: column.align }}>-</td>;
|
||||
}
|
||||
|
||||
if(!signRow) {
|
||||
return (
|
||||
<td key={getColumnKey(column)} className={cn(column.cellClassName, row.cellClassName)} style={{ textAlign: column.align }}>
|
||||
{roundedValue.toFixed(decimalPlaces)}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
{columns.map((column) => {
|
||||
return (
|
||||
<td
|
||||
key={getColumnKey(column)}
|
||||
className={cn(column.cellClassName, row.cellClassName, getSignTextClass(roundedValue, resolvedSignStyle))}
|
||||
style={{ textAlign: column.align }}
|
||||
<th
|
||||
key={getColumnKey(column)}
|
||||
className={cn(column.headerClassName, "content-text-base")}
|
||||
style={{textAlign: column.align}}
|
||||
>
|
||||
{formatSignedValue(roundedValue, resolvedSignStyle)}
|
||||
</td>
|
||||
);
|
||||
|
||||
{column.header}
|
||||
</th>
|
||||
)
|
||||
})}
|
||||
</tr>
|
||||
)}
|
||||
</thead>
|
||||
|
||||
{sectionRowsAfterCurrentRow.map((sectionRow, sectionRowIndex) => (
|
||||
<tr key={`section-row-${rowIndex}-${sectionRowIndex}`}>
|
||||
<td
|
||||
colSpan={leadingColumnCount}
|
||||
className={cn("kfpa-table__section-row content-text-base", sectionRow.className)}
|
||||
>
|
||||
{sectionRow.content}
|
||||
</td>
|
||||
<td
|
||||
colSpan={columns.length}
|
||||
className={cn("kfpa-table__section-row content-text-base", sectionRow.bodyClassName)}
|
||||
/>
|
||||
</tr>
|
||||
))}
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
<tbody>
|
||||
{rows.map((row, rowIndex) => {
|
||||
const signRow = !!signStyle?.rowSelector?.(row, rowIndex);
|
||||
const preAppendCells = row.preAppendCells ?? [];
|
||||
const sectionRowsAfterCurrentRow = sectionRows.filter(
|
||||
(sectionRow) => sectionRow.afterRowIndex === rowIndex
|
||||
);
|
||||
|
||||
return (
|
||||
<React.Fragment key={`${row.label}-${rowIndex}`}>
|
||||
<tr>
|
||||
{preAppendCells.map(renderPreAppendCell)}
|
||||
<th
|
||||
scope="row"
|
||||
className={cn(
|
||||
"kfpa-table__rowhead kfpa-table__sep-r kfpa-table__sep-r content-text-base",
|
||||
row.labelClassName
|
||||
)}
|
||||
style={{
|
||||
width: toCssSize(row.labelWidth),
|
||||
minWidth: toCssSize(row.labelWidth),
|
||||
}}
|
||||
>
|
||||
{row.label}
|
||||
</th>
|
||||
|
||||
{columns.map((column, categoryIndex) => {
|
||||
const rawValue = row.values?.[categoryIndex];
|
||||
const decimalPlaces = row.decimalPlaces ?? KFPA_DECIMAL_POINT;
|
||||
const roundedValue = toRoundedNumber(rawValue, decimalPlaces);
|
||||
|
||||
if (roundedValue === null) {
|
||||
return <td key={getColumnKey(column)}
|
||||
className={cn(column.cellClassName, row.cellClassName, column.nullCellClassName)}
|
||||
style={{textAlign: column.align}}>-</td>;
|
||||
}
|
||||
|
||||
if (!signRow) {
|
||||
return (
|
||||
<td key={getColumnKey(column)}
|
||||
className={cn(column.cellClassName, row.cellClassName)}
|
||||
style={{textAlign: column.align}}>
|
||||
{roundedValue.toFixed(decimalPlaces)}
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<td
|
||||
key={getColumnKey(column)}
|
||||
className={cn(column.cellClassName, row.cellClassName, getSignTextClass(roundedValue, resolvedSignStyle))}
|
||||
style={{textAlign: column.align}}
|
||||
>
|
||||
{formatSignedValue(roundedValue, resolvedSignStyle)}
|
||||
</td>
|
||||
);
|
||||
|
||||
})}
|
||||
</tr>
|
||||
|
||||
{sectionRowsAfterCurrentRow.map((sectionRow, sectionRowIndex) => (
|
||||
<tr key={`section-row-${rowIndex}-${sectionRowIndex}`}>
|
||||
<td
|
||||
colSpan={leadingColumnCount}
|
||||
className={cn("kfpa-table__section-row content-text-base", sectionRow.className)}
|
||||
>
|
||||
{sectionRow.content}
|
||||
</td>
|
||||
<td
|
||||
colSpan={columns.length}
|
||||
className={cn("kfpa-table__section-row content-text-base", sectionRow.bodyClassName)}
|
||||
/>
|
||||
</tr>
|
||||
))}
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
9
src/components/kfpa/CommentNote.tsx
Normal file
9
src/components/kfpa/CommentNote.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
const CommentNote = () => {
|
||||
return (
|
||||
<p className="mt-3 content-text-base">
|
||||
▶ : 완료 / ▷ : 진행 중
|
||||
</p>
|
||||
);
|
||||
};
|
||||
|
||||
export default CommentNote;
|
||||
@@ -1,9 +1,24 @@
|
||||
const CsiFormulaNote = () => {
|
||||
return (
|
||||
<p className="mt-3 content-text-base">
|
||||
※ 고객만족지수(CSI, Customer Satisfaction Index) = 고객 만족도조사 직접요소 항목 점수 X 가중치 + 고객
|
||||
만족도조사 간접요소 항목 점수 X 가중치
|
||||
</p>
|
||||
<>
|
||||
<p className="mt-3 content-text-base">
|
||||
※ 고객만족지수(CSI, Customer Satisfaction Index) = 고객 만족도조사 직접요소 항목 점수 X 가중치 + 고객
|
||||
만족도조사 간접요소 항목 점수 X 가중치
|
||||
</p>
|
||||
<p className="mt-3 content-text-base">
|
||||
※ 주요 고객 대상 : 안전점검(특수건물 관계자)
|
||||
/ UCIS(사원사 등)
|
||||
/ Bridge 플랫폼(사원사, 일반회원 등)
|
||||
/ 방재컨설팅(발주처 관계자 약 20명)
|
||||
/ 보험업무(보험 계약 담당자 약 300명)
|
||||
/ 화재조사(사원사 손해사정부서 총 11명)
|
||||
</p>
|
||||
<p className="mt-3 content-text-base">
|
||||
※ 응답 데이터 업데이트 주기 : 안전점검(매일 실시간)
|
||||
/ UCIS, Bridge플랫폼, 보험업무, 화재조사(매월 말)
|
||||
/ 방재컨설팅(각 용역이 완료되는 하반기에 진행 예정)
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
import DataTable from "@/components/table/DataTable";
|
||||
import type { DataColumn } from "@/components/table/types";
|
||||
import { cn } from "@/lib/utils";
|
||||
import type { CommentColumn, CommentField, CommentValue, DashboardCommentRowConfig } from "@/types/kfpa";
|
||||
import CommentNote from "@/components/kfpa/CommentNote";
|
||||
|
||||
type CommentTableRow = DashboardCommentRowConfig & Record<string, unknown>;
|
||||
|
||||
@@ -63,12 +65,22 @@ const CustomerSatisfactionCommentTable = ({
|
||||
const value = String(draft[column.key]?.[row.field] ?? "");
|
||||
|
||||
if (!isEditing) {
|
||||
return <div className="min-h-24 whitespace-pre-wrap text-left">{value || "-"}</div>;
|
||||
return (
|
||||
<div className={cn(
|
||||
"min-h-24 whitespace-pre-wrap text-left",
|
||||
"leading-[1.5] content-text-lg"
|
||||
)}>
|
||||
{value || "-"}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<textarea
|
||||
className="min-h-28 w-full resize-y border border-gray-300 bg-background p-2 text-sm outline-none focus:border-primary"
|
||||
className={cn(
|
||||
"h-24 w-full resize-y border border-gray-300 bg-background p-2",
|
||||
"leading-[1.5] content-text-lg outline-none focus:border-primary"
|
||||
)}
|
||||
value={value}
|
||||
onChange={(event) => onChange(column.key, row.field, event.target.value)}
|
||||
/>
|
||||
@@ -78,13 +90,16 @@ const CustomerSatisfactionCommentTable = ({
|
||||
];
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
columns={tableColumns}
|
||||
rows={tableRows}
|
||||
tableClassName="kfpa-table kfpa-detail-table kfpa-detail-comment-table"
|
||||
subheadRowClassName="bg-red-50"
|
||||
wrapperClassName="w-full"
|
||||
/>
|
||||
<>
|
||||
<DataTable
|
||||
columns={tableColumns}
|
||||
rows={tableRows}
|
||||
tableClassName="kfpa-table kfpa-detail-table kfpa-detail-comment-table"
|
||||
subheadRowClassName="bg-red-50"
|
||||
wrapperClassName="w-full"
|
||||
/>
|
||||
<CommentNote/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -36,12 +36,14 @@ export type CustomerSatisfactionDetailProps = {
|
||||
selectedDiv: string;
|
||||
sectionTitleSuffix?: string;
|
||||
viewSubTitle?: boolean;
|
||||
widthClassName?: string;
|
||||
};
|
||||
|
||||
const CustomerSatisfactionDetail = ({
|
||||
selectedDiv,
|
||||
sectionTitleSuffix,
|
||||
viewSubTitle = true,
|
||||
widthClassName = "w-full",
|
||||
}: CustomerSatisfactionDetailProps) => {
|
||||
const searchParams = useSearchParams();
|
||||
const queryClient = useQueryClient();
|
||||
@@ -122,7 +124,7 @@ const CustomerSatisfactionDetail = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
<div className={widthClassName}>
|
||||
<SectionTitle title={`${getSideMenuLabel(categoryKey, selectedDiv)} ${sectionTitleSuffix ?? '상세 내역'}`} />
|
||||
|
||||
<div className="mt-4 flex w-full items-start gap-16 overflow-x-auto pb-2">
|
||||
|
||||
@@ -55,6 +55,13 @@ const CustomerSatisfactionSummary = () => {
|
||||
: undefined,
|
||||
align: "center",
|
||||
}));
|
||||
|
||||
columns
|
||||
.filter((column) => SUMMARY_CATEGORY_KEYS.includes(column.key ?? ""))
|
||||
.forEach((column) => {
|
||||
column.nullCellClassName = "bg-null text-null"
|
||||
})
|
||||
|
||||
const categories = summaryColumns.map(getSummaryColumnLabel);
|
||||
|
||||
const rows: TopChartTableRow[] =
|
||||
@@ -146,7 +153,7 @@ const CustomerSatisfactionSummary = () => {
|
||||
signStyle={KFPA_GAP_SIGN_STYLE}
|
||||
minWidth={tableLayout.tableWidth}
|
||||
maxWidth={tableLayout.tableWidth}
|
||||
chartHeight={180}
|
||||
chartHeight={280}
|
||||
chart={
|
||||
<VerticalBar
|
||||
data={chartData}
|
||||
@@ -155,8 +162,9 @@ const CustomerSatisfactionSummary = () => {
|
||||
valueFormatter={(value) => value.toFixed(KFPA_DECIMAL_POINT)}
|
||||
barMaxWidth={30}
|
||||
showFocusLabel="all"
|
||||
labelOptions={{ position: "top", distance: 4 }}
|
||||
grid={{ left: 0, right: 0, top: 20, bottom: 5 }}
|
||||
labelOptions={{ position: "top", distance: 4, minPositionValue: 3.99 }}
|
||||
legend={{top:50}}
|
||||
grid={{ left: 0, right: 0, top: 120, bottom: 5 }}
|
||||
xAxis={{
|
||||
type: "category",
|
||||
data: categories,
|
||||
@@ -166,7 +174,7 @@ const CustomerSatisfactionSummary = () => {
|
||||
}}
|
||||
yAxis={{
|
||||
type: "value",
|
||||
min: 4,
|
||||
min: 3.95,
|
||||
max: 5,
|
||||
axisLabel: { show: false },
|
||||
axisTick: { show: false },
|
||||
|
||||
@@ -225,8 +225,8 @@ const CustomerSatisfactionTotal = () => {
|
||||
valueFormatter={(value) => value.toFixed(2)}
|
||||
barMaxWidth={30}
|
||||
showFocusLabel="all"
|
||||
labelOptions={{ position: "top", distance: 4 }}
|
||||
grid={{ left: 0, right: 0, top: 20, bottom: 5 }}
|
||||
labelOptions={{ position: "top", distance: 4 , minPositionValue: 3.99}}
|
||||
grid={{ left: 0, right: 0, top: 30, bottom: 5 }}
|
||||
xAxis={{
|
||||
type: "category",
|
||||
data: categories,
|
||||
@@ -236,7 +236,7 @@ const CustomerSatisfactionTotal = () => {
|
||||
}}
|
||||
yAxis={{
|
||||
type: "value",
|
||||
min: 4,
|
||||
min: 3.95,
|
||||
max: 5,
|
||||
axisLabel: { show: false },
|
||||
axisTick: { show: false },
|
||||
|
||||
@@ -9,6 +9,7 @@ type TableColumnShared<T> = {
|
||||
align?: TableColumnAlign;
|
||||
headerClassName?: string;
|
||||
cellClassName?: string;
|
||||
nullCellClassName?: string;
|
||||
render?: (row: T) => React.ReactNode;
|
||||
};
|
||||
|
||||
|
||||
@@ -258,9 +258,9 @@ export const DASHBOARD_METRICS_BY_CATEGORY = {
|
||||
} as const;
|
||||
|
||||
export const DASHBOARD_COMMENT_COLUMNS = [
|
||||
{ key: "performance25", label: "25년 성과" },
|
||||
{ key: "plan26", label: "26년 업무계획" },
|
||||
{ key: "performance26", label: "26년 업무계획 진행률 및 성과" },
|
||||
{ key: "performance25", label: "25년 고객 관점 주요 성과" },
|
||||
//{ key: "plan26", label: "26년 업무계획" },
|
||||
{ key: "performance26", label: "26년 고객 관점 주요 성과" },
|
||||
] as const;
|
||||
|
||||
const DEFAULT_DASHBOARD_COMMENT_ROWS = [
|
||||
|
||||
@@ -79,7 +79,6 @@ export const getAverageGapValue = (
|
||||
key: string,
|
||||
wave: number,
|
||||
) => {
|
||||
console.log(averageKey, key)
|
||||
if(averageKey === key) return null;
|
||||
|
||||
const averageValue = roundNumber(getSummaryCsiValue(dataMap, averageKey, wave), KFPA_DECIMAL_POINT);
|
||||
@@ -95,8 +94,7 @@ export const getSelectedDetail = (data: Record<string, DivDetailData> | undefine
|
||||
};
|
||||
|
||||
export const getCommentColumns = (commentValues?: Record<string, CommentValue>): CommentColumn[] => {
|
||||
const keys = Object.keys(commentValues ?? {});
|
||||
const selectedKeys = keys.length > 0 ? keys : DASHBOARD_COMMENT_COLUMNS.map((column) => column.key);
|
||||
const selectedKeys = DASHBOARD_COMMENT_COLUMNS.map((column) => column.key);
|
||||
|
||||
return selectedKeys.map((key, index) => ({
|
||||
key,
|
||||
|
||||
111
src/proxy.ts
Normal file
111
src/proxy.ts
Normal file
@@ -0,0 +1,111 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
const IP_WHITELIST_ENV = "IP_WHITELIST";
|
||||
const LOCAL_IPS = new Set(["127.0.0.1", "::1"]);
|
||||
|
||||
const normalizeIp = (ip: string) => {
|
||||
const trimmed = ip.trim();
|
||||
|
||||
if (!trimmed) return "";
|
||||
if (trimmed.startsWith("::ffff:")) return trimmed.slice("::ffff:".length);
|
||||
|
||||
const withoutBrackets = trimmed.replace(/^\[|\]$/g, "");
|
||||
const portSeparatorIndex = withoutBrackets.lastIndexOf(":");
|
||||
if (
|
||||
portSeparatorIndex > -1 &&
|
||||
withoutBrackets.indexOf(":") === portSeparatorIndex &&
|
||||
/^\d+$/.test(withoutBrackets.slice(portSeparatorIndex + 1))
|
||||
) {
|
||||
return withoutBrackets.slice(0, portSeparatorIndex);
|
||||
}
|
||||
|
||||
return withoutBrackets;
|
||||
};
|
||||
|
||||
const getClientIp = (request: NextRequest) => {
|
||||
const forwardedFor = request.headers.get("x-forwarded-for");
|
||||
if (forwardedFor) {
|
||||
return normalizeIp(forwardedFor.split(",")[0]);
|
||||
}
|
||||
|
||||
return normalizeIp(
|
||||
request.headers.get("x-real-ip") ??
|
||||
request.headers.get("cf-connecting-ip") ??
|
||||
request.headers.get("true-client-ip") ??
|
||||
""
|
||||
);
|
||||
};
|
||||
|
||||
const ipv4ToNumber = (ip: string) => {
|
||||
const parts = ip.split(".");
|
||||
if (parts.length !== 4) return null;
|
||||
|
||||
return parts.reduce<number | null>((acc, part) => {
|
||||
if (acc === null || !/^\d+$/.test(part)) return null;
|
||||
|
||||
const value = Number(part);
|
||||
if (value < 0 || value > 255) return null;
|
||||
|
||||
return ((acc << 8) + value) >>> 0;
|
||||
}, 0);
|
||||
};
|
||||
|
||||
const isIpv4InCidr = (ip: string, cidr: string) => {
|
||||
const [rangeIp, prefixRaw] = cidr.split("/");
|
||||
const prefix = Number(prefixRaw);
|
||||
const target = ipv4ToNumber(ip);
|
||||
const range = ipv4ToNumber(rangeIp);
|
||||
|
||||
if (target === null || range === null || !Number.isInteger(prefix) || prefix < 0 || prefix > 32) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const mask = prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0;
|
||||
return (target & mask) === (range & mask);
|
||||
};
|
||||
|
||||
const parseWhitelist = () =>
|
||||
(process.env[IP_WHITELIST_ENV] ?? "")
|
||||
.split(",")
|
||||
.map((ip) => normalizeIp(ip))
|
||||
.filter(Boolean);
|
||||
|
||||
const isAllowedIp = (clientIp: string) => {
|
||||
const whitelist = parseWhitelist();
|
||||
|
||||
if (whitelist.length === 0) {
|
||||
return process.env.ENV === "local" && LOCAL_IPS.has(clientIp);
|
||||
}
|
||||
|
||||
return whitelist.some((allowedIp) => {
|
||||
if (allowedIp.includes("/")) {
|
||||
return isIpv4InCidr(clientIp, allowedIp);
|
||||
}
|
||||
|
||||
return clientIp === allowedIp;
|
||||
});
|
||||
};
|
||||
|
||||
export function proxy(request: NextRequest) {
|
||||
const pathname = request.nextUrl.pathname;
|
||||
|
||||
if (pathname === "/403") {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
const clientIp = getClientIp(request);
|
||||
|
||||
if (clientIp && isAllowedIp(clientIp)) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
const url = request.nextUrl.clone();
|
||||
url.pathname = "/403";
|
||||
url.search = "";
|
||||
|
||||
return NextResponse.redirect(url);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|.*\\..*).*)"],
|
||||
};
|
||||
Reference in New Issue
Block a user