251212_01_ENH : kri-editor 1차 완성, 프로젝트 정보 저장 api연동 완료
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client'
|
||||
|
||||
import {useEffect, useState} from 'react'
|
||||
import {useEffect, useState, useCallback, useRef} from 'react'
|
||||
import BodyTitle from '@/components/layout/BodyTitle'
|
||||
import {Button} from '@/components/ui/button'
|
||||
import {Input} from '@/components/ui/input'
|
||||
@@ -13,11 +13,11 @@ import {useDialog} from '@/hooks/useDialog'
|
||||
import ResultCodeDialog from '@/components/dialog/ResultCodeDialog'
|
||||
import {useMounted} from '@/hooks/useMounted'
|
||||
import {LoadingOverlay} from '@/components/common/LoadingOverlay'
|
||||
import {KonKiwiProjectInfo, ProjectInfo} from "@/types/project";
|
||||
import {KonKiwiProjectInfo, ProjectInfo, ProjectUpdateRequest, ResultCode} from "@/types/project";
|
||||
import {
|
||||
PROJECT_STATUS_LABEL,
|
||||
PROJECT_STATUS_ORDER,
|
||||
ProjectStatus,
|
||||
ProjectStatus, ResultCodeType,
|
||||
SURVEY_TYPE_LABEL,
|
||||
SURVEY_TYPE_ORDER,
|
||||
SurveyType
|
||||
@@ -31,20 +31,24 @@ import {UserInfo} from "@/types/user";
|
||||
import {useDebouncedValue} from "@/hooks/useDebouncedValue";
|
||||
import {useAuth} from "@/hooks/useAuth";
|
||||
import {KriEditor} from "@/components/kri-editor";
|
||||
import _ from "lodash";
|
||||
|
||||
|
||||
const defaultProjectInfo: Partial<ProjectInfo> = {
|
||||
const defaultProjectInfo: ProjectInfo = {
|
||||
prjctIdx: 0,
|
||||
prjctCd: '',
|
||||
prjctName: '',
|
||||
prjctStatus: 0,
|
||||
itrntPrjctCd: '',
|
||||
prjctStatus: ProjectStatus.WAITING,
|
||||
ownerDept: '',
|
||||
ownerFw: '',
|
||||
surveyTy: 0,
|
||||
surveyTy: SurveyType.NONE,
|
||||
surveyPrjctCd: '',
|
||||
surveyUrl: '',
|
||||
ff: false,
|
||||
useContactSenario: false,
|
||||
contactSenario: '',
|
||||
regUser: '',
|
||||
regDt: '',
|
||||
}
|
||||
|
||||
type ExternalTab = 'redirect' | 'api'
|
||||
@@ -56,8 +60,10 @@ const ProjectInfoPage = () => {
|
||||
const { users, isLoading } = useItrntUserList();
|
||||
const { auth } = useAuth();
|
||||
|
||||
const [projectInfo, setProjectInfo] = useState<Partial<ProjectInfo>>(defaultProjectInfo);
|
||||
const [projectInfo, setProjectInfo] = useState<ProjectInfo>(defaultProjectInfo);
|
||||
const [outsourceUserArray, setOutsourceUserArray] = useState<string[]>([]);
|
||||
const [resultCodeArray, setResultCodeArray] = useState<ResultCode[]>([]);
|
||||
const [changeResultCodeType, setChangeResultCodeType] = useState<ResultCodeType[]>([]);
|
||||
|
||||
const [outsourceOptionArray, setOutsourceOptionArray] = useState<MultiSelectOption[]>([]);
|
||||
const [deptArray, setDeptArray] = useState<string[]>([]);
|
||||
@@ -68,6 +74,7 @@ const ProjectInfoPage = () => {
|
||||
const [surveyProjectArray, setSurveyProjectArray] = useState<KonKiwiProjectInfo[]>([]);
|
||||
|
||||
const [externalTab, setExternalTab] = useState<ExternalTab>('redirect')
|
||||
const sessionTempUrlsRef = useRef<Set<string>>(new Set());
|
||||
|
||||
const internalSurvey = [SurveyType.KON, SurveyType.KIWI];
|
||||
const baseUrl = 'https://kcont.kric.com'
|
||||
@@ -92,6 +99,7 @@ const ProjectInfoPage = () => {
|
||||
|
||||
const searchKonKiwiPrjct = async (keyword:string): Promise<void> => {
|
||||
const surveyType = projectInfo.surveyTy ?? SurveyType.NONE;
|
||||
|
||||
if(internalSurvey.includes(surveyType) && userTeam){
|
||||
const isKiwi = surveyType === SurveyType.KON? 0 : 1;
|
||||
const res = await nextApi.get<KonKiwiProjectInfo[]>(
|
||||
@@ -107,6 +115,19 @@ const ProjectInfoPage = () => {
|
||||
setProjectInfo((prev) => ({ ...prev, [field]: value }))
|
||||
}
|
||||
|
||||
const handleImageUpload = useCallback(
|
||||
async (file: File): Promise<{ url: string }> => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
|
||||
const url = await nextApi.putForm<string>(`/project/senario-image/${projectInfo.prjctCd}`, formData);
|
||||
|
||||
// 이 세션에서 업로드한 temp 파일 목록에 기록
|
||||
sessionTempUrlsRef.current.add(url);
|
||||
|
||||
return { url }
|
||||
}, [projectInfo.prjctCd]);
|
||||
|
||||
const handleResultCodeClick = () => {
|
||||
showDialog('resultCodeDialog')
|
||||
}
|
||||
@@ -116,7 +137,20 @@ const ProjectInfoPage = () => {
|
||||
alert('프로젝트명을 입력해주세요.')
|
||||
return
|
||||
}
|
||||
// TODO: 저장 API
|
||||
|
||||
const updateCodeArray = _.cloneDeep(
|
||||
resultCodeArray.filter((rc) => changeResultCodeType.includes(rc.resultCdTy))
|
||||
);
|
||||
|
||||
const requestUpdateProject:ProjectUpdateRequest = {
|
||||
projectInfo: projectInfo,
|
||||
resultCodeList: updateCodeArray,
|
||||
assignUserIdList: outsourceUserArray,
|
||||
}
|
||||
console.log(requestUpdateProject, projectInfo.prjctIdx)
|
||||
await nextApi.patch(`/project/${projectInfo.prjctIdx}`, requestUpdateProject);
|
||||
|
||||
alert("저장되었습니다.");
|
||||
}
|
||||
|
||||
const handleDeleteClick = async () => {
|
||||
@@ -135,7 +169,10 @@ const ProjectInfoPage = () => {
|
||||
useEffect(() => {
|
||||
if(selectedProject){
|
||||
nextApi.get<ProjectInfo>(`/project/info/${selectedProject.prjctIdx}`)
|
||||
.then((res) => { setProjectInfo(res)});
|
||||
.then((res) => setProjectInfo(res));
|
||||
|
||||
nextApi.get<ResultCode[]>(`/project/result-code/${selectedProject.prjctIdx}`)
|
||||
.then((res) => {setResultCodeArray(res)});
|
||||
|
||||
nextApi.get<UserInfo[]>(`/user/outsource`)
|
||||
.then((res) => {
|
||||
@@ -170,6 +207,7 @@ const ProjectInfoPage = () => {
|
||||
}
|
||||
}, [projectInfo.surveyTy, projectInfo.surveyPrjctCd])
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
let userTeams = Array.from(new Set(users.map(u => u.userTeam)));
|
||||
if(!userTeams.includes("T900")){ //TFT
|
||||
@@ -194,7 +232,6 @@ const ProjectInfoPage = () => {
|
||||
searchKonKiwiPrjct(keyword).then();
|
||||
}, [debouncedKeyword, projectInfo.surveyTy, userTeam]);
|
||||
|
||||
|
||||
if (!mounted) return <LoadingOverlay force />
|
||||
|
||||
return (
|
||||
@@ -286,9 +323,10 @@ const ProjectInfoPage = () => {
|
||||
<KriMultiSelect
|
||||
items={outsourceOptionArray}
|
||||
value={outsourceUserArray}
|
||||
onChange={(value) => console.log(value)}
|
||||
onChange={(value) => setOutsourceUserArray(value)}
|
||||
getValue={(item) => item.value}
|
||||
getLabel={(item) => item.label}
|
||||
maxCount={2}
|
||||
placeholder="없음"
|
||||
heightClassName="h-9"
|
||||
widthClassName="w-full"
|
||||
@@ -438,10 +476,12 @@ const ProjectInfoPage = () => {
|
||||
{projectInfo.useContactSenario && (
|
||||
<div className="ml-6 border rounded p-4 bg-gray-50 text-sm text-gray-600">
|
||||
<KriEditor
|
||||
value={projectInfo.contactSenario || ""}
|
||||
onChange={(str: string) => {handleChange('contactSenario', str); console.log(str)}}
|
||||
value={projectInfo.contactSenario ?? "<p></p>"}
|
||||
onChange={(html: string) => handleChange("contactSenario", html)}
|
||||
placeholder="컨택 시나리오를 작성해 주세요"
|
||||
className="w-full"
|
||||
debounceMs={600} // 기본 400ms, 원하면 늘리세요(예: 600~1000)
|
||||
onImageUpload={async (file) => await handleImageUpload(file)} // 사용 시만
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@@ -472,6 +512,10 @@ const ProjectInfoPage = () => {
|
||||
<ResultCodeDialog
|
||||
open={isDialogOpen('resultCodeDialog')}
|
||||
onOpenChange={(open) => (open ? showDialog('resultCodeDialog') : hideDialog('resultCodeDialog'))}
|
||||
changeCodeType={changeResultCodeType}
|
||||
onChangeCodeType={setChangeResultCodeType}
|
||||
sourceArray={resultCodeArray}
|
||||
onSave={setResultCodeArray}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user