-
Notifications
You must be signed in to change notification settings - Fork 2
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
5 changed files
with
85 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { MyRankResponse } from './my-rank.response'; | ||
import { axiosClient } from '@/apis/AxiosClient'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
const getMyRankPath = () => '/api/user/my-ranking'; | ||
|
||
const UserQueryKey = [getMyRankPath()]; | ||
|
||
const getMyRank = async (): Promise<MyRankResponse> => { | ||
const response = await axiosClient.get(getMyRankPath()); | ||
return response.data; | ||
}; | ||
|
||
export const useGetMyRank = () => { | ||
return useQuery<MyRankResponse, Error>({ | ||
queryKey: UserQueryKey, | ||
queryFn: getMyRank, | ||
}); | ||
}; |
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,17 @@ | ||
import ApiResponse from '../ApiResponse'; | ||
|
||
export type MyRankData = { | ||
id: number; | ||
nickname: string; | ||
profileImageUrl: string; | ||
email: string; | ||
tierInfo: { | ||
tier: string; | ||
totalExp: number; | ||
currentExp: number; | ||
}; | ||
role: 'USER' | 'ADMIN'; | ||
rank: number; | ||
}; | ||
|
||
export type MyRankResponse = ApiResponse<MyRankData>; |
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 |
---|---|---|
@@ -1,49 +1,64 @@ | ||
import { TextContainer } from '../../styles'; | ||
import * as S from './styles'; | ||
import { useGetMyRank } from '@/apis/my-rank/my-rank.api'; | ||
import Profile from '@/assets/main/ZZAN-Profile.png'; | ||
import { getTierDetails } from '@/constants/data/tierSchema'; | ||
import { useInfoStore } from '@/store/useInfoStore'; | ||
import * as Base from '@/styles/baseStyles'; | ||
import { Box, Image, Text } from '@chakra-ui/react'; | ||
import styled from '@emotion/styled'; | ||
|
||
const MyRank = () => { | ||
const { userInfo } = useInfoStore(); | ||
const { data } = useGetMyRank(); | ||
|
||
const tierDetails = userInfo?.tierInfo | ||
? getTierDetails(userInfo?.tierInfo.tier) | ||
const tierDetails = data?.data.tierInfo | ||
? getTierDetails(data?.data.tierInfo.tier) | ||
: { color: 'var(--color-class-02)' }; | ||
return ( | ||
<> | ||
<S.MyRankLayout> | ||
<Base.Text | ||
fontSize='var(--font-size-xl)' | ||
fontWeight='700' | ||
color='#457A82' | ||
> | ||
<MyRankLayout> | ||
<Text fontSize='var(--font-size-xl)' fontWeight='700' color='#457A82'> | ||
내 순위 | ||
</Base.Text> | ||
<S.RankInfoContainer> | ||
<S.RankPosition> | ||
<Base.Text fontWeight='700'>1위</Base.Text> | ||
</S.RankPosition> | ||
<S.RankProfile> | ||
<S.RankProfileImg width='4.5rem' src={Profile} /> | ||
</S.RankProfile> | ||
</Text> | ||
<RankInfoContainer> | ||
<RankPosition> | ||
<Text fontWeight='700'>{data?.data.rank}위</Text> | ||
</RankPosition> | ||
<Box display='flex'> | ||
<Image width='4.5rem' src={Profile} /> | ||
</Box> | ||
<TextContainer> | ||
<Base.Text fontSize='var(--font-size-xl)' fontWeight='650'> | ||
{userInfo?.nickname} | ||
</Base.Text> | ||
<Base.Text | ||
color={tierDetails?.color} | ||
fontWeight='700' | ||
fontSize='1.2rem' | ||
> | ||
{userInfo?.tierInfo.tier} | ||
</Base.Text> | ||
<Text fontSize='var(--font-size-xl)' fontWeight='650'> | ||
{data?.data.nickname} | ||
</Text> | ||
<Text color={tierDetails?.color} fontWeight='700' fontSize='1.2rem'> | ||
{data?.data.tierInfo.tier} | ||
</Text> | ||
</TextContainer> | ||
</S.RankInfoContainer> | ||
</S.MyRankLayout> | ||
</RankInfoContainer> | ||
</MyRankLayout> | ||
</> | ||
); | ||
}; | ||
|
||
export default MyRank; | ||
|
||
export const MyRankLayout = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
background-color: var(--color-green-06); | ||
border-bottom: 1px solid #bdc5cd; | ||
`; | ||
|
||
export const RankInfoContainer = styled.div` | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
gap: 0.6rem; | ||
padding: 1rem 0.5rem; | ||
`; | ||
|
||
export const RankPosition = styled.div` | ||
width: 3rem; | ||
text-align: center; | ||
white-space: nowrap; | ||
`; |
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