-
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] 차등 정산 기능 구현 및 테스트 작성 #406
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
ddeb93e
feat: 고정 가격을 설정했는지에 대한 isFixed 타입 추가
jinhokim98 e08b505
feat: 지출 상세 조회, 수정 api 함수 작성
jinhokim98 ee58547
feat: Get, Put query, mutation 작성
jinhokim98 d490740
feat: 고정값으로 수정할 때, 나머지 인원의 가격이 계산되는 기능 추가
jinhokim98 0e3d927
fix: isFixed field 추가로 반영되지 못한 테스트 수정
jinhokim98 cdeec00
test: useMemberReportListInAction 훅 텟트 작성
jinhokim98 efc5b57
fix: put body 형식 수정
jinhokim98 1034715
test: submit 함수 테스트 코드 작성
jinhokim98 c3e61c8
feat: 모든 인원의 가격을 고정시키려 했을 때 반영하지 않는 기능
jinhokim98 5a24a04
test: 모든 인원을 담을 때 테스트 작성
jinhokim98 9ec199d
fix: invalidate queries querykey actionId 명시
jinhokim98 1df1dfe
fix: 중복 인원이 들어왔을 때 잘못 계산되던 문제 해결
jinhokim98 ae6cf7d
test: 중복 인원일 때 테스트 코드 작성
jinhokim98 e6239f0
refactor: 지출상세 훅 리팩터링
jinhokim98 042b58b
test: 같은 멤버 다른 가격으로 변환 시 다시 계산되는 테스트 작성
jinhokim98 388bfa8
fix: isFixed 추가로 발생한 테스트 오류 수정
jinhokim98 ecda8ee
feat: 각 멤버 별 isFixed 추가 반영
jinhokim98 5a0ff8f
refactor: 서버의 isFixed 관리로 불필요한 상태 제거
jinhokim98 753e8ec
test: isFixed 필드 추가 테스트 반영
jinhokim98 c574f2d
feat: 계산값으로 값을 변경했을 때 isFixed를 해제하는 기능구현
jinhokim98 d8b3957
test: isFixed 해제 관련 테스트 작성
jinhokim98 e2d0aba
feat: member report validation 로직 작성
jinhokim98 0d5ec62
chore: 테스트를 위한 코드 작성 추후 삭제
jinhokim98 947b16a
chore: 테스트용 라우팅 삭제
jinhokim98 203922d
feat: 총 금액보다 큰지 검증하는 기능 추가
jinhokim98 46f88e7
feat: 차등 적용 input으로 handle하는 기능 추가
jinhokim98 ea9b6ce
remove: 사용하지 않는 파일 제거
jinhokim98 e63d3c1
Merge branch 'fe-dev' of https://github.com/woowacourse-teams/2024-ha…
jinhokim98 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 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 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
24 changes: 24 additions & 0 deletions
24
client/src/hooks/queries/useRequestGetMemberReportListInAction.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {useQuery} from '@tanstack/react-query'; | ||
|
||
import {requestGetMemberReportListInAction} from '@apis/request/bill'; | ||
|
||
import getEventIdByUrl from '@utils/getEventIdByUrl'; | ||
|
||
import QUERY_KEYS from '@constants/queryKeys'; | ||
|
||
const useRequestGetMemberReportListInAction = (actionId: number) => { | ||
const eventId = getEventIdByUrl(); | ||
|
||
const {data, ...queryResult} = useQuery({ | ||
queryKey: [QUERY_KEYS.memberReportInAction, actionId], | ||
queryFn: () => requestGetMemberReportListInAction({eventId, actionId}), | ||
select: data => data.members, | ||
}); | ||
|
||
return { | ||
memberReportListInActionFromServer: data ?? [], | ||
queryResult, | ||
}; | ||
}; | ||
|
||
export default useRequestGetMemberReportListInAction; |
29 changes: 29 additions & 0 deletions
29
client/src/hooks/queries/useRequestPutMemberReportListInAction.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import {useMutation, useQueryClient} from '@tanstack/react-query'; | ||
|
||
import {requestPutMemberReportListInAction} from '@apis/request/bill'; | ||
import {MemberReportInAction} from 'types/serviceType'; | ||
|
||
import getEventIdByUrl from '@utils/getEventIdByUrl'; | ||
|
||
import QUERY_KEYS from '@constants/queryKeys'; | ||
|
||
const useRequestPutMemberReportListInAction = (actionId: number) => { | ||
const eventId = getEventIdByUrl(); | ||
const queryClient = useQueryClient(); | ||
|
||
const {mutate, ...mutationProps} = useMutation({ | ||
mutationFn: (members: MemberReportInAction[]) => requestPutMemberReportListInAction({eventId, actionId, members}), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({queryKey: [QUERY_KEYS.stepList]}); | ||
queryClient.invalidateQueries({queryKey: [QUERY_KEYS.memberReport]}); | ||
queryClient.invalidateQueries({queryKey: [QUERY_KEYS.memberReportInAction, actionId]}); | ||
}, | ||
}); | ||
|
||
return { | ||
putMemberReportListInAction: mutate, | ||
mutationProps, | ||
}; | ||
}; | ||
|
||
export default useRequestPutMemberReportListInAction; |
This file contains 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
57 changes: 57 additions & 0 deletions
57
client/src/hooks/useMemberReportListInAction/useMemberReportInput.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import type {MemberReportInAction} from 'types/serviceType'; | ||
|
||
import {useEffect, useState} from 'react'; | ||
|
||
import validateMemberReportInAction from '@utils/validate/validateMemberReportInAction'; | ||
|
||
type MemberReportInput = MemberReportInAction & { | ||
index: number; | ||
}; | ||
|
||
type UseMemberReportProps = { | ||
data: MemberReportInAction[]; | ||
addAdjustedMember: (memberReport: MemberReportInAction) => void; | ||
totalPrice: number; | ||
}; | ||
|
||
const useMemberReportInput = ({data, addAdjustedMember, totalPrice}: UseMemberReportProps) => { | ||
const [inputList, setInputList] = useState<MemberReportInput[]>(data.map((item, index) => ({...item, index}))); | ||
const [canSubmit, setCanSubmit] = useState<boolean>(false); | ||
|
||
const onChange = (event: React.ChangeEvent<HTMLInputElement>, index: number) => { | ||
const {value} = event.target; | ||
|
||
validateAndAddAdjustedMember(value, index); | ||
}; | ||
|
||
const validateAndAddAdjustedMember = (price: string, index: number) => { | ||
const {isValid, errorMessage} = validateMemberReportInAction(price, totalPrice); | ||
setCanSubmit(errorMessage === null); | ||
|
||
if (isValid) { | ||
const newInputList = [...inputList]; | ||
newInputList[index].price = Number(price); | ||
setInputList(newInputList); | ||
|
||
const memberReportData: MemberReportInAction = { | ||
name: newInputList[index].name, | ||
price: newInputList[index].price, | ||
isFixed: newInputList[index].isFixed, | ||
}; | ||
addAdjustedMember(memberReportData); | ||
} | ||
}; | ||
|
||
// addAdjustedMember로 인해 data가 변했을 때 input list의 값을 맞춰주기 위함 | ||
useEffect(() => { | ||
setInputList(data.map((item, index) => ({...item, index}))); | ||
}, [data]); | ||
|
||
return { | ||
inputList, | ||
onChange, | ||
canSubmit, | ||
}; | ||
}; | ||
|
||
export default useMemberReportInput; |
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.
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.
흐음;;; 그렇긴 해요;; 이 부분 이름 짓는 거 진짜 어려웠는데 어떻게 바꾸면 좋을지 감이 안 와요ㅜㅜ