-
Notifications
You must be signed in to change notification settings - Fork 1
Api(client): category 수정 연결 #79
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
Changes from 4 commits
04c0f55
a1ee74c
ae4b808
f4c6d48
78097db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import { | |
| useGetDashboardCategories, | ||
| usePostCategory, | ||
| useGetArcons, | ||
| usePutCategory, | ||
| } from '@shared/apis/queries'; | ||
| import { useState } from 'react'; | ||
| import { useQueryClient } from '@tanstack/react-query'; | ||
|
|
@@ -23,6 +24,7 @@ export function Sidebar() { | |
| const queryClient = useQueryClient(); | ||
|
|
||
| const { data: categories } = useGetDashboardCategories(); | ||
| const { mutate: patchCategory } = usePutCategory(); | ||
| const { mutate: createCategory } = usePostCategory(); | ||
| const { data, isPending, isError } = useGetArcons(); | ||
|
|
||
|
|
@@ -66,6 +68,19 @@ export function Sidebar() { | |
| }, | ||
| }); | ||
| }; | ||
| const handlePatchCategory = (id: number) => { | ||
| patchCategory( | ||
| { id, categoryName: newCategoryName }, | ||
| { | ||
| onSuccess: () => { | ||
| setNewCategoryName(''); | ||
| queryClient.invalidateQueries({ queryKey: ['dashboardCategories'] }); | ||
| close(); | ||
| }, | ||
| onError: (error) => console.error('카테고리 수정 실패:', error), | ||
| } | ||
| ); | ||
| }; | ||
|
Comment on lines
+71
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 편집 시 입력 변경이 없으면 빈 문자열로 업데이트되는 치명적 버그 편집 팝업에서 사용자가 값을 수정하지 않으면 onChange가 호출되지 않아 newCategoryName이 빈 문자열일 수 있습니다. 이 상태로 PUT하면 카테고리명이 공백으로 바뀝니다. 또한 변경 없음(no-op)일 때는 API 호출을 생략하는 것이 안전합니다. 아래처럼 현재 이름을 안전망으로 사용하고, 공백/변경 없음 케이스를 방지해 주세요: - const handlePatchCategory = (id: number) => {
- patchCategory(
- { id, categoryName: newCategoryName },
- {
- onSuccess: () => {
- setNewCategoryName('');
- queryClient.invalidateQueries({ queryKey: ['dashboardCategories'] });
- close();
- },
- onError: (error) => console.error('카테고리 수정 실패:', error),
- }
- );
- };
+ const handlePatchCategory = (id: number) => {
+ const currentName = getCategoryName(id);
+ const trimmed = newCategoryName.trim();
+ const nextName = trimmed || currentName;
+
+ if (!nextName) {
+ console.error('카테고리 이름이 비어 있습니다.');
+ return;
+ }
+ if (nextName === currentName) {
+ // 변경 없음: API 호출 생략
+ close();
+ return;
+ }
+ patchCategory(
+ { id, categoryName: nextName },
+ {
+ onSuccess: () => {
+ setNewCategoryName('');
+ queryClient.invalidateQueries({ queryKey: ['dashboardCategories'] });
+ close();
+ },
+ onError: (error) => console.error('카테고리 수정 실패:', error),
+ }
+ );
+ };또는 편집 팝업을 열 때 초기 입력값을 state에 주입해 리스크를 더 낮출 수 있습니다(변경 범위: Line 149 인근). 예시: onEdit={(id, name) => {
setNewCategoryName(name); // 또는 handleCategoryChange(name)
openEdit(id, name);
}}🤖 Prompt for AI Agents |
||
|
|
||
| if (isPending) return <div></div>; | ||
| if (isError) return <div></div>; | ||
|
|
@@ -156,10 +171,7 @@ export function Sidebar() { | |
| onClose={close} | ||
| onChange={handleCategoryChange} | ||
| onCreateConfirm={handleCreateCategory} | ||
| onEditConfirm={() => { | ||
| // TODO: 수정 API | ||
| close(); | ||
| }} | ||
| onEditConfirm={(id) => handlePatchCategory(id)} | ||
| onDeleteConfirm={() => { | ||
| // TODO: 삭제 API | ||
| close(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,8 +11,9 @@ interface BasePopupProps { | |
| errortext?: string; | ||
| placeholder?: string; | ||
| isError?: boolean; | ||
| helperText?: string; | ||
| helperText?: string; | ||
| inputValue?: string; | ||
| defaultValue?: string; | ||
|
Comment on lines
15
to
+16
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아항 팝업키자마자
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. inputValue로 하면 수정이 안되더라고요 그래서 defaultValue로 설정하고 수정가능하게 했습니다-!!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| onInputChange?: (value: string) => void; | ||
| onLeftClick?: () => void; | ||
| onRightClick?: () => void; | ||
|
|
@@ -28,6 +29,7 @@ const Popup = ({ | |
| errortext, | ||
| isError, | ||
| inputValue, | ||
| defaultValue, | ||
| onInputChange, | ||
| onLeftClick, | ||
| onRightClick, | ||
|
|
@@ -43,9 +45,10 @@ const Popup = ({ | |
| isError={isError} | ||
| value={inputValue} | ||
| onChange={(e) => onInputChange?.(e.target.value)} | ||
| defaultValue={defaultValue} | ||
| /> | ||
| {isError && errortext && ( | ||
| <p className='mt-[0.5rem] text-error body3-r'>{errortext}</p> | ||
| <p className="text-error body3-r mt-[0.5rem]">{errortext}</p> | ||
| )} | ||
| </div> | ||
| )} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
편집 확인 시 값이 비어 전송될 수 있음(defaultValue + onChange만 사용)
defaultValue는 입력 초기값만 채우고, 사용자가 수정하지 않으면onInputChange가 호출되지 않아 상위 상태가 비어 있을 수 있습니다. 이 상태에서 “확인” 클릭 시 빈 값이 전송될 가능성이 큽니다.두 가지 중 하나로 막아주세요(권장 1):
(이 경우 Sidebar의 핸들러가
draft파라미터를 우선하도록 함께 수정 필요)📝 Committable suggestion
🤖 Prompt for AI Agents