Skip to content

Commit

Permalink
fix: type
Browse files Browse the repository at this point in the history
  • Loading branch information
rabyeoljji committed Dec 8, 2024
1 parent 4733af5 commit d43a562
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 113 deletions.
4 changes: 3 additions & 1 deletion src/app/(routes)/profile/account/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { fetchUserInfo } from '@/requests/user/server'
const AccountPage = async () => {
const user = await fetchUserInfo()

const interestCategories = user.interestField?.length ? user.interestField : ['관심 분야 없음']
const interestCategories = user.interestCategories?.length
? user.interestCategories
: ['관심 분야 없음']

return (
<main className="h-[calc(100dvh-54px-88px)] w-full overflow-y-auto px-[16px]">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const CategorySelectArea = () => {

const onSubmit = (values: FormValues) => {
mutate(
{ interestCollectionCategories: values.categories as User.InterestedCategory[] },
{ interestCollectionCategories: values.categories as NonNullable<User.InterestedCategory>[] },
{
onSuccess: () => {
router.replace('/main')
Expand Down
8 changes: 4 additions & 4 deletions src/features/quiz/components/ox-choice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import { SVGProps } from 'react'

interface OXChoiceProps {
condition: Exclude<QuizCondition, 'DISABLED'>
userAnswer?: OXQuizAnswer
onSelect: (userAnswer: OXQuizAnswer) => void
condition: Exclude<Quiz.Condition, 'DISABLED'>
userAnswer?: Quiz.OXAnswer
onSelect: (userAnswer: Quiz.OXAnswer) => void
}

const OXChoice = ({ condition, userAnswer, onSelect }: OXChoiceProps) => {
const disabled = condition === 'RIGHT' || condition === 'WRONG'

const getIconColors = (type: OXQuizAnswer) => {
const getIconColors = (type: Quiz.OXAnswer) => {
const defaultColors = {
bg: type === 'correct' ? '#4D7BF9' : '#FB8320', // 기본 배경색
fill: 'white', // 기본 채우기색
Expand Down
22 changes: 1 addition & 21 deletions src/features/quiz/config/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const quizzes: Quiz.ItemWithCategory[] = [
export const quizzes: Quiz.ItemWithMetadata[] = [
{
document: {
id: 1,
Expand All @@ -8,10 +8,6 @@ export const quizzes: Quiz.ItemWithCategory[] = [
id: 1,
name: '전공 공부',
},
category: {
id: 1,
name: 'IT',
},
id: 1,
quizType: 'MULTIPLE_CHOICE',
question: '식물기반 단백질 시장에서 대기업의 참여가 늘어나는 이유는 무엇인가요?',
Expand All @@ -33,10 +29,6 @@ export const quizzes: Quiz.ItemWithCategory[] = [
id: 1,
name: '전공 공부',
},
category: {
id: 1,
name: 'IT',
},
id: 2,
quizType: 'MIX_UP',
question: '식물기반 단백질 시장에서 대기업의 참여가 늘어나는 이유는 무엇인가요?',
Expand All @@ -53,10 +45,6 @@ export const quizzes: Quiz.ItemWithCategory[] = [
id: 1,
name: '전공 공부',
},
category: {
id: 1,
name: 'IT',
},
id: 3,
quizType: 'MULTIPLE_CHOICE',
question: '식물기반 단백질 시장에서 대기업의 참여가 늘어나는 이유는 무엇인가요?',
Expand All @@ -78,10 +66,6 @@ export const quizzes: Quiz.ItemWithCategory[] = [
id: 1,
name: '전공 공부',
},
category: {
id: 1,
name: 'IT',
},
id: 5,
quizType: 'MIX_UP',
question: '식물기반 단백질 시장에서 대기업의 참여가 늘어나는 이유는 무엇인가요?',
Expand All @@ -97,10 +81,6 @@ export const quizzes: Quiz.ItemWithCategory[] = [
id: 1,
name: '전공 공부',
},
category: {
id: 1,
name: 'IT',
},
id: 4,
quizType: 'MIX_UP',
question: '식물기반 단백질 시장에서 대기업의 참여가 늘어나는 이유는 무엇인가요?',
Expand Down
4 changes: 2 additions & 2 deletions src/features/quiz/screen/quiz-view/components/quiz-option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ const QuizOptions = ({ quiz, currentResult, onAnswer, className }: QuizOptionsPr
>
<OXChoice
condition={getOXCondition(currentResult)}
userAnswer={currentResult?.choseAnswer as OXQuizAnswer}
onSelect={(userAnswer: OXQuizAnswer) => {
userAnswer={currentResult?.choseAnswer as Quiz.OXQuizAnswer}
onSelect={(userAnswer: Quiz.OXQuizAnswer) => {
onAnswer({
id: quiz.id,
isRight: quiz.answer === userAnswer ? true : false,
Expand Down
8 changes: 3 additions & 5 deletions src/features/quiz/screen/quiz-view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ const QuizView = ({ quizzes, isFirst }: Props) => {

const [exitDialogOpen, setExitDialogOpen] = useState(false)

const currentQuiz = quizzes[currentIndex]
const currentResult = quizResults[currentIndex]
const currentQuiz = quizzes[currentIndex] ?? ({} as Quiz.ItemWithMetadata)
const currentResult = quizResults[currentIndex] ?? null

const onNext = () => {
const hasNextQuiz = handleNext(currentIndex, quizzes.length)
Expand Down Expand Up @@ -127,9 +127,7 @@ const QuizView = ({ quizzes, isFirst }: Props) => {
/>
)}

{isQuizSolved(quizResults[currentIndex]) && (
<ResultIcon isRight={quizResults[currentIndex]?.answer} />
)}
{isQuizSolved(currentResult) && <ResultIcon isRight={currentResult?.answer} />}

<ExitDialog index={currentIndex} open={exitDialogOpen} onOpenChange={setExitDialogOpen} />
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/features/quiz/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const isQuizSolved = (result: Quiz.Result | null): result is Quiz.Result
}

export const getAnswerText = (answer: string) => {
const OXType = ['correct', 'incorrect'] as OXQuizAnswer[]
const OXType = ['correct', 'incorrect'] as Quiz.OXAnswer[]
const isOXType = OXType.find((oxType) => oxType === answer)

if (isOXType) {
Expand All @@ -34,7 +34,7 @@ export const getAnswerText = (answer: string) => {
}

export const getQuizSetTypeEnum = (quizSetType: 'today' | 'document' | 'collection' | 'create') => {
let enumQuizType: QuizSetType
let enumQuizType: Quiz.SetType

switch (quizSetType) {
case 'today':
Expand Down
2 changes: 1 addition & 1 deletion src/features/user/components/category-drawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const CategoryDrawer = ({

const onSubmit = (values: FormValues) => {
mutate(
{ interestCollectionCategories: values.categories as User.InterestedCategory[] },
{ interestCollectionCategories: values.categories as NonNullable<User.InterestedCategory>[] },
{
onSuccess: () => {
setCompleteOpen(true)
Expand Down
67 changes: 21 additions & 46 deletions src/types/quiz.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { DeepRequired } from 'react-hook-form'
import { paths } from './schema'
import { components, paths } from './schema'

/** Quiz.SetType으로 이동 */
type QuizSetType = 'DOCUMENT_QUIZ_SET' | 'TODAY_QUIZ_SET' | 'COLLECTION_QUIZ_SET' | 'FIRST_QUIZ_SET'
type ReplayQuizType = 'RANDOM' | 'MIX_UP' | 'MULTIPLE_CHOICE'

type QuizItem = {
id: number
Expand All @@ -14,63 +13,39 @@ type QuizItem = {
answer?: 'correct' | 'incorrect'
}

type QuizType = 'MIX_UP' | 'MULTIPLE_CHOICE'
type ReplayQuizType = 'RANDOM' | 'MIX_UP' | 'MULTIPLE_CHOICE'

type QuizCondition = 'IDLE' | 'DISABLED' | 'RIGHT' | 'WRONG'

type Category = {
id: number
name: string
}

type DocumentInQuiz = Pick<Document.ItemInList, 'id' | 'name'>
type DirectoryInQuiz = Pick<Directory.Item, 'id' | 'name'>

type ConsecutiveDays = {
currentConsecutiveDays: number
maxConsecutiveDays: number
}
type DocumentInQuiz = DeepRequired<components['schemas']['DocumentDto']>
type DirectoryInQuiz = DeepRequired<components['schemas']['DirectoryDto']>

type QuizWithMetadata = {
document: DocumentInQuiz
directory: DirectoryInQuiz
} & QuizItem

type QuizWithCategory = {
category: Category
} & QuizWithMetadata

type QuizRecord = {
question: string
answer: string
explanation: string
options: string[]
choseAnswer: string
documentName: string
directoryName: string
}

type QuizSetRecord = {
quizSetId: string
quizSetType: QuizSetType
name: string
quizCount: number
score: number
solvedDate: string
// 처리 필요
type ConsecutiveDays = {
currentConsecutiveDays: number
maxConsecutiveDays: number
}

declare global {
declare namespace Quiz {
type Item = QuizItem
type List = QuizItem[]
type ItemWithMetadata = QuizWithMetadata
type ItemWithCategory = QuizWithCategory
type Type = QuizType
type Record = QuizRecord
type Result = UpdateQuizResultPayload['quizzes'][number]

type SetType = QuizSetType
type Type = Exclude<DeepRequired<components['schemas']['QuizDto']['quizType']>, undefined>
type OXAnswer = 'correct' | 'incorrect'

type SetRecord = DeepRequired<components['schemas']['GetSingleQuizSetRecordDto']>
type Record = DeepRequired<components['schemas']['GetQuizRecordDto']>
type Result = Quiz.Request.UpdateQuizResult['quizzes'][number]

type SetType = Exclude<
DeepRequired<components['schemas']['GetQuizRecordDto']['quizSetType']>,
undefined
>

type Condition = 'IDLE' | 'DISABLED' | 'RIGHT' | 'WRONG'

declare namespace Request {
/** PATCH /api/v2/quiz/result
Expand Down
35 changes: 5 additions & 30 deletions src/types/user.d.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
import { DeepRequired } from 'react-hook-form'
import { paths } from './schema'

type interestedCategory =
| 'IT'
| 'LAW'
| 'ART'
| 'BUSINESS_ECONOMY'
| 'HISTORY_PHILOSOPHY'
| 'LANGUAGE'
| 'SOCIETY_POLITICS'
| 'MEDICINE_PHARMACY'
| 'SCIENCE_ENGINEERING'
| 'OTHER'

interface UserInfo {
id: number
name: string
email: string
socialPlatform: 'KAKAO' | 'GOOGLE'
role: 'ROLE_USER' | 'ROLE_ADMIN'
interestField: interestedCategory[]
documentUsage: {
possessDocumentCount: number
maxPossessDocumentCount: number
}
star: number
quizNotificationEnabled: boolean
}
import { components, paths } from './schema'

declare global {
declare namespace User {
type Info = UserInfo
type InterestedCategory = interestedCategory
type Info = DeepRequired<components['schemas']['GetMemberInfoResponse']>
type InterestedCategory = DeepRequired<
components['schemas']['GetCollectionCategoriesDto']['collectionCategory']
>

declare namespace Request {
/** PATCH /api/v2/members/update-today-quiz-count
Expand Down

0 comments on commit d43a562

Please sign in to comment.