|
@@ -1,11 +1,19 @@
|
1
|
1
|
import React from 'react';
|
2
|
2
|
import { StyleSheet, Text, View, TextInput, Button, Pressable } from 'react-native';
|
3
|
3
|
import { sqlite_exec_parameterised } from '../db/query';
|
|
4
|
+import DateTimePicker from '@react-native-community/datetimepicker';
|
|
5
|
+
|
4
|
6
|
|
5
|
7
|
export default function AddDepense(props){
|
6
|
8
|
const [addingDepense, onAddDepense] = React.useState(false);
|
7
|
9
|
const [depenseValue, onValueEdit] = React.useState(null);
|
8
|
10
|
const [descriptionValue, onDescriptionEdit] = React.useState(null);
|
|
11
|
+ const [depenseDate, onDateChange] = React.useState(new Date())
|
|
12
|
+ const [timePickerDisplay, onDatePicker] = React.useState(false)
|
|
13
|
+
|
|
14
|
+ const toggleDateInput = () => {
|
|
15
|
+ onDatePicker(true);
|
|
16
|
+ }
|
9
|
17
|
|
10
|
18
|
return (<View style={ add_depenses_styles.overlay }>
|
11
|
19
|
<View >
|
|
@@ -30,6 +38,31 @@ export default function AddDepense(props){
|
30
|
38
|
}}
|
31
|
39
|
/>
|
32
|
40
|
</View>
|
|
41
|
+ <View style={ add_depenses_styles.form_entry }>
|
|
42
|
+ <Text> 📅</Text>
|
|
43
|
+ <TextInput
|
|
44
|
+ onPressIn={ () => toggleDateInput()}
|
|
45
|
+ value={ depenseDate.toDateString() } style={ add_depenses_styles.input }
|
|
46
|
+ onChangeText={ (value) => {
|
|
47
|
+ onDescriptionEdit(value);
|
|
48
|
+ }}
|
|
49
|
+ />
|
|
50
|
+ {/* https://github.com/react-native-datetimepicker/datetimepicker */}
|
|
51
|
+ { timePickerDisplay && <DateTimePicker
|
|
52
|
+ testID="dateTimePicker"
|
|
53
|
+ value={depenseDate}
|
|
54
|
+ mode={"date"}
|
|
55
|
+ is24Hour={true}
|
|
56
|
+ display="default"
|
|
57
|
+ onChange={(event, value) => {
|
|
58
|
+ console.log(value);
|
|
59
|
+ console.log(value.valueOf());
|
|
60
|
+ onDatePicker(false);
|
|
61
|
+ onDateChange(new Date(value));
|
|
62
|
+ }}
|
|
63
|
+ />
|
|
64
|
+ }
|
|
65
|
+ </View>
|
33
|
66
|
<Pressable
|
34
|
67
|
style={add_depenses_styles.button_add}
|
35
|
68
|
onPress={() =>
|
|
@@ -39,10 +72,12 @@ export default function AddDepense(props){
|
39
|
72
|
{
|
40
|
73
|
sqlite_exec_parameterised(
|
41
|
74
|
"INSERT INTO expense (value, description, date) values (?, ?, ?)",
|
42
|
|
- [depenseValue, descriptionValue, Date.now()], (res) => {
|
|
75
|
+ [depenseValue, descriptionValue, depenseDate.valueOf()], (res) => {
|
43
|
76
|
onAddDepense(false);
|
44
|
77
|
}
|
45
|
78
|
);
|
|
79
|
+ props.fetchDepenses();
|
|
80
|
+
|
46
|
81
|
}
|
47
|
82
|
}}>
|
48
|
83
|
<Text>Ajouter</Text>
|