Files
frontend/apps/st/src/components/statistics/verification/detail/Indicators.tsx
T

84 lines
2.7 KiB
TypeScript

import React from "react";
import { useQuery } from "@tanstack/react-query";
import { ENDPOINT } from "@/shared/config";
import { stAnlsRsltApi } from "@/entities/statistics/api/statistics-analysis-result-api";
import { LoadingWithAnimation } from "@common/components";
interface IndicatorsProps {
anlsSn: number;
vrfcTrgtSn: string | null;
}
const Indicators: React.FC<IndicatorsProps> = ({ anlsSn, vrfcTrgtSn }) => {
const { data: chartData, isLoading } = useQuery({
queryKey: [
ENDPOINT.STATVERIFY_SERVICE.ST_ANLS_RSLT,
"chart",
anlsSn,
vrfcTrgtSn,
],
queryFn: () => stAnlsRsltApi.getChartData(anlsSn, Number(vrfcTrgtSn)),
enabled: !!anlsSn && !!vrfcTrgtSn,
});
const dtl = chartData?.dtl;
if (!vrfcTrgtSn) {
return (
<div className="card card-border flex min-h-[10rem] items-center justify-center gap-6 text-[1.4rem] text-muted-foreground">
항목을 선택해주세요
</div>
);
}
if (isLoading) {
return (
<div className="flex w-full items-center justify-center py-40">
<div className="relative size-[5rem]">
<LoadingWithAnimation color="primary" />
</div>
</div>
);
}
const IndicatorItem = ({
label,
value,
}: {
label: string;
value: number | null | undefined;
}) => (
<div className="flex flex-1 flex-col gap-2 overflow-hidden rounded border bg-gray-50 p-2">
<h4
className="truncate text-[1.2rem] font-medium text-label"
title={label}
>
{label}
</h4>
<div className="truncate text-[1.6rem] font-bold">
{value != null ? Number(value).toFixed(4) : "-"}
</div>
</div>
);
return (
<div className="card card-border !m-0 grid min-h-[10rem] grid-cols-4 gap-2">
<IndicatorItem label="R 중위수" value={dtl?.rtCnterVl} />
<IndicatorItem label="E 중위수" value={dtl?.lastTrsfScrCnterVl} />
<IndicatorItem label="하위 기준값" value={dtl?.lastTrsfScrLlmtVl} />
<IndicatorItem
label="상위 기준값"
value={dtl?.lastTrsfScrUplmtVl}
/>
<IndicatorItem label="이상치 하한값" value={dtl?.llmtVl} />
<IndicatorItem label="이상치 상한값" value={dtl?.uplmtVl} />
<IndicatorItem label="이상치 하한선" value={dtl?.otlrLlmtLine} />
<IndicatorItem label="이상치 상한선" value={dtl?.otlrUplmtLine} />
</div>
);
};
export default Indicators;