-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
์ํฌ์ค๋ฃจ์ด ํ ๋ฆฌํ์คํธ๋ ๊ด๋ฆฌ์ ๊ณ์ ์ญ์ ๊ธฐ๋ฅ์ ์ถ๊ฐํฉ๋๋ค. ์๋ก์ด API ์๋ํฌ์ธํธ, ์ฌ์ฉ์ ๊ณ์ ์ญ์ ๋ฅผ ์ํ API ํจ์, React ํ , ๊ทธ๋ฆฌ๊ณ ๊ด๋ฆฌ์ ํ๋กํ ์ปดํฌ๋ํธ๊ฐ ์์ ๋์์ต๋๋ค. ์ด ๋ณ๊ฒฝ์ฌํญ์ ์ฌ์ฉ์๊ฐ ์์ ์ ๊ณ์ ์ ์ญ์ ํ ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ฉฐ, ๋ก๊ทธ์์ ํ๋ก์ธ์ค๋ฅผ ๋์ฑ ์ธํฐ๋ํฐ๋ธํ๊ณ ์กฐ์ง์ ์ผ๋ก ๋ง๋ญ๋๋ค. ๋ณ๊ฒฝ ์ฌํญ
์ํ์ค ๋ค์ด์ด๊ทธ๋จ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
๊ด๋ จ ๊ฐ๋ฅ์ฑ ์๋ PR
์ ์๋ ๋ฆฌ๋ทฐ์ด
ํ ๋ผ์ ์
Finishing Touches
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? ๐ชง TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
: ์ฌ์ฉ์ ๊ฒฝํ ๊ฐ์ ์ด ํ์ํฉ๋๋ค.๋ค์ ์ฌํญ๋ค์ ๊ณ ๋ คํด์ฃผ์ธ์:
- ๋ก๋ฉ ์ํ ์ฒ๋ฆฌ๊ฐ ํ์ํฉ๋๋ค
- ๊ณ์ ์ญ์ ์ ์ฌ์ฉ์ ํ์ธ์ด ํ์ํฉ๋๋ค
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
๐ 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)
export const deleteUserAccount = async () => { | ||
const response = await axios.delete('/api/admin'); | ||
return response; | ||
}; |
There was a problem hiding this comment.
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.
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; | |
}; |
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 }); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ณด์ ๋ฐ ์๋ฌ ์ฒ๋ฆฌ ๊ฐ์ ์ด ํ์ํฉ๋๋ค.
๋ค์๊ณผ ๊ฐ์ ์ค์ํ ๋ณด์ ๋ฐ ์๋ฌ ์ฒ๋ฆฌ ์ด์๊ฐ ์์ต๋๋ค:
- catch ๋ธ๋ก์์ ๊ธฐ๋ณธ ์๋ต์ด ์์ต๋๋ค
- ์ฟ ํค ๋ณด์ ์ค์ ์ด ๋๋ฝ๋์์ต๋๋ค
- ์๋ฌ ์๋ต ํ์ ์ด ์ ์๋์ง ์์์ต๋๋ค
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.
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 } | |
); | |
} | |
} |
<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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ ๏ธ Refactor suggestion
์ ๊ทผ์ฑ ๋ฐ ์ฌ์ฉ์ ๊ฒฝํ ๊ฐ์ ์ด ํ์ํฉ๋๋ค.
๋ค์๊ณผ ๊ฐ์ ๊ฐ์ ์ฌํญ์ด ํ์ํฉ๋๋ค:
- ๋ฒํผ์ aria-label ์ถ๊ฐ
- ์ธ๋ถ ํด๋ฆญ ์ ๋ฉ๋ด ๋ซ๊ธฐ
- ํ๋์ฝ๋ฉ๋ ๊ฐ๋ค์ 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;
}
<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> |
There was a problem hiding this comment.
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.
<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> |
๐ก ๋ฐฐ๊ฒฝ ๋ฐ ๊ฐ์
์ ์ ํํด ๊ธฐ๋ฅ ์ ์
๐ ์์ ๋ด์ฉ
Summary by CodeRabbit
์๋ก์ด ๊ธฐ๋ฅ
๊ฐ์ ์ฌํญ
๋ฒ๊ทธ ์์