-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddContact.js
114 lines (103 loc) · 2.74 KB
/
AddContact.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
import React from 'react';
import { StyleSheet, TextInput, SafeAreaView, View, Button } from 'react-native';
import { addContactToList } from './Datastore';
import { DatePicker } from 'react-native-woodpicker'
import CaAvatar from './CaAvatar';
const AddContact = ({ navigation }) => {
// variabili di stato
const [name, onChangeName] = React.useState('');
const [birthday, onChangeBirthday] = React.useState();
const [address, onChangeAddress] = React.useState('');
const [phone, onChangePhone] = React.useState('');
// se la data non è selezionata metti il testo placeholder
const handleBdText = () => birthday
? birthday.toDateString()
: "Data di Nascita";
const handleContactCreation = () => {
// controllo validità dati
if (name == "") {
alert("Per favore, inserisci un nome");
return;
}
if (phone == "") {
alert("Per favore, inserisci un numero di telefono");
return;
}
// registra dati in rubrica
if (
!addContactToList(name, birthday, address, phone)
) {
alert("Impossibile creare il contatto, " + route.params.auid);
} else {
navigation.navigate('ContactList')
}
}
return (
<SafeAreaView style={styles.globalView}>
<View style={styles.avatarView}>
<CaAvatar size={100} name={name} uid={""} />
</View>
<TextInput
style={styles.textInput}
onChangeText={onChangeName}
placeholder='Nome e cognome'
value={name}
/>
<DatePicker
style={styles.textInput}
value={birthday}
onDateChange={onChangeBirthday}
title="Data di nascita"
text={handleBdText()}
isNullable={false}
iosDisplay="spinner"
androidDisplay="spinner"
/>
<TextInput
style={styles.textInput}
onChangeText={onChangeAddress}
placeholder='Indirizzo'
value={address}
/>
<TextInput
style={styles.textInput}
onChangeText={onChangePhone}
placeholder='Numero di telefono'
value={phone}
keyboardType='number-pad'
/>
<View style={styles.spacer}></View>
<Button
title='Salva'
style={styles.createButton}
onPress={() => handleContactCreation()}
/>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
globalView: {
margin: 17,
flexDirection: 'column',
},
textInput: {
height: 30,
borderBottomColor: 'gray',
borderBottomWidth: 1,
padding: 5,
marginRight: 8,
marginLeft: 8,
marginTop: 20,
},
spacer: {
marginTop: 20
},
avatarView: {
flexDirection: 'row',
justifyContent: 'center',
width: '100%',
marginTop: 20,
marginBottom: 10,
}
});
export default AddContact;