diff --git a/src/views/laanc/FlightPlan.js b/src/views/laanc/FlightPlan.js index 7fdefb24..5df81ca2 100644 --- a/src/views/laanc/FlightPlan.js +++ b/src/views/laanc/FlightPlan.js @@ -6,6 +6,7 @@ import { VscRadioTower } from 'react-icons/vsc'; import { useDispatch, useSelector } from 'react-redux'; import Flatpickr from 'react-flatpickr'; import '@styles/react/libs/flatpickr/flatpickr.scss'; +import { ErrorModal } from '../../components/modal/ErrorModal'; import moment from 'moment'; import { Button, @@ -34,13 +35,151 @@ import { import { useHistory } from 'react-router-dom'; const FlightPlan = props => { const [detailData, setDetailData] = useState(initFlightBas.initDetail); + const [modal2, setModal2] = useState({ + isOpen: false, + title: '', + desc: '' + }); const history = useHistory(); const handleChange = ({ name, value, type, index, pIndex }) => { - setDetailData(prevState => ({ - ...prevState, - [name]: value - })); + // 입력 값에서 숫자 이외의 문자를 제거 + console.log('>>', name); + + const arrName = `${type}List`; + + switch (type) { + case 'area': + case 'pilot': + case 'arcrft': + if (name === 'fltElev' || name === 'bufferZone') { + const newValue = value.replace(/[^0-9]/g, ''); + setDetailData(prevState => { + const arr = [...prevState[arrName]]; + const updateData = { + ...prevState[arrName][0], + [name]: newValue + }; + arr[0] = updateData; + return { + ...prevState, + [arrName]: arr + }; + }); + } else { + setDetailData(prevState => { + const arr = [...prevState[arrName]]; + const updateData = { + ...prevState[arrName][0], + [name]: value + }; + arr[0] = updateData; + return { + ...prevState, + [arrName]: arr + }; + }); + } + break; + case 'plan': + default: + setDetailData(prevState => ({ + ...prevState, + [name]: value + })); + break; + } + }; + + console.log('>>>', detailData); + const handlerNext = () => { + 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.pilotList[0].memberName) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '이름을 입력해 주세요.' + }); + + return false; + } else if (!check_num.test(detailData.pilotList[0].hpno)) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '연락처를 확인해 주세요.' + }); + return false; + + return false; + } else if (!reg_email.test(detailData.pilotList[0].email)) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '이메일을 확인해 주세요.' + }); + + return false; + } else if (!detailData.fltPurpose) { + 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].bufferZone) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '반경을 입력해 주세요.' + }); + + return false; + } else if (!detailData.areaList[0].fltMethod) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '비행방식를 입력해 주세요.' + }); + + return false; + } else if (!detailData.arcrftList[0].groupNm) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '기체 신고 번호를 입력해 주세요.' + }); + + return false; + } else if (!detailData.arcrftList[0].arcrftTypeCd) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '기체 종류를 입력해 주세요.' + }); + + return false; + } else if (!detailData.arcrftList[0].ownerNm) { + setModal2({ + isOpen: true, + title: '필수값 입력 오류', + desc: '소유자명(법인명)를 입력해 주세요.' + }); + + return false; + } else handleClick(2); }; const handleClick = value => { @@ -124,11 +263,11 @@ const FlightPlan = props => { id='memberName' name='memberName' // defaultValue={data.memberName} - // value={data.memberName || ''} + value={detailData.pilotList[0].memberName || ''} onChange={e => { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'pilot', name, value }); @@ -155,7 +294,7 @@ const FlightPlan = props => { onChange={e => { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'pilot', name, value }); @@ -169,12 +308,12 @@ const FlightPlan = props => { id='hpno' name='hpno' // defaultValue={data.hpno} - // value={data.hpno || ''} + value={detailData.pilotList[0].hpno || ''} bsSize='sm' onChange={e => { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'pilot', name, value }); @@ -194,12 +333,12 @@ const FlightPlan = props => { id='email' name='email' // defaultValue={data.email || ''} - // value={data.email} + value={detailData.pilotList[0].email} bsSize='sm' onChange={e => { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'pilot', name, value }); @@ -228,8 +367,8 @@ const FlightPlan = props => { id='schFltStDt' name='schFltStDt' data-enable-time - // defaultValue={data.schFltStDt} - // value={data.schFltStDt} + defaultValue={detailData.schFltStDt} + value={detailData.schFltStDt} onChange={date => { const value = moment(date[0]).format('YYYY-MM-DD HH:mm:ss') || @@ -255,8 +394,8 @@ const FlightPlan = props => { id='schFltEndDt' name='schFltEndDt' data-enable-time - // defaultValue={data.schFltEndDt} - // value={data.schFltEndDt} + defaultValue={detailData.schFltEndDt} + value={detailData.schFltEndDt} onChange={date => { const value = moment(date[0]).format('YYYY-MM-DD HH:mm:ss') || @@ -280,7 +419,7 @@ const FlightPlan = props => { type='select' id='fltPurpose' name='fltPurpose' - // value={data.fltPurpose} + value={detailData.fltPurpose} bsSize='sm' onChange={e => { const { name, value } = e.target; @@ -325,15 +464,15 @@ const FlightPlan = props => { { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'area', name, value }); @@ -350,15 +489,15 @@ const FlightPlan = props => { { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'area', name, value }); @@ -375,15 +514,15 @@ const FlightPlan = props => { { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'area', name, value }); @@ -407,21 +546,21 @@ const FlightPlan = props => { { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'arcrft', name, value }); }} // innerRef={props.data} - placeholder='100m' + placeholder='' /> @@ -432,15 +571,15 @@ const FlightPlan = props => { { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'arcrft', name, value }); @@ -457,21 +596,21 @@ const FlightPlan = props => { { const { name, value } = e.target; handleChange({ - type: 'plan', + type: 'arcrft', name, value }); }} // innerRef={props.data} - placeholder='100m' + placeholder='' /> @@ -496,7 +635,7 @@ const FlightPlan = props => { className='mr-1' color='primary' bsSize='sm' - onClick={() => handleClick(2)} + onClick={() => handlerNext()} > 다음 @@ -506,6 +645,7 @@ const FlightPlan = props => { + ); };