Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-fe: 공고 수정 화면에서 수정버튼 활성화되지 않는 문제 수정 #630

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions frontend/src/components/postManagement/PostManageBoard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,29 @@ export default function PostManageBoard({ postId }: PostManageBoardProps) {
const quillRef = useRef<ReactQuill | null>(null);

const { isLoading, postState, setPostState, modifyPostMutator } = usePostManagement({ postId });
const todayText = new Date().toISOString().split('T')[0];
const startDateText = postState ? formatDate(postState.startDate) : '';
const endDateText = postState ? formatDate(postState.endDate) : '';
const [contentText, setContentText] = useState<string | undefined>('');

const { register, errors } = useForm<RecruitmentInfoState>({ initialValues: postState });

const isModifyButtonValid = !!(
postState &&
postState.startDate &&
postState.endDate &&
postState.title.trim() &&
contentText?.trim() &&
!Object.values(errors).some((error) => error)
);

useEffect(() => {
if (!contentText) {
setContentText(postState.postingContent);
return;
}
setContentText(quillRef.current?.unprivilegedEditor?.getText());
}, [quillRef]);
}, [postState.postingContent, contentText, quillRef]);

useEffect(() => {
if (wrapperRef.current && !isLoading) {
Expand All @@ -43,15 +57,6 @@ export default function PostManageBoard({ postId }: PostManageBoardProps) {
return <div>로딩 중입니다...</div>;
}

const isModifyButtonValid = !!(
postState &&
postState.startDate &&
postState.endDate &&
postState.title.trim() &&
contentText?.trim() &&
!Object.values(errors).some((error) => error)
);

const handleStartDate = (e: React.ChangeEvent<HTMLInputElement>) => {
setPostState((prev) => ({
...prev,
Expand Down Expand Up @@ -98,7 +103,7 @@ export default function PostManageBoard({ postId }: PostManageBoardProps) {
<DateInput
width="22rem"
label="시작일"
min={postState.startDate.split('T')[0]}
min={todayText}
max={postState.endDate.split('T')[0]}
innerText={startDateText}
onChange={handleStartDate}
Expand Down
Loading