diff --git a/egovframe-template-simple-react-contribution/src/pages/admin/contents/PopUp/Writer.jsx b/egovframe-template-simple-react-contribution/src/pages/admin/contents/PopUp/Writer.jsx index b02df6e..5fc2f5d 100644 --- a/egovframe-template-simple-react-contribution/src/pages/admin/contents/PopUp/Writer.jsx +++ b/egovframe-template-simple-react-contribution/src/pages/admin/contents/PopUp/Writer.jsx @@ -34,7 +34,7 @@ function PopupWriter(props) { const [modeInfo, setModeInfo] = useState({ mode: props.mode }); const [text, setText] = useState(""); - const [scheduleDetail, setScheduleDetail] = useState({ schdulDeptName: "관리자부서", schdulChargerName: "관리자", schdulKindCode: 2, reptitSeCode: "1", startDate: new Date(), endDate: new Date() }); + const [popupDetail, setScheduleDetail] = useState({ startDate: new Date(), endDate: new Date() }); const [schdulBgndeHH, setSchdulBgndeHH] = useState(); const [schdulBgndeMM, setSchdulBgndeMM] = useState(); @@ -42,46 +42,72 @@ function PopupWriter(props) { const [schdulEnddeMM, setSchdulEnddeMM] = useState(); const [boardAttachFiles, setBoardAttachFiles] = useState(); - useEffect(function () { + useEffect(function () { + initMode(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const formValidator = (formData) => { - if (formData.get('schdulNm') === null || formData.get('schdulNm') === "") { - alert("일정명은 필수 값입니다."); - return false; - } - if (formData.get('schdulCn') === null || formData.get('schdulCn') === "") { - alert("일정내용은 필수 값입니다."); - return false; - } - if (formData.get('schdulSe') === null || formData.get('schdulSe') === "") { - alert("일정구분은 필수 값입니다."); - return false; - } - if (formData.get('schdulIpcrCode') === null || formData.get('schdulIpcrCode') === "") { - alert("중요도는 필수 값입니다."); - return false; - } - if (formData.get('reptitSeCode') === null ||formData.get('reptitSeCode') === "") { - alert("반복구분은 필수 값입니다."); + if (formData.get('title') === null || formData.get('title') === "") { + alert("제목은 필수 값입니다."); return false; } + if (formData.get('schdulBgnde') > formData.get('schdulEndde')) { alert("종료일시는 시작일시보다 앞 설 수 없습니다."); return false; } + if (formData.get('contents') === null || formData.get('contents') === "") { + alert("내용은 필수 값입니다."); + return false; + } return true; } - const updateSchedule = () => { + const initMode = () => { + + // props.mode 값이 없으면 에러가 발생한다. + switch (props.mode) { + case CODE.MODE_CREATE: + setModeInfo({ + ...modeInfo, + modeTitle: "등록", + method : "POST", + editURL: '/contents/api/popup-manage' + }); + break; + case CODE.MODE_MODIFY: + setModeInfo({ + ...modeInfo, + modeTitle: "수정", + method : "PUT", + editURL: '/contents/api/popup-manage' + }); + break; + default: + navigate({pathname: URL.ERROR}, {state: {msg : ""}}); + } + //retrieveDetail(); + } + + + + const createPopup = () => { const formData = new FormData(); - for (let key in scheduleDetail) { - formData.append(key, scheduleDetail[key]); - console.log("scheduleDetail [%s] ", key, scheduleDetail[key]); + for (let key in popupDetail) { + if ( key === 'startDate' ) { + formData.append(key, getDateFourteenDigit( popupDetail[key] )); + } else if( key === 'endDate' ) { + formData.append(key, getDateFourteenDigit( popupDetail[key] )); + } else { + formData.append(key, popupDetail[key]); + } } + //게시글 내용 + formData.append("contents", text); + if (formValidator(formData)) { const requestOptions = { method: modeInfo.method, @@ -173,14 +199,14 @@ function PopupWriter(props) {