|
1 | 1 | import { useMutation, useQuery } from "@tanstack/react-query"; |
2 | 2 | import { createFileRoute, useNavigate } from "@tanstack/react-router"; |
| 3 | +import { camelCase, upperFirst } from "es-toolkit/compat"; |
3 | 4 | import { AnimatePresence, motion } from "motion/react"; |
4 | 5 | import { AspectRatio, RadioGroup } from "radix-ui"; |
5 | 6 | import { useEffect, useState } from "react"; |
6 | | -import { match } from "ts-pattern"; |
| 7 | +import { match, P } from "ts-pattern"; |
7 | 8 | import Button from "@/components/Button"; |
8 | 9 | import { Tag, type TagVariant } from "@/components/tag/Tag"; |
9 | | - |
10 | 10 | import { getBrandLevels1 } from "@/generated/brand/brand"; |
11 | 11 | import type { GymLevelResponse } from "@/generated/model"; |
12 | 12 | import { setLevel } from "@/generated/onboarding/onboarding"; |
13 | 13 | import { getHeaderToken } from "@/utils/cookie"; |
14 | 14 | import { LevelRadioButton } from "./-components/LevelRadioButton"; |
15 | 15 |
|
| 16 | +const convertPascalCase = (value: string) => { |
| 17 | + return upperFirst(camelCase(value)); |
| 18 | +}; |
| 19 | + |
16 | 20 | export const Route = createFileRoute("/onboarding/level/")({ |
17 | 21 | component: OnboardingLevelComponent, |
18 | 22 | }); |
@@ -69,11 +73,9 @@ function OnboardingLevelComponent() { |
69 | 73 |
|
70 | 74 | const selectedLabel = match(selectedLevel) |
71 | 75 | .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 | + ) |
77 | 79 | .otherwise(() => ""); |
78 | 80 |
|
79 | 81 | useEffect( |
@@ -143,13 +145,7 @@ function OnboardingLevelComponent() { |
143 | 145 | value={level.id?.toString() ?? ""} |
144 | 146 | checked={level.id === selectedLevel?.id} |
145 | 147 | > |
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)} |
153 | 149 | </LevelRadioButton> |
154 | 150 | ))} |
155 | 151 | </RadioGroup.Root> |
|
0 commit comments