-
Notifications
You must be signed in to change notification settings - Fork 5
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
[FE] 전체 참여자 관리: '수정 완료'시, Toast 띄우기 #636
Conversation
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.
고생했습니다 소하!
몇 가지 코멘트 남겨놨는데 참고로 봐주세요.
크리티컬하지는 않아 approve 합니다
client/src/hooks/useEventMember.ts
Outdated
const hasDuplicateMemberName = (): boolean => { | ||
const nameSet = new Set(reports.map(member => member.memberName)); | ||
return nameSet.size !== reports.length; | ||
}; |
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.
이 부분 변경 요청했었는데 바꾸니깐 너무 보기 쉬워진 것 같아요👍👍
client/src/hooks/useEventMember.ts
Outdated
if (deleteMembers.length > 0) { | ||
for (const id of deleteMembers) { | ||
deleteMember({memberId: id}); | ||
await deleteMember({memberId: id}); |
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.
await 굳입니다. 여기까지 써야 삭제를 기다릴 수 있어요!
client/src/hooks/useEventMember.ts
Outdated
|
||
// 변경된 사항이 존재한다면 해당 reports만을 PUT api 요청 | ||
if (changedMembers.length > 0) { | ||
await putMember({members: changedMembers}); |
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.
근데 put도 순서가 보장되어야 할 이유가 있었나요?
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.
delete 요청과 put 요청이 전송된 후에 toast가 띄워져야 하기 때문에 await를 붙어줬어용
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.
아 토스트!!!! 좋아요
client/src/hooks/useEventMember.ts
Outdated
} | ||
|
||
return false; // 중복된 이름이 없으면 false 반환 | ||
}; | ||
toast.confirm('수정이 완료되었어요 :)'); |
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.
진짜 토스트 너무 쓰기 편해졌다..!
근데 개인적인 의견으론 토스트를 띄우는 기능은 훅이 아니라 컴포넌트 단으로 옮겨야 한다고 생각해요.
나중에 테스트 코드를 짤 때 번거로움이 생길 수도 있을 것 같아서요.
toast가 뜨는 기능 자체는 api 요청과는 관계 없으니 훅에서 내보낸 함수를 이용해서 호출이 완료된 뒤에 성공하면 토스트를 띄우는 방식이 좋아보입니다!
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.
마자용.. 그래서 컴포넌트 측에서 하려고 했다가..? 요청이 모두 정상적으로 보내진 후에 toast를 띄워야 하는데.. 그럼 hook에서 요청이 모두 정상적으로 이뤄졌는지에 대한 상태를 만들어서 컴포넌트측으로 넘겨주는 작업이 필요하다고 생각했어요. 근데 toast를 hook에서 띄우면 이런 상태 관리가 추가로 필요하지 않을 것 같아서 hook에서 진행해줬습니당..
흠,.. 뭐가 더 나을지 더 이야기해봐요!
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.
브콜한테 배울 때는 이런 토스트같은 로직을 훅에 묶어두면 이 훅을 다른 곳에서 사용하고 토스트를 띄우기 싫은 경우 대응이 어렵다! 라고 해서 분리하는게 좋다고 생각해왔는데요. 이 훅이 EventMember라는 페이지에 강하게 묶여있고 다른 곳에서 재사용될 가능성이 0에 수렴한다면 ... 그냥 토스트를 이곳에 넣어도 괜찮을 것 같아요.
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.
react-query에서 내보내주는 isSuccess를 이용해도 좋을 것 같아요.
client/src/hooks/useEventMember.ts
Outdated
|
||
setFilteredChangedMembers(changedMembers); | ||
}, [reports, changedMembers, deleteMembers]); | ||
// 초기 값과 비교하여 변경된 사항이 존재하는지 확인 | ||
const hasChanges = reports.some(report => | ||
initialReports.find( | ||
initial => | ||
initial.memberId === report.memberId && | ||
(initial.memberName !== report.memberName || initial.isDeposited !== report.isDeposited), | ||
), | ||
); | ||
|
||
const changeMemberName = (memberId: number, newName: string) => { | ||
// 유효성 검사 (4글자) | ||
// 변경된 사항이 존재 혹은 삭제된 member가 존재한다면 true | ||
return hasChanges || deleteMembers.length > 0; |
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.
분리하니까 더 가독성이 좋아보여요 😆
client/src/hooks/useEventMember.ts
Outdated
import useRequestDeleteMember from './queries/member/useRequestDeleteMember'; | ||
import useRequestPutMembers from './queries/member/useRequestPutMembers'; | ||
import useRequestGetReports from './queries/report/useRequestGetReports'; | ||
|
||
interface ReturnUseEventMember { | ||
reports: Report[]; | ||
isCanRequest: boolean; | ||
isCanSubmit: boolean; |
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.
이름이 더 직관적이네요 ! 👍👍
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.
여기도...! canSubmit이 좋아 보여용 하핫
client/src/hooks/useEventMember.ts
Outdated
const hasDuplicateMemberName = (): boolean => { | ||
const nameSet = new Set(reports.map(member => member.memberName)); | ||
return nameSet.size !== reports.length; | ||
}; | ||
|
||
// 중복된 이름이 존재할 경우 isCanRequest를 false로 변경 | ||
if (hasDuplicateMemberName()) { | ||
setIsCanRequest(false); | ||
} else { | ||
// 변경된 사항이 존재하거나 삭제한 member가 존재한다면 isCanRequest를 true로 변경 | ||
setIsCanRequest(changedMembers.length > 0 || deleteMembers.length > 0); | ||
// 중복 이름이라면 false | ||
return false; | ||
} | ||
|
||
// memberName 유효성 검사 (0글자) | ||
const hasEmptyName = changedMembers.some(member => member.name.trim().length === 0); | ||
if (hasEmptyName) setIsCanRequest(false); | ||
// 이름이 공백이라면 false | ||
const hasEmptyName = reports.some(report => report.memberName.trim().length === 0); | ||
if (hasEmptyName) return false; | ||
|
||
setFilteredChangedMembers(changedMembers); | ||
}, [reports, changedMembers, deleteMembers]); | ||
// 초기 값과 비교하여 변경된 사항이 존재하는지 확인 | ||
const hasChanges = reports.some(report => | ||
initialReports.find( | ||
initial => | ||
initial.memberId === report.memberId && | ||
(initial.memberName !== report.memberName || initial.isDeposited !== report.isDeposited), | ||
), | ||
); |
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.
작은 유틸 함수처럼 나뉘어 있으니까 확실히 이해하기 쉬운 것 같아요. 😆
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.
고생많았습니다 !! 👍
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.
고생 많았습니다~!
client/src/hooks/useEventMember.ts
Outdated
import useRequestDeleteMember from './queries/member/useRequestDeleteMember'; | ||
import useRequestPutMembers from './queries/member/useRequestPutMembers'; | ||
import useRequestGetReports from './queries/report/useRequestGetReports'; | ||
|
||
interface ReturnUseEventMember { | ||
reports: Report[]; | ||
isCanRequest: boolean; | ||
isCanSubmit: boolean; |
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.
여기도...! canSubmit이 좋아 보여용 하핫
issue
🚨612번이 선행되어야 합니다.
구현 사항
웨디가 toast 사용을 매우 간단!하게 개선해줘서 저는 단순하게 api 요청이 완료되면 수정이 완료되었다는 toast를 띄워주는 코드 한 줄만 추가해줬습니다 ~
추가 구현 사항
백엔드 측의 api 요청 형식이 변경되어 프론트 측에서 PUT 요청 형식을 변경했습니다.
기존: 변경된 member 데이터만을 전송
변경: 모든 member 데이터를 전송
🫡 참고사항