diff --git a/apis/auth.tsx b/apis/auth.tsx index a8f5757..d88d664 100644 --- a/apis/auth.tsx +++ b/apis/auth.tsx @@ -20,7 +20,7 @@ export const SignIn = async (userData: { return response.data; } catch (error) { if (error.response) { - //200 이 외 + // 200 이외 console.error("서버 응답 오류:", error.response.data); } else if (error.request) { // 요청이 전송되었으나 응답을 받지 못한 경우 diff --git a/apis/calendar.ts b/apis/calendar.ts new file mode 100644 index 0000000..fb0325b --- /dev/null +++ b/apis/calendar.ts @@ -0,0 +1,27 @@ +import client, { ResponseBody } from "./client"; + +interface GetMonthCalendarResponse extends ResponseBody { + result: MonthCalendarProps[]; +} + +export interface MonthCalendarProps { + programIdx: number; + name: string; + openDate: { + year: number; + month: number; + day: number; + }; + dueDate: { + year: number; + month: number; + day: number; + }; +} + +// 챌린지 월별 조회 +export const getMonthCalendar = async (): Promise => { + const response = await client.get("/programs", {}); + // console.log("calenderData", response.data.result); + return response.data.result; +}; diff --git a/apis/hooks/calendar.ts b/apis/hooks/calendar.ts new file mode 100644 index 0000000..d994897 --- /dev/null +++ b/apis/hooks/calendar.ts @@ -0,0 +1,14 @@ +import { useQuery } from "@tanstack/react-query"; +import { getMonthCalendar } from "../calendar"; + +const useGetMonthCalendar = () => { + const { data } = useQuery({ + queryKey: ["getMonthCalendar"], + queryFn: getMonthCalendar, + }); + // console.log("isLoading", isLoading); + console.log("Query Data", data); + return { data }; +}; + +export { useGetMonthCalendar }; diff --git a/components/NavBar.tsx b/components/NavBar.tsx index 5131c48..d7f5887 100644 --- a/components/NavBar.tsx +++ b/components/NavBar.tsx @@ -19,41 +19,38 @@ const NavBar = () => { }, []); return ( - <> -
-
- - handleNavigate("/")} - iconType="home" - > - - - handleNavigate("/calendar")} - iconType="calendar" - > - - - handleNavigate("/mypage")} - iconType="mypage" - > - - - +
+
+ handleNavigate("/")} + iconType="home" + > + + + handleNavigate("/calendar")} + iconType="calendar" + > + + + handleNavigate("/mypage")} + iconType="mypage" + > + +
); diff --git a/components/calendar/InfoCalendar.tsx b/components/calendar/InfoCalendar.tsx index 259b838..82a928f 100644 --- a/components/calendar/InfoCalendar.tsx +++ b/components/calendar/InfoCalendar.tsx @@ -2,6 +2,9 @@ import Calendar from "react-calendar"; import { useState } from "react"; import styled from "styled-components"; import moment from "moment"; +import { useGetMonthCalendar } from "@/apis/hooks/calendar"; +import { MonthCalendarProps } from "@/apis/calendar"; +import Dot from "@/public/svgs/Dot.svg"; export default function InfoCalendar() { type DatePiece = Date | null; @@ -9,10 +12,57 @@ export default function InfoCalendar() { const [clickedDate, setClickedDate] = useState(new Date()); + // const [monthCalendarData, setMonthCalendarData] = useState< + // MonthCalendarProps[] + // >([]); + const onChangeToday = () => { setClickedDate(clickedDate); }; + const { data } = useGetMonthCalendar(); + + const customTileContent = ({ date, view }: { date: Date; view: string }) => { + let isOpen = true; + if (data && view === "month") { + const dayData = data.find((dayData: MonthCalendarProps) => { + const openDate = new Date( + dayData.openDate.year, + dayData.openDate.month - 1, + dayData.openDate.day, + ); + + const dueDate = new Date( + dayData.dueDate.year, + dayData.dueDate.month - 1, + dayData.dueDate.day, + ); + + if (date.getTime() === openDate.getTime()) isOpen = true; + else isOpen = false; + + return ( + date.getTime() === openDate.getTime() || + date.getTime() === dueDate.getTime() + ); + }); + + if (dayData) { + return ( +
+
+ +
+ {dayData.name} +
+
+
+ ); + } + } + return null; + }; + return (
@@ -24,6 +74,7 @@ export default function InfoCalendar() { prev2Label={null} minDate={new Date(2024, 4, 1)} formatDay={(locale, date) => moment(date).format("DD")} + tileContent={customTileContent} />
@@ -42,6 +93,20 @@ const StyledCalendarWrapper = styled.div` padding: 0; } + .custom-tile-content { + /* position: absolute; */ + display: flex; + justify-content: center; + align-items: center; + z-index: 1; + } + + .custom-tile-text { + text-align: start; + line-height: 130%; + flex-wrap: wrap; + } + /* 년도, 월 */ .react-calendar__navigation { display: flex; diff --git a/pages/calendar.tsx b/pages/calendar.tsx index eab1a6d..303a9bb 100644 --- a/pages/calendar.tsx +++ b/pages/calendar.tsx @@ -7,6 +7,8 @@ import InfoCalendar from "@/components/calendar/InfoCalendar"; import { NextPage } from "next"; const CalendarPage: NextPage = () => { + const date = new Date(); + console.log(date); return (
diff --git a/pages/login.tsx b/pages/login.tsx index 9deb870..779cd6d 100644 --- a/pages/login.tsx +++ b/pages/login.tsx @@ -44,12 +44,12 @@ const Login: NextPage = () => { ); const signInMutation = useMutation({ + queryKey: ["SignIn"], mutationFn: SignIn, onSuccess: async (data) => { console.log(data); const accessToken = data.result.accessToken; const refreshToken = data.result.refreshToken; - console.log("accessToken:", accessToken); setTokenFromLocalStorage(accessToken); router.push("/"); alert("로그인에 성공하였습니다"); diff --git a/public/svgs/Dot.svg b/public/svgs/Dot.svg new file mode 100644 index 0000000..3780dcd --- /dev/null +++ b/public/svgs/Dot.svg @@ -0,0 +1,5 @@ + + + + +