Add Popup Form

parent 293360a7
import { View, Text, StyleSheet, TextInput, Button, Image } from 'react-native' import { View, Text, StyleSheet, TextInput, Button, Image, Modal, TouchableOpacity } from 'react-native'
import React, { useState } from 'react' import React, { useState } from 'react'
import { db } from '../config' import { db } from '../config'
import { ref, set } from 'firebase/database' import { ref, set } from 'firebase/database'
...@@ -7,6 +7,7 @@ const AddData = () => { ...@@ -7,6 +7,7 @@ const AddData = () => {
const [Job_Satisfaction, setTitle] = useState(''); const [Job_Satisfaction, setTitle] = useState('');
const [Sleep_Hours, setSleepHours] = useState(''); const [Sleep_Hours, setSleepHours] = useState('');
const [Additional_Text, setText] = useState(''); const [Additional_Text, setText] = useState('');
const [modalVisible, setModalVisible] = useState(false);
// function to update data in Firebase Realtime DB // function to update data in Firebase Realtime DB
const updateData = () => { const updateData = () => {
...@@ -24,39 +25,62 @@ const AddData = () => { ...@@ -24,39 +25,62 @@ const AddData = () => {
} else { } else {
console.error("Invalid input for Job Satisfaction or Sleep Hours. Please enter valid numbers."); console.error("Invalid input for Job Satisfaction or Sleep Hours. Please enter valid numbers.");
} }
setModalVisible(false); // Close the modal after updating data
} }
return ( return (
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.header}>STRESS TRACKER </Text> <Text style={styles.header}>STRESS TRACKER </Text>
<Image <TouchableOpacity onPress={() => setModalVisible(true)}>
source={require('../images/Home.jpg')} <Image
style={styles.image} source={require('../images/Home.jpg')}
/> style={styles.image}
<TextInput />
placeholder='Job Satisfaction' </TouchableOpacity>
value={Job_Satisfaction}
onChangeText={(text) => setTitle(text)}
style={styles.input}
keyboardType='numeric'
/>
<TextInput
placeholder='Sleep hours'
value={Sleep_Hours}
onChangeText={(text) => setSleepHours(text)}
style={styles.input}
keyboardType='numeric'
/>
<TextInput
placeholder='Additional text'
value={Additional_Text}
onChangeText={(text) => setText(text)}
style={styles.input}
/>
<Button <Button
title='Update Data' title="Open Popup"
onPress={updateData} onPress={() => setModalVisible(true)}
/> />
<Modal
animationType="slide"
transparent={true}
visible={modalVisible}
onRequestClose={() => {
setModalVisible(!modalVisible);
}}
>
<View style={styles.modalContainer}>
<View style={styles.modalContent}>
<TouchableOpacity onPress={() => setModalVisible(false)} style={styles.closeButton}>
<Text style={styles.closeButtonText}>X</Text>
</TouchableOpacity>
<TextInput
placeholder='Job Satisfaction'
value={Job_Satisfaction}
onChangeText={(text) => setTitle(text)}
style={styles.input}
keyboardType='numeric'
/>
<TextInput
placeholder='Sleep hours'
value={Sleep_Hours}
onChangeText={(text) => setSleepHours(text)}
style={styles.input}
keyboardType='numeric'
/>
<TextInput
placeholder='Additional text'
value={Additional_Text}
onChangeText={(text) => setText(text)}
style={styles.input}
/>
<Button
title='Update Data'
onPress={updateData}
/>
</View>
</View>
</Modal>
</View> </View>
) )
} }
...@@ -86,5 +110,32 @@ const styles = StyleSheet.create({ ...@@ -86,5 +110,32 @@ const styles = StyleSheet.create({
image: { image: {
width: '100%', width: '100%',
height: 200, height: 200,
} },
modalContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
modalContent: {
backgroundColor: '#fff',
padding: 20,
borderRadius: 10,
width: '80%',
},
closeButton: {
position: 'absolute',
top: 10,
right: 10,
backgroundColor: '#ccc',
borderRadius: 15,
width: 30,
height: 30,
justifyContent: 'center',
alignItems: 'center',
},
closeButtonText: {
fontSize: 20,
fontWeight: 'bold',
},
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment