@@ -14,14 +14,10 @@ import {
1414 TouchableOpacity ,
1515} from 'react-native' ;
1616
17+ import { myShifts , type ShiftDto } from '../api/shifts' ;
1718import { getAllMyTimesheets , type Timesheet } from '../api/timesheets' ;
1819import { useAppTheme } from '../theme' ;
19- import {
20- formatHours ,
21- formatShiftDate ,
22- formatTimesheetDateTime ,
23- sumHours ,
24- } from '../utils/timesheet' ;
20+ import { fmtShiftLabel , formatHours , formatTimesheetDateTime , sumHours } from '../utils/timesheet' ;
2521
2622import type { RootStackParamList } from '../navigation/AppNavigator' ;
2723import type { AppColors } from '../theme/colors' ;
@@ -37,13 +33,18 @@ export default function TimesheetsScreen() {
3733 const [ loading , setLoading ] = useState ( true ) ;
3834 const [ refreshing , setRefreshing ] = useState ( false ) ;
3935 const [ items , setItems ] = useState < Timesheet [ ] > ( [ ] ) ;
36+ const [ shiftsById , setShiftsById ] = useState < Record < string , ShiftDto > > ( { } ) ;
4037 const [ error , setError ] = useState < string | null > ( null ) ;
4138
4239 const load = async ( ) => {
4340 try {
4441 setError ( null ) ;
45- const rows = await getAllMyTimesheets ( ) ;
42+ const [ rows , shifts ] = await Promise . all ( [
43+ getAllMyTimesheets ( ) ,
44+ myShifts ( ) . catch ( ( ) => [ ] as ShiftDto [ ] ) ,
45+ ] ) ;
4646 setItems ( rows ) ;
47+ setShiftsById ( Object . fromEntries ( shifts . map ( ( shift ) => [ shift . _id , shift ] ) ) ) ;
4748 } catch ( e : unknown ) {
4849 let msg = t ( 'timesheet.error' ) ;
4950
@@ -82,7 +83,7 @@ export default function TimesheetsScreen() {
8283 style = { s . card }
8384 onPress = { ( ) => navigation . navigate ( 'TimesheetDetails' , { timesheetId : item . id } ) }
8485 >
85- < Text style = { s . title } > { formatShiftDate ( item . shiftDate ) } </ Text >
86+ < Text style = { s . title } > { fmtShiftLabel ( shiftsById [ item . shiftId ] , item . shiftId ) } </ Text >
8687
8788 < View style = { s . row } >
8889 < Text style = { s . label } > { t ( 'timesheet.checkIn' ) } </ Text >
0 commit comments