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

๐Ÿ”€ ์œ ์ € ํƒˆํ‡ด ๊ธฐ๋Šฅ ์ œ์ž‘ #76

Merged
merged 3 commits into from
Jan 16, 2025

Conversation

Ethen1264
Copy link
Contributor

@Ethen1264 Ethen1264 commented Jan 15, 2025

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

์œ ์ € ํƒˆํ‡ด ๊ธฐ๋Šฅ ์ œ์ž‘

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

  • ์œ ์ € ํƒˆํ‡ด ๊ธฐ๋Šฅ ์ œ์ž‘
  • ๋ผ์šฐํŠธ ts์ œ์ž‘
  • tanstack query mutation ์ œ์ž‘
  • ๋กœ๊ทธ์•„์›ƒ๊ณผ ํƒˆํ‡ด๋ฅผ ๋ชจ๋‹ฌ ํ˜•ํƒœ๋กœ ๋ณ€๊ฒฝ

Summary by CodeRabbit

  • ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ

    • ๊ด€๋ฆฌ์ž ๊ณ„์ • ์‚ญ์ œ ๊ธฐ๋Šฅ ์ถ”๊ฐ€
    • ๋กœ๊ทธ์•„์›ƒ ์˜ต์…˜ ๋ฉ”๋‰ด์— ๊ณ„์ • ์‚ญ์ œ ๋ฒ„ํŠผ ๋„์ž…
  • ๊ฐœ์„  ์‚ฌํ•ญ

    • ๋กœ๊ทธ์•„์›ƒ ํ”„๋กœ์„ธ์Šค ๊ฐœ์„ 
    • ์‚ฌ์šฉ์ž ์ƒํ˜ธ์ž‘์šฉ ๋ฐ ์ ‘๊ทผ์„ฑ ํ–ฅ์ƒ
  • ๋ฒ„๊ทธ ์ˆ˜์ •

    • ํ† ํฐ ๊ด€๋ฆฌ ๋ฐ ์ฟ ํ‚ค ์ฒ˜๋ฆฌ ๋กœ์ง ๊ฐ•ํ™”

@Ethen1264 Ethen1264 added the โœจ Feature ์‹ ๊ทœ ๊ธฐ๋Šฅ label Jan 15, 2025
@Ethen1264 Ethen1264 self-assigned this Jan 15, 2025
Copy link

coderabbitai bot commented Jan 15, 2025

์›Œํฌ์Šค๋ฃจ

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

๋ณ€๊ฒฝ ์‚ฌํ•ญ

ํŒŒ์ผ ๋ณ€๊ฒฝ ์š”์•ฝ
src/app/api/admin/route.ts ๊ณ„์ • ์‚ญ์ œ๋ฅผ ์œ„ํ•œ ์ƒˆ๋กœ์šด DELETE ํ•จ์ˆ˜ ์ถ”๊ฐ€
src/entities/admin/api/deleteUserAccount.ts ๊ณ„์ • ์‚ญ์ œ API ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ์ƒˆ๋กœ์šด ํ•จ์ˆ˜ ์ถ”๊ฐ€
src/entities/admin/model/useDeleteUserAccount.ts ๊ณ„์ • ์‚ญ์ œ๋ฅผ ์œ„ํ•œ ์ƒˆ๋กœ์šด React ํ›… ์ƒ์„ฑ
src/entities/admin/ui/AdminProfile/index.tsx ๊ณ„์ • ์‚ญ์ œ ์˜ต์…˜์„ ํฌํ•จํ•œ ๋กœ๊ทธ์•„์›ƒ ๋ฉ”๋‰ด ์—…๋ฐ์ดํŠธ

์‹œํ€€์Šค ๋‹ค์ด์–ด๊ทธ๋žจ

sequenceDiagram
    participant User
    participant AdminProfile
    participant DeleteUserAccountHook
    participant API
    
    User->>AdminProfile: ๊ณ„์ • ์‚ญ์ œ ๋ฒ„ํŠผ ํด๋ฆญ
    AdminProfile->>DeleteUserAccountHook: deleteAccount() ํ˜ธ์ถœ
    DeleteUserAccountHook->>API: DELETE ์š”์ฒญ ์ „์†ก
    API-->>DeleteUserAccountHook: ์‘๋‹ต ์ˆ˜์‹ 
    alt ์‚ญ์ œ ์„ฑ๊ณต
        DeleteUserAccountHook->>User: ์„ฑ๊ณต ํ† ์ŠคํŠธ ํ‘œ์‹œ
        DeleteUserAccountHook->>User: ํ™ˆํŽ˜์ด์ง€๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ
    else ์‚ญ์ œ ์‹คํŒจ
        DeleteUserAccountHook->>User: ์—๋Ÿฌ ํ† ์ŠคํŠธ ํ‘œ์‹œ
    end
Loading

๊ด€๋ จ ๊ฐ€๋Šฅ์„ฑ ์žˆ๋Š” PR

์ œ์•ˆ๋œ ๋ฆฌ๋ทฐ์–ด

  • happytaeyoon

ํ† ๋ผ์˜ ์‹œ

๐Ÿฐ ๊ณ„์ • ์‚ญ์ œ, ์ƒˆ๋กœ์šด ์‹œ์ž‘
๋ฒ„ํŠผ ํ•˜๋‚˜๋กœ ๋ชจ๋“  ๊ฒƒ ์ •๋ฆฌ
์ž์œ ๋กœ์›€์„ ๋Š๋ผ๋ฉฐ
ํ† ๋ผ์ฒ˜๋Ÿผ ๊น”๋”ํ•˜๊ฒŒ
์ƒˆ ํŽ˜์ด์ง€๋กœ ๋„์•ฝ! ๐Ÿš€

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

๐Ÿงน Nitpick comments (1)
src/entities/admin/model/useDeleteUserAccount.ts (1)

6-19: ์‚ฌ์šฉ์ž ๊ฒฝํ—˜ ๊ฐœ์„ ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ์‚ฌํ•ญ๋“ค์„ ๊ณ ๋ คํ•ด์ฃผ์„ธ์š”:

  1. ๋กœ๋”ฉ ์ƒํƒœ ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค
  2. ๊ณ„์ • ์‚ญ์ œ ์ „ ์‚ฌ์šฉ์ž ํ™•์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค
 export const useDeleteUserAccount = () => {
   const router = useRouter();
+  const [isConfirmed, setIsConfirmed] = useState(false);
 
   return useMutation({
-    mutationFn: () => deleteUserAccount(),
+    mutationFn: async () => {
+      if (!isConfirmed) {
+        const userConfirmed = window.confirm('์ •๋ง๋กœ ๊ณ„์ •์„ ์‚ญ์ œํ•˜์‹œ๊ฒ ์Šต๋‹ˆ๊นŒ? ์ด ์ž‘์—…์€ ๋˜๋Œ๋ฆด ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.');
+        if (!userConfirmed) {
+          throw new Error('User cancelled');
+        }
+        setIsConfirmed(true);
+      }
+      return deleteUserAccount();
+    },
     onSuccess: () => {
       toast.success('ํƒˆํ‡ด๊ฐ€ ์™„๋ฃŒ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.');
       router.push('/');
     },
     onError: () => {
+      setIsConfirmed(false);
       toast.error('์œ ์ € ํƒˆํ‡ด๋ฅผ ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.');
     },
   });
 };
๐Ÿ“œ Review details

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

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 8396a3d and 60177cc.

๐Ÿ“’ Files selected for processing (4)
  • src/app/api/admin/route.ts (1 hunks)
  • src/entities/admin/api/deleteUserAccount.ts (1 hunks)
  • src/entities/admin/model/useDeleteUserAccount.ts (1 hunks)
  • src/entities/admin/ui/AdminProfile/index.tsx (2 hunks)

Comment on lines +3 to +6
export const deleteUserAccount = async () => {
const response = await axios.delete('/api/admin');
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

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

์‘๋‹ต ๋ฐ ์—๋Ÿฌ ์ฒ˜๋ฆฌ๊ฐ€ ์ƒ์œ„ ์ปดํฌ๋„ŒํŠธ๋กœ ์œ„์ž„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฐœ์„ ์‚ฌํ•ญ์„ ์ œ์•ˆ๋“œ๋ฆฝ๋‹ˆ๋‹ค:

+import { AxiosResponse } from 'axios';
+
+interface DeleteAccountResponse {
+  success: boolean;
+  message?: string;
+}
+
-export const deleteUserAccount = async () => {
+export const deleteUserAccount = async (): Promise<AxiosResponse<DeleteAccountResponse>> => {
   const response = await axios.delete('/api/admin');
   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
export const deleteUserAccount = async () => {
const response = await axios.delete('/api/admin');
return response;
};
import { AxiosResponse } from 'axios';
interface DeleteAccountResponse {
success: boolean;
message?: string;
}
export const deleteUserAccount = async (): Promise<AxiosResponse<DeleteAccountResponse>> => {
const response = await axios.delete('/api/admin');
return response;
};

Comment on lines +28 to +58
export async function DELETE() {
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;

if (!accessToken) {
return NextResponse.json(
{ error: 'Access token not found' },
{ status: 401 },
);
}

try {
await apiClient.delete('/admin', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});

const response = NextResponse.json({ success: true });
response.cookies.set('accessToken', '', { maxAge: 0 });
response.cookies.set('refreshToken', '', { maxAge: 0 });
return response;
} catch (error) {
if (error instanceof AxiosError) {
const status = error.response?.status || 500;
const message =
error.response?.data?.message || 'delete user account failed';
return NextResponse.json({ error: message }, { status });
}
}
}
Copy link

Choose a reason for hiding this comment

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

โš ๏ธ Potential issue

๋ณด์•ˆ ๋ฐ ์—๋Ÿฌ ์ฒ˜๋ฆฌ ๊ฐœ์„ ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ค‘์š”ํ•œ ๋ณด์•ˆ ๋ฐ ์—๋Ÿฌ ์ฒ˜๋ฆฌ ์ด์Šˆ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค:

  1. catch ๋ธ”๋ก์—์„œ ๊ธฐ๋ณธ ์‘๋‹ต์ด ์—†์Šต๋‹ˆ๋‹ค
  2. ์ฟ ํ‚ค ๋ณด์•ˆ ์„ค์ •์ด ๋ˆ„๋ฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค
  3. ์—๋Ÿฌ ์‘๋‹ต ํƒ€์ž…์ด ์ •์˜๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค
 export async function DELETE() {
   const cookieStore = cookies();
   const accessToken = cookieStore.get('accessToken')?.value;
 
   if (!accessToken) {
     return NextResponse.json(
       { error: 'Access token not found' },
       { status: 401 },
     );
   }
 
   try {
     await apiClient.delete('/admin', {
       headers: {
         Authorization: `Bearer ${accessToken}`,
       },
     });
 
     const response = NextResponse.json({ success: true });
-    response.cookies.set('accessToken', '', { maxAge: 0 });
-    response.cookies.set('refreshToken', '', { maxAge: 0 });
+    response.cookies.set('accessToken', '', {
+      maxAge: 0,
+      httpOnly: true,
+      secure: process.env.NODE_ENV === 'production',
+      sameSite: 'strict'
+    });
+    response.cookies.set('refreshToken', '', {
+      maxAge: 0,
+      httpOnly: true,
+      secure: process.env.NODE_ENV === 'production',
+      sameSite: 'strict'
+    });
     return response;
   } catch (error) {
     if (error instanceof AxiosError) {
       const status = error.response?.status || 500;
       const message =
         error.response?.data?.message || 'delete user account failed';
       return NextResponse.json({ error: message }, { status });
     }
+    return NextResponse.json(
+      { error: '์•Œ ์ˆ˜ ์—†๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.' },
+      { status: 500 }
+    );
   }
 }
๐Ÿ“ 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 async function DELETE() {
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;
if (!accessToken) {
return NextResponse.json(
{ error: 'Access token not found' },
{ status: 401 },
);
}
try {
await apiClient.delete('/admin', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const response = NextResponse.json({ success: true });
response.cookies.set('accessToken', '', { maxAge: 0 });
response.cookies.set('refreshToken', '', { maxAge: 0 });
return response;
} catch (error) {
if (error instanceof AxiosError) {
const status = error.response?.status || 500;
const message =
error.response?.data?.message || 'delete user account failed';
return NextResponse.json({ error: message }, { status });
}
}
}
export async function DELETE() {
const cookieStore = cookies();
const accessToken = cookieStore.get('accessToken')?.value;
if (!accessToken) {
return NextResponse.json(
{ error: 'Access token not found' },
{ status: 401 },
);
}
try {
await apiClient.delete('/admin', {
headers: {
Authorization: `Bearer ${accessToken}`,
},
});
const response = NextResponse.json({ success: true });
response.cookies.set('accessToken', '', {
maxAge: 0,
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'strict'
});
response.cookies.set('refreshToken', '', {
maxAge: 0,
httpOnly: true,
secure: process.env.NODE_ENV === 'production',
sameSite: 'strict'
});
return response;
} catch (error) {
if (error instanceof AxiosError) {
const status = error.response?.status || 500;
const message =
error.response?.data?.message || 'delete user account failed';
return NextResponse.json({ error: message }, { status });
}
return NextResponse.json(
{ error: '์•Œ ์ˆ˜ ์—†๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค.' },
{ status: 500 }
);
}
}

Comment on lines +31 to +51
<div>
<button onClick={handleLogoutClick}>
<Logout />
</button>
{isToggleLogout && (
<div className="absolute right-0 top-[30px] flex h-fit flex-col gap-2 rounded-[6px] border border-gray-200 bg-white p-2 shadow-[0px_4px_4px_0px_rgba(0,_0,_0,_0.25)]">
<button
onClick={() => logout()}
className="w-full rounded-[6px] px-5 py-2 text-body2 text-gray-500 hover:bg-error hover:text-white"
>
๋กœ๊ทธ์•„์›ƒ
</button>
<button
onClick={() => deleteAccount()}
className="w-full rounded-[6px] px-5 py-2 text-body2 text-gray-500 hover:bg-error hover:text-white"
>
ํšŒ์›ํƒˆํ‡ด
</button>
</div>
)}
</div>
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-label ์ถ”๊ฐ€
  2. ์™ธ๋ถ€ ํด๋ฆญ ์‹œ ๋ฉ”๋‰ด ๋‹ซ๊ธฐ
  3. ํ•˜๋“œ์ฝ”๋”ฉ๋œ ๊ฐ’๋“ค์„ props๋กœ ๋ณ€๊ฒฝ
-      <div>
+      <div className="relative">
+        <button
+          onClick={handleLogoutClick}
+          aria-label="๋กœ๊ทธ์•„์›ƒ ๋ฉ”๋‰ด ์—ด๊ธฐ"
+          aria-expanded={isToggleLogout}
+        >
-          <Logout />
+          <Logout aria-hidden="true" />
+        </button>
         {isToggleLogout && (
           <div className="absolute right-0 top-[30px] flex h-fit flex-col gap-2 rounded-[6px] border border-gray-200 bg-white p-2 shadow-[0px_4px_4px_0px_rgba(0,_0,_0,_0.25)]">
             <button
               onClick={() => logout()}
+              aria-label="๋กœ๊ทธ์•„์›ƒ"
               className="w-full rounded-[6px] px-5 py-2 text-body2 text-gray-500 hover:bg-error hover:text-white"
             >
               ๋กœ๊ทธ์•„์›ƒ
             </button>
             <button
               onClick={() => deleteAccount()}
+              aria-label="ํšŒ์›ํƒˆํ‡ด"
               className="w-full rounded-[6px] px-5 py-2 text-body2 text-gray-500 hover:bg-error hover:text-white"
             >
               ํšŒ์›ํƒˆํ‡ด
             </button>
           </div>
         )}
       </div>

์ถ”๊ฐ€๋กœ ์™ธ๋ถ€ ํด๋ฆญ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ์ปค์Šคํ…€ ํ›…์„ ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœ๋“œ๋ฆฝ๋‹ˆ๋‹ค:

import { useEffect, useRef } from 'react';

function useOutsideClick(callback: () => void) {
  const ref = useRef<HTMLDivElement>(null);

  useEffect(() => {
    function handleClickOutside(event: MouseEvent) {
      if (ref.current && !ref.current.contains(event.target as Node)) {
        callback();
      }
    }
    document.addEventListener('mousedown', handleClickOutside);
    return () => {
      document.removeEventListener('mousedown', handleClickOutside);
    };
  }, [callback]);

  return ref;
}

Comment on lines +23 to 30
<div className="relative flex w-full justify-between">
<div className="flex items-center gap-[124px] mobile:flex-col mobile:gap-[30px]">
<div className="space-y-[32px]">
<ProfileInfo label="์ด๋ฆ„" value="๊น€์ง„์›" />
<ProfileInfo label="์•„์ด๋””" value="jin1234" />
<ProfileInfo label="์ด๋ฉ”์ผ" value="[email protected]" />
</div>
</div>
Copy link

Choose a reason for hiding this comment

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

๐Ÿ› ๏ธ Refactor suggestion

ํ•˜๋“œ์ฝ”๋”ฉ๋œ ์‚ฌ์šฉ์ž ์ •๋ณด๋ฅผ props๋กœ ๋ณ€๊ฒฝํ•ด์ฃผ์„ธ์š”.

์ปดํฌ๋„ŒํŠธ์˜ ์žฌ์‚ฌ์šฉ์„ฑ์„ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณ€๊ฒฝ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค:

-const AdminProfile = () => {
+interface AdminProfileProps {
+  name: string;
+  username: string;
+  email: string;
+}
+
+const AdminProfile = ({ name, username, email }: AdminProfileProps) => {
   const { mutate: logout } = useLogout();
   const { mutate: deleteAccount } = useDeleteUserAccount();
   const [isToggleLogout, setIsToggleLogout] = useState(false);

   return (
     <div className="relative flex w-full justify-between">
       <div className="flex items-center gap-[124px] mobile:flex-col mobile:gap-[30px]">
         <div className="space-y-[32px]">
-          <ProfileInfo label="์ด๋ฆ„" value="๊น€์ง„์›" />
-          <ProfileInfo label="์•„์ด๋””" value="jin1234" />
-          <ProfileInfo label="์ด๋ฉ”์ผ" value="[email protected]" />
+          <ProfileInfo label="์ด๋ฆ„" value={name} />
+          <ProfileInfo label="์•„์ด๋””" value={username} />
+          <ProfileInfo label="์ด๋ฉ”์ผ" value={email} />
         </div>
       </div>
๐Ÿ“ 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
<div className="relative flex w-full justify-between">
<div className="flex items-center gap-[124px] mobile:flex-col mobile:gap-[30px]">
<div className="space-y-[32px]">
<ProfileInfo label="์ด๋ฆ„" value="๊น€์ง„์›" />
<ProfileInfo label="์•„์ด๋””" value="jin1234" />
<ProfileInfo label="์ด๋ฉ”์ผ" value="[email protected]" />
</div>
</div>
interface AdminProfileProps {
name: string;
username: string;
email: string;
}
const AdminProfile = ({ name, username, email }: AdminProfileProps) => {
<div className="relative flex w-full justify-between">
<div className="flex items-center gap-[124px] mobile:flex-col mobile:gap-[30px]">
<div className="space-y-[32px]">
<ProfileInfo label="์ด๋ฆ„" value={name} />
<ProfileInfo label="์•„์ด๋””" value={username} />
<ProfileInfo label="์ด๋ฉ”์ผ" value={email} />
</div>
</div>

@Ethen1264 Ethen1264 merged commit 483d192 into develop Jan 16, 2025
2 checks passed
@Ethen1264 Ethen1264 deleted the feature/delete-user-account branch January 23, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
โœจ Feature ์‹ ๊ทœ ๊ธฐ๋Šฅ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants