Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REV-354/리뷰 상세 조회 api 분리 #76

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/apis/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export { default as useGetReceivedReviews } from './useGetReceivedReviews'
export { default as useGetCreatedReviews } from './useGetCreatedReviews'
export { default as useGetAllUser } from './useGetAllUser'
export { default as useGetAllReviews } from './useGetAllReviews'
export { default as useGetReviewFirst } from './useGetReviewFirst'
export { default as useGetReviewForCreator } from './useGetReviewForCreator'
export { default as useGetReviewForParticipation } from './useGetReviewForParticipation'
export { default as useGetReviewQuestion } from './useGetReviewQuestion'
export { default as useUser } from './useUser'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ interface Response {
data: Data
}

const useGetReviewFirst = ({ id }: { id: number }) => {
const useGetReviewForCreator = ({ id }: { id: number }) => {
const getReviewFirst = async () => {
const response = await apiClient.get<Response>(`/reviews/${id}`)

return response.data.data
}

return useSuspenseQuery({
queryKey: [`/reviews/${id}`],
queryKey: [`/reviews/${id}/creator`],
queryFn: getReviewFirst,
})
}

export default useGetReviewFirst
export default useGetReviewForCreator
58 changes: 58 additions & 0 deletions src/apis/hooks/useGetReviewForParticipation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { useSuspenseQuery } from '@tanstack/react-query'
import apiClient from '../apiClient'

export type QuestionType =
| 'SINGLE_CHOICE'
| 'MULTIPLE_CHOICE'
| 'RATING'
| 'SUBJECTIVE'
| 'DROPDOWN'
| 'HEXASTAT'

export interface QuestionOption {
optionId: number
optionName: string
}

export interface Question {
id: number
title: string
description: string
type: QuestionType
isRequired: boolean
questionOptions: QuestionOption[]
}

export interface Receiver {
receiverId: number
name: string
}

export interface Data {
id: number
title: string
receivers: Receiver[]
description: string
status: string
questions: Question[]
}

interface Response {
success: boolean
data: Data
}

const useGetReviewForParticipation = ({ id }: { id: number }) => {
const getReviewFirst = async () => {
const response = await apiClient.get<Response>(`/reviews/${id}`)

return response.data.data
}

return useSuspenseQuery({
queryKey: [`/reviews/${id}/participation`],
queryFn: getReviewFirst,
})
}

export default useGetReviewForParticipation
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MouseEvent } from 'react'
import { useFormContext } from 'react-hook-form'
import { useLocation } from 'react-router-dom'
import { Question } from '@/apis/hooks/useGetReviewFirst'
import { Question } from '@/apis/hooks/useGetReviewForCreator'
import { ReviewReplyStartType, ReviewReplyEditType } from '../../types'

interface QuestionItemProps {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReviewReplyPage/components/Questions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormContext } from 'react-hook-form'
import { Question } from '@/apis/hooks/useGetReviewFirst'
import { Question } from '@/apis/hooks/useGetReviewForCreator'
import { ReviewReplyStartType, ReviewReplyEditType } from '../../types'
import {
ReplyText,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MouseEvent } from 'react'
import { useLocation } from 'react-router-dom'
import { Profile } from '@/components'
import { Receiver } from '@/apis/hooks/useGetReviewFirst'
import { Receiver } from '@/apis/hooks/useGetReviewForCreator'
import { CheckInTheCircleIcon } from '@/assets/icons'

interface ReceiverItemProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, MouseEvent, ChangeEvent, useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { useLocation } from 'react-router-dom'
import { QuestionOption } from '@/apis/hooks/useGetReviewFirst'
import { QuestionOption } from '@/apis/hooks/useGetReviewForCreator'
import { CheckIcon } from '@/assets/icons'
import {
ReviewReplyStartType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, MouseEvent, useEffect, useMemo } from 'react'
import { useFieldArray, useFormContext } from 'react-hook-form'
import { useLocation } from 'react-router-dom'
import { QuestionOption } from '@/apis/hooks/useGetReviewFirst'
import { QuestionOption } from '@/apis/hooks/useGetReviewForCreator'
import { CheckIcon } from '@/assets/icons'
import {
ReviewReplyStartType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, MouseEvent, ChangeEvent, useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { useLocation } from 'react-router-dom'
import { QuestionOption } from '@/apis/hooks/useGetReviewFirst'
import { QuestionOption } from '@/apis/hooks/useGetReviewForCreator'
import {
ReviewReplyStartType,
ReviewReplyEditType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect } from 'react'
import { useFormContext } from 'react-hook-form'
import { useLocation } from 'react-router-dom'
import { QuestionOption } from '@/apis/hooks/useGetReviewFirst'
import { QuestionOption } from '@/apis/hooks/useGetReviewForCreator'
import {
ReviewReplyStartType,
ReviewReplyEditType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormContext } from 'react-hook-form'
import { Data } from '@/apis/hooks/useGetReviewFirst'
import { Data } from '@/apis/hooks/useGetReviewForCreator'
import { ReceiverItem, QuestionItem } from '..'
import {
useHandleReceiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { FormProvider, useForm, useFieldArray } from 'react-hook-form'
import { useNavigate, useLocation } from 'react-router-dom'
import {
useEditResponse,
useGetReviewFirst,
useGetReviewForCreator,
useUser,
useGetResponseByResponserForReviewReplyPage,
} from '@/apis/hooks'
import { Question } from '@/apis/hooks/useGetReviewFirst'
import { Question } from '@/apis/hooks/useGetReviewForCreator'
import { ReviewReplyEditType } from '../../types'
import ReviewReply from './ReviewReply'

Expand All @@ -22,7 +22,7 @@ const ReviewReplyEdit = () => {
reviewId,
responserId: user?.id as number,
})
const { data: reviewData } = useGetReviewFirst({ id: reviewId })
const { data: reviewData } = useGetReviewForCreator({ id: reviewId })
const { mutate: editResponse } = useEditResponse()
const { title, questions } = reviewData

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormContext } from 'react-hook-form'
import { Data } from '@/apis/hooks/useGetReviewFirst'
import { Data } from '@/apis/hooks/useGetReviewForCreator'
import { ReceiverItem, QuestionItem } from '../'
import {
useHandleReceiver,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/ReviewReplyPage/components/ReviewReplyEnd/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { useState } from 'react'
import { FormProvider, useForm, useFieldArray } from 'react-hook-form'
import { useLocation } from 'react-router-dom'
import {
useGetReviewFirst,
useGetReviewForCreator,
useUser,
useGetResponseByResponserForReviewReplyPage,
} from '@/apis/hooks'
import { Question } from '@/apis/hooks/useGetReviewFirst'
import { Question } from '@/apis/hooks/useGetReviewForCreator'
import { ReviewReplyEndType } from '../../types'
import ReviewReply from './ReviewReply'

Expand All @@ -20,7 +20,7 @@ const ReviewReplyEnd = () => {
reviewId,
responserId: user?.id as number,
})
const { data: reviewData } = useGetReviewFirst({ id: reviewId })
const { data: reviewData } = useGetReviewForCreator({ id: reviewId })
const { title, questions } = reviewData

const methods = useForm<ReviewReplyEndType>({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useFormContext } from 'react-hook-form'
import { Data } from '@/apis/hooks/useGetReviewFirst'
import { Data } from '@/apis/hooks/useGetReviewForCreator'
import { QuestionItem, ReceiverItem } from '..'
import {
useHandleReceiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChangeEvent, useState, Dispatch, SetStateAction } from 'react'
import { SubmitHandler, useFieldArray, useFormContext } from 'react-hook-form'
import { Profile, SearchBar } from '@/components'
import { useUser } from '@/apis/hooks'
import { Question } from '@/apis/hooks/useGetReviewFirst'
import { Question } from '@/apis/hooks/useGetReviewForCreator'
import { CloseIcon } from '@/assets/icons'
import { ReviewReplyStartType } from '../../types'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { useNavigate, useLocation } from 'react-router-dom'
import { useCreateResponse, useGetReviewFirst } from '@/apis/hooks'
import { useCreateResponse, useGetReviewForCreator } from '@/apis/hooks'
import { ReviewReplyStartType } from '../../types'
import ReviewReply from './ReviewReply'
import ReceiverSelect from './ReviewSelect'
Expand All @@ -12,7 +12,7 @@ const ReviewReplyStart = () => {
const reviewId = parseInt(pathname.split('/').at(-1) as string)
const [reviewStep, setReviewStep] = useState(1)

const { data: reviewData } = useGetReviewFirst({ id: reviewId })
const { data: reviewData } = useGetReviewForCreator({ id: reviewId })
const { mutate: createResponse } = useCreateResponse()
const { title, description, receivers } = reviewData

Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReviewReplyPage/hooks/useClickNextButton.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dispatch, SetStateAction } from 'react'
import { Question, Receiver } from '@/apis/hooks/useGetReviewFirst'
import { Question, Receiver } from '@/apis/hooks/useGetReviewForCreator'

interface UseClickNextButtonProps {
questions: Question[]
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReviewReplyPage/hooks/useHandleQuestion.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState, MouseEvent } from 'react'
import { useFormContext } from 'react-hook-form'
import { useLocation } from 'react-router-dom'
import { Question } from '@/apis/hooks/useGetReviewFirst'
import { Question } from '@/apis/hooks/useGetReviewForCreator'
import { ReviewReplyStartType } from '../types'

interface UseHandleQuestionProps {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReviewReplyPage/hooks/useHandleReceiver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, MouseEvent } from 'react'
import { Receiver } from '@/apis/hooks/useGetReviewFirst'
import { Receiver } from '@/apis/hooks/useGetReviewForCreator'

interface UseHandleReceiverProps {
receivers: Receiver[]
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ReviewReplyPage/hooks/useReplyComplete.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect, useCallback } from 'react'
import { useFormContext } from 'react-hook-form'
import { Receiver } from '@/apis/hooks/useGetReviewFirst'
import { Receiver } from '@/apis/hooks/useGetReviewForCreator'
import { ReviewReplyEditType } from '../types'

interface UseReplyCompleteProps {
Expand Down
Loading