-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
451 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Box, Flex } from "@chakra-ui/react"; | ||
import Image from "next/image"; | ||
import styled from "styled-components"; | ||
|
||
export interface IImageTileData { | ||
imageUrl: string; | ||
text: string; | ||
url?: string; | ||
func?: () => void; | ||
id?: string; | ||
} | ||
|
||
interface IImageTileGridLayout { | ||
imageDataArr: IImageTileData[]; | ||
selectedId?: string[]; | ||
selectedSubId?: string[]; | ||
} | ||
export default function ImageTileFlexLayout({ | ||
imageDataArr, | ||
|
||
selectedId, | ||
selectedSubId, | ||
}: IImageTileGridLayout) { | ||
function ImageTileLayout({ url, text }: { url: string; text: string }) { | ||
return ( | ||
<Flex direction="column" alignItems="center"> | ||
<Box w="64px" h="64px" borderRadius="8px" overflow="hidden"> | ||
<Image width={64} height={64} src={url} alt="studyPlaceImage" /> | ||
</Box> | ||
<Box mt="12px">{text}</Box> | ||
</Flex> | ||
); | ||
} | ||
|
||
return ( | ||
<Flex overflow="auto" pb="12px"> | ||
{imageDataArr.map((imageData, idx) => ( | ||
<Button | ||
key={idx} | ||
$isSelected={ | ||
selectedId?.includes(imageData?.id) | ||
? "main" | ||
: selectedSubId?.includes(imageData?.id) | ||
? "sub" | ||
: null | ||
} | ||
onClick={imageData.func} | ||
> | ||
<ImageTileLayout url={imageData.imageUrl} text={imageData.text} /> | ||
</Button> | ||
))} | ||
</Flex> | ||
); | ||
} | ||
|
||
const Button = styled.button<{ $isSelected: "main" | "sub" | null }>` | ||
background-color: ${(props) => | ||
props.$isSelected === "main" | ||
? "var(--color-mint)" | ||
: props.$isSelected === "sub" | ||
? "var(--color-orange)" | ||
: null}; | ||
color: ${(props) => (props.$isSelected ? "white" : "inherit")}; | ||
border-radius: var(--rounded); | ||
margin-right: 12px; | ||
height: 100px; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ export const getMyStudy = ( | |
} | ||
}), | ||
); | ||
|
||
console.log(34, participations, myStudy); | ||
return myStudy; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import CheckList from "../../components/atoms/CheckList"; | ||
import { IModal } from "../../types/components/modalTypes"; | ||
import { IFooterOptions, ModalLayout } from "../Modals"; | ||
|
||
function StudyPointGuideModal({ setIsModal }: IModal) { | ||
const footerOptions: IFooterOptions = { | ||
main: { | ||
text: "확인", | ||
}, | ||
}; | ||
|
||
const STUDY_CONTENTS = [ | ||
"결과 발표 이전에 신청한 경우 5 POINT + 선택한 서브 장소 만큼 추가 포인트 획득!", | ||
"가장 먼저 신청한 인원은 +10 POINT, 두번째 인원은 +5 POINT, 세번째 인원은 +2 POINT를 추가 획득!", | ||
"당일 참여나 자유 스터디의 경우 +2 POINT", | ||
]; | ||
|
||
return ( | ||
<ModalLayout setIsModal={setIsModal} title="스터디 포인트" footerOptions={footerOptions}> | ||
<CheckList contents={STUDY_CONTENTS} /> | ||
</ModalLayout> | ||
); | ||
} | ||
|
||
export default StudyPointGuideModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { Box } from "@chakra-ui/react"; | ||
import dayjs, { Dayjs } from "dayjs"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { useEffect, useState } from "react"; | ||
import { useQueryClient } from "react-query"; | ||
import { useRecoilValue } from "recoil"; | ||
|
||
import Selector from "../../components/atoms/Selector"; | ||
import ImageTileFlexLayout from "../../components/molecules/layouts/ImageTileFlexLayout"; | ||
import { IImageTileData } from "../../components/molecules/layouts/ImageTitleGridLayout"; | ||
import { StudyVoteTimeRullets } from "../../components/services/studyVote/StudyVoteTimeRulletDrawer"; | ||
import { STUDY_VOTE } from "../../constants/keys/queryKeys"; | ||
import { POINT_SYSTEM_PLUS } from "../../constants/serviceConstants/pointSystemConstants"; | ||
import { useToast } from "../../hooks/custom/CustomToast"; | ||
import { | ||
useStudyOpenFreeMutation, | ||
useStudyParticipationMutation, | ||
} from "../../hooks/study/mutations"; | ||
import { usePointSystemMutation } from "../../hooks/user/mutations"; | ||
import { usePointSystemLogQuery } from "../../hooks/user/queries"; | ||
import { myStudyState } from "../../recoils/studyRecoils"; | ||
import { ModalSubtitle } from "../../styles/layout/modal"; | ||
import { IModal } from "../../types/components/modalTypes"; | ||
import { IParticipation } from "../../types/models/studyTypes/studyDetails"; | ||
import { IStudyVote } from "../../types/models/studyTypes/studyInterActions"; | ||
import { LocationEn } from "../../types/services/locationTypes"; | ||
import { convertLocationLangTo } from "../../utils/convertUtils/convertDatas"; | ||
import { dayjsToStr } from "../../utils/dateTimeUtils"; | ||
import { IFooterOptions, ModalLayout } from "../Modals"; | ||
|
||
interface StudySimpleVoteModalProps extends IModal { | ||
studyVoteData: IParticipation[]; | ||
} | ||
|
||
function StudySimpleVoteModal({ studyVoteData, setIsModal }: StudySimpleVoteModalProps) { | ||
const toast = useToast(); | ||
const searchParams = useSearchParams(); | ||
const date = searchParams.get("date"); | ||
const locationEn = searchParams.get("location") as LocationEn; | ||
const location = convertLocationLangTo(locationEn, "kr"); | ||
|
||
const myStudy = useRecoilValue(myStudyState); | ||
const [selectedPlace, setSelectedPlace] = useState<string>(); | ||
const [isFirstPage, setIsFirstPage] = useState(true); | ||
const [myVote, setMyVote] = useState<IStudyVote>(); | ||
const [voteTime, setVoteTime] = useState<{ start: Dayjs; end: Dayjs }>(); | ||
|
||
const { data: pointLog } = usePointSystemLogQuery("point", true, { | ||
enabled: !!myStudy, | ||
}); | ||
const { mutate: getPoint } = usePointSystemMutation("point"); | ||
|
||
const { mutateAsync: openFree } = useStudyOpenFreeMutation(date, {}); | ||
|
||
const { mutate: patchAttend, isLoading } = useStudyParticipationMutation(dayjs(date), "post", { | ||
onSuccess() { | ||
handleSuccess(); | ||
}, | ||
}); | ||
|
||
useEffect(() => { | ||
setMyVote((old) => ({ | ||
...old, | ||
place: selectedPlace, | ||
start: voteTime?.start, | ||
end: voteTime?.end, | ||
})); | ||
}, [selectedPlace, voteTime]); | ||
|
||
const queryClient = useQueryClient(); | ||
|
||
const handleSuccess = async () => { | ||
queryClient.invalidateQueries([STUDY_VOTE, date, location]); | ||
if (myPrevVotePoint) { | ||
await getPoint({ | ||
message: "스터디 투표 취소", | ||
value: -myPrevVotePoint, | ||
}); | ||
} | ||
await getPoint({ | ||
...POINT_SYSTEM_PLUS.STUDY_VOTE_DAILY, | ||
sub: date, | ||
}); | ||
toast( | ||
"success", | ||
`참여 완료! ${POINT_SYSTEM_PLUS.STUDY_VOTE_DAILY.value} 포인트가 적립되었습니다."}`, | ||
); | ||
setIsModal(false); | ||
}; | ||
|
||
const myPrevVotePoint = pointLog?.find( | ||
(item) => item.message === "스터디 투표" && item.meta.sub === dayjsToStr(dayjs(date)), | ||
)?.meta.value; | ||
|
||
const handleVote = async () => { | ||
if (!myVote?.place || !myVote?.start || !myVote?.end) { | ||
toast("error", "누락된 정보가 있습니다."); | ||
return; | ||
} | ||
const findPlace = studyVoteData?.find((par) => par.place._id === myVote.place); | ||
|
||
if (findPlace.status === "dismissed") { | ||
await openFree(myVote?.place); | ||
setTimeout(() => { | ||
patchAttend(myVote); | ||
}, 500); | ||
} else patchAttend(myVote); | ||
}; | ||
|
||
const imageDataArr: IImageTileData[] = studyVoteData | ||
?.filter((par) => par.status === "dismissed") | ||
.map((par) => ({ | ||
imageUrl: par.place.image, | ||
text: par.place.branch, | ||
id: par.place._id, | ||
func: () => setSelectedPlace(par.place._id), | ||
})) | ||
.sort((a) => (a.text === "개인 스터디" ? 1 : -1)); | ||
|
||
const dismissedPlaces = studyVoteData | ||
?.filter((par) => par.status === "dismissed") | ||
.map((par) => par.place.branch); | ||
|
||
const footerOptions: IFooterOptions = { | ||
main: { | ||
text: isFirstPage ? "선택 완료" : "참여 신청", | ||
func: isFirstPage ? () => setIsFirstPage(false) : handleVote, | ||
isLoading, | ||
}, | ||
}; | ||
|
||
return ( | ||
<ModalLayout title="당일 참여 신청" footerOptions={footerOptions} setIsModal={setIsModal}> | ||
<Box> | ||
{isFirstPage ? ( | ||
<> | ||
<ModalSubtitle> | ||
오픈된 스터디에 참여하거나 자유 스터디로 오픈할 수 있습니다. | ||
</ModalSubtitle> | ||
<ImageTileFlexLayout imageDataArr={imageDataArr} selectedId={[selectedPlace]} /> | ||
<Box mt="20px"> | ||
<Selector | ||
options={["선택 없음", ...dismissedPlaces]} | ||
defaultValue={selectedPlace} | ||
setValue={setSelectedPlace} | ||
/> | ||
</Box> | ||
</> | ||
) : ( | ||
<StudyVoteTimeRullets setVoteTime={setVoteTime} /> | ||
)} | ||
</Box> | ||
</ModalLayout> | ||
); | ||
} | ||
|
||
export default StudySimpleVoteModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.