aboutsummaryrefslogtreecommitdiff
path: root/src/components/friends/InviteFriendTile.tsx
blob: 9613b1ac50643bada1990a4d9d917d47ebaab051 (plain)
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
import React, {useEffect, useState} from 'react';
import {
  StyleSheet,
  Text,
  TouchableOpacity,
  TouchableWithoutFeedback,
  View,
} from 'react-native';
import {TAGG_LIGHT_BLUE} from '../../constants';
import {inviteFriendService} from '../../services';
import {normalize} from '../../utils';

interface InviteFriendTileProps {
  item: Object;
}

const InviteFriendTile: React.FC<InviteFriendTileProps> = ({item}) => {
  const [invited, setInvited] = useState<boolean>(false);
  const [formatedPhoneNumber, setFormattedPhoneNumber] = useState<string>('');
  const handleInviteFriend = async () => {
    const response = await inviteFriendService(
      item.phoneNumber,
      item.firstName,
      item.lastName,
    );
    if (response) {
      setInvited(response);
    }
  };

  useEffect(() => {
    const formatPhoneNumer = () => {
      const unformatted_number: string = item.phoneNumber;
      const part_one: string = unformatted_number.substring(2, 5);
      const part_two: string = unformatted_number.substring(5, 8);
      const part_three: string = unformatted_number.substring(
        8,
        unformatted_number.length,
      );
      const temp = '(' + part_one + ')' + part_two + '-' + part_three;
      setFormattedPhoneNumber(temp);
    };
    formatPhoneNumer();
  });

  return (
    <TouchableWithoutFeedback>
      <View style={styles.container}>
        <View style={styles.bodyContainer}>
          <Text style={styles.label}>
            {item.firstName + ' ' + item.lastName}
          </Text>
          <Text style={styles.phoneNumber}>{formatedPhoneNumber}</Text>
        </View>
        <TouchableOpacity
          disabled={invited}
          style={styles.button}
          onPress={handleInviteFriend}>
          <Text style={styles.buttonTitle}>
            {invited ? 'Invited' : 'Invite'}
          </Text>
        </TouchableOpacity>
      </View>
    </TouchableWithoutFeedback>
  );
};

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'space-between',
    height: normalize(42),
    marginBottom: '5%',
  },
  bodyContainer: {
    flexDirection: 'column',
    height: normalize(42),
    justifyContent: 'space-around',
  },
  label: {
    fontWeight: '500',
    fontSize: normalize(14),
  },
  phoneNumber: {
    fontSize: normalize(12),
    fontWeight: '400',
    color: '#6C6C6C',
    letterSpacing: normalize(0.1),
  },
  button: {
    alignSelf: 'center',
    justifyContent: 'center',
    alignItems: 'center',
    width: 82,
    height: 25,
    borderColor: TAGG_LIGHT_BLUE,
    borderWidth: 2,
    borderRadius: 2,
    padding: 0,
    backgroundColor: 'transparent',
  },
  buttonTitle: {
    color: TAGG_LIGHT_BLUE,
    padding: 0,
    fontSize: normalize(11),
    fontWeight: '700',
    lineHeight: normalize(13.13),
    letterSpacing: normalize(0.6),
    paddingHorizontal: '3.8%',
  },
});

export default InviteFriendTile;