Skip to content

Commit

Permalink
Merge pull request #396 from SejongPeer/feature/36
Browse files Browse the repository at this point in the history
feat : [36] 게시글 초기화 함수로 수정/ 태그 기능 수정 /게시글 작성 시 내용 초기화
  • Loading branch information
Youjiiin authored Aug 19, 2024
2 parents 1d24c2a + c1e123d commit d99718c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/components/studyPostWrite/studyRequirement/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Tag = () => {
.split('#')
.filter(e => e !== '');

setTags(tagSplit);
setTags(list);
};
return (
<div className={style.inputWrapper}>
Expand Down
1 change: 0 additions & 1 deletion src/pages/main/mainPage/MainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import buddy_button from '../../../assets/image/buddy_button.png';
import honbobButton from '../../../assets/image/honbobButton.png';
import style from './MainPage.module.css';
import { BuddyHandler, HonbobHandler } from './api';

const images = [honbobUse, buddyUse, peerUse];

const MainPage = () => {
Expand Down
54 changes: 26 additions & 28 deletions src/pages/study/studyPostWrite/StudyPostWrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const StudyPostWrite = props => {
setQuestionLink,
setTags,
} = usePostStore();

const {
isPopupVisible,
popupMessage,
Expand All @@ -85,6 +86,14 @@ const StudyPostWrite = props => {
studyLink,
tags
);
// 게시글 초기화
const reset = usePostStore(state => state.reset);
const resetCategory = useTimeTableStore(state => state.reset);
useEffect(() => {
reset();
resetCategory();
}, []);

const navigate = useNavigate();

const handleDatePickerFocus = event => {
Expand Down Expand Up @@ -233,7 +242,10 @@ const StudyPostWrite = props => {
}
const formStartDate = format(startDate, 'yyyy-MM-dd HH:mm:ss');
const formEndDate = format(endDate, 'yyyy-MM-dd HH:mm:ss');

const tagSplit = tags
.replace(/(\s*)/g, '')
.split('#')
.filter(e => e !== '');
const studyData =
studyType === 'lecture'
? {
Expand All @@ -247,7 +259,7 @@ const StudyPostWrite = props => {
lectureId: category,
recruitmentStartAt: formStartDate,
recruitmentEndAt: formEndDate,
tags: tags,
tags: tagSplit,
images: null,
}
: {
Expand All @@ -261,7 +273,7 @@ const StudyPostWrite = props => {
externalActivityId: category,
recruitmentStartAt: formStartDate,
recruitmentEndAt: formEndDate,
tags: tags,
tags: tagSplit,
images: null,
};
console.log(studyData);
Expand Down Expand Up @@ -289,18 +301,9 @@ const StudyPostWrite = props => {
}
alert('게시글 작성 완료');

// 게시글 초기화
setTitle('');
setCategory(null);
setStartDate('');
setEndDate('');
setMemberNum(1);
setSelectedWay('FACE_TO_FACE');
setSelectedFrequency('ONCE_OR_TWICE_A_WEEK');
setContent('');
setStudyLink('');
setQuestionLink('');
setTags([]);
//게시글 초기화 함수
reset();
resetCategory();

navigate(`/study/post/${studyId}`);
if (!response.ok) {
Expand Down Expand Up @@ -338,7 +341,10 @@ const StudyPostWrite = props => {
}
const formStartDate = format(startDate, 'yyyy-MM-dd HH:mm:ss');
const formEndDate = format(endDate, 'yyyy-MM-dd HH:mm:ss');

const tagSplit = tags
.replace(/(\s*)/g, '')
.split('#')
.filter(e => e !== '');
const studyData = {
title: title,
content: content,
Expand All @@ -350,7 +356,7 @@ const StudyPostWrite = props => {
lectureId: category,
recruitmentStartAt: formStartDate,
recruitmentEndAt: formEndDate,
tags: tags,
tags: tagSplit,
images: null,
};
console.log(studyData);
Expand Down Expand Up @@ -381,17 +387,9 @@ const StudyPostWrite = props => {
}
alert('게시글 수정 완료');

// 게시글 초기화
setTitle('');
setStartDate('');
setEndDate('');
setMemberNum(1);
setSelectedWay('FACE_TO_FACE');
setSelectedFrequency('ONCE_OR_TWICE_A_WEEK');
setContent('');
setStudyLink('');
setQuestionLink('');
setTags([]);
//게시글 초기화
reset();
resetCategory();

navigate(`/study/post/${props.studyId}`);
} catch (err) {
Expand Down
14 changes: 14 additions & 0 deletions src/pages/study/studyPostWrite/usePostStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,19 @@ const usePostStore = create(set => ({
setStudyLink: studyLink => set({ studyLink }),
setQuestionLink: questionLink => set({ questionLink }),
setTags: tags => set({ tags }),
reset: () =>
set({
title: '',
category: null,
startDate: '',
endDate: '',
memberNum: 1,
selectedWay: 'FACE_TO_FACE',
selectedFrequency: 'ONCE_OR_TWICE_A_WEEK',
content: '',
questionLink: '',
studyLink: '',
tags: [],
}),
}));
export default usePostStore;
6 changes: 6 additions & 0 deletions src/pages/study/timeTable/useTimeTableStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const useTimeTableStore = create(set => ({
setTableInfos: tableInfos => set({ tableInfos }),
setShowData: showData => set({ showData }),
setSubjectName: subjectName => set({ subjectName }),
reset: () =>
set({
tableInfos: [],
showData: [],
subjectName: '',
}),
}));

export default useTimeTableStore;

0 comments on commit d99718c

Please sign in to comment.