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
9 changes: 5 additions & 4 deletions src/entities/auth/api/myInfo.api.ts
Original file line number Diff line number Diff line change
@@ -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<ApiResponse<UserProfile>>("/api/users/me");
return res.data;
Expand All @@ -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<ApiResponse<UserProfile>>("/api/users", data);
return res.data;
}
Expand Down
15 changes: 15 additions & 0 deletions src/entities/auth/index.ts
Original file line number Diff line number Diff line change
@@ -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";
6 changes: 6 additions & 0 deletions src/entities/auth/types/auth.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ export type CheckEmailResponse = {
data: { exists: boolean };
timestamp: string;
};

export type UpdateProfileRequest = {
nickname: string;
currentPassword?: string | null;
password?: string | null;
};
12 changes: 12 additions & 0 deletions src/entities/trash/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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, TrashActionParam } from "@/entities/trash";
import { useToast } from "@/shared/hooks/useToast";
import { ApiError } from "@/shared/lib/api/types";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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, TrashActionParam } from "@/entities/trash";
import { useToast } from "@/shared/hooks/useToast";
import { ApiError } from "@/shared/lib/api/types";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyProfileFormData>({
Expand Down
4 changes: 4 additions & 0 deletions src/features/user/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export { useMyProfileForm } from "./hooks/useMyProfileForm";
export { useDeleteMeMutation } from "./mutation/useDeleteMeMutation";
export { useUpdateProfileMutation } from "./mutation/useUpdateProfileMutation";
export { useUploadProfileImageMutation } from "./mutation/useUploadProfileImageMutation";
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/widgets/my/MyProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/my/ProfileImageUploader.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/trash/PersonalTrash/PersonalTrash.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { trashQueries } from "@/features/trash/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";
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/trash/TeamTrash/TeamTrash.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";

import { trashQueries } from "@/features/trash/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";
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/trash/TrashItem/TrashItem.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from "react";

import { TrashItemData } from "@/features/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) {
Expand All @@ -16,7 +16,7 @@ function TrashItem({ isSelected, onToggle, ...item }: TrashItemProps) {
<Icon
name={isSelected ? "ActiveFilledCheckBox" : "InactiveFilledCheckBox"}
className="tablet:size-6 size-5 cursor-pointer"
onClick={() => onToggle(item.id)}
onClick={() => onToggle(`${item.itemType}-${item.id}`)}
/>
</div>
<div className="flex min-w-0 flex-col">
Expand Down
38 changes: 21 additions & 17 deletions src/widgets/trash/TrashList/TrashList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";
import React, { useState } from "react";

import { useDeleteTrashMutation } from "@/features/trash/hooks/useDeleteTrashMutation";
import { useRestoreTrashMutation } from "@/features/trash/hooks/useRestoreTrashMutation";
import { TrashItemData } from "@/features/trash/types/trash.types";
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";
Expand All @@ -15,30 +15,34 @@ interface TrashListProps {
}

function TrashList({ items, bottomRef, isFetchingNextPage }: TrashListProps) {
const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set());
const [selectedKeys, setSelectedKeys] = useState<Set<string>>(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")
Expand All @@ -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()),
});
};

Expand All @@ -65,8 +69,8 @@ function TrashList({ items, bottomRef, isFetchingNextPage }: TrashListProps) {
<div className="bg-inverse-normal tablet:rounded-4xl tablet:h-[733px] tablet:pr-5 h-[646px] w-full overflow-y-auto rounded-3xl pt-4 pr-2 pl-5">
{items.map((item) => (
<TrashItem
key={item.id}
isSelected={selectedIds.has(item.id)}
key={getItemKey(item)}
isSelected={selectedKeys.has(getItemKey(item))}
onToggle={handleToggle}
{...item}
/>
Expand All @@ -91,15 +95,15 @@ 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}
>
복구
</SoftButton>
<SoftButton
variant={"grayActive"}
className="tablet:w-[90px] w-20 whitespace-nowrap"
onClick={handleDelete}
disabled={selectedIds.size === 0 || isRestore || isDeleting}
disabled={selectedKeys.size === 0 || isRestore || isDeleting}
>
삭제
</SoftButton>
Expand Down
Loading