feat: 관리자 - 컨텐츠관리 - 팝업관리에서 '팝업 추가' API 요청 front-end
parent
b3c99b68cf
commit
811e914666
|
|
@ -34,7 +34,7 @@ function PopupWriter(props) {
|
||||||
|
|
||||||
const [modeInfo, setModeInfo] = useState({ mode: props.mode });
|
const [modeInfo, setModeInfo] = useState({ mode: props.mode });
|
||||||
const [text, setText] = useState("");
|
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 [schdulBgndeHH, setSchdulBgndeHH] = useState();
|
||||||
const [schdulBgndeMM, setSchdulBgndeMM] = useState();
|
const [schdulBgndeMM, setSchdulBgndeMM] = useState();
|
||||||
|
|
@ -43,45 +43,71 @@ function PopupWriter(props) {
|
||||||
const [boardAttachFiles, setBoardAttachFiles] = useState();
|
const [boardAttachFiles, setBoardAttachFiles] = useState();
|
||||||
|
|
||||||
useEffect(function () {
|
useEffect(function () {
|
||||||
|
initMode();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const formValidator = (formData) => {
|
const formValidator = (formData) => {
|
||||||
if (formData.get('schdulNm') === null || formData.get('schdulNm') === "") {
|
if (formData.get('title') === null || formData.get('title') === "") {
|
||||||
alert("일정명은 필수 값입니다.");
|
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("반복구분은 필수 값입니다.");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formData.get('schdulBgnde') > formData.get('schdulEndde')) {
|
if (formData.get('schdulBgnde') > formData.get('schdulEndde')) {
|
||||||
alert("종료일시는 시작일시보다 앞 설 수 없습니다.");
|
alert("종료일시는 시작일시보다 앞 설 수 없습니다.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (formData.get('contents') === null || formData.get('contents') === "") {
|
||||||
|
alert("내용은 필수 값입니다.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
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();
|
const formData = new FormData();
|
||||||
|
|
||||||
for (let key in scheduleDetail) {
|
for (let key in popupDetail) {
|
||||||
formData.append(key, scheduleDetail[key]);
|
if ( key === 'startDate' ) {
|
||||||
console.log("scheduleDetail [%s] ", key, scheduleDetail[key]);
|
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)) {
|
if (formValidator(formData)) {
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
method: modeInfo.method,
|
method: modeInfo.method,
|
||||||
|
|
@ -173,14 +199,14 @@ function PopupWriter(props) {
|
||||||
<div className="top_tit">
|
<div className="top_tit">
|
||||||
<h1 className="tit_1">팝업 추가</h1>
|
<h1 className="tit_1">팝업 추가</h1>
|
||||||
</div>
|
</div>
|
||||||
|
{/* <!-- 상단 입력 form --> */}
|
||||||
<div className='board_view2'>
|
<div className='board_view2'>
|
||||||
<dl>
|
<dl>
|
||||||
<dt><label htmlFor="title">제목</label><span className="req">필수</span></dt>
|
<dt><label htmlFor="title">제목</label><span className="req">필수</span></dt>
|
||||||
<dd>
|
<dd>
|
||||||
<input className="f_input2 w_full" type="text" name="title" title="제목" id="title" placeholder="제목을 입력하세요."
|
<input className="f_input2 w_full" type="text" name="title" title="제목" id="title" placeholder="제목을 입력하세요."
|
||||||
value={scheduleDetail.title}
|
value={popupDetail.title}
|
||||||
onChange={(e) => setScheduleDetail({ ...scheduleDetail, title: e.target.value })}
|
onChange={(e) => setScheduleDetail({ ...popupDetail, title: e.target.value })}
|
||||||
/>
|
/>
|
||||||
</dd>
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
@ -189,14 +215,14 @@ function PopupWriter(props) {
|
||||||
<dd className="datetime">
|
<dd className="datetime">
|
||||||
<span className="line_break">
|
<span className="line_break">
|
||||||
<DatePicker
|
<DatePicker
|
||||||
selected={scheduleDetail.startDate}
|
selected={popupDetail.startDate}
|
||||||
name="schdulBgnde"
|
name="schdulBgnde"
|
||||||
className="f_input"
|
className="f_input"
|
||||||
dateFormat="yyyy-MM-dd HH:mm"
|
dateFormat="yyyy-MM-dd HH:mm"
|
||||||
showTimeInput
|
showTimeInput
|
||||||
onChange={(date) => {
|
onChange={(date) => {
|
||||||
console.log("setStartDate : ", date);
|
console.log("setStartDate : ", date);
|
||||||
setScheduleDetail({ ...scheduleDetail, schdulBgnde: getDateFourteenDigit(date), schdulBgndeYYYMMDD: getYYYYMMDD(date), schdulBgndeHH: date.getHours(), schdulBgndeMM: date.getMinutes(), startDate: date });
|
setScheduleDetail({ ...popupDetail, schdulBgnde: getDateFourteenDigit(date), schdulBgndeYYYMMDD: getYYYYMMDD(date), schdulBgndeHH: date.getHours(), schdulBgndeMM: date.getMinutes(), startDate: date });
|
||||||
setSchdulBgndeHH(date.getHours());
|
setSchdulBgndeHH(date.getHours());
|
||||||
setSchdulBgndeMM(date.getMinutes());
|
setSchdulBgndeMM(date.getMinutes());
|
||||||
}} />
|
}} />
|
||||||
|
|
@ -206,15 +232,15 @@ function PopupWriter(props) {
|
||||||
</span>
|
</span>
|
||||||
<span className="line_break">
|
<span className="line_break">
|
||||||
<DatePicker
|
<DatePicker
|
||||||
selected={scheduleDetail.endDate}
|
selected={popupDetail.endDate}
|
||||||
name="schdulEndde"
|
name="schdulEndde"
|
||||||
className="f_input"
|
className="f_input"
|
||||||
dateFormat="yyyy-MM-dd HH:mm"
|
dateFormat="yyyy-MM-dd HH:mm"
|
||||||
showTimeInput
|
showTimeInput
|
||||||
minDate={scheduleDetail.startDate}
|
minDate={popupDetail.startDate}
|
||||||
onChange={(date) => {
|
onChange={(date) => {
|
||||||
console.log("setEndDate: ", date);
|
console.log("setEndDate: ", date);
|
||||||
setScheduleDetail({ ...scheduleDetail, schdulEndde: getDateFourteenDigit(date), schdulEnddeYYYMMDD: getYYYYMMDD(date), schdulEnddeHH: date.getHours(), schdulEnddeMM: date.getMinutes(), endDate: date });
|
setScheduleDetail({ ...popupDetail, schdulEndde: getDateFourteenDigit(date), schdulEnddeYYYMMDD: getYYYYMMDD(date), schdulEnddeHH: date.getHours(), schdulEnddeMM: date.getMinutes(), endDate: date });
|
||||||
setSchdulEnddeHH(date.getHours());
|
setSchdulEnddeHH(date.getHours());
|
||||||
setSchdulEnddeMM(date.getMinutes());
|
setSchdulEnddeMM(date.getMinutes());
|
||||||
}
|
}
|
||||||
|
|
@ -227,7 +253,7 @@ function PopupWriter(props) {
|
||||||
<EgovAttachFile
|
<EgovAttachFile
|
||||||
fnChangeFile={(attachfile) => {
|
fnChangeFile={(attachfile) => {
|
||||||
console.log("====>>> Changed attachfile file = ", attachfile);
|
console.log("====>>> Changed attachfile file = ", attachfile);
|
||||||
const arrayConcat = { ...scheduleDetail}; // 기존 단일 파일 업로드에서 다중파일 객체 추가로 변환(아래 for문으로)
|
const arrayConcat = { ...popupDetail}; // 기존 단일 파일 업로드에서 다중파일 객체 추가로 변환(아래 for문으로)
|
||||||
for ( let i = 0; i < attachfile.length; i++) {
|
for ( let i = 0; i < attachfile.length; i++) {
|
||||||
arrayConcat[`file_${i}`] = attachfile[i];
|
arrayConcat[`file_${i}`] = attachfile[i];
|
||||||
}
|
}
|
||||||
|
|
@ -240,6 +266,7 @@ function PopupWriter(props) {
|
||||||
boardFiles={boardAttachFiles}
|
boardFiles={boardAttachFiles}
|
||||||
mode={props.mode} />
|
mode={props.mode} />
|
||||||
</div>
|
</div>
|
||||||
|
{/* <!--// 상단 입력 form --> */}
|
||||||
|
|
||||||
{/* <!-- 게시판 --> */}
|
{/* <!-- 게시판 --> */}
|
||||||
<RichTextEditor item={text} setText={setText}/>
|
<RichTextEditor item={text} setText={setText}/>
|
||||||
|
|
@ -249,7 +276,7 @@ function PopupWriter(props) {
|
||||||
<div className="board_btn_area">
|
<div className="board_btn_area">
|
||||||
<div className="left_col btn1">
|
<div className="left_col btn1">
|
||||||
<button className="btn btn_skyblue_h46 w_100"
|
<button className="btn btn_skyblue_h46 w_100"
|
||||||
onClick={() => updateSchedule()}
|
onClick={() => createPopup()}
|
||||||
> 저장</button>
|
> 저장</button>
|
||||||
{modeInfo.mode === CODE.MODE_MODIFY &&
|
{modeInfo.mode === CODE.MODE_MODIFY &&
|
||||||
<button className="btn btn_skyblue_h46 w_100"
|
<button className="btn btn_skyblue_h46 w_100"
|
||||||
|
|
@ -257,14 +284,13 @@ function PopupWriter(props) {
|
||||||
onClickDeleteSchedule(location.state?.schdulId);
|
onClickDeleteSchedule(location.state?.schdulId);
|
||||||
}}>삭제</button>
|
}}>삭제</button>
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="right_col btn1">
|
<div className="right_col btn1">
|
||||||
<Link to={URL.ADMIN__CONTENTS__POP_UP} className="btn btn_blue_h46 w_100">목록</Link>
|
<Link to={URL.ADMIN__CONTENTS__POP_UP} className="btn btn_blue_h46 w_100">목록</Link>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* <!--// 버튼영역 --> */}
|
{/* <!--// 버튼영역 --> */}
|
||||||
|
|
||||||
</StyledDiv>
|
</StyledDiv>
|
||||||
{/* <!--// 본문 --> */}
|
{/* <!--// 본문 --> */}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue