From afcf04d67a33593ca6b664a19ec956f3d07ad64e Mon Sep 17 00:00:00 2001 From: Jungmin Date: Sat, 19 Oct 2024 05:20:55 +0900 Subject: [PATCH] the last of the last --- src/app/dashboard/note/[noteId]/page.tsx | 4 +- src/app/dashboard/todoboard/page.tsx | 4 +- src/components/CreateNewTodo copy.tsx | 325 ----------------------- 3 files changed, 2 insertions(+), 331 deletions(-) delete mode 100644 src/components/CreateNewTodo copy.tsx diff --git a/src/app/dashboard/note/[noteId]/page.tsx b/src/app/dashboard/note/[noteId]/page.tsx index 1b9598e..3d401bc 100644 --- a/src/app/dashboard/note/[noteId]/page.tsx +++ b/src/app/dashboard/note/[noteId]/page.tsx @@ -3,13 +3,11 @@ import { toast } from "react-toastify"; import Image from "next/image"; import { ChangeEvent, useEffect, useState } from "react"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; -import { useQuery } from "@tanstack/react-query"; import useModal from "@/hook/useModal"; -import { getNote, getNotes, patchNotes, postNotes } from "@/api/noteAPI"; +import { getNote, patchNotes, postNotes } from "@/api/noteAPI"; import { getTodos } from "@/api/todoAPI"; import UploadLinkModal from "@/components/UploadLinkModal"; -import LoadingScreen from "@/components/LoadingScreen"; import { NoteType, TodoType } from "@/app/Types/TodoGoalType"; export default function NotePage() { diff --git a/src/app/dashboard/todoboard/page.tsx b/src/app/dashboard/todoboard/page.tsx index 04c00e5..5bba9f8 100644 --- a/src/app/dashboard/todoboard/page.tsx +++ b/src/app/dashboard/todoboard/page.tsx @@ -1,15 +1,13 @@ "use client"; import { useEffect, useState } from "react"; -import { useQuery } from "@tanstack/react-query"; -import { toast } from "react-toastify"; import CreateNewTodo from "@/components/CreateNewTodo"; import useModal from "@/hook/useModal"; import { getAllTodos } from "@/api/todoAPI"; +import { TodoType } from "@/app/Types/TodoGoalType"; import TodoItem from "../components/TodoItem"; -import { TodoType } from "@/app/Types/TodoGoalType"; type StatusType = "All" | "Todo" | "Done"; diff --git a/src/components/CreateNewTodo copy.tsx b/src/components/CreateNewTodo copy.tsx deleted file mode 100644 index d8e75d3..0000000 --- a/src/components/CreateNewTodo copy.tsx +++ /dev/null @@ -1,325 +0,0 @@ -"use client"; - -import { toast } from "react-toastify"; -import Image from "next/image"; -import { ChangeEvent, useEffect, useRef, useState } from "react"; - -import { editTodo, postFile, postTodos } from "@/api/todoAPI"; -import useModal from "@/hook/useModal"; -import { useGoalStore } from "@/store/goalStore"; -import useTodoStore from "@/store/todoStore"; - -import LinkUpload from "./LinkUpload"; - -export type TodoType = { - noteId?: number | null; - done: boolean; - linkUrl?: string | null; - fileUrl?: string | null; - title: string; - id: number; - goal: GoalType; - userId: number; - teamId: string; - updatedAt: string; - createdAt: string; -}; -export type GoalType = { - id: number; - teamId: string; - title: string; - userId: number; - createdAt: string; - updatedAt: string; -}; - -export type FileType = { - url?: string | null; -}; - -export type CreateNewTodoProps = { - closeCreateNewTodo: () => void; - goal?: GoalType; - title?: string; - fileUrl?: string | undefined; - linkUrl?: string | undefined; - todoId?: number; - isEdit?: boolean; - goalId?: number | undefined; // 목표 ID를 받아옴 -}; - -export default function CreateNewTodo({ - closeCreateNewTodo, - goal, - title, - fileUrl, - linkUrl, - todoId, - isEdit, - goalId, // 목표 ID를 받아옴 -}: CreateNewTodoProps) { - const fileInputRef = useRef(null); - const [isOpenGoals, setIsOpenGoals] = useState(false); - const [isFileUpload, setIsFileUpload] = useState(false); - const [fileTitle, setFileTitle] = useState(""); - const { Modal, openModal, closeModal } = useModal(); - const { goals } = useGoalStore(); - const { createTodo, updateTodo } = useTodoStore(); - - const [todo, setTodo] = useState({ - title: "", - fileUrl: null, - linkUrl: null, - goal: goal || { - id: 0, - teamId: "", - title: "", - userId: 0, - createdAt: "", - updatedAt: "", - }, - done: false, - noteId: null, - id: 0, - userId: 0, - teamId: "", - updatedAt: "", - createdAt: "", - }); - - useEffect(() => { - // 할 일 추가할 때 목표가 설정되어 있지 않으면 전역 상태에서 기본값 설정 - if (!goal && goals.length > 0) { - const defaultGoal = goals.find((g) => g.id === goalId); // goalId와 일치하는 목표 찾기 - if (defaultGoal) { - setTodo((prevTodo) => ({ - ...prevTodo, - goal: defaultGoal, // 일치하는 목표가 있으면 todo에 설정 - })); - } - } - }, [goal, goals, goalId]); - - const handleTitleChange = (e: React.ChangeEvent) => { - setTodo({ ...todo, title: e.target.value }); - }; - - const handleFileChange = async (e: ChangeEvent) => { - const MAX_FILE_SIZE = 3 * 1024 * 1024; // 3MB 제한 - const selectedFile = e.target.files?.[0]; - - if (!selectedFile) { - toast.error("파일이 선택되지 않았습니다."); - return; - } - - if (selectedFile.size > MAX_FILE_SIZE) { - toast.error("파일은 3MB 이하만 업로드 가능합니다."); - setIsFileUpload(false); - return; - } - - const response = await postFile(selectedFile); - if (response) { - setTodo((prevTodo) => ({ - ...prevTodo, - fileUrl: response.url, - })); - setFileTitle(selectedFile.name); - setIsFileUpload(true); - toast.success("파일이 성공적으로 업로드되었습니다"); - } else { - toast.error("파일 업로드 실패"); - } - }; - - const handleGoalSelect = (goalId: number, goalTitle: string) => { - setTodo((prevTodo) => ({ - ...prevTodo, - goal: { ...prevTodo.goal, id: goalId, title: goalTitle }, - })); - setIsOpenGoals(false); - }; - - const handleSubmit = async (e: React.FormEvent) => { - e.preventDefault(); - - let response; - // 할 일 수정 - if (isEdit && todoId) { - response = await editTodo(todo.title, todo.goal.id, todo.fileUrl, todo.linkUrl, todoId); - if (response) { - toast.success("할 일이 성공적으로 수정되었습니다"); - updateTodo(response); // 수정된 할 일 전달 - } else { - toast.error("할 일 수정 실패"); - } - } else { - // 할 일 추가 - const newTodo: TodoType = { - title: todo.title, - fileUrl: todo.fileUrl, - linkUrl: todo.linkUrl, - goal: { id: todo.goal.id, title: todo.goal.title, teamId: "", userId: 0, createdAt: "", updatedAt: "" }, - done: false, - noteId: 0 || null || undefined, - id: Date.now(), - userId: 0, - teamId: "FESI3-5", - updatedAt: new Date().toISOString(), - createdAt: new Date().toISOString(), - }; - - await createTodo(newTodo); - toast.success("할 일이 성공적으로 생성되었습니다"); - } - closeCreateNewTodo(); - }; - - useEffect(() => { - if (isEdit && goal) { - setTodo((prevTodo) => ({ - ...prevTodo, - title: title || "", - linkUrl: linkUrl || null, - fileUrl: fileUrl || null, - goal: goal, - })); - } - - if (fileUrl) { - setIsFileUpload(true); - } - }, [isEdit, title, fileUrl, linkUrl, goal]); - - return ( - <> -
-
-

제목

- - -
-
-

자료

-
-
- checkbox-icon - 파일 업로드 -
-
openModal("LINK_ATTACHMENT")} - > - checkbox-icon - 링크 첨부 -
-
-
-
- {fileTitle ? ( -

{fileTitle}

- ) : ( -
{ - e.stopPropagation(); - fileInputRef.current?.click(); - }} - > -

+

-

파일을 업로드해주세요

-
- )} - - -
-
-
- - {/* 목표 선택 UI */} -
-

- 목표 -

-
setIsOpenGoals((prev) => !prev)} - className="flex w-full cursor-pointer justify-between rounded-xl bg-slate-50 px-[20px] py-3" - > -

- {todo.goal.id ? todo.goal.title : "목표를 선택해주세요"} -

- arrowdown-icon -
- - {isOpenGoals && ( -
-
    - {goals.length > 0 ? ( - goals.map((goal) => ( -
  • handleGoalSelect(goal.id, goal.title)} - > - {goal.title} -
  • - )) - ) : ( -
  • 목표가 없습니다.
  • - )} -
-
- )} -
- - {/* 제출 버튼 */} - -
- - - - - ); -}