행정지원 검토의견 수정

This commit is contained in:
2026-10-20 10:04:42 +09:00
parent 3a5b48b608
commit 8a98cd7d19
15 changed files with 2012 additions and 1526 deletions
@@ -0,0 +1,22 @@
import { client } from "@/shared/api";
import { ENDPOINT } from "@/shared/config";
import type { RvwOpnnUpdateRequestDto } from "@/shared/model";
const BASE = ENDPOINT.AS_SERVICE.FNRS_CNSLTN_RVW_OPNN;
async function update(
fnrsCnsltnDocNo: string,
rvwOpnnSn: number,
body: RvwOpnnUpdateRequestDto,
): Promise<void> {
await client.put<void>(`${BASE}/${fnrsCnsltnDocNo}/${rvwOpnnSn}`, body);
}
async function deleteFn(fnrsCnsltnDocNo: string, rvwOpnnSn: number): Promise<void> {
await client.delete<void>(`${BASE}/${fnrsCnsltnDocNo}/${rvwOpnnSn}`);
}
export const fnrsCnsltnRvwOpnnService = {
update,
delete: deleteFn,
};
+66 -65
View File
@@ -1,65 +1,66 @@
export { fnrsCnsltnMngService } from "./api/fnrs-cnsltn-service"; export { fnrsCnsltnRvwOpnnService } from "./api/fnrs-cnsltn-rvw-opnn-service";
export { fnrsCnsltnKeys } from "./api/queries"; export { fnrsCnsltnMngService } from "./api/fnrs-cnsltn-service";
export { export { fnrsCnsltnKeys } from "./api/queries";
useChangePrgrsSttsComCd, export {
useDeleteFnrsCnsltnMng, useChangePrgrsSttsComCd,
useFnrsCnsltnFileVrfcResults, useDeleteFnrsCnsltnMng,
useFnrsCnsltnMng, useFnrsCnsltnFileVrfcResults,
useFnrsCnsltnMngPage, useFnrsCnsltnMng,
useRequestActnReviewFnrsCnsltnMng, useFnrsCnsltnMngPage,
useRequestExamineFnrsCnsltnMng, useRequestActnReviewFnrsCnsltnMng,
useSaveApplyFnrsCnsltnMng, useRequestExamineFnrsCnsltnMng,
useSaveFnrsCnsltnMng, useSaveApplyFnrsCnsltnMng,
useSubmitReqSupplementFnrsCnsltnMng, useSaveFnrsCnsltnMng,
useSubmitSupplementFnrsCnsltnMng, useSubmitReqSupplementFnrsCnsltnMng,
useTechReviewFnrsCnsltnMng, useSubmitSupplementFnrsCnsltnMng,
useUpdateFnrsCnsltnMng, useTechReviewFnrsCnsltnMng,
} from "./api/queries"; useUpdateFnrsCnsltnMng,
export type { } from "./api/queries";
BizCstItem, export type {
BzScaleItem, BizCstItem,
CklstResultItem, BzScaleItem,
EsntlAtchFileItem, CklstResultItem,
FnrsCnsltnApplySaveRequestDto, EsntlAtchFileItem,
FnrsCnsltnMngSaveRequestDto, FnrsCnsltnApplySaveRequestDto,
FnrsCnsltnRvwOpnnSaveRequestDto, FnrsCnsltnMngSaveRequestDto,
FnrsCnsltnSplmntDmndItem, FnrsCnsltnRvwOpnnSaveRequestDto,
FnrsSharItem, FnrsCnsltnSplmntDmndItem,
} from "./model/fnrs-cnsltn-apply-payload-schema"; FnrsSharItem,
export { } from "./model/fnrs-cnsltn-apply-payload-schema";
fnrsCnsltnApplySaveSchema, export {
fnrsCnsltnBizCstItemSchema, fnrsCnsltnApplySaveSchema,
fnrsCnsltnBzScaleItemSchema, fnrsCnsltnBizCstItemSchema,
fnrsCnsltnCklstResultItemSchema, fnrsCnsltnBzScaleItemSchema,
fnrsCnsltnEsntlAtchFileItemSchema, fnrsCnsltnCklstResultItemSchema,
fnrsCnsltnMngSaveSchema, fnrsCnsltnEsntlAtchFileItemSchema,
fnrsCnsltnRvwOpnnSaveSchema, fnrsCnsltnMngSaveSchema,
fnrsCnsltnSplmntDmndItemSchema, fnrsCnsltnRvwOpnnSaveSchema,
fnrsSharItemSchema, fnrsCnsltnSplmntDmndItemSchema,
} from "./model/fnrs-cnsltn-apply-payload-schema"; fnrsSharItemSchema,
export type { } from "./model/fnrs-cnsltn-apply-payload-schema";
AtflMngClientResponseDto, export type {
BizCstTreeDto, AtflMngClientResponseDto,
BizSclTreeDto, BizCstTreeDto,
CklstRvwRsltTreeDto, BizSclTreeDto,
DocPrgrsUpdateRequestDto, CklstRvwRsltTreeDto,
ElaprDocPrgrsClientResponseDto, DocPrgrsUpdateRequestDto,
EsntlAtchFileMngTreeResponseDto, ElaprDocPrgrsClientResponseDto,
FnrsCnsltnFileVrfcRsltResponseDto, EsntlAtchFileMngTreeResponseDto,
FnrsCnsltnMngDetResponseDto, FnrsCnsltnFileVrfcRsltResponseDto,
FnrsCnsltnMngResponseDto, FnrsCnsltnMngDetResponseDto,
FnrsCnsltnMngSearchDto, FnrsCnsltnMngResponseDto,
FnrsCnsltnMngService, FnrsCnsltnMngSearchDto,
FnrsCnsltnMngUpdateRequestDto, FnrsCnsltnMngService,
FnrsCnsltnRvwOpnnResponseDto, FnrsCnsltnMngUpdateRequestDto,
FnrsCnsltnSplmntDmndResponseDto, FnrsCnsltnRvwOpnnResponseDto,
RagIndexingInfoDto, FnrsCnsltnSplmntDmndResponseDto,
} from "./model/fnrs-cnsltn-interface"; RagIndexingInfoDto,
export type { } from "./model/fnrs-cnsltn-interface";
EnvoActnReviewReqDto, export type {
FnrsExamineRequestDto, EnvoActnReviewReqDto,
} from "./model/fnrs-cnsltn-payload-schema"; FnrsExamineRequestDto,
export { } from "./model/fnrs-cnsltn-payload-schema";
envoActnReviewReqSchema, export {
fnrsExamineRequestSchema, envoActnReviewReqSchema,
} from "./model/fnrs-cnsltn-payload-schema"; fnrsExamineRequestSchema,
} from "./model/fnrs-cnsltn-payload-schema";
@@ -0,0 +1,22 @@
import { client } from "@/shared/api";
import { ENDPOINT } from "@/shared/config";
import type { RvwOpnnUpdateRequestDto } from "@/shared/model";
const BASE = ENDPOINT.AS_SERVICE.INSTL_SNCN_RVW_OPNN;
async function update(
instlSncnDocNo: string,
rvwOpnnSn: number,
body: RvwOpnnUpdateRequestDto,
): Promise<void> {
await client.put<void>(`${BASE}/${instlSncnDocNo}/${rvwOpnnSn}`, body);
}
async function deleteFn(instlSncnDocNo: string, rvwOpnnSn: number): Promise<void> {
await client.delete<void>(`${BASE}/${instlSncnDocNo}/${rvwOpnnSn}`);
}
export const instlSncnRvwOpnnService = {
update,
delete: deleteFn,
};
+1
View File
@@ -1,3 +1,4 @@
export { instlSncnRvwOpnnService } from "./api/instl-sncn-rvw-opnn-service";
export { instlSncnRegionService, instlSncnService } from "./api/instl-sncn-service"; export { instlSncnRegionService, instlSncnService } from "./api/instl-sncn-service";
export { export {
instlSncnKeys, instlSncnKeys,
@@ -0,0 +1,23 @@
import { client } from "@/shared/api";
import { ENDPOINT } from "@/shared/config";
import type { RvwOpnnUpdateRequestDto } from "@/shared/model";
const BASE = ENDPOINT.AS_SERVICE.SEWER_BSC_PLAN_RVW_OPNNS;
async function update(
sewerBscPlanDocNo: string,
chgCycl: number,
rvwOpnnSn: number,
body: RvwOpnnUpdateRequestDto,
): Promise<void> {
await client.put<void>(`${BASE}/${sewerBscPlanDocNo}/${chgCycl}/${rvwOpnnSn}`, body);
}
async function deleteFn(sewerBscPlanDocNo: string, chgCycl: number, rvwOpnnSn: number): Promise<void> {
await client.delete<void>(`${BASE}/${sewerBscPlanDocNo}/${chgCycl}/${rvwOpnnSn}`);
}
export const sewerBscPlanRvwOpnnService = {
update,
delete: deleteFn,
};
+65 -64
View File
@@ -1,64 +1,65 @@
export { sewerBscPlanKeys } from "./api/queries"; export { sewerBscPlanKeys } from "./api/queries";
export { export {
useDeleteSewerBscPlan, useDeleteSewerBscPlan,
useSaveApplySewerBscPlan, useSaveApplySewerBscPlan,
useSaveSewerBscPlan, useSaveSewerBscPlan,
useSewerBscPlan, useSewerBscPlan,
useSewerBscPlanDetails, useSewerBscPlanDetails,
useSewerBscPlanPage, useSewerBscPlanPage,
useSubmitReqSupplementSewerBscPlan, useSubmitReqSupplementSewerBscPlan,
useSubmitSupplementSewerBscPlan, useSubmitSupplementSewerBscPlan,
useTechReviewSewerBscPlan, useTechReviewSewerBscPlan,
useUpdateSewerBscPlan, useUpdateSewerBscPlan,
} from "./api/queries"; } from "./api/queries";
export { sewerBscPlanService } from "./api/sewer-bsc-plan-service"; export { sewerBscPlanRvwOpnnService } from "./api/sewer-bsc-plan-rvw-opnn-service";
export type { export { sewerBscPlanService } from "./api/sewer-bsc-plan-service";
CklstResultItem, export type {
EsntlAtchFileItem, CklstResultItem,
SewerBscPlanApplySaveRequestDto, EsntlAtchFileItem,
SewerBscPlanBizCstItem, SewerBscPlanApplySaveRequestDto,
SewerBscPlanDtlSaveRequestDto, SewerBscPlanBizCstItem,
SewerBscPlanFnrsCstItem, SewerBscPlanDtlSaveRequestDto,
SewerBscPlanOtlnItem, SewerBscPlanFnrsCstItem,
SewerBscPlanRvwOpnnItem, SewerBscPlanOtlnItem,
SewerBscPlanSaveRequestDto, SewerBscPlanRvwOpnnItem,
SewerBscPlanSplmntDmndItem, SewerBscPlanSaveRequestDto,
SewerBscPlanTmplntDtlItem, SewerBscPlanSplmntDmndItem,
SewerBscPlanTmplntItem, SewerBscPlanTmplntDtlItem,
SewerBscPlanTmplntTmprStrgItem, SewerBscPlanTmplntItem,
} from "./model/sewer-bsc-plan-apply-payload-schema"; SewerBscPlanTmplntTmprStrgItem,
export { } from "./model/sewer-bsc-plan-apply-payload-schema";
sewerBscPlanApplySaveSchema, export {
sewerBscPlanBizCstItemSchema, sewerBscPlanApplySaveSchema,
sewerBscPlanCklstResultItemSchema, sewerBscPlanBizCstItemSchema,
sewerBscPlanDtlSaveSchema, sewerBscPlanCklstResultItemSchema,
sewerBscPlanEsntlAtchFileItemSchema, sewerBscPlanDtlSaveSchema,
sewerBscPlanFnrsCstItemSchema, sewerBscPlanEsntlAtchFileItemSchema,
sewerBscPlanOtlnItemSchema, sewerBscPlanFnrsCstItemSchema,
sewerBscPlanRvwOpnnItemSchema, sewerBscPlanOtlnItemSchema,
sewerBscPlanSaveSchema, sewerBscPlanRvwOpnnItemSchema,
sewerBscPlanSplmntDmndItemSchema, sewerBscPlanSaveSchema,
sewerBscPlanTmplntDtlItemSchema, sewerBscPlanSplmntDmndItemSchema,
sewerBscPlanTmplntItemSchema, sewerBscPlanTmplntDtlItemSchema,
sewerBscPlanTmplntTmprStrgItemSchema, sewerBscPlanTmplntItemSchema,
} from "./model/sewer-bsc-plan-apply-payload-schema"; sewerBscPlanTmplntTmprStrgItemSchema,
export type { } from "./model/sewer-bsc-plan-apply-payload-schema";
AtflMngClientResponseDto, export type {
CklstRvwRsltTreeDto, AtflMngClientResponseDto,
EsntlAtchFileMngTreeResponseDto, CklstRvwRsltTreeDto,
SewerBscPlanApplySaveResponseDto, EsntlAtchFileMngTreeResponseDto,
SewerBscPlanBizCstResponseDto, SewerBscPlanApplySaveResponseDto,
SewerBscPlanDetResponseDto, SewerBscPlanBizCstResponseDto,
SewerBscPlanDtlResponseDto, SewerBscPlanDetResponseDto,
SewerBscPlanFnrsCstResponseDto, SewerBscPlanDtlResponseDto,
SewerBscPlanOtlnResponseDto, SewerBscPlanFnrsCstResponseDto,
SewerBscPlanResponseDto, SewerBscPlanOtlnResponseDto,
SewerBscPlanRvwOpnnResponseDto, SewerBscPlanResponseDto,
SewerBscPlanSearchRequestDto, SewerBscPlanRvwOpnnResponseDto,
SewerBscPlanService, SewerBscPlanSearchRequestDto,
SewerBscPlanSplmntDmndResponseDto, SewerBscPlanService,
SewerBscPlanTmplntDtlResponseDto, SewerBscPlanSplmntDmndResponseDto,
SewerBscPlanTmplntResponseDto, SewerBscPlanTmplntDtlResponseDto,
SewerBscPlanTmplntTmprStrgResponseDto, SewerBscPlanTmplntResponseDto,
SewerBscPlanUpdateRequestDto, SewerBscPlanTmplntTmprStrgResponseDto,
} from "./model/sewer-bsc-plan-interface"; SewerBscPlanUpdateRequestDto,
} from "./model/sewer-bsc-plan-interface";
@@ -1,338 +1,336 @@
"use client"; "use client";
import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { dayjs, getDefaultFileKey, useTus } from "@/shared/lib"; import { useQueryClient } from "@tanstack/react-query";
import { TextShimmer } from "@/shared/ui";
import { SectionCollapsible } from "@/shared/ui"; import { getDefaultFileKey, useTus, useUserStore } from "@/shared/lib";
import { Field, FieldLabel, FieldSet } from "@/shared/ui/field"; import { TextShimmer } from "@/shared/ui";
import { AttachmentDownloadLink, attachService } from "@/entities/attach"; import { SectionCollapsible } from "@/shared/ui";
import type { DesignCnstnRvwOpnnResponseDto } from "@/entities/design-cnstn"; import { Field, FieldLabel, FieldSet } from "@/shared/ui/field";
import { import { attachService } from "@/entities/attach";
Button, import {
RadioGroup, designCnstnKeys,
RadioGroupItem, type DesignCnstnRvwOpnnResponseDto,
Table, designCnstnRvwOpnnService,
TableBody, } from "@/entities/design-cnstn";
TableCell, import { RvwOpnnListTable } from "@/widgets/pbadms-sprt";
TableHead, import {
TableHeader, Button,
TableRow, RadioGroup,
Textarea, RadioGroupItem,
} from "@common/components"; Table,
TableCell,
import type { TableHead,
ReviewOpinionFormData, TableHeader,
ReviewOpinionGetFormDataResult, TableRow,
} from "../../lib/review-opinion-utils"; Textarea,
import type { ReviewStepCode } from "../../model/view-types"; } from "@common/components";
import { REVIEW_STEP_LABELS } from "../../model/view-types";
import type {
const RVW_OPNN_FILE_KEY_PREFIX = "rvw-opnn::"; ReviewOpinionFormData,
ReviewOpinionGetFormDataResult,
interface TechReviewOpinionSectionProps { } from "../../lib/review-opinion-utils";
rvwList: DesignCnstnRvwOpnnResponseDto[]; import type { ReviewStepCode } from "../../model/view-types";
editableReviewStep?: ReviewStepCode; import { REVIEW_STEP_LABELS } from "../../model/view-types";
atrzSeComCdList?: string[];
isAtrzLoading?: boolean; const RVW_OPNN_FILE_KEY_PREFIX = "rvw-opnn::";
}
interface TechReviewOpinionSectionProps {
export interface TechReviewOpinionSectionHandle { rvwList: DesignCnstnRvwOpnnResponseDto[];
getFormData: () => ReviewOpinionGetFormDataResult | null; editableReviewStep?: ReviewStepCode;
resetForm: () => void; atrzSeComCdList?: string[];
} isAtrzLoading?: boolean;
}
interface TechReviewOpinionTableProps {
items: DesignCnstnRvwOpnnResponseDto[]; export interface TechReviewOpinionSectionHandle {
} getFormData: () => ReviewOpinionGetFormDataResult | null;
resetForm: () => void;
interface UploadedOpinionFile { }
fileName: string;
fileKey: string; interface TechReviewOpinionTableProps {
atflId?: string; items: DesignCnstnRvwOpnnResponseDto[];
atflCd?: string; isReviewTurn: boolean;
} }
const EMPTY_FORM_DATA: ReviewOpinionFormData = { interface UploadedOpinionFile {
rvwRsltCn: "", fileName: string;
rvwRsltAnmlyYn: "", fileKey: string;
atchFileGroupId: "", atflId?: string;
opnrSeComCd: "", atflCd?: string;
}; }
function createRvwOpnnUploadKey(file: File) { const EMPTY_FORM_DATA: ReviewOpinionFormData = {
return `${RVW_OPNN_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`; rvwRsltCn: "",
} rvwRsltAnmlyYn: "",
atchFileGroupId: "",
function hasFormContent(formData: ReviewOpinionFormData) { opnrSeComCd: "",
return Boolean(formData.rvwRsltCn.trim() || formData.rvwRsltAnmlyYn || formData.atchFileGroupId); };
}
function createRvwOpnnUploadKey(file: File) {
const TechReviewOpinionSection = forwardRef< return `${RVW_OPNN_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`;
TechReviewOpinionSectionHandle, }
TechReviewOpinionSectionProps
>(function TechReviewOpinionSection( function hasFormContent(formData: ReviewOpinionFormData) {
{ rvwList, editableReviewStep, atrzSeComCdList = [], isAtrzLoading = false }, return Boolean(formData.rvwRsltCn.trim() || formData.rvwRsltAnmlyYn || formData.atchFileGroupId);
ref, }
) {
const canWriteOpinion = !isAtrzLoading && atrzSeComCdList.includes("ATRZ02"); const TechReviewOpinionSection = forwardRef<
const [formData, setFormData] = useState<ReviewOpinionFormData>({ TechReviewOpinionSectionHandle,
...EMPTY_FORM_DATA, TechReviewOpinionSectionProps
opnrSeComCd: editableReviewStep ?? "", >(function TechReviewOpinionSection(
}); { rvwList, editableReviewStep, atrzSeComCdList = [], isAtrzLoading = false },
const [uploadedFile, setUploadedFile] = useState<UploadedOpinionFile | null>(null); ref,
) {
useEffect(() => { const canWriteOpinion = !isAtrzLoading && atrzSeComCdList.includes("ATRZ02");
setFormData((prev) => ({ const [formData, setFormData] = useState<ReviewOpinionFormData>({
...prev, ...EMPTY_FORM_DATA,
opnrSeComCd: editableReviewStep ?? "", opnrSeComCd: editableReviewStep ?? "",
})); });
}, [editableReviewStep]); const [uploadedFile, setUploadedFile] = useState<UploadedOpinionFile | null>(null);
const { uploadFileAsync, isUploading, uploads } = useTus({ useEffect(() => {
onSuccess: (atflCd, atflId, _file, fileKey) => { setFormData((prev) => ({
if (!atflCd || !atflId) return; ...prev,
opnrSeComCd: editableReviewStep ?? "",
setFormData((prev) => ({ ...prev, atchFileGroupId: atflCd })); }));
setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev)); }, [editableReviewStep]);
},
onError: (_error, _file, fileKey) => { const { uploadFileAsync, isUploading, uploads } = useTus({
setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev)); onSuccess: (atflCd, atflId, _file, fileKey) => {
}, if (!atflCd || !atflId) return;
});
setFormData((prev) => ({ ...prev, atchFileGroupId: atflCd }));
useImperativeHandle( setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev));
ref, },
() => ({ onError: (_error, _file, fileKey) => {
getFormData: () => { setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev));
if (!canWriteOpinion || !editableReviewStep || !hasFormContent(formData)) { },
return null; });
}
useImperativeHandle(
return { ref,
formData: { () => ({
...formData, getFormData: () => {
opnrSeComCd: editableReviewStep, if (!canWriteOpinion || !editableReviewStep || !hasFormContent(formData)) {
}, return null;
rvwList, }
};
}, return {
resetForm: () => { formData: {
setFormData({ ...formData,
...EMPTY_FORM_DATA, opnrSeComCd: editableReviewStep,
opnrSeComCd: editableReviewStep ?? "", },
}); rvwList,
setUploadedFile(null); };
}, },
}), resetForm: () => {
[canWriteOpinion, editableReviewStep, formData, rvwList], setFormData({
); ...EMPTY_FORM_DATA,
opnrSeComCd: editableReviewStep ?? "",
const kecoRvwList = rvwList.filter((item) => item.opnrSeComCd === "KECO"); });
const hasKecoSection = setUploadedFile(null);
kecoRvwList.length > 0 || (editableReviewStep === "KECO" && canWriteOpinion); },
}),
if (!hasKecoSection) { [canWriteOpinion, editableReviewStep, formData, rvwList],
return null; );
}
const kecoRvwList = rvwList.filter((item) => item.opnrSeComCd === "KECO");
async function handleFileUpload(files: FileList | null) { const hasKecoSection =
if (!files || files.length === 0) return; kecoRvwList.length > 0 || (editableReviewStep === "KECO" && canWriteOpinion);
const file = files[0]; if (!hasKecoSection) {
const fileKey = createRvwOpnnUploadKey(file); return null;
const existingAtflCd = formData.atchFileGroupId; }
setUploadedFile({ fileName: file.name, fileKey }); async function handleFileUpload(files: FileList | null) {
if (!files || files.length === 0) return;
try {
await uploadFileAsync(file, { const file = files[0];
fileKey, const fileKey = createRvwOpnnUploadKey(file);
metadata: existingAtflCd ? { atflCd: existingAtflCd } : undefined, const existingAtflCd = formData.atchFileGroupId;
});
} catch { setUploadedFile({ fileName: file.name, fileKey });
// onError callback handles cleanup
} try {
} await uploadFileAsync(file, {
fileKey,
async function handleFileRemove() { metadata: existingAtflCd ? { atflCd: existingAtflCd } : undefined,
if (!uploadedFile) return; });
} catch {
uploads[uploadedFile.fileKey]?.abort(); // onError callback handles cleanup
}
if (uploadedFile.atflId) { }
try {
await attachService.deleteAttachmentByAtflId(uploadedFile.atflId); async function handleFileRemove() {
} catch (error) { if (!uploadedFile) return;
console.error("검토의견 첨부파일 삭제 실패:", error);
} uploads[uploadedFile.fileKey]?.abort();
}
if (uploadedFile.atflId) {
setUploadedFile(null); try {
setFormData((prev) => ({ ...prev, atchFileGroupId: "" })); await attachService.deleteAttachmentByAtflId(uploadedFile.atflId);
} } catch (error) {
console.error("검토의견 첨부파일 삭제 실패:", error);
function renderOpinionForm(reviewStep: ReviewStepCode) { }
if (editableReviewStep !== reviewStep || !canWriteOpinion) return null; }
const uploading = uploadedFile ? (isUploading[uploadedFile.fileKey] ?? false) : false; setUploadedFile(null);
setFormData((prev) => ({ ...prev, atchFileGroupId: "" }));
return ( }
<div className="space-y-2">
<h4 className="text-xl font-semibold">검토의견 작성</h4> function isReviewTurn(reviewStep: ReviewStepCode) {
<Table caption="검토의견 작성으로 의견내용, 검토결과, 첨부파일 정보 제공" variant="secondary"> return editableReviewStep === reviewStep && canWriteOpinion;
<TableHeader> }
<TableRow>
<TableHead scope="row" className="w-[12rem]">의견내용</TableHead> function renderOpinionForm(reviewStep: ReviewStepCode) {
<TableCell> if (!isReviewTurn(reviewStep)) return null;
<Textarea
value={formData.rvwRsltCn} const uploading = uploadedFile ? (isUploading[uploadedFile.fileKey] ?? false) : false;
onChange={(event) =>
setFormData((prev) => ({ ...prev, rvwRsltCn: event.target.value })) return (
} <div className="space-y-2">
placeholder="의견내용을 입력하세요" <h4 className="text-xl font-semibold">검토의견 작성</h4>
rows={4} <Table
className="min-h-[8rem] !text-xl" caption="검토의견 작성으로 의견내용, 검토결과, 첨부파일 정보 제공"
/> variant="secondary"
</TableCell> >
</TableRow> <TableHeader>
<TableRow> <TableRow>
<TableHead scope="row">검토결과</TableHead> <TableHead scope="row" className="w-[12rem]">
<TableCell> 의견내용
<FieldSet> </TableHead>
<RadioGroup <TableCell>
value={formData.rvwRsltAnmlyYn} <Textarea
onValueChange={(value) => value={formData.rvwRsltCn}
setFormData((prev) => ({ onChange={(event) =>
...prev, setFormData((prev) => ({ ...prev, rvwRsltCn: event.target.value }))
rvwRsltAnmlyYn: value as ReviewOpinionFormData["rvwRsltAnmlyYn"], }
})) placeholder="의견내용을 입력하세요"
} rows={4}
> className="min-h-[8rem] !text-xl"
<div className="flex flex-wrap gap-4"> />
<FieldLabel </TableCell>
htmlFor={`rvw-opnn-normal-${reviewStep}`} </TableRow>
className="!w-auto border-none" <TableRow>
> <TableHead scope="row">검토결과</TableHead>
<Field orientation="horizontal" className="w-auto"> <TableCell>
<RadioGroupItem value="N" id={`rvw-opnn-normal-${reviewStep}`} /> <FieldSet>
<span className="font-normal">정상</span> <RadioGroup
</Field> value={formData.rvwRsltAnmlyYn}
</FieldLabel> onValueChange={(value) =>
<FieldLabel setFormData((prev) => ({
htmlFor={`rvw-opnn-abnormal-${reviewStep}`} ...prev,
className="!w-auto border-none" rvwRsltAnmlyYn: value as ReviewOpinionFormData["rvwRsltAnmlyYn"],
> }))
<Field orientation="horizontal" className="w-auto"> }
<RadioGroupItem value="Y" id={`rvw-opnn-abnormal-${reviewStep}`} /> >
<span className="font-normal">이상</span> <div className="flex flex-wrap gap-4">
</Field> <FieldLabel
</FieldLabel> htmlFor={`rvw-opnn-normal-${reviewStep}`}
</div> className="!w-auto border-none"
</RadioGroup> >
</FieldSet> <Field orientation="horizontal" className="w-auto">
</TableCell> <RadioGroupItem value="N" id={`rvw-opnn-normal-${reviewStep}`} />
</TableRow> <span className="font-normal">정상</span>
<TableRow> </Field>
<TableHead scope="row">첨부파일</TableHead> </FieldLabel>
<TableCell> <FieldLabel
{uploadedFile ? ( htmlFor={`rvw-opnn-abnormal-${reviewStep}`}
<div className="flex items-center gap-2"> className="!w-auto border-none"
<TextShimmer className="text-xl" active={uploading}> >
{uploadedFile.fileName} <Field orientation="horizontal" className="w-auto">
</TextShimmer> <RadioGroupItem value="Y" id={`rvw-opnn-abnormal-${reviewStep}`} />
<Button <span className="font-normal">이상</span>
size="icon" </Field>
onClick={(e) => { </FieldLabel>
e.preventDefault(); </div>
void handleFileRemove(); </RadioGroup>
}} </FieldSet>
disabled={uploading} </TableCell>
className="size-8 !bg-destructive" </TableRow>
> <TableRow>
<i className="diveicon di-x text-xs" aria-label="삭제" /> <TableHead scope="row">첨부파일</TableHead>
</Button> <TableCell>
</div> {uploadedFile ? (
) : ( <div className="flex items-center gap-2">
<label> <TextShimmer className="text-xl" active={uploading}>
<input {uploadedFile.fileName}
type="file" </TextShimmer>
className="hidden" <Button
onChange={(event) => { size="icon"
void handleFileUpload(event.target.files); onClick={(e) => {
event.target.value = ""; e.preventDefault();
}} void handleFileRemove();
/> }}
<Button size="sm" variant="outline" type="button" asChild> disabled={uploading}
<span>파일 선택</span> className="size-8 !bg-destructive"
</Button> >
</label> <i className="diveicon di-x text-xs" aria-label="삭제" />
)} </Button>
</TableCell> </div>
</TableRow> ) : (
</TableHeader> <label>
</Table> <input
</div> type="file"
); className="hidden"
} onChange={(event) => {
void handleFileUpload(event.target.files);
return ( event.target.value = "";
<SectionCollapsible title={`${REVIEW_STEP_LABELS.KECO} 검토의견`}> }}
<div className="space-y-6"> />
{kecoRvwList.length > 0 ? <TechReviewOpinionTable items={kecoRvwList} /> : null} <Button size="sm" variant="outline" type="button" asChild>
{renderOpinionForm("KECO")} <span>파일 선택</span>
</div> </Button>
</SectionCollapsible> </label>
); )}
}); </TableCell>
</TableRow>
function TechReviewOpinionTable({ items }: TechReviewOpinionTableProps) { </TableHeader>
return ( </Table>
<div className="overflow-x-auto"> </div>
<Table caption="검토의견 목록으로 의견자명, 의견내용, 검토결과, 첨부파일, 등록일시 정보 제공" variant="secondary"> );
<colgroup> }
<col width="10%" />
<col width="55%" /> return (
<col width="5%" /> <SectionCollapsible title={`${REVIEW_STEP_LABELS.KECO} 검토의견`}>
<col width="20%" /> <div className="space-y-6">
<col width="10%" /> {kecoRvwList.length > 0 ? (
</colgroup> <TechReviewOpinionTable items={kecoRvwList} isReviewTurn={isReviewTurn("KECO")} />
<TableHeader> ) : null}
<TableRow> {renderOpinionForm("KECO")}
<TableHead>의견자명</TableHead> </div>
<TableHead>의견내용</TableHead> </SectionCollapsible>
<TableHead>검토결과</TableHead> );
<TableHead>첨부파일</TableHead> });
<TableHead>등록일시</TableHead>
</TableRow> function getRvwOpnnIds(item: DesignCnstnRvwOpnnResponseDto) {
</TableHeader> if (!item.designCnstnDocNo || item.rvwOpnnSn == null) {
<TableBody> throw new Error("검토의견 식별값이 없습니다.");
{items.map((item) => ( }
<TableRow key={`${item.designCnstnDocNo}_${item.rvwOpnnSn}`}> return [item.designCnstnDocNo, item.rvwOpnnSn] as const;
<TableCell align="center">{item.opnrNm}</TableCell> }
<TableCell align="left">{item.rvwRsltCn || "-"}</TableCell>
<TableCell align="center"> function TechReviewOpinionTable({ items, isReviewTurn }: TechReviewOpinionTableProps) {
{item.rvwRsltAnmlyYn === "Y" ? "이상" : item.rvwRsltAnmlyYn === "N" ? "정상" : "-"} const queryClient = useQueryClient();
</TableCell> const currentUserUuid = useUserStore((state) => state.userInfo?.userUnqId);
<TableCell align="center">
{item.atchFileInfo?.atflCd ? ( return (
<AttachmentDownloadLink <RvwOpnnListTable
atflCd={item.atchFileInfo.atflCd} items={items}
fileName={item.atchFileInfo.orgnlFileNm || "다운로드"} getRowKey={(item) => `${item.designCnstnDocNo}_${item.rvwOpnnSn}`}
/> currentUserUuid={currentUserUuid}
) : ( isReviewTurn={isReviewTurn}
"-" onUpdate={async (item, body) => {
)} await designCnstnRvwOpnnService.update(...getRvwOpnnIds(item), body);
</TableCell> await queryClient.invalidateQueries({ queryKey: designCnstnKeys.all });
<TableCell align="center"> }}
{item.regDt ? dayjs(item.regDt).format("YYYY-MM-DD HH:mm:ss") : "-"} onDelete={async (item) => {
</TableCell> await designCnstnRvwOpnnService.delete(...getRvwOpnnIds(item));
</TableRow> await queryClient.invalidateQueries({ queryKey: designCnstnKeys.all });
))} }}
</TableBody> />
</Table> );
</div> }
);
} export { TechReviewOpinionSection };
export { TechReviewOpinionSection };
@@ -1,352 +1,347 @@
"use client"; "use client";
import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { dayjs, getDefaultFileKey, useTus } from "@/shared/lib"; import { useQueryClient } from "@tanstack/react-query";
import { AttachmentFileField, SectionCollapsible } from "@/shared/ui";
import { Field, FieldLabel, FieldSet } from "@/shared/ui/field"; import { getDefaultFileKey, useTus, useUserStore } from "@/shared/lib";
import { import { AttachmentFileField, SectionCollapsible } from "@/shared/ui";
AttachmentDownloadLink, import { Field, FieldLabel, FieldSet } from "@/shared/ui/field";
attachService, import { attachService, useDownloadAttachmentByAtflId } from "@/entities/attach";
useDownloadAttachmentByAtflId, import {
} from "@/entities/attach"; fnrsCnsltnKeys,
import type { FnrsCnsltnRvwOpnnResponseDto } from "@/entities/fnrs-cnsltn"; type FnrsCnsltnRvwOpnnResponseDto,
import { fnrsCnsltnRvwOpnnService,
RadioGroup, } from "@/entities/fnrs-cnsltn";
RadioGroupItem, import { RvwOpnnListTable } from "@/widgets/pbadms-sprt";
Table, import {
TableBody, RadioGroup,
TableCell, RadioGroupItem,
TableHead, Table,
TableHeader, TableCell,
TableRow, TableHead,
Textarea, TableHeader,
} from "@common/components"; TableRow,
Textarea,
import type { } from "@common/components";
ReviewOpinionFormData,
ReviewOpinionGetFormDataResult, import type {
} from "../../lib/review-opinion-utils"; ReviewOpinionFormData,
import type { ReviewStepCode } from "../../model/view-types"; ReviewOpinionGetFormDataResult,
import { REVIEW_STEP_LABELS } from "../../model/view-types"; } from "../../lib/review-opinion-utils";
import type { ReviewStepCode } from "../../model/view-types";
const RVW_OPNN_FILE_KEY_PREFIX = "rvw-opnn::"; import { REVIEW_STEP_LABELS } from "../../model/view-types";
interface TechReviewOpinionSectionProps { const RVW_OPNN_FILE_KEY_PREFIX = "rvw-opnn::";
rvwList: FnrsCnsltnRvwOpnnResponseDto[];
editableReviewStep?: ReviewStepCode; interface TechReviewOpinionSectionProps {
atrzSeComCdList?: string[]; rvwList: FnrsCnsltnRvwOpnnResponseDto[];
isAtrzLoading?: boolean; editableReviewStep?: ReviewStepCode;
} atrzSeComCdList?: string[];
isAtrzLoading?: boolean;
export interface TechReviewOpinionSectionHandle { }
getFormData: () => ReviewOpinionGetFormDataResult | null;
resetForm: () => void; export interface TechReviewOpinionSectionHandle {
} getFormData: () => ReviewOpinionGetFormDataResult | null;
resetForm: () => void;
interface TechReviewOpinionTableProps { }
items: FnrsCnsltnRvwOpnnResponseDto[];
} interface TechReviewOpinionTableProps {
items: FnrsCnsltnRvwOpnnResponseDto[];
interface UploadedOpinionFile { isReviewTurn: boolean;
fileName: string; }
fileKey: string;
atflId?: string; interface UploadedOpinionFile {
atflCd?: string; fileName: string;
} fileKey: string;
atflId?: string;
const EMPTY_FORM_DATA: ReviewOpinionFormData = { atflCd?: string;
rvwRsltCn: "", }
rvwRsltAnmlyYn: "",
atchFileGroupId: "", const EMPTY_FORM_DATA: ReviewOpinionFormData = {
opnrSeComCd: "", rvwRsltCn: "",
}; rvwRsltAnmlyYn: "",
atchFileGroupId: "",
function createRvwOpnnUploadKey(file: File) { opnrSeComCd: "",
return `${RVW_OPNN_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`; };
}
function createRvwOpnnUploadKey(file: File) {
function hasFormContent(formData: ReviewOpinionFormData) { return `${RVW_OPNN_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`;
return Boolean(formData.rvwRsltCn.trim() || formData.rvwRsltAnmlyYn || formData.atchFileGroupId); }
}
function hasFormContent(formData: ReviewOpinionFormData) {
const TechReviewOpinionSection = forwardRef< return Boolean(formData.rvwRsltCn.trim() || formData.rvwRsltAnmlyYn || formData.atchFileGroupId);
TechReviewOpinionSectionHandle, }
TechReviewOpinionSectionProps
>(function TechReviewOpinionSection( const TechReviewOpinionSection = forwardRef<
{ rvwList, editableReviewStep, atrzSeComCdList = [], isAtrzLoading = false }, TechReviewOpinionSectionHandle,
ref, TechReviewOpinionSectionProps
) { >(function TechReviewOpinionSection(
const canWriteKecoOpinion = !isAtrzLoading && atrzSeComCdList.includes("ATRZ02"); { rvwList, editableReviewStep, atrzSeComCdList = [], isAtrzLoading = false },
const [formData, setFormData] = useState<ReviewOpinionFormData>({ ref,
...EMPTY_FORM_DATA, ) {
opnrSeComCd: editableReviewStep ?? "", const canWriteKecoOpinion = !isAtrzLoading && atrzSeComCdList.includes("ATRZ02");
}); const [formData, setFormData] = useState<ReviewOpinionFormData>({
const [uploadedFile, setUploadedFile] = useState<UploadedOpinionFile | null>(null); ...EMPTY_FORM_DATA,
const { mutate: downloadByAtflId } = useDownloadAttachmentByAtflId(); opnrSeComCd: editableReviewStep ?? "",
});
useEffect(() => { const [uploadedFile, setUploadedFile] = useState<UploadedOpinionFile | null>(null);
setFormData((prev) => ({ const { mutate: downloadByAtflId } = useDownloadAttachmentByAtflId();
...prev,
opnrSeComCd: editableReviewStep ?? "", useEffect(() => {
})); setFormData((prev) => ({
}, [editableReviewStep]); ...prev,
opnrSeComCd: editableReviewStep ?? "",
const { uploadFileAsync, isUploading, uploads } = useTus({ }));
onSuccess: (atflCd, atflId, _file, fileKey) => { }, [editableReviewStep]);
if (!atflCd || !atflId) return;
const { uploadFileAsync, isUploading, uploads } = useTus({
setFormData((prev) => ({ ...prev, atchFileGroupId: atflCd })); onSuccess: (atflCd, atflId, _file, fileKey) => {
setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev)); if (!atflCd || !atflId) return;
},
onError: (_error, _file, fileKey) => { setFormData((prev) => ({ ...prev, atchFileGroupId: atflCd }));
setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev)); setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev));
}, },
}); onError: (_error, _file, fileKey) => {
setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev));
useImperativeHandle( },
ref, });
() => ({
getFormData: () => { useImperativeHandle(
if (!editableReviewStep || !hasFormContent(formData)) { ref,
return null; () => ({
} getFormData: () => {
if (editableReviewStep === "KECO" && !canWriteKecoOpinion) { if (!editableReviewStep || !hasFormContent(formData)) {
return null; return null;
} }
if (editableReviewStep === "KECO" && !canWriteKecoOpinion) {
return { return null;
formData: { }
...formData,
opnrSeComCd: editableReviewStep, return {
}, formData: {
rvwList, ...formData,
}; opnrSeComCd: editableReviewStep,
}, },
resetForm: () => { rvwList,
setFormData({ };
...EMPTY_FORM_DATA, },
opnrSeComCd: editableReviewStep ?? "", resetForm: () => {
}); setFormData({
setUploadedFile(null); ...EMPTY_FORM_DATA,
}, opnrSeComCd: editableReviewStep ?? "",
}), });
[canWriteKecoOpinion, editableReviewStep, formData, rvwList], setUploadedFile(null);
); },
}),
const envRvwList = rvwList.filter((item) => item.opnrSeComCd === "ENV"); [canWriteKecoOpinion, editableReviewStep, formData, rvwList],
const kecoRvwList = rvwList.filter((item) => item.opnrSeComCd === "KECO"); );
const hasEnvSection = envRvwList.length > 0 || editableReviewStep === "ENV"; const envRvwList = rvwList.filter((item) => item.opnrSeComCd === "ENV");
const hasKecoSection = kecoRvwList.length > 0 || editableReviewStep === "KECO"; const kecoRvwList = rvwList.filter((item) => item.opnrSeComCd === "KECO");
if (!hasEnvSection && !hasKecoSection) { const hasEnvSection = envRvwList.length > 0 || editableReviewStep === "ENV";
return null; const hasKecoSection = kecoRvwList.length > 0 || editableReviewStep === "KECO";
}
if (!hasEnvSection && !hasKecoSection) {
async function handleFileUpload(files: FileList | null) { return null;
if (!files || files.length === 0) return; }
const file = files[0]; async function handleFileUpload(files: FileList | null) {
const fileKey = createRvwOpnnUploadKey(file); if (!files || files.length === 0) return;
const existingAtflCd = formData.atchFileGroupId;
const file = files[0];
setUploadedFile({ fileName: file.name, fileKey }); const fileKey = createRvwOpnnUploadKey(file);
const existingAtflCd = formData.atchFileGroupId;
try {
await uploadFileAsync(file, { setUploadedFile({ fileName: file.name, fileKey });
fileKey,
metadata: existingAtflCd ? { atflCd: existingAtflCd } : undefined, try {
}); await uploadFileAsync(file, {
} catch { fileKey,
// onError callback handles cleanup metadata: existingAtflCd ? { atflCd: existingAtflCd } : undefined,
} });
} } catch {
// onError callback handles cleanup
async function handleFileRemove() { }
if (!uploadedFile) return; }
uploads[uploadedFile.fileKey]?.abort(); async function handleFileRemove() {
if (!uploadedFile) return;
if (uploadedFile.atflId) {
try { uploads[uploadedFile.fileKey]?.abort();
await attachService.deleteAttachmentByAtflId(uploadedFile.atflId);
} catch (error) { if (uploadedFile.atflId) {
console.error("검토의견 첨부파일 삭제 실패:", error); try {
} await attachService.deleteAttachmentByAtflId(uploadedFile.atflId);
} } catch (error) {
console.error("검토의견 첨부파일 삭제 실패:", error);
setUploadedFile(null); }
setFormData((prev) => ({ ...prev, atchFileGroupId: "" })); }
}
setUploadedFile(null);
function renderOpinionForm(reviewStep: ReviewStepCode) { setFormData((prev) => ({ ...prev, atchFileGroupId: "" }));
if (editableReviewStep !== reviewStep) return null; }
if (reviewStep === "KECO" && !canWriteKecoOpinion) return null;
function isReviewTurn(reviewStep: ReviewStepCode) {
const uploading = uploadedFile ? (isUploading[uploadedFile.fileKey] ?? false) : false; if (editableReviewStep !== reviewStep) return false;
if (reviewStep === "KECO" && !canWriteKecoOpinion) return false;
return ( return true;
<div className="space-y-2"> }
<h4 className="text-xl font-semibold">검토의견 작성</h4>
<Table caption="검토의견 작성으로 의견내용, 검토결과, 첨부파일 정보 제공" variant="secondary"> function renderOpinionForm(reviewStep: ReviewStepCode) {
<TableHeader> if (!isReviewTurn(reviewStep)) return null;
<TableRow>
<TableHead className="w-[12rem]">의견내용</TableHead> const uploading = uploadedFile ? (isUploading[uploadedFile.fileKey] ?? false) : false;
<TableCell>
<Textarea return (
value={formData.rvwRsltCn} <div className="space-y-2">
onChange={(event) => <h4 className="text-xl font-semibold">검토의견 작성</h4>
setFormData((prev) => ({ ...prev, rvwRsltCn: event.target.value })) <Table
} caption="검토의견 작성으로 의견내용, 검토결과, 첨부파일 정보 제공"
placeholder="의견내용을 입력하세요" variant="secondary"
rows={4} >
className="min-h-[8rem] !text-xl" <TableHeader>
/> <TableRow>
</TableCell> <TableHead className="w-[12rem]">의견내용</TableHead>
</TableRow> <TableCell>
<TableRow> <Textarea
<TableHead>검토결과</TableHead> value={formData.rvwRsltCn}
<TableCell> onChange={(event) =>
<FieldSet> setFormData((prev) => ({ ...prev, rvwRsltCn: event.target.value }))
<RadioGroup }
value={formData.rvwRsltAnmlyYn} placeholder="의견내용을 입력하세요"
onValueChange={(value) => rows={4}
setFormData((prev) => ({ className="min-h-[8rem] !text-xl"
...prev, />
rvwRsltAnmlyYn: value as ReviewOpinionFormData["rvwRsltAnmlyYn"], </TableCell>
})) </TableRow>
} <TableRow>
> <TableHead>검토결과</TableHead>
<div className="flex flex-wrap gap-4"> <TableCell>
<FieldLabel <FieldSet>
htmlFor={`rvw-opnn-normal-${reviewStep}`} <RadioGroup
className="!w-auto border-none" value={formData.rvwRsltAnmlyYn}
> onValueChange={(value) =>
<Field orientation="horizontal" className="w-auto"> setFormData((prev) => ({
<RadioGroupItem value="N" id={`rvw-opnn-normal-${reviewStep}`} /> ...prev,
<span className="font-normal">정상</span> rvwRsltAnmlyYn: value as ReviewOpinionFormData["rvwRsltAnmlyYn"],
</Field> }))
</FieldLabel> }
<FieldLabel >
htmlFor={`rvw-opnn-abnormal-${reviewStep}`} <div className="flex flex-wrap gap-4">
className="!w-auto border-none" <FieldLabel
> htmlFor={`rvw-opnn-normal-${reviewStep}`}
<Field orientation="horizontal" className="w-auto"> className="!w-auto border-none"
<RadioGroupItem value="Y" id={`rvw-opnn-abnormal-${reviewStep}`} /> >
<span className="font-normal">이상</span> <Field orientation="horizontal" className="w-auto">
</Field> <RadioGroupItem value="N" id={`rvw-opnn-normal-${reviewStep}`} />
</FieldLabel> <span className="font-normal">정상</span>
</div> </Field>
</RadioGroup> </FieldLabel>
</FieldSet> <FieldLabel
</TableCell> htmlFor={`rvw-opnn-abnormal-${reviewStep}`}
</TableRow> className="!w-auto border-none"
<TableRow> >
<TableHead>첨부파일</TableHead> <Field orientation="horizontal" className="w-auto">
<TableCell> <RadioGroupItem value="Y" id={`rvw-opnn-abnormal-${reviewStep}`} />
<AttachmentFileField <span className="font-normal">이상</span>
files={ </Field>
uploadedFile </FieldLabel>
? [ </div>
{ </RadioGroup>
fileKey: uploadedFile.fileKey, </FieldSet>
fileName: uploadedFile.fileName, </TableCell>
onDownload: uploadedFile.atflId </TableRow>
? () => downloadByAtflId(uploadedFile.atflId!) <TableRow>
: undefined, <TableHead>첨부파일</TableHead>
}, <TableCell>
] <AttachmentFileField
: [] files={
} uploadedFile
inputId={`rvw-opnn-${reviewStep}-file-input`} ? [
isUploadingByKey={isUploading} {
multiple={false} fileKey: uploadedFile.fileKey,
showAddButton={!uploadedFile} fileName: uploadedFile.fileName,
addDisabled={uploading} onDownload: uploadedFile.atflId
onAdd={(fileList) => void handleFileUpload(fileList)} ? () => downloadByAtflId(uploadedFile.atflId!)
onRemove={() => void handleFileRemove()} : undefined,
/> },
</TableCell> ]
</TableRow> : []
</TableHeader> }
</Table> inputId={`rvw-opnn-${reviewStep}-file-input`}
</div> isUploadingByKey={isUploading}
); multiple={false}
} showAddButton={!uploadedFile}
addDisabled={uploading}
return ( onAdd={(fileList) => void handleFileUpload(fileList)}
<> onRemove={() => void handleFileRemove()}
{hasEnvSection ? ( />
<SectionCollapsible title={`${REVIEW_STEP_LABELS.ENV} 검토의견`}> </TableCell>
<div className="space-y-6"> </TableRow>
{envRvwList.length > 0 ? <TechReviewOpinionTable items={envRvwList} /> : null} </TableHeader>
{renderOpinionForm("ENV")} </Table>
</div> </div>
</SectionCollapsible> );
) : null} }
{hasKecoSection ? (
<SectionCollapsible title={`${REVIEW_STEP_LABELS.KECO} 검토의견`}> return (
<div className="space-y-6"> <>
{kecoRvwList.length > 0 ? <TechReviewOpinionTable items={kecoRvwList} /> : null} {hasEnvSection ? (
{/* <SectionCollapsible title={`${REVIEW_STEP_LABELS.ENV} 검토의견`}>
재원협의에서 환경공단 검토의견은 자동 생성 <div className="space-y-6">
{renderOpinionForm("KECO")} {envRvwList.length > 0 ? (
*/} <TechReviewOpinionTable items={envRvwList} isReviewTurn={isReviewTurn("ENV")} />
</div> ) : null}
</SectionCollapsible> {renderOpinionForm("ENV")}
) : null} </div>
</> </SectionCollapsible>
); ) : null}
}); {hasKecoSection ? (
<SectionCollapsible title={`${REVIEW_STEP_LABELS.KECO} 검토의견`}>
function TechReviewOpinionTable({ items }: TechReviewOpinionTableProps) { <div className="space-y-6">
return ( {kecoRvwList.length > 0 ? (
<div className="overflow-x-auto"> <TechReviewOpinionTable items={kecoRvwList} isReviewTurn={isReviewTurn("KECO")} />
<Table caption="검토의견 목록으로 의견자명, 의견내용, 검토결과, 첨부파일, 등록일시 정보 제공" variant="secondary"> ) : null}
<colgroup> {/*
<col width="10%" /> 재원협의에서 환경공단 검토의견은 자동 생성
<col width="55%" /> {renderOpinionForm("KECO")}
<col width="5%" /> */}
<col width="20%" /> </div>
<col width="10%" /> </SectionCollapsible>
</colgroup> ) : null}
<TableHeader> </>
<TableRow> );
<TableHead>의견자명</TableHead> });
<TableHead>의견내용</TableHead>
<TableHead>검토결과</TableHead> function getRvwOpnnIds(item: FnrsCnsltnRvwOpnnResponseDto) {
<TableHead>첨부파일</TableHead> if (!item.fnrsCnsltnDocNo || item.rvwOpnnSn == null) {
<TableHead>등록일시</TableHead> throw new Error("검토의견 식별값이 없습니다.");
</TableRow> }
</TableHeader> return [item.fnrsCnsltnDocNo, item.rvwOpnnSn] as const;
<TableBody> }
{items.map((item) => (
<TableRow key={`${item.fnrsCnsltnDocNo}_${item.rvwOpnnSn}`}> function TechReviewOpinionTable({ items, isReviewTurn }: TechReviewOpinionTableProps) {
<TableCell align="center">{item.opnrNm}</TableCell> const queryClient = useQueryClient();
<TableCell align="left">{item.rvwRsltCn || "-"}</TableCell> const currentUserUuid = useUserStore((state) => state.userInfo?.userUnqId);
<TableCell align="center">
{item.rvwRsltAnmlyYn === "Y" ? "이상" : item.rvwRsltAnmlyYn === "N" ? "정상" : "-"} return (
</TableCell> <RvwOpnnListTable
<TableCell align="center"> items={items}
{item.atchFileInfo?.atflCd ? ( getRowKey={(item) => `${item.fnrsCnsltnDocNo}_${item.rvwOpnnSn}`}
<AttachmentDownloadLink currentUserUuid={currentUserUuid}
atflCd={item.atchFileInfo.atflCd} isReviewTurn={isReviewTurn}
fileName={item.atchFileInfo.orgnlFileNm || "다운로드"} onUpdate={async (item, body) => {
/> await fnrsCnsltnRvwOpnnService.update(...getRvwOpnnIds(item), body);
) : ( await queryClient.invalidateQueries({ queryKey: fnrsCnsltnKeys.all });
"-" }}
)} onDelete={async (item) => {
</TableCell> await fnrsCnsltnRvwOpnnService.delete(...getRvwOpnnIds(item));
<TableCell align="center"> await queryClient.invalidateQueries({ queryKey: fnrsCnsltnKeys.all });
{item.regDt ? dayjs(item.regDt).format("YYYY-MM-DD HH:mm:ss") : "-"} }}
</TableCell> />
</TableRow> );
))} }
</TableBody>
</Table> export { TechReviewOpinionSection };
</div>
);
}
export { TechReviewOpinionSection };
@@ -1,350 +1,352 @@
"use client"; "use client";
import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { dayjs, getDefaultFileKey, useTus } from "@/shared/lib"; import { useQueryClient } from "@tanstack/react-query";
import { TextShimmer } from "@/shared/ui";
import { SectionCollapsible } from "@/shared/ui"; import { getDefaultFileKey, useTus, useUserStore } from "@/shared/lib";
import { Field, FieldLabel, FieldSet } from "@/shared/ui/field"; import { TextShimmer } from "@/shared/ui";
import { AttachmentDownloadLink, attachService } from "@/entities/attach"; import { SectionCollapsible } from "@/shared/ui";
import type { InstlSncnRvwOpnnResponseDto, ReviewStepCode } from "@/entities/instl-sncn"; import { Field, FieldLabel, FieldSet } from "@/shared/ui/field";
import { import { attachService } from "@/entities/attach";
Button, import {
RadioGroup, instlSncnKeys,
RadioGroupItem, type InstlSncnRvwOpnnResponseDto,
Table, instlSncnRvwOpnnService,
TableBody, type ReviewStepCode,
TableCell, } from "@/entities/instl-sncn";
TableHead, import { RvwOpnnListTable } from "@/widgets/pbadms-sprt";
TableHeader, import {
TableRow, Button,
Textarea, RadioGroup,
} from "@common/components"; RadioGroupItem,
Table,
import type { ReviewOpinionFormData } from "../../lib/review-opinion-utils"; TableCell,
import { REVIEW_STEP_LABELS } from "../../model/view-types"; TableHead,
TableHeader,
const RVW_OPNN_FILE_KEY_PREFIX = "rvw-opnn::"; TableRow,
Textarea,
interface TechReviewOpinionSectionProps { } from "@common/components";
rvwList: InstlSncnRvwOpnnResponseDto[];
editableReviewStep?: ReviewStepCode; import type { ReviewOpinionFormData } from "../../lib/review-opinion-utils";
atrzSeComCdList?: string[]; import { REVIEW_STEP_LABELS } from "../../model/view-types";
isAtrzLoading?: boolean;
} const RVW_OPNN_FILE_KEY_PREFIX = "rvw-opnn::";
export interface TechReviewOpinionSectionHandle { interface TechReviewOpinionSectionProps {
getFormData: () => ReviewOpinionFormData | null; rvwList: InstlSncnRvwOpnnResponseDto[];
resetForm: () => void; editableReviewStep?: ReviewStepCode;
} atrzSeComCdList?: string[];
isAtrzLoading?: boolean;
interface TechReviewOpinionTableProps { }
items: InstlSncnRvwOpnnResponseDto[];
} export interface TechReviewOpinionSectionHandle {
getFormData: () => ReviewOpinionFormData | null;
interface UploadedOpinionFile { resetForm: () => void;
fileName: string; }
fileKey: string;
atflId?: string; interface TechReviewOpinionTableProps {
atflCd?: string; items: InstlSncnRvwOpnnResponseDto[];
} isReviewTurn: boolean;
}
const EMPTY_FORM_DATA: ReviewOpinionFormData = {
rvwRsltCn: "", interface UploadedOpinionFile {
rvwRsltAnmlyYn: "", fileName: string;
atchFileGroupId: "", fileKey: string;
opnrSeComCd: "", atflId?: string;
}; atflCd?: string;
}
function createRvwOpnnUploadKey(file: File) {
return `${RVW_OPNN_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`; const EMPTY_FORM_DATA: ReviewOpinionFormData = {
} rvwRsltCn: "",
rvwRsltAnmlyYn: "",
function hasFormContent(formData: ReviewOpinionFormData) { atchFileGroupId: "",
return Boolean(formData.rvwRsltCn.trim() || formData.rvwRsltAnmlyYn || formData.atchFileGroupId); opnrSeComCd: "",
} };
const TechReviewOpinionSection = forwardRef< function createRvwOpnnUploadKey(file: File) {
TechReviewOpinionSectionHandle, return `${RVW_OPNN_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`;
TechReviewOpinionSectionProps }
>(function TechReviewOpinionSection(
{ rvwList, editableReviewStep, atrzSeComCdList = [], isAtrzLoading = false }, function hasFormContent(formData: ReviewOpinionFormData) {
ref, return Boolean(formData.rvwRsltCn.trim() || formData.rvwRsltAnmlyYn || formData.atchFileGroupId);
) { }
const canWriteKecoOpinion = !isAtrzLoading && atrzSeComCdList.includes("ATRZ02");
const [formData, setFormData] = useState<ReviewOpinionFormData>({ const TechReviewOpinionSection = forwardRef<
...EMPTY_FORM_DATA, TechReviewOpinionSectionHandle,
opnrSeComCd: editableReviewStep ?? "", TechReviewOpinionSectionProps
}); >(function TechReviewOpinionSection(
const [uploadedFile, setUploadedFile] = useState<UploadedOpinionFile | null>(null); { rvwList, editableReviewStep, atrzSeComCdList = [], isAtrzLoading = false },
ref,
useEffect(() => { ) {
setFormData((prev) => ({ const canWriteKecoOpinion = !isAtrzLoading && atrzSeComCdList.includes("ATRZ02");
...prev, const [formData, setFormData] = useState<ReviewOpinionFormData>({
opnrSeComCd: editableReviewStep ?? "", ...EMPTY_FORM_DATA,
})); opnrSeComCd: editableReviewStep ?? "",
}, [editableReviewStep]); });
const [uploadedFile, setUploadedFile] = useState<UploadedOpinionFile | null>(null);
const { uploadFileAsync, isUploading, uploads } = useTus({
onSuccess: (atflCd, atflId, _file, fileKey) => { useEffect(() => {
if (!atflCd || !atflId) return; setFormData((prev) => ({
...prev,
setFormData((prev) => ({ ...prev, atchFileGroupId: atflCd })); opnrSeComCd: editableReviewStep ?? "",
setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev)); }));
}, }, [editableReviewStep]);
onError: (_error, _file, fileKey) => {
setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev)); const { uploadFileAsync, isUploading, uploads } = useTus({
}, onSuccess: (atflCd, atflId, _file, fileKey) => {
}); if (!atflCd || !atflId) return;
useImperativeHandle( setFormData((prev) => ({ ...prev, atchFileGroupId: atflCd }));
ref, setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev));
() => ({ },
getFormData: () => { onError: (_error, _file, fileKey) => {
if (!editableReviewStep || !hasFormContent(formData)) { setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev));
return null; },
} });
if (editableReviewStep === "KECO" && !canWriteKecoOpinion) {
return null; useImperativeHandle(
} ref,
() => ({
return { getFormData: () => {
...formData, if (!editableReviewStep || !hasFormContent(formData)) {
opnrSeComCd: editableReviewStep, return null;
}; }
}, if (editableReviewStep === "KECO" && !canWriteKecoOpinion) {
resetForm: () => { return null;
setFormData({ }
...EMPTY_FORM_DATA,
opnrSeComCd: editableReviewStep ?? "", return {
}); ...formData,
setUploadedFile(null); opnrSeComCd: editableReviewStep,
}, };
}), },
[canWriteKecoOpinion, editableReviewStep, formData], resetForm: () => {
); setFormData({
...EMPTY_FORM_DATA,
const envRvwList = rvwList.filter((item) => item.opnrSeComCd === "ENV"); opnrSeComCd: editableReviewStep ?? "",
const kecoRvwList = rvwList.filter((item) => item.opnrSeComCd === "KECO"); });
setUploadedFile(null);
const hasEnvSection = envRvwList.length > 0 || editableReviewStep === "ENV"; },
const hasKecoSection = }),
kecoRvwList.length > 0 || (editableReviewStep === "KECO" && canWriteKecoOpinion); [canWriteKecoOpinion, editableReviewStep, formData],
);
if (!hasEnvSection && !hasKecoSection) {
return null; const envRvwList = rvwList.filter((item) => item.opnrSeComCd === "ENV");
} const kecoRvwList = rvwList.filter((item) => item.opnrSeComCd === "KECO");
async function handleFileUpload(files: FileList | null) { const hasEnvSection = envRvwList.length > 0 || editableReviewStep === "ENV";
if (!files || files.length === 0) return; const hasKecoSection =
kecoRvwList.length > 0 || (editableReviewStep === "KECO" && canWriteKecoOpinion);
const file = files[0];
const fileKey = createRvwOpnnUploadKey(file); if (!hasEnvSection && !hasKecoSection) {
const existingAtflCd = formData.atchFileGroupId; return null;
}
setUploadedFile({ fileName: file.name, fileKey });
async function handleFileUpload(files: FileList | null) {
try { if (!files || files.length === 0) return;
await uploadFileAsync(file, {
fileKey, const file = files[0];
metadata: existingAtflCd ? { atflCd: existingAtflCd } : undefined, const fileKey = createRvwOpnnUploadKey(file);
}); const existingAtflCd = formData.atchFileGroupId;
} catch {
// onError callback handles cleanup setUploadedFile({ fileName: file.name, fileKey });
}
} try {
await uploadFileAsync(file, {
async function handleFileRemove() { fileKey,
if (!uploadedFile) return; metadata: existingAtflCd ? { atflCd: existingAtflCd } : undefined,
});
uploads[uploadedFile.fileKey]?.abort(); } catch {
// onError callback handles cleanup
if (uploadedFile.atflId) { }
try { }
await attachService.deleteAttachmentByAtflId(uploadedFile.atflId);
} catch (error) { async function handleFileRemove() {
console.error("검토의견 첨부파일 삭제 실패:", error); if (!uploadedFile) return;
}
} uploads[uploadedFile.fileKey]?.abort();
setUploadedFile(null); if (uploadedFile.atflId) {
setFormData((prev) => ({ ...prev, atchFileGroupId: "" })); try {
} await attachService.deleteAttachmentByAtflId(uploadedFile.atflId);
} catch (error) {
function renderOpinionForm(reviewStep: ReviewStepCode) { console.error("검토의견 첨부파일 삭제 실패:", error);
if (editableReviewStep !== reviewStep) return null; }
if (reviewStep === "KECO" && !canWriteKecoOpinion) return null; }
const uploading = uploadedFile ? (isUploading[uploadedFile.fileKey] ?? false) : false; setUploadedFile(null);
setFormData((prev) => ({ ...prev, atchFileGroupId: "" }));
return ( }
<div className="space-y-2">
<h4 className="text-xl font-semibold">검토의견 작성</h4> function isReviewTurn(reviewStep: ReviewStepCode) {
<Table caption="검토의견 작성으로 의견내용, 검토결과, 첨부파일 정보 제공" variant="secondary"> if (editableReviewStep !== reviewStep) return false;
<TableHeader> if (reviewStep === "KECO" && !canWriteKecoOpinion) return false;
<TableRow> return true;
<TableHead scope="row" className="w-[12rem]">의견내용</TableHead> }
<TableCell>
<Textarea function renderOpinionForm(reviewStep: ReviewStepCode) {
value={formData.rvwRsltCn} if (!isReviewTurn(reviewStep)) return null;
onChange={(event) =>
setFormData((prev) => ({ ...prev, rvwRsltCn: event.target.value })) const uploading = uploadedFile ? (isUploading[uploadedFile.fileKey] ?? false) : false;
}
placeholder="의견내용을 입력하세요" return (
rows={4} <div className="space-y-2">
className="min-h-[8rem] !text-xl" <h4 className="text-xl font-semibold">검토의견 작성</h4>
/> <Table
</TableCell> caption="검토의견 작성으로 의견내용, 검토결과, 첨부파일 정보 제공"
</TableRow> variant="secondary"
<TableRow> >
<TableHead scope="row">검토결과</TableHead> <TableHeader>
<TableCell> <TableRow>
<FieldSet> <TableHead scope="row" className="w-[12rem]">
<RadioGroup 의견내용
value={formData.rvwRsltAnmlyYn} </TableHead>
onValueChange={(value) => <TableCell>
setFormData((prev) => ({ <Textarea
...prev, value={formData.rvwRsltCn}
rvwRsltAnmlyYn: value as ReviewOpinionFormData["rvwRsltAnmlyYn"], onChange={(event) =>
})) setFormData((prev) => ({ ...prev, rvwRsltCn: event.target.value }))
} }
> placeholder="의견내용을 입력하세요"
<div className="flex flex-wrap gap-4"> rows={4}
<FieldLabel className="min-h-[8rem] !text-xl"
htmlFor={`rvw-opnn-normal-${reviewStep}`} />
className="!w-auto border-none" </TableCell>
> </TableRow>
<Field orientation="horizontal" className="w-auto"> <TableRow>
<RadioGroupItem value="N" id={`rvw-opnn-normal-${reviewStep}`} /> <TableHead scope="row">검토결과</TableHead>
<span className="font-normal">정상</span> <TableCell>
</Field> <FieldSet>
</FieldLabel> <RadioGroup
<FieldLabel value={formData.rvwRsltAnmlyYn}
htmlFor={`rvw-opnn-abnormal-${reviewStep}`} onValueChange={(value) =>
className="!w-auto border-none" setFormData((prev) => ({
> ...prev,
<Field orientation="horizontal" className="w-auto"> rvwRsltAnmlyYn: value as ReviewOpinionFormData["rvwRsltAnmlyYn"],
<RadioGroupItem value="Y" id={`rvw-opnn-abnormal-${reviewStep}`} /> }))
<span className="font-normal">이상</span> }
</Field> >
</FieldLabel> <div className="flex flex-wrap gap-4">
</div> <FieldLabel
</RadioGroup> htmlFor={`rvw-opnn-normal-${reviewStep}`}
</FieldSet> className="!w-auto border-none"
</TableCell> >
</TableRow> <Field orientation="horizontal" className="w-auto">
<TableRow> <RadioGroupItem value="N" id={`rvw-opnn-normal-${reviewStep}`} />
<TableHead scope="row">첨부파일</TableHead> <span className="font-normal">정상</span>
<TableCell> </Field>
{uploadedFile ? ( </FieldLabel>
<div className="flex items-center gap-2"> <FieldLabel
<TextShimmer className="text-xl" active={uploading}> htmlFor={`rvw-opnn-abnormal-${reviewStep}`}
{uploadedFile.fileName} className="!w-auto border-none"
</TextShimmer> >
<Button <Field orientation="horizontal" className="w-auto">
size="icon" <RadioGroupItem value="Y" id={`rvw-opnn-abnormal-${reviewStep}`} />
onClick={(e) => { <span className="font-normal">이상</span>
e.preventDefault(); </Field>
void handleFileRemove(); </FieldLabel>
}} </div>
disabled={uploading} </RadioGroup>
className="size-8 !bg-destructive" </FieldSet>
> </TableCell>
<i className="diveicon di-x text-xs" aria-label="삭제" /> </TableRow>
</Button> <TableRow>
</div> <TableHead scope="row">첨부파일</TableHead>
) : ( <TableCell>
<label> {uploadedFile ? (
<input <div className="flex items-center gap-2">
type="file" <TextShimmer className="text-xl" active={uploading}>
className="hidden" {uploadedFile.fileName}
onChange={(event) => { </TextShimmer>
void handleFileUpload(event.target.files); <Button
event.target.value = ""; size="icon"
}} onClick={(e) => {
/> e.preventDefault();
<Button size="sm" variant="outline" type="button" asChild> void handleFileRemove();
<span>파일 선택</span> }}
</Button> disabled={uploading}
</label> className="size-8 !bg-destructive"
)} >
</TableCell> <i className="diveicon di-x text-xs" aria-label="삭제" />
</TableRow> </Button>
</TableHeader> </div>
</Table> ) : (
</div> <label>
); <input
} type="file"
className="hidden"
return ( onChange={(event) => {
<> void handleFileUpload(event.target.files);
{hasEnvSection ? ( event.target.value = "";
<SectionCollapsible title={`${REVIEW_STEP_LABELS.ENV} 검토의견`}> }}
<div className="space-y-6"> />
{envRvwList.length > 0 ? <TechReviewOpinionTable items={envRvwList} /> : null} <Button size="sm" variant="outline" type="button" asChild>
{renderOpinionForm("ENV")} <span>파일 선택</span>
</div> </Button>
</SectionCollapsible> </label>
) : null} )}
{hasKecoSection ? ( </TableCell>
<SectionCollapsible title={`${REVIEW_STEP_LABELS.KECO} 검토의견`}> </TableRow>
<div className="space-y-6"> </TableHeader>
{kecoRvwList.length > 0 ? <TechReviewOpinionTable items={kecoRvwList} /> : null} </Table>
{renderOpinionForm("KECO")} </div>
</div> );
</SectionCollapsible> }
) : null}
</> return (
); <>
}); {hasEnvSection ? (
<SectionCollapsible title={`${REVIEW_STEP_LABELS.ENV} 검토의견`}>
function TechReviewOpinionTable({ items }: TechReviewOpinionTableProps) { <div className="space-y-6">
return ( {envRvwList.length > 0 ? (
<div className="overflow-x-auto"> <TechReviewOpinionTable items={envRvwList} isReviewTurn={isReviewTurn("ENV")} />
<Table caption="검토의견 목록으로 의견자명, 의견내용, 검토결과, 첨부파일, 등록일시 정보 제공" variant="secondary"> ) : null}
<colgroup> {renderOpinionForm("ENV")}
<col width="10%" /> </div>
<col width="55%" /> </SectionCollapsible>
<col width="5%" /> ) : null}
<col width="20%" /> {hasKecoSection ? (
<col width="10%" /> <SectionCollapsible title={`${REVIEW_STEP_LABELS.KECO} 검토의견`}>
</colgroup> <div className="space-y-6">
<TableHeader> {kecoRvwList.length > 0 ? (
<TableRow> <TechReviewOpinionTable items={kecoRvwList} isReviewTurn={isReviewTurn("KECO")} />
<TableHead>의견자명</TableHead> ) : null}
<TableHead>의견내용</TableHead> {renderOpinionForm("KECO")}
<TableHead>검토결과</TableHead> </div>
<TableHead>첨부파일</TableHead> </SectionCollapsible>
<TableHead>등록일시</TableHead> ) : null}
</TableRow> </>
</TableHeader> );
<TableBody> });
{items.map((item) => (
<TableRow key={`${item.instlSncnDocNo}_${item.rvwOpnnSn}`}> function getRvwOpnnIds(item: InstlSncnRvwOpnnResponseDto) {
<TableCell align="center">{item.opnrNm}</TableCell> if (!item.instlSncnDocNo || item.rvwOpnnSn == null) {
<TableCell align="left">{item.rvwRsltCn || "-"}</TableCell> throw new Error("검토의견 식별값이 없습니다.");
<TableCell align="center"> }
{item.rvwRsltAnmlyYn === "Y" ? "이상" : item.rvwRsltAnmlyYn === "N" ? "정상" : "-"} return [item.instlSncnDocNo, item.rvwOpnnSn] as const;
</TableCell> }
<TableCell align="center">
{item.atchFileInfo?.atflCd ? ( function TechReviewOpinionTable({ items, isReviewTurn }: TechReviewOpinionTableProps) {
<AttachmentDownloadLink const queryClient = useQueryClient();
atflCd={item.atchFileInfo.atflCd} const currentUserUuid = useUserStore((state) => state.userInfo?.userUnqId);
fileName={item.atchFileInfo.orgnlFileNm || "다운로드"}
/> return (
) : ( <RvwOpnnListTable
"-" items={items}
)} getRowKey={(item) => `${item.instlSncnDocNo}_${item.rvwOpnnSn}`}
</TableCell> currentUserUuid={currentUserUuid}
<TableCell align="center"> isReviewTurn={isReviewTurn}
{item.regDt ? dayjs(item.regDt).format("YYYY-MM-DD HH:mm:ss") : "-"} onUpdate={async (item, body) => {
</TableCell> await instlSncnRvwOpnnService.update(...getRvwOpnnIds(item), body);
</TableRow> await queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
))} }}
</TableBody> onDelete={async (item) => {
</Table> await instlSncnRvwOpnnService.delete(...getRvwOpnnIds(item));
</div> await queryClient.invalidateQueries({ queryKey: instlSncnKeys.all });
); }}
} />
);
export { TechReviewOpinionSection }; }
export { TechReviewOpinionSection };
@@ -1,357 +1,356 @@
"use client"; "use client";
import { forwardRef, useEffect, useImperativeHandle, useState } from "react"; import { forwardRef, useEffect, useImperativeHandle, useState } from "react";
import { dayjs, getDefaultFileKey, useTus } from "@/shared/lib"; import { useQueryClient } from "@tanstack/react-query";
import { TextShimmer } from "@/shared/ui";
import { SectionCollapsible } from "@/shared/ui"; import { getDefaultFileKey, useTus, useUserStore } from "@/shared/lib";
import { Field, FieldLabel, FieldSet } from "@/shared/ui/field"; import { TextShimmer } from "@/shared/ui";
import { AttachmentDownloadLink, attachService } from "@/entities/attach"; import { SectionCollapsible } from "@/shared/ui";
import type { SewerBscPlanRvwOpnnResponseDto } from "@/entities/sewer-bsc-plan"; import { Field, FieldLabel, FieldSet } from "@/shared/ui/field";
import { import { attachService } from "@/entities/attach";
Button, import {
RadioGroup, sewerBscPlanKeys,
RadioGroupItem, type SewerBscPlanRvwOpnnResponseDto,
Table, sewerBscPlanRvwOpnnService,
TableBody, } from "@/entities/sewer-bsc-plan";
TableCell, import { RvwOpnnListTable } from "@/widgets/pbadms-sprt";
TableHead, import {
TableHeader, Button,
TableRow, RadioGroup,
Textarea, RadioGroupItem,
} from "@common/components"; Table,
TableCell,
import type { TableHead,
ReviewOpinionFormData, TableHeader,
ReviewOpinionGetFormDataResult, TableRow,
} from "../../lib/review-opinion-utils"; Textarea,
import type { ReviewStepCode } from "../../model/view-types"; } from "@common/components";
import { REVIEW_STEP_LABELS } from "../../model/view-types";
import type {
const RVW_OPNN_FILE_KEY_PREFIX = "rvw-opnn::"; ReviewOpinionFormData,
ReviewOpinionGetFormDataResult,
interface TechReviewOpinionSectionProps { } from "../../lib/review-opinion-utils";
rvwList: SewerBscPlanRvwOpnnResponseDto[]; import type { ReviewStepCode } from "../../model/view-types";
editableReviewStep?: ReviewStepCode; import { REVIEW_STEP_LABELS } from "../../model/view-types";
atrzSeComCdList?: string[];
isAtrzLoading?: boolean; const RVW_OPNN_FILE_KEY_PREFIX = "rvw-opnn::";
}
interface TechReviewOpinionSectionProps {
export interface TechReviewOpinionSectionHandle { rvwList: SewerBscPlanRvwOpnnResponseDto[];
getFormData: () => ReviewOpinionGetFormDataResult | null; editableReviewStep?: ReviewStepCode;
resetForm: () => void; atrzSeComCdList?: string[];
} isAtrzLoading?: boolean;
}
interface TechReviewOpinionTableProps {
items: SewerBscPlanRvwOpnnResponseDto[]; export interface TechReviewOpinionSectionHandle {
} getFormData: () => ReviewOpinionGetFormDataResult | null;
resetForm: () => void;
interface UploadedOpinionFile { }
fileName: string;
fileKey: string; interface TechReviewOpinionTableProps {
atflId?: string; items: SewerBscPlanRvwOpnnResponseDto[];
atflCd?: string; isReviewTurn: boolean;
} }
const EMPTY_FORM_DATA: ReviewOpinionFormData = { interface UploadedOpinionFile {
rvwRsltCn: "", fileName: string;
rvwRsltAnmlyYn: "", fileKey: string;
atchFileGroupId: "", atflId?: string;
opnrSeComCd: "", atflCd?: string;
}; }
function createRvwOpnnUploadKey(file: File) { const EMPTY_FORM_DATA: ReviewOpinionFormData = {
return `${RVW_OPNN_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`; rvwRsltCn: "",
} rvwRsltAnmlyYn: "",
atchFileGroupId: "",
function hasFormContent(formData: ReviewOpinionFormData) { opnrSeComCd: "",
return Boolean(formData.rvwRsltCn.trim() || formData.rvwRsltAnmlyYn || formData.atchFileGroupId); };
}
function createRvwOpnnUploadKey(file: File) {
const TechReviewOpinionSection = forwardRef< return `${RVW_OPNN_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`;
TechReviewOpinionSectionHandle, }
TechReviewOpinionSectionProps
>(function TechReviewOpinionSection( function hasFormContent(formData: ReviewOpinionFormData) {
{ rvwList, editableReviewStep, atrzSeComCdList = [], isAtrzLoading = false }, return Boolean(formData.rvwRsltCn.trim() || formData.rvwRsltAnmlyYn || formData.atchFileGroupId);
ref, }
) {
const canWriteKecoOpinion = !isAtrzLoading && atrzSeComCdList.includes("ATRZ02"); const TechReviewOpinionSection = forwardRef<
const [formData, setFormData] = useState<ReviewOpinionFormData>({ TechReviewOpinionSectionHandle,
...EMPTY_FORM_DATA, TechReviewOpinionSectionProps
opnrSeComCd: editableReviewStep ?? "", >(function TechReviewOpinionSection(
}); { rvwList, editableReviewStep, atrzSeComCdList = [], isAtrzLoading = false },
const [uploadedFile, setUploadedFile] = useState<UploadedOpinionFile | null>(null); ref,
) {
useEffect(() => { const canWriteKecoOpinion = !isAtrzLoading && atrzSeComCdList.includes("ATRZ02");
setFormData((prev) => ({ const [formData, setFormData] = useState<ReviewOpinionFormData>({
...prev, ...EMPTY_FORM_DATA,
opnrSeComCd: editableReviewStep ?? "", opnrSeComCd: editableReviewStep ?? "",
})); });
}, [editableReviewStep]); const [uploadedFile, setUploadedFile] = useState<UploadedOpinionFile | null>(null);
const { uploadFileAsync, isUploading, uploads } = useTus({ useEffect(() => {
onSuccess: (atflCd, atflId, _file, fileKey) => { setFormData((prev) => ({
if (!atflCd || !atflId) return; ...prev,
opnrSeComCd: editableReviewStep ?? "",
setFormData((prev) => ({ ...prev, atchFileGroupId: atflCd })); }));
setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev)); }, [editableReviewStep]);
},
onError: (_error, _file, fileKey) => { const { uploadFileAsync, isUploading, uploads } = useTus({
setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev)); onSuccess: (atflCd, atflId, _file, fileKey) => {
}, if (!atflCd || !atflId) return;
});
setFormData((prev) => ({ ...prev, atchFileGroupId: atflCd }));
useImperativeHandle( setUploadedFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev));
ref, },
() => ({ onError: (_error, _file, fileKey) => {
getFormData: () => { setUploadedFile((prev) => (prev?.fileKey === fileKey ? null : prev));
if (!editableReviewStep || !hasFormContent(formData)) { },
return null; });
}
if (editableReviewStep === "KECO" && !canWriteKecoOpinion) { useImperativeHandle(
return null; ref,
} () => ({
getFormData: () => {
return { if (!editableReviewStep || !hasFormContent(formData)) {
formData: { return null;
...formData, }
opnrSeComCd: editableReviewStep, if (editableReviewStep === "KECO" && !canWriteKecoOpinion) {
}, return null;
rvwList, }
};
}, return {
resetForm: () => { formData: {
setFormData({ ...formData,
...EMPTY_FORM_DATA, opnrSeComCd: editableReviewStep,
opnrSeComCd: editableReviewStep ?? "", },
}); rvwList,
setUploadedFile(null); };
}, },
}), resetForm: () => {
[canWriteKecoOpinion, editableReviewStep, formData, rvwList], setFormData({
); ...EMPTY_FORM_DATA,
opnrSeComCd: editableReviewStep ?? "",
const envRvwList = rvwList.filter((item) => item.opnrSeComCd === "ENV"); });
const kecoRvwList = rvwList.filter((item) => item.opnrSeComCd === "KECO"); setUploadedFile(null);
},
const hasEnvSection = envRvwList.length > 0 || editableReviewStep === "ENV"; }),
const hasKecoSection = [canWriteKecoOpinion, editableReviewStep, formData, rvwList],
kecoRvwList.length > 0 || (editableReviewStep === "KECO" && canWriteKecoOpinion); );
if (!hasEnvSection && !hasKecoSection) { const envRvwList = rvwList.filter((item) => item.opnrSeComCd === "ENV");
return null; const kecoRvwList = rvwList.filter((item) => item.opnrSeComCd === "KECO");
}
const hasEnvSection = envRvwList.length > 0 || editableReviewStep === "ENV";
async function handleFileUpload(files: FileList | null) { const hasKecoSection =
if (!files || files.length === 0) return; kecoRvwList.length > 0 || (editableReviewStep === "KECO" && canWriteKecoOpinion);
const file = files[0]; if (!hasEnvSection && !hasKecoSection) {
const fileKey = createRvwOpnnUploadKey(file); return null;
const existingAtflCd = formData.atchFileGroupId; }
setUploadedFile({ fileName: file.name, fileKey }); async function handleFileUpload(files: FileList | null) {
if (!files || files.length === 0) return;
try {
await uploadFileAsync(file, { const file = files[0];
fileKey, const fileKey = createRvwOpnnUploadKey(file);
metadata: existingAtflCd ? { atflCd: existingAtflCd } : undefined, const existingAtflCd = formData.atchFileGroupId;
});
} catch { setUploadedFile({ fileName: file.name, fileKey });
// onError callback handles cleanup
} try {
} await uploadFileAsync(file, {
fileKey,
async function handleFileRemove() { metadata: existingAtflCd ? { atflCd: existingAtflCd } : undefined,
if (!uploadedFile) return; });
} catch {
uploads[uploadedFile.fileKey]?.abort(); // onError callback handles cleanup
}
if (uploadedFile.atflId) { }
try {
await attachService.deleteAttachmentByAtflId(uploadedFile.atflId); async function handleFileRemove() {
} catch (error) { if (!uploadedFile) return;
console.error("검토의견 첨부파일 삭제 실패:", error);
} uploads[uploadedFile.fileKey]?.abort();
}
if (uploadedFile.atflId) {
setUploadedFile(null); try {
setFormData((prev) => ({ ...prev, atchFileGroupId: "" })); await attachService.deleteAttachmentByAtflId(uploadedFile.atflId);
} } catch (error) {
console.error("검토의견 첨부파일 삭제 실패:", error);
function renderOpinionForm(reviewStep: ReviewStepCode) { }
if (editableReviewStep !== reviewStep) return null; }
if (reviewStep === "KECO" && !canWriteKecoOpinion) return null;
setUploadedFile(null);
const uploading = uploadedFile ? (isUploading[uploadedFile.fileKey] ?? false) : false; setFormData((prev) => ({ ...prev, atchFileGroupId: "" }));
}
return (
<div className="space-y-2"> function isReviewTurn(reviewStep: ReviewStepCode) {
<h4 className="text-xl font-semibold">검토의견 작성</h4> if (editableReviewStep !== reviewStep) return false;
<Table caption="검토의견 작성으로 의견내용, 검토결과, 첨부파일 정보 제공" variant="secondary"> if (reviewStep === "KECO" && !canWriteKecoOpinion) return false;
<TableHeader> return true;
<TableRow> }
<TableHead className="w-[12rem]">의견내용</TableHead>
<TableCell> function renderOpinionForm(reviewStep: ReviewStepCode) {
<Textarea if (!isReviewTurn(reviewStep)) return null;
value={formData.rvwRsltCn}
onChange={(event) => const uploading = uploadedFile ? (isUploading[uploadedFile.fileKey] ?? false) : false;
setFormData((prev) => ({ ...prev, rvwRsltCn: event.target.value }))
} return (
placeholder="의견내용을 입력하세요" <div className="space-y-2">
rows={4} <h4 className="text-xl font-semibold">검토의견 작성</h4>
className="min-h-[8rem] !text-xl" <Table
/> caption="검토의견 작성으로 의견내용, 검토결과, 첨부파일 정보 제공"
</TableCell> variant="secondary"
</TableRow> >
<TableRow> <TableHeader>
<TableHead>검토결과</TableHead> <TableRow>
<TableCell> <TableHead className="w-[12rem]">의견내용</TableHead>
<FieldSet> <TableCell>
<RadioGroup <Textarea
value={formData.rvwRsltAnmlyYn} value={formData.rvwRsltCn}
onValueChange={(value) => onChange={(event) =>
setFormData((prev) => ({ setFormData((prev) => ({ ...prev, rvwRsltCn: event.target.value }))
...prev, }
rvwRsltAnmlyYn: value as ReviewOpinionFormData["rvwRsltAnmlyYn"], placeholder="의견내용을 입력하세요"
})) rows={4}
} className="min-h-[8rem] !text-xl"
> />
<div className="flex flex-wrap gap-4"> </TableCell>
<FieldLabel </TableRow>
htmlFor={`rvw-opnn-normal-${reviewStep}`} <TableRow>
className="!w-auto border-none" <TableHead>검토결과</TableHead>
> <TableCell>
<Field orientation="horizontal" className="w-auto"> <FieldSet>
<RadioGroupItem value="N" id={`rvw-opnn-normal-${reviewStep}`} /> <RadioGroup
<span className="font-normal">정상</span> value={formData.rvwRsltAnmlyYn}
</Field> onValueChange={(value) =>
</FieldLabel> setFormData((prev) => ({
<FieldLabel ...prev,
htmlFor={`rvw-opnn-abnormal-${reviewStep}`} rvwRsltAnmlyYn: value as ReviewOpinionFormData["rvwRsltAnmlyYn"],
className="!w-auto border-none" }))
> }
<Field orientation="horizontal" className="w-auto"> >
<RadioGroupItem value="Y" id={`rvw-opnn-abnormal-${reviewStep}`} /> <div className="flex flex-wrap gap-4">
<span className="font-normal">이상</span> <FieldLabel
</Field> htmlFor={`rvw-opnn-normal-${reviewStep}`}
</FieldLabel> className="!w-auto border-none"
</div> >
</RadioGroup> <Field orientation="horizontal" className="w-auto">
</FieldSet> <RadioGroupItem value="N" id={`rvw-opnn-normal-${reviewStep}`} />
</TableCell> <span className="font-normal">정상</span>
</TableRow> </Field>
<TableRow> </FieldLabel>
<TableHead>첨부파일</TableHead> <FieldLabel
<TableCell> htmlFor={`rvw-opnn-abnormal-${reviewStep}`}
{uploadedFile ? ( className="!w-auto border-none"
<div className="flex items-center gap-2"> >
<TextShimmer className="text-xl" active={uploading}> <Field orientation="horizontal" className="w-auto">
{uploadedFile.fileName} <RadioGroupItem value="Y" id={`rvw-opnn-abnormal-${reviewStep}`} />
</TextShimmer> <span className="font-normal">이상</span>
<Button </Field>
size="icon" </FieldLabel>
onClick={(e) => { </div>
e.preventDefault(); </RadioGroup>
void handleFileRemove(); </FieldSet>
}} </TableCell>
disabled={uploading} </TableRow>
className="size-8 !bg-destructive" <TableRow>
> <TableHead>첨부파일</TableHead>
<i className="diveicon di-x text-xs" aria-label="삭제" /> <TableCell>
</Button> {uploadedFile ? (
</div> <div className="flex items-center gap-2">
) : ( <TextShimmer className="text-xl" active={uploading}>
<label> {uploadedFile.fileName}
<input </TextShimmer>
type="file" <Button
className="hidden" size="icon"
onChange={(event) => { onClick={(e) => {
void handleFileUpload(event.target.files); e.preventDefault();
event.target.value = ""; void handleFileRemove();
}} }}
/> disabled={uploading}
<Button size="sm" variant="outline" type="button" asChild> className="size-8 !bg-destructive"
<span>파일 선택</span> >
</Button> <i className="diveicon di-x text-xs" aria-label="삭제" />
</label> </Button>
)} </div>
</TableCell> ) : (
</TableRow> <label>
</TableHeader> <input
</Table> type="file"
</div> className="hidden"
); onChange={(event) => {
} void handleFileUpload(event.target.files);
event.target.value = "";
return ( }}
<> />
{hasEnvSection ? ( <Button size="sm" variant="outline" type="button" asChild>
<SectionCollapsible title={`${REVIEW_STEP_LABELS.ENV} 검토의견`}> <span>파일 선택</span>
<div className="space-y-6"> </Button>
{envRvwList.length > 0 ? <TechReviewOpinionTable items={envRvwList} /> : null} </label>
{renderOpinionForm("ENV")} )}
</div> </TableCell>
</SectionCollapsible> </TableRow>
) : null} </TableHeader>
{hasKecoSection ? ( </Table>
<SectionCollapsible title={`${REVIEW_STEP_LABELS.KECO} 검토의견`}> </div>
<div className="space-y-6"> );
{kecoRvwList.length > 0 ? <TechReviewOpinionTable items={kecoRvwList} /> : null} }
{renderOpinionForm("KECO")}
</div> return (
</SectionCollapsible> <>
) : null} {hasEnvSection ? (
</> <SectionCollapsible title={`${REVIEW_STEP_LABELS.ENV} 검토의견`}>
); <div className="space-y-6">
}); {envRvwList.length > 0 ? (
<TechReviewOpinionTable items={envRvwList} isReviewTurn={isReviewTurn("ENV")} />
function TechReviewOpinionTable({ items }: TechReviewOpinionTableProps) { ) : null}
return ( {renderOpinionForm("ENV")}
<div className="overflow-x-auto"> </div>
<Table caption="검토의견 목록으로 의견자명, 의견내용, 검토결과, 첨부파일, 등록일시 정보 제공" variant="secondary"> </SectionCollapsible>
<colgroup> ) : null}
<col width="10%" /> {hasKecoSection ? (
<col width="55%" /> <SectionCollapsible title={`${REVIEW_STEP_LABELS.KECO} 검토의견`}>
<col width="5%" /> <div className="space-y-6">
<col width="20%" /> {kecoRvwList.length > 0 ? (
<col width="10%" /> <TechReviewOpinionTable items={kecoRvwList} isReviewTurn={isReviewTurn("KECO")} />
</colgroup> ) : null}
<TableHeader> {renderOpinionForm("KECO")}
<TableRow> </div>
<TableHead>의견자명</TableHead> </SectionCollapsible>
<TableHead>의견내용</TableHead> ) : null}
<TableHead>검토결과</TableHead> </>
<TableHead>첨부파일</TableHead> );
<TableHead>등록일시</TableHead> });
</TableRow>
</TableHeader> function getRvwOpnnIds(item: SewerBscPlanRvwOpnnResponseDto) {
<TableBody> if (!item.sewerBscPlanDocNo || item.chgCycl == null || item.rvwOpnnSn == null) {
{items.map((item) => ( throw new Error("검토의견 식별값이 없습니다.");
<TableRow key={`${item.sewerBscPlanDocNo}_${item.rvwOpnnSn}`}> }
<TableCell align="center">{item.opnrNm}</TableCell> return [item.sewerBscPlanDocNo, item.chgCycl, item.rvwOpnnSn] as const;
<TableCell align="left">{item.rvwRsltCn || "-"}</TableCell> }
<TableCell align="center">
{item.rvwRsltAnmlyYn === "Y" ? "이상" : item.rvwRsltAnmlyYn === "N" ? "정상" : "-"} function TechReviewOpinionTable({ items, isReviewTurn }: TechReviewOpinionTableProps) {
</TableCell> const queryClient = useQueryClient();
<TableCell align="center"> const currentUserUuid = useUserStore((state) => state.userInfo?.userUnqId);
{item.atchFileInfo?.atflCd ? (
<AttachmentDownloadLink return (
atflCd={item.atchFileInfo.atflCd} <RvwOpnnListTable
fileName={item.atchFileInfo.orgnlFileNm || "다운로드"} items={items}
/> getRowKey={(item) => `${item.sewerBscPlanDocNo}_${item.rvwOpnnSn}`}
) : ( currentUserUuid={currentUserUuid}
"-" isReviewTurn={isReviewTurn}
)} onUpdate={async (item, body) => {
</TableCell> await sewerBscPlanRvwOpnnService.update(...getRvwOpnnIds(item), body);
<TableCell align="center"> await queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
{item.regDt ? dayjs(item.regDt).format("YYYY-MM-DD HH:mm:ss") : "-"} }}
</TableCell> onDelete={async (item) => {
</TableRow> await sewerBscPlanRvwOpnnService.delete(...getRvwOpnnIds(item));
))} await queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
</TableBody> }}
</Table> />
</div> );
); }
}
export { TechReviewOpinionSection };
export { TechReviewOpinionSection };
+3
View File
@@ -12,11 +12,13 @@ export const ENDPOINT = {
RVW_MNPW: "/as-service/api/v1/rvw-mnpw", RVW_MNPW: "/as-service/api/v1/rvw-mnpw",
BNS_IF: "/as-service/api/v1/if", BNS_IF: "/as-service/api/v1/if",
INSTL_SNCN: "/as-service/api/v1/instl-sncn", INSTL_SNCN: "/as-service/api/v1/instl-sncn",
INSTL_SNCN_RVW_OPNN: "/as-service/api/v1/instl-sncn-rvw-opnn",
CKLST: "/as-service/api/v1/cklst", CKLST: "/as-service/api/v1/cklst",
CKLST_ARTCL: "/as-service/api/v1/cklst-artcl", CKLST_ARTCL: "/as-service/api/v1/cklst-artcl",
CKLST_RVW: "/as-service/api/v1/cklst-rvw", CKLST_RVW: "/as-service/api/v1/cklst-rvw",
ADSTDSTR: "/as-service/api/v1/adstdstr", ADSTDSTR: "/as-service/api/v1/adstdstr",
FNRS_CNSLTN_MNG: "/as-service/api/v1/fnrs-cnsltn-mng", FNRS_CNSLTN_MNG: "/as-service/api/v1/fnrs-cnsltn-mng",
FNRS_CNSLTN_RVW_OPNN: "/as-service/api/v1/fnrs-cnsltn-rvw-opnn",
FNRS_SHAR_SE: "/as-service/api/v1/fnrs-shar-se-mng", FNRS_SHAR_SE: "/as-service/api/v1/fnrs-shar-se-mng",
DESIGN_CNSTN: "/as-service/api/v1/design-cnstn", DESIGN_CNSTN: "/as-service/api/v1/design-cnstn",
DESIGN_CNSTN_BIZ_CST: "/as-service/api/v1/design-cnstn-biz-cst", DESIGN_CNSTN_BIZ_CST: "/as-service/api/v1/design-cnstn-biz-cst",
@@ -24,6 +26,7 @@ export const ENDPOINT = {
DESIGN_CNSTN_ESNTL_ATCH_FILE: "/as-service/api/v1/design-cnstn-esntl-atch-file", DESIGN_CNSTN_ESNTL_ATCH_FILE: "/as-service/api/v1/design-cnstn-esntl-atch-file",
DESIGN_CNSTN_RVW_OPNN: "/as-service/api/v1/design-cnstn-rvw-opnn", DESIGN_CNSTN_RVW_OPNN: "/as-service/api/v1/design-cnstn-rvw-opnn",
SEWER_BSC_PLAN: "/as-service/api/v1/sewer-bsc-plans", SEWER_BSC_PLAN: "/as-service/api/v1/sewer-bsc-plans",
SEWER_BSC_PLAN_RVW_OPNNS: "/as-service/api/v1/sewer-bsc-plan-rvw-opnns",
DASHBOARD: "/as-service/api/v1/dashboard", DASHBOARD: "/as-service/api/v1/dashboard",
DCRAG_TO: "/as-service/api/v1/dcrag-to", DCRAG_TO: "/as-service/api/v1/dcrag-to",
AI_AUTO_PRCS_MNG: "/as-service/api/v1/ai-auto-prcs-mng", AI_AUTO_PRCS_MNG: "/as-service/api/v1/ai-auto-prcs-mng",
+1
View File
@@ -46,6 +46,7 @@ export type {
PbadmsMngDetResponseBase, PbadmsMngDetResponseBase,
RvwOpnnResponseExtension, RvwOpnnResponseExtension,
RvwOpnnSaveBase, RvwOpnnSaveBase,
RvwOpnnUpdateRequestDto,
SplmntDmndResponseExtension, SplmntDmndResponseExtension,
SplmntDmndSaveBase, SplmntDmndSaveBase,
} from "./pbadms-sprt"; } from "./pbadms-sprt";
+11
View File
@@ -231,11 +231,22 @@ export interface PbadmsApplySaveHeader {
rvwStpCd?: string; rvwStpCd?: string;
} }
/** 검토의견 수정 공통 요청 DTO */
export interface RvwOpnnUpdateRequestDto {
opnrSeComCd?: string;
opnrNm?: string;
rvwRsltCn?: string;
rvwRsltAnmlyYn?: string;
atchFileGroupId?: string;
}
/** 검토의견 응답 공통 확장 필드 */ /** 검토의견 응답 공통 확장 필드 */
export interface RvwOpnnResponseExtension { export interface RvwOpnnResponseExtension {
opnrSeCdNm?: string; opnrSeCdNm?: string;
atchFileInfo?: AtflMngClientResponseDto; atchFileInfo?: AtflMngClientResponseDto;
regDt?: string; regDt?: string;
rgtr?: string;
rgtrNm?: string;
} }
/** 보완요구 응답 공통 확장 필드 */ /** 보완요구 응답 공통 확장 필드 */
+1
View File
@@ -51,6 +51,7 @@ export {
} from "./ui/pbadms-task-apply-dialog"; } from "./ui/pbadms-task-apply-dialog";
export { PrivacyConsentSection } from "./ui/privacy-consent-section"; export { PrivacyConsentSection } from "./ui/privacy-consent-section";
export { ProgressStatusSection } from "./ui/progress-status-section"; export { ProgressStatusSection } from "./ui/progress-status-section";
export { RvwOpnnListTable, type RvwOpnnListTableProps } from "./ui/rvw-opnn-list-table";
export { export {
SplmntDmndDialog, SplmntDmndDialog,
type SplmntDmndDialogConfirmItem, type SplmntDmndDialogConfirmItem,
@@ -0,0 +1,406 @@
"use client";
import { useState } from "react";
import { useConfirm } from "@frontend-opensource/use-react-hooks";
import { dayjs, getDefaultFileKey, useTus } from "@/shared/lib";
import type { AtflMngClientResponseDto, RvwOpnnUpdateRequestDto } from "@/shared/model";
import { AttachmentFileField } from "@/shared/ui";
import { Field, FieldLabel, FieldSet } from "@/shared/ui/field";
import {
AttachmentDownloadLink,
attachService,
useDownloadAttachmentByAtflId,
} from "@/entities/attach";
import {
Button,
RadioGroup,
RadioGroupItem,
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
Textarea,
} from "@common/components";
const RVW_OPNN_EDIT_FILE_KEY_PREFIX = "rvw-opnn-edit::";
/** 업무별 검토의견 응답 DTO 공통 필드 (업무마다 null 허용 여부가 달라 느슨하게 정의) */
interface RvwOpnnListItem {
opnrSeComCd?: string | null;
opnrNm?: string | null;
rvwRsltCn?: string | null;
rvwRsltAnmlyYn?: string | null;
atchFileGroupId?: string | null;
atchFileInfo?: AtflMngClientResponseDto | null;
regDt?: string | null;
rgtr?: string | null;
}
interface RvwOpnnListTableProps<T extends RvwOpnnListItem> {
items: T[];
getRowKey: (item: T) => string;
/** 로그인 사용자 UUID — 검토의견 등록자(rgtr)와 같을 때만 수정·삭제 버튼 노출 */
currentUserUuid?: string;
/** 현재 검토 단계가 로그인 사용자 차례인지 여부 — false면 등록자라도 수정·삭제 불가 */
isReviewTurn?: boolean;
onUpdate: (item: T, body: RvwOpnnUpdateRequestDto) => Promise<void>;
onDelete: (item: T) => Promise<void>;
}
interface EditDraft {
rvwRsltCn: string;
rvwRsltAnmlyYn: string;
atchFileGroupId: string;
}
interface EditFile {
fileName: string;
fileKey: string;
atflId?: string;
atflCd?: string;
/** 이번 수정 중 새로 업로드한 파일 여부 (취소 시 정리 대상) */
isNew: boolean;
}
function formatAnmlyYn(value?: string | null) {
if (value === "Y") return "이상";
if (value === "N") return "정상";
return "-";
}
function RvwOpnnListTable<T extends RvwOpnnListItem>({
items,
getRowKey,
currentUserUuid,
isReviewTurn = false,
onUpdate,
onDelete,
}: RvwOpnnListTableProps<T>) {
const { confirm } = useConfirm();
const { mutate: downloadByAtflId } = useDownloadAttachmentByAtflId();
const [editingKey, setEditingKey] = useState<string | null>(null);
const [draft, setDraft] = useState<EditDraft | null>(null);
const [editFile, setEditFile] = useState<EditFile | null>(null);
const [isSubmitting, setIsSubmitting] = useState(false);
const { uploadFileAsync, isUploading, uploads } = useTus({
onSuccess: (atflCd, atflId, _file, fileKey) => {
if (!atflCd || !atflId) return;
setDraft((prev) => (prev ? { ...prev, atchFileGroupId: atflCd } : prev));
setEditFile((prev) => (prev?.fileKey === fileKey ? { ...prev, atflCd, atflId } : prev));
},
onError: (_error, _file, fileKey) => {
setEditFile((prev) => (prev?.fileKey === fileKey ? null : prev));
},
});
const editFileUploading = editFile ? (isUploading[editFile.fileKey] ?? false) : false;
function canModify(item: T) {
return isReviewTurn && Boolean(currentUserUuid) && item.rgtr === currentUserUuid;
}
async function discardNewFile(file: EditFile | null) {
if (!file?.isNew) return;
uploads[file.fileKey]?.abort();
if (file.atflId) {
try {
await attachService.deleteAttachmentByAtflId(file.atflId);
} catch (error) {
console.error("검토의견 첨부파일 삭제 실패:", error);
}
}
}
function resetEdit() {
setEditingKey(null);
setDraft(null);
setEditFile(null);
}
function startEdit(item: T) {
void discardNewFile(editFile);
setEditingKey(getRowKey(item));
setDraft({
rvwRsltCn: item.rvwRsltCn ?? "",
rvwRsltAnmlyYn: item.rvwRsltAnmlyYn ?? "",
atchFileGroupId: item.atchFileGroupId ?? "",
});
setEditFile(
item.atchFileInfo?.atflCd
? {
fileName: item.atchFileInfo.orgnlFileNm || "첨부파일",
fileKey: `${RVW_OPNN_EDIT_FILE_KEY_PREFIX}${item.atchFileInfo.atflCd}`,
atflId: item.atchFileInfo.atflId,
atflCd: item.atchFileInfo.atflCd,
isNew: false,
}
: null,
);
}
function cancelEdit() {
void discardNewFile(editFile);
resetEdit();
}
async function handleFileAdd(files: FileList | null) {
if (!files || files.length === 0) return;
const file = files[0];
const fileKey = `${RVW_OPNN_EDIT_FILE_KEY_PREFIX}${getDefaultFileKey(file)}`;
setEditFile({ fileName: file.name, fileKey, isNew: true });
try {
await uploadFileAsync(file, { fileKey });
} catch {
// onError callback handles cleanup
}
}
function handleFileRemove() {
// 기존 파일은 저장 시점에 연결만 해제하고, 새로 올린 파일은 즉시 정리
void discardNewFile(editFile);
setEditFile(null);
setDraft((prev) => (prev ? { ...prev, atchFileGroupId: "" } : prev));
}
async function handleSave(item: T) {
if (!draft) return;
if (!draft.rvwRsltCn.trim()) {
alert("의견내용을 입력하세요.");
return;
}
if (!draft.rvwRsltAnmlyYn) {
alert("검토결과를 선택하세요.");
return;
}
if (!(await confirm("검토의견을 수정하시겠습니까?"))) return;
setIsSubmitting(true);
try {
await onUpdate(item, {
opnrSeComCd: item.opnrSeComCd ?? undefined,
opnrNm: item.opnrNm ?? undefined,
rvwRsltCn: draft.rvwRsltCn,
rvwRsltAnmlyYn: draft.rvwRsltAnmlyYn,
atchFileGroupId: draft.atchFileGroupId,
});
alert("수정되었습니다.");
resetEdit();
} catch (error) {
console.error("검토의견 수정 실패:", error);
alert("검토의견 수정 중 오류가 발생했습니다.");
} finally {
setIsSubmitting(false);
}
}
async function handleDelete(item: T) {
if (!(await confirm("검토의견을 삭제하시겠습니까?"))) return;
setIsSubmitting(true);
try {
await onDelete(item);
alert("삭제되었습니다.");
if (editingKey === getRowKey(item)) resetEdit();
} catch (error) {
console.error("검토의견 삭제 실패:", error);
alert("검토의견 삭제 중 오류가 발생했습니다.");
} finally {
setIsSubmitting(false);
}
}
function renderViewRow(item: T) {
return (
<>
<TableCell align="left">{item.rvwRsltCn || "-"}</TableCell>
<TableCell align="center">{formatAnmlyYn(item.rvwRsltAnmlyYn)}</TableCell>
<TableCell align="center">
{item.atchFileInfo?.atflCd ? (
<AttachmentDownloadLink
atflCd={item.atchFileInfo.atflCd}
fileName={item.atchFileInfo.orgnlFileNm || "다운로드"}
/>
) : (
"-"
)}
</TableCell>
</>
);
}
function renderEditRow(rowKey: string, editDraft: EditDraft) {
return (
<>
<TableCell align="left">
<Textarea
value={editDraft.rvwRsltCn}
onChange={(event) =>
setDraft((prev) => (prev ? { ...prev, rvwRsltCn: event.target.value } : prev))
}
placeholder="의견내용을 입력하세요"
rows={4}
className="min-h-[8rem] !text-xl"
/>
</TableCell>
<TableCell align="center">
<FieldSet>
<RadioGroup
value={editDraft.rvwRsltAnmlyYn}
onValueChange={(value) =>
setDraft((prev) => (prev ? { ...prev, rvwRsltAnmlyYn: value } : prev))
}
>
<div className="flex flex-col gap-2">
<FieldLabel
htmlFor={`rvw-opnn-edit-normal-${rowKey}`}
className="!w-auto border-none"
>
<Field orientation="horizontal" className="w-auto">
<RadioGroupItem value="N" id={`rvw-opnn-edit-normal-${rowKey}`} />
<span className="font-normal">정상</span>
</Field>
</FieldLabel>
<FieldLabel
htmlFor={`rvw-opnn-edit-abnormal-${rowKey}`}
className="!w-auto border-none"
>
<Field orientation="horizontal" className="w-auto">
<RadioGroupItem value="Y" id={`rvw-opnn-edit-abnormal-${rowKey}`} />
<span className="font-normal">이상</span>
</Field>
</FieldLabel>
</div>
</RadioGroup>
</FieldSet>
</TableCell>
<TableCell align="center">
<AttachmentFileField
files={
editFile
? [
{
fileKey: editFile.fileKey,
fileName: editFile.fileName,
onDownload: editFile.atflId
? () => downloadByAtflId(editFile.atflId!)
: undefined,
},
]
: []
}
inputId={`rvw-opnn-edit-${rowKey}-file-input`}
isUploadingByKey={isUploading}
multiple={false}
showAddButton={!editFile}
addDisabled={editFileUploading}
onAdd={(fileList) => void handleFileAdd(fileList)}
onRemove={handleFileRemove}
/>
</TableCell>
</>
);
}
return (
<div className="overflow-x-auto">
<Table
caption="검토의견 목록으로 의견자명, 의견내용, 검토결과, 첨부파일, 등록일시, 관리 정보 제공"
variant="secondary"
>
<colgroup>
<col width="10%" />
<col width="47%" />
<col width="6%" />
<col width="17%" />
<col width="10%" />
<col width="10%" />
</colgroup>
<TableHeader>
<TableRow>
<TableHead>의견자명</TableHead>
<TableHead>의견내용</TableHead>
<TableHead>검토결과</TableHead>
<TableHead>첨부파일</TableHead>
<TableHead>등록일시</TableHead>
<TableHead>관리</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{items.map((item) => {
const rowKey = getRowKey(item);
const isEditing = editingKey === rowKey && draft !== null;
return (
<TableRow key={rowKey}>
<TableCell align="center">{item.opnrNm}</TableCell>
{isEditing ? renderEditRow(rowKey, draft) : renderViewRow(item)}
<TableCell align="center">
{item.regDt ? dayjs(item.regDt).format("YYYY-MM-DD HH:mm:ss") : "-"}
</TableCell>
<TableCell align="center">
{!canModify(item) ? (
"-"
) : isEditing ? (
<div className="flex flex-wrap justify-center gap-1">
<Button
type="button"
size="sm"
onClick={() => void handleSave(item)}
disabled={isSubmitting || editFileUploading}
>
저장
</Button>
<Button
type="button"
size="sm"
color="white"
onClick={cancelEdit}
disabled={isSubmitting}
>
취소
</Button>
</div>
) : (
<div className="flex flex-wrap justify-center gap-1">
<Button
type="button"
size="sm"
color="white"
onClick={() => startEdit(item)}
disabled={isSubmitting}
>
수정
</Button>
<Button
type="button"
size="sm"
color="gray"
onClick={() => void handleDelete(item)}
disabled={isSubmitting}
>
삭제
</Button>
</div>
)}
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</div>
);
}
export { RvwOpnnListTable, type RvwOpnnListTableProps };