fix(teams): correct API response structure for browse teams

- Match ListResponse structure: data (array) + meta (pagination)
- Use correct query param name: per_page instead of limit

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Maulana Sodiqin
2025-11-29 17:05:27 +07:00
co-authored by Claude
parent 4fcc96ac15
commit b472fbdbbf
+18 -14
View File
@@ -106,12 +106,16 @@ interface Submission {
created_at: string; created_at: string;
} }
// Pagination response type // List response type with pagination
interface PaginatedTeamsResponse { interface ListResponseWithMeta<T> {
teams: Team[]; message: string;
total: number; data: T[];
page: number; meta: {
per_page: number; page: number;
per_page: number;
total_page: number;
total_data: number;
};
} }
// Team CRUD Hooks // Team CRUD Hooks
@@ -127,22 +131,22 @@ export const useTeams = (params?: {
queryFn: async () => { queryFn: async () => {
const queryParams = new URLSearchParams(); const queryParams = new URLSearchParams();
if (params?.page) queryParams.append('page', String(params.page)); if (params?.page) queryParams.append('page', String(params.page));
if (params?.limit) queryParams.append('limit', String(params.limit)); if (params?.limit) queryParams.append('per_page', String(params.limit));
if (params?.search) queryParams.append('search', params.search); if (params?.search) queryParams.append('search', params.search);
if (params?.city) queryParams.append('city', params.city); if (params?.city) queryParams.append('city', params.city);
if (params?.visibility) queryParams.append('visibility', params.visibility); if (params?.visibility) queryParams.append('visibility', params.visibility);
const response = await hackathonApi.get<HackathonApiResponse<PaginatedTeamsResponse>>( const response = await hackathonApi.get<ListResponseWithMeta<Team>>(
`/teams/browse${queryParams.toString() ? `?${queryParams.toString()}` : ''}` `/teams/browse${queryParams.toString() ? `?${queryParams.toString()}` : ''}`
); );
const data = response.data.data; const { data, meta } = response.data;
return { return {
teams: data?.teams || [], teams: data || [],
total: data?.total || 0, total: meta?.total_data || 0,
page: data?.page || 1, page: meta?.page || 1,
perPage: data?.per_page || 12, perPage: meta?.per_page || 12,
totalPages: Math.ceil((data?.total || 0) / (data?.per_page || 12)), totalPages: meta?.total_page || 1,
}; };
}, },
}); });