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

๐Ÿ”€ ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ ๋ฆฌํŒฉํ† ๋ง ์ง„ํ–‰ #62

Merged
merged 5 commits into from
Dec 18, 2024

Conversation

Ethen1264
Copy link
Contributor

@Ethen1264 Ethen1264 commented Dec 17, 2024

๐Ÿ’ก ๋ฐฐ๊ฒฝ ๋ฐ ๊ฐœ์š”

ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ ๋ฆฌํŒฉํ† ๋ง ์ง„ํ–‰

๐Ÿ“ƒ ์ž‘์—…๋‚ด์šฉ

ํšŒ์›๊ฐ€์ž… api -> tanstack query๋กœ ๋ณ€๊ฒฝ
๋ฌธ์ž์ „์†ก api -> tanstack query๋กœ ๋ณ€๊ฒฝ
๏ฟฝ๋ฌธ์žํ™•์ธ api -> tanstack query๋กœ ๋ณ€๊ฒฝ
ํƒ€์ด๋จธ ์ดˆ๊ธฐํ™” ๋ถˆ๊ฐ€ ์ด์Šˆ ํ•ด๊ฒฐ

Summary by CodeRabbit

  • New Features

    • SMS ์ฝ”๋“œ ํ™•์ธ ๋ฐ ์‚ฌ์šฉ์ž ๊ฐ€์ž…์„ ์œ„ํ•œ ์ƒˆ๋กœ์šด ์ปค์Šคํ…€ ํ›… ์ถ”๊ฐ€.
    • SMS ์ „์†ก ๊ธฐ๋Šฅ์„ ์œ„ํ•œ ์ƒˆ๋กœ์šด ํ›… ์ถ”๊ฐ€.
    • ์‚ฌ์šฉ์ž ๊ฐ€์ž… ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์ƒˆ๋กœ์šด ์ธํ„ฐํŽ˜์ด์Šค ๋ฐ ํ•จ์ˆ˜ ์ถ”๊ฐ€.
  • Bug Fixes

    • SMS ์ „์†ก ๋ฐ ์ฝ”๋“œ ํ™•์ธ ๋กœ์ง ๊ฐœ์„ ์œผ๋กœ ์‚ฌ์šฉ์ž ํ”ผ๋“œ๋ฐฑ ํ–ฅ์ƒ.
  • Refactor

    • ๊ธฐ์กด API ํ˜ธ์ถœ์„ ์ปค์Šคํ…€ ํ›…์œผ๋กœ ๋Œ€์ฒดํ•˜์—ฌ ์ฝ”๋“œ ๊ฐ€๋…์„ฑ ๋ฐ ์œ ์ง€ ๊ด€๋ฆฌ์„ฑ ํ–ฅ์ƒ.
  • Chores

    • ๋ถˆํ•„์š”ํ•œ ํŒŒ์ผ ๋ฐ ๋ฉ”์„œ๋“œ ์‚ญ์ œ.

@Ethen1264 Ethen1264 added โšก๏ธperformance ์„ฑ๋Šฅ ๊ฐœ์„  ๐Ÿž Bug ๋ฒ„๊ทธ ๋ฐœ์ƒ ๐Ÿ“ฌ Type: API ์„œ๋ฒ„ API ํ†ต์‹  labels Dec 17, 2024
@Ethen1264 Ethen1264 self-assigned this Dec 17, 2024
Copy link

coderabbitai bot commented Dec 17, 2024

Walkthrough

์ด ํ’€ ๋ฆฌํ€˜์ŠคํŠธ๋Š” ์‚ฌ์šฉ์ž ๊ฐ€์ž… ํ”„๋กœ์„ธ์Šค์™€ ๊ด€๋ จ๋œ API ๋ฐ ๋ชจ๋ธ ๊ณ„์ธต์„ ๋ฆฌํŒฉํ† ๋งํ•ฉ๋‹ˆ๋‹ค. ๊ธฐ์กด์˜ ์ง์ ‘์ ์ธ API ํ˜ธ์ถœ ๋ฐฉ์‹์—์„œ React Query ํ›…์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ณ€๊ฒฝ๋˜์—ˆ์œผ๋ฉฐ, SMS ์ธ์ฆ, ์‚ฌ์šฉ์ž ๊ฐ€์ž…, ํƒ€์ด๋จธ ๊ด€๋ฆฌ ๋“ฑ์˜ ๋กœ์ง์„ ๋” ๋ชจ๋“ˆํ™”ํ•˜๊ณ  ์ถ”์ƒํ™”ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฝ”๋“œ์˜ ๊ตฌ์กฐ๋ฅผ ๊ฐœ์„ ํ•˜๊ณ  ์ƒํƒœ ๊ด€๋ฆฌ๋ฅผ ๋” ํšจ์œจ์ ์œผ๋กœ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค.

Changes

ํŒŒ์ผ ๋ณ€๊ฒฝ ์š”์•ฝ
src/entities/signUp/api/checkSmsCode.ts ์‚ญ์ œ๋จ
src/entities/signUp/api/getCheckSmsCode.ts ์ƒˆ๋กœ์šด SMS ์ฝ”๋“œ ๊ฒ€์ฆ API ํ•จ์ˆ˜ ์ถ”๊ฐ€
src/entities/signUp/api/postSendSms.ts ์ƒˆ๋กœ์šด SMS ์ „์†ก API ํ•จ์ˆ˜ ์ถ”๊ฐ€
src/entities/signUp/api/postSignup.ts ์ƒˆ๋กœ์šด ์‚ฌ์šฉ์ž ๊ฐ€์ž… API ํ•จ์ˆ˜ ๋ฐ ์ธํ„ฐํŽ˜์ด์Šค ์ถ”๊ฐ€
src/entities/signUp/api/sendSms.ts ์‚ญ์ œ๋จ
src/entities/signUp/api/signup.ts ์‚ญ์ œ๋จ
src/entities/signUp/model/useCheckSmsCode.ts SMS ์ฝ”๋“œ ๊ฒ€์ฆ์„ ์œ„ํ•œ ์ƒˆ๋กœ์šด React Query ํ›… ์ถ”๊ฐ€
src/entities/signUp/model/useSendSms.ts SMS ์ „์†ก์„ ์œ„ํ•œ ์ƒˆ๋กœ์šด React Query ํ›… ์ถ”๊ฐ€
src/entities/signUp/model/useSignup.ts ์‚ฌ์šฉ์ž ๊ฐ€์ž…์„ ์œ„ํ•œ ์ƒˆ๋กœ์šด React Query ํ›… ์ถ”๊ฐ€
src/entities/signUp/model/useTimer.ts ํƒ€์ด๋จธ ํ›… ์—…๋ฐ์ดํŠธ
src/entities/signUp/ui/SignUpForm/index.tsx ์ƒˆ๋กœ์šด ํ›…๋“ค๋กœ ์ปดํฌ๋„ŒํŠธ ๋กœ์ง ์—…๋ฐ์ดํŠธ

Sequence Diagram

sequenceDiagram
    participant User
    participant SignUpForm
    participant useSendSms
    participant postSendSms
    participant useCheckSmsCode
    participant getCheckSmsCode
    participant useSignup
    participant postSignup

    User->>SignUpForm: ์ „ํ™”๋ฒˆํ˜ธ ์ž…๋ ฅ
    SignUpForm->>useSendSms: SMS ์ „์†ก ์š”์ฒญ
    useSendSms->>postSendSms: SMS ์ „์†ก API ํ˜ธ์ถœ
    postSendSms-->>useSendSms: SMS ์ „์†ก ์‘๋‹ต
    useSendSms-->>SignUpForm: SMS ์ „์†ก ์ƒํƒœ ์—…๋ฐ์ดํŠธ

    User->>SignUpForm: SMS ์ฝ”๋“œ ์ž…๋ ฅ
    SignUpForm->>useCheckSmsCode: SMS ์ฝ”๋“œ ๊ฒ€์ฆ
    useCheckSmsCode->>getCheckSmsCode: SMS ์ฝ”๋“œ ๊ฒ€์ฆ API ํ˜ธ์ถœ
    getCheckSmsCode-->>useCheckSmsCode: ๊ฒ€์ฆ ๊ฒฐ๊ณผ
    
    User->>SignUpForm: ๊ฐ€์ž… ์ •๋ณด ์ž…๋ ฅ
    SignUpForm->>useSignup: ๊ฐ€์ž… ์š”์ฒญ
    useSignup->>postSignup: ์‚ฌ์šฉ์ž ๊ฐ€์ž… API ํ˜ธ์ถœ
    postSignup-->>useSignup: ๊ฐ€์ž… ์‘๋‹ต
Loading

Poem

๐Ÿฐ ์ฝ”๋“œ์˜ ํ† ๋ผ, ๋›ฐ์–ด๋‹ค๋…€์š”
SMS ํ›…์œผ๋กœ ๊ฒฝ๋กœ๋ฅผ ์—ด์–ด์š”
๋ฆฌํŒฉํ† ๋ง์˜ ์‹ ์„ ํ•œ ๋ฐ”๋žŒ
์ฟผ๋ฆฌ์™€ ํ•จ๊ป˜ ์ถค์„ ์ถ”์–ด์š”
๋” ๋‚˜์€ ๊ฐ€์ž…, ๋” ์‰ฌ์šด ๊ธธ! ๐Ÿš€

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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: 5

๐Ÿ”ญ Outside diff range comments (1)
src/entities/signUp/ui/SignUpForm/index.tsx (1)

Line range hint 132-141: SMS ์ธ์ฆ ์ž…๋ ฅ ํ•„๋“œ์˜ ๋น„ํ™œ์„ฑํ™” ๋กœ์ง์— ์˜ค๋ฅ˜๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

disabled={!isSmsSent && watch('code') !== null} ์กฐ๊ฑด์ด ์ง๊ด€์ ์ด์ง€ ์•Š์œผ๋ฉฐ, ์ž˜๋ชป๋œ ์ƒํ™ฉ์—์„œ ์ž…๋ ฅ ํ•„๋“œ๊ฐ€ ๋น„ํ™œ์„ฑํ™”๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

-              disabled={!isSmsSent && watch('code') !== null}
+              disabled={!isSmsSent}
๐Ÿงน Nitpick comments (7)
src/entities/signUp/model/useCheckSmsCode.ts (1)

4-10: TanStack Query ์„ค์ • ์ตœ์ ํ™”๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

ํ˜„์žฌ ์ฟผ๋ฆฌ ์„ค์ •์ด ๊ธฐ๋ณธ๊ฐ’๋งŒ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์–ด, SMS ์ธ์ฆ ํŠน์„ฑ์— ๋งž๊ฒŒ ์ตœ์ ํ™”๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐœ์„ ํ•ด๋ณด์„ธ์š”:

 export const useCheckSmsCode = (phoneNumber: string, code: string) => {
   return useQuery({
     queryKey: ['CheckSmsCode', phoneNumber, code],
     queryFn: () => getCheckSmsCode(phoneNumber, code),
     enabled: false,
+    retry: 1,
+    staleTime: 0,
+    cacheTime: 1000 * 60 * 5, // 5๋ถ„
+    onError: (error) => {
+      if (axios.isAxiosError(error)) {
+        toast.error(error.response?.data?.message || 'SMS ์ธ์ฆ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
+      }
+    }
   });
 };

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด:

  1. ์‹คํŒจ ์‹œ 1๋ฒˆ๋งŒ ์žฌ์‹œ๋„
  2. ์บ์‹œ๋Š” 5๋ถ„๊ฐ„ ์œ ์ง€
  3. ์—๋Ÿฌ ์ฒ˜๋ฆฌ๊ฐ€ ํ†ตํ•ฉ๋ฉ๋‹ˆ๋‹ค
src/entities/signUp/api/getCheckSmsCode.ts (1)

4-14: ์‘๋‹ต ํƒ€์ž… ์ •์˜๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค

ํƒ€์ž… ์•ˆ์ •์„ฑ์„ ์œ„ํ•ด API ์‘๋‹ต ํƒ€์ž…์„ ์ •์˜ํ•˜๊ณ  ์ ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ํƒ€์ž…์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์„ ์ œ์•ˆ๋“œ๋ฆฝ๋‹ˆ๋‹ค:

interface CheckSmsResponse {
  success: boolean;
  message?: string;
}

export const getCheckSmsCode = async (phoneNumber: string, code: string): Promise<CheckSmsResponse> => {
  // ... existing code
}
src/entities/signUp/model/useSendSms.ts (2)

17-17: ์˜คํƒ€๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”

์—๋Ÿฌ ๋ฉ”์‹œ์ง€์— ์˜คํƒ€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค:

  • "๋ฌธ์ œ ๋งค์‹œ์ง€" -> "๋ฌธ์ž ๋ฉ”์‹œ์ง€"

9-19: mutation ์„ค์ • ๊ฐœ์„ ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค

mutation ์„ค์ •์— retry ์˜ต์…˜๊ณผ ๊ตฌ์ฒด์ ์ธ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•˜๋ฉด ์ข‹์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์„ ์ œ์•ˆ๋“œ๋ฆฝ๋‹ˆ๋‹ค:

  return useMutation({
    mutationFn: (phoneNumber: string) => postSendSms(phoneNumber),
+   retry: 1,
    onSuccess: () => {
      setIsSmsSent(true);
      setTimer(180);
      toast.success('๋ฌธ์ž ๋ฉ”์‹œ์ง€ ์ „์†ก์ด ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
    },
-   onError: () => {
+   onError: (error: Error) => {
+     const errorMessage = error.message === 'INVALID_PHONE' 
+       ? '์˜ฌ๋ฐ”๋ฅธ ์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.'
+       : '๋ฌธ์ž ๋ฉ”์‹œ์ง€ ์ „์†ก์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.';
-     toast.error('๋ฌธ์ œ ๋งค์‹œ์ง€ ์ „์†ก์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
+     toast.error(errorMessage);
    },
  });
src/entities/signUp/model/useSignup.ts (1)

23-25: ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋ฅผ ๋” ๊ตฌ์ฒด์ ์œผ๋กœ ๊ฐœ์„ ํ•ด ๋ณด์„ธ์š”.

ํ˜„์žฌ๋Š” ๋ชจ๋“  ์—๋Ÿฌ์— ๋Œ€ํ•ด ๋™์ผํ•œ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. API ์‘๋‹ต์˜ ์—๋Ÿฌ ํƒ€์ž…์— ๋”ฐ๋ผ ๋‹ค๋ฅธ ๋ฉ”์‹œ์ง€๋ฅผ ํ‘œ์‹œํ•˜๋ฉด ์‚ฌ์šฉ์ž์—๊ฒŒ ๋” ๋ช…ํ™•ํ•œ ํ”ผ๋“œ๋ฐฑ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

-    onError: () => {
-      toast.error('ํšŒ์›๊ฐ€์ž…์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
-    },
+    onError: (error: any) => {
+      const errorMessage = error.response?.data?.message || 'ํšŒ์›๊ฐ€์ž…์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.';
+      toast.error(errorMessage);
+    },
src/entities/signUp/ui/SignUpForm/index.tsx (2)

Line range hint 43-49: ํผ ์ œ์ถœ ์‹œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๋ฅผ ๊ฐœ์„ ํ•ด ๋ณด์„ธ์š”.

ํ˜„์žฌ๋Š” ์ฒซ ๋ฒˆ์งธ ์—๋Ÿฌ๋งŒ ํ‘œ์‹œํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ๋ชจ๋“  ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ์˜ค๋ฅ˜๋ฅผ ํ•œ ๋ฒˆ์— ๋ณด์—ฌ์ฃผ๋ฉด ์‚ฌ์šฉ์ž ๊ฒฝํ—˜์ด ํ–ฅ์ƒ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

       (data) => signup(data),
-        (errors) => {
-          const firstError = Object.values(errors)[0];
-          if (firstError && firstError.message) {
-            showError(firstError.message as string);
-          }
-        },
+        (errors) => {
+          const errorMessages = Object.values(errors)
+            .map(error => error.message)
+            .filter(Boolean);
+          errorMessages.forEach(message => showError(message as string));
+        },
๐Ÿงฐ Tools
๐Ÿช› Biome (1.9.4)

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 144-150: ํƒ€์ด๋จธ ํ‘œ์‹œ์˜ ์ ‘๊ทผ์„ฑ์„ ๊ฐœ์„ ํ•ด ๋ณด์„ธ์š”.

์‹œ๊ฐ„ ํ‘œ์‹œ๊ฐ€ ์Šคํฌ๋ฆฐ ๋ฆฌ๋” ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ช…ํ™•ํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. aria-label์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์ ‘๊ทผ์„ฑ์„ ํ–ฅ์ƒ์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

            className="text-caption2 text-gray-300"
            disabled={isSmsSent}
+            aria-label={isSmsSent 
+              ? `์ธ์ฆ๋ฒˆํ˜ธ ์žฌ๋ฐœ์†ก๊นŒ์ง€ ๋‚จ์€ ์‹œ๊ฐ„: ${Math.floor(timer / 60)}๋ถ„ ${timer % 60}์ดˆ` 
+              : '์ธ์ฆ๋ฒˆํ˜ธ ๋ฐœ์†กํ•˜๊ธฐ'}
๐Ÿ“œ Review details

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

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 48bdbdd and 468c1fe.

๐Ÿ“’ Files selected for processing (11)
  • src/entities/signUp/api/checkSmsCode.ts (0 hunks)
  • src/entities/signUp/api/getCheckSmsCode.ts (1 hunks)
  • src/entities/signUp/api/postSendSms.ts (1 hunks)
  • src/entities/signUp/api/postSignup.ts (1 hunks)
  • src/entities/signUp/api/sendSms.ts (0 hunks)
  • src/entities/signUp/api/signup.ts (0 hunks)
  • src/entities/signUp/model/useCheckSmsCode.ts (1 hunks)
  • src/entities/signUp/model/useSendSms.ts (1 hunks)
  • src/entities/signUp/model/useSignup.ts (1 hunks)
  • src/entities/signUp/model/useTimer.ts (1 hunks)
  • src/entities/signUp/ui/SignUpForm/index.tsx (4 hunks)
๐Ÿ’ค Files with no reviewable changes (3)
  • src/entities/signUp/api/checkSmsCode.ts
  • src/entities/signUp/api/sendSms.ts
  • src/entities/signUp/api/signup.ts
๐Ÿ”‡ Additional comments (2)
src/entities/signUp/model/useSignup.ts (1)

1-12: ๊น”๋”ํ•œ ํƒ€์ž… ์ •์˜์™€ ํ•„์š”ํ•œ import ๊ตฌ๋ฌธ์ž…๋‹ˆ๋‹ค!

SignUpData ์ธํ„ฐํŽ˜์ด์Šค๊ฐ€ ํšŒ์›๊ฐ€์ž…์— ํ•„์š”ํ•œ ๋ชจ๋“  ํ•„๋“œ๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

src/entities/signUp/ui/SignUpForm/index.tsx (1)

Line range hint 7-36: ์ปค์Šคํ…€ ํ›…์„ ํ™œ์šฉํ•œ ๊น”๋”ํ•œ ๋ฆฌํŒฉํ† ๋ง์ž…๋‹ˆ๋‹ค!

React Query๋ฅผ ์‚ฌ์šฉํ•œ ์ƒํƒœ ๊ด€๋ฆฌ๊ฐ€ ์ž˜ ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. SMS ์ธ์ฆ ๊ด€๋ จ ๋กœ์ง์ด ํ›…์œผ๋กœ ๋ถ„๋ฆฌ๋˜์–ด ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์ด ํ–ฅ์ƒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

๐Ÿงฐ Tools
๐Ÿช› Biome (1.9.4)

[error] 46-46: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Comment on lines +4 to +12
export const postSendSms = async (phoneNumber: string) => {
if (!phoneNumber) {
toast.error('์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.');
return;
}

const response = await axios.post('/api/auth/sms', { phoneNumber });
return response;
};
Copy link

Choose a reason for hiding this comment

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

๐Ÿ› ๏ธ Refactor suggestion

API ์š”์ฒญ์— ๋Œ€ํ•œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ์™€ ํƒ€์ž… ์•ˆ์ „์„ฑ ๊ฐœ์„ ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ์‚ฌํ•ญ๋“ค์„ ๊ฐœ์„ ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค:

  1. axios ์š”์ฒญ์— ๋Œ€ํ•œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๊ฐ€ ๋ˆ„๋ฝ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค
  2. ์‘๋‹ต ๋ฐ์ดํ„ฐ์˜ ํƒ€์ž…์ด ์ •์˜๋˜์–ด ์žˆ์ง€ ์•Š์Šต๋‹ˆ๋‹ค
  3. ์ „ํ™”๋ฒˆํ˜ธ ํ˜•์‹์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค

๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐœ์„ ํ•ด๋ณด์„ธ์š”:

+interface SendSmsResponse {
+  success: boolean;
+  message: string;
+}
+
 export const postSendSms = async (phoneNumber: string) => {
   if (!phoneNumber) {
     toast.error('์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.');
     return;
   }
+  
+  if (!/^01[0-9]{8,9}$/.test(phoneNumber)) {
+    toast.error('์˜ฌ๋ฐ”๋ฅธ ์ „ํ™”๋ฒˆํ˜ธ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค.');
+    return;
+  }
 
-  const response = await axios.post('/api/auth/sms', { phoneNumber });
-  return response;
+  try {
+    const { data } = await axios.post<SendSmsResponse>('/api/auth/sms', { phoneNumber });
+    return data;
+  } catch (error) {
+    if (axios.isAxiosError(error)) {
+      toast.error(error.response?.data?.message || 'SMS ์ „์†ก์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
+    }
+    throw error;
+  }
 };
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const postSendSms = async (phoneNumber: string) => {
if (!phoneNumber) {
toast.error('์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.');
return;
}
const response = await axios.post('/api/auth/sms', { phoneNumber });
return response;
};
interface SendSmsResponse {
success: boolean;
message: string;
}
export const postSendSms = async (phoneNumber: string) => {
if (!phoneNumber) {
toast.error('์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.');
return;
}
if (!/^01[0-9]{8,9}$/.test(phoneNumber)) {
toast.error('์˜ฌ๋ฐ”๋ฅธ ์ „ํ™”๋ฒˆํ˜ธ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค.');
return;
}
try {
const { data } = await axios.post<SendSmsResponse>('/api/auth/sms', { phoneNumber });
return data;
} catch (error) {
if (axios.isAxiosError(error)) {
toast.error(error.response?.data?.message || 'SMS ์ „์†ก์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
}
throw error;
}
};

Comment on lines +3 to +9
interface SignUpData {
name: string;
nickname: string;
email: string;
password: string;
phoneNumber: string;
}
Copy link

Choose a reason for hiding this comment

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

๐Ÿ› ๏ธ Refactor suggestion

ํšŒ์›๊ฐ€์ž… ๋ฐ์ดํ„ฐ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

SignUpData ์ธํ„ฐํŽ˜์ด์Šค์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋กœ์ง์ด ๋ˆ„๋ฝ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด Zod๋ฅผ ์‚ฌ์šฉํ•œ ์Šคํ‚ค๋งˆ ๊ฒ€์ฆ์„ ์ถ”๊ฐ€ํ•ด๋ณด์„ธ์š”:

import { z } from 'zod';

export const SignUpSchema = z.object({
  name: z.string().min(2, '์ด๋ฆ„์€ 2๊ธ€์ž ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค'),
  nickname: z.string().min(2, '๋‹‰๋„ค์ž„์€ 2๊ธ€์ž ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค'),
  email: z.string().email('์˜ฌ๋ฐ”๋ฅธ ์ด๋ฉ”์ผ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค'),
  password: z.string().min(8, '๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” 8์ž ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค'),
  phoneNumber: z.string().regex(/^01[0-9]{8,9}$/, '์˜ฌ๋ฐ”๋ฅธ ์ „ํ™”๋ฒˆํ˜ธ ํ˜•์‹์ด ์•„๋‹™๋‹ˆ๋‹ค')
});

export type SignUpData = z.infer<typeof SignUpSchema>;

Comment on lines +11 to +14
export const postSignup = async (data: SignUpData) => {
const response = await axios.post('/api/auth/signup', data);
return response;
};
Copy link

Choose a reason for hiding this comment

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

๐Ÿ› ๏ธ Refactor suggestion

์—๋Ÿฌ ์ฒ˜๋ฆฌ์™€ ์‘๋‹ต ํƒ€์ž… ์ •์˜๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

API ์‘๋‹ต์— ๋Œ€ํ•œ ํƒ€์ž… ์ •์˜์™€ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๊ฐ€ ๋ˆ„๋ฝ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐœ์„ ํ•ด๋ณด์„ธ์š”:

+interface SignUpResponse {
+  success: boolean;
+  message: string;
+  userId?: string;
+}
+
 export const postSignup = async (data: SignUpData) => {
+  try {
+    await SignUpSchema.parseAsync(data);
+    const { data: response } = await axios.post<SignUpResponse>('/api/auth/signup', data);
+    return response;
+  } catch (error) {
+    if (error instanceof z.ZodError) {
+      toast.error(error.errors[0].message);
+    } else if (axios.isAxiosError(error)) {
+      toast.error(error.response?.data?.message || 'ํšŒ์›๊ฐ€์ž…์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
+    }
+    throw error;
+  }
 };

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

Comment on lines +10 to +12
const response = await axios.get(
`/api/auth/sms?phoneNumber=${phoneNumber}&code=${code}`,
);
Copy link

Choose a reason for hiding this comment

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

โš ๏ธ Potential issue

URL ํŒŒ๋ผ๋ฏธํ„ฐ ์ธ์ฝ”๋”ฉ ๋ฐ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค

๋ณด์•ˆ ๋ฐ ์•ˆ์ •์„ฑ ํ–ฅ์ƒ์„ ์œ„ํ•œ ์ˆ˜์ •์‚ฌํ•ญ๋“ค์ž…๋‹ˆ๋‹ค:

  1. URL ํŒŒ๋ผ๋ฏธํ„ฐ์— encodeURIComponent๋ฅผ ์ ์šฉํ•˜์—ฌ XSS ๊ณต๊ฒฉ์„ ๋ฐฉ์ง€ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค
  2. axios ์š”์ฒญ์— ๋Œ€ํ•œ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์„ ์ œ์•ˆ๋“œ๋ฆฝ๋‹ˆ๋‹ค:

-  const response = await axios.get(
-    `/api/auth/sms?phoneNumber=${phoneNumber}&code=${code}`,
-  );
+  try {
+    const response = await axios.get(
+      `/api/auth/sms?phoneNumber=${encodeURIComponent(phoneNumber)}&code=${encodeURIComponent(code)}`,
+    );
+    return response;
+  } catch (error) {
+    toast.error('์ธ์ฆ๋ฒˆํ˜ธ ํ™•์ธ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
+    throw error;
+  }
-  return response;
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const response = await axios.get(
`/api/auth/sms?phoneNumber=${phoneNumber}&code=${code}`,
);
try {
const response = await axios.get(
`/api/auth/sms?phoneNumber=${encodeURIComponent(phoneNumber)}&code=${encodeURIComponent(code)}`,
);
return response;
} catch (error) {
toast.error('์ธ์ฆ๋ฒˆํ˜ธ ํ™•์ธ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
throw error;
}

Comment on lines +15 to +18
} else if (timer === 0) {
setIsSmsSent(false);
}
}, [timer, setTimer]);
}, [timer, setTimer, setIsSmsSent]);
Copy link

Choose a reason for hiding this comment

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

๐Ÿ› ๏ธ Refactor suggestion

ํƒ€์ด๋จธ ๋กœ์ง ๊ฐœ์„ ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค

ํƒ€์ด๋จธ ๊ด€๋ จ ์ƒ์ˆ˜๋ฅผ ์ •์˜ํ•˜๊ณ  cleanup ๋กœ์ง์„ ๋ณด์™„ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•˜๋Š” ๊ฒƒ์„ ์ œ์•ˆ๋“œ๋ฆฝ๋‹ˆ๋‹ค:

+ const TIMER_ENDED = 0;
+ 
  useEffect(() => {
    if (timer > 0) {
      const intervalId = setInterval(() => {
        setTimer((prev) => prev - 1);
      }, 1000);

      return () => clearInterval(intervalId);
-    } else if (timer === 0) {
+    } else if (timer === TIMER_ENDED) {
      setIsSmsSent(false);
    }
+    
+    return () => {
+      setIsSmsSent(false);
+    };
  }, [timer, setTimer, setIsSmsSent]);
๐Ÿ“ Committable suggestion

โ€ผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if (timer === 0) {
setIsSmsSent(false);
}
}, [timer, setTimer]);
}, [timer, setTimer, setIsSmsSent]);
const TIMER_ENDED = 0;
useEffect(() => {
if (timer > 0) {
const intervalId = setInterval(() => {
setTimer((prev) => prev - 1);
}, 1000);
return () => clearInterval(intervalId);
} else if (timer === TIMER_ENDED) {
setIsSmsSent(false);
}
return () => {
setIsSmsSent(false);
};
}, [timer, setTimer, setIsSmsSent]);

@Ethen1264 Ethen1264 changed the title ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ ๋ฆฌํŒฉํ† ๋ง ์ง„ํ–‰ ๐Ÿ”€ ํšŒ์›๊ฐ€์ž… ํŽ˜์ด์ง€ ๋ฆฌํŒฉํ† ๋ง ์ง„ํ–‰ Dec 18, 2024
@Ethen1264 Ethen1264 merged commit 387251d into develop Dec 18, 2024
2 checks passed
@Ethen1264 Ethen1264 deleted the refector/signup branch December 23, 2024 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
๐Ÿž Bug ๋ฒ„๊ทธ ๋ฐœ์ƒ โšก๏ธperformance ์„ฑ๋Šฅ ๊ฐœ์„  ๐Ÿ“ฌ Type: API ์„œ๋ฒ„ API ํ†ต์‹ 
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants