-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 토큰 만료 후 인증이 필요한 서비스에 접근시 자동 로그아웃 되는 기능을 구현한다 (#554)
* refactor: 로그아웃 메서드 수정 - 멤버 토큰 삭제 기능 개선 - 멤버 정보 삭제 기능 추가 [#543] * feat: fetch 추상화 유틸 구현 [#543] * feat: 만료된 토큰에 대한 핸들링 메서드 구현 [#543] * feat: 현재 가지고 있는 필터 정보를 요청 형식에 맞게 반환하는 메서드 구현 [#543] * refactor: msw에 면경된 API 명세 적용 [#543] * refactor: 추상화된 fetch함수 사용 [#543] * feat: 모든 서버 필터링 정보를 초기화 하는 메서드 구현 [#543] * refactor: 로그아웃 시 sessionStorage에 저장되던 멤버 정보 초기값 수정 [#543] * comment: 토큰 액션 메서드 주석 추가 [#543] * fix: 타입 에러 수정 [#543] * feat: 자동차 등록 실패시 모달을 닫는 기능 구현 [#543] * refactor: useMemberFilters 훅 내부 fetch함수 fetchUtils로 변경 [#543] * refactor: 불필요한 console.log삭제 [#543] * comment: 완료한 TODO 주석 삭제 [#543] * refactor: console.log 삭제 [#543] * refactor: useServerStationFilterActions 객체명 수정 - useServerStationFilterStoreActions [#543] * refactor: 컴포넌트 내 복잡한 로직 훅 분리 [#543] * refactor: fetchMemberFilters 메서드 에러 처리 추가 [#543] * refactor: getMemberToken 메서드에 fetchUtils 적용 [#543] * fix: 로그인 로직 진행중 발생한 오류 수정 [#543] * refactor: 로그인 여부 판별 로직 수정 - 첫 화면 로딩 시 로그인 되어 있다면 "로그인 되었습니다" 토스트 표시 - 첫 화면 로딩 시 로그인 되어 있지 않다면 아무런 토스트도 표시하지 않음 [#543] * refactor: 로그인 로딩 페이지 수정 [#543]
- Loading branch information
Showing
16 changed files
with
291 additions
and
223 deletions.
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
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
67 changes: 67 additions & 0 deletions
67
...d/src/components/ui/ServerStationFilters/hooks/useServerStationFiltersComponentActions.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,67 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { fetchUtils } from '@utils/fetch'; | ||
import { getAPIEndPoint } from '@utils/login'; | ||
|
||
import { toastActions } from '@stores/layout/toastStore'; | ||
import { memberInfoStore } from '@stores/login/memberInfoStore'; | ||
import { serverStationFilterAction } from '@stores/station-filters/serverStationFiltersStore'; | ||
|
||
import { QUERY_KEY_MEMBER_SELECTED_FILTERS, QUERY_KEY_STATIONS } from '@constants/queryKeys'; | ||
|
||
import type { StationFilters } from '@type'; | ||
|
||
export const useServerStationFiltersComponentActions = () => { | ||
const queryClient = useQueryClient(); | ||
const { showToast } = toastActions; | ||
|
||
const fallbackToPreviousFilters = () => { | ||
const { resetAllServerStationFilters } = serverStationFilterAction; | ||
const stationFilters = queryClient.getQueryData<StationFilters>([ | ||
QUERY_KEY_MEMBER_SELECTED_FILTERS, | ||
]); | ||
resetAllServerStationFilters(stationFilters); | ||
|
||
queryClient.invalidateQueries({ queryKey: [QUERY_KEY_STATIONS] }); | ||
|
||
showToast('필터 적용에 실패했습니다', 'error'); | ||
}; | ||
|
||
const handleStationsRefetch = () => { | ||
queryClient.invalidateQueries({ queryKey: [QUERY_KEY_STATIONS] }); | ||
showToast('필터가 적용되었습니다'); | ||
}; | ||
|
||
const applyMemberFilters = async () => { | ||
const APIEndPoint = getAPIEndPoint(); | ||
const memberId = memberInfoStore.getState()?.memberId; | ||
|
||
const { getMemberFilterRequestBody } = serverStationFilterAction; | ||
const memberFilterRequestBody = getMemberFilterRequestBody(); | ||
|
||
return await fetchUtils.post<StationFilters, typeof memberFilterRequestBody>( | ||
`${APIEndPoint}/members/${memberId}/filters`, | ||
memberFilterRequestBody | ||
); | ||
}; | ||
|
||
const submitMemberFilters = async () => { | ||
const { setAllServerStationFilters } = serverStationFilterAction; | ||
|
||
try { | ||
const stationFilters = await applyMemberFilters(); | ||
|
||
setAllServerStationFilters(stationFilters); | ||
handleStationsRefetch(); | ||
} catch { | ||
fallbackToPreviousFilters(); | ||
} | ||
}; | ||
|
||
return { | ||
fallbackToPreviousFilters, | ||
handleStationsRefetch, | ||
applyMemberFilters, | ||
submitMemberFilters, | ||
}; | ||
}; |
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
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
Oops, something went wrong.