Update DB configurations

parent f6d14975
......@@ -15,19 +15,35 @@ const AddData = () => {
const updateData = () => {
const jobSatisfactionValue = Job_Satisfaction === 'Yes' ? 0 : 1;
const sleepHoursValue = parseInt(selectedHours);
let sleepHoursValue = parseInt(selectedHours);
// Applying the logic to set sleep hours value
if (!isNaN(sleepHoursValue)) {
sleepHoursValue = sleepHoursValue > 8 ? 0 : 1;
} else {
console.error("Invalid input for Sleep Hours. Please enter a valid number.");
return; // Exit the function if sleep hours is invalid
}
const postData = {
Job_Satisfaction: jobSatisfactionValue,
Sleep_Hours: sleepHoursValue,
Text: Additional_Text,
isNew: false
isNew: true // Set isNew to true initially
};
set(ref(db, 'live_data'), postData);
} else {
console.error("Invalid input for Sleep Hours. Please enter a valid number.");
}
set(ref(db, 'live_data'), postData)
.then(() => {
console.log("Data updated successfully");
// After some time or event, update isNew to false
setTimeout(() => {
set(ref(db, 'live_data/isNew'), false);
}, 5000); // Example: Set isNew to false after 5 seconds
})
.catch(error => {
console.error("Error updating data:", error);
});
setModalVisible(false); // Close the modal after updating data
};
......
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