Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions guard_app/src/screen/ShiftDetailsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Ionicons } from '@expo/vector-icons';
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
import { AxiosError } from 'axios';
import React, { useEffect, useState } from 'react';
import { Alert, ScrollView, StyleSheet, Text, TouchableOpacity, View } from 'react-native';

Expand Down Expand Up @@ -95,9 +96,14 @@ export default function ShiftDetailsScreen() {
}

if (route.params.refresh) route.params.refresh();
} catch (e: any) {
} catch (e: unknown) {
setModalVisible(false);
const msg = e?.response?.data?.message ?? e?.message ?? 'Action failed';
let msg;
if (e instanceof AxiosError) {
msg = e?.response?.data?.message ?? e?.message ?? 'Action failed';
} else {
msg = 'Action failed';
}

if (typeof msg === 'string' && msg.toLowerCase().includes('location')) {
Alert.alert('Location Error', 'You are not at the shift location ❌');
Expand Down
13 changes: 9 additions & 4 deletions guard_app/src/screen/TimeSheetsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// src/screen/TimesheetsScreen.tsx
import { useFocusEffect } from '@react-navigation/native';
import { AxiosError } from 'axios';
import React, { useCallback, useState } from 'react';
import {
View,
Expand Down Expand Up @@ -28,7 +29,7 @@ function fmtDateTime(d?: string | null) {
}

function fmtShiftLabel(att: Attendance) {
const s = att.shiftId as any;
const s = att.shiftId;

if (s && typeof s === 'object') {
const title = s.title ?? 'Shift';
Expand All @@ -52,9 +53,13 @@ export default function TimesheetsScreen() {
try {
const rows = await getMyAttendance();
setItems(rows);
} catch (e: any) {
const msg = e?.response?.data?.message ?? e?.message ?? 'Failed to load timesheets';
Alert.alert('Error', msg);
} catch (e: unknown) {
if (e instanceof AxiosError) {
const msg = e?.response?.data?.message ?? e?.message ?? 'Failed to load timesheets';
Alert.alert('Error', msg);
} else {
Alert.alert('Error', 'Failed to load timesheets');
}
} finally {
setLoading(false);
setRefreshing(false);
Expand Down
Loading