diff --git a/src/components/home/RecruitingChallengeCard.tsx b/src/components/home/RecruitingChallengeCard.tsx index 04816ea..e0fb023 100644 --- a/src/components/home/RecruitingChallengeCard.tsx +++ b/src/components/home/RecruitingChallengeCard.tsx @@ -4,8 +4,6 @@ import Link from 'next/link'; import IRecruitingChallenge from '@/types/recruitingChallenge'; import VERIFICATION_TYPE from '@/constants/verificationType'; import screenSize from '@/constants/screenSize'; -import calculatePeriod from '@/utils/calculatePeriod'; -import calculateDDay from '@/utils/calculateDDay'; export default function RecruitingChallengeCard({ challengeGroupId, @@ -13,13 +11,11 @@ export default function RecruitingChallengeCard({ imageUrl, verificationType, participantCount, - startDate, - endDate, isFree, + dateDiff, }: IRecruitingChallenge) { - const caculateRecruitDDay = (date: string) => { - let dDay = -1; - dDay = calculateDDay(date) - 1; + const calculateRecruitDDay = (day: number) => { + const dDay = day - 1; let dDayStr; if (dDay < 0) { dDayStr = '모집 마감'; @@ -28,6 +24,16 @@ export default function RecruitingChallengeCard({ } return dDayStr; }; + const calculateProgressePeroid = (day: number) => { + const days = Math.abs(day) + 1; + let periodStr = ''; + if (days % 7 === 0) { + periodStr = `${days / 7}주`; + } else { + periodStr = `${days}일`; + } + return periodStr; + }; return ( @@ -41,14 +47,16 @@ export default function RecruitingChallengeCard({ priority /> {participantCount} - {caculateRecruitDDay(startDate)} + + {calculateRecruitDDay(dateDiff.startToToday)} + {groupTitle}
챌린지 인증 빈도
매일
챌린지 진행 기한
-
{calculatePeriod(startDate, endDate)}
+
{calculateProgressePeroid(dateDiff.startToEnd)}
챌린지 인증 방식
{VERIFICATION_TYPE[verificationType]}
{isFree && ( diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 5501e52..5f5076f 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -19,6 +19,7 @@ import getRecruitingChallengeApi from '@/lib/axios/home/api'; import createServerInstance from '@/lib/axios/serverInstance'; import serverErrorCatch from '@/lib/axios/serverErrorCatch'; import { IAuthResponse } from '@/lib/axios/instance'; +import calculateDDay from '@/utils/calculateDDay'; RecoilEnv.RECOIL_DUPLICATE_ATOM_KEY_CHECKING_ENABLED = false; @@ -232,9 +233,17 @@ async function getServerSidePropsFunction( return response.data; }; const recruitingChallenges = await fetchRecruitingChallenges(); + const enhancedChallenges = recruitingChallenges.map((challenge) => ({ + ...challenge, + dateDiff: { + startToToday: calculateDDay(challenge.startDate), + startToEnd: calculateDDay(challenge.startDate, challenge.endDate), + }, + })); + return { props: { - recruitingChallenges, + recruitingChallenges: enhancedChallenges, isLogined, }, }; diff --git a/src/types/recruitingChallenge.ts b/src/types/recruitingChallenge.ts index cb59822..9df9583 100644 --- a/src/types/recruitingChallenge.ts +++ b/src/types/recruitingChallenge.ts @@ -9,6 +9,10 @@ interface IRecruitingChallenge { participantCount: number; startDate: string; endDate: string; + dateDiff: { + startToToday: number; + startToEnd: number; + }; } export default IRecruitingChallenge;