-
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] EventLoader하위로 EditAccountPage를 옮겨 데이터를 유지하기 위한 로직을 제거 #877
Changes from 10 commits
95c202e
cd05817
f266747
5940a0a
9f935b8
7639328
ed80902
0b3310a
b222f04
574258a
569434d
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {createContext, PropsWithChildren} from 'react'; | ||
|
||
import {Event, EventId} from 'types/serviceType'; | ||
|
||
import {useAuthStore} from '@store/authStore'; | ||
|
||
type EventDataContextType = Event & { | ||
eventToken: EventId; | ||
isAdmin: boolean; | ||
}; | ||
|
||
type EventDataProviderProps = PropsWithChildren<Omit<EventDataContextType, 'isAdmin'>>; | ||
|
||
export const EventDataContext = createContext<EventDataContextType | null>(null); | ||
|
||
const EventDataProvider = ({children, ...props}: EventDataProviderProps) => { | ||
const {isAdmin} = useAuthStore(); | ||
|
||
return <EventDataContext.Provider value={{isAdmin, ...props}}>{children}</EventDataContext.Provider>; | ||
}; | ||
|
||
export default EventDataProvider; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,17 @@ | ||
import {useSuspenseQueries} from '@tanstack/react-query'; | ||
import {useEffect} from 'react'; | ||
import {Outlet} from 'react-router-dom'; | ||
|
||
import {requestGetEvent} from '@apis/request/event'; | ||
import {requestGetReports} from '@apis/request/report'; | ||
import {requestGetSteps} from '@apis/request/step'; | ||
import {WithErrorHandlingStrategy} from '@errors/RequestGetError'; | ||
import {requestGetAllMembers} from '@apis/request/member'; | ||
import useEventLoader from '@hooks/useEventLoader'; | ||
|
||
import {useTotalExpenseAmountStore} from '@store/totalExpenseAmountStore'; | ||
import EventDataProvider from './EventDataProvider'; | ||
|
||
import getEventIdByUrl from '@utils/getEventIdByUrl'; | ||
const EventLoader = () => { | ||
const eventData = useEventLoader(); | ||
|
||
import QUERY_KEYS from '@constants/queryKeys'; | ||
|
||
const EventLoader = ({children, ...props}: React.PropsWithChildren<WithErrorHandlingStrategy | null> = {}) => { | ||
const eventId = getEventIdByUrl(); | ||
|
||
const queries = useSuspenseQueries({ | ||
queries: [ | ||
{queryKey: [QUERY_KEYS.event], queryFn: () => requestGetEvent({eventId, ...props})}, | ||
{ | ||
queryKey: [QUERY_KEYS.reports], | ||
queryFn: () => requestGetReports({eventId, ...props}), | ||
}, | ||
{ | ||
queryKey: [QUERY_KEYS.steps], | ||
queryFn: () => requestGetSteps({eventId, ...props}), | ||
}, | ||
{ | ||
queryKey: [QUERY_KEYS.allMembers], | ||
queryFn: () => requestGetAllMembers({eventId, ...props}), | ||
}, | ||
], | ||
}); | ||
|
||
const {updateTotalExpenseAmount} = useTotalExpenseAmountStore(); | ||
|
||
const stepsData = queries[2]; | ||
|
||
useEffect(() => { | ||
if (stepsData.isSuccess && stepsData.data) { | ||
updateTotalExpenseAmount(stepsData.data); | ||
} | ||
}, [stepsData.data, stepsData.isSuccess, updateTotalExpenseAmount]); | ||
|
||
return children; | ||
return ( | ||
<EventDataProvider {...eventData}> | ||
<Outlet /> | ||
</EventDataProvider> | ||
); | ||
}; | ||
|
||
export default EventLoader; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {useContext} from 'react'; | ||
|
||
import {EventDataContext} from '@components/Loader/EventDataProvider'; | ||
|
||
const useEventDataContext = () => { | ||
const value = useContext(EventDataContext); | ||
|
||
if (!value) { | ||
throw new Error('EventDataProvider와 함께 사용해주세요.'); | ||
} | ||
Comment on lines
+8
to
+10
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. 에러메세지까지 친절하게 띄워주기..👍🏻 |
||
|
||
return value; | ||
}; | ||
|
||
export default useEventDataContext; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {useSuspenseQueries} from '@tanstack/react-query'; | ||
import {useEffect} from 'react'; | ||
|
||
import {requestGetEvent} from '@apis/request/event'; | ||
import {requestGetAllMembers} from '@apis/request/member'; | ||
import {requestGetReports} from '@apis/request/report'; | ||
import {requestGetSteps} from '@apis/request/step'; | ||
|
||
import {useTotalExpenseAmountStore} from '@store/totalExpenseAmountStore'; | ||
|
||
import getEventIdByUrl from '@utils/getEventIdByUrl'; | ||
|
||
import QUERY_KEYS from '@constants/queryKeys'; | ||
|
||
/** | ||
* 이 훅이 하는 일: | ||
* 이벤트 정보 불러오기 + 총액 상태 계산하기 | ||
*/ | ||
Comment on lines
+15
to
+18
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. 제가 작성했던 방식은 여기서 데이터를 fetch 해두고 하위 컴포넌트에서 캐시된 데이터를 불러와서 사용하는 방식이었어요. 이렇게 바꾸게 되면 여기서 데이터를 fetch 하고 하위 컴포넌트에서 context를 사용해서 값을 불러올 수 있게 될 것 같아요! 하지만 하위에서는 context와 의존성이 생긴다는 제약은 있지만..;; |
||
const useEventLoader = () => { | ||
const eventId = getEventIdByUrl(); | ||
|
||
const {updateTotalExpenseAmount} = useTotalExpenseAmountStore(); | ||
|
||
const queries = useSuspenseQueries({ | ||
queries: [ | ||
{queryKey: [QUERY_KEYS.event], queryFn: () => requestGetEvent({eventId})}, | ||
{ | ||
queryKey: [QUERY_KEYS.reports], | ||
queryFn: () => requestGetReports({eventId}), | ||
}, | ||
{ | ||
queryKey: [QUERY_KEYS.steps], | ||
queryFn: () => requestGetSteps({eventId}), | ||
}, | ||
{ | ||
queryKey: [QUERY_KEYS.allMembers], | ||
queryFn: () => requestGetAllMembers({eventId}), | ||
}, | ||
Comment on lines
+35
to
+38
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. 저는 이 부분도 논의해보고 싶어요. 이 데이터를 여기서 fetch하는 이유는 순전히 amplitude에 데이터를 보내기 위해서 였어요. 행사 당 평균 인원 수를 확인해보고 싶어서 호출하는 것인데 지금 amplitude에서 이를 확인하고 있지 않아서 빠져도 되지 않을까 하는 생각도 있습니다. 이 내용은 회의 때 이야기해봐도 좋을 것 같아요 |
||
], | ||
}); | ||
|
||
const [eventData, reportsData, stepsData, membersData] = queries; | ||
const {data, isSuccess} = stepsData; | ||
|
||
useEffect(() => { | ||
if (isSuccess && data) { | ||
updateTotalExpenseAmount(data); | ||
} | ||
}, [data, isSuccess]); | ||
|
||
const {eventName, bankName, accountNumber, createdByGuest} = eventData.data; | ||
|
||
return { | ||
eventName, | ||
bankName, | ||
accountNumber, | ||
createdByGuest, | ||
eventToken: eventId, | ||
}; | ||
}; | ||
|
||
export default useEventLoader; |
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.
버그를 해결했다는게 더 유용한거죠!!!! 저는 그냥 숟가락만 얹었을 뿐,,