When I click on button2, I sent datas from a #textBox1 to collumn Rating and the email of currentUser to collumn email, on my data collection AvaliacaoUsuarios, but this datas are add in 2 lines.
I would like to add the current user email in the same line of a data sent by a form.
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady(() => {
// Initialise the button2 click handler
$w('#button1').onClick(button1_onclick); // Don't do this AND set the handler in the property panel. One or the other! This is easier to debug ;-)
});
export function button1_onclick() {
let user = wixUsers.currentUser;
// If we are logged in then save the email address
if (user.loggedIn) {
// User is logged in so lets save their email address.
let userEmail;
user.getEmail()
.then((email) => {
userEmail = email;
//------------------------------------------------------//
// We need to process the email information inside of the then()
// function call
// Because the getEmail call will take time and we don't want
// to try to use the userEmail value until we know we have a value
// to work with
//------------------------------------------------------//
const toInsert = {
"email": userEmail
};
// add the item to the collection...
// We return the result of the insert. This way if the getEmail function
// fails OR the insert fails then the catch() will report the error.
return wixData.insert("AvaliacaoUsuarios", toInsert);
})
.catch((err) => {
console.log(err);
});
}
}