-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 홈 화면 TODO 조회·생성·완료·순서 변경 API 및 AI 소요 시간 추천 연동 #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e98c0da
feat(web): 홈 화면 조회 API 연동 (#159)
kimminna 5317715
Merge branch 'develop' of https://github.com/Team-Timo/Timo-client in…
kimminna 5f87fd8
fix(web): 홈 화면 투두 카드 날짜 범위 및 오늘 스크롤 위치 수정 (#159)
kimminna f2a6109
feat(web): TODO 생성 API 연동 (#159)
kimminna e6fcd5d
fix(web): 홈 투두 응답의 null priority·tag 파싱 오류 수정 (#159)
kimminna 92ba234
fix(web): 홈 투두 응답 icon null 파싱 오류 수정 (#159)
kimminna 0bf7ac1
feat(web): 투두 및 하위 투두 완료 상태 변경 API 연동 (#159)
kimminna f794401
refactor(web): 투두 생성 성공 시 홈 뷰 쿼리 무효화로 전환 (#159)
kimminna dd6c46d
feat(web): 시간 트리거 클릭 시 AI 소요 시간 자동 추천 (#159)
kimminna 21658cb
fix(web): 드롭다운 바깥 클릭 시 모달까지 닫히는 레이스 컨디션 수정 (#159)
kimminna 001b574
fix(web): 홈 뷰 쿼리 staleTime 제거로 토글 시 재요청 보장 (#159)
kimminna dca3e17
feat(web): 투두 순서 변경 API 연동 (#159)
kimminna de08d88
fix(web): OverlayModal 오버레이 클릭 감지에 터치/펜 입력 지원 (#159)
kimminna File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 49 additions & 31 deletions
80
.../app/[locale]/(main)/(with-time-sidebar)/home/_hooks/todo-modal/use-create-todo-submit.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,42 +1,60 @@ | ||
| "use client"; | ||
|
|
||
| import { useQueryClient } from "@tanstack/react-query"; | ||
| import { useState } from "react"; | ||
|
|
||
| import type { TodoCreateRequest } from "@/api/generated/models"; | ||
| import type { CreateTodoRequest } from "@/api/todo/todo-schema"; | ||
| import type { CreateTodoTag } from "@/app/[locale]/(main)/(with-time-sidebar)/home/_containers/todo-modal/CreateTodoModalContent"; | ||
| import type { Todo } from "@/app/[locale]/(main)/(with-time-sidebar)/home/_types/todo-type"; | ||
|
|
||
| import { convertApiDurationToSeconds } from "@/app/[locale]/(main)/(with-time-sidebar)/home/_utils/todo-time"; | ||
| import { getGetHomeQueryKey } from "@/api/generated/endpoints/home/home"; | ||
| import { useCreateTodo } from "@/api/generated/endpoints/todo/todo"; | ||
| import { todoCreateResponseSchema } from "@/app/[locale]/(main)/(with-time-sidebar)/home/_types/todo-type"; | ||
|
|
||
| // 목데이터: 실제 API 호출 없이 로컬 상태에만 즉시 반영한다. | ||
| const buildTodoFromRequest = ( | ||
| const buildCreateTodoRequestBody = ( | ||
| data: CreateTodoRequest, | ||
| tag: CreateTodoTag, | ||
| ): Todo => ({ | ||
| todoId: Date.now(), | ||
| icon: data.icon, | ||
| ): TodoCreateRequest => ({ | ||
| icon: data.icon ?? undefined, | ||
| title: data.title, | ||
| completed: false, | ||
| durationSeconds: convertApiDurationToSeconds(data.duration), | ||
| priority: data.priority ?? "MEDIUM", | ||
| tag: { tagId: tag.id, name: tag.name }, | ||
| hasMemo: Boolean(data.memo?.trim()), | ||
| isRepeated: data.repeatType !== "NONE", | ||
| timerStatus: "STOPPED", | ||
| sortOrder: 0, | ||
| subtasks: (data.subtasks ?? []).map((content, index) => ({ | ||
| subtaskId: Date.now() + index, | ||
| content, | ||
| completed: false, | ||
| })), | ||
| subtasks: data.subtasks?.length ? data.subtasks : undefined, | ||
| date: data.date, | ||
| duration: data.duration, | ||
| priority: data.priority ?? undefined, | ||
| tagId: data.tagId ?? undefined, | ||
| repeatType: data.repeatType, | ||
| repeatWeekdays: data.repeatWeekdays?.length ? data.repeatWeekdays : undefined, | ||
| repeatDayOfMonth: data.repeatDayOfMonth ?? undefined, | ||
| memo: data.memo?.trim() ? data.memo : undefined, | ||
| }); | ||
|
|
||
| export interface UseCreateTodoSubmitParams { | ||
| onCreate: (todo: Todo) => void; | ||
| } | ||
| export const useCreateTodoSubmit = () => { | ||
| const [isErrorToastOpen, setIsErrorToastOpen] = useState(false); | ||
| const { mutate: createTodo } = useCreateTodo(); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| const handleSubmit = (data: CreateTodoRequest) => { | ||
| createTodo( | ||
| { data: buildCreateTodoRequestBody(data) }, | ||
| { | ||
| onSuccess: (response) => { | ||
| const parsed = todoCreateResponseSchema.safeParse(response.data); | ||
|
|
||
| export const useCreateTodoSubmit = ({ | ||
| onCreate, | ||
| }: UseCreateTodoSubmitParams) => { | ||
| const handleSubmit = (data: CreateTodoRequest, tag: CreateTodoTag) => { | ||
| onCreate(buildTodoFromRequest(data, tag)); | ||
| if (!parsed.success) { | ||
| setIsErrorToastOpen(true); | ||
| return; | ||
| } | ||
|
|
||
| queryClient.invalidateQueries({ queryKey: getGetHomeQueryKey() }); | ||
| }, | ||
| onError: () => { | ||
| setIsErrorToastOpen(true); | ||
| }, | ||
| }, | ||
| ); | ||
| }; | ||
|
|
||
| return { handleSubmit }; | ||
| return { | ||
| handleSubmit, | ||
| isErrorToastOpen, | ||
| closeErrorToast: () => setIsErrorToastOpen(false), | ||
| }; | ||
|
kimminna marked this conversation as resolved.
|
||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.