import React, { useEffect } from 'react'; import { View, Text, ScrollView, TouchableOpacity } from 'react-native'; import Icon from 'react-native-vector-icons/Ionicons'; import { RouteProp, useRoute } from '@react-navigation/native'; import { useTheme } from '@theme'; import { useAppDispatch, useAppSelector, RootState } from '@store'; import { getCustomerDetails } from './thunk'; import { getStyles } from './customerDetails.styles'; import { CustomersStackParamList } from '../../navigation/customersStack'; import { Loader, CustomerDetailHeader } from '@components'; import { handleEmailPress, handlePhonePress, handleWebsitePress, } from '@utils'; type CustomerDetailsRouteProp = RouteProp< CustomersStackParamList, 'customerDetails' >; export const CustomerDetailsScreen = () => { const route = useRoute(); const dispatch = useAppDispatch(); const { theme: colors } = useTheme(); const styles = getStyles(colors); const userid = route.params?.userid || route.params?.customer?.userid; const initialCustomer = route.params?.customer; const { item: customerState, loading, error } = useAppSelector( (state: RootState) => state.customerDetails, ); useEffect(() => { if (userid) { dispatch(getCustomerDetails({ userid })); } }, [dispatch, userid]); const customer = customerState || initialCustomer; if (loading && !customer) { return ; } if (error && !customer) { return ( {error} ); } if (!customer) { return ( No customer details found. ); } const billingAddress = [ customer.billing_street || customer.address, customer.billing_city || customer.city, customer.billing_state || customer.state, customer.billing_zip || customer.zip, customer.billing_country || customer.country, ] .filter(Boolean) .join(', '); const shippingAddress = [ customer.shipping_street, customer.shipping_city, customer.shipping_state, customer.shipping_zip, customer.shipping_country, ] .filter(Boolean) .join(', '); return ( {/* Top Header & Quick Actions */} {/* Contact Details */} Contact Details {customer.email ? ( <> handleEmailPress(customer.email)} activeOpacity={0.7}> Email {customer.email} ) : null} {customer.phonenumber ? ( <> handlePhonePress(customer.phonenumber)} activeOpacity={0.7}> Phone {customer.phonenumber} ) : null} {customer.website ? ( <> handleWebsitePress(customer.website)} activeOpacity={0.7}> Website {customer.website} ) : null} {customer.vat ? ( VAT Number {customer.vat} ) : null} {/* Address Information */} Address Information {billingAddress ? ( <> Billing Address {billingAddress} {shippingAddress ? : null} ) : null} {shippingAddress ? ( Shipping Address {shippingAddress} ) : null} {!billingAddress && !shippingAddress ? ( No address information provided. ) : null} ); };