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 ] 시작일, 마감일 동일할 때 등록 못하도록 수정 #108

Merged
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
15 changes: 11 additions & 4 deletions src/pages/nottodo/NotTodoCreatePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ import { currentNottodoState } from '@/recoil/nottodo/atom';
export default function NotTodoCreatePage() {
const router = useNavigate();
const params = useParams();
const today = new Date();
const endDateRef = useRef<HTMLInputElement>(null);
const [title, setTitle] = useState<string>('');
const [goal, setGoal] = useState<string>('');
const [startDate, setStartDate] = useState<Date>(new Date());
const [endDate, setEndDate] = useState<Date>(new Date());
const [startDate, setStartDate] = useState<Date>(new Date(today.getFullYear(), today.getMonth(), today.getDate()));
const [endDate, setEndDate] = useState<Date>(new Date(today.getFullYear(), today.getMonth(), today.getDate()));
const [inputStartDate, setInputStartDate] = useState<string>('');
const [inputEndDate, setInputEndDate] = useState<string>('');
const [message1, setMessage1] = useState<string>('');
Expand Down Expand Up @@ -101,14 +102,20 @@ export default function NotTodoCreatePage() {
// 시작일, 종료일 계산
const startTime = startDate.getTime();
const endTime = endDate.getTime();

if (startTime > endTime) {
setDateHelpText('시작일이 종료일보다 늦을 수 없습니다');
return false;
}

// 100일 초과 여부 검사
const diff = endTime - startTime;
const dayTime = 1000 * 60 * 60 * 24;
// 1일 미만인지 검사
if (diff < dayTime) {
setDateHelpText('도전일은 1일 이상이 되어야 합니다.');
return false;
}
// 100일 초과 여부 검사
if (diff > dayTime * 100) {
setDateHelpText('100일 이상은 등록하실 수 없습니다');
return false;
Expand Down Expand Up @@ -222,7 +229,7 @@ export default function NotTodoCreatePage() {
필수
</div>
<div className="title1 ml-2">언제까지 도전하시나요?</div>
<div className="title2 text-accent ml-auto">총 {diffDay(startDate, endDate) + 1}일</div>
<div className="title2 text-accent ml-auto">총 {diffDay(startDate, endDate)}일</div>
</div>
<div className="w-full flex items-center">
<Input
Expand Down