-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from kakao-tech-campus-2nd-step3/Week11
Week11 3
- Loading branch information
Showing
25 changed files
with
379 additions
and
96 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,32 @@ | ||
import { queryOptions } from '@tanstack/react-query' | ||
|
||
import { authorizationInstance } from '@/api/instance' | ||
import { appendParamsToUrl } from '@/api/utils/common/appendParamsToUrl' | ||
import { AdminQuestion, PagingRequestParams } from '@/types' | ||
|
||
type GetAdminQuestionsResponse = { | ||
content: AdminQuestion[] | ||
totalPages?: number | ||
totalElements?: number | ||
} | ||
|
||
const getAdminQuestions = async (params: PagingRequestParams) => { | ||
const response = await authorizationInstance.get<GetAdminQuestionsResponse>( | ||
appendParamsToUrl('api/admin/question', params) | ||
) | ||
|
||
return { | ||
questions: response.data.content, | ||
totalPages: response.data.totalPages, | ||
totalElements: response.data.totalElements, | ||
} | ||
} | ||
|
||
export const getAdminQuestionsQuries = { | ||
all: () => ['getAdminQuestions'], | ||
adminQuestions: (page?: number, size?: number) => | ||
queryOptions({ | ||
queryKey: [...getAdminQuestionsQuries.all(), page, size], | ||
queryFn: () => getAdminQuestions({ page: String(page), size: 8 }), | ||
}), | ||
} |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Box, Flex, Text } from '@chakra-ui/react' | ||
import { useQuery } from '@tanstack/react-query' | ||
|
||
import { getAdminQuestionsQuries } from '@/api/services/admin/admin' | ||
import { Loading } from '@/components/Loading' | ||
import ErrorPage from '@/pages/ErrorPage' | ||
|
||
export default function GetQuestionAdminPage() { | ||
const { | ||
data: questions, | ||
status, | ||
isLoading, | ||
isError, | ||
} = useQuery(getAdminQuestionsQuries.adminQuestions(0, 10)) | ||
|
||
if (status === 'pending' || isLoading) return <Loading /> | ||
if (isError) return <ErrorPage /> | ||
if (!questions) return '질문 아무것도 없음' | ||
|
||
const questionsList = questions.questions | ||
const totalElements = questions?.totalElements | ||
const totalPages = questions?.totalPages | ||
|
||
return ( | ||
<Flex width="100%" justifyContent="center" margin="40px auto"> | ||
<Box textAlign="center" width="100%" padding="0 50px"> | ||
<Text fontWeight={600} fontSize="x-large" marginBottom={10}> | ||
질문 리스트 | ||
</Text> | ||
<Flex flexDirection="column" gap={2}> | ||
<Flex | ||
borderBottom="1px solid" | ||
borderColor="brown.700" | ||
paddingBottom={2} | ||
> | ||
<Box width="80px">questionId</Box> | ||
<Box width="80px">groupId</Box> | ||
<Box width={400}>questionContent</Box> | ||
<Box width={200}>createdAt</Box> | ||
<Box width={100} color="orange.700"> | ||
status | ||
</Box> | ||
</Flex> | ||
{questionsList.map((question, idx) => ( | ||
<Flex | ||
key={question.questionId} | ||
borderBottom={idx === 7 ? '' : '1px solid'} | ||
borderColor="brown.500" | ||
paddingBottom={2} | ||
> | ||
<Box width="80px">{question.questionId}</Box> | ||
<Box width="80px">{question.groupId}</Box> | ||
<Box width={400}>{question.questionContent}</Box> | ||
<Box width={200}>{question.createdAt}</Box> | ||
<Box width={100} color="orange.700"> | ||
{question.status} | ||
</Box> | ||
</Flex> | ||
))} | ||
</Flex> | ||
</Box> | ||
</Flex> | ||
) | ||
} |
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,59 @@ | ||
import { useNavigate } from 'react-router-dom' | ||
|
||
import { Box, Button, Flex, Image, Text } from '@chakra-ui/react' | ||
import { useQuery } from '@tanstack/react-query' | ||
|
||
import { getAdminQuestionsQuries } from '@/api/services/admin/admin' | ||
import cookies from '@/assets/cookies.svg' | ||
import { Loading } from '@/components/Loading' | ||
|
||
import ErrorPage from '../ErrorPage' | ||
|
||
export default function Admin() { | ||
const { data, status, isLoading, isError } = useQuery( | ||
getAdminQuestionsQuries.adminQuestions(0, 10) | ||
) | ||
|
||
const navigate = useNavigate() | ||
|
||
if (status === 'pending' || isLoading) return <Loading /> | ||
if (isError) return <ErrorPage /> | ||
|
||
console.log(data) | ||
|
||
return ( | ||
<Flex | ||
width="full" | ||
margin="auto 30%" | ||
flexDirection="column" | ||
justifyContent="center" | ||
alignContent="center" | ||
> | ||
<Image margin="20px 60px" src={cookies} /> | ||
<Box textAlign="center"> | ||
<Text fontWeight={700} fontSize="xx-large" marginBottom={18}> | ||
Whokie 관리자 페이지 | ||
</Text> | ||
</Box> | ||
<Flex margin="0 20px" flexDirection="column" gap={3}> | ||
<Button | ||
bg="primary" | ||
color="white" | ||
_hover={{ bg: 'orange.500' }} | ||
onClick={() => navigate('/admin/get/questions')} | ||
> | ||
질문 보기 | ||
</Button> | ||
<Button bg="brown.500" color="white" _hover={{ bg: 'brown.600' }}> | ||
질문 만들기 | ||
</Button> | ||
<Button bg="primary" color="white" _hover={{ bg: 'orange.500' }}> | ||
관리자 리스트 | ||
</Button> | ||
<Button bg="brown.500" color="white" _hover={{ bg: 'brown.600' }}> | ||
그룹 리스트 | ||
</Button> | ||
</Flex> | ||
</Flex> | ||
) | ||
} |
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
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
Oops, something went wrong.