Skip to content

Commit

Permalink
[ merge into dev ] 2시간 뒤 절제기록 수정 못하도록 수정
Browse files Browse the repository at this point in the history
[ fix ] 2시간 뒤 절제기록 수정 못하도록 수정
  • Loading branch information
NeatKYU authored Sep 11, 2023
2 parents acc2751 + addeed7 commit 72f436f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
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;
};

0 comments on commit 72f436f

Please sign in to comment.