Skip to content

Commit

Permalink
[ fix ] 수정된게 없으면 버튼 비활성화
Browse files Browse the repository at this point in the history
  • Loading branch information
NeatKYU committed Sep 13, 2023
1 parent c60ed62 commit 978767e
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/pages/nottodo/NotTodoCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ import { diffDay, formatDateToString, dateToyyyymmdd } from '@/utils/datepicker'
import { Toast } from '@/components/toast/Toast';
import { createNottodo, editNottodo } from '@/api/nottodo';
import { useRecoilValue } from 'recoil';
import { currentNottodoState } from '@/recoil/nottodo/atom';
import { currentNottodoState, nottodoProps } from '@/recoil/nottodo/atom';

interface editPayload {
notToDoText: string;
startDate: string;
endDate: string;
goal: string;
cheerUpMsg1: string;
cheerUpMsg2: string;
cheerUpMsg3: string;
}

export default function NotTodoCreatePage() {
const router = useNavigate();
Expand Down Expand Up @@ -188,10 +198,38 @@ export default function NotTodoCreatePage() {
}
};

const isEditing = (origin: nottodoProps | null, edit: editPayload) => {
if (origin) {
if (origin.notToDoText !== edit.notToDoText) return true;
if (origin.startDate !== edit.startDate) return true;
if (origin.endDate !== edit.endDate) return true;
if (origin.goal !== edit.goal) return true;
if (origin.cheerUpMessageList[0].content !== edit.cheerUpMsg1) return true;
if (origin.cheerUpMessageList[1].content !== edit.cheerUpMsg2) return true;
if (origin.cheerUpMessageList[2].content !== edit.cheerUpMsg3) return true;
return false;
} else {
return false;
}
};

const renderButton = (isEdit: boolean) => {
if (isEdit) {
const payload = {
notToDoText: title,
startDate: dateToyyyymmdd(startDate, '-'),
endDate: dateToyyyymmdd(endDate, '-'),
goal,
cheerUpMsg1: message1,
cheerUpMsg2: message2,
cheerUpMsg3: message3,
};
return (
<BottomButton variant="secondary" clickHandler={handleEdit}>
<BottomButton
variant="secondary"
disabled={!isEditing(currentNottodo, payload)}
clickHandler={handleEdit}
>
수정 완료
</BottomButton>
);
Expand Down

0 comments on commit 978767e

Please sign in to comment.