From 9896dcf22cfea626bdf9a607cf33209a0ee28694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A7=84=ED=98=B8?= Date: Fri, 16 Aug 2024 19:51:17 +0900 Subject: [PATCH 1/3] =?UTF-8?q?refactor:=20alive=20->=20delete=20member=20?= =?UTF-8?q?list=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../useDeleteMemberAction.tsx | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/client/src/hooks/useDeleteMemberAction/useDeleteMemberAction.tsx b/client/src/hooks/useDeleteMemberAction/useDeleteMemberAction.tsx index 265eafecd..323ee9be6 100644 --- a/client/src/hooks/useDeleteMemberAction/useDeleteMemberAction.tsx +++ b/client/src/hooks/useDeleteMemberAction/useDeleteMemberAction.tsx @@ -22,7 +22,7 @@ const useDeleteMemberAction = ({ showToastExistSameMemberFromAfterStep, }: UseDeleteMemberActionProps) => { const {stepList, refreshStepList} = useStepList(); - const [aliveActionList, setAliveActionList] = useState(memberActionList); + const [deleteActionList, setDeleteActionList] = useState([]); const eventId = getEventIdByUrl(); const {fetch} = useFetch(); @@ -34,20 +34,15 @@ const useDeleteMemberAction = ({ setIsBottomSheetOpened(false); }, onError: () => { - setAliveActionList(memberActionList); + setDeleteActionList([]); }, }); }; // TODO: (@cookie: 추후에 반복문으로 delete하는 것이 아니라 한 번에 모아서 delete 처리하기 (backend에 문의)) const deleteMemberActionList = async () => { - const aliveActionIdList = aliveActionList.map(({actionId}) => actionId); - const deleteMemberActionIdList = memberActionList - .filter(({actionId}) => !aliveActionIdList.includes(actionId)) - .map(({actionId}) => actionId); - - for (const deleteMemberActionId of deleteMemberActionIdList) { - await deleteMemberAction(deleteMemberActionId); + for (const {actionId} of deleteActionList) { + await deleteMemberAction(actionId); } }; @@ -66,7 +61,7 @@ const useDeleteMemberAction = ({ const addDeleteMemberAction = (memberAction: MemberAction) => { checkAlreadyExistMemberAction(memberAction, showToastAlreadyExistMemberAction); checkExistSameMemberFromAfterStep(memberAction, () => showToastExistSameMemberFromAfterStep(memberAction.name)); - setAliveActionList(prev => prev.filter(aliveMember => aliveMember.actionId !== memberAction.actionId)); + setDeleteActionList(prev => [...prev, memberAction]); }; const isExistSameMemberFromAfterStep = (memberAction: MemberAction) => { @@ -81,6 +76,9 @@ const useDeleteMemberAction = ({ return memberNameList.filter(member => member === memberAction.name).length >= 2; }; + const aliveActionList = memberActionList.filter( + memberAction => !deleteActionList.some(deleteAction => deleteAction.actionId === memberAction.actionId), + ); return {aliveActionList, deleteMemberActionList, addDeleteMemberAction}; }; From 085cbaa0f6e81109f1c82a70ea9ac96d2d1ee860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A7=84=ED=98=B8?= Date: Fri, 16 Aug 2024 19:51:58 +0900 Subject: [PATCH 2/3] =?UTF-8?q?refactor:=20=EB=B9=84=EB=8F=99=EA=B8=B0=20?= =?UTF-8?q?=EC=95=84=EB=8B=8C=20=ED=95=A8=EC=88=98=20async=20await=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hooks/useDeleteMemberAction/useDeleteMemberAction.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/hooks/useDeleteMemberAction/useDeleteMemberAction.test.tsx b/client/src/hooks/useDeleteMemberAction/useDeleteMemberAction.test.tsx index 9ca4d7bff..bb0809046 100644 --- a/client/src/hooks/useDeleteMemberAction/useDeleteMemberAction.test.tsx +++ b/client/src/hooks/useDeleteMemberAction/useDeleteMemberAction.test.tsx @@ -53,7 +53,7 @@ describe('useDeleteMemberAction', () => { expect(result.current.stepListResult.stepList).not.toStrictEqual([]); }); - await act(async () => { + act(() => { const memberAction = { actionId: 1, name: '망쵸', From 989b88f5fb542346a19f856c66d8f4231ef3692d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=A7=84=ED=98=B8?= Date: Fri, 16 Aug 2024 19:52:20 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=ED=9B=85=20=EB=82=B4=EC=97=90?= =?UTF-8?q?=EC=84=9C=20errorIndexList=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=EC=9E=88=EC=A7=80=20=EC=95=8A=EC=95=84=EC=84=9C=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0=ED=96=88=EC=8A=B5=EB=8B=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AddBillActionListModalContent.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/client/src/components/Modal/SetActionModal/AddBillActionListModalContent/AddBillActionListModalContent.tsx b/client/src/components/Modal/SetActionModal/AddBillActionListModalContent/AddBillActionListModalContent.tsx index 0f11852af..e5165804e 100644 --- a/client/src/components/Modal/SetActionModal/AddBillActionListModalContent/AddBillActionListModalContent.tsx +++ b/client/src/components/Modal/SetActionModal/AddBillActionListModalContent/AddBillActionListModalContent.tsx @@ -17,7 +17,6 @@ const AddBillActionListModalContent = ({setIsOpenBottomSheet}: AddBillActionList inputPairList, inputRefList, errorMessage, - errorIndexList, handleInputChange, getFilledInputPairList, deleteEmptyInputPairElementOnBlur, @@ -48,7 +47,6 @@ const AddBillActionListModalContent = ({setIsOpenBottomSheet}: AddBillActionList onBlur={() => deleteEmptyInputPairElementOnBlur()} // TODO: (@weadie) 이 블러프롭이 내부적으로 index를 넘기고 있기 때문에 화살표 함수로 써야만하내요.. placeholder="지출 내역" ref={el => (inputRefList.current[index * 2] = el)} - isError={errorIndexList.includes(index)} /> deleteEmptyInputPairElementOnBlur()} placeholder="금액" ref={el => (inputRefList.current[index * 2 + 1] = el)} - isError={errorIndexList.includes(index)} /> ))}