@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.
@@ -12,30 +12,34 @@
12
12
  * limitations under the License.
13
13
  */
14
14
 
15
- import React from 'react';
16
- import PropTypes from 'prop-types';
15
+ import {
16
+ useCallback,
17
+ useMemo
18
+ } from 'react';
17
19
 
18
20
  import {
19
- StyleSheet,
20
- Text,
21
- View,
21
+ Linking,
22
+ Platform,
22
23
  SafeAreaView,
24
+ ScrollView,
23
25
  Share,
24
- Linking,
26
+ StyleSheet,
27
+ Text,
25
28
  TouchableOpacity,
26
- Platform,
27
- ScrollView
29
+ View,
28
30
  } from 'react-native';
29
- import {Appbar, Headline, List, withTheme} from "react-native-paper";
31
+ import {
32
+ Headline,
33
+ List,
34
+ useTheme,
35
+ } from "react-native-paper";
30
36
 
31
- import { connect } from 'react-redux'
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
- * Parameters:
47
- * - contact: Contact object with all information about the contact
48
- *
49
- * Navigation-Parameters:
50
- * - none
50
+ * @param {object} props
51
+ * @param {object} props.contact - Der anzuzeigende Kontakt
51
52
  */
52
- class ContactDetailComponent extends React.Component {
53
- static propTypes = {
54
- contact: PropTypes.object.isRequired
55
- };
56
-
57
- // Styles of this component
58
- styles;
59
-
60
- contact = null;
61
-
62
-
63
- constructor(props) {
64
- super(props);
65
- // ------------------------------------------------------------------------
66
- // PLUGIN FUNCTIONALITY
67
- // ------------------------------------------------------------------------
68
-
69
- const { pluginStyles,theme } = this.props;
70
- this.styles = componentStyles(theme);
71
-
72
- if(pluginStyles) {
73
- this.styles = merge(this.styles, pluginStyles);
74
- }
75
-
76
- this.styles = StyleSheet.create(this.styles);
77
-
78
- // ------------------------------------------------------------------------
79
- };
80
-
81
- /**
82
- * Share function for contact
83
- *
84
- * @returns {Promise<void>}
85
- * @private
86
- */
87
- async _onShare() {
88
- try {
89
- const { t } = this.props;
90
-
91
- let phone = "";
92
- if(this.contact.telephone.length > 0) {
93
- phone += "\n"+ t('contact:phone') +": ";
94
- this.contact.telephone.forEach((phoneNumber) => {
95
- phone += phoneNumber.number + '\n';
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
- let message = t('contact:title') + ' - ' + this.contact.firstName + ' ' + this.contact.lastName +
100
- ((this.contact.building) ? "\n" + t('contact:building') + ": " + this.contact.building : '') +
101
- ((this.contact.department) ? "\n" + t('contact:department') + ": " + this.contact.department : '') +
102
- ((this.contact.room && this.contact.room.title) ? "\n" + t('contact:room') + ": " + this.contact.room.title : '') +
103
- ((this.contact.email) ? "\n" + t('contact:email') + ": " + this.contact.email : '') +
104
- phone;
105
-
106
- const result = await Share.share({
107
- message: message
108
- });
109
-
110
- if (result.action === Share.sharedAction) {
111
- if (result.activityType) {
112
- // shared with activity type of result.activityType
113
- } else {
114
- // shared
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
- } else if (result.action === Share.dismissedAction) {
117
- // dismissed
118
- }
119
- } catch (error) {
120
- alert(error.message);
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
- right={props =>
176
- <List.Icon {...props}
177
- icon="phone"/>}
178
- />
179
- </TouchableOpacity>
180
- );
181
- index++;
182
- });
183
- }
184
-
185
-
186
- return (
187
- <ScrollView style={this.styles.containerInner}>
188
- <Headline style={this.styles.name}>{contact.firstName} {contact.lastName}</Headline>
189
- {output}
190
- <View style={this.styles.space}/>
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
- export default connect(mapStateToProps, null)(withTranslation()(withTheme(ContactDetailComponent)))
211
+ : <Text>
212
+ {t('contact:couldNotLoad')}
213
+ </Text>;
214
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olea-bps/base",
3
- "version": "1.1.5",
3
+ "version": "1.1.6",
4
4
  "description": "OLEA base library",
5
5
  "main": "index.js",
6
6
  "repository": {