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 ] 2시간 뒤 절제기록 수정 못하도록 수정 #98

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
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
22 changes: 15 additions & 7 deletions src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import { useNavigate } from 'react-router-dom';
import { deleteModeration, getModerationList, ModerationType, postModeration, putModeration } from '@/api/moderation';

import { ModerationList } from './components/moderationList';
import { dateToAmPmTimeFormat, getFirstDateOfMonth, getLastDateOfMonth, isSameDate } from '@/utils/date';
import {
dateToAmPmTimeFormat,
getFirstDateOfMonth,
getLastDateOfMonth,
isSameDate,
isTwoHourPassing,
} from '@/utils/date';

export default function HomePage() {
const [selectedDate, setSelectedDate] = useState<Date>(new Date());
Expand Down Expand Up @@ -318,12 +324,14 @@ export default function HomePage() {
>
삭제
</button>
<button
className="w-full h-[48px] title2 bg-gray-50 rounded-lg text-gray-900"
onClick={handleOpenEdit}
>
수정
</button>
{selectedModeration && !isTwoHourPassing(selectedModeration.regDtm) ? (
<button
className="w-full h-[48px] title2 bg-gray-50 rounded-lg text-gray-900"
onClick={handleOpenEdit}
>
수정
</button>
) : null}
</div>
</BottomPopup>
<ConfirmPopup
Expand Down
11 changes: 11 additions & 0 deletions src/utils/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ export const parsingDotDate = (date: Date | string) => {

return `${year}.${month}.${day}`;
};

export const isTwoHourPassing = (date: string) => {
const newDate = new Date(date).getTime();
if (isNaN(newDate)) {
throw new Error('Invalid date string');
}
const currentTime = new Date().getTime();
const twoHoursInMilliseconds = 2 * 60 * 60 * 1000;

return currentTime - newDate >= twoHoursInMilliseconds;
};