-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/GU-99/grow-up-fe into fe…
…ature/#69-user-setting-ui
- Loading branch information
Showing
19 changed files
with
779 additions
and
126 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
// ToDo: MEMORY_UNITS 으로 묶는거 고려해보기 | ||
export const KB = 1024; | ||
export const MB = 1024 * KB; | ||
export const GB = 1024 * MB; | ||
|
||
// ToDo: DeepFreeze로 변경할 것, 상수 정의 컨벤션 적용할 것 | ||
export const fileSizeUnits = Object.freeze([ | ||
{ unit: 'GB', value: GB }, | ||
{ unit: 'MB', value: MB }, | ||
{ unit: 'KB', value: KB }, | ||
{ unit: 'B', value: 1 }, | ||
]); | ||
|
||
// ToDo: TIME_UNITS 으로 묶는거 고려해보기 | ||
export const MILLISECOND = 1; | ||
export const SECOND = 1000 * MILLISECOND; | ||
export const MINUTE = 60 * SECOND; | ||
export const HOUR = 60 * MINUTE; | ||
export const DAY = 24 * HOUR; |
Empty file.
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,61 @@ | ||
import axios from 'axios'; | ||
import { useState, useCallback } from 'react'; | ||
import type { AxiosResponse } from 'axios'; | ||
|
||
type PromiseCallback<T, P extends unknown[]> = (...args: P) => Promise<AxiosResponse<T>>; | ||
|
||
/** | ||
* Axios API 함수를 처리하는 커스텀 훅 | ||
* | ||
* @export | ||
* @template T - AxiosResponse의 응답 데이터 타입 | ||
* @template {unknown[]} P - API 함수에 전달되는 매개변수의 가변인자 타입 배열 | ||
* @param {PromiseCallback<T, P>} fetchCallback - API 요청을 수행하는 함수 | ||
* @returns {{ | ||
* data: T | undefined; // API 요청의 응답 데이터 | ||
* error: Error | null; // API 요청 중 발생한 에러 | ||
* loading: boolean; // 데이터 로딩 중인지 여부 | ||
* fetchData: (...args: P) => Promise<void>; // API 요청을 호출하는 함수 | ||
* }} | ||
* @example | ||
* const { data, error, loading, fetchData } = useAxios(fetchCallback) // fetchCallback에서 타입을 반환한다면, 자동 타입 추론이 가능 | ||
* const { data, error, loading, fetchData } = useAxios<User[], Parameters<typeof fetchCallback>>(fetchCallback); | ||
*/ | ||
export default function useAxios<T, P extends unknown[]>(fetchCallback: PromiseCallback<T, P>) { | ||
const [data, setData] = useState<T>(); | ||
const [error, setError] = useState<Error | null>(null); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const clearData = useCallback(() => { | ||
setData(undefined); | ||
setError(null); | ||
setLoading(false); | ||
}, []); | ||
|
||
const fetchData = useCallback( | ||
async (...params: P) => { | ||
try { | ||
setLoading(true); | ||
const response = await fetchCallback(...params); | ||
setData(response.data); | ||
} catch (error: unknown) { | ||
setError(error as Error); | ||
|
||
if (!axios.isAxiosError(error)) return; | ||
|
||
if (error.request) { | ||
// ToDo: 네트워크 요청을 보냈지만 응답이 없는 경우 에러 처리 | ||
} else if (error.response) { | ||
// ToDo: 요청후 응답을 받았지만 200 이외의 응답 코드인 경우 예외 처리 | ||
} else { | ||
// ToDo: request 설정 오류 | ||
} | ||
} finally { | ||
setLoading(false); | ||
} | ||
}, | ||
[fetchCallback], | ||
); | ||
|
||
return { data, error, loading, clearData, fetchData }; | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { setupWorker } from 'msw/browser'; | ||
import { handlers } from './handlers'; | ||
import handlers from '@mocks/handlers'; | ||
|
||
export const worker = setupWorker(...handlers); |
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
// ToDo: API 설계되면 엔드포인트 넣어서 설정할 것. | ||
export const handlers = []; | ||
import userServiceHandler from '@mocks/services/userServiceHandler'; | ||
import teamServiceHandler from '@mocks/services/teamServiceHandler'; | ||
import projectServiceHandler from '@mocks/services/projectServiceHandler'; | ||
|
||
const handlers = [...userServiceHandler, ...teamServiceHandler, ...projectServiceHandler]; | ||
|
||
export default handlers; |
Oops, something went wrong.