import React, { useEffect } from "react"; import { View, Text, StyleSheet, TouchableOpacity, SafeAreaView, StatusBar, ActivityIndicator, } from "react-native"; import { useDispatch, useSelector } from "react-redux"; import { RootState } from "../../store/rootReducer"; // Adjust path as needed import { getUserDetails } from "../../store/userSlice"; import { AppDispatch } from "@/store"; import Header from "@/components/common/Header"; interface MyVehicleScreenProps { navigation?: any; // Replace with proper navigation type } const MyVehicleScreen: React.FC = ({ navigation }) => { const dispatch = useDispatch(); const { data: userData, loading, error, } = useSelector((state: RootState) => state.user); useEffect(() => { // Fetch user details when component mounts if (!userData) { dispatch(getUserDetails()); } }, [dispatch, userData]); // Get the first vehicle from the user data const vehicle = userData?.vehicles?.[0]; if (loading) { return ( Loading vehicle details... ); } if (error) { return ( Error: {error} ); } return ( <>
{/* OEM - Model */} OEM - Model {vehicle?.model ? `Yatri - ${vehicle.model}` : "--"} {/* Chassis Number */} Chassis Number {vehicle?.chasis_number || "--"} {/* Vehicle ID */} Vehicle ID {vehicle?.vehicle_id ? vehicle.vehicle_id.toString() : "--"} ); }; const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#ffffff", }, header: { flexDirection: "row", alignItems: "center", paddingHorizontal: 16, paddingVertical: 12, borderBottomWidth: 1, borderBottomColor: "#f0f0f0", }, backButton: { marginRight: 12, padding: 4, }, backIcon: { width: 24, height: 24, justifyContent: "center", alignItems: "center", }, backIconText: { fontSize: 20, fontWeight: "600", color: "#25324B", }, headerTitle: { fontSize: 18, fontWeight: "600", color: "#25324B", }, content: { flex: 1, paddingHorizontal: 16, paddingTop: 16, }, itemContainer: { backgroundColor: "#FCFCFC", borderRadius: 8, overflow: "hidden", }, item: { paddingHorizontal: 16, paddingVertical: 16, }, label: { fontSize: 14, color: "#25324B", fontWeight: "400", marginBottom: 4, lineHeight: 20, }, value: { fontSize: 14, color: "#25324B", fontWeight: "600", lineHeight: 20, }, divider: { height: 1, backgroundColor: "#E5E9F0", marginHorizontal: 16, }, loadingContainer: { flex: 1, justifyContent: "center", alignItems: "center", }, loadingText: { marginTop: 16, fontSize: 16, color: "#25324B", }, errorContainer: { flex: 1, justifyContent: "center", alignItems: "center", paddingHorizontal: 16, }, errorText: { fontSize: 16, color: "#FF6B6B", textAlign: "center", }, }); export default MyVehicleScreen;