Skip to content

Commit

Permalink
Merge pull request #191 from prgrms-web-devcourse-final-project/feat/#…
Browse files Browse the repository at this point in the history
…185

메이트 디테일 페이지
  • Loading branch information
w-ho-choo authored Dec 9, 2024
2 parents c6d950a + 48442de commit a679481
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/apis/loginService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ interface LoginResponse {
code: number
}

// const { setAge, setGender, setMemberId, setNickname, setTeamId } =
// useUserStore.getState()

// 로그인 요청 함수
export const loginPost = async (email: string): Promise<LoginResponseData> => {
try {
Expand Down
1 change: 0 additions & 1 deletion src/apis/matePostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const matePostService = {
const response = await fetchApi
.get<MatePostResponse>(`mates/${matePostId}`)
.json()

return response.data
},

Expand Down
63 changes: 53 additions & 10 deletions src/pages/MateDetailPage/MateDetailAction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,57 @@ const MateDetailAction = ({
const navigate = useNavigate()
const { setMateFormData, setSelectedWeek, setImg } = useMateFormStore()

const [isChattingStarted, setIsChattingStarted] = useState(false)

// 상태 값
const isConditionMatched = true // 조건 일치 여부
const isRecruitmentComplete = false // 모집 완료 여부
const isHost = false // 방장 여부
const totalParticipants = 20 // 참여자 수
const isStatusCompleted = false // 직관 완료 여부
const isStatusCompleted = matePostData.status === '직관완료' ? true : false
const isHost =
matePostData.authorId.toString() === localStorage.getItem('memberId')
? true
: false

const isRecruitmentCompleted =
matePostData.status === '모집완료' ? true : false

const isConditionMatched = (() => {
const userGender = localStorage.getItem('gender')
const userAge = localStorage.getItem('age')

// 나이를 숫자로 변환
const ageAsNumber = Number(userAge)
if (isNaN(ageAsNumber) || ageAsNumber < 10) {
return false // 나이가 10살 미만이거나 숫자가 아니면 false
}


// 나이를 범위로 변환
let userAgeGroup: string
if (ageAsNumber < 10) {
return false // 10대 미만은 false
} else if (ageAsNumber < 20) {
userAgeGroup = '10대'
} else if (ageAsNumber < 30) {
userAgeGroup = '20대'
} else if (ageAsNumber < 40) {
userAgeGroup = '30대'
} else if (ageAsNumber < 50) {
userAgeGroup = '40대'
} else {
userAgeGroup = '50대이상'
}

// 성별 조건 확인
const isGenderMatched =
matePostData.gender === '상관없음' || matePostData.gender === userGender

// 나이 조건 확인
const isAgeMatched =
matePostData.age === '상관없음' ||
matePostData.age === userAgeGroup ||
(userAgeGroup === '50대이상' && matePostData.age === '50대이상')

return isGenderMatched && isAgeMatched
})()

const totalParticipants = matePostData.currentChatMembers // 참여자 수

const { createChatRoom, createIsPending, createIsError, createError } =
useCreateMateChatRoom(matePostData.postId.toString())
Expand Down Expand Up @@ -62,7 +105,7 @@ const MateDetailAction = ({
// 조건별 UI 렌더링
const renderNotice = () => {
if (isStatusCompleted) return '직관이 완료되었습니다.'
if (isRecruitmentComplete) {
if (isRecruitmentCompleted) {
return isConditionMatched || isHost
? '모집이 완료되었습니다.'
: '⚠️ 이런! 모임에서 원하는 조건이 아니에요!'
Expand All @@ -74,7 +117,7 @@ const MateDetailAction = ({
}

const renderActions = () => {
if (isStatusCompleted || isRecruitmentComplete) {
if (isStatusCompleted || isRecruitmentCompleted) {
return null
}

Expand All @@ -90,7 +133,7 @@ const MateDetailAction = ({
)
}

if (!isChattingStarted && isConditionMatched) {
if (isConditionMatched) {
return (
<>
<ChattingPeople>대화중인 메이트 - {totalParticipants}</ChattingPeople>
Expand Down
3 changes: 3 additions & 0 deletions src/typings/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export interface MatePostData {
manner: number
content: string
postId: number
authorId: number
currentChatMembers: number

}

export interface MatePostResponse {
Expand Down

0 comments on commit a679481

Please sign in to comment.