src/components/CV/TopSection/InfoLine.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 143
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 111
mnd 4
bc 4
fnc 0
dl 0
loc 143
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from 'react'
2
import PropTypes from 'prop-types'
3
import { connect } from 'react-redux'
4
import cx from 'classnames'
5
import { withTranslation } from 'react-i18next'
6
import PlaceIcon from '@material-ui/icons/Place'
7
import PhoneAndroidIcon from '@material-ui/icons/PhoneAndroid'
8
import Tooltip from '@material-ui/core/Tooltip'
9
import { makeStyles } from '@material-ui/core/styles'
10
import EmailIcon from '@material-ui/icons/Email'
11
import CakeIcon from '@material-ui/icons/Cake'
12
import FlagIcon from '@material-ui/icons/Flag'
13
import HomeIcon from '@material-ui/icons/Home'
14
import GitHubIcon from '@material-ui/icons/GitHub'
15
import TwitterIcon from '@material-ui/icons/Twitter'
16
import topStyle from './index.scss'
17
import { autoDetectDmy, age } from '../../../utils/timeFormat'
18
import Copy from './Copy'
19
import Call from './Call'
20
21
const useStyles = makeStyles({
22
  tooltip: {
23
    fontSize: '0.8rem',
24
    textAlign: 'center',
25
  },
26
})
27
28
const InfoLine = ({
29
  type,
30
  text,
31
  url,
32
  isNotExtUrl,
33
  isSocial,
34
  currentLang,
35
  t,
36
}) => {
37
  const classes = useStyles()
38
  const typeMapping = {
39
    address: {
40
      name: t('Address'),
41
      icon: PlaceIcon,
42
    },
43
    tel: {
44
      name: t('Telephone number'),
45
      icon: PhoneAndroidIcon,
46
    },
47
    email: {
48
      name: t('Email'),
49
      icon: EmailIcon,
50
    },
51
    birth_date: {
52
      name: t('Birth date'),
53
      icon: CakeIcon,
54
    },
55
    birth_place: {
56
      name: t('Birth place'),
57
      icon: FlagIcon,
58
    },
59
    website: {
60
      name: t('Website'),
61
      icon: HomeIcon,
62
    },
63
    github: {
64
      name: t('GitHub'),
65
      icon: GitHubIcon,
66
    },
67
    twitter: {
68
      name: t('Twitter'),
69
      icon: TwitterIcon,
70
    },
71
  }
72
  const typeLower = type.toLowerCase()
73
  const TypeIcon = typeMapping[typeLower].icon
74
75
  return (
76
    <div
77
      className={cx({
78
        [topStyle.social]: isSocial,
79
        [topStyle.infoline]: true,
80
      })}
81
      data-type={typeLower}
82
    >
83
      <Tooltip
84
        classes={{ tooltip: classes.tooltip }}
85
        title={typeMapping[typeLower].name}
86
      >
87
        <span
88
          className={`${topStyle.svgwrapper} ${topStyle.fronticon}`}
89
          aria-label={typeMapping[typeLower].name}
90
        >
91
          <TypeIcon />
92
        </span>
93
      </Tooltip>
94
      {url ? (
95
        <a
96
          href={url}
97
          className={topStyle.text}
98
          target={isNotExtUrl ? undefined : '_blank'}
99
          rel={isNotExtUrl ? undefined : 'noopener noreferrer'}
100
        >
101
          {text}
102
        </a>
103
      ) : (
104
        <span className={topStyle.text}>
105
          {typeLower === 'birth_date'
106
            ? `${autoDetectDmy(text, currentLang)} (${age(text, currentLang)})`
107
            : text}
108
        </span>
109
      )}
110
      {typeLower === 'tel' && (
111
        <>
112
          <Copy text={text} title={t('Copy phone number')} />
113
          <Call tel={text} title={t('Call the number')} />
114
        </>
115
      )}
116
      {typeLower === 'email' && (
117
        <Copy text={text} title={t('Copy Email address')} />
118
      )}
119
    </div>
120
  )
121
}
122
123
InfoLine.defaultProps = {
124
  isNotExtUrl: false,
125
  isSocial: false,
126
}
127
128
InfoLine.propTypes = {
129
  type: PropTypes.string.isRequired,
130
  text: PropTypes.string.isRequired,
131
  url: PropTypes.string,
132
  isNotExtUrl: PropTypes.bool,
133
  isSocial: PropTypes.bool,
134
  currentLang: PropTypes.string.isRequired,
135
  t: PropTypes.func.isRequired,
136
}
137
138
const mapStateToProps = (state) => ({
139
  currentLang: state.lang,
140
})
141
142
export default connect(mapStateToProps)(withTranslation()(InfoLine))
143