Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion frontend/src/components/Button/LogoutButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,45 @@
import { useState } from 'react';

import useLogoutMutation from './hooks/useLogoutMutation';
import * as S from './LogoutButton.styled';

import { useDrawer } from '@/components/Drawer/hooks/useDrawer';
import HomeModal from '@/pages/PlanPage/components/HomeModal';
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider relocating the modal to a shared components directory.

Importing HomeModal from a page-specific directory (@/pages/PlanPage/components/HomeModal) into a generic button component creates tight coupling and violates component isolation principles. This makes the LogoutButton dependent on PlanPage components, which could lead to maintainability issues.

Consider one of these solutions:

  1. Move HomeModal to a shared components directory (e.g., @/components/Modal/HomeModal)
  2. Create a generic confirmation modal component specifically for logout actions
  3. Use a global modal context or state management solution
-import HomeModal from '@/pages/PlanPage/components/HomeModal';
+import ConfirmationModal from '@/components/Modal/ConfirmationModal';
📝 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
import HomeModal from '@/pages/PlanPage/components/HomeModal';
// frontend/src/components/Button/LogoutButton/index.tsx
import React, { useState } from 'react';
import { useLogoutMutation } from '@/hooks/useLogoutMutation';
import { useDrawer } from '@/hooks/useDrawer';
-import HomeModal from '@/pages/PlanPage/components/HomeModal';
+import ConfirmationModal from '@/components/Modal/ConfirmationModal';
// …rest of the component…
🤖 Prompt for AI Agents
In frontend/src/components/Button/LogoutButton/index.tsx at line 7, the import
of HomeModal from a page-specific directory creates tight coupling and breaks
component isolation. To fix this, move HomeModal to a shared components
directory such as @/components/Modal/HomeModal, or alternatively create a
generic confirmation modal for logout actions, or implement a global modal
context/state management to handle modals more cleanly and decouple LogoutButton
from PlanPage components.


const LogoutButton = () => {
const [isModalOpen, setIsModalOpen] = useState(false);
const { logoutMutation } = useLogoutMutation();
const { closeDrawer } = useDrawer();

const handleLogoutClick = () => {
closeDrawer();
setIsModalOpen(true);
};

const handleConfirmLogout = () => {
logoutMutation();
setIsModalOpen(false);
};
Comment on lines +19 to +22
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider improving error handling and operation order.

The current implementation calls logoutMutation() before closing the modal, which could lead to UI inconsistencies if the logout fails. Consider handling the logout result or reordering operations.

 const handleConfirmLogout = () => {
-  logoutMutation();
-  setIsModalOpen(false);
+  setIsModalOpen(false);
+  logoutMutation();
 };

Or better yet, handle the logout result:

 const handleConfirmLogout = async () => {
+  try {
+    await logoutMutation();
     setIsModalOpen(false);
+  } catch (error) {
+    // Handle logout error - maybe show error message
+    console.error('Logout failed:', 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
const handleConfirmLogout = () => {
logoutMutation();
setIsModalOpen(false);
};
// Before:
// const handleConfirmLogout = () => {
// logoutMutation();
// setIsModalOpen(false);
// };
// Improved: handle the logout result and only close the modal on success
const handleConfirmLogout = async () => {
try {
await logoutMutation();
setIsModalOpen(false);
} catch (error) {
// Handle logout error - maybe show an error message to the user
console.error('Logout failed:', error);
}
};
🤖 Prompt for AI Agents
In frontend/src/components/Button/LogoutButton/index.tsx around lines 19 to 22,
the logoutMutation is called before closing the modal, which may cause UI
inconsistencies if logout fails. Refactor handleConfirmLogout to await the
logoutMutation call and only close the modal if the logout succeeds.
Additionally, add error handling to manage any logout failures gracefully
without closing the modal prematurely.


const handleCloseModal = () => {
setIsModalOpen(false);
};

return (
<>
<S.LogoutButton onClick={handleLogoutClick}>로그아웃</S.LogoutButton>

return <S.LogoutButton onClick={() => logoutMutation()}>로그아웃</S.LogoutButton>;
{isModalOpen && (
<HomeModal
title="로그아웃"
content={['정말로 로그아웃 하시겠습니까?']}
close={handleCloseModal}
onConfirm={handleConfirmLogout}
confirmText="로그아웃"
/>
)}
</>
);
};

export default LogoutButton;