@olea-bps/base 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/ContactDetail/index.js +174 -195
- package/package.json +1 -1
|
@@ -12,30 +12,34 @@
|
|
|
12
12
|
* limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import
|
|
16
|
-
|
|
15
|
+
import {
|
|
16
|
+
useCallback,
|
|
17
|
+
useMemo
|
|
18
|
+
} from 'react';
|
|
17
19
|
|
|
18
20
|
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
View,
|
|
21
|
+
Linking,
|
|
22
|
+
Platform,
|
|
22
23
|
SafeAreaView,
|
|
24
|
+
ScrollView,
|
|
23
25
|
Share,
|
|
24
|
-
|
|
26
|
+
StyleSheet,
|
|
27
|
+
Text,
|
|
25
28
|
TouchableOpacity,
|
|
26
|
-
|
|
27
|
-
ScrollView
|
|
29
|
+
View,
|
|
28
30
|
} from 'react-native';
|
|
29
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
Headline,
|
|
33
|
+
List,
|
|
34
|
+
useTheme,
|
|
35
|
+
} from "react-native-paper";
|
|
30
36
|
|
|
31
|
-
import {
|
|
32
|
-
import {withTranslation} from "react-i18next";
|
|
33
|
-
import merge from 'lodash/merge';
|
|
37
|
+
import { useTranslation } from "react-i18next";
|
|
34
38
|
|
|
35
39
|
import componentStyles from './styles';
|
|
36
40
|
import AppbarComponent from '../AppBar';
|
|
37
41
|
import AppbarAction from '../AppbarAction';
|
|
38
|
-
|
|
42
|
+
import { default as Icon } from '../../libraries/icons-openasist';
|
|
39
43
|
|
|
40
44
|
/**
|
|
41
45
|
* Contact Detail Component
|
|
@@ -43,193 +47,168 @@ import AppbarAction from '../AppbarAction';
|
|
|
43
47
|
* Shows the detailed information of a contact with name and contact details.
|
|
44
48
|
* Provides a share functionality.
|
|
45
49
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* Navigation-Parameters:
|
|
50
|
-
* - none
|
|
50
|
+
* @param {object} props
|
|
51
|
+
* @param {object} props.contact - Der anzuzeigende Kontakt
|
|
51
52
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
53
|
+
export default function ContactDetailComponent({ contact, ...restProps }) {
|
|
54
|
+
const theme = useTheme();
|
|
55
|
+
const { themeStyles } = theme;
|
|
56
|
+
const { t } = useTranslation();
|
|
57
|
+
|
|
58
|
+
const styles = useMemo(
|
|
59
|
+
() => StyleSheet.create(componentStyles(theme)),
|
|
60
|
+
[theme, componentStyles]
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const onShare = useCallback(
|
|
64
|
+
async () => {
|
|
65
|
+
try {
|
|
66
|
+
// Telephone-Objekte aus dem Kontakt auslesen. Falls diese nicht vorhanden sind, mit einem leeren Array initialisieren
|
|
67
|
+
const contactTelephones = contact?.telephone ?? [];
|
|
68
|
+
const shareMessageTelephoneNumbers = contactTelephones
|
|
69
|
+
.map(telephone => telephone.number)
|
|
70
|
+
.map(number => `${t('contact:phone')}: ${number}`)
|
|
71
|
+
.join('\n');
|
|
72
|
+
|
|
73
|
+
const shareMessage = `${t('contact:title')} - ${contact.firstName} ${contact.lastName}`
|
|
74
|
+
+
|
|
75
|
+
(
|
|
76
|
+
contact?.building
|
|
77
|
+
? `\n${t('contact:building')}: ${contact.building}`
|
|
78
|
+
: ''
|
|
79
|
+
)
|
|
80
|
+
+
|
|
81
|
+
(
|
|
82
|
+
contact?.department
|
|
83
|
+
? `\n${t('contact:department')}: ${contact.department}`
|
|
84
|
+
: ''
|
|
85
|
+
)
|
|
86
|
+
+
|
|
87
|
+
(
|
|
88
|
+
contact?.room?.title
|
|
89
|
+
? `\n${t('contact:room')}: ${contact.room.title}`
|
|
90
|
+
: ''
|
|
91
|
+
)
|
|
92
|
+
+
|
|
93
|
+
(
|
|
94
|
+
contact?.email
|
|
95
|
+
? `\n${t('contact:email')}: ${contact.email}`
|
|
96
|
+
: ''
|
|
97
|
+
)
|
|
98
|
+
+
|
|
99
|
+
(
|
|
100
|
+
shareMessageTelephoneNumbers
|
|
101
|
+
? '\n' + shareMessageTelephoneNumbers
|
|
102
|
+
: ''
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
await Share.share({
|
|
106
|
+
message: shareMessage,
|
|
96
107
|
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
alert(error.message);
|
|
97
110
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
},
|
|
112
|
+
[contact, t]
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
return contact
|
|
116
|
+
? <SafeAreaView style={[styles.container, themeStyles.safeAreaContainer]}>
|
|
117
|
+
<AppbarComponent
|
|
118
|
+
{...restProps}
|
|
119
|
+
title={t('contact:contactInformation')}
|
|
120
|
+
rightAction={<AppbarAction icon='share' onPress={onShare} />}
|
|
121
|
+
/>
|
|
122
|
+
<ScrollView style={styles.containerInner}>
|
|
123
|
+
<Headline style={styles.name}>{contact.firstName} {contact.lastName}</Headline>
|
|
124
|
+
{
|
|
125
|
+
contact?.building
|
|
126
|
+
? <List.Item
|
|
127
|
+
key="building"
|
|
128
|
+
title={t('contact:building')}
|
|
129
|
+
description={contact.building}
|
|
130
|
+
descriptionStyle={themeStyles.textLighter}
|
|
131
|
+
titleStyle={themeStyles.searchDetailTitle}
|
|
132
|
+
descriptionNumberOfLines={200} />
|
|
133
|
+
: null
|
|
115
134
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Render contact details content
|
|
126
|
-
*
|
|
127
|
-
* @returns {*}
|
|
128
|
-
* @private
|
|
129
|
-
*/
|
|
130
|
-
_renderContent = () => {
|
|
131
|
-
const { contact, t } = this.props;
|
|
132
|
-
const { themeStyles } = this.props.theme;
|
|
133
|
-
|
|
134
|
-
let output = [];
|
|
135
|
-
let index = 1;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if(contact.building)
|
|
141
|
-
output.push(<List.Item key="building" title={t('contact:building')} description={contact.building}
|
|
142
|
-
descriptionStyle={themeStyles.textLighter} titleStyle={themeStyles.searchDetailTitle}
|
|
143
|
-
descriptionNumberOfLines={200}/>);
|
|
144
|
-
|
|
145
|
-
if(contact.department)
|
|
146
|
-
output.push(<List.Item key="department" title={t('contact:department')} description={contact.department}
|
|
147
|
-
descriptionStyle={themeStyles.textLighter} titleStyle={themeStyles.searchDetailTitle}
|
|
148
|
-
descriptionNumberOfLines={200}/>);
|
|
149
|
-
|
|
150
|
-
if(contact.room && contact.room.title)
|
|
151
|
-
output.push(<List.Item key="room" title={t('contact:room')} description={contact.room.title}
|
|
152
|
-
descriptionStyle={themeStyles.textLighter} titleStyle={themeStyles.searchDetailTitle}
|
|
153
|
-
descriptionNumberOfLines={200}/>);
|
|
154
|
-
|
|
155
|
-
if(contact.email)
|
|
156
|
-
output.push(<TouchableOpacity key="email" onPress={() => Linking.openURL('mailto:' + contact.email)}>
|
|
157
|
-
<List.Item title={t('contact:email')} description={contact.email}
|
|
158
|
-
descriptionStyle={themeStyles.textLighter} titleStyle={themeStyles.searchDetailTitle}
|
|
159
|
-
right={props => <List.Icon {...props} icon="email"/>}/>
|
|
160
|
-
</TouchableOpacity>
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
if(contact.telephone.length > 0) {
|
|
164
|
-
contact.telephone.forEach((phoneNumber) => {
|
|
165
|
-
output.push(
|
|
166
|
-
<TouchableOpacity key={'phone_'+ index} onPress={() => {
|
|
167
|
-
const formattedPhoneNumber = phoneNumber.number.replace(/\s/g, '');
|
|
168
|
-
Linking.openURL('tel:' + formattedPhoneNumber).catch(error => console.error(`ContactDetailComponent - Fehler beim öffnen des Telefons ${Platform.OS}`, error));
|
|
169
|
-
}}>
|
|
170
|
-
<List.Item
|
|
171
|
-
title={t('contact:phone') + ' ' + index}
|
|
172
|
-
description={phoneNumber.number}
|
|
135
|
+
{
|
|
136
|
+
contact?.department
|
|
137
|
+
? <List.Item
|
|
138
|
+
key="department"
|
|
139
|
+
title={t('contact:department')}
|
|
140
|
+
description={contact.department}
|
|
173
141
|
descriptionStyle={themeStyles.textLighter}
|
|
174
142
|
titleStyle={themeStyles.searchDetailTitle}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
{
|
|
190
|
-
|
|
143
|
+
descriptionNumberOfLines={200} />
|
|
144
|
+
: null
|
|
145
|
+
}
|
|
146
|
+
{
|
|
147
|
+
contact?.room && contact?.room?.title
|
|
148
|
+
? <List.Item
|
|
149
|
+
key="room"
|
|
150
|
+
title={t('contact:room')}
|
|
151
|
+
description={contact.room.title}
|
|
152
|
+
descriptionStyle={themeStyles.textLighter}
|
|
153
|
+
titleStyle={themeStyles.searchDetailTitle}
|
|
154
|
+
descriptionNumberOfLines={200} />
|
|
155
|
+
: null
|
|
156
|
+
}
|
|
157
|
+
{
|
|
158
|
+
contact?.email
|
|
159
|
+
? <TouchableOpacity
|
|
160
|
+
key="email"
|
|
161
|
+
onPress={() => Linking.openURL('mailto:' + contact.email)}
|
|
162
|
+
>
|
|
163
|
+
<List.Item
|
|
164
|
+
title={t('contact:email')}
|
|
165
|
+
description={contact.email}
|
|
166
|
+
descriptionStyle={themeStyles.textLighter}
|
|
167
|
+
titleStyle={themeStyles.searchDetailTitle}
|
|
168
|
+
right={props => <List.Icon {...props} icon="email" />}
|
|
169
|
+
/>
|
|
170
|
+
</TouchableOpacity>
|
|
171
|
+
: null
|
|
172
|
+
}
|
|
173
|
+
{
|
|
174
|
+
Array.isArray(contact?.telephone)
|
|
175
|
+
? contact.telephone.map(
|
|
176
|
+
(telephone, index, telephones) => {
|
|
177
|
+
|
|
178
|
+
const title = telephones.length == 1
|
|
179
|
+
? t('contact:phone')
|
|
180
|
+
: t('contact:phone') + ' ' + index;
|
|
181
|
+
|
|
182
|
+
const telephoneNumber = telephone.number
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<TouchableOpacity
|
|
186
|
+
key={telephoneNumber}
|
|
187
|
+
onPress={
|
|
188
|
+
() => {
|
|
189
|
+
const formattedPhoneNumber = telephone.number.replace(/\s/g, '');
|
|
190
|
+
Linking.openURL('tel:' + formattedPhoneNumber).catch(error => console.error(`ContactDetailComponent - Fehler beim öffnen des Telefons ${Platform.OS}`, error));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
>
|
|
194
|
+
<List.Item
|
|
195
|
+
title={title}
|
|
196
|
+
description={telephoneNumber}
|
|
197
|
+
descriptionStyle={themeStyles.textLighter}
|
|
198
|
+
titleStyle={themeStyles.searchDetailTitle}
|
|
199
|
+
right={props => <Icon {...props} icon={'call'} />}
|
|
200
|
+
/>
|
|
201
|
+
</TouchableOpacity>
|
|
202
|
+
)
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
: null
|
|
206
|
+
}
|
|
207
|
+
<View style={styles.space} />
|
|
191
208
|
</ScrollView>
|
|
192
|
-
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
render() {
|
|
196
|
-
// ------------------------------------------------------------------------
|
|
197
|
-
// PLUGIN FUNCTIONALITY
|
|
198
|
-
// ------------------------------------------------------------------------
|
|
199
|
-
const PluginComponent = this.props.pluginComponent;
|
|
200
|
-
if (PluginComponent) {
|
|
201
|
-
return <PluginComponent />;
|
|
202
|
-
}
|
|
203
|
-
// ------------------------------------------------------------------------
|
|
204
|
-
|
|
205
|
-
const {themeStyles} = this.props.theme;
|
|
206
|
-
const { contact, t } = this.props;
|
|
207
|
-
|
|
208
|
-
if(!contact){
|
|
209
|
-
return (<Text>{t('contact:couldNotLoad')}</Text>);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
this.contact = contact;
|
|
213
|
-
|
|
214
|
-
return (
|
|
215
|
-
<SafeAreaView style={[this.styles.container, themeStyles.safeAreaContainer]}>
|
|
216
|
-
<AppbarComponent
|
|
217
|
-
{...this.props}
|
|
218
|
-
title={t('contact:contactInformation')}
|
|
219
|
-
rightAction={<AppbarAction icon='share' onPress={this._onShare.bind(this)} />}
|
|
220
|
-
/>
|
|
221
|
-
{this._renderContent()}
|
|
222
|
-
</SafeAreaView>
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
const mapStateToProps = state => {
|
|
229
|
-
return {
|
|
230
|
-
pluginComponent: state.pluginReducer.contactDetail.component,
|
|
231
|
-
pluginStyles: state.pluginReducer.contactDetail.styles
|
|
232
|
-
};
|
|
233
|
-
};
|
|
209
|
+
</SafeAreaView>
|
|
234
210
|
|
|
235
|
-
|
|
211
|
+
: <Text>
|
|
212
|
+
{t('contact:couldNotLoad')}
|
|
213
|
+
</Text>;
|
|
214
|
+
}
|