11import React , { useMemo } from 'react' ;
2- import { StyleSheet } from 'react-native' ;
2+ import i18n from 'i18n' ;
3+ import { StyleSheet , View } from 'react-native' ;
34import { useTheme } from '@react-navigation/native' ;
45import PropTypes from 'prop-types' ;
56import { Icon , Text , Pressable } from 'components' ;
7+ import Clipboard from '@react-native-clipboard/clipboard' ;
68
79import { openNumber } from 'src/helpers/UrlHelper' ;
10+ import { showToast } from 'helpers/ToastHelper' ;
811
912const createStyles = theme => {
1013 const { spacing } = theme ;
@@ -15,8 +18,9 @@ const createStyles = theme => {
1518 alignItems : 'center' ,
1619 marginTop : spacing . smaller ,
1720 marginBottom : spacing . micro ,
21+ gap : spacing . micro ,
1822 } ,
19- detailText : {
23+ copyButton : {
2024 marginLeft : spacing . micro ,
2125 } ,
2226 } ) ;
@@ -33,20 +37,39 @@ const ContactDetails = ({ type, value, iconName }) => {
3337 const { colors } = theme ;
3438 const styles = useMemo ( ( ) => createStyles ( theme ) , [ theme ] ) ;
3539
40+ // Avoid rendering if the value is empty or whitespace (Case: identifier)
41+ if ( ! value || value === ' ' ) {
42+ return null ;
43+ }
44+
3645 const onClickOpen = ( ) => {
3746 if ( type === 'phoneNumber' ) {
3847 openNumber ( { phoneNumber : value } ) ;
3948 } else {
4049 return ;
4150 }
4251 } ;
52+
53+ const showCopyButton = type === 'phoneNumber' || type === 'email' ;
54+
55+ const onClickCopy = ( ) => {
56+ Clipboard . setString ( value ) ;
57+ showToast ( { message : i18n . t ( 'CONVERSATION_DETAILS.CLIPBOARD_SUCCESS' ) } ) ;
58+ } ;
4359 return (
44- < Pressable style = { styles . detailsContainer } onPress = { ( ) => onClickOpen ( ) } >
60+ < View style = { styles . detailsContainer } >
4561 < Icon icon = { iconName } color = { colors . primaryColor } size = { 14 } />
46- < Text sm color = { colors . textDark } style = { styles . detailText } >
47- { value }
48- </ Text >
49- </ Pressable >
62+ < Pressable onPress = { ( ) => onClickOpen ( ) } >
63+ < Text sm color = { colors . textDark } >
64+ { value }
65+ </ Text >
66+ </ Pressable >
67+ { showCopyButton && (
68+ < Pressable style = { styles . copyButton } onPress = { ( ) => onClickCopy ( ) } >
69+ < Icon icon = "copy-outline" color = { colors . text } size = { 14 } />
70+ </ Pressable >
71+ ) }
72+ </ View >
5073 ) ;
5174} ;
5275
0 commit comments