Skip to content

Commit 9709082

Browse files
authored
feat: DeleteCategory 연결 (#92)
1 parent 23bd2df commit 9709082

File tree

3 files changed

+32
-9
lines changed

3 files changed

+32
-9
lines changed

apps/client/src/shared/apis/axios.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,17 @@ export const getAcorns = async () => {
2929
};
3030

3131
export interface postSignUpRequest {
32-
email: string,
33-
remindDefault: string,
34-
fcmToken: string
32+
email: string;
33+
remindDefault: string;
34+
fcmToken: string;
3535
}
3636

3737
export const postSignUp = async (responsedata: postSignUpRequest) => {
38-
const {data} = await apiRequest.post('/api/v1/auth/signup', responsedata);
38+
const { data } = await apiRequest.post('/api/v1/auth/signup', responsedata);
3939
return data;
40-
};
40+
};
41+
42+
export const deleteCategory = async (id: number) => {
43+
const response = await apiRequest.delete(`/api/v1/categories/${id}`);
44+
return response;
45+
};

apps/client/src/shared/apis/queries.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useMutation, useQuery, UseQueryResult } from '@tanstack/react-query';
22
import {
3+
deleteCategory,
34
getDashboardCategories,
45
postCategory,
56
postSignUp,
@@ -32,6 +33,12 @@ export const usePutCategory = () => {
3233
});
3334
};
3435

36+
export const useDeleteCategory = () => {
37+
return useMutation({
38+
mutationFn: (id: number) => deleteCategory(id),
39+
});
40+
};
41+
3542
export const useGetArcons = (): UseQueryResult<AcornsResponse, AxiosError> => {
3643
return useQuery({
3744
queryKey: ['arcons'],

apps/client/src/shared/components/sidebar/Sidebar.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
usePostCategory,
1616
useGetArcons,
1717
usePutCategory,
18+
useDeleteCategory,
1819
} from '@shared/apis/queries';
1920
import { useState } from 'react';
2021
import { useQueryClient } from '@tanstack/react-query';
@@ -27,6 +28,7 @@ export function Sidebar() {
2728
const { mutate: patchCategory } = usePutCategory();
2829
const { mutate: createCategory } = usePostCategory();
2930
const { data, isPending, isError } = useGetArcons();
31+
const { mutate: deleteCategory } = useDeleteCategory();
3032

3133
const {
3234
activeTab,
@@ -82,6 +84,18 @@ export function Sidebar() {
8284
);
8385
};
8486

87+
const handleDeleteCategory = (id: number) => {
88+
deleteCategory(id, {
89+
onSuccess: () => {
90+
queryClient.invalidateQueries({ queryKey: ['dashboardCategories'] });
91+
close();
92+
},
93+
onError: (error) => {
94+
console.error('카테고리 삭제 실패:', error);
95+
},
96+
});
97+
};
98+
8599
if (isPending) return <div></div>;
86100
if (isError) return <div></div>;
87101
const acornCount = data.acornCount;
@@ -172,10 +186,7 @@ export function Sidebar() {
172186
onChange={handleCategoryChange}
173187
onCreateConfirm={handleCreateCategory}
174188
onEditConfirm={(id) => handlePatchCategory(id)}
175-
onDeleteConfirm={() => {
176-
// TODO: 삭제 API
177-
close();
178-
}}
189+
onDeleteConfirm={(id) => handleDeleteCategory(id)}
179190
/>
180191
</aside>
181192
);

0 commit comments

Comments
 (0)