-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathentity-info.component.js
134 lines (119 loc) · 3.54 KB
/
entity-info.component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React from 'react';
import styled from 'styled-components';
import { ListItem } from 'react-native-elements';
import Communications from 'react-native-communications';
import { SectionList } from 'components';
import { colors, fonts } from 'config';
import { t } from 'utils';
type Props = {
entity: Object,
orgs: Array,
locale: string,
navigation: Object,
};
const StyledListItem = styled(ListItem).attrs({
containerStyle: {
borderBottomColor: colors.greyLight,
borderBottomWidth: 1,
},
titleStyle: {
color: colors.black,
...fonts.fontPrimary,
},
subtitleStyle: {
color: colors.greyDark,
...fonts.fontPrimary,
},
underlayColor: props => (props.hideChevron ? null : colors.greyLight),
hideChevron: props => props.hideChevron,
})``;
const getBlogLink = url =>
url.substr(0, 4) === 'http' ? url : `http://${url}`;
const getLocationLink = location =>
`https://www.google.com/maps/place/${location.split(' ').join('+')}`;
const getCompanyFormatted = company => {
const companyFormatted = company.replace(/ /g, '');
return company.charAt(0) === '@'
? companyFormatted.substring(1)
: companyFormatted;
};
const companyInOrgs = (company, orgs) =>
orgs.some(
org =>
org.login.toLowerCase() === getCompanyFormatted(company).toLowerCase()
);
const navigateToCompany = (company, orgs, navigation) => {
if (companyInOrgs(company, orgs)) {
navigation.navigate('Organization', {
organization: orgs.find(
org =>
org.login.toLowerCase() === getCompanyFormatted(company).toLowerCase()
),
});
}
};
export const EntityInfo = ({ entity, orgs, locale, navigation }: Props) => {
const checksKeys = ['company', 'location', 'email', 'blog'];
if (!checksKeys.filter(key => !!entity[key]).length) {
return null;
}
return (
<SectionList title={t('INFO', locale)}>
{!!entity.company &&
entity.company !== '' && (
<StyledListItem
title={t('Company', locale)}
leftIcon={{
name: 'organization',
color: colors.grey,
type: 'octicon',
}}
subtitle={entity.company}
onPress={() => navigateToCompany(entity.company, orgs, navigation)}
hideChevron={!companyInOrgs(entity.company, orgs)}
/>
)}
{!!entity.location &&
entity.location !== '' && (
<StyledListItem
title={t('Location', locale)}
leftIcon={{
name: 'location',
color: colors.grey,
type: 'octicon',
}}
subtitle={entity.location}
onPress={() => Communications.web(getLocationLink(entity.location))}
/>
)}
{!!entity.email &&
entity.email !== '' && (
<StyledListItem
title={t('Email', locale)}
leftIcon={{
name: 'mail',
color: colors.grey,
type: 'octicon',
}}
subtitle={entity.email}
onPress={() =>
Communications.email([entity.email], null, null, null, null)
}
/>
)}
{!!entity.blog &&
entity.blog !== '' && (
<StyledListItem
title={t('Website', locale)}
leftIcon={{
name: 'link',
color: colors.grey,
type: 'octicon',
}}
subtitle={entity.blog}
onPress={() => Communications.web(getBlogLink(entity.blog))}
/>
)}
</SectionList>
);
};