From 493781a3e67aefbf95e1fec83e875a33eb8b24ec Mon Sep 17 00:00:00 2001 From: LeeJaein Date: Fri, 1 May 2026 18:33:24 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor(#243):=20trash=C2=B7user=20?= =?UTF-8?q?=EB=8F=84=EB=A9=94=EC=9D=B8=EC=9D=84=20FSD=20=EA=B5=AC=EC=A1=B0?= =?UTF-8?q?=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/auth/api/myInfo.api.ts | 9 +++++---- src/entities/auth/types/auth.type.ts | 6 ++++++ src/{features => entities}/trash/api/trash.api.ts | 0 .../trash => entities/trash/query}/trash.queryKey.ts | 5 ++--- src/{features => entities}/trash/types/trash.types.ts | 0 .../useDeleteTrashMutation/useDeleteTrashMutation.ts | 4 ++-- .../useRestoreTrashMutation/useRestoreTrashMutation.ts | 4 ++-- .../hooks/useDeleteMeMutation/useDeleteMeMutation.ts | 3 +-- src/widgets/trash/PersonalTrash/PersonalTrash.tsx | 2 +- src/widgets/trash/TeamTrash/TeamTrash.tsx | 2 +- src/widgets/trash/TrashItem/TrashItem.tsx | 2 +- src/widgets/trash/TrashList/TrashList.tsx | 2 +- 12 files changed, 22 insertions(+), 17 deletions(-) rename src/{features => entities}/trash/api/trash.api.ts (100%) rename src/{features/trash => entities/trash/query}/trash.queryKey.ts (90%) rename src/{features => entities}/trash/types/trash.types.ts (100%) diff --git a/src/entities/auth/api/myInfo.api.ts b/src/entities/auth/api/myInfo.api.ts index 09f74ebf..4ed68a4b 100644 --- a/src/entities/auth/api/myInfo.api.ts +++ b/src/entities/auth/api/myInfo.api.ts @@ -1,9 +1,10 @@ -import { UserProfile } from "@/entities/auth/types/auth.type"; +import { + UpdateProfileRequest, + UserProfile, +} from "@/entities/auth/types/auth.type"; import { apiClient } from "@/shared/lib/api/client"; import { ApiResponse } from "@/shared/lib/api/types"; -import { MyProfileFormData } from "../../../features/user/types/myProfile.type"; - export async function getMyInfo() { const res = await apiClient.get>("/api/users/me"); return res.data; @@ -19,7 +20,7 @@ export async function uploadProfileImage(file: File) { return res.data; } -export async function updateProfile(data: MyProfileFormData) { +export async function updateProfile(data: UpdateProfileRequest) { const res = await apiClient.put>("/api/users", data); return res.data; } diff --git a/src/entities/auth/types/auth.type.ts b/src/entities/auth/types/auth.type.ts index 0e2c8990..7c9cd551 100644 --- a/src/entities/auth/types/auth.type.ts +++ b/src/entities/auth/types/auth.type.ts @@ -17,3 +17,9 @@ export type CheckEmailResponse = { data: { exists: boolean }; timestamp: string; }; + +export type UpdateProfileRequest = { + nickname: string; + currentPassword?: string | null; + password?: string | null; +}; diff --git a/src/features/trash/api/trash.api.ts b/src/entities/trash/api/trash.api.ts similarity index 100% rename from src/features/trash/api/trash.api.ts rename to src/entities/trash/api/trash.api.ts diff --git a/src/features/trash/trash.queryKey.ts b/src/entities/trash/query/trash.queryKey.ts similarity index 90% rename from src/features/trash/trash.queryKey.ts rename to src/entities/trash/query/trash.queryKey.ts index bc8ad887..94dc89bf 100644 --- a/src/features/trash/trash.queryKey.ts +++ b/src/entities/trash/query/trash.queryKey.ts @@ -3,9 +3,8 @@ import { infiniteQueryOptions } from "@tanstack/react-query"; import { getPersonalTrashList, getTeamTrashList, -} from "@/features/trash/api/trash.api"; - -import { STALE_TIME } from "../../shared/constants/query/staleTime"; +} from "@/entities/trash/api/trash.api"; +import { STALE_TIME } from "@/shared/constants/query/staleTime"; const SIZE = 20; diff --git a/src/features/trash/types/trash.types.ts b/src/entities/trash/types/trash.types.ts similarity index 100% rename from src/features/trash/types/trash.types.ts rename to src/entities/trash/types/trash.types.ts diff --git a/src/features/trash/hooks/useDeleteTrashMutation/useDeleteTrashMutation.ts b/src/features/trash/hooks/useDeleteTrashMutation/useDeleteTrashMutation.ts index e42de087..2ba521ea 100644 --- a/src/features/trash/hooks/useDeleteTrashMutation/useDeleteTrashMutation.ts +++ b/src/features/trash/hooks/useDeleteTrashMutation/useDeleteTrashMutation.ts @@ -1,7 +1,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { deleteTrash } from "@/features/trash/api/trash.api"; -import { TrashActionParam } from "@/features/trash/types/trash.types"; +import { deleteTrash } from "@/entities/trash/api/trash.api"; +import { TrashActionParam } from "@/entities/trash/types/trash.types"; import { useToast } from "@/shared/hooks/useToast"; import { ApiError } from "@/shared/lib/api/types"; diff --git a/src/features/trash/hooks/useRestoreTrashMutation/useRestoreTrashMutation.ts b/src/features/trash/hooks/useRestoreTrashMutation/useRestoreTrashMutation.ts index 8ea57063..0da96769 100644 --- a/src/features/trash/hooks/useRestoreTrashMutation/useRestoreTrashMutation.ts +++ b/src/features/trash/hooks/useRestoreTrashMutation/useRestoreTrashMutation.ts @@ -1,7 +1,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { restoreTrash } from "@/features/trash/api/trash.api"; -import { TrashActionParam } from "@/features/trash/types/trash.types"; +import { restoreTrash } from "@/entities/trash/api/trash.api"; +import { TrashActionParam } from "@/entities/trash/types/trash.types"; import { useToast } from "@/shared/hooks/useToast"; import { ApiError } from "@/shared/lib/api/types"; diff --git a/src/features/user/hooks/useDeleteMeMutation/useDeleteMeMutation.ts b/src/features/user/hooks/useDeleteMeMutation/useDeleteMeMutation.ts index 4e8744d7..d803545c 100644 --- a/src/features/user/hooks/useDeleteMeMutation/useDeleteMeMutation.ts +++ b/src/features/user/hooks/useDeleteMeMutation/useDeleteMeMutation.ts @@ -1,11 +1,10 @@ import { useMutation } from "@tanstack/react-query"; import { useRouter } from "next/navigation"; +import { deleteMe } from "@/entities/auth/api/myInfo.api"; import { logoutAction } from "@/features/auth/logout/actions/logoutAction"; import { useToast } from "@/shared/hooks/useToast"; -import { deleteMe } from "../../../../entities/auth/api/myInfo.api"; - export function useDeleteMeMutation() { const { toast } = useToast(); const router = useRouter(); diff --git a/src/widgets/trash/PersonalTrash/PersonalTrash.tsx b/src/widgets/trash/PersonalTrash/PersonalTrash.tsx index 774efb90..89586d45 100644 --- a/src/widgets/trash/PersonalTrash/PersonalTrash.tsx +++ b/src/widgets/trash/PersonalTrash/PersonalTrash.tsx @@ -1,5 +1,5 @@ "use client"; -import { trashQueries } from "@/features/trash/trash.queryKey"; +import { trashQueries } from "@/entities/trash/query/trash.queryKey"; import { useInfiniteScroll } from "@/shared/hooks/useInfiniteScroll"; import TrashEmpty from "@/widgets/trash/TrashEmpty"; import TrashList from "@/widgets/trash/TrashList"; diff --git a/src/widgets/trash/TeamTrash/TeamTrash.tsx b/src/widgets/trash/TeamTrash/TeamTrash.tsx index aa585af3..a94140ac 100644 --- a/src/widgets/trash/TeamTrash/TeamTrash.tsx +++ b/src/widgets/trash/TeamTrash/TeamTrash.tsx @@ -1,6 +1,6 @@ import React from "react"; -import { trashQueries } from "@/features/trash/trash.queryKey"; +import { trashQueries } from "@/entities/trash/query/trash.queryKey"; import { useInfiniteScroll } from "@/shared/hooks/useInfiniteScroll"; import TrashEmpty from "@/widgets/trash/TrashEmpty"; import TrashList from "@/widgets/trash/TrashList"; diff --git a/src/widgets/trash/TrashItem/TrashItem.tsx b/src/widgets/trash/TrashItem/TrashItem.tsx index 0de4f339..cc5e5a47 100644 --- a/src/widgets/trash/TrashItem/TrashItem.tsx +++ b/src/widgets/trash/TrashItem/TrashItem.tsx @@ -1,6 +1,6 @@ import React from "react"; -import { TrashItemData } from "@/features/trash/types/trash.types"; +import { TrashItemData } from "@/entities/trash/types/trash.types"; import { Icon } from "@/shared/ui/Icon"; import TrashBadge from "@/widgets/trash/TrashItem/TrashBadge"; diff --git a/src/widgets/trash/TrashList/TrashList.tsx b/src/widgets/trash/TrashList/TrashList.tsx index 4af7543e..b930e940 100644 --- a/src/widgets/trash/TrashList/TrashList.tsx +++ b/src/widgets/trash/TrashList/TrashList.tsx @@ -1,9 +1,9 @@ "use client"; import React, { useState } from "react"; +import { TrashItemData } from "@/entities/trash/types/trash.types"; import { useDeleteTrashMutation } from "@/features/trash/hooks/useDeleteTrashMutation"; import { useRestoreTrashMutation } from "@/features/trash/hooks/useRestoreTrashMutation"; -import { TrashItemData } from "@/features/trash/types/trash.types"; import SoftButton from "@/shared/ui/Button/SoftButton"; import TrashItem from "../TrashItem"; From b330c561fe761aede4c3596f00f1cadd88ba5bc6 Mon Sep 17 00:00:00 2001 From: LeeJaein Date: Sun, 3 May 2026 10:58:49 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor(#243):=20mutation=20=ED=8F=B4?= =?UTF-8?q?=EB=8D=94=20=EB=B6=84=EB=A6=AC=20=EB=B0=8F=20index.ts=20?= =?UTF-8?q?=EA=B3=B5=EA=B0=9C=20API=20=EC=A0=95=EB=B9=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - features/trash, features/user 훅을 mutation/ 폴더로 이동 - entities/trash, entities/auth index.ts 생성 (public API 규칙 적용) - features/user index.ts 생성 - TrashList 중복 key 및 선택 버그 수정 (id → itemType-id 복합키) - 관련 import 경로 전체 수정 --- src/entities/auth/index.ts | 15 ++++++++ src/entities/trash/index.ts | 12 ++++++ .../useDeleteTrashMutation/index.ts | 0 .../useDeleteTrashMutation.ts | 3 +- .../useRestoreTrashMutation/index.ts | 0 .../useRestoreTrashMutation.ts | 3 +- .../useMyProfileForm/useMyProfileForm.ts | 2 +- src/features/user/index.ts | 4 ++ .../useDeleteMeMutation/index.ts | 0 .../useDeleteMeMutation.ts | 0 .../useUpdateProfileMutation/index.ts | 0 .../useUpdateProfileMutation.ts | 0 .../useUploadProfileImageMutation/index.ts | 0 .../useUploadProfileImageMutation.ts | 0 src/widgets/my/MyProfileForm.tsx | 5 +-- src/widgets/my/ProfileImageUploader.tsx | 2 +- .../trash/PersonalTrash/PersonalTrash.tsx | 2 +- src/widgets/trash/TeamTrash/TeamTrash.tsx | 2 +- src/widgets/trash/TrashItem/TrashItem.tsx | 6 +-- src/widgets/trash/TrashList/TrashList.tsx | 38 ++++++++++--------- 20 files changed, 63 insertions(+), 31 deletions(-) create mode 100644 src/entities/auth/index.ts create mode 100644 src/entities/trash/index.ts rename src/features/trash/{hooks => mutation}/useDeleteTrashMutation/index.ts (100%) rename src/features/trash/{hooks => mutation}/useDeleteTrashMutation/useDeleteTrashMutation.ts (87%) rename src/features/trash/{hooks => mutation}/useRestoreTrashMutation/index.ts (100%) rename src/features/trash/{hooks => mutation}/useRestoreTrashMutation/useRestoreTrashMutation.ts (87%) create mode 100644 src/features/user/index.ts rename src/features/user/{hooks => mutation}/useDeleteMeMutation/index.ts (100%) rename src/features/user/{hooks => mutation}/useDeleteMeMutation/useDeleteMeMutation.ts (100%) rename src/features/user/{hooks => mutation}/useUpdateProfileMutation/index.ts (100%) rename src/features/user/{hooks => mutation}/useUpdateProfileMutation/useUpdateProfileMutation.ts (100%) rename src/features/user/{hooks => mutation}/useUploadProfileImageMutation/index.ts (100%) rename src/features/user/{hooks => mutation}/useUploadProfileImageMutation/useUploadProfileImageMutation.ts (100%) diff --git a/src/entities/auth/index.ts b/src/entities/auth/index.ts new file mode 100644 index 00000000..2377854b --- /dev/null +++ b/src/entities/auth/index.ts @@ -0,0 +1,15 @@ +export { + deleteMe, + getMyInfo, + updateProfile, + uploadProfileImage, +} from "./api/myInfo.api"; +export { checkEmailDuplicate, signupMutationFn } from "./api/signup.api"; +export { userQueries } from "./query/user.queryKey"; +export type { + AuthFormType, + CheckEmailResponse, + SocialType, + UpdateProfileRequest, + UserProfile, +} from "./types/auth.type"; diff --git a/src/entities/trash/index.ts b/src/entities/trash/index.ts new file mode 100644 index 00000000..e5218045 --- /dev/null +++ b/src/entities/trash/index.ts @@ -0,0 +1,12 @@ +export { + deleteTrash, + getPersonalTrashList, + getTeamTrashList, + restoreTrash, +} from "./api/trash.api"; +export { trashQueries } from "./query/trash.queryKey"; +export type { + TrashActionParam, + TrashItemData, + TrashListData, +} from "./types/trash.types"; diff --git a/src/features/trash/hooks/useDeleteTrashMutation/index.ts b/src/features/trash/mutation/useDeleteTrashMutation/index.ts similarity index 100% rename from src/features/trash/hooks/useDeleteTrashMutation/index.ts rename to src/features/trash/mutation/useDeleteTrashMutation/index.ts diff --git a/src/features/trash/hooks/useDeleteTrashMutation/useDeleteTrashMutation.ts b/src/features/trash/mutation/useDeleteTrashMutation/useDeleteTrashMutation.ts similarity index 87% rename from src/features/trash/hooks/useDeleteTrashMutation/useDeleteTrashMutation.ts rename to src/features/trash/mutation/useDeleteTrashMutation/useDeleteTrashMutation.ts index 2ba521ea..d1297b9a 100644 --- a/src/features/trash/hooks/useDeleteTrashMutation/useDeleteTrashMutation.ts +++ b/src/features/trash/mutation/useDeleteTrashMutation/useDeleteTrashMutation.ts @@ -1,7 +1,6 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { deleteTrash } from "@/entities/trash/api/trash.api"; -import { TrashActionParam } from "@/entities/trash/types/trash.types"; +import { deleteTrash, TrashActionParam } from "@/entities/trash"; import { useToast } from "@/shared/hooks/useToast"; import { ApiError } from "@/shared/lib/api/types"; diff --git a/src/features/trash/hooks/useRestoreTrashMutation/index.ts b/src/features/trash/mutation/useRestoreTrashMutation/index.ts similarity index 100% rename from src/features/trash/hooks/useRestoreTrashMutation/index.ts rename to src/features/trash/mutation/useRestoreTrashMutation/index.ts diff --git a/src/features/trash/hooks/useRestoreTrashMutation/useRestoreTrashMutation.ts b/src/features/trash/mutation/useRestoreTrashMutation/useRestoreTrashMutation.ts similarity index 87% rename from src/features/trash/hooks/useRestoreTrashMutation/useRestoreTrashMutation.ts rename to src/features/trash/mutation/useRestoreTrashMutation/useRestoreTrashMutation.ts index 0da96769..3596a03d 100644 --- a/src/features/trash/hooks/useRestoreTrashMutation/useRestoreTrashMutation.ts +++ b/src/features/trash/mutation/useRestoreTrashMutation/useRestoreTrashMutation.ts @@ -1,7 +1,6 @@ import { useMutation, useQueryClient } from "@tanstack/react-query"; -import { restoreTrash } from "@/entities/trash/api/trash.api"; -import { TrashActionParam } from "@/entities/trash/types/trash.types"; +import { restoreTrash, TrashActionParam } from "@/entities/trash"; import { useToast } from "@/shared/hooks/useToast"; import { ApiError } from "@/shared/lib/api/types"; diff --git a/src/features/user/hooks/useMyProfileForm/useMyProfileForm.ts b/src/features/user/hooks/useMyProfileForm/useMyProfileForm.ts index d2cc2f39..524ec986 100644 --- a/src/features/user/hooks/useMyProfileForm/useMyProfileForm.ts +++ b/src/features/user/hooks/useMyProfileForm/useMyProfileForm.ts @@ -6,7 +6,7 @@ import { myProfileSchema, } from "@/features/user/types/myProfile.type"; -import { useUpdateProfileMutation } from "../useUpdateProfileMutation"; +import { useUpdateProfileMutation } from "../../mutation/useUpdateProfileMutation"; export function useMyProfileForm(initialNickname: string) { const [values, setValues] = useState({ diff --git a/src/features/user/index.ts b/src/features/user/index.ts new file mode 100644 index 00000000..9afd9cf8 --- /dev/null +++ b/src/features/user/index.ts @@ -0,0 +1,4 @@ +export { useMyProfileForm } from "./hooks/useMyProfileForm"; +export { useDeleteMeMutation } from "./mutation/useDeleteMeMutation"; +export { useUpdateProfileMutation } from "./mutation/useUpdateProfileMutation"; +export { useUploadProfileImageMutation } from "./mutation/useUploadProfileImageMutation"; diff --git a/src/features/user/hooks/useDeleteMeMutation/index.ts b/src/features/user/mutation/useDeleteMeMutation/index.ts similarity index 100% rename from src/features/user/hooks/useDeleteMeMutation/index.ts rename to src/features/user/mutation/useDeleteMeMutation/index.ts diff --git a/src/features/user/hooks/useDeleteMeMutation/useDeleteMeMutation.ts b/src/features/user/mutation/useDeleteMeMutation/useDeleteMeMutation.ts similarity index 100% rename from src/features/user/hooks/useDeleteMeMutation/useDeleteMeMutation.ts rename to src/features/user/mutation/useDeleteMeMutation/useDeleteMeMutation.ts diff --git a/src/features/user/hooks/useUpdateProfileMutation/index.ts b/src/features/user/mutation/useUpdateProfileMutation/index.ts similarity index 100% rename from src/features/user/hooks/useUpdateProfileMutation/index.ts rename to src/features/user/mutation/useUpdateProfileMutation/index.ts diff --git a/src/features/user/hooks/useUpdateProfileMutation/useUpdateProfileMutation.ts b/src/features/user/mutation/useUpdateProfileMutation/useUpdateProfileMutation.ts similarity index 100% rename from src/features/user/hooks/useUpdateProfileMutation/useUpdateProfileMutation.ts rename to src/features/user/mutation/useUpdateProfileMutation/useUpdateProfileMutation.ts diff --git a/src/features/user/hooks/useUploadProfileImageMutation/index.ts b/src/features/user/mutation/useUploadProfileImageMutation/index.ts similarity index 100% rename from src/features/user/hooks/useUploadProfileImageMutation/index.ts rename to src/features/user/mutation/useUploadProfileImageMutation/index.ts diff --git a/src/features/user/hooks/useUploadProfileImageMutation/useUploadProfileImageMutation.ts b/src/features/user/mutation/useUploadProfileImageMutation/useUploadProfileImageMutation.ts similarity index 100% rename from src/features/user/hooks/useUploadProfileImageMutation/useUploadProfileImageMutation.ts rename to src/features/user/mutation/useUploadProfileImageMutation/useUploadProfileImageMutation.ts diff --git a/src/widgets/my/MyProfileForm.tsx b/src/widgets/my/MyProfileForm.tsx index 59f517fd..a2fba52d 100644 --- a/src/widgets/my/MyProfileForm.tsx +++ b/src/widgets/my/MyProfileForm.tsx @@ -3,10 +3,9 @@ import { useSuspenseQuery } from "@tanstack/react-query"; import { useRouter } from "next/navigation"; import React from "react"; -import { userQueries } from "@/entities/auth/query/user.queryKey"; +import { userQueries } from "@/entities/auth"; import { logoutAction } from "@/features/auth/logout/actions/logoutAction"; -import { useDeleteMeMutation } from "@/features/user/hooks/useDeleteMeMutation/useDeleteMeMutation"; -import { useMyProfileForm } from "@/features/user/hooks/useMyProfileForm"; +import { useDeleteMeMutation, useMyProfileForm } from "@/features/user"; import { useOverlay } from "@/shared/hooks/useOverlay"; import Button from "@/shared/ui/Button/Button/Button"; import { Icon } from "@/shared/ui/Icon"; diff --git a/src/widgets/my/ProfileImageUploader.tsx b/src/widgets/my/ProfileImageUploader.tsx index 8869acba..ee3add77 100644 --- a/src/widgets/my/ProfileImageUploader.tsx +++ b/src/widgets/my/ProfileImageUploader.tsx @@ -1,7 +1,7 @@ "use client"; import React, { useRef } from "react"; -import { useUploadProfileImageMutation } from "@/features/user/hooks/useUploadProfileImageMutation"; +import { useUploadProfileImageMutation } from "@/features/user/mutation/useUploadProfileImageMutation"; import { useToast } from "@/shared/hooks/useToast"; import ActionButton from "../../shared/ui/Button/ActionButton/ActionButton"; diff --git a/src/widgets/trash/PersonalTrash/PersonalTrash.tsx b/src/widgets/trash/PersonalTrash/PersonalTrash.tsx index 89586d45..8a945506 100644 --- a/src/widgets/trash/PersonalTrash/PersonalTrash.tsx +++ b/src/widgets/trash/PersonalTrash/PersonalTrash.tsx @@ -1,5 +1,5 @@ "use client"; -import { trashQueries } from "@/entities/trash/query/trash.queryKey"; +import { trashQueries } from "@/entities/trash"; import { useInfiniteScroll } from "@/shared/hooks/useInfiniteScroll"; import TrashEmpty from "@/widgets/trash/TrashEmpty"; import TrashList from "@/widgets/trash/TrashList"; diff --git a/src/widgets/trash/TeamTrash/TeamTrash.tsx b/src/widgets/trash/TeamTrash/TeamTrash.tsx index a94140ac..35e5ef1d 100644 --- a/src/widgets/trash/TeamTrash/TeamTrash.tsx +++ b/src/widgets/trash/TeamTrash/TeamTrash.tsx @@ -1,6 +1,6 @@ import React from "react"; -import { trashQueries } from "@/entities/trash/query/trash.queryKey"; +import { trashQueries } from "@/entities/trash"; import { useInfiniteScroll } from "@/shared/hooks/useInfiniteScroll"; import TrashEmpty from "@/widgets/trash/TrashEmpty"; import TrashList from "@/widgets/trash/TrashList"; diff --git a/src/widgets/trash/TrashItem/TrashItem.tsx b/src/widgets/trash/TrashItem/TrashItem.tsx index cc5e5a47..6d159369 100644 --- a/src/widgets/trash/TrashItem/TrashItem.tsx +++ b/src/widgets/trash/TrashItem/TrashItem.tsx @@ -1,12 +1,12 @@ import React from "react"; -import { TrashItemData } from "@/entities/trash/types/trash.types"; +import { TrashItemData } from "@/entities/trash"; import { Icon } from "@/shared/ui/Icon"; import TrashBadge from "@/widgets/trash/TrashItem/TrashBadge"; interface TrashItemProps extends TrashItemData { isSelected: boolean; - onToggle: (id: number) => void; + onToggle: (key: string) => void; } function TrashItem({ isSelected, onToggle, ...item }: TrashItemProps) { @@ -16,7 +16,7 @@ function TrashItem({ isSelected, onToggle, ...item }: TrashItemProps) { onToggle(item.id)} + onClick={() => onToggle(`${item.itemType}-${item.id}`)} />
diff --git a/src/widgets/trash/TrashList/TrashList.tsx b/src/widgets/trash/TrashList/TrashList.tsx index b930e940..e4eee6a7 100644 --- a/src/widgets/trash/TrashList/TrashList.tsx +++ b/src/widgets/trash/TrashList/TrashList.tsx @@ -1,9 +1,9 @@ "use client"; import React, { useState } from "react"; -import { TrashItemData } from "@/entities/trash/types/trash.types"; -import { useDeleteTrashMutation } from "@/features/trash/hooks/useDeleteTrashMutation"; -import { useRestoreTrashMutation } from "@/features/trash/hooks/useRestoreTrashMutation"; +import { TrashItemData } from "@/entities/trash"; +import { useDeleteTrashMutation } from "@/features/trash/mutation/useDeleteTrashMutation"; +import { useRestoreTrashMutation } from "@/features/trash/mutation/useRestoreTrashMutation"; import SoftButton from "@/shared/ui/Button/SoftButton"; import TrashItem from "../TrashItem"; @@ -15,30 +15,34 @@ interface TrashListProps { } function TrashList({ items, bottomRef, isFetchingNextPage }: TrashListProps) { - const [selectedIds, setSelectedIds] = useState>(new Set()); + const [selectedKeys, setSelectedKeys] = useState>(new Set()); const { mutate: restoreMutate, isPending: isRestore } = useRestoreTrashMutation(); const { mutate: deleteMutate, isPending: isDeleting } = useDeleteTrashMutation(); - const handleToggle = (id: number) => { - setSelectedIds((prev) => { + const getItemKey = (item: TrashItemData) => `${item.itemType}-${item.id}`; + + const handleToggle = (key: string) => { + setSelectedKeys((prev) => { const next = new Set(prev); - next.has(id) ? next.delete(id) : next.add(id); + next.has(key) ? next.delete(key) : next.add(key); return next; }); }; const handleSelectAll = () => { - if (selectedIds.size === items.length) { - setSelectedIds(new Set()); + if (selectedKeys.size === items.length) { + setSelectedKeys(new Set()); } else { - setSelectedIds(new Set(items.map((item) => item.id))); + setSelectedKeys(new Set(items.map(getItemKey))); } }; const getSelectedTrashItems = () => { - const selectedItems = items.filter((item) => selectedIds.has(item.id)); + const selectedItems = items.filter((item) => + selectedKeys.has(getItemKey(item)), + ); return { goalIds: selectedItems .filter((item) => item.itemType === "GOAL") @@ -50,13 +54,13 @@ function TrashList({ items, bottomRef, isFetchingNextPage }: TrashListProps) { }; const handleRestore = () => { restoreMutate(getSelectedTrashItems(), { - onSuccess: () => setSelectedIds(new Set()), + onSuccess: () => setSelectedKeys(new Set()), }); }; const handleDelete = () => { deleteMutate(getSelectedTrashItems(), { - onSuccess: () => setSelectedIds(new Set()), + onSuccess: () => setSelectedKeys(new Set()), }); }; @@ -65,8 +69,8 @@ function TrashList({ items, bottomRef, isFetchingNextPage }: TrashListProps) {
{items.map((item) => ( @@ -91,7 +95,7 @@ function TrashList({ items, bottomRef, isFetchingNextPage }: TrashListProps) { variant={"grayActive"} className="tablet:w-[90px] w-20 whitespace-nowrap" onClick={handleRestore} - disabled={selectedIds.size === 0 || isRestore || isDeleting} + disabled={selectedKeys.size === 0 || isRestore || isDeleting} > 복구 @@ -99,7 +103,7 @@ function TrashList({ items, bottomRef, isFetchingNextPage }: TrashListProps) { variant={"grayActive"} className="tablet:w-[90px] w-20 whitespace-nowrap" onClick={handleDelete} - disabled={selectedIds.size === 0 || isRestore || isDeleting} + disabled={selectedKeys.size === 0 || isRestore || isDeleting} > 삭제