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

πŸ› 폼 생성 제좜 이슈 #86

Merged
merged 2 commits into from
Jan 30, 2025

Conversation

Ethen1264
Copy link
Contributor

@Ethen1264 Ethen1264 commented Jan 30, 2025

πŸ’‘ λ°°κ²½ 및 κ°œμš”

μ„œλ²„μ—μ„œ 데이터λ₯Ό JSON이 μ•„λ‹ˆλΌ λ¬Έμžμ—΄λ‘œ 받도둝 μ„€κ³„ν•˜μ—¬ 기쑴에 λ³΄λ‚΄λ˜ ν˜•μ‹μ΄ μ•„λ‹Œ μƒˆλ‘œμš΄ 방법을 μ μš©ν•΄μ•Ό ν–ˆμ—ˆλ‹€.

πŸ“ƒ μž‘μ—…λ‚΄μš©

  • jsonData ν˜•μ‹ λ³€κ²½
  • νƒ€μž…μ΄ text이면 option듀이 λ‚˜νƒ€λ‚˜μ§€ μ•Šκ²Œ 적용
  • κ·Έμ™Έ μŠ€νƒ€μΌ 적용

πŸ”€ 변경사항

{"1": "μ΄ˆλ“±ν•™κ΅", "2": "쀑학ꡐ", "3": "고등학ꡐ", "4": "λŒ€ν•™κ΅"} => {"1":"μ΄ˆλ“±ν•™κ΅","2":"쀑학ꡐ","3":"고등학ꡐ","4":"λŒ€ν•™κ΅"}"

Summary by CodeRabbit

  • μƒˆλ‘œμš΄ κΈ°λŠ₯

    • 폼 생성 μ‹œ μ°Έκ°€μž μœ ν˜• 및 동적 폼 데이터 ꡬ쑰 κ°œμ„ 
    • ν† κΈ€ λ²„νŠΌμ˜ μ‹œκ°μ  ν”Όλ“œλ°± ν–₯상
  • 버그 μˆ˜μ •

    • 폼 생성 쀑 였λ₯˜ 처리 및 μœ νš¨μ„± 검사 κ°•ν™”
    • 폼 μ˜΅μ…˜ 및 제λͺ© μž…λ ₯에 λŒ€ν•œ ν•„μˆ˜ μž…λ ₯ 검증 μΆ”κ°€
  • λ¦¬νŒ©ν† λ§

    • νƒ€μž… μ •μ˜ 및 API μš”μ²­ ꡬ쑰 κ°„μ†Œν™”
    • λ„€λΉ„κ²Œμ΄μ…˜ νŒŒλΌλ―Έν„° λŒ€μ†Œλ¬Έμž 일관성 κ°œμ„ 
  • 제거된 κΈ°λŠ₯

    • TextOption μ»΄ν¬λ„ŒνŠΈ 제거

@Ethen1264 Ethen1264 added the 🐞 Bug 버그 λ°œμƒ label Jan 30, 2025
@Ethen1264 Ethen1264 self-assigned this Jan 30, 2025
Copy link

coderabbitai bot commented Jan 30, 2025

Walkthrough

이 ν’€ λ¦¬ν€˜μŠ€νŠΈλŠ” 폼 생성 및 제좜 ν”„λ‘œμ„ΈμŠ€μ™€ κ΄€λ ¨λœ μ—¬λŸ¬ μ»΄ν¬λ„ŒνŠΈμ™€ API μ—”λ“œν¬μΈνŠΈμ— λŒ€ν•œ κ΄‘λ²”μœ„ν•œ λ³€κ²½ 사항을 ν¬ν•¨ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€. μ£Όμš” λ³€κ²½ 사항은 폼 생성 둜직의 μœ νš¨μ„± 검사 κ°•ν™”, 응닡 처리 κ°œμ„ , νƒ€μž… μ •μ˜ μΆ”κ°€, 그리고 일뢀 μ»΄ν¬λ„ŒνŠΈμ˜ μƒνƒœ 관리 둜직 μˆ˜μ •μ„ ν¬ν•¨ν•©λ‹ˆλ‹€.

Changes

파일 λ³€κ²½ μš”μ•½
src/app/api/form/[expo_id]/route.ts NextResponse 객체λ₯Ό μ‚¬μš©ν•œ 응닡 처리 둜직 μˆ˜μ •
src/entities/create-form/index.tsx TextOption μ»΄ν¬λ„ŒνŠΈ 내보내기 제거
src/entities/create-form/ui/FormTitle/index.tsx μž…λ ₯ ν•„λ“œ μœ νš¨μ„± 검사 μ˜΅μ…˜ μΆ”κ°€
src/entities/create-form/ui/OptionItem/index.tsx μž…λ ₯ ν•„λ“œ ν•„μˆ˜ ν•­λͺ© 및 였λ₯˜ λ©”μ‹œμ§€ μΆ”κ°€
src/shared/types/create-form/type.ts CreateFormRequest μΈν„°νŽ˜μ΄μŠ€ μΆ”κ°€
src/views/create-form/api/createForm.ts CreateFormRequest νƒ€μž…μœΌλ‘œ 데이터 νŒŒλΌλ―Έν„° λ³€κ²½
src/views/create-form/model/formCreateRouter.ts λΌμš°νŒ… μΌ€μ΄μŠ€ λŒ€λ¬Έμžλ‘œ λ³€κ²½
src/views/create-form/ui/createForm/index.tsx 였λ₯˜ 처리 및 제좜 둜직 κ°œμ„ 

Suggested labels

⚑️performance, πŸ“¬ Type: API

Suggested reviewers

  • happytaeyoon

Poem

🐰 폼을 λ§Œλ“œλŠ” ν† λΌμ˜ λ…Έλž˜ 🐰

νƒ€μž…κ³Ό κ²€μ¦μ˜ 좀을 μΆ”λ©°
μ½”λ“œλŠ” 흐λ₯΄κ³  였λ₯˜λŠ” μž λ“€μ–΄
μƒˆλ‘œμš΄ κΈ°λŠ₯의 문을 μ—΄μ–΄
ν† λΌμ˜ μ†κΈΈλ‘œ μ™„μ„±λ˜λŠ” 세상

✨ Finishing Touches
  • πŸ“ Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❀️ Share
πŸͺ§ Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

πŸ”­ Outside diff range comments (1)
src/views/create-form/api/createForm.ts (1)

Line range hint 10-12: API ν˜ΈμΆœμ— λŒ€ν•œ μ—λŸ¬ μ²˜λ¦¬κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

μ„œλ²„ 응닡 μ‹€νŒ¨λ‚˜ λ„€νŠΈμ›Œν¬ 였λ₯˜μ— λŒ€ν•œ μ²˜λ¦¬κ°€ μ—†μŠ΅λ‹ˆλ‹€. μ μ ˆν•œ μ—λŸ¬ 처리λ₯Ό μΆ”κ°€ν•˜λŠ” 것이 μ’‹κ² μŠ΅λ‹ˆλ‹€.

 export const createForm = async ({
   data,
   id,
 }: {
   data: CreateFormRequest;
   id: string;
 }) => {
-  const response = await axios.post(`/api/form/${id}`, data);
-  return response;
+  try {
+    const response = await axios.post(`/api/form/${id}`, data);
+    return response;
+  } catch (error) {
+    if (axios.isAxiosError(error)) {
+      throw new Error(`폼 생성 μ‹€νŒ¨: ${error.message}`);
+    }
+    throw error;
+  }
 };
🧹 Nitpick comments (7)
src/entities/create-form/ui/FormTitle/index.tsx (1)

14-16: 폼 μœ νš¨μ„± 검사가 적절히 μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€.

ν•„μˆ˜ μž…λ ₯ 검증이 잘 κ΅¬ν˜„λ˜μ—ˆμœΌλ©°, 인덱슀λ₯Ό ν™œμš©ν•œ 동적 μ—λŸ¬ λ©”μ‹œμ§€ 생성이 νš¨κ³Όμ μž…λ‹ˆλ‹€.

μ—λŸ¬ λ©”μ‹œμ§€ 관리 κ°œμ„ μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€.

ν˜„μž¬ μ—λŸ¬ λ©”μ‹œμ§€κ°€ μ»΄ν¬λ„ŒνŠΈμ— 직접 ν•˜λ“œμ½”λ”©λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. λ‹€κ΅­μ–΄ μ§€μ›μ΄λ‚˜ λ©”μ‹œμ§€ 일관성을 μœ„ν•΄ μƒμˆ˜ 파일둜 λΆ„λ¦¬ν•˜λŠ” 것을 κ³ λ €ν•΄λ³΄μ„Έμš”.

λ‹€μŒκ³Ό 같이 κ°œμ„ ν•  수 μžˆμŠ΅λ‹ˆλ‹€:

+// src/shared/constants/errorMessages.ts
+export const ERROR_MESSAGES = {
+  FORM_TITLE_REQUIRED: (index: number) => `${index + 1}번 폼의 제λͺ©μ„ μž…λ ₯ν•΄μ£Όμ„Έμš”`,
+};

// FormTitle component
-          required: `${index + 1}번 폼의 제λͺ©μ„ μž…λ ₯ν•΄μ£Όμ„Έμš”`,
+          required: ERROR_MESSAGES.FORM_TITLE_REQUIRED(index),
src/views/create-form/model/formCreateRouter.ts (1)

13-14: λ„€λΉ„κ²Œμ΄μ…˜ μƒμˆ˜ μ •μ˜κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

λ„€λΉ„κ²Œμ΄μ…˜ 값듀을 μƒμˆ˜λ‘œ μ •μ˜ν•˜μ—¬ νƒ€μž… μ•ˆμ •μ„±μ„ 높이고 μž¬μ‚¬μš©μ„±μ„ κ°œμ„ ν•˜λŠ” 것이 μ’‹κ² μŠ΅λ‹ˆλ‹€.

+export const NAVIGATION_TYPES = {
+  STANDARD: 'STANDARD',
+  TRAINEE: 'TRAINEE',
+} as const;
+
+type NavigationType = typeof NAVIGATION_TYPES[keyof typeof NAVIGATION_TYPES];
+
 export const formCreateRouter = ({
   id,
   navigation,
   router,
 }: {
   id: string;
-  navigation: string | null;
+  navigation: NavigationType | null;
   router: AppRouterInstance;
 }) => {
   switch (navigation) {
-    case 'STANDARD':
-      router.push(`/create-form/${id}?navigation=TRAINEE`);
+    case NAVIGATION_TYPES.STANDARD:
+      router.push(`/create-form/${id}?navigation=${NAVIGATION_TYPES.TRAINEE}`);
       break;
-    case 'TRAINEE':
+    case NAVIGATION_TYPES.TRAINEE:
       router.push('/');
       break;
     default:
+      console.warn(`μ•Œ 수 μ—†λŠ” λ„€λΉ„κ²Œμ΄μ…˜ νƒ€μž…: ${navigation}`);
       break;
   }
 };

Also applies to: 16-17

src/shared/types/create-form/type.ts (1)

25-33: μΈν„°νŽ˜μ΄μŠ€μ— λŒ€ν•œ λ¬Έμ„œν™”κ°€ ν•„μš”ν•©λ‹ˆλ‹€.

각 ν•„λ“œμ˜ λͺ©μ κ³Ό μ œμ•½μ‚¬ν•­μ„ μ„€λͺ…ν•˜λŠ” JSDoc λ¬Έμ„œλ₯Ό μΆ”κ°€ν•˜λ©΄ μ’‹κ² μŠ΅λ‹ˆλ‹€.

+/**
+ * 폼 생성 μš”μ²­μ— λŒ€ν•œ 데이터 ꡬ쑰
+ */
 export interface CreateFormRequest {
+  /** 정보 μ΄λ―Έμ§€μ˜ URL λ˜λŠ” base64 λ¬Έμžμ—΄ */
   informationImage: string;
+  /** μ°Έκ°€μž μœ ν˜• μ‹λ³„μž */
   participantType: string;
+  /** 동적 폼 ν•„λ“œ λ°°μ—΄ */
   dynamicForm: {
+    /** 폼 ν•„λ“œμ˜ 제λͺ© */
     title: string;
+    /** 폼 ν•„λ“œμ˜ μœ ν˜• */
     formType: string;
+    /** JSON 데이터λ₯Ό λ¬Έμžμ—΄λ‘œ λ³€ν™˜ν•œ κ°’ */
     jsonData: string;
   }[];
 }
src/app/api/form/[expo_id]/route.ts (1)

23-26: 응닡 μ²˜λ¦¬κ°€ κ°œμ„ λ˜μ—ˆμœΌλ‚˜ μΆ”κ°€ κ°œμ„ μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€.

응닡 μ²˜λ¦¬κ°€ NextResponseλ₯Ό μ‚¬μš©ν•˜μ—¬ κ°œμ„ λ˜μ—ˆμŠ΅λ‹ˆλ‹€. λ‹€λ§Œ λ‹€μŒκ³Ό 같은 μΆ”κ°€ κ°œμ„ μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

  1. 성곡 μ‘λ‹΅μ˜ μƒνƒœ μ½”λ“œλ₯Ό λͺ…μ‹œμ μœΌλ‘œ 201둜 μ„€μ •
  2. CORS 헀더 μΆ”κ°€ κ³ λ €

λ‹€μŒκ³Ό 같이 μˆ˜μ •ν•˜λŠ” 것을 μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

-    return new NextResponse(JSON.stringify(response.data), {
-      status: response.status,
-      headers: { 'Content-Type': 'application/json' },
-    });
+    return new NextResponse(JSON.stringify(response.data), {
+      status: 201,
+      headers: {
+        'Content-Type': 'application/json',
+        'Access-Control-Allow-Origin': '*',
+      },
+    });
src/views/create-form/ui/createForm/index.tsx (2)

54-61: 데이터 λ³€ν™˜ 둜직 κ°œμ„ μ΄ ν•„μš”ν•©λ‹ˆλ‹€.

ν˜„μž¬ κ΅¬ν˜„μ€ μž‘λ™ν•˜μ§€λ§Œ, 가독성과 μœ μ§€λ³΄μˆ˜μ„±μ„ μœ„ν•΄ λ‹€μŒκ³Ό 같은 κ°œμ„ μ„ μ œμ•ˆλ“œλ¦½λ‹ˆλ‹€:

-        jsonData: JSON.stringify(
-          question.options.reduce(
-            (acc, option, index) => {
-              acc[(index + 1).toString()] = option.value;
-              return acc;
-            },
-            {} as Record<string, string>,
-          ),
-        ),
+        jsonData: JSON.stringify(
+          Object.fromEntries(
+            question.options.map((option, index) => [
+              (index + 1).toString(),
+              option.value,
+            ]),
+          ),
+        ),

81-84: μ—λŸ¬ λ‘œκΉ… κ°œμ„ μ΄ ν•„μš”ν•©λ‹ˆλ‹€.

μ½˜μ†” 둜그λ₯Ό ν”„λ‘œλ•μ…˜ ν™˜κ²½μ—μ„œ μ œκ±°ν•˜κ±°λ‚˜ proper λ‘œκΉ… μ‹œμŠ€ν…œμœΌλ‘œ λŒ€μ²΄ν•˜λŠ” 것이 μ’‹μŠ΅λ‹ˆλ‹€.

-        onSubmit={handleSubmit(onSubmit, (errors) => {
-          console.log(errors);
-          handleFormErrors(errors, showError);
-        })}
+        onSubmit={handleSubmit(onSubmit, (errors) => {
+          handleFormErrors(errors, showError);
+        })}
src/widgets/create-form/ui/FormContainer/index.tsx (1)

101-112: useEffect κ΅¬ν˜„μ΄ μ μ ˆν•©λ‹ˆλ‹€!

μ˜΅μ…˜ μ΄ˆκΈ°ν™”μ™€ μ²΄ν¬λ°•μŠ€ μƒνƒœ 관리가 잘 κ΅¬ν˜„λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€. λ‹€λ§Œ, 가독성 ν–₯상을 μœ„ν•΄ 쑰건문을 μƒμˆ˜λ‘œ μΆ”μΆœν•˜λŠ” 것을 κ³ λ €ν•΄λ³΄μ„Έμš”.

+  const isSentenceType = selectedOption?.value === 'SENTENCE';
+  const isImageType = selectedOption?.value === 'IMAGE';
+
   useEffect(() => {
-    if (selectedOption?.value === 'SENTENCE') {
+    if (isSentenceType) {
       setValue(`questions.${index}.options`, []);
     }
 
-    if (
-      selectedOption?.value === 'SENTENCE' ||
-      selectedOption?.value === 'IMAGE'
-    ) {
+    if (isSentenceType || isImageType) {
       setIsCheckBox(false);
     }
   }, [selectedOption, index, setValue]);
πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 9a570f5 and 3c66fec.

πŸ“’ Files selected for processing (13)
  • src/app/api/form/[expo_id]/route.ts (1 hunks)
  • src/entities/create-form/index.tsx (0 hunks)
  • src/entities/create-form/ui/FormTitle/index.tsx (1 hunks)
  • src/entities/create-form/ui/OptionItem/index.tsx (1 hunks)
  • src/entities/create-form/ui/TextOption/index.tsx (0 hunks)
  • src/shared/types/create-form/type.ts (1 hunks)
  • src/shared/ui/ToggleButton/index.tsx (1 hunks)
  • src/views/create-form/api/createForm.ts (1 hunks)
  • src/views/create-form/model/formCreateRouter.ts (1 hunks)
  • src/views/create-form/model/useCreateForm.ts (2 hunks)
  • src/views/create-form/ui/createForm/index.tsx (3 hunks)
  • src/widgets/create-form/ui/FormContainer/index.tsx (3 hunks)
  • src/widgets/expo-created/ui/ExpoCreatedContainer/index.tsx (1 hunks)
πŸ’€ Files with no reviewable changes (2)
  • src/entities/create-form/index.tsx
  • src/entities/create-form/ui/TextOption/index.tsx
βœ… Files skipped from review due to trivial changes (1)
  • src/widgets/expo-created/ui/ExpoCreatedContainer/index.tsx
πŸ”‡ Additional comments (5)
src/views/create-form/api/createForm.ts (1)

2-2: νƒ€μž… μ •μ˜ κ°œμ„ μ΄ 잘 μ΄λ£¨μ–΄μ‘ŒμŠ΅λ‹ˆλ‹€.

λ³„λ„μ˜ νƒ€μž… 파일둜 λΆ„λ¦¬ν•˜μ—¬ μž¬μ‚¬μš©μ„±κ³Ό μœ μ§€λ³΄μˆ˜μ„±μ΄ ν–₯μƒλ˜μ—ˆμŠ΅λ‹ˆλ‹€.

Also applies to: 8-8

src/views/create-form/model/useCreateForm.ts (1)

4-4: νƒ€μž… μ•ˆμ „μ„±μ΄ κ°œμ„ λ˜μ—ˆμŠ΅λ‹ˆλ‹€! πŸ‘

CreateFormRequest νƒ€μž…μ„ λ„μž…ν•˜μ—¬ 폼 λ°μ΄ν„°μ˜ νƒ€μž… μ•ˆμ „μ„±μ΄ ν–₯μƒλ˜μ—ˆμŠ΅λ‹ˆλ‹€. μ΄λŠ” λŸ°νƒ€μž„ 였λ₯˜λ₯Ό λ°©μ§€ν•˜κ³  μ½”λ“œμ˜ μœ μ§€λ³΄μˆ˜μ„±μ„ λ†’μ΄λŠ”λ° 도움이 λ©λ‹ˆλ‹€.

Also applies to: 17-18

src/entities/create-form/ui/OptionItem/index.tsx (1)

28-28: ν•„μˆ˜ μž…λ ₯ μœ νš¨μ„± 검사가 μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€! πŸ‘

μ˜΅μ…˜ μž…λ ₯ ν•„λ“œμ— ν•„μˆ˜ μž…λ ₯ μœ νš¨μ„± 검사λ₯Ό μΆ”κ°€ν•œ 것은 쒋은 κ°œμ„ μž…λ‹ˆλ‹€. μ‚¬μš©μžμ—κ²Œ λͺ…ν™•ν•œ μ—λŸ¬ λ©”μ‹œμ§€λ₯Ό μ œκ³΅ν•˜μ—¬ UXκ°€ ν–₯μƒλ˜μ—ˆμŠ΅λ‹ˆλ‹€.

src/views/create-form/ui/createForm/index.tsx (2)

33-35: μ—λŸ¬ 처리 ν•¨μˆ˜κ°€ μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€! πŸ‘

showError ν•¨μˆ˜λ₯Ό 톡해 μΌκ΄€λœ μ—λŸ¬ 처리 방식을 μ œκ³΅ν•˜λŠ” 것은 쒋은 μ ‘κ·Όμž…λ‹ˆλ‹€.


44-47: 폼 μœ νš¨μ„± 검사가 μΆ”κ°€λ˜μ—ˆμŠ΅λ‹ˆλ‹€! πŸ‘

μ΅œμ†Œ ν•œ 개의 폼이 ν•„μš”ν•˜λ‹€λŠ” μœ νš¨μ„± 검사λ₯Ό μΆ”κ°€ν•œ 것은 쒋은 κ°œμ„ μž…λ‹ˆλ‹€.

Comment on lines +17 to 23
className={`relative inline-flex h-6 w-12 items-center rounded-full transition-colors ${isToggled ? 'bg-main-100' : 'bg-gray-100'}`}
>
<span
className={`inline-block h-7 w-7 transform rounded-full bg-gray-500 transition-transform duration-300 ${
isToggled ? 'translate-x-9' : 'translate-x-0'
className={`inline-block h-7 w-7 transform rounded-full transition-transform duration-300 ${
isToggled ? 'translate-x-9 bg-main-600' : 'translate-x-0 bg-gray-500'
}`}
/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

μ ‘κ·Όμ„± 속성과 μ»€μŠ€ν„°λ§ˆμ΄μ§• κΈ°λŠ₯이 ν•„μš”ν•©λ‹ˆλ‹€.

  1. 접근성을 μœ„ν•œ ARIA 속성이 λˆ„λ½λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
  2. μ»΄ν¬λ„ŒνŠΈμ˜ μž¬μ‚¬μš©μ„±μ„ μœ„ν•΄ 색상과 크기λ₯Ό props둜 받도둝 κ°œμ„ μ΄ ν•„μš”ν•©λ‹ˆλ‹€.
+interface ToggleButtonProps {
+  onChange?: (isToggled: boolean) => void;
+  defaultValue?: boolean;
+  ariaLabel?: string;
+}
+
-function ToggleButton() {
+function ToggleButton({
+  onChange,
+  defaultValue = false,
+  ariaLabel = 'ν† κΈ€ λ²„νŠΌ',
+}: ToggleButtonProps) {
-  const [isToggled, setIsToggled] = useState(false);
+  const [isToggled, setIsToggled] = useState(defaultValue);

   const toggle = (e: React.MouseEvent) => {
     preventEvent(e);
-    setIsToggled(!isToggled);
+    const newValue = !isToggled;
+    setIsToggled(newValue);
+    onChange?.(newValue);
   };

   return (
     <button
+      role="switch"
+      aria-checked={isToggled}
+      aria-label={ariaLabel}
       onClick={toggle}
       className={`relative inline-flex h-6 w-12 items-center rounded-full transition-colors ${
         isToggled ? 'bg-main-100' : 'bg-gray-100'
       }`}
     >

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +129 to +131
{selectedOption?.value !== 'SENTENCE' ? (
<AddItemButton onClick={() => append({ value: '' })} />
) : null}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ› οΈ Refactor suggestion

쑰건뢀 λ Œλ”λ§ λ‘œμ§μ„ κ°œμ„ ν•˜μ„Έμš”.

λ™μΌν•œ 쑰건이 μ—¬λŸ¬ κ³³μ—μ„œ 반볡되고 μžˆμŠ΅λ‹ˆλ‹€. μƒμˆ˜λ‘œ μΆ”μΆœν•˜μ—¬ μž¬μ‚¬μš©ν•˜λ©΄ μ½”λ“œμ˜ μœ μ§€λ³΄μˆ˜μ„±μ΄ ν–₯상될 κ²ƒμž…λ‹ˆλ‹€.

+  const isSentenceType = selectedOption?.value === 'SENTENCE';
+  const isImageType = selectedOption?.value === 'IMAGE';
+  const showOptions = !isSentenceType;
+  const showCheckBox = !isSentenceType && !isImageType;

   // ...
-  {selectedOption?.value !== 'SENTENCE' ? (
+  {showOptions && (
     <AddItemButton onClick={() => append({ value: '' })} />
-  ) : null}
   )}
   
   // ...
-  {selectedOption?.value !== 'IMAGE' &&
-   selectedOption?.value !== 'SENTENCE' ? (
+  {showCheckBox && (
     <CheckBox
       toggleCheck={handleCheckBox}
       isCheckBox={isCheckBox}
       text="기타"
     />
-  ) : null}
   )}

Also applies to: 134-135

@Ethen1264 Ethen1264 merged commit 7783c37 into develop Jan 30, 2025
2 checks passed
@Ethen1264 Ethen1264 deleted the fix/create-form branch February 3, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 Bug 버그 λ°œμƒ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants