Skip to content

Commit

Permalink
Feat: 투표 기한 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
goeun208 committed Apr 11, 2024
1 parent 356259f commit de34a8d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
28 changes: 19 additions & 9 deletions src/components/vote/setting/VoteTimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,31 @@ import PickerOverlay from './timePicker/PickerOverlay';
import { useState } from 'react';

const VoteTimePicker = ({ setOpenPicker, setVoteEndAt }: any) => {
const date = new Date();
const date: any = new Date();
const year = date.getFullYear();

const [month, setMonth] = useState<number>(1);
const [day, setDay] = useState<number>(1);
const [time, setTime] = useState(0);
const [hour, setHour] = useState<number>(1);
const [min, setMin] = useState<number>(0);
const settingDate: any = new Date(year, month - 1, day, time === 0 ? hour : 12 + hour, min, 0);
let diffTime = (settingDate.getTime() - date.getTime()) / (1000 * 60 * 60);
let diffDay = (settingDate.getTime() - date.getTime()) / (1000 * 60 * 60 * 24);

const onClickSelectBtn = () => {
setVoteEndAt(
`${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}T${
time === 0 ? (hour === 12 ? '00' : '0' + hour) : hour === 12 ? hour : hour + 12
}:${min < 10 ? '0' + min : min}:00`,
);
if (diffTime >= 1 && diffDay <= 7) {
// 1시간 이후이면서 7일 이내
setOpenPicker(false);
} else {
alert('마감시간은 지금으로부터 최소 1시간 이후, 최대 7일 이내로 설정할 수 있습니다.');
}
};

return (
<div>
Expand All @@ -29,14 +46,7 @@ const VoteTimePicker = ({ setOpenPicker, setVoteEndAt }: any) => {
</div>

<div
onClick={() => {
setOpenPicker(false),
setVoteEndAt(
`${year}-${month < 10 ? '0' + month : month}-${day < 10 ? '0' + day : day}T${
time === 0 ? (hour === 12 ? '00' : '0' + hour) : hour === 12 ? hour : hour + 12
}:${min < 10 ? '0' + min : min}:00`,
);
}}
onClick={onClickSelectBtn}
className="w-[585px] h-[72px] rounded-2xl text-b2 bg-main_orange text-white flex items-center justify-center mx-auto mt-16">
선택완료
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/pages/vote/detail/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ const VoteDetailPage = () => {
const [clickedEndVote, setClickedEndVote] = useState<boolean>(false); // 투표 종료 버튼 클릭 여부
const [voteMax, setVoteMax] = useState<any>();
const token = api.getToken();
const userId = api.getId();
const groupIdData = useRecoilValue(groupIdAtom);
const groupAdminId = typeof window !== 'undefined' ? sessionStorage.getItem('adminId') : null;
const [voteIds, setVoteIds] = useState<any>([]);

const response = useGetGroupVote(groupIdData.groupId);
const response = useGetGroupVote(groupIdData.groupId, userId);
const currentId = api.getEmail();
const voteP: voteSelectPlaceData = {
groupId: groupIdData.groupId,
Expand Down

0 comments on commit de34a8d

Please sign in to comment.