-
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] 지출 내역 추가 변경사항 적용 #414
Changes from 11 commits
33c3c66
dc4bcd9
cfd953f
e3e1b6c
df9e2e2
958aeff
dc5a60e
7330b72
b48ad94
62b2cbf
5d4a67c
930d27a
b4bec69
1ea2ee4
6152fc5
bbf8b4d
deff0f6
6c2e838
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,38 @@ | ||
import {Flex} from 'haengdong-design'; | ||
import {useMemo} from 'react'; | ||
|
||
import {BillStep, MemberStep} from 'types/serviceType'; | ||
import useRequestGetStepList from '@hooks/queries/useRequestGetStepList'; | ||
|
||
import Step from './Step'; | ||
|
||
const StepList = () => { | ||
// const {stepList} = useStepList(); | ||
interface StepListProps { | ||
isAddEditableItem: boolean; | ||
setIsAddEditableItem: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
const StepList = ({isAddEditableItem, setIsAddEditableItem}: StepListProps) => { | ||
const {data: stepListData} = useRequestGetStepList(); | ||
const stepList = stepListData ?? ([] as (MemberStep | BillStep)[]); | ||
|
||
// TODO: (@weadie) if else 구문이 지저분하므로 리펙터링이 필요합니다. | ||
const lastBillItemIndex = useMemo(() => { | ||
const billSteps = stepList.map((step, index) => ({...step, index})).filter(step => step.type === 'BILL'); | ||
|
||
// billSteps 배열이 비어 있지 않으면 마지막 항목의 index를 반환, 그렇지 않으면 -1을 반환 | ||
return billSteps.length > 0 ? billSteps.slice(-1)[0].index : -1; | ||
}, [stepList]); | ||
|
||
return ( | ||
<Flex flexDirection="column" gap="0.5rem" paddingInline="0.5rem"> | ||
{stepList.map((step, index) => ( | ||
<Step step={step} key={`${step.stepName}${index}`} /> | ||
<Step | ||
index={index} | ||
step={step} | ||
lastBillItemIndex={lastBillItemIndex} | ||
key={`${step.stepName}${index}`} | ||
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. stepName이 지금 없으니 이렇게 하는게 맞네요 |
||
isAddEditableItem={isAddEditableItem} | ||
setIsAddEditableItem={setIsAddEditableItem} | ||
/> | ||
))} | ||
</Flex> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import {useState} from 'react'; | ||
|
||
import validatePurchase from '@utils/validate/validatePurchase'; | ||
import {Bill} from 'types/serviceType'; | ||
|
||
import useRequestPostBillList from './queries/useRequestPostBillList'; | ||
import {BillInputType, InputPair} from './useDynamicBillActionInput'; | ||
|
||
interface UseSetBillInputProps { | ||
setIsAddEditableItem: React.Dispatch<React.SetStateAction<boolean>>; | ||
} | ||
|
||
interface UseSetBillInputReturns { | ||
billInput: Bill; | ||
handleChangeBillInput: (field: BillInputType, event: React.ChangeEvent<HTMLInputElement>) => void; | ||
handleBlurBillRequest: () => void; | ||
} | ||
|
||
const useSetBillInput = ({setIsAddEditableItem}: UseSetBillInputProps): UseSetBillInputReturns => { | ||
const initialInput = {title: '', price: 0}; | ||
const [billInput, setBillInput] = useState<Bill>(initialInput); | ||
|
||
const {mutate: postBillList} = useRequestPostBillList(); | ||
|
||
const handleChangeBillInput = (field: BillInputType, event: React.ChangeEvent<HTMLInputElement>) => { | ||
const {value} = event.target; | ||
const {isValid} = validatePurchase({ | ||
...billInput, | ||
[field]: value, | ||
}); | ||
|
||
if (isValid) { | ||
setBillInput(prev => ({ | ||
...prev, | ||
[field]: value, | ||
})); | ||
} | ||
}; | ||
|
||
Comment on lines
+20
to
+39
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. bill 저도 차등 기능 넣을 때 써야하는데 참고할게요..! 굿 |
||
const handleBlurBillRequest = () => { | ||
const isEmptyTitle = billInput.title.trim().length; | ||
const isEmptyPrice = Number(billInput.price); | ||
|
||
// 두 input의 값이 모두 채워졌을 때 api 요청 | ||
// api 요청을 하면 Input을 띄우지 않음 | ||
if (isEmptyTitle && isEmptyPrice) { | ||
postBillList( | ||
{billList: [billInput]}, | ||
{ | ||
onSuccess: () => { | ||
setIsAddEditableItem(false); | ||
}, | ||
Todari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
); | ||
} | ||
}; | ||
|
||
return { | ||
billInput, | ||
handleBlurBillRequest, | ||
handleChangeBillInput, | ||
}; | ||
}; | ||
|
||
export default useSetBillInput; |
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.
오 step.type이 BILL 인 경우만 BillStep 컴포넌트로 들어오는 줄 알았는데 아니었군요.?
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.
Step에서의 조건 때문에 BillStepItem에서 위 조건문을 추가하게 되었어요!