aboutsummaryrefslogtreecommitdiff
path: root/src/screens/profile/SettingsScreen.tsx
blob: f9d437d0384b97db82cd595825c98e13e3ff0314 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import React from 'react';
import {
  Alert,
  Image,
  SectionList,
  StatusBar,
  StyleSheet,
  Text,
  TouchableOpacity,
  View,
} from 'react-native';
import {SafeAreaView} from 'react-native-safe-area-context';
import {normalize, SCREEN_WIDTH} from '../../utils/layouts';
import {Background} from '../../components';
import {BackgroundGradientType} from '../../types';
import {logout} from '../../store/actions';
import {useDispatch, useSelector} from 'react-redux';
import {useNavigation} from '@react-navigation/core';
import {RootState} from 'src/store/rootReducer';
import {ERROR_ATTEMPT_EDIT_SP} from '../../constants/strings';

const DATA = [
  {
    title: 'ACCOUNT',
    data: [
      {
        title: 'Suggested People Profile',
        preimage: require('../../assets/images/tagg-logo.png'),
        postimage: require('../../assets/images/settings/white-arrow.png'),
      },
      {
        title: 'Privacy',
        preimage: require('../../assets/images/settings/settings-white.png'),
        postimage: require('../../assets/images/settings/white-arrow.png'),
      },
    ],
  },
  {
    title: 'GENERAL',
    data: [
      {
        title: 'Terms of use',
        preimage: require('../../assets/images/settings/termsofuse.png'),
        postimage: require('../../assets/images/settings/white-arrow.png'),
      },
      {
        title: 'Privacy Policy',
        preimage: require('../../assets/images/settings/privacypolicy.png'),
        postimage: require('../../assets/images/settings/white-arrow.png'),
      },
    ],
  },
];

const SettingsScreen: React.FC = () => {
  const dispatch = useDispatch();
  const navigation = useNavigation();
  const {suggested_people_linked} = useSelector(
    (state: RootState) => state.user.profile,
  );
  const goToUpdateSPProfile = () => {
    if (suggested_people_linked === 0) {
      Alert.alert(ERROR_ATTEMPT_EDIT_SP);
    } else {
      // Sending undefined for updatedSelectedBadges to mark that there was no update yet
      navigateTo('UpdateSPPicture', {
        editing: true,
      });
    }
  };

  const navigateTo = (screen: string, options: object) => {
    navigation.navigate(screen, options);
  };

  const getActions = (type: string) => {
    switch (type) {
      case 'Suggested People Profile':
        goToUpdateSPProfile();
        break;
      case 'Privacy':
        navigateTo('PrivacyScreen', {});
        break;
      case 'Terms of use':
        //TODO:
        break;
      case 'Privacy Policy':
        //TODO:
        break;
      default:
        break;
    }
  };

  const Item = ({
    title,
    preimage,
    postimage,
  }: {
    title: string;
    preimage: number;
    postimage: number;
  }) => (
    <TouchableOpacity onPress={() => getActions(title)} style={styles.item}>
      <Image
        resizeMode={'cover'}
        style={{width: SCREEN_WIDTH * 0.05, height: SCREEN_WIDTH * 0.05}}
        source={preimage}
      />
      <View style={{marginLeft: 40}}>
        <Text style={styles.title}>{title}</Text>
      </View>
      <Image
        style={{width: 15, height: 15, position: 'absolute', right: 0}}
        source={postimage}
      />
    </TouchableOpacity>
  );

  return (
    <>
      <StatusBar barStyle="light-content" />
      <Background gradientType={BackgroundGradientType.Light}>
        <SafeAreaView>
          <View style={{marginLeft: 28, marginRight: 43}}>
            <SectionList
              sections={DATA}
              keyExtractor={(item, index) => item.title + index}
              renderItem={({item: {title, preimage, postimage}}) => {
                return <Item {...{title, preimage, postimage}} />;
              }}
              renderSectionHeader={({section: {title}}) => (
                <View style={{marginTop: 46}}>
                  <Text style={styles.header}>{title}</Text>
                </View>
              )}
              ListFooterComponent={() => (
                <TouchableOpacity
                  style={{marginTop: '20%', marginLeft: '12%'}}
                  onPress={() => {
                    navigation.reset({
                      index: 0,
                      routes: [{name: 'SuggestedPeople'}],
                    });
                    dispatch(logout());
                  }}>
                  <Text style={styles.logoutStyle}>Logout</Text>
                </TouchableOpacity>
              )}
            />
          </View>
        </SafeAreaView>
      </Background>
    </>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  item: {
    marginTop: 36,
    flexDirection: 'row',
    justifyContent: 'flex-start',
    alignItems: 'center',
  },
  header: {
    fontSize: normalize(18),
    fontWeight: '600',
    lineHeight: normalize(21.48),
    color: '#E9E9E9',
  },
  title: {
    fontSize: normalize(15),
    fontWeight: '600',
    lineHeight: normalize(17.9),
    color: 'white',
  },
  logoutStyle: {
    fontSize: normalize(20),
    fontWeight: '600',
    lineHeight: normalize(23.87),
    color: 'white',
  },
});

export default SettingsScreen;