185 lines
8.3 KiB
TypeScript
185 lines
8.3 KiB
TypeScript
import { useState, useEffect, useCallback } from "react";
|
|
import { Button, Col, Modal, Row } from "react-bootstrap";
|
|
import type { logicType, questionInfoType } from "@modules/TypeModule";
|
|
import { DndProvider } from "react-dnd";
|
|
import { HTML5Backend } from "react-dnd-html5-backend";
|
|
import { LogicChild } from "@componentsQuestionSetup/LogicChild";
|
|
import axios from "axios";
|
|
import { URL_SEED } from "@modules/AxiosModule";
|
|
import { useRecoilState, useRecoilValue } from "recoil";
|
|
import { loginToken, projectInfo } from "@token/Token";
|
|
|
|
export const TotalLogicModal = (props:{
|
|
skey: string,
|
|
show :boolean,
|
|
onHide: () => void,
|
|
questionInfo: questionInfoType[],
|
|
}) => {
|
|
const [filterInfo, setFilterInfo] = useState<questionInfoType[]>([]);
|
|
const [deleteQuestionArray, setDeleteQuestionArray] = useState<number[]>([]);
|
|
const [allSelected, setAllSelected] = useState(false);
|
|
const [totalLogicArray, setTotalLogicArray] = useState<{ uk: number; before: any; after: any; }[]>([]);
|
|
const projectState = useRecoilValue(projectInfo);
|
|
const [token, setToken] = useRecoilState(loginToken);
|
|
const [beforeLogicArray, setBeforeLogicArray] = useState<logicType[]>([]);
|
|
const [afterLogicArray, setAfterLogicArray] = useState<logicType[]>([]);
|
|
|
|
const addTotalLogicBtn = () => {
|
|
// setTotalLogicArray([...totalLogicArray, {"logic":"","page":""}]);
|
|
}
|
|
|
|
const deleteQuestionClick = (uk:number) => {
|
|
setDeleteQuestionArray(prevUniqueKey => {
|
|
if (prevUniqueKey.includes(uk)) {
|
|
// 이미 활성화된 row를 클릭한 경우, 해당 ID를 제거
|
|
return prevUniqueKey.filter(questionUK => questionUK !== uk);
|
|
} else {
|
|
// 새로운 row를 활성화하는 경우, 해당 ID를 추가
|
|
return [...prevUniqueKey, uk];
|
|
}
|
|
});
|
|
}
|
|
|
|
//전체 선택
|
|
const allCheck = () => {
|
|
if (!allSelected) {
|
|
const newDeleteQuestionArray = filterInfo.map(ele => ele.question_unique_key);
|
|
setDeleteQuestionArray(newDeleteQuestionArray);
|
|
} else {
|
|
setDeleteQuestionArray([]);
|
|
}
|
|
setAllSelected(!allSelected);
|
|
}
|
|
|
|
//문항리스트
|
|
const infoFilterArray = () => {
|
|
const infoFilter = props.questionInfo.filter((ele) => ele.question_order > 0).sort((a, b) => a.question_order - b.question_order);
|
|
setFilterInfo(infoFilter);
|
|
}
|
|
|
|
// const renderTotalLogicChild = useCallback((logicData:logicType, logicArray:logicType[], questionInfo:questionInfoType[], eleIndex:number, questionUK:number) => {
|
|
// return (
|
|
// <LogicChild
|
|
// key={eleIndex}
|
|
// logicGroup={"total"}
|
|
// logicData={logicData}
|
|
// questionInfo={questionInfo}
|
|
// eleIndex={eleIndex}
|
|
// logicArray = {logicArray}
|
|
// questionUK={questionUK}
|
|
// setLogicArray = {setTotalLogicArray}
|
|
// moveLogicChild = {moveBeforeLogicChild}
|
|
// />
|
|
// )
|
|
// }, []);
|
|
|
|
|
|
const logicListShow = () => {
|
|
deleteQuestionArray.map((ele, idx) => {
|
|
axios.get(URL_SEED + '/question/getQuestionLogic', {
|
|
params: {
|
|
project_code: projectState.prjcode,
|
|
question_unique_key: ele
|
|
},
|
|
headers: {
|
|
'Authorization': `Bearer ${token.access}`,
|
|
}
|
|
}).then((response) => {
|
|
if (response.status === 200) {
|
|
const newLogic = {
|
|
uk: ele,
|
|
before: response.data.before_logic || [],
|
|
after: response.data.after_logic || []
|
|
};
|
|
|
|
setTotalLogicArray(prevArray => [...prevArray, newLogic]);
|
|
|
|
if (response.data.before_logic !== null) {
|
|
setBeforeLogicArray(response.data.before_logic);
|
|
} else {
|
|
setBeforeLogicArray([]);
|
|
}
|
|
if (response.data.after_logic !== null) {
|
|
setAfterLogicArray(response.data.after_logic);
|
|
} else {
|
|
setAfterLogicArray([]);
|
|
}
|
|
}
|
|
}).catch(error => {
|
|
console.log("getQuestionLogic", error);
|
|
});
|
|
});
|
|
};
|
|
|
|
useEffect(() => {
|
|
infoFilterArray();
|
|
},[props.questionInfo])
|
|
|
|
useEffect(() => {
|
|
logicListShow();
|
|
},[deleteQuestionArray])
|
|
|
|
return(
|
|
<Modal show={props.show} size="lg" backdrop='static'>
|
|
<Modal.Header>
|
|
<Modal.Title className="text-center">
|
|
전체 로직
|
|
</Modal.Title>
|
|
</Modal.Header>
|
|
<Modal.Body className="logicForm" style={{maxHeight:"600px!important", height:"600px", paddingTop:"0px", paddingBottom:"0px"}}>
|
|
<Row>
|
|
<Col md={3} style={{ overflowY:"auto", height:"600px", background:"#F3F4F5", paddingTop:"10px", borderRight:"1px solid #DEE2E6"}}>
|
|
<div className="custom-chk all-chcek mb-3">
|
|
<input type="checkbox" id="chk-all" checked={ allSelected } onChange={allCheck}/>
|
|
<label htmlFor="chk-all">전체 선택</label>
|
|
</div>
|
|
{
|
|
filterInfo.map((ele, index) => {
|
|
return(
|
|
<div key={ele.question_unique_key} className='d-flex list-item justify-content-center management'>
|
|
<div className="custom-chk">
|
|
<input type="checkbox" id={"chkDelete_" + ele.question_unique_key} value={ele.question_unique_key} onChange={() => deleteQuestionClick(ele.question_unique_key)} checked={deleteQuestionArray.includes(ele.question_unique_key)} />
|
|
<label htmlFor={"chkDelete_" + ele.question_unique_key} onChange={() => deleteQuestionClick(ele.question_unique_key)} />
|
|
</div>
|
|
<label className="w-100" htmlFor={"chkDelete_" + ele.question_unique_key} onChange={() => deleteQuestionClick(ele.question_unique_key)}>
|
|
<div className="file-li border mb-1" id={"chkDelete_" + ele.question_unique_key}
|
|
style={{
|
|
cursor: "pointer",
|
|
backgroundColor: deleteQuestionArray.includes(ele.question_unique_key) ? "#B1DFBC" : "white"
|
|
}}
|
|
>
|
|
{ele.question_id}
|
|
</div>
|
|
</label>
|
|
</div>
|
|
)
|
|
})
|
|
}
|
|
</Col>
|
|
<Col style={{paddingTop:"10px"}}>
|
|
{/* <div style={{height:"50%", }}>
|
|
<div>
|
|
<Button onClick={ addTotalLogicBtn }>전체 로직추가</Button>
|
|
</div>
|
|
<DndProvider backend={HTML5Backend}>
|
|
<div style={{overflowY:"auto", maxHeight:"75%", height:"75%"}}>
|
|
{
|
|
// totalLogicArray?.map((ele, index) => renderTotalLogicChild( ele, totalLogicArray, props.questionInfo, index, props.questionUniqueKey))
|
|
}
|
|
</div>
|
|
</DndProvider>
|
|
</div> */}
|
|
</Col>
|
|
</Row>
|
|
|
|
|
|
</Modal.Body>
|
|
<Modal.Footer>
|
|
<div className='mt-2 mr-1 float-right'>
|
|
<Button className='project-save-btn mr-2' variant="primary" >저장</Button>
|
|
<Button variant="secondary" onClick={()=>{props.onHide()}}>닫기</Button>
|
|
</div>
|
|
</Modal.Footer>
|
|
</Modal>
|
|
)
|
|
} |