You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

add_depense.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import React from 'react';
  2. import { StyleSheet, Text, View, TextInput, Button, Pressable } from 'react-native';
  3. import { sqlite_exec_parameterised } from '../db/query';
  4. export default function AddDepense(props){
  5. const [addingDepense, onAddDepense] = React.useState(false);
  6. const [depenseValue, onValueEdit] = React.useState(null);
  7. const [descriptionValue, onDescriptionEdit] = React.useState(null);
  8. return (<View style={ add_depenses_styles.overlay }>
  9. <View >
  10. {addingDepense ?
  11. <View style={ add_depenses_styles.form_area }>
  12. <Text> Nouvelle dépense</Text>
  13. <View style={ add_depenses_styles.form_entry }>
  14. <Text> 💸</Text>
  15. <TextInput
  16. keyboardType="numeric"
  17. style={ add_depenses_styles.input }
  18. onChangeText={ (value) => {
  19. onValueEdit(value);
  20. }}
  21. />
  22. </View>
  23. <View style={ add_depenses_styles.form_entry }>
  24. <Text> 📃</Text>
  25. <TextInput style={ add_depenses_styles.input }
  26. onChangeText={ (value) => {
  27. onDescriptionEdit(value);
  28. }}
  29. />
  30. </View>
  31. <Pressable
  32. style={add_depenses_styles.button_add}
  33. onPress={() =>
  34. {
  35. console.log(depenseValue);
  36. if(null != depenseValue)
  37. {
  38. sqlite_exec_parameterised(
  39. "INSERT INTO expense (value, description, date) values (?, ?, ?)",
  40. [depenseValue, descriptionValue, Date.now()], (res) => {
  41. onAddDepense(false);
  42. }
  43. );
  44. }
  45. }}>
  46. <Text>Ajouter</Text>
  47. </Pressable>
  48. </View>
  49. : <View/>}
  50. </View>
  51. <View style={ add_depenses_styles.button_add_parent }>
  52. <Pressable
  53. style={add_depenses_styles.button_add}
  54. onPress={() => onAddDepense(!addingDepense)}>
  55. <Text>{!addingDepense ? "+" : "-"}</Text>
  56. </Pressable>
  57. </View>
  58. </View>
  59. );
  60. }
  61. const add_depenses_styles = StyleSheet.create({
  62. overlay: {
  63. height: "100%",
  64. width: "100%",
  65. position: 'absolute',
  66. },
  67. form_area: {
  68. backgroundColor: '#f2f2f2',
  69. zIndex: 10,
  70. elevation: 10,
  71. margin: 5,
  72. marginTop: '50%',
  73. display: 'flex',
  74. flexDirection: 'column',
  75. justifyContent: "space-between",
  76. borderWidth: 1,
  77. },
  78. form_entry :{
  79. display: 'flex',
  80. flexDirection: 'row',
  81. },
  82. input :{
  83. width: "50%",
  84. borderWidth: 1,
  85. textAlign: 'center',
  86. },
  87. button_add: {
  88. borderWidth: 1,
  89. padding: 10,
  90. },
  91. button_add_parent: {
  92. position: 'absolute',
  93. bottom: 10,
  94. right: 10,
  95. }
  96. });