diff --git a/src/components/basis/flight/plan/FlightPlanAreaDetailForm.js b/src/components/basis/flight/plan/FlightPlanAreaDetailForm.js index 6b1b483..3b3bf66 100644 --- a/src/components/basis/flight/plan/FlightPlanAreaDetailForm.js +++ b/src/components/basis/flight/plan/FlightPlanAreaDetailForm.js @@ -10,8 +10,16 @@ import { Button } from 'reactstrap'; -const FlightPlanAreaDetailForm = ({ handleSave, handleClose, handleChange, handleBufferList, data, mapControl, test }) => { - +const FlightPlanAreaDetailForm = ({ + handleSave, + handleClose, + handleChange, + handleBufferList, + data, + mapControl, + test, + isDone +}) => { const coordList = data ? data[0].coordList : null; return ( @@ -36,14 +44,23 @@ const FlightPlanAreaDetailForm = ({ handleSave, handleClose, handleChange, handl
- {coordList ? + {coordList ? ( coordList.map((coord, idx) => { const latlon = coord.lat + ' / ' + coord.lon; return ( - + - + - ) + ); }) - : + ) : ( - + - } - + )}
@@ -85,65 +103,88 @@ const FlightPlanAreaDetailForm = ({ handleSave, handleClose, handleChange, handl
- - {test ? + + {test || isDone ? ( { + value={ + data[0].bufferZone + ? data[0].bufferZone + : '' + } + onChange={e => { const { name, value } = e.target; handleChange({ name, value - }) + }); }} /> - : + ) : ( { + value={ + data[0].bufferZone + ? data[0].bufferZone + : '' + } + onChange={e => { const { name, value } = e.target; handleChange({ name, value - }) + }); }} /> - } + )}
- {test ? + {test || isDone ? ( handleBufferList()} > 적용 - : + ) : ( handleBufferList()} > 적용 - } + )}
@@ -153,23 +194,26 @@ const FlightPlanAreaDetailForm = ({ handleSave, handleClose, handleChange, handl - + { + onChange={e => { const { name, value } = e.target; handleChange({ name, value - }) + }); }} + disabled={test || isDone} /> @@ -179,22 +223,27 @@ const FlightPlanAreaDetailForm = ({ handleSave, handleClose, handleChange, handl - + { + value={ + data[0].fltMethod ? data[0].fltMethod : '' + } + onChange={e => { const { name, value } = e.target; handleChange({ name, value - }) + }); }} + disabled={test || isDone} /> @@ -205,18 +254,17 @@ const FlightPlanAreaDetailForm = ({ handleSave, handleClose, handleChange, handl
- {test ? + {test || isDone ? ( handleSave()} - - disabled={test} + disabled={test || isDone} > 등록 - : + ) : ( 등록 - } + )} - ) -} + ); +}; export default FlightPlanAreaDetailForm; diff --git a/src/components/basis/flight/plan/FlightPlanAreaMap.js b/src/components/basis/flight/plan/FlightPlanAreaMap.js index ea1d5e0..bd10389 100644 --- a/src/components/basis/flight/plan/FlightPlanAreaMap.js +++ b/src/components/basis/flight/plan/FlightPlanAreaMap.js @@ -214,7 +214,8 @@ const FlightPlanAreaMap = props => { handleCoordinates={handleCoordinates} handleInitCoordinates={handleInitCoordinates} handleConfirm={props.handleConfirm} - isDisabled={props.test} + isYour={props.test} + isDone={props.isDone} /> ) : null} @@ -304,7 +305,7 @@ const FlightPlanAreaMap = props => { className='mr-1' color='primary' onClick={e => handlerDrawType('LINE')} - disabled={props.test} + disabled={props.test || props.isDone} > WayPoint @@ -312,7 +313,7 @@ const FlightPlanAreaMap = props => { className='mr-1' color='primary' onClick={e => handlerDrawType('CIRCLE')} - disabled={props.test} + disabled={props.test || props.isDone} > Circle @@ -320,7 +321,7 @@ const FlightPlanAreaMap = props => { className='mr-1' color='primary' onClick={e => handlerDrawType('POLYGON')} - disabled={props.test} + disabled={props.test || props.isDone} > Polygon @@ -332,7 +333,7 @@ const FlightPlanAreaMap = props => { // ):( // {disabled:false} // )} - disabled={props.test} + disabled={props.test || props.isDone} > 초기화 diff --git a/src/components/basis/flight/plan/FlightPlanForm.js b/src/components/basis/flight/plan/FlightPlanForm.js index fdb9130..700aece 100644 --- a/src/components/basis/flight/plan/FlightPlanForm.js +++ b/src/components/basis/flight/plan/FlightPlanForm.js @@ -34,7 +34,8 @@ const FlightPlanForm = ({ handleSave, handleDelete, modal, - handleDeleteArray + handleDeleteArray, + isDone }) => { const { areaList, pilotList, arcrftList } = data; @@ -79,7 +80,7 @@ const FlightPlanForm = ({ *성명 @@ -126,7 +128,7 @@ const FlightPlanForm = ({
@@ -152,7 +155,7 @@ const FlightPlanForm = ({ *이메일 @@ -187,45 +191,8 @@ const FlightPlanForm = ({ * 비행시작일자 - {/* { - (isFlightDone) ? - ( - - ) - : - ( - { - const value = moment(date[0]).format('YYYY-MM-DD HH:mm:ss') || ''; - handleChange({ - type: 'plan', - name: 'schFltStDt', - value - }) - }} - placeholder='비행 시작일자 선택(클릭)' - {...{options:{minDate: "today"}}} - /> - ) - } */} @@ -255,45 +223,8 @@ const FlightPlanForm = ({ * 비행종료일자 - {/* { - (isFlightDone) ? - ( - - ) - : - ( - { - const value = moment(date[0]).format('YYYY-MM-DD HH:mm:ss') || ''; - handleChange({ - type: 'plan', - name: 'schFltEndDt', - value - }) - }} - placeholder='비행 종료일자 선택(클릭)' - {...{options:{minDate: "today"}}} - /> - ) - } */} @@ -324,7 +256,7 @@ const FlightPlanForm = ({ 목적

조종사 정보

{ handleModal({ target: 'pilot', isOpen: true }); @@ -419,6 +352,7 @@ const FlightPlanForm = ({ data={item} handleChange={handleChange} handleDeleteArray={handleDeleteArray} + isDone={isDone} /> )) ) : ( @@ -432,7 +366,7 @@ const FlightPlanForm = ({

기체 정보

{ handleModal({ target: 'arcrft', isOpen: true }); @@ -449,6 +383,7 @@ const FlightPlanForm = ({ data={item} handleChange={handleChange} handleDeleteArray={handleDeleteArray} + isDone={isDone} /> )) ) : ( @@ -461,7 +396,7 @@ const FlightPlanForm = ({
{data.planSno ? ( - + ); }; export default FlightPlanForm; -const SelectModal = ({ handleModal, modal, test }) => { +const SelectModal = ({ handleModal, modal, test, isDone }) => { let title = ''; let description = ''; let type = ''; @@ -529,6 +469,7 @@ const SelectModal = ({ handleModal, modal, test }) => { handleModal={handleModal} type={type} test={test} + isDone={isDone} /> ); } @@ -686,7 +627,13 @@ const AreaForm = ({ data, handleChange, index }) => {
); }; -const PilotForm = ({ data, handleChange, index, handleDeleteArray }) => { +const PilotForm = ({ + data, + handleChange, + index, + handleDeleteArray, + isDone +}) => { const [test, setTest] = useState(); const { user } = useSelector(state => state.authState, shallowEqual); const { detail } = useSelector(state => state.flightState); @@ -806,7 +753,7 @@ const PilotForm = ({ data, handleChange, index, handleDeleteArray }) => { {data.groupNm ? ( handleDeleteArray({ type: 'pilot', index })} @@ -822,7 +769,13 @@ const PilotForm = ({ data, handleChange, index, handleDeleteArray }) => { ); }; -const ArcrftForm = ({ data, handleChange, index, handleDeleteArray }) => { +const ArcrftForm = ({ + data, + handleChange, + index, + handleDeleteArray, + isDone +}) => { const [test, setTest] = useState(); const { user } = useSelector(state => state.authState, shallowEqual); const { detail } = useSelector(state => state.flightState); @@ -945,7 +898,7 @@ const ArcrftForm = ({ data, handleChange, index, handleDeleteArray }) => { {data.groupNm ? ( handleDeleteArray({ type: 'arcrft', index })} diff --git a/src/components/map/naver/draw/FlightPlanDraw.js b/src/components/map/naver/draw/FlightPlanDraw.js index 5d8a7a9..aad4aad 100644 --- a/src/components/map/naver/draw/FlightPlanDraw.js +++ b/src/components/map/naver/draw/FlightPlanDraw.js @@ -7,7 +7,8 @@ import { InfoModal } from '../../../modal/InfoModal'; export const FlightPlanDraw = props => { const dispatch = useDispatch(); const mapControl = useSelector(state => state.controlMapReducer); - const isDisabled = props.isDisabled; + const isYour = props.isYour; + const isDone = props.isDone; const [pastPolyline, setPolyline] = useState(); const [pastBuffer, setBuffer] = useState(); @@ -590,7 +591,8 @@ export const FlightPlanDraw = props => { let clickSet; { - isDisabled === true ? (clickSet = false) : (clickSet = true); + // isDisabled === true ? (clickSet = false) : (clickSet = true); + (isYour || isDone) === true ? (clickSet = false) : (clickSet = true); } if (areas.areaType && areas.areaType === 'LINE') { @@ -629,7 +631,8 @@ export const FlightPlanDraw = props => { ); // dragCircleEve.push(naver.maps.Event.addListener(dragCircle[i], 'mousedown', function () { onMouseDownDrag(i) })) { - isDisabled + // isDisabled + isYour || isDone ? {} : dragCircleEve.push( naver.maps.Event.addListener( @@ -741,7 +744,8 @@ export const FlightPlanDraw = props => { ); // dragCircleEve.push(naver.maps.Event.addListener(dragCircle[i], 'mousedown', function () { onMouseDownDrag(i) })) { - isDisabled + // isDisabled + isYour || isDone ? {} : dragCircleEve.push( naver.maps.Event.addListener( @@ -838,7 +842,8 @@ export const FlightPlanDraw = props => { }); // Eve.mousedownEve = naver.maps.Event.addListener(circle, 'mousedown', function () { onMouseDownDrag(0); }) { - isDisabled + // isDisabled + isYour || isDone ? {} : (Eve.mousedownEve = naver.maps.Event.addListener( circle, diff --git a/src/containers/basis/flight/plan/FlightPlanAreaContainer.js b/src/containers/basis/flight/plan/FlightPlanAreaContainer.js index 0eb5f96..7ec74a2 100644 --- a/src/containers/basis/flight/plan/FlightPlanAreaContainer.js +++ b/src/containers/basis/flight/plan/FlightPlanAreaContainer.js @@ -1,60 +1,60 @@ import React, { useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import {Col, Row } from 'reactstrap'; +import { Col, Row } from 'reactstrap'; import * as Actions from '../../../../modules/basis/flight/actions/basisFlightAction'; import FlightPlanAreaMap from '../../../../components/basis/flight/plan/FlightPlanAreaMap'; import { drawTypeChangeAction } from '../../../../modules/control/map/actions/controlMapActions'; import FlightPlanAreaDetailContainer from './FlightPlanAreaDetailContainer'; -const FlightPlanAreaContainer = ({handleModal, test}) => { - const dispatch = useDispatch(); +const FlightPlanAreaContainer = ({ handleModal, test, isDone }) => { + const dispatch = useDispatch(); - const { publicAreaList} = useSelector(state => state.flightState); - const [airArea, setAirArea] = useState(null); + const { publicAreaList } = useSelector(state => state.flightState); + const [airArea, setAirArea] = useState(null); - useEffect(() => { - dispatch(drawTypeChangeAction('')); - getAirAreaList(); - }, []); + useEffect(() => { + dispatch(drawTypeChangeAction('')); + getAirAreaList(); + }, []); - useEffect(() => { - setAirArea(publicAreaList); - }, [publicAreaList]) + useEffect(() => { + setAirArea(publicAreaList); + }, [publicAreaList]); + const getAirAreaList = () => { + dispatch(Actions.PUBLIC_AREA_LIST.request()); + }; - const getAirAreaList = () => { - dispatch(Actions.PUBLIC_AREA_LIST.request()); - } - - const handleConfirm = (areaList) => { - if(areaList === undefined) { - alert('영역을 설정해 주세요.') - return false; - } - - dispatch(Actions.AREA_COORDINATE_LIST_SAVE(areaList)) + const handleConfirm = areaList => { + if (areaList === undefined) { + alert('영역을 설정해 주세요.'); + return false; } - return ( - - - {airArea != null ? ( - - ) : null} - - - - - - - ) -} + dispatch(Actions.AREA_COORDINATE_LIST_SAVE(areaList)); + }; + + return ( + + + {airArea != null ? ( + + ) : null} + + + + + + ); +}; export default FlightPlanAreaContainer; diff --git a/src/containers/basis/flight/plan/FlightPlanAreaDetailContainer.js b/src/containers/basis/flight/plan/FlightPlanAreaDetailContainer.js index f5cd10c..2a3c8b8 100644 --- a/src/containers/basis/flight/plan/FlightPlanAreaDetailContainer.js +++ b/src/containers/basis/flight/plan/FlightPlanAreaDetailContainer.js @@ -3,34 +3,35 @@ import { useDispatch, useSelector } from 'react-redux'; import { Col, Row, Form } from 'reactstrap'; import * as Actions from '../../../../modules/basis/flight/actions/basisFlightAction'; import FlightPlanAreaDetailForm from '../../../../components/basis/flight/plan/FlightPlanAreaDetailForm'; -import {initFlightBas} from '../../../../modules/basis/flight/models/basisFlightModel'; +import { initFlightBas } from '../../../../modules/basis/flight/models/basisFlightModel'; import { InfoModal } from '../../../../components/modal/InfoModal'; import axios from '../../../../modules/utils/customAxiosUtil'; - -const FlightPlanAreaDetailContainer = ({ handleModal,test }) => { +const FlightPlanAreaDetailContainer = ({ handleModal, test, isDone }) => { const dispatch = useDispatch(); const mapControl = useSelector(state => state.controlMapReducer); const { areaCoordList, detail } = useSelector(state => state.flightState); - const [areaDetail, setAreaDetail] = useState(initFlightBas.initDetail.areaList); + const [areaDetail, setAreaDetail] = useState( + initFlightBas.initDetail.areaList + ); const [alertModal, setAlertModal] = useState({ isOpen: false, title: '', desc: '' }); - const handleClose = (status) => { - handleModal({ type: 'area', isOpne: false}); - } + const handleClose = status => { + handleModal({ type: 'area', isOpne: false }); + }; const handleSave = async () => { const resultAreaDetail = areaDetail.map(area => { return { ...area, - coordList : areaDetail[0].coordList - } - }) + coordList: areaDetail[0].coordList + }; + }); // const resultAreaDetail_api = areaDetail.map((area, i) => { // let polygonCoord = areaDetail[0].coordList.concat(areaDetail[0].coordList[0]); @@ -39,7 +40,7 @@ const FlightPlanAreaDetailContainer = ({ handleModal,test }) => { // return { // ...area, // coordList : polygonCoord - // } + // } // } else { // return { // ...area, @@ -50,43 +51,44 @@ const FlightPlanAreaDetailContainer = ({ handleModal,test }) => { const { data } = await axios.post( // `api/bas/flight/airspace/contains`, resultAreaDetail_api - `api/bas/flight/airspace/contains`, resultAreaDetail - ) + `api/bas/flight/airspace/contains`, + resultAreaDetail + ); - if(data.result) { + if (data.result) { setAlertModal({ isOpen: true, title: '우회 여부 확인', desc: '경로상에 비행 금지된 구역이 있습니다.\n우회하여 경로 설정해주시기 바랍니다.' - }) + }); return false; } dispatch(Actions.AREA_DETAIL_LIST_SAVE(resultAreaDetail)); - handleModal({ type: 'area', isOpne: false}); - } + handleModal({ type: 'area', isOpne: false }); + }; const handleChange = ({ name, value }) => { setAreaDetail(prevState => { const areaList = prevState.map((area, i) => { return { ...area, - [name] : value - } + [name]: value + }; }); return areaList; - }) - } + }); + }; const handleBufferList = () => { dispatch(Actions.FLIGHT_PLAN_AREA_BUFFER_LIST.request(areaDetail)); - } + }; useEffect(() => { // 좌표등록 (등록 시 데이터 초기화) - if(areaCoordList !== undefined) { + if (areaCoordList !== undefined) { setAreaDetail(areaCoordList); // 새로 만든 영역 } }, [areaCoordList]); @@ -103,7 +105,6 @@ const FlightPlanAreaDetailContainer = ({ handleModal,test }) => { // }, []) - return ( @@ -116,12 +117,12 @@ const FlightPlanAreaDetailContainer = ({ handleModal,test }) => { data={areaDetail} mapControl={mapControl} test={test} + isDone={isDone} /> - - ) -} + ); +}; export default FlightPlanAreaDetailContainer; diff --git a/src/containers/basis/flight/plan/FlightPlanDetailContainer.js b/src/containers/basis/flight/plan/FlightPlanDetailContainer.js index ee63560..9bbdb94 100644 --- a/src/containers/basis/flight/plan/FlightPlanDetailContainer.js +++ b/src/containers/basis/flight/plan/FlightPlanDetailContainer.js @@ -4,537 +4,560 @@ import { CustomDetailLayout } from '../../../../components/layout/CustomDetailLa 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'; - const initModal = { - area: false, - pilot: false, - arcrft: false -} + area: false, + pilot: false, + arcrft: false +}; const FlightPlanDetailContainer = () => { - const dispatch = useDispatch(); - const history = useHistory(); - const location = useLocation(); - const urlParams = useParams(); - const flightState = useSelector(state => state.flightState); - 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: '' - }); - - useEffect(() => { - if (Object.keys(urlParams).length === 0 && urlParams.constructor === Object) return; - dispatch(Actions.FLIGHT_PLAN_DETAIL.request(urlParams.planSno)); - }, [urlParams]) + const dispatch = useDispatch(); + const urlParams = useParams(); + const flightState = useSelector(state => state.flightState); + 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 [date, setDate] = useState(); + const [isDone, setIsDone] = useState(); + + useEffect(() => { + setDate(''); + }, []); + + useEffect(() => { + if (date) { + let cTime = new Date(); + let pTime = new Date(date); + if (cTime > pTime) { + setIsDone(true); + } else { + setIsDone(false); + } + } + }, [date]); - useEffect(() => { - setDetailData({ - ...detail, - cstmrSno: sessionStorage.getItem('cstmrSno'), - groupId: sessionStorage.getItem('groupId'), - }); - }, [detail]) - - useEffect(() => { - if (pilotSelect !== undefined) { - const pilotList = detailData.pilotList.concat(); - const pilot = Object.assign({}, initFlightBas['pilot']); - - pilot.planSno = detailData.planSno; - pilot.cstmrSno = pilotSelect.cstmrSno; - pilot.groupNm = pilotSelect.groupNm; - pilot.clncd = pilotSelect.clncd; - pilot.email = pilotSelect.email; - pilot.memberName = pilotSelect.memberName; - pilot.hpno = pilotSelect.hpno; - - // 파일럿 중복 확인 - let checking = true - - 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); - } else { - pilotList[i] = pilot; - } - }); + useEffect(() => { + if (Object.keys(urlParams).length === 0 && urlParams.constructor === Object) + return; + dispatch(Actions.FLIGHT_PLAN_DETAIL.request(urlParams.planSno)); + }, [urlParams]); - if (checking) { - setDetailData(prevState => { - return { - ...prevState, - ['pilotList']: pilotList - } - }); - } + useEffect(() => { + if (detail.createDt) { + setDate(detail.schFltStDt); + } + setDetailData({ + ...detail, + cstmrSno: sessionStorage.getItem('cstmrSno'), + groupId: sessionStorage.getItem('groupId') + }); + }, [detail]); + + useEffect(() => { + if (pilotSelect !== undefined) { + const pilotList = detailData.pilotList.concat(); + const pilot = Object.assign({}, initFlightBas['pilot']); + + pilot.planSno = detailData.planSno; + pilot.cstmrSno = pilotSelect.cstmrSno; + pilot.groupNm = pilotSelect.groupNm; + pilot.clncd = pilotSelect.clncd; + pilot.email = pilotSelect.email; + pilot.memberName = pilotSelect.memberName; + pilot.hpno = pilotSelect.hpno; + + // 파일럿 중복 확인 + let checking = true; + + pilotList.forEach((p, i) => { + if (p.cstmrSno === pilotSelect.cstmrSno) { + setModal2({ + isOpen: true, + title: '중복값 입력 오류', + desc: '이미 등록된 조종사 정보입니다.' + }); + checking = false; + return false; } - }, [pilotSelect]) - - useEffect(() => { - if (arcrftSelect !== undefined) { - const arcrftList = detailData.arcrftList.concat(); - 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) { - setModal2({ - isOpen: true, - title: '중복값 입력 오류', - desc: '이미 등록된 기체 정보입니다.' - }); - checking = false; - return false; - } - - if (p.idntfNum) { - if (i === arcrftList.length - 1) arcrftList.push(arcrft); - } else { - arcrftList[i] = arcrft; - } - }); - - if (checking) { - setDetailData(prevState => { - return { - ...prevState, - ['arcrftList']: arcrftList - } - }) - } + if (p.cstmrSno !== 0) { + if (i === pilotList.length - 1) pilotList.push(pilot); + } else { + pilotList[i] = pilot; } - }, [arcrftSelect]) - - 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) { - targetCoordList = targetArea.coordList.map((coord, j) => { - return { - ...coord, - planAreaSno: area.planAreaSno, - planAreaCoordSno: 0 - } - }) - } - - return { - ...area, - areaType: targetArea.areaType, - bufferZone: targetArea.bufferZone ? targetArea.bufferZone : 0, - fltElev: targetArea.fltElev ? targetArea.fltElev : 0, - fltMethod: targetArea.fltMethod ? targetArea.fltMethod : '', - coordList: targetCoordList - } - }); - - setDetailData(prevState => { - return { - ...prevState, - ['areaList']: createAreaList - } - }) - - // dispatch(Actions.AREA_DETAIL_INIT()); + }); + + if (checking) { + setDetailData(prevState => { + return { + ...prevState, + ['pilotList']: pilotList + }; + }); + } + } + }, [pilotSelect]); + + useEffect(() => { + if (arcrftSelect !== undefined) { + const arcrftList = detailData.arcrftList.concat(); + 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) { + setModal2({ + isOpen: true, + title: '중복값 입력 오류', + desc: '이미 등록된 기체 정보입니다.' + }); + checking = false; + return false; } - }, [areaList]); - - useEffect(() => { - // 조종사, 기체 정보 Redux 초기화 - dispatch(Actions.PILOT_ARCRFT_SELECT_INIT()); - }, [flightState]); - - const handleModal = (modal) => { - if (modal.target === 'area' && modal.isOpen) { - if (detailData.areaList) { - dispatch(Actions.FLIGHT_PLAN_AREA_BUFFER_LIST.request(detailData.areaList)); - } + if (p.idntfNum) { + if (i === arcrftList.length - 1) arcrftList.push(arcrft); + } else { + arcrftList[i] = arcrft; } - - setModal(prevState => ({ - ...initModal, - [modal.target]: modal.isOpen - })) + }); + + if (checking) { + setDetailData(prevState => { + return { + ...prevState, + ['arcrftList']: arcrftList + }; + }); + } } - - // 변경감지 - const handleChange = ({ name, value, type, index, pIndex }) => { - const arrName = `${type}List`; - switch (type) { - case 'coord': - // TODO 추후 삭제 필요 start - if (name == 'lonlat') { - const values = value.split("/"); - let latValue = 1 - let lonValue = 1 - if (values.length == 1) { - latValue = values[0].trim(); - } else if (values.length == 2) { - latValue = values[0].trim(); - lonValue = values[1].trim(); - } else { - return; - } - setDetailData(prevState => { - const areaList = prevState.areaList.map((area, i) => { - if (i !== pIndex) return { ...area }; - - const coordList = area.coordList.map((coord, j) => { - if (j !== index) return { ...coord }; - return { - ...coord, - lat: latValue, - lon: lonValue - } - }) - return { - ...area, - coordList - } - }) - return { - ...prevState, - areaList - } - }) - return; - } - // TODO 추후 삭제 필요 end - - setDetailData(prevState => { - const areaArr = [...prevState.areaList]; - const coordArr = areaArr[pIndex].coordList; - const updateData = { - ...coordArr[index], - [name]: value - } - coordArr[index] = updateData; - areaArr[pIndex] = coordArr - return { - ...prevState, - areaList: areaArr - } - }) - break; - case 'area': - case 'pilot': - case 'arcrft': - setDetailData(prevState => { - const arr = [...prevState[arrName]]; - const updateData = { - ...prevState[arrName][index], - [name]: value - } - arr[index] = updateData; - return { - ...prevState, - [arrName]: arr - } - }) - break; - case 'plan': - default: - setDetailData(prevState => ({ - ...prevState, - [name]: value - })) - break; + }, [arcrftSelect]); + + 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) { + targetCoordList = targetArea.coordList.map((coord, j) => { + return { + ...coord, + planAreaSno: area.planAreaSno, + planAreaCoordSno: 0 + }; + }); } - } - // 추가 - const handleAddArray = ({ type, pIndex }) => { - const arrName = `${type}List`; - switch (type) { - case 'coord': - setDetailData(prevState => { - const areaArr = [...prevState.areaList]; - const coordArr = [...areaArr[pIndex].coordList, initFlightBas[type]]; - areaArr[pIndex] = coordArr; - return { - ...prevState, - areaList: [...areaArr] - } - }) - break; - case 'area': - case 'pilot': - setDetailData(prevState => { - return { - ...prevState, - [arrName]: [...prevState[arrName], initFlightBas[type]] - } - }) - break; - case 'arcrft': - setDetailData(prevState => { - return { - ...prevState, - [arrName]: [...prevState[arrName], initFlightBas[type]] - } - }) - break; - default: - break; - } + return { + ...area, + areaType: targetArea.areaType, + bufferZone: targetArea.bufferZone ? targetArea.bufferZone : 0, + fltElev: targetArea.fltElev ? targetArea.fltElev : 0, + fltMethod: targetArea.fltMethod ? targetArea.fltMethod : '', + coordList: targetCoordList + }; + }); + + setDetailData(prevState => { + return { + ...prevState, + ['areaList']: createAreaList + }; + }); + + // dispatch(Actions.AREA_DETAIL_INIT()); } - // 삭제 - const handleDeleteArray = ({ type, index, pIndex }) => { - const arrName = `${type}List`; - switch (type) { - case 'coord': - setDetailData(prevState => { - const areaArr = [...prevState.areaList]; - const coordArr = [...areaArr[pIndex]]; - const deleteData = coordArr.splice(index, 1); - areaArr[pIndex] = coordArr; - return { - ...prevState, - areaList: [...areaArr] - } - }) - break; - case 'area': - case 'pilot': - setDetailData(prevState => { - const arr = [...prevState[arrName]]; - const deleteData = arr.splice(index, 1); - - const id = initFlight.detail['pilotList'] - - 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) { - return { - ...prevState, - [arrName]: arr - } - } - else { - return { - ...prevState, - [arrName]: id - } - } - }) - break; - default: - break; - } + }, [areaList]); + + useEffect(() => { + // 조종사, 기체 정보 Redux 초기화 + dispatch(Actions.PILOT_ARCRFT_SELECT_INIT()); + }, [flightState]); + + const handleModal = modal => { + if (modal.target === 'area' && modal.isOpen) { + if (detailData.areaList) { + dispatch( + Actions.FLIGHT_PLAN_AREA_BUFFER_LIST.request(detailData.areaList) + ); + } } - // 저장 - const handleSave = () => { - 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; - } - - else if (!detailData.hpno) { - setModal2({ - isOpen: true, - title: '필수값 입력 오류', - desc: '전화번호를 입력해 주세요.' - }); - - return false; - } - - else if (!detailData.email) { - setModal2({ - isOpen: true, - title: '필수값 입력 오류', - desc: '이메일을 입력해 주세요.' - }); - - return false; - } - else if (!detailData.fltPurpose) { - setModal2({ - isOpen: true, - title: '필수값 입력 오류', - desc: '비행목적을 선택해 주세요.' - }); - - return false; - } - else if (!detailData.areaList[0].coordList[0].lat) { - setModal2({ - isOpen: true, - title: '필수값 입력 오류', - desc: '좌표를 선택해 주세요.' - }); - - return false; - } - else if (!detailData.areaList[0].fltElev) { - setModal2({ - isOpen: true, - title: '필수값 입력 오류', - desc: '반경/고도를 입력해 주세요.' - }); - - return false; - } - else if (!detailData.areaList[0].fltMethod) { - setModal2({ - isOpen: true, - title: '필수값 입력 오류', - desc: '비행방식를 입력해 주세요.' - }); - return false; - } - else if (!detailData.pilotList[0].groupNm) { - setModal2({ - isOpen: true, - title: '필수값 입력 오류', - desc: '조종사를 선택해 주세요.' - }); - - return false; - } - else if (!detailData.arcrftList[0].groupNm) { - setModal2({ - isOpen: true, - title: '필수값 입력 오류', - desc: '기체를 선택해 주세요.' - }); - - 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: '이메일 형식을 다시 확인해 주세요.', + setModal(prevState => ({ + ...initModal, + [modal.target]: modal.isOpen + })); + }; + + // 변경감지 + const handleChange = ({ name, value, type, index, pIndex }) => { + const arrName = `${type}List`; + switch (type) { + case 'coord': + // TODO 추후 삭제 필요 start + if (name == 'lonlat') { + const values = value.split('/'); + let latValue = 1; + let lonValue = 1; + if (values.length == 1) { + latValue = values[0].trim(); + } else if (values.length == 2) { + latValue = values[0].trim(); + lonValue = values[1].trim(); + } else { + return; + } + setDetailData(prevState => { + const areaList = prevState.areaList.map((area, i) => { + if (i !== pIndex) return { ...area }; + + const coordList = area.coordList.map((coord, j) => { + if (j !== index) return { ...coord }; + return { + ...coord, + lat: latValue, + lon: lonValue + }; + }); + return { + ...area, + coordList + }; }); - return false; + return { + ...prevState, + areaList + }; + }); + return; } - if (!detailData.planSno) { - dispatch(Actions.FLIGHT_PLAN_CREATE.request(detailData)); - } else { - dispatch(Actions.FLIGHT_PLAN_UPDATE.request(detailData)); - } - - dispatch(Actions.FLIGHT_PLAN_GROUP_SELECT({ cstmrSno: 0, groupId: '', groupNm: '' })); + // TODO 추후 삭제 필요 end + + setDetailData(prevState => { + const areaArr = [...prevState.areaList]; + const coordArr = areaArr[pIndex].coordList; + const updateData = { + ...coordArr[index], + [name]: value + }; + coordArr[index] = updateData; + areaArr[pIndex] = coordArr; + return { + ...prevState, + areaList: areaArr + }; + }); + break; + case 'area': + case 'pilot': + case 'arcrft': + setDetailData(prevState => { + const arr = [...prevState[arrName]]; + const updateData = { + ...prevState[arrName][index], + [name]: value + }; + arr[index] = updateData; + return { + ...prevState, + [arrName]: arr + }; + }); + break; + case 'plan': + default: + setDetailData(prevState => ({ + ...prevState, + [name]: value + })); + break; } - // 삭제 - const handleDelete = () => { - if (!urlParams.planSno || urlParams.planSno) { - - dispatch(Actions.FLIGHT_PLAN_DELETE.request(urlParams.planSno)); - } - dispatch(Actions.FLIGHT_PLAN_GROUP_SELECT({ cstmrSno: 0, groupId: '', groupNm: '' })); + }; + + // 추가 + const handleAddArray = ({ type, pIndex }) => { + const arrName = `${type}List`; + switch (type) { + case 'coord': + setDetailData(prevState => { + const areaArr = [...prevState.areaList]; + const coordArr = [...areaArr[pIndex].coordList, initFlightBas[type]]; + areaArr[pIndex] = coordArr; + return { + ...prevState, + areaList: [...areaArr] + }; + }); + break; + case 'area': + case 'pilot': + setDetailData(prevState => { + return { + ...prevState, + [arrName]: [...prevState[arrName], initFlightBas[type]] + }; + }); + break; + case 'arcrft': + setDetailData(prevState => { + return { + ...prevState, + [arrName]: [...prevState[arrName], initFlightBas[type]] + }; + }); + break; + default: + break; + } + }; + // 삭제 + const handleDeleteArray = ({ type, index, pIndex }) => { + const arrName = `${type}List`; + switch (type) { + case 'coord': + setDetailData(prevState => { + const areaArr = [...prevState.areaList]; + const coordArr = [...areaArr[pIndex]]; + const deleteData = coordArr.splice(index, 1); + areaArr[pIndex] = coordArr; + return { + ...prevState, + areaList: [...areaArr] + }; + }); + break; + case 'area': + case 'pilot': + setDetailData(prevState => { + const arr = [...prevState[arrName]]; + const deleteData = arr.splice(index, 1); + + const id = initFlight.detail['pilotList']; + + 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) { + return { + ...prevState, + [arrName]: arr + }; + } else { + return { + ...prevState, + [arrName]: id + }; + } + }); + break; + default: + break; + } + }; + // 저장 + const handleSave = () => { + 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; + } else if (!detailData.hpno) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '전화번호를 입력해 주세요.' + }); + + return false; + } else if (!detailData.email) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '이메일을 입력해 주세요.' + }); + + return false; + } else if (!detailData.fltPurpose) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '비행목적을 선택해 주세요.' + }); + + return false; + } else if (!detailData.areaList[0].coordList[0].lat) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '좌표를 선택해 주세요.' + }); + + return false; + } else if (!detailData.areaList[0].fltElev) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '반경/고도를 입력해 주세요.' + }); + + return false; + } else if (!detailData.areaList[0].fltMethod) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '비행방식를 입력해 주세요.' + }); + + return false; + } else if (!detailData.pilotList[0].groupNm) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '조종사를 선택해 주세요.' + }); + + return false; + } else if (!detailData.arcrftList[0].groupNm) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '기체를 선택해 주세요.' + }); + + 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 { + dispatch(Actions.FLIGHT_PLAN_UPDATE.request(detailData)); } - return ( - - - - {/**/} - - ) + 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)); + } + dispatch( + Actions.FLIGHT_PLAN_GROUP_SELECT({ + cstmrSno: 0, + groupId: '', + groupNm: '' + }) + ); + }; + + return ( + + + + {/**/} + + ); }; export default FlightPlanDetailContainer;