aboutsummaryrefslogtreecommitdiff
path: root/src/components/onboarding/TermsConditions.tsx
blob: 9bd0ee3bb347f1b469cc7bcdb0736318886c504f (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
import React, {useState} from 'react';
import {
  Modal,
  StyleSheet,
  View,
  Text,
  Button,
  TouchableOpacity,
  ScrollView,
  ViewProps,
} from 'react-native';

import {RadioCheckbox, CenteredView, OverlayView} from '../common';
import TermsAndConditionsText from './TermsAndConditionsText';

interface TermsConditionsProps extends ViewProps {
  accepted: boolean;
  onChange: (accepted: boolean) => void;
}
const TermsConditions: React.FC<TermsConditionsProps> = (props) => {
  // boolean representing if modal is visible
  const [modalVisible, setModalVisible] = useState(false);
  // destructure props
  const {accepted, onChange} = props;
  /**
   * Hides the modal.
   */
  const hideModal = (): void => {
    if (modalVisible) {
      setModalVisible(false);
    }
  };
  /**
   * Sets `accepted` to `true` and hides the modal.
   */
  const handleAccept = (): void => {
    onChange(true);
    hideModal();
  };
  /**
   * Toggles the value of `accepted`.
   */
  const toggleAccepted = (): void => {
    onChange(!accepted);
  };

  return (
    <View {...props}>
      <View style={styles.body}>
        <RadioCheckbox checked={accepted} onPress={toggleAccepted} />
        <View style={styles.bodyPrompt}>
          <Text style={styles.bodyPromptText}>Accept </Text>
          <TouchableOpacity onPress={() => setModalVisible(true)}>
            <Text
              style={[styles.bodyPromptText, styles.bodyPromptTextUnderline]}>
              Terms and Conditions
            </Text>
          </TouchableOpacity>
        </View>
      </View>
      <Modal visible={modalVisible} transparent={true} animationType="fade">
        <OverlayView>
          <CenteredView>
            <View style={styles.modalView}>
              <ScrollView
                style={styles.modalScrollView}
                contentContainerStyle={styles.modalScrollViewContent}>
                <Text style={styles.tcHeader}>
                  End User License Agreement (EULA) & Terms of Service
                </Text>
                <TermsAndConditionsText />
              </ScrollView>
              <View style={styles.modalActions}>
                <Button title="Accept" onPress={handleAccept} />
                <View style={styles.modalActionsDivider} />
                <Button title="Close" onPress={hideModal} />
              </View>
            </View>
          </CenteredView>
        </OverlayView>
      </Modal>
    </View>
  );
};

const styles = StyleSheet.create({
  body: {
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
  },
  bodyPrompt: {
    flexDirection: 'row',
    marginLeft: 10,
  },
  bodyPromptText: {
    fontSize: 16,
    color: '#fff',
  },
  bodyPromptTextUnderline: {
    textDecorationLine: 'underline',
  },
  modalView: {
    width: '85%',
    height: '55%',
    backgroundColor: '#fff',
    shadowColor: '#000',
    shadowOpacity: 30,
    shadowOffset: {width: 0, height: 2},
    shadowRadius: 5,
    borderRadius: 8,
    paddingTop: 30,
    paddingBottom: 15,
    paddingHorizontal: 20,
    alignItems: 'center',
    justifyContent: 'space-between',
  },
  modalScrollViewContent: {
    justifyContent: 'center',
    alignItems: 'center',
  },
  modalScrollView: {
    marginBottom: 10,
  },
  tcHeader: {
    fontSize: 18,
    fontWeight: 'bold',
  },
  modalActions: {
    flexDirection: 'row',
    justifyContent: 'space-evenly',
    alignItems: 'center',
    width: '100%',
  },
  modalActionsDivider: {
    height: '60%',
    backgroundColor: '#0160Ca',
    width: 1,
  },
});

export default TermsConditions;