-
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] 토큰이 없을 때, 관리페이지로 이동하면 오류가 발생하는 부분 수정 #338
Changes from all commits
36d7ed1
60f3847
17d74fe
4c7849c
da3b874
f5118a3
0a23137
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,32 +4,31 @@ import {useEffect, useState} from 'react'; | |
|
||
import {requestGetMemberReportList} from '@apis/request/report'; | ||
|
||
import useEventId from '@hooks/useEventId'; | ||
|
||
import {useFetch} from '@apis/useFetch'; | ||
|
||
import getEventIdByUrl from '@utils/getEventIdByUrl'; | ||
|
||
type UseSearchMemberReportListParams = { | ||
name: string; | ||
}; | ||
|
||
const useSearchMemberReportList = ({name}: UseSearchMemberReportListParams) => { | ||
const [memberReportList, setMemberReportList] = useState<MemberReport[]>([]); | ||
const [memberReportSearchList, setMemberReportSearchList] = useState<MemberReport[]>([]); | ||
const {eventId} = useEventId(); | ||
const eventId = getEventIdByUrl(); | ||
const {fetch} = useFetch(); | ||
|
||
useEffect(() => { | ||
const fetchMemberReportList = async () => { | ||
// TODO: (@weadie) cors 고쳐지면 주석 풀게요. | ||
// TODO: (@weadie) eventId에 의존하는 두 개의 훅에 대한 리펙토링 필요 | ||
if (eventId === '') return; | ||
|
||
const memberReportListData = await fetch({queryFunction: () => requestGetMemberReportList({eventId})}); | ||
setMemberReportList(memberReportListData); | ||
}; | ||
|
||
fetchMemberReportList(); | ||
}, [eventId]); | ||
}, []); | ||
Comment on lines
21
to
+31
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. window.location.pathname는 값이 바로 들어온다니 토다리 덕분에 처음 알게되었습니다! 좋은 방향으로 리빽또링 된 것 같아 죠습니다 ㅎ.ㅎ |
||
|
||
// TODO: (@weadie) 글자가 완성될 때마다 아래 로직이 실행되어야 합니다. | ||
useEffect(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,10 @@ import {requestPostBillList} from '@apis/request/bill'; | |
import {requestGetAllMemberList, requestPostMemberList} from '@apis/request/member'; | ||
import {requestGetStepList} from '@apis/request/stepList'; | ||
|
||
import useEventId from '@hooks/useEventId'; | ||
|
||
import {useFetch} from '@apis/useFetch'; | ||
|
||
import getEventIdByUrl from '@utils/getEventIdByUrl'; | ||
|
||
interface StepListContextProps { | ||
stepList: (BillStep | MemberStep)[]; | ||
allMemberList: string[]; | ||
|
@@ -25,16 +25,7 @@ const StepListProvider = ({children}: PropsWithChildren) => { | |
const {fetch} = useFetch(); | ||
const [stepList, setStepList] = useState<(BillStep | MemberStep)[]>([]); | ||
const [allMemberList, setAllMemberList] = useState<string[]>([]); | ||
|
||
const {eventId} = useEventId(); | ||
|
||
useEffect(() => { | ||
if (eventId === '') return; | ||
|
||
refreshStepList(); | ||
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. 처음 랜더링됐을 때 리프레시 시키는 로직은 없어도 버그 없었나요? 그러면 빼는게 좋은 선택+ 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. stepList를 사용하는 곳에서 refresh해도되긴 합니당! 근데 번거로울 것 같긴 해요. 그래서 쿠키가 말한 부분이 궁금하네요..! 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. 이부분 로직이 없으면 제대로 작동하지 않네요. |
||
|
||
// TODO: (@weadie) useEffect를 꼭 써야하는가? | ||
}, [eventId]); | ||
const eventId = getEventIdByUrl(); | ||
|
||
const refreshStepList = async () => { | ||
const stepList = await fetch({queryFunction: () => requestGetStepList({eventId})}); | ||
|
@@ -43,6 +34,10 @@ const StepListProvider = ({children}: PropsWithChildren) => { | |
setStepList(stepList); | ||
}; | ||
|
||
useEffect(() => { | ||
refreshStepList(); | ||
}, []); | ||
|
||
const updateMemberList = async ({type, memberNameList}: {type: MemberType; memberNameList: string[]}) => { | ||
try { | ||
await fetch({queryFunction: () => requestPostMemberList({eventId, type, memberNameList})}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,13 @@ | ||
import {useEffect, useState} from 'react'; | ||
import {Title, FixedButton, ListButton} from 'haengdong-design'; | ||
import {useNavigate, useOutletContext} from 'react-router-dom'; | ||
import {useOutletContext} from 'react-router-dom'; | ||
|
||
import StepList from '@components/StepList/StepList'; | ||
import {requestGetEventName} from '@apis/request/event'; | ||
import {ModalBasedOnMemberCount} from '@components/Modal/index'; | ||
|
||
import {useStepList} from '@hooks/useStepList'; | ||
import useEventId from '@hooks/useEventId'; | ||
import useAuth from '@hooks/useAuth'; | ||
|
||
import {ROUTER_URLS} from '@constants/routerUrls'; | ||
|
||
import {EventPageContextProps} from '../EventPageLayout'; | ||
|
||
import {receiptStyle, titleAndListButtonContainerStyle} from './AdminPage.style'; | ||
|
@@ -24,21 +20,14 @@ const AdminPage = () => { | |
|
||
const {getTotalPrice, allMemberList} = useStepList(); | ||
const {postAuthentication} = useAuth(); | ||
const navigate = useNavigate(); | ||
|
||
useEffect(() => { | ||
if (eventId === '') return; | ||
|
||
const postAuth = async () => { | ||
try { | ||
await postAuthentication({eventId: eventId}); | ||
} catch (error) { | ||
navigate(`${ROUTER_URLS.event}/${eventId}/login`); | ||
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. 에러일 때 navigate시키는 기능은 없어진걸까요? 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. 이거는 useFetch 내부에서 이미 처리해주고 있기 때문에, 여기 catch에서 잡히는게 별도로 없었어용 그래서 제외했습니다 |
||
} | ||
await postAuthentication({eventId: eventId}); | ||
}; | ||
|
||
postAuth(); | ||
}, [eventId]); | ||
}, []); | ||
|
||
const handleOpenAllMemberListButton = () => { | ||
setIsOpenFixedBottomBottomSheet(prev => !prev); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import REGEXP from '@constants/regExp'; | ||
|
||
const extractEventIdFromUrl = (url: string) => { | ||
const regex = REGEXP.eventUrl; | ||
const match = url.match(regex); | ||
return match ? match[1] : null; | ||
}; | ||
|
||
const getEventIdByUrl = () => { | ||
return extractEventIdFromUrl(window.location.pathname) || ''; | ||
}; | ||
|
||
export default getEventIdByUrl; |
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.
어우 이 라인을 위한 수정이 많네요. 번거로우셨을텐데 고마워요