From f158921a56f7c9e17a34d7ebee5f0a8703fe58ab Mon Sep 17 00:00:00 2001 From: sanguu Date: Wed, 28 Sep 2022 11:05:39 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=84=ED=96=89=EA=B3=84=ED=9A=8D=EC=84=9C(?= =?UTF-8?q?=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80=EC=82=AC=20=EA=B8=B0?= =?UTF-8?q?=ED=9A=8DX=20=EB=B2=84=EC=A0=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flight/plan/FlightPlanDetailContainer.js | 265 ++++++++++-------- 1 file changed, 147 insertions(+), 118 deletions(-) diff --git a/src/containers/basis/flight/plan/FlightPlanDetailContainer.js b/src/containers/basis/flight/plan/FlightPlanDetailContainer.js index 9c6f0c8..ee63560 100644 --- a/src/containers/basis/flight/plan/FlightPlanDetailContainer.js +++ b/src/containers/basis/flight/plan/FlightPlanDetailContainer.js @@ -1,10 +1,10 @@ -import React, {useEffect, useState} from 'react'; +import React, { useEffect, useState } from 'react'; import FlightPlanForm from '../../../../components/basis/flight/plan/FlightPlanForm'; -import {CustomDetailLayout} from '../../../../components/layout/CustomDetailLayout'; -import {useHistory, useLocation, useParams} from 'react-router-dom'; -import {useDispatch, useSelector} from 'react-redux'; +import { CustomDetailLayout } from '../../../../components/layout/CustomDetailLayout'; +import { useHistory, useLocation, useParams } from 'react-router-dom'; +import { useDispatch, useSelector } from 'react-redux'; import * as Actions from '../../../../modules/basis/flight/actions/basisFlightAction'; -import {initFlight, initFlightBas} from '../../../../modules/basis/flight/models/basisFlightModel'; +import { initFlight, initFlightBas } from '../../../../modules/basis/flight/models/basisFlightModel'; import { AiFillPropertySafety } from 'react-icons/ai'; import { ErrorModal } from '../../../../components/modal/ErrorModal'; import { CgArrowLeftR } from 'react-icons/cg'; @@ -25,30 +25,30 @@ const FlightPlanDetailContainer = () => { const { detail, pilotSelect, arcrftSelect, areaList, selectGroup } = flightState; const [modal, setModal] = useState(initModal); const [detailData, setDetailData] = useState(initFlightBas.initDetail); - //모달 관련 설정 - const [modal2, setModal2] = useState({ - isOpen: false, - title: '', - desc: '' - }); + //모달 관련 설정 + const [modal2, setModal2] = useState({ + isOpen: false, + title: '', + desc: '' + }); useEffect(() => { if (Object.keys(urlParams).length === 0 && urlParams.constructor === Object) return; dispatch(Actions.FLIGHT_PLAN_DETAIL.request(urlParams.planSno)); }, [urlParams]) - useEffect(() => { + useEffect(() => { setDetailData({ ...detail, cstmrSno: sessionStorage.getItem('cstmrSno'), - groupId: sessionStorage.getItem('groupId'), + groupId: sessionStorage.getItem('groupId'), }); }, [detail]) useEffect(() => { - if(pilotSelect !== undefined) { + if (pilotSelect !== undefined) { const pilotList = detailData.pilotList.concat(); - const pilot = Object.assign({}, initFlightBas['pilot']); + const pilot = Object.assign({}, initFlightBas['pilot']); pilot.planSno = detailData.planSno; pilot.cstmrSno = pilotSelect.cstmrSno; @@ -61,116 +61,116 @@ const FlightPlanDetailContainer = () => { // 파일럿 중복 확인 let checking = true - pilotList.forEach((p, i) => { - if(p.cstmrSno === pilotSelect.cstmrSno) { + pilotList.forEach((p, i) => { + if (p.cstmrSno === pilotSelect.cstmrSno) { setModal2({ isOpen: true, title: '중복값 입력 오류', desc: '이미 등록된 조종사 정보입니다.' - }); + }); checking = false; return false; } - if(p.cstmrSno !== 0) { - if(i === pilotList.length -1) pilotList.push(pilot); + if (p.cstmrSno !== 0) { + if (i === pilotList.length - 1) pilotList.push(pilot); } else { pilotList[i] = pilot; - } + } }); - if(checking) { + if (checking) { setDetailData(prevState => { return { ...prevState, ['pilotList']: pilotList } }); - } + } } - + }, [pilotSelect]) - useEffect(() => { - if(arcrftSelect !== undefined) { + useEffect(() => { + if (arcrftSelect !== undefined) { const arcrftList = detailData.arcrftList.concat(); - const arcrft = Object.assign({}, initFlightBas['arcrft']); - - arcrft.planSno = detailData.planSno; + const arcrft = Object.assign({}, initFlightBas['arcrft']); + + arcrft.planSno = detailData.planSno; arcrft.arcrftSno = arcrftSelect.arcrftSno; arcrft.groupId = arcrftSelect.groupId; arcrft.groupNm = arcrftSelect.groupNm; arcrft.arcrftModelNm = arcrftSelect.arcrftModelNm; arcrft.idntfTypeCd = arcrftSelect.idntfTypeCd; arcrft.arcrftTypeCd = arcrftSelect.arcrftTypeCd; - arcrft.idntfNum = arcrftSelect.idntfNum; - arcrft.ownerNm = arcrftSelect.ownerNm; - - let checking = true; - - arcrftList.forEach((p,i) => { - if(p.idntfNum === arcrftSelect.idntfNum) { + arcrft.idntfNum = arcrftSelect.idntfNum; + arcrft.ownerNm = arcrftSelect.ownerNm; + + let checking = true; + + arcrftList.forEach((p, i) => { + if (p.idntfNum === arcrftSelect.idntfNum) { setModal2({ isOpen: true, title: '중복값 입력 오류', desc: '이미 등록된 기체 정보입니다.' - }); + }); checking = false; return false; - } - - if(p.idntfNum) { - if(i === arcrftList.length -1) arcrftList.push(arcrft); - } else { + } + + if (p.idntfNum) { + if (i === arcrftList.length - 1) arcrftList.push(arcrft); + } else { arcrftList[i] = arcrft; - } - }); + } + }); - if(checking) { + if (checking) { setDetailData(prevState => { return { ...prevState, ['arcrftList']: arcrftList } - }) - } + }) + } } }, [arcrftSelect]) - useEffect(() => { - if(areaList !== undefined) { + useEffect(() => { + if (areaList !== undefined) { const areas = detailData.areaList.concat(); - + const createAreaList = areas.map((area, i) => { const targetArea = areaList[i]; - + let targetCoordList = area.coordList; - if(targetArea.coordList) { + if (targetArea.coordList) { targetCoordList = targetArea.coordList.map((coord, j) => { return { ...coord, - planAreaSno : area.planAreaSno, - planAreaCoordSno : 0 + planAreaSno: area.planAreaSno, + planAreaCoordSno: 0 } }) - } + } return { ...area, - areaType : targetArea.areaType, + areaType: targetArea.areaType, bufferZone: targetArea.bufferZone ? targetArea.bufferZone : 0, - fltElev : targetArea.fltElev ? targetArea.fltElev : 0, - fltMethod : targetArea.fltMethod ? targetArea.fltMethod : '', - coordList : targetCoordList + fltElev: targetArea.fltElev ? targetArea.fltElev : 0, + fltMethod: targetArea.fltMethod ? targetArea.fltMethod : '', + coordList: targetCoordList } - }); + }); setDetailData(prevState => { return { ...prevState, ['areaList']: createAreaList } - }) + }) // dispatch(Actions.AREA_DETAIL_INIT()); } @@ -179,14 +179,14 @@ const FlightPlanDetailContainer = () => { useEffect(() => { // 조종사, 기체 정보 Redux 초기화 - dispatch(Actions.PILOT_ARCRFT_SELECT_INIT()); + dispatch(Actions.PILOT_ARCRFT_SELECT_INIT()); }, [flightState]); const handleModal = (modal) => { - if(modal.target === 'area' && modal.isOpen) { - if(detailData.areaList) { + if (modal.target === 'area' && modal.isOpen) { + if (detailData.areaList) { dispatch(Actions.FLIGHT_PLAN_AREA_BUFFER_LIST.request(detailData.areaList)); - } + } } setModal(prevState => ({ @@ -196,18 +196,18 @@ const FlightPlanDetailContainer = () => { } // 변경감지 - const handleChange = ({name, value, type, index, pIndex}) => { + const handleChange = ({ name, value, type, index, pIndex }) => { const arrName = `${type}List`; switch (type) { case 'coord': // TODO 추후 삭제 필요 start - if(name == 'lonlat'){ + if (name == 'lonlat') { const values = value.split("/"); let latValue = 1 let lonValue = 1 - if(values.length == 1){ + if (values.length == 1) { latValue = values[0].trim(); - } else if(values.length == 2){ + } else if (values.length == 2) { latValue = values[0].trim(); lonValue = values[1].trim(); } else { @@ -215,10 +215,10 @@ const FlightPlanDetailContainer = () => { } setDetailData(prevState => { const areaList = prevState.areaList.map((area, i) => { - if(i !== pIndex) return {...area}; + if (i !== pIndex) return { ...area }; const coordList = area.coordList.map((coord, j) => { - if(j !== index) return {...coord}; + if (j !== index) return { ...coord }; return { ...coord, lat: latValue, @@ -281,7 +281,7 @@ const FlightPlanDetailContainer = () => { } // 추가 - const handleAddArray = ({type, pIndex}) => { + const handleAddArray = ({ type, pIndex }) => { const arrName = `${type}List`; switch (type) { case 'coord': @@ -317,7 +317,7 @@ const FlightPlanDetailContainer = () => { } } // 삭제 - const handleDeleteArray = ({type, index, pIndex}) => { + const handleDeleteArray = ({ type, index, pIndex }) => { const arrName = `${type}List`; switch (type) { case 'coord': @@ -337,36 +337,36 @@ const FlightPlanDetailContainer = () => { setDetailData(prevState => { const arr = [...prevState[arrName]]; const deleteData = arr.splice(index, 1); - + const id = initFlight.detail['pilotList'] - - if(arr.length > 0) { + + if (arr.length > 0) { return { ...prevState, [arrName]: arr } - } + } else { return { ...prevState, [arrName]: id } - } + } }) break; case 'arcrft': setDetailData(prevState => { const arr = [...prevState[arrName]]; const deleteData = arr.splice(index, 1); - + const id = initFlight.detail['arcrftList'] - if(arr.length > 0) { + if (arr.length > 0) { return { ...prevState, [arrName]: arr } - } - else{ + } + else { return { ...prevState, [arrName]: id @@ -380,37 +380,43 @@ const FlightPlanDetailContainer = () => { } // 저장 const handleSave = () => { - - if (!detailData.memberName) { + const reg_email = /^([0-9a-zA-Z_\.-]+)@([0-9a-zA-Z_-]+)(\.[0-9a-zA-Z_-]+){1,2}$/; + const check_num = /[0-9]/; + const check_kor = + /^[가-힣a-zA-Z0-9][^!@#$%^&*()+\=\[\]{};':"\\|,.<>\/?\s]*$/; + + if (!detailData.memberName) { setModal2({ isOpen: true, title: '필수값 입력 오류', desc: '이름을 입력해 주세요.' - }); + }); - return false; + return false; } + else if (!detailData.hpno) { setModal2({ isOpen: true, title: '필수값 입력 오류', desc: '전화번호를 입력해 주세요.' - }); + }); - return false; + return false; } - else if(!detailData.email){ + + else if (!detailData.email) { setModal2({ isOpen: true, title: '필수값 입력 오류', desc: '이메일을 입력해 주세요.' - }); + }); - return false; + return false; } - else if(!detailData.fltPurpose){ + else if (!detailData.fltPurpose) { setModal2({ - isOpen:true, + isOpen: true, title: '필수값 입력 오류', desc: '비행목적을 선택해 주세요.' }); @@ -422,63 +428,86 @@ const FlightPlanDetailContainer = () => { isOpen: true, title: '필수값 입력 오류', desc: '좌표를 선택해 주세요.' - }); + }); - return false; + return false; } else if (!detailData.areaList[0].fltElev) { setModal2({ isOpen: true, title: '필수값 입력 오류', desc: '반경/고도를 입력해 주세요.' - }); + }); - return false; + return false; } else if (!detailData.areaList[0].fltMethod) { setModal2({ isOpen: true, title: '필수값 입력 오류', desc: '비행방식를 입력해 주세요.' - }); + }); - return false; + return false; } else if (!detailData.pilotList[0].groupNm) { setModal2({ isOpen: true, title: '필수값 입력 오류', desc: '조종사를 선택해 주세요.' - }); + }); - return false; + return false; } else if (!detailData.arcrftList[0].groupNm) { setModal2({ isOpen: true, title: '필수값 입력 오류', desc: '기체를 선택해 주세요.' - }); + }); - return false; + return false; + } + else if (!check_kor.test(detailData.memberName)) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '지원하지 않는 입력값 입니다.' + }); + return false; + } + else if (!check_num.test(detailData.hpno)) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '연락처에 숫자만 입력해주세요.' + }); + return false; + } + if (!reg_email.test(detailData.email)) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '이메일 형식을 다시 확인해 주세요.', + }); + return false; } - if (!detailData.planSno) { dispatch(Actions.FLIGHT_PLAN_CREATE.request(detailData)); - } else { + } else { dispatch(Actions.FLIGHT_PLAN_UPDATE.request(detailData)); } - dispatch(Actions.FLIGHT_PLAN_GROUP_SELECT( {cstmrSno: 0, groupId: '', groupNm: ''} )); + dispatch(Actions.FLIGHT_PLAN_GROUP_SELECT({ cstmrSno: 0, groupId: '', groupNm: '' })); } // 삭제 const handleDelete = () => { - if(!urlParams.planSno || urlParams.planSno){ - - dispatch(Actions.FLIGHT_PLAN_DELETE.request(urlParams.planSno)); + if (!urlParams.planSno || urlParams.planSno) { + + dispatch(Actions.FLIGHT_PLAN_DELETE.request(urlParams.planSno)); + } + dispatch(Actions.FLIGHT_PLAN_GROUP_SELECT({ cstmrSno: 0, groupId: '', groupNm: '' })); } - dispatch(Actions.FLIGHT_PLAN_GROUP_SELECT({cstmrSno: 0, groupId: '', groupNm: ''})); -} return ( @@ -491,14 +520,14 @@ const FlightPlanDetailContainer = () => { handleChange={handleChange} handleAddArray={handleAddArray} handleDeleteArray={handleDeleteArray} - // handlerSave={ - // pageType === 'create' ? handlerCreate : handlerUpdate - // } - // onChange={onChange} - // handlerDelete={handlerDelete} - // handlerInput={handlerInput} + // handlerSave={ + // pageType === 'create' ? handlerCreate : handlerUpdate + // } + // onChange={onChange} + // handlerDelete={handlerDelete} + // handlerInput={handlerInput} /> - + {/*