Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 10 additions & 5 deletions apps/client/src/shared/apis/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@ export const getAcorns = async () => {
};

export interface postSignUpRequest {
email: string,
remindDefault: string,
fcmToken: string
email: string;
remindDefault: string;
fcmToken: string;
}

export const postSignUp = async (responsedata: postSignUpRequest) => {
const {data} = await apiRequest.post('/api/v1/auth/signup', responsedata);
const { data } = await apiRequest.post('/api/v1/auth/signup', responsedata);
return data;
};
};

export const deleteCategory = async (id: number) => {
const response = await apiRequest.delete(`/api/v1/categories/${id}`);
return response;
};
7 changes: 7 additions & 0 deletions apps/client/src/shared/apis/queries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
import {
deleteCategory,
getDashboardCategories,
postCategory,
postSignUp,
Expand Down Expand Up @@ -32,6 +33,12 @@ export const usePutCategory = () => {
});
};

export const useDeleteCategory = () => {
return useMutation({
mutationFn: (id: number) => deleteCategory(id),
});
};

export const useGetArcons = (): UseQueryResult<AcornsResponse, AxiosError> => {
return useQuery({
queryKey: ['arcons'],
Expand Down
19 changes: 15 additions & 4 deletions apps/client/src/shared/components/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
usePostCategory,
useGetArcons,
usePutCategory,
useDeleteCategory,
} from '@shared/apis/queries';
import { useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';
Expand All @@ -27,6 +28,7 @@ export function Sidebar() {
const { mutate: patchCategory } = usePutCategory();
const { mutate: createCategory } = usePostCategory();
const { data, isPending, isError } = useGetArcons();
const { mutate: deleteCategory } = useDeleteCategory();

const {
activeTab,
Expand Down Expand Up @@ -82,6 +84,18 @@ export function Sidebar() {
);
};

const handleDeleteCategory = (id: number) => {
deleteCategory(id, {
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['dashboardCategories'] });
close();
},
onError: (error) => {
console.error('카테고리 삭제 실패:', error);
},
});
};
Comment on lines +87 to +97
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 handleDeleteCategory = (id: number) => {
-    deleteCategory(id, {
+  const handleDeleteCategory = (id: number) => {
+    const name = getCategoryName(id);
+    if (name === '안 읽은 정보') {
+      console.warn('기본 카테고리는 삭제할 수 없습니다.');
+      return;
+    }
+    mutateDeleteCategory(id, {
       onSuccess: () => {
+        if (selectedCategoryId === id) {
+          setSelectedCategoryId(null);
+        }
         queryClient.invalidateQueries({ queryKey: ['dashboardCategories'] });
         close();
       },
       onError: (error) => {
         console.error('카테고리 삭제 실패:', error);
       },
     });
   };

옵션 메뉴에서 기본 카테고리에는 "삭제" 버튼 자체를 숨기는 UX 보완도 가능합니다. 원하시면 OptionsMenuPortal 조건 분기 패치 제안 드리겠습니다.

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

🤖 Prompt for AI Agents
In apps/client/src/shared/components/sidebar/Sidebar.tsx around lines 87–97,
prevent deletion of the default "안 읽은 정보" category and clear selection if the
deleted category was selected: before calling deleteCategory, check whether the
target category is the default (compare id to the known defaultCategoryId or
category.isDefault flag) and bail out (or show a user-facing message) instead of
invoking delete; after successful deletion, if the app's current
selectedCategoryId equals the deleted id, call the selection reset handler
(e.g., setSelectedCategory(null) or selectDefaultCategory()) before calling
close() and invalidating queries; optionally, also hide the "Delete" option in
the OptionsMenuPortal for default categories by adding the same conditional
around the button render.


if (isPending) return <div></div>;
if (isError) return <div></div>;
const acornCount = data.acornCount;
Expand Down Expand Up @@ -172,10 +186,7 @@ export function Sidebar() {
onChange={handleCategoryChange}
onCreateConfirm={handleCreateCategory}
onEditConfirm={(id) => handlePatchCategory(id)}
onDeleteConfirm={() => {
// TODO: 삭제 API
close();
}}
onDeleteConfirm={(id) => handleDeleteCategory(id)}
/>
</aside>
);
Expand Down
Loading