Skip to content

Commit f8620e2

Browse files
committed
fix(unit-user-usage): show error messages when there are api errors
1 parent cfe839f commit f8620e2

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

components/usage/UnitUserUsage.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ dayjs.extend(utc);
1313
import { useCallback, useState } from "react";
1414

1515
import {
16+
Alert,
1617
Box,
1718
CircularProgress,
1819
Container,
@@ -45,12 +46,22 @@ export const UnitUserUsage = ({ unitId }: UnitUserUsageProps) => {
4546
});
4647
}, [queryClient, unitId]);
4748

48-
const { data } = useGetUserInventory({ unit_id: unitId });
49-
const { data: unit } = useGetUnit(unitId);
50-
const { data: unitUserList } = useGetOrganisationUnitUsers(unitId);
49+
const { data, error: inventoryError } = useGetUserInventory({ unit_id: unitId });
50+
const { data: unit, error: unitError } = useGetUnit(unitId);
51+
const { data: unitUserList, error: unitUsersError } = useGetOrganisationUnitUsers(unitId);
5152

5253
const [pivot, setPivot] = useState(false);
5354

55+
if (inventoryError) {
56+
return <Alert severity="error">{inventoryError.message}</Alert>;
57+
}
58+
if (unitError) {
59+
return <Alert severity="error">{unitError.message}</Alert>;
60+
}
61+
if (unitUsersError) {
62+
return <Alert severity="error">{unitUsersError.message}</Alert>;
63+
}
64+
5465
if (data === undefined || unit === undefined || unitUserList === undefined) {
5566
return <CenterLoader />;
5667
}

0 commit comments

Comments
 (0)