fix: handle Flask API response wrapper format
continuous-integration/drone/push Build is passing Details

Fix TypeError: t.map is not a function on Plans and Members pages

Issue: Backend wraps responses in { status: 'success', data: {...} }
but frontend was expecting direct data.

Changes:
- Update handleApiResponse to extract data from Flask wrapper
- Special handling for policy endpoint (returns { policy: {...} })
- Handles both wrapped and unwrapped responses for compatibility

Fixes the 'Application error' on Plans and Members pages.
master
Guillermo Pages 3 weeks ago
parent 86b1414ae0
commit 238320b015

@ -29,10 +29,14 @@ import apiFetch from '@/src/utils/apiFetch';
/**
* Handle API response
* Flask backend wraps responses in: { status: 'success'|'fail', data: {...} }
*/
async function handleApiResponse<T>(response: Response): Promise<FacilityAdminApiResult<T>> {
if (response.ok) {
const data = await response.json();
const json = await response.json();
// Flask returns { status: 'success', data: {...} }
// Extract the actual data from the wrapper
const data = json.data !== undefined ? json.data : json;
return { success: true, data };
}
@ -529,7 +533,15 @@ export async function getPolicy(
headers: { 'Content-Type': 'application/json' },
});
return handleApiResponse<FacilityPolicy>(response);
const result = await handleApiResponse<any>(response);
// Backend returns { status: 'success', data: { policy: {...} } }
// Extract the policy object
if (result.success && result.data.policy) {
return { success: true, data: result.data.policy };
}
return result as FacilityAdminApiResult<FacilityPolicy>;
} catch (error) {
return {
success: false,

Loading…
Cancel
Save