From 0de698b3072575349d8b1a9945a86196c937a7ba Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Thu, 7 May 2026 15:31:42 +0900 Subject: [PATCH] =?UTF-8?q?260507=5F01=5FENH:=20SafetyInspectionTotal,=20S?= =?UTF-8?q?afetyInspectionDivDetail=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../(pages)/(main)/safety-inspection/page.tsx | 4 +- .../sub/SafetyInspectionDivDetail.tsx | 302 ++++++++++++++++++ .../sub/SafetyInspectionTotal.tsx | 262 +++++++++++++++ src/app/api/admin/[[...slug]]/route.ts | 35 ++ src/app/api/statistics/[[...slug]]/route.ts | 30 ++ src/app/globals.css | 60 +++- src/components/chart/BaseEChart.tsx | 99 ++++++ src/components/chart/HorizontalBar.tsx | 91 ++++++ src/components/chart/VerticalBar.tsx | 93 ++++++ src/components/chart/color.ts | 134 ++++++++ src/components/chart/types.ts | 2 + src/components/chart/utill.ts | 22 ++ src/components/combo/TopChartTable.tsx | 236 ++++++++++++++ src/components/combo/types.ts | 21 ++ src/components/common/LoadingOverlay.tsx | 2 +- src/components/common/SectionTitle.tsx | 10 + src/components/dialog/loginDialog.tsx | 2 +- src/components/layout/MainLayout.tsx | 12 +- src/components/table/BaseDataTable.tsx | 162 ++++++++++ src/components/table/DataTable.tsx | 43 +++ src/components/table/core/BaseTableHeader.tsx | 18 ++ .../table/core/BaseTableRenderer.tsx | 68 ++++ .../table/core/table-core.helpers.tsx | 242 ++++++++++++++ src/components/table/table.config.ts | 12 + src/components/table/types.ts | 64 ++++ src/components/ui/dialog.tsx | 2 +- src/config/kfpaConfig.ts | 36 +-- src/config/menu.data.ts | 13 +- src/const/{commonConst.ts => common.const.ts} | 0 src/const/kfpa.const.ts | 2 + src/lib/http-util.ts | 2 +- src/lib/kfpa-utill.ts | 3 + src/lib/utils.ts | 55 ++++ src/query/admin.ts | 15 + src/query/key/keys.ts | 10 + src/query/statistics.ts | 27 ++ src/types/kfpa.ts | 36 ++- 37 files changed, 2172 insertions(+), 55 deletions(-) create mode 100644 src/app/(pages)/(main)/safety-inspection/sub/SafetyInspectionDivDetail.tsx create mode 100644 src/app/(pages)/(main)/safety-inspection/sub/SafetyInspectionTotal.tsx create mode 100644 src/app/api/admin/[[...slug]]/route.ts create mode 100644 src/app/api/statistics/[[...slug]]/route.ts create mode 100644 src/components/chart/BaseEChart.tsx create mode 100644 src/components/chart/HorizontalBar.tsx create mode 100644 src/components/chart/VerticalBar.tsx create mode 100644 src/components/chart/color.ts create mode 100644 src/components/chart/utill.ts create mode 100644 src/components/combo/TopChartTable.tsx create mode 100644 src/components/combo/types.ts create mode 100644 src/components/common/SectionTitle.tsx create mode 100644 src/components/table/BaseDataTable.tsx create mode 100644 src/components/table/DataTable.tsx create mode 100644 src/components/table/core/BaseTableHeader.tsx create mode 100644 src/components/table/core/BaseTableRenderer.tsx create mode 100644 src/components/table/core/table-core.helpers.tsx create mode 100644 src/components/table/table.config.ts create mode 100644 src/components/table/types.ts rename src/const/{commonConst.ts => common.const.ts} (100%) create mode 100644 src/const/kfpa.const.ts create mode 100644 src/lib/kfpa-utill.ts create mode 100644 src/query/admin.ts create mode 100644 src/query/statistics.ts diff --git a/src/app/(pages)/(main)/safety-inspection/page.tsx b/src/app/(pages)/(main)/safety-inspection/page.tsx index 674e92b..e22ea26 100644 --- a/src/app/(pages)/(main)/safety-inspection/page.tsx +++ b/src/app/(pages)/(main)/safety-inspection/page.tsx @@ -1,12 +1,14 @@ 'use client' import {useLayoutFilter} from "@/components/layout/LayoutCategoryContext"; +import SafetyInspectionTotal from "./sub/SafetyInspectionTotal"; +import SafetyInspectionDivDetail from "./sub/SafetyInspectionDivDetail"; const SafetyInspectionPage = () => { const { selectedDiv } = useLayoutFilter(); return ( -
SafetyInspectionPage {selectedDiv}
+ selectedDiv === "-1" ? : ) } diff --git a/src/app/(pages)/(main)/safety-inspection/sub/SafetyInspectionDivDetail.tsx b/src/app/(pages)/(main)/safety-inspection/sub/SafetyInspectionDivDetail.tsx new file mode 100644 index 0000000..bac458c --- /dev/null +++ b/src/app/(pages)/(main)/safety-inspection/sub/SafetyInspectionDivDetail.tsx @@ -0,0 +1,302 @@ +"use client"; + +import { useEffect, useMemo, useState } from "react"; +import { useQueryClient } from "@tanstack/react-query"; +import { toast } from "sonner"; +import DataTable from "@/components/table/DataTable"; +import type { DataColumn } from "@/components/table/types"; +import { Button } from "@/components/ui/button"; +import { DIV_KEY_MAP } from "@/config/kfpaConfig"; +import { useAuth } from "@/hooks/useAuth"; +import { formatKoreanBaseDate } from "@/lib/utils"; +import { useWriteDivCommentMutation } from "@/query/admin"; +import { statisticsQueryKeys } from "@/query/key/keys"; +import { useDivDetailDataQuery } from "@/query/statistics"; +import type { CommentValue, DivDetailData } from "@/types/kfpa"; +import { Pencil, Save, X } from 'lucide-react'; +import SectionTitle from "@/components/common/SectionTitle"; + +export type SafetyInspectionDivDetailProps = { + selectedDiv: string; +}; + +type RankRow = { + type: string; + csi: number | null; + rank: string; +}; + +type CommentField = keyof CommentValue; + +type CommentRow = { + label: string; + importance: string; + field: CommentField; +}; + +type CommentTableRow = CommentRow & Record; + +const DEFAULT_COMMENT_COLUMNS = [ + { key: "performance25", label: "25년 성과" }, + { key: "plan26", label: "26년 업무계획" }, + { key: "performance26", label: "26년 업무계획 진행률 및 성과" }, +]; + +const COMMENT_ROWS: CommentRow[] = [ + { label: "고객 직접 체감", importance: "★★★", field: "directExperience" }, + { label: "고객 간접 체감", importance: "★★", field: "indirectExperience" }, + { label: "내부역량 강화 등", importance: "★", field: "capability" }, +]; + +const RANK_ROWS = [ + { key: "90", label: "일반" }, + { key: "4", label: "공장" }, + { key: "12", label: "아파트" }, +]; + +const getSelectedDetail = (data: Record | undefined, selectedDiv: string) => { + if (!data) return undefined; + return data[selectedDiv] ?? Object.values(data)[0]; +}; + +const getCommentColumns = (commentValues?: Record) => { + const keys = Object.keys(commentValues ?? {}); + const selectedKeys = keys.length > 0 ? keys : DEFAULT_COMMENT_COLUMNS.map((column) => column.key); + + return selectedKeys.map((key, index) => ({ + key, + label: DEFAULT_COMMENT_COLUMNS[index]?.label ?? key, + })); +}; + +const createEmptyCommentValue = (): CommentValue => ({ + directExperience: "", + indirectExperience: "", + capability: "", +}); + +const createDraft = (columns: Array<{ key: string }>, source?: Record) => + columns.reduce>((acc, column) => { + acc[column.key] = { + ...createEmptyCommentValue(), + ...(source?.[column.key] ?? {}), + }; + return acc; + }, {}); + +const SafetyInspectionDivDetail = ({ selectedDiv }: SafetyInspectionDivDetailProps) => { + const { auth } = useAuth(); + const queryClient = useQueryClient(); + const { data, isLoading, isError } = useDivDetailDataQuery(selectedDiv, selectedDiv !== "-1"); + const writeMutation = useWriteDivCommentMutation(); + + const detail = useMemo(() => getSelectedDetail(data, selectedDiv), [data, selectedDiv]); + const commentColumns = useMemo(() => getCommentColumns(detail?.commentValues), [detail?.commentValues]); + const [isEditing, setIsEditing] = useState(false); + const [draft, setDraft] = useState>(() => + createDraft(commentColumns, detail?.commentValues) + ); + + useEffect(() => { + setIsEditing(false); + setDraft(createDraft(commentColumns, detail?.commentValues)); + }, [commentColumns, detail?.commentValues, selectedDiv]); + + const baseDateLabel = useMemo(() => formatKoreanBaseDate(), []); + const isAuthenticated = auth.user != null; + + const rankRows: RankRow[] = useMemo(() => { + const ranks = detail?.csiRanks ?? {}; + return RANK_ROWS.map(({ key, label }) => ({ + type: label, + csi: ranks[key]?.csi ?? 0, + rank: `${ranks[key]?.divRank ?? 0}/6`, + })); + }, [detail?.csiRanks]); + + const rankColumns: DataColumn[] = useMemo( + () => [ + { key: "type", header: "물건 유형", align: "center" }, + { + key: "csi", + header: "고객만족지수", + align: "center", + render: (row) => (typeof row.csi === "number" ? row.csi.toFixed(2) : "-"), + }, + { key: "rank", header: "지역본부순위", align: "center" }, + ], + [] + ); + + const updateDraft = (columnKey: string, field: CommentField, value: string) => { + setDraft((prev) => ({ + ...prev, + [columnKey]: { + ...createEmptyCommentValue(), + ...(prev[columnKey] ?? {}), + [field]: value, + }, + })); + }; + + const commentRows: CommentTableRow[] = useMemo( + () => + COMMENT_ROWS.map((row) => ({ + ...row, + ...Object.fromEntries(commentColumns.map((column) => [column.key, draft[column.key]?.[row.field] ?? ""])), + })), + [commentColumns, draft] + ); + + const commentTableColumns: DataColumn[] = useMemo( + () => [ + { + key: "label", + header: "", + rowHead: true, + width: 170, + align: "center", + cellClassName: "bg-red-50 text-center font-bold", + }, + { + key: "importance", + header: "중요도(난이도)", + width: 110, + align: "center", + cellClassName: "font-bold", + }, + ...commentColumns.map>((column) => ({ + key: column.key, + header: column.label, + align: "left", + cellClassName: "align-top", + render: (row) => { + const value = String(draft[column.key]?.[row.field] ?? ""); + + if (!isEditing) { + return
{value || "-"}
; + } + + return ( +