igcrmmobile/scratch/fix_attendance.js

85 lines
3.2 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const filePath = 'c:\\ignosidev\\Igcrm\\apps\\mobile\\src\\screens\\AttendanceScreen.js';
let content = fs.readFileSync(filePath, 'utf8');
// 1. Add Linking to imports
content = content.replace(
/import { View, Text, StyleSheet, PermissionsAndroid, Platform, Alert, ActivityIndicator, TouchableOpacity, FlatList, RefreshControl } from 'react-native';/,
"import { View, Text, StyleSheet, PermissionsAndroid, Platform, Alert, ActivityIndicator, TouchableOpacity, FlatList, RefreshControl, Linking } from 'react-native';"
);
// 2. Add openMap function and update renderHistoryItem
const openMapFunc = ` const openMap = (lat, lng) => {
const url = Platform.select({
ios: \`maps:0,0?q=\${lat},\${lng}\`,
android: \`geo:0,0?q=\${lat},\${lng}(Attendance Location)\`
});
Linking.openURL(url);
};
const renderHistoryItem = ({ item }) => (
<View style={styles.historyCard}>
<View style={styles.dateBox}>
<Text style={styles.dateText}>{getDayMonth(item.checkInTime)}</Text>
</View>
<View style={styles.timeBox}>
<View style={styles.timeRow}>
<Text style={styles.timeLabel}>In:</Text>
<Text style={styles.timeValue}>{formatDate(item.checkInTime)}</Text>
</View>
<View style={styles.timeRow}>
<Text style={styles.timeLabel}>Out:</Text>
<Text style={styles.timeValue}>{item.checkOutTime ? formatDate(item.checkOutTime) : 'Active'}</Text>
</View>
{(item.checkInLat && item.checkInLng) && (
<TouchableOpacity
onPress={() => openMap(item.checkInLat, item.checkInLng)}
style={styles.locationContainer}
>
<Text style={styles.locationText}>
📍 {item.checkInLat.toFixed(4)}, {item.checkInLng.toFixed(4)}
</Text>
<Text style={styles.mapLink}>View Map</Text>
</TouchableOpacity>
)}
</View>
<View style={[styles.statusIndicator, item.checkOutTime ? styles.statusCompleted : styles.statusActive]} />
</View>
);`;
content = content.replace(/const renderHistoryItem = \({ item }\) => \([\s\S]*?\n\s{4}\);/, openMapFunc);
// 3. Add styles
const newStyles = ` emptyText: {
textAlign: 'center',
marginTop: 30,
color: Colors.textLight
},
locationContainer: {
flexDirection: 'row',
alignItems: 'center',
marginTop: 8,
paddingTop: 8,
borderTopWidth: 1,
borderTopColor: Colors.borderLight,
},
locationText: {
fontSize: 11,
color: Colors.textMuted,
marginRight: 10
},
mapLink: {
fontSize: 11,
color: Colors.secondary,
fontWeight: 'bold',
textDecorationLine: 'underline'
}
});`;
content = content.replace(/emptyText: {[\s\S]*?\n\s{4}}\n}\);/, newStyles);
fs.writeFileSync(filePath, content, 'utf8');
console.log('File updated successfully!');