-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailsScreen.js
163 lines (158 loc) · 4.49 KB
/
DetailsScreen.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
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
// DetailsScreen.js
import React, { useState } from 'react';
import { View, Text, TextInput, Modal, StyleSheet, Pressable, Alert, Button } from 'react-native';
import DateTimePicker from 'react-native-ui-datepicker';
import dayjs from 'dayjs';
const DetailsScreen = ({ navigation }) => {
const [goalName, setGoalName] = useState('');
const [goalDescription, setGoalDescription] = useState('');
const [goalAmount, setGoalAmount] = useState(0);
const [initialAmount, setInitialAmount] = useState(0);
const [goalDate_End, setGoalDate_End] = useState(dayjs('0000-12-00').format('DD/MM/YYYY').toString());
const [monthlyIncome, setMonthlyIncome] = useState(0);
const [modalVisible, setModalVisible] = useState(false);
const handleRegister = () => {
const poupancaData = {
poupancaName: goalName,
goal: goalAmount,
description: goalDescription,
};
axios
.post("http://localhost:8000/addPoupanca", poupancaData)
.then((response) => {
Alert.alert(
"Registration Successful",
"You have been registered successfully"
);
setGoalName("");
setGoalAmount("");
setGoalDescription("");
})
.catch((error) => {
Alert.alert(
"Registration Fail",
"An error occurred during registration"
);
console.log("register failed", error);
});
};
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Nome da nova poupança</Text>
<TextInput
style={{ height: 40 }}
placeholder="Carro novo..."
onChangeText={newText => setGoalName(newText)}
value={goalName}
defaultValue={goalName}
/>
<Text>Meta</Text>
<TextInput
style={{ height: 40 }}
placeholder="Valor da Meta"
onChangeText={newText => setGoalAmount(newText)}
defaultValue={goalAmount}
value={goalAmount}
/>
<Text>Valor inicial</Text>
<TextInput
style={{ height: 40 }}
placeholder="-MT"
onChangeText={newText => setInitialAmount(newText)}
defaultValue={initialAmount}
/>
<Text>Descrição</Text>
<TextInput
style={{ height: 40 }}
placeholder="Descrição"
onChangeText={newText => setGoalDescription(newText)}
value={goalDescription}
defaultValue={goalDescription}
/>
<Text>Expectaviva de Término da Poupança</Text>
<Pressable
style={[styles.button, styles.buttonOpen]}
onPress={() => setModalVisible(true)}>
<Text>{goalDate_End}</Text>
</Pressable>
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
Alert.alert('Modal has been closed.');
setModalVisible(!modalVisible);
}}>
<View style={styles.centeredView}>
<View style={styles.modalView}>
<DateTimePicker
mode='date'
goalDate_End={goalDate_End}
onValueChange={(date) => setGoalDate_End(dayjs(date).format('DD/MM/YYYY').toString())}
/>
<Pressable
style={[styles.button, styles.buttonClose]}
onPress={() => setModalVisible(!modalVisible)}>
<Text style={styles.textStyle}>Hide Modal</Text>
</Pressable>
</View>
</View>
</Modal>
<Button
onPress={() => {
navigation.navigate('Home')
handleRegister()
}}
title="Gravar nova poupança" color="#841584"
accessibilityLabel="Learn more about this purple button" />
</View >
);
};
const styles = StyleSheet.create({
centeredView: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
marginTop: 22,
},
modalView: {
margin: 20,
backgroundColor: 'white',
borderRadius: 20,
padding: 35,
alignItems: 'center',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
button: {
borderRadius: 20,
padding: 10,
elevation: 2,
},
buttonOpen: {
backgroundColor: '#F194FF',
},
buttonClose: {
backgroundColor: '#2196F3',
},
textStyle: {
color: 'white',
fontWeight: 'bold',
textAlign: 'center',
},
modalText: {
marginBottom: 15,
textAlign: 'center',
},
inputStyle: {
borderWidth: 2,
borderColor: "black",
},
});
export default DetailsScreen;