Skip to content

Commit af4e6e4

Browse files
authored
Merge pull request #17 from DguFarmSystem/fix/#16
fix: TypeScript 타입 오류 수정 및 API 응답 타입 개선
2 parents d570f5f + a54f89c commit af4e6e4

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"dev": "vite",
88
"build": "tsc -b && vite build",
99
"lint": "eslint .",
10-
"preview": "vite preview"
10+
"preview": "vite preview",
11+
"type-check": "tsc --noEmit"
1112
},
1213
"dependencies": {
1314
"@react-oauth/google": "^0.12.1",

src/hooks/useApplyList.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,32 @@ interface Apply {
99
updatedAt: string;
1010
}
1111

12-
1312
export const useApplyList = (track: string | null) => {
1413
const [applyList, setApplyList] = useState<Apply[]>([]);
1514
const [loading, setLoading] = useState(false);
1615
const [error, setError] = useState<string | null>(null);
1716
const accessToken = useAuthStore((state) => state.accessToken);
1817

19-
useEffect(() => {
20-
const fetchList = async () => {
21-
setLoading(true);
22-
setError(null);
18+
useEffect(() => {
19+
const fetchList = async () => {
20+
if (!accessToken || !track) return;
21+
22+
setLoading(true);
23+
setError(null);
24+
25+
try {
26+
const data = await fetchApplyList(accessToken, track);
27+
setApplyList(data);
28+
} catch (err) {
29+
setError("지원서 목록을 조회하는 중 오류가 발생했습니다.");
30+
} finally {
31+
setLoading(false);
32+
}
33+
};
2334

24-
try {
25-
const data = await fetchApplyList(accessToken, track);
26-
setApplyList(data);
27-
} catch (err) {
28-
setError("지원서 목록을 조회하는 중 오류가 발생했습니다.");
29-
} finally {
30-
setLoading(false);
31-
}
32-
};
35+
fetchList();
36+
}, [track, accessToken]);
3337

34-
fetchList();
35-
}, [track, accessToken]);
3638

3739
return { applyList, loading, error };
38-
};
40+
};

src/services/application.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import apiConfig from "../config/apiConfig";
22
import { Application } from "../types/application";
33

4+
interface ApiResponse<T> {
5+
status: number;
6+
message: string;
7+
data: T;
8+
}
9+
410
export const fetchApplications = async (track?: string): Promise<Application[]> => {
511
try {
6-
const response = await apiConfig.get<Application[]>("/admin/apply", {
12+
const response = await apiConfig.get<ApiResponse<Application[]>>("/admin/apply", {
713
headers: {
814
Authorization: `Bearer ${localStorage.getItem("accessToken")}`,
915
Accept: "application/json",
1016
},
1117
params: track ? { track } : {},
1218
});
1319

14-
return response.data.data; // data 속성 내부 배열만 반환하는 것으로 수정했는데 'Application[]' 형식에 'data' 속성이 없다는 오류 발생.
20+
return response.data.data;
1521
} catch (error: any) {
1622
throw new Error(error.response?.data?.message || "지원서 목록 조회 실패");
1723
}
1824
};
19-

0 commit comments

Comments
 (0)