Skip to content

Commit bef3ed3

Browse files
committed
fix: API 요청에 헤더 토큰 추가 및 레벨 이름 변환 함수 개선
1 parent 4d68501 commit bef3ed3

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/routes/my/index.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Dialog } from "radix-ui";
55
import { useEffect, useMemo, useRef, useState } from "react";
66
import { DialogLevelDescriptionContent } from "@/components/dialog-level-description-content/DialogLevelDescriptionContent";
77
import { getAttempts } from "@/generated/attempts/attempts";
8+
import { getHeaderToken } from "@/utils/cookie";
89
import { MyInfo } from "./-components/MyInfo";
910
import { MyScore } from "./-components/MyScore";
1011
import { VideoCard } from "./-components/VideoCard";
@@ -36,12 +37,17 @@ function RouteComponent() {
3637
}): Promise<{ items: VideoItem[]; nextPage?: number }> => {
3738
const gymId = selectedTab ? Number(selectedTab) : undefined;
3839

39-
const response = await getAttempts({
40-
page: pageParam,
41-
size: PAGE_SIZE,
42-
gymId,
43-
success: true,
44-
});
40+
const response = await getAttempts(
41+
{
42+
page: pageParam,
43+
size: PAGE_SIZE,
44+
gymId,
45+
success: true,
46+
},
47+
{
48+
headers: getHeaderToken(),
49+
}
50+
);
4551

4652
const items: VideoItem[] = (response.data?.content ?? []).map(
4753
(attempt) => ({

src/routes/onboarding/level/-components/LevelRadioButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const LevelRadioButton = ({
1212
<RadioGroup.Item
1313
{...props}
1414
className={cn(
15-
"flex-center flex-1 max-w-14 max-h-14 min-w-10 min-h-10 rounded-[16px] overflow-hidden mt-auto shrink-0 bg-neutral-300 text-neutral-400",
15+
"flex-center w-14 h-14 rounded-[16px] overflow-hidden mt-auto shrink-0 bg-neutral-300 text-neutral-400 t-p-14-sb",
1616
"data-[state=checked]:bg-neutral-600 data-[state=checked]:text-neutral-100",
1717
"aspect-square"
1818
)}

src/routes/onboarding/level/index.tsx

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import { useMutation, useQuery } from "@tanstack/react-query";
22
import { createFileRoute, useNavigate } from "@tanstack/react-router";
3+
import { camelCase, upperFirst } from "es-toolkit/compat";
34
import { AnimatePresence, motion } from "motion/react";
45
import { AspectRatio, RadioGroup } from "radix-ui";
56
import { useEffect, useState } from "react";
6-
import { match } from "ts-pattern";
7+
import { match, P } from "ts-pattern";
78
import Button from "@/components/Button";
89
import { Tag, type TagVariant } from "@/components/tag/Tag";
9-
1010
import { getBrandLevels1 } from "@/generated/brand/brand";
1111
import type { GymLevelResponse } from "@/generated/model";
1212
import { setLevel } from "@/generated/onboarding/onboarding";
1313
import { getHeaderToken } from "@/utils/cookie";
1414
import { LevelRadioButton } from "./-components/LevelRadioButton";
1515

16+
const convertPascalCase = (value: string) => {
17+
return upperFirst(camelCase(value));
18+
};
19+
1620
export const Route = createFileRoute("/onboarding/level/")({
1721
component: OnboardingLevelComponent,
1822
});
@@ -69,11 +73,9 @@ function OnboardingLevelComponent() {
6973

7074
const selectedLabel = match(selectedLevel)
7175
.with(null, () => "")
72-
.with({ gymLevelName: "ORANGE" }, () => "주황")
73-
.with({ gymLevelName: "GREEN" }, () => "초록")
74-
.with({ gymLevelName: "BLUE" }, () => "파랑")
75-
.with({ gymLevelName: "RED" }, () => "빨강")
76-
.with({ gymLevelName: "PURPLE" }, () => "보라")
76+
.with({ gymLevelName: P.string }, (level) =>
77+
convertPascalCase(level.gymLevelName)
78+
)
7779
.otherwise(() => "");
7880

7981
useEffect(
@@ -143,13 +145,7 @@ function OnboardingLevelComponent() {
143145
value={level.id?.toString() ?? ""}
144146
checked={level.id === selectedLevel?.id}
145147
>
146-
{match(level.gymLevelName)
147-
.with("ORANGE", () => "주황")
148-
.with("GREEN", () => "초록")
149-
.with("BLUE", () => "파랑")
150-
.with("RED", () => "빨강")
151-
.with("PURPLE", () => "보라")
152-
.otherwise(() => level.gymLevelName)}
148+
{level.gymLevelName && convertPascalCase(level.gymLevelName)}
153149
</LevelRadioButton>
154150
))}
155151
</RadioGroup.Root>

0 commit comments

Comments
 (0)